Example #1
0
    def get_molecules(self):
        tpa = Molecule.from_file("input/tpa.xyz")
        tea = Molecule.from_file("input/tea.xyz")
        water = Molecule.from_file("input/water.xyz")
        cyclopentane = Molecule.from_file("input/cyclopentane.xyz")

        return [tpa, tea, water, cyclopentane]
Example #2
0
 def test_many_separate(self):
     psf = PSFFile()
     molecule = Molecule.from_file("input/ethene.xyz")
     psf.add_molecule(molecule)
     psf.add_molecule(molecule)
     molecule = Molecule.from_file("input/tea.xyz")
     psf.add_molecule(molecule)
     psf.write_to_file("output/many_separate.psf")
Example #3
0
 def test_zirconium(self):
     mol = Molecule.from_file('input/oh3siozroh3.xyz')
     mol.set_default_graph()
     assert len(mol.graph.edges)==14
     mol = Molecule.from_file('input/osih2osihosih2osih2ozrh2oh.xyz')
     mol.set_default_graph()
     assert len(mol.graph.edges)==21
     mol = Molecule.from_file('input/h3zrosihohosioh3.xyz')
     mol.set_default_graph()
     assert len(mol.graph.edges)==16
     mol = Molecule.from_file('input/zr4o8-3.xyz')
     mol.set_default_graph()
     assert len(mol.graph.edges)==12
Example #4
0
 def test_fingerprint_collisions(self):
     raise SkipTest
     # These are collisions with older versions, found by scanning the
     # pubchem database.
     cases = [
         ('SID_55127927.sdf', 'SID_56274343.sdf'),
         ('SID_55488598.sdf', 'SID_54258192.sdf'),
         ('SID_41893280.sdf', 'SID_41893278.sdf'),
         ('SID_40363570.sdf', 'SID_40363571.sdf'),
         ('SID_31646548.sdf', 'SID_31646545.sdf')
     ]
     for fn0, fn1 in cases:
         g0 = Molecule.from_file(os.path.join("input", fn0)).graph
         g1 = Molecule.from_file(os.path.join("input", fn1)).graph
         self.assertNotEqual(str(g0.fingerprint.data), str(g1.fingerprint.data))
Example #5
0
 def test_consistency(self):
     molecules = [
         Molecule.from_file("input/cyclopentane.xyz"),
         Molecule.from_file("input/funny.xyz"),
     ]
     for m in molecules:
         m.set_default_graph()
     dump_cml("output/tmp.cml", molecules)
     check = load_cml("output/tmp.cml")
     for m1, m2 in zip(molecules, check):
         self.assertEqual(m1.title, m2.title)
         self.assert_((m1.numbers==m2.numbers).all())
         self.assert_((m1.coordinates==m2.coordinates).all())
         self.assertEqual(m1.graph.num_vertices, m2.graph.num_vertices)
         self.assertEqual(set(m1.graph.edges), set(m2.graph.edges))
Example #6
0
 def test_tetra(self):
     molecule = Molecule.from_file("input/tetra.xyz")
     psf = PSFFile()
     psf.add_molecule(molecule)
     self.assert_(psf.bonds.shape[0] == 4)
     self.assert_(psf.bends.shape[0] == 6)
     psf.write_to_file("output/tetra.psf")
Example #7
0
        def test_one(xyz_fn, checks, reorder=False):
            mol = Molecule.from_file(xyz_fn)
            mol.set_default_graph()
            zmat_gen = ZMatrixGenerator(mol.graph)
            if reorder is False:
                self.assertArraysEqual(zmat_gen.new_index, numpy.arange(mol.size))
                self.assertArraysEqual(zmat_gen.old_index, numpy.arange(mol.size))

            zmat0 = zmat_gen.cart_to_zmat(mol.coordinates)
            for field, index, value in checks:
                self.assertAlmostEqual(zmat0[field][index], value, 2, "%s:%i %f!=%f" % (field,index,zmat0[field][index],value))

            numbers0, coordinates0 = zmat_to_cart(zmat0)
            mol0 = Molecule(numbers0, coordinates0)
            mol0.write_to_file("output/zmat_%s" % os.path.basename(xyz_fn))
            mol0.set_default_graph()
            zmat_gen0 = ZMatrixGenerator(mol0.graph)
            self.assertArraysEqual(zmat_gen0.new_index, numpy.arange(mol.size))
            self.assertArraysEqual(zmat_gen0.old_index, numpy.arange(mol.size))

            zmat1 = zmat_gen0.cart_to_zmat(mol0.coordinates)
            for field, index, value in checks:
                self.assertAlmostEqual(zmat1[field][index], value, 2, "%s:%i %f!=%f" % (field,index,zmat1[field][index],value))

            numbers1, coordinates1 = zmat_to_cart(zmat1)

            self.assertArraysEqual(numbers0, numbers1)
            self.assertArraysAlmostEqual(coordinates0, coordinates1, 1e-5)
Example #8
0
def setup(filename="ethane.pdb"):
    mol = Molecule.from_file(filename)

    # setup stuff
    mol.set_default_graph()
    mol.set_default_symbols()

    return mol
Example #9
0
 def test_improper(self):
     molecule = Molecule.from_file("input/formol.xyz")
     psf = PSFFile()
     psf.add_molecule(molecule)
     self.assertEqual(psf.impropers.shape, (3,4))
     test_block = set([(row[0], row[1]) for row in psf.impropers])
     self.assert_((0,1) in test_block)
     self.assert_((0,2) in test_block)
     self.assert_((0,3) in test_block)
     psf.write_to_file("output/tmp_impropers.psf")
     psf2 = PSFFile("output/tmp_impropers.psf")
     self.assertArraysEqual(psf.impropers, psf2.impropers)
Example #10
0
 def test_example_periodic(self):
     mol = Molecule.from_file("input/caplayer.cml")
     unit_cell = UnitCell(
         numpy.array([
             [14.218,  7.109,  0.0],
             [ 0.0  , 12.313,  0.0],
             [ 0.0  ,  0.0  , 10.0],
         ])*angstrom,
         numpy.array([True, True, False]),
     )
     dm = mol.distance_matrix
     dm = dm + dm.max()*numpy.identity(len(dm))
     mol = tune_geometry(mol.graph, mol, unit_cell)
     mol.write_to_file("output/caplayer.xyz")
Example #11
0
 def test_dump(self):
     m = Molecule.from_file("input/thf.xyz")
     psf = PSFFile()
     psf.add_molecule(m)
     psf.write_to_file("output/thf.psf")
Example #12
0
 def load_molecule(self, fn):
     molecule = Molecule.from_file(os.path.join("input", fn))
     if molecule.graph is None:
         molecule.set_default_graph()
     return molecule
Example #13
0
 def test_rotsym_ethane(self):
     molecule = Molecule.from_file("input/ethane.xyz")
     molecule.set_default_graph()
     rotsym = compute_rotsym(molecule, molecule.graph, threshold=0.01)
     self.assertEqual(rotsym, 6)
Example #14
0
 def test_rotsym_cyclopentane(self):
     molecule = Molecule.from_file("input/cyclopentane.xyz")
     molecule.set_default_graph()
     rotsym = compute_rotsym(molecule, molecule.graph)
     self.assertEqual(rotsym, 1)
Example #15
0
 def iter_test_molecules(self):
     for filename in ["tpa.xyz", "water.xyz", "thf_single.xyz"]:
         molecule = Molecule.from_file(os.path.join("input", filename))
         molecule.filename = filename
         molecule.set_default_graph()
         yield molecule