def _findPosition(self, unknown, a1, a2, a3, bond, angle, dihedral): sphere = Objects3D.Sphere(a1, bond) cone = Objects3D.Cone(a1, a2 - a1, angle) plane = Objects3D.Plane(a3, a2, a1) plane = plane.rotate(Objects3D.Line(a1, a2 - a1), dihedral) points = sphere.intersectWith(cone).intersectWith(plane) for p in points: if (a1 - a2).cross(p - a1) * (plane.normal) > 0: unknown.setPosition(p) break
def _N4twoH(self, atom, known, unknown): r = atom.position() r1 = known[0].position() r2 = known[1].position() plane = Objects3D.Plane(r, r1, r2) axis = -((r1 - r) + (r2 - r)).normal() plane = plane.rotate(Objects3D.Line(r, axis), 90. * Units.deg) cone = Objects3D.Cone(r, axis, 0.5 * self._hnh_angle) sphere = Objects3D.Sphere(r, self._nh_bond) circle = sphere.intersectWith(cone) points = circle.intersectWith(plane) unknown[0].setPosition(points[0]) unknown[1].setPosition(points[1])
def _N3twoH(self, atom, known, unknown): r = atom.position() r1 = known[0].position() others = filter(lambda a: a.symbol != 'H', known[0].bondedTo()) r2 = others[0].position() plane = Objects3D.Plane(r, r1, r2) axis = (r - r1).normal() cone = Objects3D.Cone(r, axis, 0.5 * self._hnh_angle) sphere = Objects3D.Sphere(r, self._nh_bond) circle = sphere.intersectWith(cone) points = circle.intersectWith(plane) unknown[0].setPosition(points[0]) unknown[1].setPosition(points[1])
def boundingSphere(self, conf=None): """Returns a sphere that contains all atoms in the object. This is *not* the minimal bounding sphere, just *some* bounding sphere.""" atoms = self.atomList() r = Vector(0., 0., 0.) for a in atoms: r = r + a.position(conf) center = r / len(atoms) r = 0. for a in self.atomList(): r = max(r, (a.position(conf) - center).length()) return Objects3D.Sphere(center, r)
def boundingSphere(self, conf=None): """ :param conf: a configuration object, or None for the current configuration :type conf: :class:~MMTK.ParticleProperties.Configuration or NoneType :returns: a sphere that contains all atoms in the object. This is B{not} the minimal bounding sphere, just B{some} bounding sphere. :rtype: Scientific.Geometry.Objects3D.Sphere """ atoms = self.atomList() center = sum( (a.position(conf) for a in atoms), Vector(0., 0., 0.)) / len(atoms) r = 0. for a in atoms: r = max(r, (a.position(conf) - center).length()) return Objects3D.Sphere(center, r)
def _N2oneH(self, atom, known, unknown): r = atom.position() r1 = known[0].position() others = filter(lambda a: a.symbol != 'H', known[0].bondedTo()) r2 = others[0].position() try: plane = Objects3D.Plane(r, r1, r2) except ZeroDivisionError: # We get here when all three points are colinear. # Add a small random displacement as a fix. from MMTK.Random import randomPointInSphere plane = Objects3D.Plane(r, r1, r2 + randomPointInSphere(0.001)) axis = (r - r1).normal() cone = Objects3D.Cone(r, axis, 0.5 * self._hch_angle) sphere = Objects3D.Sphere(r, self._nh_bond) circle = sphere.intersectWith(cone) points = circle.intersectWith(plane) unknown[0].setPosition(points[0])
def _tetrahedralH(self, atom, known, unknown, bond): r = atom.position() n = (known[0].position() - r).normal() cone = Objects3D.Cone(r, n, Numeric.arccos(-1. / 3.)) sphere = Objects3D.Sphere(r, bond) circle = sphere.intersectWith(cone) others = filter(lambda a: a.symbol != 'H', known[0].bondedTo()) others.remove(atom) other = others[0] ref = (Objects3D.Plane(circle.center, circle.normal) \ .projectionOf(other.position())-circle.center).normal() p0 = circle.center + ref * circle.radius p0 = Objects3D.rotatePoint( p0, Objects3D.Line(circle.center, circle.normal), 60. * Units.deg) p1 = Objects3D.rotatePoint( p0, Objects3D.Line(circle.center, circle.normal), 120. * Units.deg) p2 = Objects3D.rotatePoint( p1, Objects3D.Line(circle.center, circle.normal), 120. * Units.deg) unknown[0].setPosition(p0) unknown[1].setPosition(p1) unknown[2].setPosition(p2)