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 }