def test_are_equal(self):
     msc1 = MoleculeStructureComparator()
     mol1 = read_mol(os.path.join(test_dir, "t1.xyz"))
     mol2 = read_mol(os.path.join(test_dir, "t2.xyz"))
     mol3 = read_mol(os.path.join(test_dir, "t3.xyz"))
     self.assertFalse(msc1.are_equal(mol1, mol2))
     self.assertTrue(msc1.are_equal(mol2, mol3))
     thio1 = read_mol(os.path.join(test_dir, "thiophene1.xyz"))
     thio2 = read_mol(os.path.join(test_dir, "thiophene2.xyz"))
     # noinspection PyProtectedMember
     msc2 = MoleculeStructureComparator(
         priority_bonds=msc1._get_bonds(thio1))
     self.assertTrue(msc2.are_equal(thio1, thio2))
Ejemplo n.º 2
0
    def test_read_mol(self):
        test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                'test_files', "molecules")
        for fname in ("methane.log", "c60.xyz", "ethane.gjf"):
            filename = os.path.join(test_dir, fname)
            mol = read_mol(filename)
            self.assertIsInstance(mol, Molecule)

        for ext in [".xyz", ".json", ".gjf"]:
            fn = "smartio_mol_test" + ext
            write_mol(mol, fn)
            back = read_mol(fn)
            self.assertEqual(back, mol)
            os.remove(fn)
Ejemplo n.º 3
0
 def test_read_mol_babel(self):
     test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
                             'test_files', "molecules")
     for fname in ("ethane.mol", ):
         filename = os.path.join(test_dir, fname)
         mol = read_mol(filename)
         self.assertIsInstance(mol, Molecule)
Ejemplo n.º 4
0
 def test_read_mol(self):
     test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
                             'test_files', "molecules")
     for fname in ("methane.log", "c60.xyz", "ethane.gjf"):
         filename = os.path.join(test_dir, fname)
         mol = read_mol(filename)
         self.assertIsInstance(mol, Molecule)
Ejemplo n.º 5
0
 def test_group_molecules(self):
     mm = MoleculeMatcher(tolerance=0.001)
     with open(os.path.join(test_dir, "mol_list.txt")) as f:
         filename_list = [line.strip() for line in f.readlines()]
     mol_list = [read_mol(os.path.join(test_dir, f)) for f in filename_list]
     mol_groups = mm.group_molecules(mol_list)
     filename_groups = [[filename_list[mol_list.index(m)] for m in g]
                        for g in mol_groups]
     with open(os.path.join(test_dir, "grouped_mol_list.txt")) as f:
         grouped_text = f.read().strip()
     self.assertEqual(str(filename_groups), grouped_text)
 def test_get_bonds(self):
     mol1 = read_mol(os.path.join(test_dir, "t1.xyz"))
     msc = MoleculeStructureComparator()
     # noinspection PyProtectedMember
     bonds = msc._get_bonds(mol1)
     bonds_ref = [(0, 1), (0, 2), (0, 3), (0, 23), (3, 4), (3, 5), (5, 6),
                  (5, 7), (7, 8), (7, 9), (7, 21), (9, 10), (9, 11),
                  (9, 12), (12, 13), (12, 14), (12, 15), (15, 16), (15, 17),
                  (15, 18), (18, 19), (18, 20), (18, 21), (21, 22),
                  (21, 23), (23, 24), (23, 25)]
     self.assertEqual(bonds, bonds_ref)
     mol2 = read_mol(os.path.join(test_dir, "MgBH42.xyz"))
     bonds = msc._get_bonds(mol2)
     self.assertEqual(bonds, [(1, 3), (2, 3), (3, 4), (3, 5), (6, 8), (7, 8),
                              (8, 9), (8, 10)])
     msc = MoleculeStructureComparator(ignore_ionic_bond=False)
     bonds = msc._get_bonds(mol2)
     self.assertEqual(bonds, [(0, 1), (0, 2), (0, 3), (0, 5), (0, 6), (0, 7),
                              (0, 8), (0, 9), (1, 3), (2, 3), (3, 4), (3, 5),
                              (6, 8), (7, 8), (8, 9), (8, 10)])
