Exemple #1
0
def _getAlignmentOperations(molecule):  # fold>>
    xyz_mol = molecule.createXYZMolecule()
    center_of_mass = XYZMolecule.centerOfMass(xyz_mol)

    xyz_mol.translate(-center_of_mass)
    moments_of_inertia = XYZMolecule.momentsOfInertia(xyz_mol)

    # we multiply the eigenvectors by -1 if needed.
    # we want to keep the molecule oriented so that it does not change dramatically
    # (ex. we don't want it to flip just because the diagonalization returned the
    # inertial axis in the other direction)
    v0 = numpy.array(moments_of_inertia[0][1].value())
    if v0[0] < 0.0:
        v0 = -v0
    v1 = numpy.array(moments_of_inertia[1][1].value())
    if v1[1] < 0.0:
        v1 = -v1
    v2 = numpy.array(moments_of_inertia[2][1].value())
    if v2[2] < 0.0:
        v2 = -v2

    rotation = numpy.zeros((3, 3))
    rotation[0, 0] = v0[0]
    rotation[0, 1] = v0[1]
    rotation[0, 2] = v0[2]
    rotation[1, 0] = v1[0]
    rotation[1, 1] = v1[1]
    rotation[1, 2] = v1[2]
    rotation[2, 0] = v2[0]
    rotation[2, 1] = v2[1]
    rotation[2, 2] = v2[2]

    return (-center_of_mass, rotation)
    def testMomentsOfInertia(self): # fold>>
        mol = XYZMolecule.XYZMolecule( [
                                        (PeriodicTable.H, Measure.Measure( ( 0.0000000000,0.0000000000,0.0000000000  ), Units.bohr) ),
                                        (PeriodicTable.H, Measure.Measure( ( 0.0000000000,1.7920231678,-3.1038751750 ), Units.bohr) ),
                                        (PeriodicTable.H, Measure.Measure( ( 0.0000000000,4.0095495535,2.3149145141  ), Units.bohr) ),
                                        (PeriodicTable.H, Measure.Measure( ( 0.0000000000,6.3710924130,-3.1870231249 ), Units.bohr) ),
                                        (PeriodicTable.H, Measure.Measure( ( 0.0000000000,8.5886187987,2.2317665642  ), Units.bohr) ),
                                        (PeriodicTable.H, Measure.Measure( ( 0.0000000000,10.3806419665,-0.8721086108), Units.bohr) ),
                                        (PeriodicTable.C, Measure.Measure( ( 0.0000000000,1.7920231678,-1.0346250583 ), Units.bohr) ),
                                        (PeriodicTable.C, Measure.Measure( ( 0.0000000000,4.0095495535,0.2456643974  ), Units.bohr) ),
                                        (PeriodicTable.C, Measure.Measure( ( 0.0000000000,6.3710924130,-1.1177730082 ), Units.bohr) ),
                                        (PeriodicTable.C, Measure.Measure( ( 0.0000000000,8.5886187987,0.1625164475  ), Units.bohr) ),
                                        ]
                                    )

        inertia = XYZMolecule.momentsOfInertia(mol)
        self.assertEqual(len(inertia), 3)
        self.assertAlmostEqual(inertia[0][0].asUnit(Units.dalton * Units.angstrom * Units.angstrom).value(),  12.836878, 5)
        self.assertAlmostEqual(inertia[1][0].asUnit(Units.dalton * Units.angstrom * Units.angstrom).value(),  110.58507, 5)
        self.assertAlmostEqual(inertia[2][0].asUnit(Units.dalton * Units.angstrom * Units.angstrom).value(),  123.421950, 5)

        self.assertAlmostEqual(inertia[0][1].value()[0], 0.0) 
        self.assertAlmostEqual(inertia[0][1].value()[1], 0.994406, 5) 
        self.assertAlmostEqual(inertia[0][1].value()[2], 0.105628, 5) 

        self.assertAlmostEqual(inertia[1][1].value()[0], 0.0) 
        self.assertAlmostEqual(inertia[1][1].value()[1], -0.105628, 5) 
        self.assertAlmostEqual(inertia[1][1].value()[2], 0.994406, 5) 

        self.assertAlmostEqual(inertia[2][1].value()[0], 1.0) 
        self.assertAlmostEqual(inertia[2][1].value()[1], 0.0, 5) 
        self.assertAlmostEqual(inertia[2][1].value()[2], 0.0, 5)