cuikrmse.c
Go to the documentation of this file.
1 #include "filename.h"
2 #include "box_list.h"
3 #include "error.h"
4 #include "defines.h"
5 #include "parameters.h"
6 #include "bioworld.h"
7 
8 
9 #include <stdio.h>
10 #include <math.h>
11 
46 #define CUSTOM_RMSE 0
47 
72 int main(int argc, char **arg)
73 {
74  Tparameters parameters;
75  TBioWorld bioWorld;
76  Tfilename fparam,fsols;
77  Tbox *box;
78  unsigned int n,k,nBoxes,na;
79  double *point,*pos;
80  Tlist boxList;
81  Titerator i;
82  double e,eMin;
83  double *conf;
84  unsigned int nMin;
85 
86  if (argc>2)
87  {
88  /*Init parameters*/
89  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
90  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
91  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
92 
93  InitBioWorld(&parameters,arg[1],NO_UINT,&conf,&bioWorld);
94  na=BioWorldNAtoms(&bioWorld);
95  NEW(pos,na*3,double);
96 
97  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsols);
98  fprintf(stderr,"Reading solution file : %s\n",GetFileFullName(&fsols));
99  ReadListOfBoxes(GetFileFullName(&fsols),&boxList);
100  nBoxes=ListSize(&boxList);
101  if (nBoxes==0)
102  Error("Empty solution file in cuikrmse");
103 
104  /* Compute the RMSE for each conformation */
105  InitIterator(&i,&boxList);
106  First(&i);
107  k=0;
108  eMin=INF;
109 #if (CUSTOM_RMSE)
110  InitWorldCD(FALSE,&(bioWorld.w));
111 #endif
112  while(!EndOfList(&i))
113  {
114  box=(Tbox *)GetCurrent(&i);
115  if (k==0)
116  {
117  n=GetBoxNIntervals(box);
118  NEW(point,n,double);
119  }
120  GetBoxCenter(NULL,point,box);
121  BioWordGetAtomPositionsFromConformation(&parameters,FALSE,point,pos,&bioWorld);
122 #if (!CUSTOM_RMSE)
123  e=BioWorldRMSE(pos,&bioWorld);
124 #else
125  {
126  /* Code used to fix one rigid body w.r.t another in the example/Bio/2LAO.pdb
127  Here we fix the pos. of atoms 2095, 1384, and 2463 (in rigid2) w.r.t.
128  atoms 1090, 2926, and 1362 (in rigid1, ground link) */
129  double d[19];
130  /* Refrence taken from the distances encoded in 1LST.pdb */
131  double ref[19]={3.1123,3.4769,11.0310,10.7216,6.4688,5.3507,7.9431,6.9768,9.5976,8.3534,6.8026,5.5221,6.0632,9.8894,3.9570,8.9912,9.0433,8.3446,8.2828};
132  boolean collision;
133  double *sfull;
134 
135  /* Check for collision and store the result */
136  RegenerateWorldSolutionPoint(&parameters,point,&sfull,&(bioWorld.w));
137  collision=MoveAndCheckCD(&parameters,sfull,&(bioWorld.w));
138  if (collision)
139  e=INF;
140  else
141  {
142  d[0]=Distance(3,&(pos[3*1090]),&(pos[3*2905]));
143  d[1]=Distance(3,&(pos[3*1090]),&(pos[3*2906]));
144  d[2]=Distance(3,&(pos[3*1090]),&(pos[3*1382]));
145  d[3]=Distance(3,&(pos[3*1090]),&(pos[3*1381]));
146 
147  d[4]=Distance(3,&(pos[3*2924]),&(pos[3*2905]));
148  d[5]=Distance(3,&(pos[3*2924]),&(pos[3*2906]));
149  d[6]=Distance(3,&(pos[3*2924]),&(pos[3*1382]));
150  d[7]=Distance(3,&(pos[3*2924]),&(pos[3*1381]));
151 
152  d[8]=Distance(3,&(pos[3*1362]),&(pos[3*2905]));
153  d[9]=Distance(3,&(pos[3*1362]),&(pos[3*2906]));
154  d[10]=Distance(3,&(pos[3*1362]),&(pos[3*1382]));
155  d[11]=Distance(3,&(pos[3*1362]),&(pos[3*1381]));
156 
157  d[12]=Distance(3,&(pos[3*1090]),&(pos[3*2924]));
158  d[13]=Distance(3,&(pos[3*1090]),&(pos[3*1362]));
159  d[14]=Distance(3,&(pos[3*2924]),&(pos[3*1362]));
160 
161  d[15]=Distance(3,&(pos[3*2905]),&(pos[3*1382]));
162  d[16]=Distance(3,&(pos[3*2905]),&(pos[3*1381]));
163  d[17]=Distance(3,&(pos[3*2906]),&(pos[3*1382]));
164  d[18]=Distance(3,&(pos[3*2906]),&(pos[3*1381]));
165 
166  e=Distance(19,d,ref);
167  }
168  free(sfull);
169  fprintf(stderr,"%u %g\n",k,e);
170  }
171 #endif
172  if (e<eMin)
173  {
174  eMin=e;
175  nMin=k;
176  }
177  k++;
178  Advance(&i);
179  }
180  fprintf(stderr,"Minimum RMSE : %g (%u)\n",eMin,nMin);
181 
182  DeleteFileName(&fsols);
183  DeleteFileName(&fparam);
184 
185  free(conf);
186  free(point);
187  free(pos);
188  DeleteListOfBoxes(&boxList);
189  DeleteParameters(&parameters);
190  DeleteBioWorld(&bioWorld);
191  }
192  else
193  {
194  fprintf(stderr," Wrong number of parameters.\n");
195  fprintf(stderr," Use:\n");
196  fprintf(stderr," cuikrmse <problem_name>.pdb <sol_name>\n");
197  fprintf(stderr," where:\n");
198  fprintf(stderr," <problem_name> the input molecular information file (pdb).\n");
199  fprintf(stderr," <sol_name> Configurations to evaluate.\n");
200  fprintf(stderr," The extension (e.g., '.pdb') is required\n");
201  fprintf(stderr," All the extensions managed by OpenBabel can be used\n");
202  }
203 
204  return(EXIT_SUCCESS);
205 }
unsigned int RegenerateWorldSolutionPoint(Tparameters *pr, double *p, double **v, Tworld *w)
Computes the missing values in a kinematic solution.
Definition: world.c:2276
void InitBioWorld(Tparameters *p, char *filename, unsigned int maxAtomsLink, double **conformation, TBioWorld *bw)
Initializes a world form a biomolecule.
Definition: bioworld.c:1394
void First(Titerator *i)
Moves an iterator to the first position of its associated list.
Definition: list.c:356
#define FALSE
FALSE.
Definition: boolean.h:30
void DeleteBioWorld(TBioWorld *bw)
Destructor.
Definition: bioworld.c:1918
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:248
boolean MoveAndCheckCD(Tparameters *p, boolean all, unsigned int tID, double *sol, double *solPrev, Tworld *w)
Checks a point for collision.
Definition: world.c:1076
Definition of the Tfilename type and the associated functions.
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
boolean ReadListOfBoxes(char *filename, Tlist *l)
Reads a list of boxes from a file.
Definition: box_list.c:286
Collection of methods to work on Tlist of boxes.
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:992
Tworld w
Definition: bioworld.h:29
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
void DeleteListOfBoxes(Tlist *l)
Destructor.
Definition: box_list.c:353
double Distance(unsigned int s, double *v1, double *v2)
Computes the distance of two points.
boolean EndOfList(Titerator *i)
Checks if an iterator is pointing at the end of the list.
Definition: list.c:445
Definitions of constants and macros used in several parts of the cuik library.
A generic list.
Definition: list.h:46
unsigned int BioWorldNAtoms(TBioWorld *bw)
Number of atoms in the molecule.
Definition: bioworld.c:1807
void InitIterator(Titerator *i, Tlist *list)
Constructor.
Definition: list.c:284
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
A bridge between world structures and biological information.
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define SOL_EXT
File extension for solution files.
Definition: filename.h:137
A box.
Definition: box.h:83
int main(int argc, char **arg)
Main body of the cuikrmse application.
Definition: cuikrmse.c:72
void * GetCurrent(Titerator *i)
Gets the element pointed by the iterator.
Definition: list.c:299
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
Structure with the molecular and the mechanical information.
Definition: bioworld.h:28
#define INF
Infinite.
Definition: defines.h:70
double BioWorldRMSE(double *pos, TBioWorld *bw)
Computes the RMSE.
Definition: bioworld.c:1854
List iterator.
Definition: list.h:61
void GetBoxCenter(boolean *used, double *c, Tbox *b)
Returns the box center along the selected dimensions.
Definition: box.c:697
void InitWorldCD(Tparameters *pr, unsigned int mt, Tworld *w)
Initializes the collision detector.
Definition: world.c:1013
unsigned int ListSize(Tlist *list)
Gets the number of elements in the list.
Definition: list.c:180
Definition of the Tparameters type and the associated functions.
boolean Advance(Titerator *i)
Moves an iterator to the next position of its associated list.
Definition: list.c:373
void BioWordGetAtomPositionsFromConformation(Tparameters *p, boolean simp, double *conformation, double *pos, TBioWorld *bw)
Computes the position of the atoms.
Definition: bioworld.c:1817