cuikatoms2samples.c
Go to the documentation of this file.
1 #include "defines.h"
2 #include "filename.h"
3 #include "bioworld.h"
4 
5 #include <stdlib.h>
6 
73 int main(int argc, char **arg)
74 {
75  if (argc>1)
76  {
77  Tparameters parameters;
78  TBioWorld bioWorld;
79 
80  Tfilename fparam;
81  Tfilename fsamples;
82  Tfilename fatoms;
83 
84  boolean nv;
85  double *sample;
86 
87  unsigned int na;
88  double *atoms;
89 
90  unsigned int i,j,k,r;
91  boolean end;
92  int token;
93 
94  FILE *fin;
95  FILE *fout;
96 
97  /* Init parameters */
98  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
99  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
100  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
101 
102  /* Read the problem file */
103  InitBioWorld(&parameters,arg[1],NO_UINT,&sample,&bioWorld);
104  free(sample);
105 
106  /* File from where to read the atoms */
107  CreateFileName(NULL,arg[1],NULL,ATOM_EXT,&fatoms);
108  fin=fopen(GetFileFullName(&fatoms),"r");
109  if (!fin)
110  Error("Can not open the input file with the atom positions");
111 
112  /* Open the file where to store the output samples */
113  r=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
114  if (r==REP_JOINTS)
115  CreateFileName(NULL,arg[1],"_a2s",JOINTS_EXT,&fsamples);
116  else
117  CreateFileName(NULL,arg[1],"_a2s",LINKS_EXT,&fsamples);
118  fprintf(stderr,"Writing samples to : %s\n",GetFileFullName(&fsamples));
119 
120  fout=fopen(GetFileFullName(&fsamples),"w");
121  if (!fout)
122  Error("Could not open the file to write the samples");
123 
124  /* Allocate space for the atoms and the sample */
125  na=BioWorldNAtoms(&bioWorld);
126  NEW(atoms,3*na,double);
127 
128  /* Read one sample from the file of samples */
129  end=FALSE;
130  do {
131  k=0;
132  for(i=0;((!end)&&(i<na));i++)
133  {
134  for(j=0;((!end)&&(j<3));j++,k++)
135  {
136  token=fscanf(fin,"%lf",&(atoms[k]));
137  if ((token==EOF)||(token==0))
138  end=TRUE;
139  }
140  }
141 
142  if (!end)
143  {
144  /* Deduce the conformation from the atom positions */
145  nv=BioWordConformationFromAtomPositions(&parameters,atoms,&sample,&bioWorld);
146 
147  /* Save the conformation */
148  for(i=0;i<nv;i++)
149  fprintf(fout,"%.16f ",sample[i]);
150  fprintf(fout,"\n");
151 
152  free(sample);
153  }
154 
155  } while(!end);
156 
157  /* Close the files */
158  fclose(fin);
159  fclose(fout);
160 
161  /* Release memeory */
162  free(atoms);
163 
164  DeleteBioWorld(&bioWorld);
165  DeleteParameters(&parameters);
166 
167  DeleteFileName(&fparam);
168  DeleteFileName(&fsamples);
169  DeleteFileName(&fatoms);
170  }
171  else
172  {
173  fprintf(stderr," Wrong number of parameters.\n");
174  fprintf(stderr," Use:\n");
175  fprintf(stderr," cuikatoms2samples <problem_name>.pdb\n");
176  fprintf(stderr," where <problem_name>.pdb contains the molecular information\n");
177  fprintf(stderr," The '.pab' extension is required\n");
178  fprintf(stderr," All the extensions managed by OpenBabel can be used\n");
179  }
180 
181  return(EXIT_SUCCESS);
182 }
void InitBioWorld(Tparameters *p, char *filename, unsigned int maxAtomsLink, double **conformation, TBioWorld *bw)
Initializes a world form a biomolecule.
Definition: bioworld.c:1394
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
#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
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
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
int main(int argc, char **arg)
Main body of the cuikatoms2samples application.
Definitions of constants and macros used in several parts of the cuik library.
unsigned int BioWorldNAtoms(TBioWorld *bw)
Number of atoms in the molecule.
Definition: bioworld.c:1807
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 CT_REPRESENTATION
Representation.
Definition: parameters.h:215
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:187
#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
unsigned int BioWordConformationFromAtomPositions(Tparameters *p, double *atoms, double **conformation, TBioWorld *bw)
Produces the internal coordinates from the atom positions.
Definition: bioworld.c:1876
Structure with the molecular and the mechanical information.
Definition: bioworld.h:28
#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