def screwMotion(self): l = self.vector.length() if l == 0.: return Geometry.Vector(0.,0.,0.), \ Geometry.Vector(0.,0.,1.), 0., 0. else: return Geometry.Vector(0., 0., 0.), self.vector / l, 0., l
def screwMotion(self): axis, angle = self.rotation().axisAndAngle() d = self.vector*axis x = d*axis-self.vector if abs(angle) < 1.e-9: r0 = Geometry.Vector(0., 0., 0.) angle = 0. else: r0 = -0.5*((N.cos(0.5*angle)/N.sin(0.5*angle))*axis.cross(x)+x) return r0, axis, angle, d
def asVector(self): """ @returns: an equivalent vector object @rtype: L{Scientific.Geometry.Vector} @raises ValueError: if rank > 1 """ from Scientific import Geometry if self.rank == 1: return Geometry.Vector(self.array) else: raise ValueError('rank > 1')
def screwMotion(self): axis, angle = self.rotation().axisAndAngle() d = self.vector * axis if d < 0.: d = -d axis = -axis angle = -angle if abs(angle) < 1.e-9: r0 = Geometry.Vector(0., 0., 0.) angle = 0. else: x = d * axis - self.vector r0 = -0.5 * ( (N.cos(0.5 * angle) / N.sin(0.5 * angle)) * axis.cross(x) + x) return r0, axis, angle % (2. * N.pi), d
def axisAndAngle(self): """ @returns: the axis (a normalized vector) and angle (in radians). The angle is in the interval (-pi, pi] @rtype: (L{Scientific.Geometry.Vector}, C{float}) """ asym = -self.tensor.asymmetricalPart() axis = Geometry.Vector(asym[1, 2], asym[2, 0], asym[0, 1]) sine = axis.length() if abs(sine) > 1.e-10: axis = axis / sine projector = axis.dyadicProduct(axis) cosine = (self.tensor - projector).trace() / (3. - axis * axis) angle = angleFromSineAndCosine(sine, cosine) else: t = 0.5 * (self.tensor + Geometry.delta) i = N.argmax(t.diagonal().array) axis = (t[i] / N.sqrt(t[i, i])).asVector() angle = 0. if t.trace() < 2.: angle = N.pi return axis, angle
junk = co_file.readline() testline = co_file.readline() while testline != "": # Eliminate white space and split line in_str = testline.strip() in_str = in_str.split() #Convert coordinates based on atom type if (in_str[0] == "H" and len(H1) == len(H2)): #Convert coordinates to vectors for the H1's H1.append( Geo.Vector(float(in_str[1]), float(in_str[2]), float(in_str[3]))) print "H1" elif (in_str[0] == "H" and len(H2) == (len(H1) - 1)): #Convert coordinates to vectors for the H2's H2.append( Geo.Vector(float(in_str[1]), float(in_str[2]), float(in_str[3]))) print "H2" elif (in_str[0] == "O"): #Convert coordinates to vectors for the O's Oxy.append( Geo.Vector(float(in_str[1]), float(in_str[2]), float(in_str[3]))) print "O"
def screwMotion(self): axis, angle = self.axisAndAngle() return Geometry.Vector(0., 0., 0.), axis, angle, 0.
def translation(self): return Translation(Geometry.Vector(0., 0., 0.))
def inverse(self): return LinearTransformation(self.tensor.inverse(), -self.vector) # Utility functions def angleFromSineAndCosine(y, x): return atan2(y, x) def mod_angle(angle, mod): return (angle + mod / 2.) % mod - mod / 2 # Test code if __name__ == '__main__': t = Translation(Geometry.Vector(1., -2., 0)) r = Rotation(Geometry.Vector(0.1, -2., 0.5), 1.e-10) q = r.asQuaternion() angles = r.threeAngles(Geometry.Vector(1., 0., 0.), Geometry.Vector(0., 1., 0.), Geometry.Vector(0., 0., 1.)) c = t * r print c.screwMotion() s = Scaling(2.) all = s * t * r print all(Geometry.ex)
junk = xyz_file.readline() junk = xyz_file.readline() while 1: line = xyz_file.readline() if not line: break x, y, z = map(float, string.split(line)[1:]) #ignore atom label cage_type = string.split(line)[0] #get the atom type #Convert coordinates based on atom type if (cage_type == "Ar(Small)"): #Convert coordinates to vectors for the Small Cages small_cages.append(Geo.Vector(x,y,z)) elif (cage_type == "Kr(Large)"): #Convert coordinates to vectors for the Large Cages large_cages.append(Geo.Vector(x,y,z)) else: raise CorrelationError("Can't parse file. Encountered strange cage centre type: " + cage_type + " Only 'Ar(Small)' and 'Kr(Large)' accepted.") xyz_file.close() print "Read in Cage Centre locations. There are %d small and %d large cages." % (len(small_cages), len(large_cages))