ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/get_mem.c
Revision: 103
Committed: Thu Feb 19 01:37:38 2009 UTC (12 years, 7 months ago) by gilbertke
File size: 9435 byte(s)
Log Message:
major rewrite - removing global data, adding electrostatics tag to read_sdf
Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "pcmod.h"
5 #include "attached.h"
6 #include "derivs.h"
7 #include "hess.h"
8 #include "utility.h"
9 #include "nonbond.h"
10 #include "torsions.h"
11
12 void max_torsions(void);
13 void get_molecule_memory(int);
14 int use_solv(void);
15
16
17 #define STILL 1
18 #define HCT 2
19
20 EXTERN struct t_solvent {
21 int type;
22 double EPSin, EPSsolv;
23 double doffset, p1,p2,p3,p4,p5;
24 double *shct,*asolv,*rsolv,*vsolv,*gpol,*rborn;
25 } solvent;
26
27 // =======================================
28 /*void get_molecule_memory(int niatom)
29 {
30 int i,j;
31
32 atom.type = ivector(0,niatom+10);
33 atom.tclass = ivector(0,niatom+10);
34 atom.mmx_type = ivector(0,niatom+10);
35 atom.mm3_type = ivector(0,niatom+10);
36 atom.mmff_type = ivector(0,niatom+10);
37 atom.atomnum = ivector(0,niatom+10);
38 atom.use = ivector(0,niatom+10);
39 atom.flags = ilvector(0,niatom+10);
40 atom.iat = imatrix(0, niatom+10,0,MAXIAT);
41 atom.bo = imatrix(0,niatom+10, 0, MAXIAT);
42 atom.x = dvector(0,niatom+10);
43 atom.y = dvector(0,niatom+10);
44 atom.z = dvector(0,niatom+10);
45 atom.charge = dvector(0,niatom+10);
46 atom.formal_charge = dvector(0,niatom+10);
47 atom.sigma_charge = dvector(0,niatom+10);
48 atom.atomwt = dvector(0,niatom+10);
49 atom.radius = dvector(0,niatom+10);
50
51
52 for (i=0; i <= niatom; i++)
53 {
54 atom.type[i] = 0;
55 atom.tclass[i] = 0;
56 atom.mmx_type[i] = 0;
57 atom.mm3_type[i] = 0;
58 atom.mmff_type[i] = 0;
59 atom.atomnum[i] = 0;
60 atom.use[i] = 0;
61 atom.flags[i] = 0;
62 atom.x[i] = 0.0;
63 atom.y[i] = 0.0;
64 atom.z[i] = 0.0;
65 atom.charge[i] = 0.0;
66 atom.formal_charge[i] = 0.0;
67 atom.sigma_charge[i] = 0.0;
68 atom.atomwt[i] = 0.0;
69 for (j=0; j < MAXIAT; j++)
70 {
71 atom.iat[i][j] = 0;
72 atom.bo[i][j] = 0;
73 }
74 }
75
76 }*/
77 /* ================================================================ */
78 void get_memory()
79 {
80 int i, j;
81 int ntor;
82 int ntypes, found, itype[MAXATOMTYPE];
83
84 skip = imatrix(0,natom+1,0,natom+1);
85 for (i=1; i <= natom; i++)
86 {
87 for (j=1; j <=natom; j++)
88 skip[i][j] = 0;
89 }
90
91 deriv.d1 = dmatrix(0,natom+1, 0,3);
92 deriv.deb = dmatrix(0,natom+1, 0,3);
93 deriv.dea = dmatrix(0,natom+1, 0,3);
94 deriv.destb = dmatrix(0,natom+1, 0,3);
95 deriv.deopb = dmatrix(0,natom+1, 0,3);
96 deriv.detor = dmatrix(0,natom+1, 0,3);
97 deriv.de14 = dmatrix(0,natom+1, 0,3);
98 deriv.devdw = dmatrix(0,natom+1, 0,3);
99 deriv.deqq = dmatrix(0,natom+1, 0,3);
100 deriv.deaa = dmatrix(0,natom+1, 0,3);
101 deriv.destor = dmatrix(0,natom+1, 0,3);
102 deriv.dehb = dmatrix(0,natom+1, 0,3);
103 deriv.deimprop = dmatrix(0,natom+1, 0,3);
104 deriv.deub = dmatrix(0,natom+1, 0,3);
105 deriv.desolv = dmatrix(0,natom+1, 0,3);
106 deriv.degeom = dmatrix(0,natom+1, 0,3);
107 deriv.drb = dvector(0,natom+1);
108
109 ntypes = 0;
110 nonbond.maxnbtype = 0;
111
112 for (i=1; i <= natom; i++)
113 {
114 found = FALSE;
115 if (atom.type[i] > nonbond.maxnbtype)
116 nonbond.maxnbtype = atom.type[i];
117 for (j=0; j < ntypes; j++)
118 {
119 if (atom.type[i] == itype[j])
120 {
121 found = TRUE;
122 break;
123 }
124 }
125 if (found == FALSE)
126 {
127 itype[ntypes] = atom.type[i];
128 ntypes++;
129 }
130 }
131
132 j=0;
133 for (i=0; i <= ntypes; i++)
134 j+= i;
135
136 nonbond.nonbond = j;
137 nonbond.iNBtype = imatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
138 nonbond.ipif = imatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
139 nonbond.vrad = dmatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
140 nonbond.veps = dmatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
141 nonbond.vrad14 = dmatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
142 nonbond.veps14 = dmatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
143
144 max_torsions();
145 ntor = torsions.ntor;
146 if (ntor > 0)
147 {
148 torsions.i14 = imatrix(0,ntor,0,4);
149 torsions.v1 = vector(0,ntor);
150 torsions.v2 = vector(0,ntor);
151 torsions.v3 = vector(0,ntor);
152 torsions.v4 = vector(0,ntor);
153 torsions.v5 = vector(0,ntor);
154 torsions.v6 = vector(0,ntor);
155 torsions.ph1 = ivector(0,ntor);
156 torsions.ph2 = ivector(0,ntor);
157 torsions.ph3 = ivector(0,ntor);
158 torsions.ph4 = ivector(0,ntor);
159 torsions.ph5 = ivector(0,ntor);
160 torsions.ph6 = ivector(0,ntor);
161 for (i=0; i < ntor; i++)
162 {
163 torsions.v1[i] = 0.0;
164 torsions.v2[i] = 0.0;
165 torsions.v3[i] = 0.0;
166 torsions.v4[i] = 0.0;
167 torsions.v5[i] = 0.0;
168 torsions.v6[i] = 0.0;
169 torsions.ph1[i] = 0;
170 torsions.ph2[i] = 0;
171 torsions.ph3[i] = 0;
172 torsions.ph4[i] = 0;
173 torsions.ph5[i] = 0;
174 torsions.ph6[i] = 0;
175 }
176 }
177 hess.hessx = matrix(0,natom+1, 0,3);
178 hess.hessy = matrix(0,natom+1, 0,3);
179 hess.hessz = matrix(0,natom+1, 0,3);
180
181 attached.n13 = ivector(0,natom+1);
182 attached.n14 = ivector(0,natom+1);
183 attached.i13 = imatrix(0, 20, 0,natom+1);
184 attached.i14 = imatrix(0,144, 0,natom+1);
185
186 for(i=0; i <= natom; i++)
187 {
188 for (j=0; j < 3; j++)
189 {
190 deriv.d1[i][j] = 0.0;
191 deriv.deb[i][j] = 0.0;
192 deriv.dea[i][j] = 0.0;
193 deriv.destb[i][j] = 0.0;
194 deriv.deopb[i][j] = 0.0;
195 deriv.detor[i][j] = 0.0;
196 deriv.de14[i][j] = 0.0;
197 deriv.devdw[i][j] = 0.0;
198 deriv.deqq[i][j] = 0.0;
199 deriv.deaa[i][j] = 0.0;
200 deriv.destor[i][j] = 0.0;
201 deriv.dehb[i][j] = 0.0;
202 deriv.deimprop[i][j] = 0.0;
203 deriv.deub[i][j] = 0.0;
204
205 hess.hessx[i][j] = 0.0;
206 hess.hessy[i][j] = 0.0;
207 hess.hessz[i][j] = 0.0;
208 }
209 }
210 if (use_solv())
211 {
212 solvent.asolv = dvector(0,natom+1);
213 solvent.rsolv = dvector(0,natom+1);
214 solvent.rborn = dvector(0,natom+1);
215 if (solvent.type == STILL)
216 {
217 solvent.vsolv = dvector(0,natom+1);
218 solvent.gpol = dvector(0,natom+1);
219 } else if (solvent.type == HCT)
220 {
221 solvent.shct = dvector(0,natom+1);
222 }
223 }
224 }
225
226 void free_memory()
227 {
228 int ntor;
229 free_imatrix(skip, 0, natom+1,0,natom+1);
230 free_dmatrix(deriv.d1, 0,natom+1, 0,3);
231 free_dmatrix(deriv.deb, 0,natom+1, 0,3);
232 free_dmatrix(deriv.dea, 0,natom+1, 0,3);
233 free_dmatrix(deriv.destb, 0,natom+1, 0,3);
234 free_dmatrix(deriv.deopb, 0,natom+1, 0,3);
235 free_dmatrix(deriv.detor, 0,natom+1, 0,3);
236 free_dmatrix(deriv.de14, 0,natom+1, 0,3);
237 free_dmatrix(deriv.devdw, 0,natom+1, 0,3);
238 free_dmatrix(deriv.deqq, 0,natom+1, 0,3);
239 free_dmatrix(deriv.deaa, 0,natom+1, 0,3);
240 free_dmatrix(deriv.destor, 0,natom+1, 0,3);
241 free_dmatrix(deriv.dehb, 0,natom+1, 0,3);
242 free_dmatrix(deriv.deimprop,0,natom+1, 0,3);
243 free_dmatrix(deriv.deub, 0,natom+1, 0,3);
244 free_dmatrix(deriv.desolv ,0,natom+1, 0,3);
245 free_dmatrix(deriv.degeom ,0,natom+1, 0,3);
246 free_dvector(deriv.drb ,0,natom+1);
247
248 free_imatrix(nonbond.iNBtype ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
249 free_imatrix(nonbond.ipif ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
250 free_dmatrix(nonbond.vrad ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
251 free_dmatrix(nonbond.veps ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
252 free_dmatrix(nonbond.vrad14 ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
253 free_dmatrix(nonbond.veps14 ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
254
255 // ntor = 9*natom;
256 ntor = torsions.ntor;
257 if (ntor > 0)
258 {
259 free_imatrix(torsions.i14 ,0,ntor,0,4);
260 free_vector(torsions.v1 ,0,ntor);
261 free_vector(torsions.v2 ,0,ntor);
262 free_vector(torsions.v3 ,0,ntor);
263 free_vector(torsions.v4 ,0,ntor);
264 free_vector(torsions.v5 ,0,ntor);
265 free_vector(torsions.v6 ,0,ntor);
266 free_ivector(torsions.ph1 ,0,ntor);
267 free_ivector(torsions.ph2 ,0,ntor);
268 free_ivector(torsions.ph3 ,0,ntor);
269 free_ivector(torsions.ph4 ,0,ntor);
270 free_ivector(torsions.ph5 ,0,ntor);
271 free_ivector(torsions.ph6 ,0,ntor);
272 }
273
274 free_matrix(hess.hessx, 0,natom+1, 0,3);
275 free_matrix(hess.hessy, 0,natom+1, 0,3);
276 free_matrix(hess.hessz, 0,natom+1, 0,3);
277
278 free_ivector(attached.n13 ,0,natom+1);
279 free_ivector(attached.n14 ,0,natom+1);
280 free_imatrix(attached.i13 ,0, 20, 0,natom+1);
281 free_imatrix(attached.i14 ,0,144, 0,natom+1);
282
283 if (use_solv())
284 {
285 free_dvector(solvent.asolv ,0,natom+1);
286 free_dvector(solvent.rsolv ,0,natom+1);
287 free_dvector(solvent.rborn ,0,natom+1);
288 if (solvent.type == STILL)
289 {
290 free_dvector(solvent.vsolv ,0,natom+1);
291 free_dvector(solvent.gpol ,0,natom+1);
292 } else if (solvent.type == HCT)
293 {
294 free_dvector(solvent.shct ,0,natom+1);
295 }
296 }
297 }
298