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

Line User Rev File contents
1 tjod 3 #define EXTERN extern
2    
3     #include "pcwin.h"
4     #include "pcmod.h"
5     #include "utility.h"
6    
7     void getvec(void);
8     void revec(void);
9     void xaxis(float *, float *, float *);
10     void xyplan(float *, float *, float *);
11     void chain(int,int, int);
12     void message_alert(char *, char *);
13     void epimer(void);
14    
15     void epimer()
16     {
17     int i, ii, izaxis, natm1, natm2, natm3, natm4, natm5;
18     float xa, ya, za, zdif1, zdif2;
19     long int mask;
20    
21     if (selatom[1] == 0 || selatom[2] == 0 || selatom[3] == 0 )
22     {
23     message_alert("You must select three atoms - center and two attachments - for epimer","Epimer Setup");
24     return;
25     }
26     natm1 = selatom[1];
27     natm2 = selatom[2];
28     natm3 = selatom[3];
29    
30     getvec();
31    
32     natm4 = 0;
33     natm5 = 0;
34     for( i = 0; i < MAXIAT; i++ )
35     {
36     if( atom[natm1].iat[i] != 0 && atom[natm1].iat[i] != natm1 &&
37     atom[natm1].iat[i] != natm2 && atom[natm1].iat[i] != natm3 )
38     {
39     if( !natm4 )
40     {
41     natm4 = atom[natm1].iat[i];
42     }
43     else
44     {
45     if( !natm5 )
46     natm5 = atom[natm1].iat[i];
47     }
48     }
49     }
50    
51     xa = atom[natm1].x;
52     ya = atom[natm1].y;
53     za = atom[natm1].z;
54     for( ii = 1; ii <= natom; ii++ )
55     {
56     atom[ii].x -= xa;
57     atom[ii].y -= ya;
58     atom[ii].z -= za;
59     }
60     zdif1 = atom[natm2].z - atom[natm3].z;
61     zdif2 = atom[natm4].z - atom[natm5].z;
62     if( zdif1 < 0.0 )
63     zdif1 = -zdif1;
64     if( zdif2 < 0.0 )
65     zdif2 = -zdif2;
66     izaxis = 0;
67     if( zdif2 < zdif1 )
68     izaxis = 1;
69     if( izaxis )
70     {
71     xa = atom[natm5].x;
72     ya = atom[natm5].y;
73     za = atom[natm5].z;
74     for( ii = 1; ii <= natom; ii++ )
75     {
76     atom[ii].x -= xa;
77     atom[ii].y -= ya;
78     atom[ii].z -= za;
79     }
80     xa = atom[natm4].x;
81     ya = atom[natm4].y;
82     za = atom[natm4].z;
83    
84     /* *** now place these two atoms "natm1, natm4" on x-axis *** */
85     xaxis( &xa, &ya, &za );
86     xa = atom[natm1].x;
87     ya = atom[natm1].y;
88     za = atom[natm1].z;
89     /* *** now place the two atoms "namt1, natm3" on xy-plane *** */
90     xyplan( &xa, &ya, &za );
91     }
92     xa = atom[natm2].x;
93     ya = atom[natm2].y;
94     za = atom[natm2].z;
95     for( ii = 1; ii <= natom; ii++ )
96     {
97     atom[ii].x -= xa;
98     atom[ii].y -= ya;
99     atom[ii].z -= za;
100     }
101     xa = atom[natm3].x;
102     ya = atom[natm3].y;
103     za = atom[natm3].z;
104     /* *** now place these two atoms "natm2, natm3" on x-axis *** */
105     xaxis( &xa, &ya, &za );
106     xa = atom[natm1].x;
107     ya = atom[natm1].y;
108     za = atom[natm1].z;
109     /* *** now place the two atoms "namt1, natm3" on xy-plane *** */
110     xyplan( &xa, &ya, &za );
111     /* place natm1 (chiral center) at 0,0,0 */
112     xa = atom[natm1].x;
113     ya = atom[natm1].y;
114     za = atom[natm1].z;
115     for( ii = 1; ii <= natom; ii++ )
116     {
117     atom[ii].x -= xa;
118     atom[ii].y -= ya;
119     atom[ii].z -= za;
120     }
121     /* find and reflect x coord of all atoms attached to natm and natm2 */
122    
123     mask = (1 << DOT_SURF);
124     for( ii = 1; ii <= natom; ii++ )
125     atom[ii].substr[0] &= ~mask ;
126    
127    
128     chain( natm2, natm1, DOT_SURF);
129     for( ii = 1; ii <= natom; ii++ )
130     {
131     atom[ii].flags &= ~mask;
132     if( atom[ii].substr[0] & mask)
133     {
134     atom[ii].flags |= mask;
135     atom[ii].x = -atom[ii].x;
136     atom[ii].z = -atom[ii].z;
137     }
138     }
139    
140     for( ii = 1; ii <= natom; ii++ )
141     atom[ii].substr[0] &= ~mask ;
142     chain( natm3, natm1, DOT_SURF );
143    
144     for( ii = 1; ii <= natom; ii++ )
145     {
146     if( (atom[ii].substr[0] & mask) && !(atom[ii].flags & mask) )
147     {
148     atom[ii].flags |= mask;
149     atom[ii].x = -atom[ii].x;
150     atom[ii].z = -atom[ii].z;
151     }
152     }
153     if( !(atom[natm2].flags & mask) )
154     {
155     atom[natm2].x = -atom[natm2].x;
156     atom[natm2].z = -atom[natm2].z;
157     }
158     if( !(atom[natm3].flags & mask) )
159     {
160     atom[natm3].x = -atom[natm3].x;
161     atom[natm3].z = -atom[natm3].z;
162     }
163     /* reorient structure by rotating plane and the axis */
164     revec();
165     return;
166     }