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