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, 3 months ago) by gilbertke
File size: 10211 byte(s)
Log Message:
further cleanup and localization of atom data
Line File contents
1 #define EXTERN extern
2 #include "pcwin.h"
3 #include "pcmod.h"
4 #include "atom_k.h"
5 #include "draw.h"
6
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 int mm3, mmff, amber, opls;
18 } 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 EXTERN int mm3_mmx[], mmff_mmx[];
27
28 int get_field(void);
29 int get_hydrid(int);
30 int is_bond(int,int);
31
32 // ===============================================
33 void set_atomdata(int ia, int mmxtype, int mm3type, int mmfftype)
34 {
35 int type,field;
36
37 if (mmxtype > 0)
38 atom.mmx_type[ia] = mmxtype;
39 if (mm3type > 0)
40 atom.mm3_type[ia] = mm3type;
41 if (mmfftype > 0)
42 atom.mmff_type[ia] = mmfftype;
43 field = get_field();
44
45 if (field == MMX || field == MM2)
46 {
47 type = mmxtype;
48 } else if (field == MM3)
49 {
50 type = mm3type;
51 } else if (field == MMFF94)
52 {
53 type = mmfftype;
54 }
55 if ( type < 300)
56 {
57 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 }
62 }
63 // ===============================================
64 void set_atomtype(int ia, int mmxtype, int mm3type, int mmfftype)
65 {
66 if (mmxtype > 0)
67 atom.mmx_type[ia] = mmxtype;
68 if (mm3type > 0)
69 atom.mm3_type[ia] = mm3type;
70 if (mmfftype > 0)
71 atom.mmff_type[ia] = mmfftype;
72 }
73 // ======================================================
74 int make_atom(int type, float x, float y, float z,char *name)
75 {
76 int i,iz,field;
77 int mmxtype, mm3type, mmfftype;
78
79 natom++;
80 if (natom >= MAXATOM)
81 {
82 natom--;
83 message_alert("Max atoms exceeded in makeatom","PCMODEL Error");
84 return -1;
85 }
86 field = get_field();
87 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 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 if (type == 0)
100 {
101 type = atom.type[natom]; // this is an mmff type
102 mmxtype = mmff_mmxtype(type);
103 mm3type = 0;
104 mmfftype = type;
105 set_atomtype(natom,mmxtype,mm3type,mmfftype);
106 if (mmfftype == 0) return -1;
107 } else if (field == MMX || field == MM2)
108 {
109 atom.mmx_type[natom] = type;
110 mmxtype = type;
111 mm3type = AtomTypes[type-1].mm3;
112 mmfftype = AtomTypes[type-1].mmff;
113 set_atomtype(natom,mmxtype,mm3type,mmfftype);
114 } else if (field == MM3)
115 {
116 atom.mm3_type[natom] = type;
117 mmxtype = mm3_mmxtype(type);
118 mm3type = type;
119 mmfftype = AtomTypes[mmxtype-1].mmff;
120 set_atomtype(natom,mmxtype,mm3type,mmfftype);
121 } else if (field == MMFF94)
122 {
123 atom.mmff_type[natom] = type;
124 mmxtype = mmff_mmxtype(type);
125 mm3type = AtomTypes[mmxtype-1].mm3;
126 mmfftype = type;
127 set_atomtype(natom,mmxtype,mm3type,mmfftype);
128 }
129
130 atom.x[natom] = x; atom.y[natom] = y; atom.z[natom] = z;
131 atom.flags[natom] = 0;
132 return natom;
133 }
134 }
135 for( i = 0; i < 103; i++ )
136 {
137 if( strcasecmp(Elements[i].symbol,name) == 0 )
138 {
139 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 if (type > 0)
146 {
147 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 }
155 if (type != 0) atom.type[natom] = type;
156 atom.x[natom] = x; atom.y[natom] = y; atom.z[natom] = z;
157 if (type > 299)
158 return -1;
159 else if (atom.mmff_type[natom] == 0)
160 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 if (atom.iat[ia1][loop] == ia2)
183 {
184 if (bo == 1)
185 atom.bo[ia1][loop] += bo;
186 else
187 atom.bo[ia1][loop] = bo;
188
189 for (loop1 = 0; loop1 < MAXIAT; loop1++)
190 {
191 if (atom.iat[ia2][loop1] == ia1)
192 {
193 if ( bo == 1)
194 {
195 atom.bo[ia2][loop1] += bo; /* bond exists return */
196 return;
197 } else
198 {
199 atom.bo[ia2][loop1] = bo; /* bond exists return */
200 return;
201 }
202 }
203 }
204 }
205 }
206 /* bond does not exist create it */
207 for (loop = 0; loop < MAXIAT; loop++)
208 {
209 if (atom.iat[ia1][loop] == 0)
210 {
211 atom.iat[ia1][loop] = ia2;
212 atom.bo[ia1][loop] = bo;
213 break;
214 }
215 }
216 for (loop = 0; loop < MAXIAT; loop++)
217 {
218 if (atom.iat[ia2][loop] == 0)
219 {
220 atom.iat[ia2][loop] = ia1;
221 atom.bo[ia2][loop] = bo;
222 break;
223 }
224 }
225 }
226 // ===============================================
227 void deleteatom(int i)
228 {
229 int j,k, ibo;
230 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 for (j=0; j<MAXIAT; j++)
236 {
237 if (atom.iat[i][j] != 0 )
238 {
239 if (atom.atomnum[atom.iat[i][j]] == 1 || atom.atomnum[atom.iat[i][j]] == 0 )
240 {
241 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 }
247 ibo = atom.bo[i][j];
248 for (k=1; k <= ibo; k++)
249 deletebond(i,atom.iat[i][j]);
250 atom.iat[i][j] = 0;
251 }
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 if (atom.iat[i][i1] == j)
262 {
263 if (atom.bo[i][i1] == 9) /* if deleting a coordinated bond - delete it completely */
264 {
265 atom.bo[i][i1] = 0;
266 atom.iat[i][i1] = 0;
267 }
268 atom.bo[i][i1] -= 1;
269 if (atom.bo[i][i1] <= 0 )
270 atom.iat[i][i1] = 0;
271 break;
272 }
273 }
274 for (j1=0; j1 < MAXIAT; j1++)
275 {
276 if (atom.iat[j][j1] == i)
277 {
278 if (atom.bo[j][j1] == 9) /* if deleting a coordinated bond - delete it completely */
279 {
280 atom.bo[j][j1] = 0;
281 atom.iat[j][j1] = 0;
282 }
283 atom.bo[j][j1] -= 1;
284 if (atom.bo[j][j1] <= 0)
285 atom.iat[j][j1] = 0;
286 break;
287 }
288 }
289 }
290 // ========================================================
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 /* =============================================== */
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 }