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