cuiksample2pdb.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 
66 int main(int argc, char **arg)
67 {
68  if (argc>1)
69  {
70  Tparameters parameters;
71  TBioWorld bioWorld;
72 
73  Tfilename fparam;
74  Tfilename fsamples;
75  Tfilename fbio;
76 
77  boolean nv;
78  double *sample;
79 
80  FILE *fs;
81  char *fout;
82 
83  double *conf;
84  unsigned int i,r;
85  boolean end;
86  int token;
87 
88  /* Init parameters */
89  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
90  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
91 
92  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
93 
94  /* Read the problem file */
95  InitBioWorld(&parameters,arg[1],NO_UINT,&conf,&bioWorld);
96 
97  /* Open the file from where to read the samples */
98  r=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
99  if (r==REP_JOINTS)
100  CreateFileName(NULL,arg[1],"_center",JOINTS_EXT,&fsamples);
101  else
102  CreateFileName(NULL,arg[1],"_center",LINKS_EXT,&fsamples);
103 
104  fprintf(stderr,"Reading one sample from : %s\n",GetFileFullName(&fsamples));
105 
106  fs=fopen(GetFileFullName(&fsamples),"r");
107  if (!fs)
108  Error("Could not open the file to read the samples");
109 
110  /* Open the file where to store the bio-information */
111  CreateFileName(NULL,arg[1],"_sample",PDB_EXT,&fbio);
112  fout=GetFileFullName(&fbio);
113  fprintf(stderr,"Writing bio-info to : %s\n",fout);
114 
115  /* Allocate space for the sample and dof */
116  nv=BioWorldConformationSize(&bioWorld);
117  NEW(sample,nv,double);
118 
119  /* Read one sample from the file of samples */
120  end=FALSE;
121  for(i=0;((!end)&&(i<nv));i++)
122  {
123  token=fscanf(fs,"%lf",&(sample[i]));
124  if ((token==EOF)||(token==0))
125  end=TRUE;
126  }
127 
128  /* If the sample could be read correctly, use the sample to define a pdb
129  and write it to a file */
130  if (!end)
131  SaveBioWorldBioInfo(&parameters,fout,FALSE,sample,&bioWorld);
132 
133  /* Close the input file */
134  fclose(fs);
135 
136  /* Release memeory */
137  free(sample);
138  free(conf);
139 
140  DeleteBioWorld(&bioWorld);
141  DeleteParameters(&parameters);
142 
143  DeleteFileName(&fparam);
144  DeleteFileName(&fbio);
145  DeleteFileName(&fsamples);
146  }
147  else
148  {
149  fprintf(stderr," Wrong number of parameters.\n");
150  fprintf(stderr," Use:\n");
151  fprintf(stderr," cuiksample2pdb <problem_name>\n");
152  fprintf(stderr," where:\n");
153  fprintf(stderr," <problem_name>.pdb the prefix to define the bio-info.\n");
154  fprintf(stderr," The extension (e.g., '.pdb') is required\n");
155  fprintf(stderr," All the extensions managed by OpenBabel can be used\n");
156  fprintf(stderr," The output is stored in <proble_name>_sample.pdb\n");
157  }
158 
159  return(EXIT_SUCCESS);
160 }
#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:1924
#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:271
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:132
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
Definitions of constants and macros used in several parts of the cuik library.
boolean InitBioWorld(Tparameters *p, char *filename, unsigned int maxAtomsLink, double **conformation, TBioWorld *bw)
Initializes a world form a biomolecule.
Definition: bioworld.c:1394
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 PDB_EXT
Default file extension for bio-info files.
Definition: filename.h:81
#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:188
#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:294
Structure with the molecular and the mechanical information.
Definition: bioworld.h:28
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
void SaveBioWorldBioInfo(Tparameters *p, char *fname, boolean simp, double *conformation, TBioWorld *bw)
Stores the BioWorld information in a molecular format (eg. pdb).
Definition: bioworld.c:1911
int main(int argc, char **arg)
Main body of the cuiksample2pdb application.
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:181
unsigned int BioWorldConformationSize(TBioWorld *bw)
Number of variables used to represent a conformation.
Definition: bioworld.c:1817