-
Notifications
You must be signed in to change notification settings - Fork 1
/
testAngle.py
executable file
·144 lines (113 loc) · 3.67 KB
/
testAngle.py
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
import sys
import os
import numpy
from Numeric import *
from numpy import sin,cos
waterFile=open('testH2OCoord.txt','r')
def readFileCoord(self):
allCoord=[]
H2OCoord=[]
each=[]
for line in self:
line=line.split()
coord=line[3:-3]
## print coord
realCoord=[]
for i in coord:
## print i
i=float(i)
realCoord.append(i)
## realCoord=numpy.array(realCoord)
H2OCoord.append(realCoord)
print len(H2OCoord)
no=1
for H2ONo in range(len(H2OCoord)):
atomCoord=H2OCoord[H2ONo]
print atomCoord
if no/3.0==1.0:
each.append(atomCoord)
allCoord.append(each)
each=[]
no=1
else:
each.append(atomCoord)
no+=1
return allCoord
def calculateEular(self):
referenceH1=numpy.array([0.79079641377315202, 0.61207926934631729, 0.0])
referenceH2=numpy.array([-0.79079641377315202, 0.61207926934631729, 0.0])
referenceZ=numpy.array([0.0,0.0,1.0])
referenceY=numpy.array([0.0,1.0,0.0])
revReferenceY=numpy.array([0.0,-1.0,0.0])
H1=numpy.array(self[1])
H2=numpy.array(self[2])
OT=numpy.array(self[0])
H1=H1-OT
H2=H2-OT
print H1
print H2
YH2O=numpy.add(H1,H2)
ZH2O=numpy.cross(H1,H2)
XH2O=numpy.cross(YH2O,ZH2O)
ZH2OOnXY=numpy.copy(ZH2O)
ZH2OOnXY[2]=0.0
crossLine=numpy.cross(referenceZ,ZH2O)
XH2OModulus=numpy.sqrt((XH2O*XH2O).sum())
crossLineModulus=numpy.sqrt((crossLine*crossLine).sum())
## print crossLineModulus
dot1=numpy.dot(crossLine,XH2O)
cosAnglePsi=dot1/XH2OModulus/crossLineModulus
## print cosAnglePsi
anglePsi=numpy.arccos(cosAnglePsi)
## print anglePsi
if XH2O[2]<0:
anglePsi=2*pi-anglePsi
ZH2OOnXY=numpy.copy(ZH2O)
ZH2OOnXY[2]=0.0
ZH2OOnXYModulus=numpy.sqrt((ZH2OOnXY*ZH2OOnXY).sum())
dot1=numpy.dot(revReferenceY,ZH2OOnXY)
cosAnglePhi=dot1/ZH2OOnXYModulus
anglePhi=numpy.arccos(cosAnglePhi)
if ZH2OOnXY[0]<0:
anglePhi=2*pi-anglePhi
ZH2O=numpy.cross(H1,H2)
ZH2OModulus=numpy.sqrt((ZH2O*ZH2O).sum())
dot1=numpy.dot(referenceZ,ZH2O)
cosAngleTheta=dot1/ZH2OModulus
angleTheta=numpy.arccos(cosAngleTheta)
## print 'The H2O coordidate is :', self
print 'the angle is:',angleTheta,anglePhi,anglePsi
a11=cos(anglePsi)*cos(anglePhi)-cos(angleTheta)*sin(anglePhi)*sin(anglePsi)
a12=cos(anglePsi)*sin(anglePhi)+cos(angleTheta)*cos(anglePhi)*sin(anglePsi)
a13=sin(anglePsi)*sin(angleTheta)
a21=-sin(anglePsi)*cos(anglePhi)-cos(angleTheta)*sin(anglePhi)*cos(anglePsi)
a22=-sin(anglePsi)*sin(anglePhi)+cos(angleTheta)*cos(anglePhi)*cos(anglePsi)
a23=cos(anglePsi)*sin(angleTheta)
a31=sin(angleTheta)*sin(anglePhi)
a32=-sin(angleTheta)*cos(anglePhi)
a33=cos(angleTheta)
rotation=numpy.matrix([[a11,a12,a13],[a21,a22,a23],[a31,a32,a33]])
print rotation
H1=H1.reshape((-1,1))
H2=H2.reshape((-1,1))
print 'H1',H1
H1=numpy.matrix(H1)
## print H1
## print rotation*(rotation**-1)
H1=((rotation**-1)*(referenceH1.reshape(-1,1))).reshape(1,-1)
H1=numpy.array(H1)
print H1[0]
print 'H2',H2
H2=((rotation**-1)*(referenceH2.reshape(-1,1))).reshape(1,-1)
print H2[0]
H2=numpy.array(H2)
move=numpy.array([1,1,1])
O=numpy.array([0,0,0])
H2O=numpy.array([O,H1[0],H2[0]])
print H2O+move
## print numpy.dot(rotation,H2)
coord=readFileCoord(waterFile)
print len(coord)
for i in coord:
print len(i)
calculateEular(i)