ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/draw.c
Revision: 58
Committed: Mon Dec 1 06:44:59 2008 UTC (13 years, 6 months ago) by wdelano
File size: 12107 byte(s)
Log Message:
code merge 20081130
Line File contents
1 #define EXTERN extern
2 #include "pcwin.h"
3 #include "pcmod.h"
4 #include "field.h"
5 #include "atom_k.h"
6 #include "pot.h"
7 #include "energies.h"
8 #include "solv.h"
9
10 EXTERN struct t_minim_values {
11 int iprint, ndc, nconst;
12 float dielc;
13 } minim_values;
14 EXTERN struct t_units {
15 double bndunit, cbnd, qbnd;
16 double angunit, cang, qang, pang, sang, aaunit;
17 double stbnunit, ureyunit, torsunit, storunit, v14scale;
18 double aterm, bterm, cterm, dielec, chgscale;
19 } units;
20 EXTERN struct t_minim_control {
21 int type, method, field, added_const;
22 char added_path[256],added_name[256];
23 } minim_control;
24 EXTERN struct t_dipolemom {
25 double total, xdipole, ydipole, zdipole;
26 } dipolemom;
27 EXTERN struct t_vdw1 {
28 int nvdw;
29 float rad[MAXVDWCONST], eps[MAXVDWCONST];
30 int lpd[MAXVDWCONST], ihtyp[MAXVDWCONST], ihdon[MAXVDWCONST];
31 float alpha[MAXVDWCONST],n[MAXVDWCONST],a[MAXVDWCONST],g[MAXVDWCONST];
32 char da[MAXVDWCONST][2];
33 } vdw1;
34
35 EXTERN struct {
36 int mm3, mmff, amber, opls;
37 } AtomTypes[];
38
39 EXTERN struct ElementType { char symbol[3];
40 int atomnum;
41 float weight, covradius, vdwradius;
42 int s,p,d,f, type;
43 } Elements[];
44
45 EXTERN struct t_centroid {
46 int ncentroid, numsel[10];
47 int isel[10][10];
48 double x[10], y[10], z[10];
49 } centroid;
50
51 void InitialTransform(void);
52 int make_atom(int , float , float , float,char * );
53 void make_bond(int , int , int );
54 void generate_bonds(void);
55 void deleteatom(int);
56 void deletebond(int, int);
57 void set_atomtype(int,int,int,int,int,int);
58 void set_atomdata(int,int,int,int,int,int);
59 void message_alert(char *, char *);
60 void charge_dipole(void);
61 int isangle(int,int);
62 int mm3_mmxtype(int);
63 int mmff_mmxtype(int);
64
65 // ===============================================
66 void set_atomdata(int ia, int mmxtype, int mm3type, int mmfftype,int ambertype,int oplstype)
67 {
68 int type;
69
70 if (mmxtype > 0)
71 atom[ia].mmx_type = mmxtype;
72 if (mm3type > 0)
73 atom[ia].mm3_type = mm3type;
74 if (mmfftype > 0)
75 atom[ia].mmff_type = mmfftype;
76 if (ambertype > 0)
77 atom[ia].amber_type = ambertype;
78 if (oplstype > 0)
79 atom[ia].opls_type = oplstype;
80
81 if (field.type == MMX || field.type == MM2)
82 {
83 type = mmxtype;
84 } else if (field.type == MM3)
85 {
86 type = mm3type;
87 }else if (field.type == AMBER)
88 {
89 type = ambertype;
90 } else if (field.type == MMFF94)
91 {
92 type = mmfftype;
93 } else if (field.type == OPLSAA)
94 {
95 type = oplstype;
96 }
97
98 if ( type < 300)
99 {
100 atom[ia].tclass = atom_k.tclass[type];
101 atom[ia].atomnum = atom_k.number[type];
102 atom[ia].atomwt = atom_k.weight[type];
103 strcpy(atom[ia].name, atom_k.symbol[type]);
104 }
105 }
106 // ===============================================
107 void set_atomtype(int ia, int mmxtype, int mm3type, int mmfftype,int ambertype,int oplstype)
108 {
109 if (mmxtype > 0)
110 atom[ia].mmx_type = mmxtype;
111 if (mm3type > 0)
112 atom[ia].mm3_type = mm3type;
113 if (mmfftype > 0)
114 atom[ia].mmff_type = mmfftype;
115 if (ambertype > 0)
116 atom[ia].amber_type = ambertype;
117 if (oplstype > 0)
118 atom[ia].opls_type = oplstype;
119
120 }
121 // ======================================================
122 int make_atom(int type, float x, float y, float z,char *name)
123 {
124 int i,iz;
125 int mmxtype, mm3type, mmfftype,ambertype,oplstype;
126
127 natom++;
128 if (natom >= MAXATOM - 10)
129 {
130 natom--;
131 message_alert("Max atoms exceeded in makeatom","PCMODEL Error");
132 return -1;
133 }
134 iz = strlen(name);
135 if (iz > 0) // got an atom name use it
136 {
137 for (i=1; i <= atom_k.natomtype; i++)
138 {
139 if (strcmp(name,atom_k.symbol[i]) == 0) // names match
140 {
141 strcpy(atom[natom].name,name);
142 atom[natom].tclass = atom_k.tclass[i];
143 atom[natom].atomwt = atom_k.weight[i];
144 atom[natom].atomnum = atom_k.number[i];
145 atom[natom].type = atom_k.type[i];
146 if (type == 0)
147 {
148 type = atom[natom].type; // this is an mmff type
149 mmxtype = mmff_mmxtype(type);
150 mm3type = 0;
151 mmfftype = type;
152 ambertype = 0;
153 oplstype = 0;
154 set_atomtype(natom,mmxtype,mm3type,mmfftype,ambertype,oplstype);
155 if (mmfftype == 0) return -1;
156 } else if (field.type == MMX || field.type == MM2)
157 {
158 atom[natom].mmx_type = type;
159 mmxtype = type;
160 mm3type = AtomTypes[type-1].mm3;
161 mmfftype = AtomTypes[type-1].mmff;
162 ambertype = AtomTypes[type-1].amber;
163 oplstype = AtomTypes[type-1].opls;
164 set_atomtype(natom,mmxtype,mm3type,mmfftype,ambertype,oplstype);
165 } else if (field.type == MM3)
166 {
167 atom[natom].mm3_type = type;
168 mmxtype = mm3_mmxtype(type);
169 mm3type = type;
170 mmfftype = AtomTypes[mmxtype-1].mmff;
171 ambertype = AtomTypes[mmxtype-1].amber;
172 oplstype = AtomTypes[mmxtype-1].opls;
173 set_atomtype(natom,mmxtype,mm3type,mmfftype,ambertype,oplstype);
174 } else if (field.type == MMFF94)
175 {
176 atom[natom].mmff_type = type;
177 mmxtype = mmff_mmxtype(type);
178 mm3type = AtomTypes[mmxtype-1].mm3;
179 mmfftype = type;
180 ambertype = AtomTypes[mmxtype-1].amber;
181 oplstype = AtomTypes[mmxtype-1].opls;
182 set_atomtype(natom,mmxtype,mm3type,mmfftype,ambertype,oplstype);
183 }
184
185 atom[natom].x = x; atom[natom].y = y; atom[natom].z = z;
186 atom[natom].flags = 0;
187 return natom;
188 }
189 }
190 for( i = 0; i < 103; i++ )
191 {
192 if( strcasecmp(Elements[i].symbol,name) == 0 )
193 {
194 strcpy(atom[natom].name,Elements[i].symbol);
195 atom[natom].atomwt = Elements[i].weight;
196 atom[natom].atomnum = Elements[i].atomnum;
197 atom[natom].type = Elements[i].type; // set generic type
198 atom[natom].tclass = Elements[i].type; // set generic type
199 atom[natom].mmx_type = Elements[i].type; // set generic type
200 if (type > 0)
201 {
202 atom[natom].type = type; // overwrite type if type is passed in
203 if (field.type == MMX || field.type == MM2)
204 atom[natom].mmx_type = type;
205 else if (field.type == MM3)
206 atom[natom].mm3_type = type;
207 else if (field.type == MMFF94)
208 atom[natom].mmff_type = type;
209 else if (field.type == AMBER)
210 atom[natom].amber_type = type;
211 else if (field.type == OPLSAA)
212 atom[natom].opls_type = type;
213 }
214 if (type != 0) atom[natom].type = type;
215 atom[natom].x = x; atom[natom].y = y; atom[natom].z = z;
216 if (type > 299)
217 return -1;
218 else if (atom[natom].mmff_type == 0)
219 return -1;
220 else
221 return natom;
222 }
223 }
224 } else
225 {
226 message_alert("Input atom does not have valid atomic symbol or atom type","Error");
227 return -1;
228 }
229 return -1;
230 }
231 // ====================================================
232 void make_bond(int ia1, int ia2, int bo)
233 {
234 int loop,loop1;
235
236 if (ia1 < 1 || ia1 > MAXATOM) return;
237 if (ia2 < 1 || ia2 > MAXATOM) return;
238 /* find if bond exists */
239 for (loop = 0; loop < MAXIAT; loop++)
240 {
241 if (atom[ia1].iat[loop] == ia2)
242 {
243 if (bo == 1)
244 atom[ia1].bo[loop] += bo;
245 else
246 atom[ia1].bo[loop] = bo;
247
248 for (loop1 = 0; loop1 < MAXIAT; loop1++)
249 {
250 if (atom[ia2].iat[loop1] == ia1)
251 {
252 if ( bo == 1)
253 {
254 atom[ia2].bo[loop1] += bo; /* bond exists return */
255 return;
256 } else
257 {
258 atom[ia2].bo[loop1] = bo; /* bond exists return */
259 return;
260 }
261 }
262 }
263 }
264 }
265 /* bond does not exist create it */
266 for (loop = 0; loop < MAXIAT; loop++)
267 {
268 if (atom[ia1].iat[loop] == 0)
269 {
270 atom[ia1].iat[loop] = ia2;
271 atom[ia1].bo[loop] = bo;
272 break;
273 }
274 }
275 for (loop = 0; loop < MAXIAT; loop++)
276 {
277 if (atom[ia2].iat[loop] == 0)
278 {
279 atom[ia2].iat[loop] = ia1;
280 atom[ia2].bo[loop] = bo;
281 break;
282 }
283 }
284 }
285 // ===============================================
286 void deleteatom(int i)
287 {
288 int j,k, ibo;
289 atom[i].type = 0;
290 atom[i].x = 0.0F;
291 atom[i].y = 0.0F;
292 atom[i].z = 0.0F;
293 atom[i].flags = 0;
294 for (j=0; j<MAXIAT; j++)
295 {
296 if (atom[i].iat[j] != 0 )
297 {
298 if (atom[atom[i].iat[j]].atomnum == 1 || atom[atom[i].iat[j]].atomnum == 0 )
299 {
300 atom[atom[i].iat[j]].type = 0;
301 atom[atom[i].iat[j]].x = 0.0F;
302 atom[atom[i].iat[j]].y = 0.0F;
303 atom[atom[i].iat[j]].z = 0.0F;
304 atom[atom[i].iat[j]].flags = 0;
305 }
306 ibo = atom[i].bo[j];
307 for (k=1; k <= ibo; k++)
308 deletebond(i,atom[i].iat[j]);
309 atom[i].iat[j] = 0;
310 }
311 }
312 natom--;
313 }
314 // ==================================================
315 void deletebond(int i, int j)
316 {
317 int i1,j1;
318 for (i1=0; i1 < MAXIAT; i1++)
319 {
320 if (atom[i].iat[i1] == j)
321 {
322 if (atom[i].bo[i1] == 9) /* if deleting a coordinated bond - delete it completely */
323 {
324 atom[i].bo[i1] = 0;
325 atom[i].iat[i1] = 0;
326 }
327 atom[i].bo[i1] -= 1;
328 if (atom[i].bo[i1] <= 0 )
329 atom[i].iat[i1] = 0;
330 break;
331 }
332 }
333 for (j1=0; j1 < MAXIAT; j1++)
334 {
335 if (atom[j].iat[j1] == i)
336 {
337 if (atom[j].bo[j1] == 9) /* if deleting a coordinated bond - delete it completely */
338 {
339 atom[j].bo[j1] = 0;
340 atom[j].iat[j1] = 0;
341 }
342 atom[j].bo[j1] -= 1;
343 if (atom[j].bo[j1] <= 0)
344 atom[j].iat[j1] = 0;
345 break;
346 }
347 }
348 }
349 /* --------------------------- */
350 void generate_bonds(void)
351 {
352 int i,j;
353
354 bonds.numbonds = 0;
355 for (i= 0; i <= natom; i++)
356 {
357 bonds.ia1[i] = 0;
358 bonds.ia2[i] = 0;
359 bonds.bondorder[i] = 0;
360 }
361
362 for (i = 1; i <= natom; i++)
363 {
364 for (j = 0; j < MAXIAT; j++)
365 {
366 if (atom[i].iat[j] > i && atom[i].iat[j] != 0)
367 {
368 bonds.ia1[bonds.numbonds] = i;
369 bonds.ia2[bonds.numbonds] = atom[i].iat[j];
370 bonds.bondorder[bonds.numbonds] = atom[i].bo[j];
371 bonds.numbonds++;
372 }
373 }
374 }
375 }