-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransform.cpp
More file actions
207 lines (188 loc) · 6.08 KB
/
transform.cpp
File metadata and controls
207 lines (188 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//transform.cpp
#include <string>
#include <cmath>
#include <vector>
#include <sstream>
#include <iostream>
#include "molecule.h"
#include "transform.h"
void Transform::ConvertCoord(Molecule& examMole, char fromType, char toType)
{
if (fromType == 'C' && toType == '1')//Cartesian to Cylindrical_X
{
double r, theta; //x will remain the same. r and theta depend on y and z
for (int i=0; i<examMole.GetAtomCount(); i++)
{
r = sqrt(pow(examMole.GetAtomCoord(i,'y'),2)
+pow(examMole.GetAtomCoord(i,'z'),2));
theta = atan2(examMole.GetAtomCoord(i,'y'),
examMole.GetAtomCoord(i,'z'));
examMole.SetAtomCoord(i,'y',r);
examMole.SetAtomCoord(i,'z',theta);
}
}
else if (fromType == 'C' && toType == '2')//Cartesian to Cylindrical_Y
{
double r, theta;
for (int i=0; i<examMole.GetAtomCount(); i++)
{
r = sqrt(pow(examMole.GetAtomCoord(i,'x'),2)
+pow(examMole.GetAtomCoord(i,'z'),2));
theta = atan2(examMole.GetAtomCoord(i,'x'),
examMole.GetAtomCoord(i,'z'));
examMole.SetAtomCoord(i,'x',examMole.GetAtomCoord(i,'y'));
examMole.SetAtomCoord(i,'y',r);
examMole.SetAtomCoord(i,'z',theta);
}
}
else if (fromType == 'C' && toType == '3')//Cartesian to Cylindrical_Z
{
double r, theta;
for (int i=0; i<examMole.GetAtomCount(); i++)
{
r = sqrt(pow(examMole.GetAtomCoord(i,'x'),2)
+pow(examMole.GetAtomCoord(i,'y'),2));
theta = atan2(examMole.GetAtomCoord(i,'y'),
examMole.GetAtomCoord(i,'x'));
examMole.SetAtomCoord(i,'x',examMole.GetAtomCoord(i,'z'));
examMole.SetAtomCoord(i,'y',r);
examMole.SetAtomCoord(i,'z',theta);
}
}
else if (fromType == '1' && toType == 'C')//Cylindrical_X to Cartesian
{
double y, z;
for (int i=0; i<examMole.GetAtomCount(); i++)
{
y = examMole.GetAtomCoord(i,'y')
*sin(examMole.GetAtomCoord(i,'z'));
z = examMole.GetAtomCoord(i,'y')
*cos(examMole.GetAtomCoord(i,'z'));
examMole.SetAtomCoord(i,'y',y);
examMole.SetAtomCoord(i,'z',z);
}
}
else if (fromType == '2' && toType == 'C')//Cylindrical_Y to Cartesian
{
double x, z;
for (int i=0; i<examMole.GetAtomCount(); i++)
{
x = examMole.GetAtomCoord(i,'y')
*sin(examMole.GetAtomCoord(i,'z'));
z = examMole.GetAtomCoord(i,'y')
*cos(examMole.GetAtomCoord(i,'z'));
examMole.SetAtomCoord(i,'y',examMole.GetAtomCoord(i,'x'));
examMole.SetAtomCoord(i,'x',x);
examMole.SetAtomCoord(i,'z',z);
}
}
else if (fromType == '3' && toType == 'C')//Cylindrical_Z to Cartesian
{
double x, y;
for (int i=0; i<examMole.GetAtomCount(); i++)
{
y = examMole.GetAtomCoord(i,'y')
*sin(examMole.GetAtomCoord(i,'z'));
x = examMole.GetAtomCoord(i,'y')
*cos(examMole.GetAtomCoord(i,'z'));
examMole.SetAtomCoord(i,'z',examMole.GetAtomCoord(i,'x'));
examMole.SetAtomCoord(i,'x',x);
examMole.SetAtomCoord(i,'y',y);
}
}
return;
}
void Transform::CoordEdit(Molecule& examMole, double xTrans, double yTrans, double zTrans)
{//Also used to edit cylindrical coordinates
double tempXcoord, tempYcoord, tempZcoord;
for(int i=0; i<examMole.GetAtomCount(); i++)
{
tempXcoord=examMole.GetAtomCoord(i,'x')+xTrans;
tempYcoord=examMole.GetAtomCoord(i,'y')+yTrans;
tempZcoord=examMole.GetAtomCoord(i,'z')+zTrans;
examMole.SetAtomCoord(i,'x',tempXcoord);
examMole.SetAtomCoord(i,'y',tempYcoord);
examMole.SetAtomCoord(i,'z',tempZcoord);
}
return;
}
void Transform::SelectiveEdit(Molecule& examMole, double xTrans, double yTrans, double zTrans, std::vector<int>& atomSel)
{//0 0 theta atomSel
double tempXcoord, tempYcoord, tempZcoord; int j;
for(int i=0; i<atomSel.size(); i++)
{
j=atomSel[i];
//tempXcoord=examMole.GetAtomCoord(j,'x')+xTrans;
//tempYcoord=examMole.GetAtomCoord(j,'y')+yTrans;
tempZcoord=examMole.GetAtomCoord(j,'z')+zTrans;
//examMole.SetAtomCoord(j,'x',tempXcoord);
//examMole.SetAtomCoord(j,'y',tempYcoord);
examMole.SetAtomCoord(j,'z',tempZcoord);
}
}
void Transform::Center(Molecule& examMole, int A1)
{
double xTrans, yTrans, zTrans;
xTrans = -(examMole.GetAtomCoord(A1,'x'));
yTrans = -(examMole.GetAtomCoord(A1,'y'));
zTrans = -(examMole.GetAtomCoord(A1,'z'));
CoordEdit(examMole,xTrans,yTrans,zTrans);
return;
}
void Transform::AlignAxis(Molecule& examMole, char axis, int A1, int A2)
{
const double PI = 3.14159265358979323846;
if (axis == 'z' || axis == 'Z')
{
Center(examMole, A1);
ConvertCoord(examMole,'C','1');
CoordEdit(examMole,0,0,-(examMole.GetAtomCoord(A2,'z')));
ConvertCoord(examMole,'1','C');
ConvertCoord(examMole,'C','2');
CoordEdit(examMole,0,0,-(examMole.GetAtomCoord(A2,'z')));
ConvertCoord(examMole,'2','C');
}
if (axis == 'y' || axis == 'Y')
{
Center(examMole,A1);
ConvertCoord(examMole,'C','1');
CoordEdit(examMole,0,0,-(examMole.GetAtomCoord(A2,'z'))+(PI/2));
ConvertCoord(examMole,'1','C');
ConvertCoord(examMole,'C','3');
CoordEdit(examMole,0,0,-(examMole.GetAtomCoord(A2,'z'))+(PI/2));
ConvertCoord(examMole,'3','C');
}
if (axis == 'x' || axis == 'X')
{
Center(examMole, A1);
ConvertCoord(examMole,'C','2');
CoordEdit(examMole,0,0,-(examMole.GetAtomCoord(A2,'z'))-(PI/2));
ConvertCoord(examMole,'2','C');
ConvertCoord(examMole,'C','3');
CoordEdit(examMole,0,0,-(examMole.GetAtomCoord(A2,'z')));
ConvertCoord(examMole,'3','C');
}
return;
}
void Transform::BondRotate(Molecule& examMole, double theta, int atom1, int atom2, std::vector<int>& atomSel)
{
AlignAxis(examMole, 'x', atom1, atom2);
ConvertCoord(examMole,'C','1');
SelectiveEdit(examMole,0,0,theta,atomSel);
ConvertCoord(examMole,'1','C');
return;
}
void Transform::DeviceSwitch_ODSP(Molecule& examMole, int * axiAtoms, double angleDisp, double angleInc,std::vector<int>& atomSelRot, std::vector<int>& atomSelRec, std::string filename )
{
int counter = 1; int i = 0;
std::stringstream strCount;
for (double angleTot=angleInc; angleTot<=angleDisp; angleTot=angleTot+angleInc)
{
strCount << counter;
BondRotate(examMole, angleInc, *(axiAtoms) , *(axiAtoms+1), atomSelRot);
BondRotate(examMole, -angleInc, *(axiAtoms+2), *(axiAtoms+3), atomSelRec);
examMole.PrintInfo(filename + "_" + strCount.str() + ".gamess","gamess");
counter++; strCount.str("");
}
return;
}