ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/draw.c
Revision: 110
Committed: Thu Mar 12 01:43:50 2009 UTC (12 years, 7 months ago) by gilbertke
File size: 10211 byte(s)
Log Message:
further cleanup and localization of atom data
Line User Rev File contents
1 tjod 3 #define EXTERN extern
2     #include "pcwin.h"
3     #include "pcmod.h"
4     #include "atom_k.h"
5 gilbertke 63 #include "draw.h"
6 tjod 3
7     EXTERN struct t_minim_values {
8     int iprint, ndc, nconst;
9     float dielc;
10     } minim_values;
11     EXTERN struct t_minim_control {
12     int type, method, field, added_const;
13     char added_path[256],added_name[256];
14     } minim_control;
15    
16     EXTERN struct {
17 gilbertke 97 int mm3, mmff, amber, opls;
18 tjod 3 } AtomTypes[];
19    
20     EXTERN struct ElementType { char symbol[3];
21     int atomnum;
22     float weight, covradius, vdwradius;
23     int s,p,d,f, type;
24     } Elements[];
25    
26 gilbertke 63 EXTERN int mm3_mmx[], mmff_mmx[];
27 gilbertke 103
28     int get_field(void);
29 gilbertke 110 int get_hydrid(int);
30     int is_bond(int,int);
31    
32 tjod 3 // ===============================================
33 gilbertke 97 void set_atomdata(int ia, int mmxtype, int mm3type, int mmfftype)
34 tjod 3 {
35 gilbertke 103 int type,field;
36 tjod 3
37     if (mmxtype > 0)
38 gilbertke 103 atom.mmx_type[ia] = mmxtype;
39 tjod 3 if (mm3type > 0)
40 gilbertke 103 atom.mm3_type[ia] = mm3type;
41 tjod 3 if (mmfftype > 0)
42 gilbertke 103 atom.mmff_type[ia] = mmfftype;
43     field = get_field();
44    
45     if (field == MMX || field == MM2)
46 tjod 3 {
47     type = mmxtype;
48 gilbertke 103 } else if (field == MM3)
49 tjod 3 {
50     type = mm3type;
51 gilbertke 103 } else if (field == MMFF94)
52 tjod 3 {
53     type = mmfftype;
54     }
55     if ( type < 300)
56     {
57 gilbertke 103 atom.tclass[ia] = atom_k.tclass[type];
58     atom.atomnum[ia] = atom_k.number[type];
59     atom.atomwt[ia] = atom_k.weight[type];
60     strcpy(atom.name[ia], atom_k.symbol[type]);
61 wdelano 58 }
62 tjod 3 }
63     // ===============================================
64 gilbertke 97 void set_atomtype(int ia, int mmxtype, int mm3type, int mmfftype)
65 tjod 3 {
66     if (mmxtype > 0)
67 gilbertke 103 atom.mmx_type[ia] = mmxtype;
68 tjod 3 if (mm3type > 0)
69 gilbertke 103 atom.mm3_type[ia] = mm3type;
70 tjod 3 if (mmfftype > 0)
71 gilbertke 103 atom.mmff_type[ia] = mmfftype;
72 tjod 3 }
73     // ======================================================
74     int make_atom(int type, float x, float y, float z,char *name)
75     {
76 gilbertke 103 int i,iz,field;
77 gilbertke 97 int mmxtype, mm3type, mmfftype;
78 tjod 3
79     natom++;
80 gilbertke 105 if (natom >= MAXATOM)
81 tjod 3 {
82     natom--;
83     message_alert("Max atoms exceeded in makeatom","PCMODEL Error");
84     return -1;
85     }
86 gilbertke 103 field = get_field();
87 tjod 3 iz = strlen(name);
88     if (iz > 0) // got an atom name use it
89     {
90     for (i=1; i <= atom_k.natomtype; i++)
91     {
92     if (strcmp(name,atom_k.symbol[i]) == 0) // names match
93     {
94 gilbertke 103 strcpy(atom.name[natom],name);
95     atom.tclass[natom] = atom_k.tclass[i];
96     atom.atomwt[natom] = atom_k.weight[i];
97     atom.atomnum[natom] = atom_k.number[i];
98     atom.type[natom] = atom_k.type[i];
99 tjod 3 if (type == 0)
100     {
101 gilbertke 103 type = atom.type[natom]; // this is an mmff type
102 tjod 3 mmxtype = mmff_mmxtype(type);
103     mm3type = 0;
104     mmfftype = type;
105 gilbertke 97 set_atomtype(natom,mmxtype,mm3type,mmfftype);
106 tjod 3 if (mmfftype == 0) return -1;
107 gilbertke 103 } else if (field == MMX || field == MM2)
108 tjod 3 {
109 gilbertke 103 atom.mmx_type[natom] = type;
110 tjod 3 mmxtype = type;
111     mm3type = AtomTypes[type-1].mm3;
112     mmfftype = AtomTypes[type-1].mmff;
113 gilbertke 97 set_atomtype(natom,mmxtype,mm3type,mmfftype);
114 gilbertke 103 } else if (field == MM3)
115 tjod 3 {
116 gilbertke 103 atom.mm3_type[natom] = type;
117 tjod 3 mmxtype = mm3_mmxtype(type);
118     mm3type = type;
119     mmfftype = AtomTypes[mmxtype-1].mmff;
120 gilbertke 97 set_atomtype(natom,mmxtype,mm3type,mmfftype);
121 gilbertke 103 } else if (field == MMFF94)
122 tjod 3 {
123 gilbertke 103 atom.mmff_type[natom] = type;
124 tjod 3 mmxtype = mmff_mmxtype(type);
125     mm3type = AtomTypes[mmxtype-1].mm3;
126     mmfftype = type;
127 gilbertke 97 set_atomtype(natom,mmxtype,mm3type,mmfftype);
128 tjod 3 }
129    
130 gilbertke 103 atom.x[natom] = x; atom.y[natom] = y; atom.z[natom] = z;
131     atom.flags[natom] = 0;
132 tjod 3 return natom;
133     }
134     }
135     for( i = 0; i < 103; i++ )
136     {
137     if( strcasecmp(Elements[i].symbol,name) == 0 )
138     {
139 gilbertke 103 strcpy(atom.name[natom],Elements[i].symbol);
140     atom.atomwt[natom] = Elements[i].weight;
141     atom.atomnum[natom] = Elements[i].atomnum;
142     atom.type[natom] = Elements[i].type; // set generic type
143     atom.tclass[natom] = Elements[i].type; // set generic type
144     atom.mmx_type[natom] = Elements[i].type; // set generic type
145 tjod 3 if (type > 0)
146     {
147 gilbertke 103 atom.type[natom] = type; // overwrite type if type is passed in
148     if (field == MMX || field == MM2)
149     atom.mmx_type[natom] = type;
150     else if (field == MM3)
151     atom.mm3_type[natom] = type;
152     else if (field == MMFF94)
153     atom.mmff_type[natom] = type;
154 tjod 3 }
155 gilbertke 103 if (type != 0) atom.type[natom] = type;
156     atom.x[natom] = x; atom.y[natom] = y; atom.z[natom] = z;
157 tjod 3 if (type > 299)
158     return -1;
159 gilbertke 103 else if (atom.mmff_type[natom] == 0)
160 tjod 3 return -1;
161     else
162     return natom;
163     }
164     }
165     } else
166     {
167     message_alert("Input atom does not have valid atomic symbol or atom type","Error");
168     return -1;
169     }
170     return -1;
171     }
172     // ====================================================
173     void make_bond(int ia1, int ia2, int bo)
174     {
175     int loop,loop1;
176    
177     if (ia1 < 1 || ia1 > MAXATOM) return;
178     if (ia2 < 1 || ia2 > MAXATOM) return;
179     /* find if bond exists */
180     for (loop = 0; loop < MAXIAT; loop++)
181     {
182 gilbertke 103 if (atom.iat[ia1][loop] == ia2)
183 tjod 3 {
184     if (bo == 1)
185 gilbertke 103 atom.bo[ia1][loop] += bo;
186 tjod 3 else
187 gilbertke 103 atom.bo[ia1][loop] = bo;
188 tjod 3
189     for (loop1 = 0; loop1 < MAXIAT; loop1++)
190     {
191 gilbertke 103 if (atom.iat[ia2][loop1] == ia1)
192 tjod 3 {
193     if ( bo == 1)
194     {
195 gilbertke 103 atom.bo[ia2][loop1] += bo; /* bond exists return */
196 tjod 3 return;
197     } else
198     {
199 gilbertke 103 atom.bo[ia2][loop1] = bo; /* bond exists return */
200 tjod 3 return;
201     }
202     }
203     }
204     }
205     }
206     /* bond does not exist create it */
207     for (loop = 0; loop < MAXIAT; loop++)
208     {
209 gilbertke 103 if (atom.iat[ia1][loop] == 0)
210 tjod 3 {
211 gilbertke 103 atom.iat[ia1][loop] = ia2;
212     atom.bo[ia1][loop] = bo;
213 tjod 3 break;
214     }
215     }
216     for (loop = 0; loop < MAXIAT; loop++)
217     {
218 gilbertke 103 if (atom.iat[ia2][loop] == 0)
219 tjod 3 {
220 gilbertke 103 atom.iat[ia2][loop] = ia1;
221     atom.bo[ia2][loop] = bo;
222 tjod 3 break;
223     }
224     }
225     }
226     // ===============================================
227     void deleteatom(int i)
228     {
229     int j,k, ibo;
230 gilbertke 103 atom.type[i] = 0;
231     atom.x[i] = 0.0F;
232     atom.y[i] = 0.0F;
233     atom.z[i] = 0.0F;
234     atom.flags[i] = 0;
235 tjod 3 for (j=0; j<MAXIAT; j++)
236     {
237 gilbertke 103 if (atom.iat[i][j] != 0 )
238 tjod 3 {
239 gilbertke 103 if (atom.atomnum[atom.iat[i][j]] == 1 || atom.atomnum[atom.iat[i][j]] == 0 )
240 tjod 3 {
241 gilbertke 103 atom.type[atom.iat[i][j]] = 0;
242     atom.x[atom.iat[i][j]] = 0.0F;
243     atom.y[atom.iat[i][j]] = 0.0F;
244     atom.z[atom.iat[i][j]] = 0.0F;
245     atom.flags[atom.iat[i][j]] = 0;
246 tjod 3 }
247 gilbertke 103 ibo = atom.bo[i][j];
248 tjod 3 for (k=1; k <= ibo; k++)
249 gilbertke 103 deletebond(i,atom.iat[i][j]);
250     atom.iat[i][j] = 0;
251 tjod 3 }
252     }
253     natom--;
254     }
255     // ==================================================
256     void deletebond(int i, int j)
257     {
258     int i1,j1;
259     for (i1=0; i1 < MAXIAT; i1++)
260     {
261 gilbertke 103 if (atom.iat[i][i1] == j)
262 tjod 3 {
263 gilbertke 103 if (atom.bo[i][i1] == 9) /* if deleting a coordinated bond - delete it completely */
264 tjod 3 {
265 gilbertke 103 atom.bo[i][i1] = 0;
266     atom.iat[i][i1] = 0;
267 tjod 3 }
268 gilbertke 103 atom.bo[i][i1] -= 1;
269     if (atom.bo[i][i1] <= 0 )
270     atom.iat[i][i1] = 0;
271 tjod 3 break;
272     }
273     }
274     for (j1=0; j1 < MAXIAT; j1++)
275     {
276 gilbertke 103 if (atom.iat[j][j1] == i)
277 tjod 3 {
278 gilbertke 103 if (atom.bo[j][j1] == 9) /* if deleting a coordinated bond - delete it completely */
279 tjod 3 {
280 gilbertke 103 atom.bo[j][j1] = 0;
281     atom.iat[j][j1] = 0;
282 tjod 3 }
283 gilbertke 103 atom.bo[j][j1] -= 1;
284     if (atom.bo[j][j1] <= 0)
285     atom.iat[j][j1] = 0;
286 tjod 3 break;
287     }
288     }
289     }
290 gilbertke 63 // ========================================================
291     int mm3_mmxtype(int mm3type)
292     {
293     int i;
294    
295     if (mm3type < 153)
296     i = mm3_mmx[mm3type-1];
297     else if (mm3type == 200)
298     i = 60;
299     else
300     i = mm3type;
301     return(i);
302     }
303     // ==================================================
304     int mmff_mmxtype(int mmfftype)
305     {
306     int i;
307     if (mmfftype < 100)
308     i = mmff_mmx[mmfftype-1];
309     else
310     i = mmfftype;
311     return(i);
312     }
313 gilbertke 110 /* =============================================== */
314     // get hybridization of atom - tetrahedral = 1, planar = 2, linear = 3
315     //
316     int get_hybrid(int ia)
317     {
318     int itype;
319    
320     itype = atom.mmx_type[ia];
321     if (itype == 2 || itype == 3 || itype == 7 || itype == 9 || itype == 25 ||
322     itype == 26 || itype == 29 || itype == 30 || itype == 37 || itype == 38 ||
323     itype == 40 || itype == 57 )
324     return 2;
325     else if (itype == 4 || itype == 10)
326     return 3;
327     else
328     return 1;
329     }
330     /* ------------------------------------*/
331     int is_bond(int ia, int ib)
332     {
333     int i;
334     for (i=0; i < MAXIAT; i++)
335     {
336     if (atom.iat[ia][i] == ib)
337     return TRUE;
338     }
339     return FALSE;
340     }