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