ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/smi23d/src/mengine/torsions.c
Revision: 3
Committed: Mon Jun 9 21:38:26 2008 UTC (11 years, 4 months ago) by tjod
File size: 9057 byte(s)
Log Message:
test

Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "pcmod.h"
5 #include "torsions.h"
6
7 int isbond(int, int);
8 int isangle(int,int);
9 int istorsion(int, int);
10 void get_torsions(void);
11 void message_alert(char *, char *);
12 int is_metal(char *);
13 int is_linear(int);
14
15 struct t_allene {
16 int nallene, ntor[10];
17 } allene;
18 EXTERN struct t_minim_control {
19 int type, method, field, added_const;
20 char added_path[256],added_name[256];
21 } minim_control;
22
23 int is_allene(int i, int j, int k, int l)
24 {
25 if (atom[i].mmx_type == 2 && atom[j].mmx_type == 4 && atom[k].mmx_type == 2)
26 return FALSE;
27 if (atom[j].mmx_type == 2 && atom[k].mmx_type == 4 && atom[l].mmx_type == 2)
28 return FALSE;
29 return TRUE;
30 }
31 // ==================================================
32 int is_linear(int ia)
33 {
34 if (atom[ia].mmx_type == 4 || atom[ia].mmx_type == 10)
35 return TRUE;
36 if (atom[ia].mmff_type == 53)
37 return TRUE;
38 return FALSE;
39 }
40 // ==================================
41 int istorsion(int ia1, int ia2)
42 {
43 int i;
44
45 for (i=0; i < torsions.ntor; i++)
46 {
47 if (torsions.i14[i][0] == ia1 && torsions.i14[i][3] == ia2)
48 return TRUE;
49 if (torsions.i14[i][0] == ia2 && torsions.i14[i][3] == ia1)
50 return TRUE;
51 }
52 return FALSE;
53 }
54 // ==================================
55 void get_torsions()
56 {
57 int i, j, k, l,m;
58 int ia1, ia2, nRc;
59 int katm, latm;
60
61 torsions.ntor = 0;
62 allene.nallene = 0;
63 for (i=1; i <=natom; i++)
64 {
65 ia1 = i;
66 for(j=0; j< MAXIAT; j++)
67 {
68 if (atom[i].iat[j] != 0 && isbond(i,atom[i].iat[j]) && atom[atom[i].iat[j]].type < 300 )
69 {
70 ia2 = atom[i].iat[j];
71 if (is_linear(ia2) == FALSE)
72 {
73 for(k=0; k<MAXIAT; k++)
74 {
75 if (atom[ia2].iat[k] != 0 && isbond(atom[i].iat[j],atom[atom[i].iat[j]].iat[k]) && atom[atom[i].iat[j]].type < 300 )
76 {
77 katm = atom[atom[i].iat[j]].iat[k];
78 if (isbond(ia2,katm) && atom[katm].type < 300 )
79 {
80 if (i != katm)
81 {
82 for(l=0; l<MAXIAT; l++)
83 {
84 if (isbond(katm,atom[katm].iat[l]) && !is_linear(katm) )
85 {
86 latm = atom[katm].iat[l];
87 nRc = is_allene(i,atom[i].iat[j],katm,latm);
88 if ( (latm != atom[i].iat[j]) && (latm >i) && nRc)
89 {
90 torsions.i14[torsions.ntor][0] = i;
91 torsions.i14[torsions.ntor][1] = atom[i].iat[j];
92 torsions.i14[torsions.ntor][2] = katm;
93 torsions.i14[torsions.ntor][3] = latm;
94 torsions.ntor++;
95 if (torsions.ntor > MAXTOR)
96 {
97 message_alert("Too many torsions. PCMODEL will now exit","Torsion Setup");
98 fprintf(pcmoutfile,"Too many torsions in torsion setup.\n");
99 exit(0);
100 }
101 }
102 }
103 }
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111 }
112 // look for allenes
113 for (i=1; i <= natom; i++)
114 {
115 if (atom[i].mmx_type == 4)
116 {
117 if (atom[i].bo[0] == 2 && atom[i].bo[1] == 2) // got an cummulene
118 {
119 if (atom[atom[i].iat[0]].mmx_type == 2 && atom[atom[i].iat[1]].mmx_type == 2) // got an allene
120 {
121 katm = atom[i].iat[0];
122 latm = atom[i].iat[1];
123 if (atom[katm].iat[0] == i)
124 {
125 j = atom[katm].iat[1];
126 k = atom[katm].iat[2];
127 }else if (atom[katm].iat[1] == i)
128 {
129 j = atom[katm].iat[0];
130 k = atom[katm].iat[2];
131 }else if (atom[katm].iat[2] == i)
132 {
133 j = atom[katm].iat[1];
134 k = atom[katm].iat[2];
135 }
136
137 if (atom[latm].iat[0] == i)
138 {
139 l = atom[latm].iat[1];
140 m = atom[latm].iat[2];
141 }else if (atom[katm].iat[1] == i)
142 {
143 l = atom[latm].iat[0];
144 m = atom[latm].iat[2];
145 }else if (atom[katm].iat[2] == i)
146 {
147 l = atom[latm].iat[1];
148 m = atom[latm].iat[2];
149 }
150 torsions.i14[torsions.ntor][0] = j;
151 torsions.i14[torsions.ntor][1] = katm;
152 torsions.i14[torsions.ntor][2] = latm;
153 torsions.i14[torsions.ntor][3] = l;
154 allene.ntor[allene.nallene] = torsions.ntor;
155 allene.nallene++;
156 torsions.ntor++;
157
158 torsions.i14[torsions.ntor][0] = j;
159 torsions.i14[torsions.ntor][1] = katm;
160 torsions.i14[torsions.ntor][2] = latm;
161 torsions.i14[torsions.ntor][3] = m;
162 allene.ntor[allene.nallene] = torsions.ntor;
163 allene.nallene++;
164 torsions.ntor++;
165
166 torsions.i14[torsions.ntor][0] = k;
167 torsions.i14[torsions.ntor][1] = katm;
168 torsions.i14[torsions.ntor][2] = latm;
169 torsions.i14[torsions.ntor][3] = l;
170 allene.ntor[allene.nallene] = torsions.ntor;
171 allene.nallene++;
172 torsions.ntor++;
173
174 torsions.i14[torsions.ntor][0] = k;
175 torsions.i14[torsions.ntor][1] = katm;
176 torsions.i14[torsions.ntor][2] = latm;
177 torsions.i14[torsions.ntor][3] = m;
178 allene.ntor[allene.nallene] = torsions.ntor;
179 allene.nallene++;
180 torsions.ntor++;
181 if (torsions.ntor > MAXTOR)
182 {
183 message_alert("Too many allene torsions. PCMODEL will now exit","Torsion Setup");
184 fprintf(pcmoutfile,"Too many allene torsions in torsion setup.\n");
185 }
186 if (allene.nallene > 10)
187 {
188 message_alert("Too many allene torsions. PCMODEL will now exit","Torsion Setup");
189 fprintf(pcmoutfile,"Too many allene torsions in torsion setup.\n");
190 }
191 }
192 }
193 }
194 }
195 }
196 // ======================================================================
197 void max_torsions()
198 {
199 int i, j, k, l;
200 int ia1, ia2;
201 int katm, latm;
202
203 torsions.ntor = 0;
204 for (i=1; i <=natom; i++)
205 {
206 ia1 = i;
207 for(j=0; j< MAXIAT; j++)
208 {
209 if (isbond(i,atom[i].iat[j]) )
210 {
211 ia2 = atom[i].iat[j];
212 for(k=0; k<MAXIAT; k++)
213 {
214 if (isbond(atom[i].iat[j],atom[atom[i].iat[j]].iat[k]) )
215 {
216 katm = atom[atom[i].iat[j]].iat[k];
217 if (i != katm)
218 {
219 for(l=0; l<MAXIAT; l++)
220 {
221 if (isbond(katm,atom[katm].iat[l]) )
222 {
223 latm = atom[katm].iat[l];
224 if ( (latm != atom[i].iat[j]) && (latm >i) )
225 {
226 torsions.ntor++;
227 }
228 }
229 }
230 }
231 }
232 }
233 }
234 }
235 }
236 // find allenes
237 for (i=0; i <= natom; i++)
238 {
239 if (atom[i].mmx_type == 4)
240 {
241 if (atom[i].bo[0] == 2 && atom[i].bo[1] == 2)
242 {
243 if (atom[atom[i].iat[0]].mmx_type == 2 && atom[atom[i].iat[1]].mmx_type == 2)
244 {
245 torsions.ntor += 4;
246 }
247 }
248 }
249 }
250 }