ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/gmmx_run.c
Revision: 85
Committed: Mon Jan 12 15:05:44 2009 UTC (10 years, 9 months ago) by gilbertke
File size: 5427 byte(s)
Log Message:
more cleanup and code removal
Line File contents
1 /* NOTICE: this source code file has been modified for use with FreeMOL */
2 #define EXTERN extern
3 #include "pcwin.h"
4 #include "pcmod.h"
5 #include "utility.h"
6 #include "energies.h"
7 #include "dipmom.h"
8 #include "vibrate.h"
9
10 #include <errno.h>
11
12 struct t_logp {
13 float logp;
14 } logp_calc;
15
16 EXTERN struct t_files {
17 int nfiles, append, batch, icurrent, ibatno;
18 } files;
19
20 EXTERN struct t_minim_values {
21 int iprint, ndc, nconst;
22 float dielc;
23 } minim_values;
24 EXTERN struct t_minim_control {
25 int type, method, field, added_const;
26 char added_path[256],added_name[256];
27 } minim_control;
28
29 int rd_sdf(FILE *);
30 int setup_calculation(void);
31 void end_calculation(void);
32 void minimize(void);
33 static int close_contact(int);
34 void initialize(void);
35 void type(void);
36 void read_gmmxinp(char*,FILE*,int);
37 void hdel(int);
38 void hadd(void);
39 int FetchRecord(FILE *, char *);
40 void write_sdf(int);
41 void zero_data(void);
42 void type_mmx(void);
43 void read_datafiles(char *);
44 void xlogp(float *);
45
46 // =====================================
47 void read_gmmxinp(char *paramfile,
48 FILE *infile,
49 int flags)
50 {
51 char line[121];
52 int i,ncount,nret,j,k,jj,nc;
53 int icount;
54 int ngood, nbparam, nbatom,nbcontact;
55 int bcontact = FALSE;
56 int batom = FALSE;
57 float logp;
58 //char *std_file;
59 char bad_atom[80],bad_contact[80],bad_param[80];
60 FILE *logfile;
61
62 // check filetype
63 ncount = 0;
64
65 /*
66 std_file = strdup(out_file);
67 strcpy(Savebox.fname, out_file);
68 */
69
70 // build filenames
71 strcpy(bad_atom,"_batom.sdf");
72 strcpy(bad_contact,"_bcontact.sdf");
73 strcpy(bad_param,"_bparam.sdf");
74
75 // open logfile
76 logfile = pcmlogfile;
77
78 files.nfiles = 0;
79 //
80 minim_control.field = MMFF94;
81 //strcpy(line,paramfile);
82 zero_data();
83 read_datafiles(paramfile);
84 minim_control.method = 1; // just do first deriv minimization
85 icount = 0;
86 //
87 ngood = nbparam = nbatom = nbcontact = 0;
88 i = 0;
89 while (1)
90 // for (i=1; i <= files.nfiles; i++)
91 {
92 ++i;
93 initialize();
94 nret = rd_sdf(infile);
95 if (-1 == nret) return ;
96 if (FALSE == nret)
97 {
98 fprintf(logfile,"Strnum: %d Cannot handle aromatic bonds. Try Kekule version.\n",i);
99 goto L_10;
100 natom = 0;
101 }
102
103 if (natom == 1)
104 {
105 fprintf(logfile,"Strnum: %d has only one atom\n",i);
106 goto L_10;
107 }
108 if (nret == TRUE)
109 {
110 // TJO
111 if (flags & DO_ADDH)
112 {
113 hdel(0);
114 hadd();
115 }
116 type();
117
118 // minim_values.iprint = TRUE;
119 nret = setup_calculation();
120 // for(i=1; i<= natom; i++)
121 //printf("Atom: %d %d %x\n",i,atom[i].type,atom[i].flags);
122 //if (minim_values.iprint == TRUE) exit(0);
123 if (nret == TRUE)
124 {
125 minimize();
126 // compute xlogp
127 if (energies.total < 1000.0)
128 {
129 if (flags & DO_XLOGP) {
130 if (VERBOSE) fprintf(pcmlogfile, " Evaluating XlogP\n");
131 xlogp(&logp);
132 logp_calc.logp = logp;
133 }
134 // compute dipole moment
135 dipolemom.xdipole = 0.0;
136 dipolemom.ydipole = 0.0;
137 dipolemom.zdipole = 0.0;
138 if (flags & DO_DIPOLE) {
139 if (VERBOSE) fprintf(pcmlogfile, " Evaluating dipole moment\n");
140 charge_dipole();
141 dipolemom.total = sqrt(dipolemom.xdipole*dipolemom.xdipole +
142 dipolemom.ydipole*dipolemom.ydipole +
143 dipolemom.zdipole*dipolemom.zdipole);
144 }
145 // compute vib
146 if (flags & DO_VIBRATION) {
147 if (VERBOSE) fprintf(pcmlogfile, " Evaluating vibrational parameters\n");
148 vibrate();
149 }
150 write_sdf(flags);
151 ++ngood;
152 ++files.nfiles;
153 }
154 } else
155 {
156 strcpy(Savebox.fname,bad_param);
157 files.append = TRUE;
158 //write_sdf(flags);
159 nbparam++;
160 //strcpy(Savebox.fname,std_file);
161 fprintf(logfile,"Strnum: %d CID: %s fails on missing parameters\n",files.nfiles,Struct_Title);
162 if (VERBOSE)
163 fprintf(stdout, "Missing parameters - no calc - %s\n",Struct_Title);
164 }
165 end_calculation();
166 if (VERBOSE) {
167 fprintf(stdout,
168 "Strnum: %d %s natom %d \n",files.nfiles,Struct_Title, natom);
169 }
170 } else // read_sdf failed
171 {
172 fprintf(logfile,"Strnum: %d CID: %s fails on unsupported atom\n",files.nfiles,Struct_Title);
173 strcpy(Savebox.fname,bad_atom);
174 files.append = TRUE;
175 if (batom == FALSE)
176 {
177 batom = TRUE;
178 files.append = FALSE;
179 }
180 //write_sdf(flags);
181 nbatom++;
182 //strcpy(Savebox.fname,std_file);
183 }
184 L_10:
185 continue;
186 }
187 // fclose(infile);
188 fprintf(logfile,"Ngood: %d Nbparam: %d Nbatom: %d Nbcontact: %d \n",ngood,nbparam,nbatom,nbcontact);
189 if (VERBOSE) {
190 fprintf(stdout,
191 "Ngood: %d Nbparam: %d Nbatom: %d Nbcontact: %d \n",
192 ngood,nbparam,nbatom,nbcontact);
193 }
194
195 // fclose(logfile);
196 }
197 // ================================================
198 int close_contact(int mode)
199 {
200 int i, j;
201 double dx,dy,dz;
202
203 for (i=1; i < natom; i++)
204 {
205 for (j=i+1; j <= natom; j++)
206 {
207 dx = fabs(atom[i].x - atom[j].x);
208 dy = fabs(atom[i].y - atom[j].y);
209 dz = fabs(atom[i].z - atom[j].z);
210 if ( (dx + dy + dz) < 0.1)
211 {
212 return FALSE;
213 }
214 }
215 }
216 return TRUE;
217 }