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