예제 #1
0
 def test_thiane_ethynyl(self):
     mm = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper())
     mol1 = Molecule.from_file(os.path.join(test_dir,
                                            "thiane_ethynyl1.sdf"))
     mol2 = Molecule.from_file(os.path.join(test_dir,
                                            "thiane_ethynyl2.sdf"))
     self.assertFalse(mm.fit(mol1, mol2))
    def test_to_and_from_dict(self):
        mm = MoleculeMatcher(tolerance=0.5,
                             mapper=InchiMolAtomMapper(angle_tolerance=50.0))
        d = mm.as_dict()
        mm2 = MoleculeMatcher.from_dict(d)
        self.assertEqual(d, mm2.as_dict())

        mm = MoleculeMatcher(tolerance=0.5, mapper=IsomorphismMolAtomMapper())
        d = mm.as_dict()
        mm2 = MoleculeMatcher.from_dict(d)
        self.assertEqual(d, mm2.as_dict())
예제 #3
0
    def add_if_belongs(self, cand_snl, exact_match=True):

        # no need to compare if structue is different
        if cand_snl.snlgroup_key != self.canonical_snl.snlgroup_key:
            return False

        # make sure the structure is not already in all_structures
        if cand_snl.snl_id in self.all_snl_ids:
            print('WARNING: add_if_belongs() has detected that you are ' \
                  'trying to add the same SNL id twice!')
            return False

        if exact_match:
            mm = MoleculeMatcher(
                tolerance=0.01, mapper=InchiMolAtomMapper(angle_tolerance=5.0))

            if not mm.fit(cand_snl.structure, self.canonical_structure):
                return False

        # everything checks out, add to the group
        self.all_snl_ids.append(cand_snl.snl_id)
        self.updated_at = datetime.datetime.utcnow()

        return True
 def test_cdi_23(self):
     mm = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper())
     mol1 = Molecule.from_file(os.path.join(test_dir, "cdi_23_1.xyz"))
     mol2 = Molecule.from_file(os.path.join(test_dir, "cdi_23_2.xyz"))
     self.assertFalse(mm.fit(mol1, mol2))
 def test_strange_inchi(self):
     mm = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper())
     mol1 = Molecule.from_file(os.path.join(test_dir, "k1.sdf"))
     mol2 = Molecule.from_file(os.path.join(test_dir, "k2.sdf"))
     self.assertTrue(mm.fit(mol1, mol2))
 def test_fit(self):
     self.fit_with_mapper(IsomorphismMolAtomMapper())
     self.fit_with_mapper(InchiMolAtomMapper())
 def test_thiane(self):
     mm = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper())
     mol1 = read_mol(os.path.join(test_dir, "thiane1.sdf"))
     mol2 = read_mol(os.path.join(test_dir, "thiane2.sdf"))
     self.assertFalse(mm.fit(mol1, mol2))
예제 #8
0
species_list = []
coords_list = []
for line in f:
    line_splitted = line.split()
    species_list.append(line_splitted[0])
    line_splitted.pop(0)
    line_splitted_float = []
    for coord in line_splitted:
        coord = float(coord)
        line_splitted_float.append(coord)
    coords_list.append(line_splitted_float)
mol = Molecule(species_list, coords_list)
"""
Find equivalent non-H sites then store a list of non-H atom without equivalent sites (label_list).
"""
mapper = InchiMolAtomMapper()
labelInfo = mapper._inchi_labels(BabelMolAdaptor(mol)._obmol)
# print(labelInfo,len(labelInfo))
label_list = list(labelInfo[0])
for equivalent_group in labelInfo[1]:
    for atomLabel in range(0, len(equivalent_group)):
        if atomLabel > 0:
            label_list.remove(labelInfo[0][equivalent_group[atomLabel] - 1])
print("Atomic numbers of non-H non-equivalent sites are: ", label_list)
"""
Find a list of sites that can be substituted using functional groups. These sites are hydrogen that
directly bound to either C or N atoms.
"""
substitute_sitelist = []
for i in label_list:
    if mol[i - 1].species_string in ["C", "N"]: