cuikenergy.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 
52 #define TRUE_COSTS 0
53 
82 int main(int argc, char **arg)
83 {
84  Tparameters parameters;
85  TBioWorld bioWorld;
86  Tfilename fparam,fsols,fcost;
87  Tbox *box;
88  FILE *fout;
89  unsigned int n,k,nBoxes;
90  double *point;
91  Tlist boxList;
92  Titerator i;
93  double *cost,minCost,maxCost;
94  double *conf;
95  unsigned int nMin,nMax;
96  double e;
97 
98  if (argc>2)
99  {
100  /*Init parameters*/
101  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
102  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
103  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
104 
105  InitBioWorld(&parameters,arg[1],NO_UINT,&conf,&bioWorld);
106 
107  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsols);
108  fprintf(stderr,"Reading solution file : %s\n",GetFileFullName(&fsols));
109  ReadListOfBoxes(GetFileFullName(&fsols),&boxList);
110  nBoxes=ListSize(&boxList);
111  if (nBoxes==0)
112  Error("Empty solution file in cuikenergy");
113 
114  /* Compute the energy for each conformation */
115  InitIterator(&i,&boxList);
116  First(&i);
117  k=0;
118  NEW(cost,nBoxes,double);
119  while(!EndOfList(&i))
120  {
121  box=(Tbox *)GetCurrent(&i);
122  if (k==0)
123  {
124  n=GetBoxNIntervals(box);
125  NEW(point,n,double);
126  }
127  GetBoxCenter(NULL,point,box);
128  e=BioWorldEnergy(&parameters,FALSE,point,(void *)&bioWorld);
129  #if (TRUE_COSTS)
130  cost[k]=e;
131  #else
132  cost[k]=log(e);
133  #endif
134 
135  fprintf(stderr,"%u -> %g (%g)\n",k,cost[k],e);
136 
137  if (k==0)
138  {
139  minCost=cost[k]; nMin=k;
140  maxCost=cost[k]; nMax=k;
141  }
142  else
143  {
144  if (cost[k]>maxCost)
145  { maxCost=cost[k]; nMax=k; }
146  else
147  {
148  if (cost[k]<minCost)
149  { minCost=cost[k]; nMin=k; }
150  }
151  }
152  k++;
153  Advance(&i);
154  }
155  fprintf(stderr,"Extreme energies : %g (%u) -- %g (%u)\n",minCost,nMin,maxCost,nMax);
156 
157  /* Normalize and write */
158  CreateFileName(NULL,arg[2],NULL,COST_EXT,&fcost);
159  fprintf(stderr,"Writing cost file : %s\n",GetFileFullName(&fcost));
160 
161  fout=fopen(GetFileFullName(&fcost),"w");
162  if (!fout)
163  Error("Output file for costs can not be opened");
164 
165  //if (maxCost>4*minCost)
166  // maxCost=4*minCost;
167  for(k=0;k<nBoxes;k++)
168  {
169  //if (cost[k]>maxCost)
170  // fprintf(fout,"1e-5\n");
171  //else
172  {
173  /* Low energy is good -> low values must be mapped to values
174  close to 1 to get green */
175 
176  #if (TRUE_COSTS)
177  fprintf(fout,"%g\n",cost[k]);
178  #else
179  e=((cost[k]-minCost)/(maxCost-minCost))*(1-1e-3)+1e-3;
180  //e=pow(e,0.5);
181  fprintf(fout,"%g\n",e);
182  #endif
183  }
184  }
185  fclose(fout);
186 
187  DeleteFileName(&fsols);
188  DeleteFileName(&fcost);
189  DeleteFileName(&fparam);
190 
191  free(conf);
192  free(point);
193  free(cost);
194  DeleteListOfBoxes(&boxList);
195  DeleteParameters(&parameters);
196  DeleteBioWorld(&bioWorld);
197  }
198  else
199  {
200  fprintf(stderr," Wrong number of parameters.\n");
201  fprintf(stderr," Use:\n");
202  fprintf(stderr," cuikenergy <problem_name>.pdb <sol_name>\n");
203  fprintf(stderr," where:\n");
204  fprintf(stderr," <problem_name> the input molecular information file (pdb).\n");
205  fprintf(stderr," <sol_name> Configurations to evaluate.\n");
206  fprintf(stderr," The extension (e.g., '.pdb') is required\n");
207  fprintf(stderr," All the extensions managed by OpenBabel can be used\n");
208  fprintf(stderr," The ouput file is <sol_name>.cost\n");
209  }
210 
211  return(EXIT_SUCCESS);
212 }
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
double BioWorldEnergy(Tparameters *p, boolean simp, double *conformation, void *bw)
Computes the energy of a given configuration.
Definition: bioworld.c:1896
#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
Definition of the Tfilename type and the associated functions.
#define COST_EXT
File extension for arrays of costs.
Definition: filename.h:155
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
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
int main(int argc, char **arg)
Main body of the cuikenergy application.
Definition: cuikenergy.c:82
void DeleteListOfBoxes(Tlist *l)
Destructor.
Definition: box_list.c:353
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
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
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
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
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