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 }