def dihedral(self, p1, p2, p3, p4, conf = None): """Returns the dihedral angle between the plane containing the distance vectors |p1|-|p2| and |p3|-|p2| and the plane containing the distance vectors |p2|-|p3| and |p4|-|p3|.""" v1 = self.distanceVector(p2, p1, conf) v2 = self.distanceVector(p3, p2, conf) v3 = self.distanceVector(p3, p4, conf) a = v1.cross(v2).normal() b = v3.cross(v2).normal() cos = a*b sin = b.cross(a)*v2/v2.length() return Transformation.angleFromSineAndCosine(sin, cos)
def __init__(self, attr, point1, point2): center = 0.5 * (point1 + point2) axis = point2 - point1 self.height = axis.length() if self.height > 0: axis = axis / self.height rot_axis = ey.cross(axis) sine = rot_axis.length() cosine = ey * axis angle = Transformation.angleFromSineAndCosine(sine, cosine) if abs(angle) < 1.e-4 or abs(angle - 2. * N.pi) < 1.e-4: rotation = None else: if abs(sine) < 1.e-4: rot_axis = ex rotation = (rot_axis, angle) else: rotation = None ShapeObject.__init__(self, attr, rotation, center, center)
def __init__(self, attr, point1, point2): center = 0.5*(point1+point2) axis = point2-point1 self.height = axis.length() if self.height > 0: axis = axis/self.height rot_axis = VectorModule.ey.cross(axis) sine = rot_axis.length() cosine = VectorModule.ey*axis angle = Transformation.angleFromSineAndCosine(sine, cosine) if abs(angle) < 1.e-4 or abs(angle-2.*Numeric.pi) < 1.e-4: rotation = None else: if abs(sine) < 1.e-4: rot_axis = VectorModule.ex rotation = (rot_axis, angle) else: rotation = None ShapeObject.__init__(self, attr, rotation, center, center)
def addImproperTerm(self, data, improper, object, global_data): if not self.arguments[2]: return a1 = improper.a1 a2 = improper.a2 a3 = improper.a3 a4 = improper.a4 i1 = a1.index i2 = a2.index i3 = a3.index i4 = a4.index t1 = global_data.atom_type[a1] t2 = global_data.atom_type[a2] t3 = global_data.atom_type[a3] t4 = global_data.atom_type[a4] terms = self.dataset.improperParameters(t1, t2, t3, t4) if terms is not None: atoms = [(t2,i2,a2), (t3,i3,a3), (t4,i4,a4)] atoms.sort(_order) i2, i3, i4 = tuple(map(lambda t: t[1], atoms)) a2, a3, a4 = tuple(map(lambda t: t[2], atoms)) v1 = a2.position()-a3.position() v2 = a3.position()-a1.position() v3 = a4.position()-a1.position() a = v1.cross(v2).normal() b = v3.cross(v2).normal() cos = a*b sin = b.cross(a)*v2/v2.length() dihedral = Transformation.angleFromSineAndCosine(sin, cos) if dihedral > Numeric.pi: dihedral = dihedral - 2.*Numeric.pi for p in terms: if p[2] != 0.: mult = p[0] phase = Numeric.fmod(Numeric.pi-mult*dihedral, 2.*Numeric.pi) if phase < 0.: phase = phase + 2.*Numeric.pi data.add('dihedrals', (i2, i3, i1, i4, p[0], phase) + p[2:])
def addDihedralTerm(self, data, dihedral, object, global_data): if not self.arguments[2]: return a1 = dihedral.a1 a2 = dihedral.a2 a3 = dihedral.a3 a4 = dihedral.a4 i1 = a1.index i2 = a2.index i3 = a3.index i4 = a4.index global_data.add('1_4_pairs', (i1, i4)) t1 = global_data.atom_type[a1] t2 = global_data.atom_type[a2] t3 = global_data.atom_type[a3] t4 = global_data.atom_type[a4] terms = self.dataset.dihedralParameters(t1, t2, t3, t4) if terms is not None: v1 = a1.position()-a2.position() v2 = a2.position()-a3.position() v3 = a4.position()-a3.position() a = v1.cross(v2).normal() b = v3.cross(v2).normal() cos = a*b sin = b.cross(a)*v2/v2.length() dihedral = Transformation.angleFromSineAndCosine(sin, cos) if dihedral > Numeric.pi: dihedral = dihedral - 2.*Numeric.pi for p in terms: if p[2] != 0.: mult = p[0] phase = Numeric.fmod(Numeric.pi-mult*dihedral, 2.*Numeric.pi) if phase < 0.: phase = phase + 2.*Numeric.pi data.add('dihedrals', (i1, i2, i3, i4, p[0], phase) + p[2:])