Exemplo n.º 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 testCenterOfMass(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) ),
                                        ]
                                    )

        center_of_mass = XYZMolecule.centerOfMass(mol)
        self.assertAlmostEqual(center_of_mass.value()[0], 0.000000, 6)
        self.assertAlmostEqual(center_of_mass.value()[1], 5.190321, 6)
        self.assertAlmostEqual(center_of_mass.value()[2], -0.436054, 6)
Exemplo n.º 3
0
def main(argv): # fold>>

    options = _getOptions(argv)

    infile = XYZFile.XYZFile(options.input_filename)
    outfile = XYZFile.XYZFile()


    for mol_idx in xrange(infile.numOfMolecules()):
        atom_list = []
        for atom_idx in xrange(infile.numOfAtoms(mol_idx)):
            atom_list.append(infile.atom(mol_idx, atom_idx))
            

        molecule = XYZMolecule.XYZMolecule(atom_list)
        molecule.translate(-XYZMolecule.centerOfMass(molecule))

        new_mol_index = outfile.createMolecule()
        for atom in zip(molecule.elements(), molecule.atomPos()):
            outfile.addAtom(new_mol_index,atom)
            


    outfile.saveTo(options.output_filename)