ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/get_mem.c
Revision: 63
Committed: Wed Dec 3 03:46:32 2008 UTC (12 years, 9 months ago) by gilbertke
File size: 8277 byte(s)
Log Message:
updated read_sdf type_mmx and first pass at using best practices
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 "rings.h"
9 #include "utility.h"
10 #include "nonbond.h"
11 #include "torsions.h"
12 #include "solv.h"
13 #include "pot.h"
14
15 void max_torsions(void);
16
17
18 #define STILL 1
19 #define HCT 2
20
21 EXTERN struct t_solvent {
22 int type;
23 double doffset, p1,p2,p3,p4,p5;
24 double *shct,*asolv,*rsolv,*vsolv,*gpol,*rborn;
25 } solvent;
26
27
28 int *skip;
29
30 /* ================================================================ */
31 void get_memory()
32 {
33 int i, j;
34 int ntor;
35 int ntypes, found, itype[MAXATOMTYPE];
36
37 skip = ivector(0,natom+1);
38
39 deriv.d1 = dmatrix(0,natom+1, 0,3);
40 deriv.deb = dmatrix(0,natom+1, 0,3);
41 deriv.dea = dmatrix(0,natom+1, 0,3);
42 deriv.destb = dmatrix(0,natom+1, 0,3);
43 deriv.deopb = dmatrix(0,natom+1, 0,3);
44 deriv.detor = dmatrix(0,natom+1, 0,3);
45 deriv.de14 = dmatrix(0,natom+1, 0,3);
46 deriv.devdw = dmatrix(0,natom+1, 0,3);
47 deriv.deqq = dmatrix(0,natom+1, 0,3);
48 deriv.deaa = dmatrix(0,natom+1, 0,3);
49 deriv.destor = dmatrix(0,natom+1, 0,3);
50 deriv.dehb = dmatrix(0,natom+1, 0,3);
51 deriv.deimprop = dmatrix(0,natom+1, 0,3);
52 deriv.deub = dmatrix(0,natom+1, 0,3);
53 deriv.desolv = dmatrix(0,natom+1, 0,3);
54 deriv.degeom = dmatrix(0,natom+1, 0,3);
55 deriv.drb = dvector(0,natom+1);
56
57 ntypes = 0;
58 nonbond.maxnbtype = 0;
59
60 for (i=1; i <= natom; i++)
61 {
62 found = FALSE;
63 if (atom[i].type > nonbond.maxnbtype)
64 nonbond.maxnbtype = atom[i].type;
65 for (j=0; j < ntypes; j++)
66 {
67 if (atom[i].type == itype[j])
68 {
69 found = TRUE;
70 break;
71 }
72 }
73 if (found == FALSE)
74 {
75 itype[ntypes] = atom[i].type;
76 ntypes++;
77 }
78 }
79
80 j=0;
81 for (i=0; i <= ntypes; i++)
82 j+= i;
83
84 nonbond.nonbond = j;
85 nonbond.iNBtype = imatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
86 nonbond.ipif = imatrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
87 nonbond.vrad = matrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
88 nonbond.veps = matrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
89 nonbond.vrad14 = matrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
90 nonbond.veps14 = matrix(0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
91
92 max_torsions();
93 ntor = torsions.ntor;
94 if (ntor > 0)
95 {
96 torsions.i14 = imatrix(0,ntor,0,4);
97 torsions.v1 = vector(0,ntor);
98 torsions.v2 = vector(0,ntor);
99 torsions.v3 = vector(0,ntor);
100 torsions.v4 = vector(0,ntor);
101 torsions.v5 = vector(0,ntor);
102 torsions.v6 = vector(0,ntor);
103 torsions.ph1 = ivector(0,ntor);
104 torsions.ph2 = ivector(0,ntor);
105 torsions.ph3 = ivector(0,ntor);
106 torsions.ph4 = ivector(0,ntor);
107 torsions.ph5 = ivector(0,ntor);
108 torsions.ph6 = ivector(0,ntor);
109 for (i=0; i < ntor; i++)
110 {
111 torsions.v1[i] = 0.0;
112 torsions.v2[i] = 0.0;
113 torsions.v3[i] = 0.0;
114 torsions.v4[i] = 0.0;
115 torsions.v5[i] = 0.0;
116 torsions.v6[i] = 0.0;
117 torsions.ph1[i] = 0;
118 torsions.ph2[i] = 0;
119 torsions.ph3[i] = 0;
120 torsions.ph4[i] = 0;
121 torsions.ph5[i] = 0;
122 torsions.ph6[i] = 0;
123 }
124 }
125 hess.hessx = matrix(0,natom+1, 0,3);
126 hess.hessy = matrix(0,natom+1, 0,3);
127 hess.hessz = matrix(0,natom+1, 0,3);
128
129 rings.r13 = imatrix(0,natom+1, 0,3);
130 rings.r14 = imatrix(0,natom+1, 0,4);
131 rings.r15 = imatrix(0,natom+1, 0,5);
132 rings.r16 = imatrix(0,natom+1, 0,6);
133
134 attached.n13 = ivector(0,natom+1);
135 attached.n14 = ivector(0,natom+1);
136 attached.i13 = imatrix(0, 20, 0,natom+1);
137 attached.i14 = imatrix(0,144, 0,natom+1);
138
139 for(i=0; i <= natom; i++)
140 {
141 for (j=0; j < 3; j++)
142 {
143 deriv.d1[i][j] = 0.0;
144 deriv.deb[i][j] = 0.0;
145 deriv.dea[i][j] = 0.0;
146 deriv.destb[i][j] = 0.0;
147 deriv.deopb[i][j] = 0.0;
148 deriv.detor[i][j] = 0.0;
149 deriv.de14[i][j] = 0.0;
150 deriv.devdw[i][j] = 0.0;
151 deriv.deqq[i][j] = 0.0;
152 deriv.deaa[i][j] = 0.0;
153 deriv.destor[i][j] = 0.0;
154 deriv.dehb[i][j] = 0.0;
155 deriv.deimprop[i][j] = 0.0;
156 deriv.deub[i][j] = 0.0;
157
158 hess.hessx[i][j] = 0.0;
159 hess.hessy[i][j] = 0.0;
160 hess.hessz[i][j] = 0.0;
161 }
162 }
163 if (pot.use_solv)
164 {
165 solvent.asolv = dvector(0,natom+1);
166 solvent.rsolv = dvector(0,natom+1);
167 solvent.rborn = dvector(0,natom+1);
168 if (solvent.type == STILL)
169 {
170 solvent.vsolv = dvector(0,natom+1);
171 solvent.gpol = dvector(0,natom+1);
172 } else if (solvent.type == HCT)
173 {
174 solvent.shct = dvector(0,natom+1);
175 }
176 }
177 }
178
179 void free_memory()
180 {
181 int ntor;
182 free_ivector(skip, 0, natom+1);
183 free_dmatrix(deriv.d1, 0,natom+1, 0,3);
184 free_dmatrix(deriv.deb, 0,natom+1, 0,3);
185 free_dmatrix(deriv.dea, 0,natom+1, 0,3);
186 free_dmatrix(deriv.destb, 0,natom+1, 0,3);
187 free_dmatrix(deriv.deopb, 0,natom+1, 0,3);
188 free_dmatrix(deriv.detor, 0,natom+1, 0,3);
189 free_dmatrix(deriv.de14, 0,natom+1, 0,3);
190 free_dmatrix(deriv.devdw, 0,natom+1, 0,3);
191 free_dmatrix(deriv.deqq, 0,natom+1, 0,3);
192 free_dmatrix(deriv.deaa, 0,natom+1, 0,3);
193 free_dmatrix(deriv.destor, 0,natom+1, 0,3);
194 free_dmatrix(deriv.dehb, 0,natom+1, 0,3);
195 free_dmatrix(deriv.deimprop,0,natom+1, 0,3);
196 free_dmatrix(deriv.deub, 0,natom+1, 0,3);
197 free_dmatrix(deriv.desolv ,0,natom+1, 0,3);
198 free_dmatrix(deriv.degeom ,0,natom+1, 0,3);
199 free_dvector(deriv.drb ,0,natom+1);
200
201 free_imatrix(nonbond.iNBtype ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
202 free_imatrix(nonbond.ipif ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
203 free_matrix(nonbond.vrad ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
204 free_matrix(nonbond.veps ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
205 free_matrix(nonbond.vrad14 ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
206 free_matrix(nonbond.veps14 ,0,nonbond.maxnbtype+1, 0,nonbond.maxnbtype+1);
207
208 // ntor = 9*natom;
209 ntor = torsions.ntor;
210 if (ntor > 0)
211 {
212 free_imatrix(torsions.i14 ,0,ntor,0,4);
213 free_vector(torsions.v1 ,0,ntor);
214 free_vector(torsions.v2 ,0,ntor);
215 free_vector(torsions.v3 ,0,ntor);
216 free_vector(torsions.v4 ,0,ntor);
217 free_vector(torsions.v5 ,0,ntor);
218 free_vector(torsions.v6 ,0,ntor);
219 free_ivector(torsions.ph1 ,0,ntor);
220 free_ivector(torsions.ph2 ,0,ntor);
221 free_ivector(torsions.ph3 ,0,ntor);
222 free_ivector(torsions.ph4 ,0,ntor);
223 free_ivector(torsions.ph5 ,0,ntor);
224 free_ivector(torsions.ph6 ,0,ntor);
225 }
226
227 free_matrix(hess.hessx, 0,natom+1, 0,3);
228 free_matrix(hess.hessy, 0,natom+1, 0,3);
229 free_matrix(hess.hessz, 0,natom+1, 0,3);
230
231 free_imatrix(rings.r13, 0,natom+1, 0,3);
232 free_imatrix(rings.r14, 0,natom+1, 0,4);
233 free_imatrix(rings.r15, 0,natom+1, 0,5);
234 free_imatrix(rings.r16, 0,natom+1, 0,6);
235 free_ivector(attached.n13 ,0,natom+1);
236 free_ivector(attached.n14 ,0,natom+1);
237 free_imatrix(attached.i13 ,0, 20, 0,natom+1);
238 free_imatrix(attached.i14 ,0,144, 0,natom+1);
239
240 if (pot.use_solv)
241 {
242 free_dvector(solvent.asolv ,0,natom+1);
243 free_dvector(solvent.rsolv ,0,natom+1);
244 free_dvector(solvent.rborn ,0,natom+1);
245 if (solvent.type == STILL)
246 {
247 free_dvector(solvent.vsolv ,0,natom+1);
248 free_dvector(solvent.gpol ,0,natom+1);
249 } else if (solvent.type == HCT)
250 {
251 free_dvector(solvent.shct ,0,natom+1);
252 }
253 }
254 }
255