5 """toDeg(ang) - converts an angle in radians to an angle in degrees"""
6 return ang / math.pi * 180.0
9 """toRad(ang) - converts an angle in degrees to an angle in radians"""
10 return ang / 180.0 * math.pi
13 return (atom2[0]-atom1[0])**2 + (atom2[1]-atom1[1])**2 + \
14 (atom2[2]-atom1[2])**2
18 return (
dist_sq(atom1, atom2))**0.5
22 A = [xA, yA, zA], and B and C are defined in the same fashion. Given
23 these 3 coordinates, returns the angle between the AB and BC bond vectors.
34 phistp =
stp(AB,BC,CD)
44 """vector(atom1, atom2) - return the mathematical vector from A to B
45 Given two points, A and B, this function returns the vector going
46 from point A to point B, represented as a list of cartesian
47 components. A and be must be lists of coordinates in x, y, and
50 vector([x1, y1, z1], [x2, y2, z2]) ==> [x2-x1, y2-y1, z2-z1]
52 return [atom2[0]-atom1[0], atom2[1]-atom1[1], atom2[2]-atom1[2]]
55 """vabs(vec) - return the absolute value of a given vector
56 The absolute value of a three-dimensional vector from point A to
57 point B is defined as the distance between points A and B. This
58 function evaluates that value for a vector as defined above.
60 return math.sqrt(vec[0]**2 + vec[1]**2 + vec[2]**2)
77 v3.append(v1[i] + v2[i])
83 print 'error: Cannot average an empty list of objects'
87 sum=
vadd(sum,vlist[i])
92 gets the root sum of squares for two vectors (the distance
97 s_sq=s_sq+(v1[i]-v2[i])**2
98 return math.sqrt(s_sq)
101 """dot(v1, v2) - return the inner (dot) product of two vectors
102 This function evaluates the dot product between two vectors, defined
105 dot([x1, y1, z1], [x2, y2, z2]) ==> x1*x2 + y1*y2 + z1*z2
107 It can be shown that this is also equal to:
109 dot(v1, v2) ==> |v1| * |v2| * cos(theta)
111 Where theta is the angle between the vectors.
113 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]
116 """cross(v1, v2) - returns the cross product of two vectors
117 This function evaluates the cross product between two cartesian
118 vectors in 3d. For v1 = [x1, y1, z1], v2 = [x2, y2, z2], and
119 cartesian unit vectors i, j, and k, this is defined as the
120 determinant of the following matrix:
128 cross([x1, y1, z1], [x2, y2, z2]) ==>
129 [y1*z2 - z1*y2, z1*x2 - x1*z2, x1*y2 - y1*x2]
131 It can also be shown that
133 -- |cross(v1, v2)| == |v1| * |v2| * sin(theta)
135 Where theta is the angle between the two vectors.
137 return [v1[1]*v2[2] - v1[2]*v2[1],
138 v1[2]*v2[0] - v1[0]*v2[2],
139 v1[0]*v2[1] - v1[1]*v2[0]]
142 """stp(v1, v2, v3) - return the scalar triple product of three vectors
143 This function will return the scalar triple product of three vectors,
144 defined most simply as dot(v3, cross(v1, v2)). It can be shown that
145 |stp(v1, v2, v3)| is the volume of the parallelpiped with sides
146 defined by the vectors. It follows that the following relationships
149 stp(v1, v2, v3) == stp(v2, v3, v1) == stp(v3, v1, v2)
154 """vangle(v1, v2) - returns the angle (in radians) between two vectors
155 If v1 and v2 are two vectors, this function uses the cosine
156 relationship given above (in dot) to determine the angle between
157 those vectors when one vector is projected on the plane of the other.
158 Note that this value can only be the range of the arccos function,
159 so theta will be in the range 0 to Pi.
170 if vcos >= 1.0:
return 0.0
171 elif vcos <= -1.0:
return math.pi
173 return math.acos(vcos)
BooleanOptionKey const range
Fstring::size_type len(Fstring const &s)
Length.