cuikpdb2sample.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 
59 int main(int argc, char **arg)
60 {
61  if (argc>1)
62  {
63  Tparameters parameters;
64  TBioWorld bioWorld;
65 
66  Tfilename fparam;
67  Tfilename fsamples;
68 
69  boolean nv;
70  double *sample;
71 
72  unsigned int i,r;
73 
74  FILE *fout;
75 
76  /* Init parameters */
77  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
78  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
79  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
80 
81  /* Read the problem file */
82  InitBioWorld(&parameters,arg[1],NO_UINT,&sample,&bioWorld);
83  nv=BioWorldConformationSize(&bioWorld);
84 
85  /* Open the file where to store the output sample */
86  r=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
87  if (r==REP_JOINTS)
88  CreateFileName(NULL,arg[1],"_pdb",JOINTS_EXT,&fsamples);
89  else
90  CreateFileName(NULL,arg[1],"_pdb",LINKS_EXT,&fsamples);
91  fprintf(stderr,"Writing sample to : %s\n",GetFileFullName(&fsamples));
92 
93  fout=fopen(GetFileFullName(&fsamples),"w");
94  if (!fout)
95  Error("Could not open the file to write the sample");
96 
97  /* Save the conformation */
98  for(i=0;i<nv;i++)
99  fprintf(fout,"%.16f ",sample[i]);
100  fprintf(fout,"\n");
101 
102  /* Close the files */
103  fclose(fout);
104 
105  /* Release memeory */
106  free(sample);
107 
108  DeleteBioWorld(&bioWorld);
109  DeleteParameters(&parameters);
110 
111  DeleteFileName(&fparam);
112  DeleteFileName(&fsamples);
113  }
114  else
115  {
116  fprintf(stderr," Wrong number of parameters.\n");
117  fprintf(stderr," Use:\n");
118  fprintf(stderr," cuikpdb2sample <problem_name>.pdb\n");
119  fprintf(stderr," where:\n");
120  fprintf(stderr," <problem_name>.pdb the prefix to define the bio-info.\n");
121  fprintf(stderr," The extension (e.g., '.pdb') is required\n");
122  fprintf(stderr," All the extensions managed by OpenBabel can be used\n");
123  fprintf(stderr," The output is stored in <proble_name>_pdb.dof\n");
124  fprintf(stderr," or in <proble_name>_pdb.sample depending on the representation used\n");
125  }
126 
127  return(EXIT_SUCCESS);
128 }