Ejemplo n.º 7
0
 def test_cyclic(self):
     a = PointGroupAnalyzer(H2O2)
     self.assertEqual(a.sch_symbol, "C2")
     self.assertEqual(len(a.get_pointgroup()), 2)
     a = PointGroupAnalyzer(H2O)
     self.assertEqual(a.sch_symbol, "C2v")
     self.assertEqual(len(a.get_pointgroup()), 4)
     a = PointGroupAnalyzer(NH3)
     self.assertEqual(a.sch_symbol, "C3v")
     self.assertEqual(len(a.get_pointgroup()), 6)
     cs2 = read_mol(os.path.join(test_dir, "Carbon_Disulfide.xyz"))
     a = PointGroupAnalyzer(cs2, eigen_tolerance=0.001)
     self.assertEqual(a.sch_symbol, "C2v")
 def test_to_and_from_dict(self):
     msc1 = MoleculeStructureComparator()
     d1 = msc1.to_dict
     d2 = MoleculeStructureComparator.from_dict(d1).to_dict
     self.assertEqual(d1, d2)
     thio1 = read_mol(os.path.join(test_dir, "thiophene1.xyz"))
     # noinspection PyProtectedMember
     msc2 = MoleculeStructureComparator(
         bond_length_cap=0.2,
         priority_bonds=msc1._get_bonds(thio1),
         priority_cap=0.5)
     d1 = msc2.to_dict
     d2 = MoleculeStructureComparator.from_dict(d1).to_dict
     self.assertEqual(d1, d2)
Ejemplo n.º 9
0
    def fit_with_mapper(self, mapper):
        coords = [[0.000000, 0.000000, 0.000000],
                  [0.000000, 0.000000, 1.089000],
                  [1.026719, 0.000000, -0.363000],
                  [-0.513360, -0.889165, -0.363000],
                  [-0.513360, 0.889165, -0.363000]]
        mol1 = Molecule(["C", "H", "H", "H", "H"], coords)
        op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
        rotcoords = [op.operate(c) for c in coords]
        mol2 = Molecule(["C", "H", "H", "H", "H"], rotcoords)
        mm = MoleculeMatcher(mapper=mapper)
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "benzene1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "benzene2.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "benzene1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "t2.xyz"))
        self.assertFalse(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "c1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "c2.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "t3.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "t4.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "j1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "j2.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "ethene1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "ethene2.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "toluene1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "toluene2.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "cyclohexane1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "cyclohexane2.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mol1 = read_mol(os.path.join(test_dir, "oxygen1.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "oxygen2.xyz"))
        self.assertTrue(mm.fit(mol1, mol2))

        mm = MoleculeMatcher(tolerance=0.001, mapper=mapper)
        mol1 = read_mol(os.path.join(test_dir, "t3.xyz"))
        mol2 = read_mol(os.path.join(test_dir, "t4.xyz"))
        self.assertFalse(mm.fit(mol1, mol2))
Ejemplo n.º 10
0
 def test_get_rmsd(self):
     mm = MoleculeMatcher()
     mol1 = read_mol(os.path.join(test_dir, "t3.xyz"))
     mol2 = read_mol(os.path.join(test_dir, "t4.xyz"))
     self.assertEqual('{0:7.3}'.format(mm.get_rmsd(mol1, mol2)), "0.00488")
Ejemplo n.º 11
0
 def test_cdi_23(self):
     mm = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper())
     mol1 = read_mol(os.path.join(test_dir, "cdi_23_1.xyz"))
     mol2 = read_mol(os.path.join(test_dir, "cdi_23_2.xyz"))
     self.assertFalse(mm.fit(mol1, mol2))
Ejemplo n.º 12
0
 def test_thiane_ethynyl(self):
     mm = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper())
     mol1 = read_mol(os.path.join(test_dir, "thiane_ethynyl1.sdf"))
     mol2 = read_mol(os.path.join(test_dir, "thiane_ethynyl2.sdf"))
     self.assertFalse(mm.fit(mol1, mol2))
Ejemplo n.º 13
0
 def test_strange_inchi(self):
     mm = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper())
     mol1 = read_mol(os.path.join(test_dir, "k1.sdf"))
     mol2 = read_mol(os.path.join(test_dir, "k2.sdf"))
     self.assertTrue(mm.fit(mol1, mol2))