cuiksamples2atoms.c
Go to the documentation of this file.
1 #include "defines.h"
2 #include "filename.h"
3 #include "world.h"
4 
5 #include <stdlib.h>
6 
111 int main(int argc, char **arg)
112 {
113  if (argc>1)
114  {
115  Tparameters parameters;
116  Tworld world;
117 
118  Tfilename fparam;
119  Tfilename fsamples;
120  Tfilename fworld;
121  Tfilename fatoms;
122 
123  boolean nv;
124  double *sample;
125 
126  char *fn;
127  FILE *fs;
128 
129  unsigned int i,r;
130  boolean end;
131  int token;
132 
133  FILE *fout;
134 
135  /* Init parameters */
136  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
137  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
138 
139  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
140 
141  /* Read the problem file */
142  CreateFileName(NULL,arg[1],NULL,WORLD_EXT,&fworld);
143  fprintf(stderr,"Reading world file : %s\n",GetFileFullName(&fworld));
144  InitWorldFromFile(&parameters,&fworld,&world);
145 
146  if (!IsMechanismInWorldAllSpheres(&world))
147  Warning("The world is not sphere-only");
148 
149  /* Open the file from where to read the samples */
150  r=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
151  if (r==REP_JOINTS)
152  CreateFileName(NULL,arg[1],NULL,JOINTS_EXT,&fsamples);
153  else
154  CreateFileName(NULL,arg[1],NULL,LINKS_EXT,&fsamples);
155 
156  fprintf(stderr,"Reading one sample from : %s\n",GetFileFullName(&fsamples));
157 
158  fs=fopen(GetFileFullName(&fsamples),"r");
159 
160  if (!fs)
161  Error("Could not open the file to read the samples");
162 
163  if (argc>2)
164  fn=arg[2];
165  else
166  fn=arg[1];
167 
168  /* Open the file where to store the bio-information */
169  CreateFileName(NULL,fn,NULL,ATOM_EXT,&fatoms);
170  fprintf(stderr,"Writing atoms to : %s\n",GetFileFullName(&fatoms));
171 
172  /* Allocate space for the sample/dof */
173  nv=GetWorldNumSystemVariables(&world);
174  NEW(sample,nv,double);
175 
176  /* Read one sample from the file of samples */
177  fout=fopen(GetFileFullName(&fatoms),"w");
178  if (!fout)
179  Error("Could not open the file to store the atom positions");
180 
181  end=FALSE;
182  do {
183  for(i=0;((!end)&&(i<nv));i++)
184  {
185  token=fscanf(fs,"%lf",&(sample[i]));
186  if ((token==EOF)||(token==0))
187  end=TRUE;
188  }
189  /* If the sample could be read correctly, save the atom positions */
190  if (!end)
191  WorldPrintAtoms(&parameters,fout,sample,&world);
192  } while (!end);
193 
194  fclose(fout);
195 
196  /* Close the input file */
197  fclose(fs);
198 
199  /* Release memeory */
200  free(sample);
201  DeleteWorld(&world);
202  DeleteParameters(&parameters);
203 
204  DeleteFileName(&fparam);
205  DeleteFileName(&fworld);
206  DeleteFileName(&fsamples);
207  DeleteFileName(&fatoms);
208  }
209  else
210  {
211  fprintf(stderr,"Use:\n");
212  fprintf(stderr," cuiksamples2atoms <problem_name> <out_name>\n");
213  fprintf(stderr," <problem_name> the prefix to define the world,\n");
214  fprintf(stderr," .params and .samples files.\n");
215  fprintf(stderr," <out_name> [optional] The output atom file.\n");
216  fprintf(stderr,"CAUTION: This only works for carefully defined worlds\n");
217  fprintf(stderr," where the atoms are in the same order as in\n");
218  fprintf(stderr," the PDB. This is NOT the case for automatically\n");
219  fprintf(stderr," generated worlds (as those generated for protein loops)\n");
220  }
221 
222  return(EXIT_SUCCESS);
223 }
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
#define FALSE
FALSE.
Definition: boolean.h:30
#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
void InitWorldFromFile(Tparameters *p, Tfilename *f, Tworld *w)
Constructor.
void WorldPrintAtoms(Tparameters *pr, FILE *f, double *pt, Tworld *w)
Generates a file with the atom centers in global coordiantes.
Definition: world.c:2304
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
unsigned int GetWorldNumSystemVariables(Tworld *w)
Number of system variables in the kinematic subsystem.
Definition: world.c:2158
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
All the necessary information to generate equations for mechanisms.
Definition: world.h:124
Definition of the Tworld type and the associated functions.
void DeleteWorld(Tworld *w)
Destructor.
Definition: world.c:2792
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
boolean IsMechanismInWorldAllSpheres(Tworld *w)
TRUE if the mechanisms in the world is based on spheres.
Definition: world.c:1432
Definitions of constants and macros used in several parts of the cuik library.
void Warning(const char *s)
General warning function.
Definition: error.c:116
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
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 CT_REPRESENTATION
Representation.
Definition: parameters.h:215
#define WORLD_EXT
File extension for problem files.
Definition: filename.h:161
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:187
int main(int argc, char **arg)
Main body of the cuiksamples2atoms application.
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
#define ATOM_EXT
File extension for atom coordinates files.
Definition: filename.h:88
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:180