Esempio n. 1
0
 def testHelium(self):
     """
     adjlist: Test that the adjlist reading and writing works with Helium.
     """
     smiles = '[He]'
     inchi = 'InChI=1S/He'
     adjlist = '1 He u0 p1 c0'
     adjlist_old = '1 He 0'
     adjlist_intermediate = '1 He 0 1'
     
     mol_smiles = Molecule().fromSMILES(smiles)
     mol_inchi = Molecule().fromInChI(inchi)
     mol = Molecule().fromAdjacencyList(adjlist)
     mol_old = Molecule().fromAdjacencyList(adjlist_old)
     mol_intermediate = Molecule().fromAdjacencyList(adjlist_intermediate)
     
     # Isomorphic check
     self.assertTrue(mol_smiles.isIsomorphic(mol))
     self.assertTrue(mol_smiles.isIsomorphic(mol_inchi))
     self.assertTrue(mol_smiles.isIsomorphic(mol_old))
     self.assertTrue(mol_smiles.isIsomorphic(mol_intermediate))
     
     # Adjlist check
     self.assertEqual(mol_smiles.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol_inchi.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol_old.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol_intermediate.toAdjacencyList().strip(), adjlist)
     
     self.assertEqual(mol.toSMILES(),smiles)
     self.assertEqual(mol.toInChI(),'InChI=1S/He')
Esempio n. 2
0
    def testAdjacencyList(self):
        """
        adjlist: Check the adjacency list read/write functions for a full molecule.
        """
        molecule1 = Molecule().fromAdjacencyList("""
        1  C u0 {2,D} {7,S} {8,S}
        2  C u0 {1,D} {3,S} {9,S}
        3  C u0 {2,S} {4,D} {10,S}
        4  C u0 {3,D} {5,S} {11,S}
        5  C u1 {4,S} {6,S} {12,S}
        6  C u0 {5,S} {13,S} {14,S} {15,S}
        7  H u0 {1,S}
        8  H u0 {1,S}
        9  H u0 {2,S}
        10 H u0 {3,S}
        11 H u0 {4,S}
        12 H u0 {5,S}
        13 H u0 {6,S}
        14 H u0 {6,S}
        15 H u0 {6,S}
        """)
        molecule2 = Molecule().fromSMILES('C=CC=C[CH]C')
        self.assertTrue(molecule1.isIsomorphic(molecule2))
        self.assertTrue(molecule2.isIsomorphic(molecule1))

        #Test that charges are correctly stored and written with adjacency lists
        adjlist3 = """
1 C u0 p1 c-1 {2,T}
2 O u0 p1 c+1 {1,T}
"""
        molecule3 = Molecule().fromAdjacencyList(adjlist3)
        self.assertEquals(molecule3.atoms[0].charge, -1)
        self.assertEquals(molecule3.atoms[1].charge, 1)
        adjlist4 = molecule3.toAdjacencyList()
        self.assertEquals(adjlist3.strip(), adjlist4.strip())
Esempio n. 3
0
    def testHelium(self):
        """
        adjlist: Test that the adjlist reading and writing works with Helium.
        """
        smiles = '[He]'
        inchi = 'InChI=1S/He'
        adjlist = '1 He u0 p1 c0'
        adjlist_old = '1 He 0'
        adjlist_intermediate = '1 He 0 1'

        mol_smiles = Molecule().fromSMILES(smiles)
        mol_inchi = Molecule().fromInChI(inchi)
        mol = Molecule().fromAdjacencyList(adjlist)
        mol_old = Molecule().fromAdjacencyList(adjlist_old)
        mol_intermediate = Molecule().fromAdjacencyList(adjlist_intermediate)

        # Isomorphic check
        self.assertTrue(mol_smiles.isIsomorphic(mol))
        self.assertTrue(mol_smiles.isIsomorphic(mol_inchi))
        self.assertTrue(mol_smiles.isIsomorphic(mol_old))
        self.assertTrue(mol_smiles.isIsomorphic(mol_intermediate))

        # Adjlist check
        self.assertEqual(mol_smiles.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol_inchi.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol_old.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol_intermediate.toAdjacencyList().strip(), adjlist)

        self.assertEqual(mol.toSMILES(), smiles)
        self.assertEqual(mol.toInChI(), 'InChI=1S/He')
Esempio n. 4
0
    def testAdjacencyList(self):
        """
        adjlist: Check the adjacency list read/write functions for a full molecule.
        """
        molecule1 = Molecule().fromAdjacencyList("""
        1  C u0 {2,D} {7,S} {8,S}
        2  C u0 {1,D} {3,S} {9,S}
        3  C u0 {2,S} {4,D} {10,S}
        4  C u0 {3,D} {5,S} {11,S}
        5  C u1 {4,S} {6,S} {12,S}
        6  C u0 {5,S} {13,S} {14,S} {15,S}
        7  H u0 {1,S}
        8  H u0 {1,S}
        9  H u0 {2,S}
        10 H u0 {3,S}
        11 H u0 {4,S}
        12 H u0 {5,S}
        13 H u0 {6,S}
        14 H u0 {6,S}
        15 H u0 {6,S}
        """)
        molecule2 = Molecule().fromSMILES('C=CC=C[CH]C')
        self.assertTrue(molecule1.isIsomorphic(molecule2))
        self.assertTrue(molecule2.isIsomorphic(molecule1))

        #Test that charges are correctly stored and written with adjacency lists
        adjlist3 = """
1 C u0 p1 c-1 {2,T}
2 O u0 p1 c+1 {1,T}
"""
        molecule3 = Molecule().fromAdjacencyList(adjlist3)
        self.assertEquals(molecule3.atoms[0].charge, -1)
        self.assertEquals(molecule3.atoms[1].charge, 1)
        adjlist4 = molecule3.toAdjacencyList()
        self.assertEquals(adjlist3.strip(), adjlist4.strip())
Esempio n. 5
0
 def testIsomorphism(self):
     """
     Check the graph isomorphism functions.
     """
     molecule1 = Molecule().fromSMILES('C=CC=C[CH]C')
     molecule2 = Molecule().fromSMILES('C[CH]C=CC=C')
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
Esempio n. 6
0
 def testIsomorphism(self):
     """
     Check the graph isomorphism functions.
     """
     molecule1 = Molecule().fromSMILES('C=CC=C[CH]C')
     molecule2 = Molecule().fromSMILES('C[CH]C=CC=C')
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
Esempio n. 7
0
def test(lines, smiles, params):
    """
    checks if the given parameters allow proper identification of the image
    based on comparison with the smiles and the use of the set of parameters
    """

    m = Molecule().fromSMILES(smiles)  #make actual molecule

    try:
        lines = lines_to_graph(lines, params)
    except:
        print lines, lines_to_graph(lines, params)
        raise TypeError

    adj = getAdjMatrix(lines)
    atomnames = ['C'] * adj.shape[0]
    try:
        molecule = Adjacency(adj, atomnames)

        molecule.addHydrogens()
        rmgmol = molecule.toRMGmol()
    except:
        #print 'failed to generate molecule'
        print smiles
        plt.figure()
        plotLines(lines)
        return False
    boo = m.isIsomorphic(rmgmol)
    if not boo:
        pass
        print smiles
        plt.figure()
        plotLines(lines)
    return boo
Esempio n. 8
0
def test_isotope_subgraph_isomorphism_molecule_and_group():
    """
    Checks that subgraph isomorphism works with enriched molecules and groups
    """
    methanei = Molecule().fromAdjacencyList("""
    1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S}
    2 H u0 p0 c0 {1,S}
    3 H u0 p0 c0 {1,S}
    4 H u0 p0 c0 {1,S}
    5 H u0 p0 c0 {1,S}
    """)
    methane = Molecule().fromAdjacencyList("""
    1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
    2 H u0 p0 c0 {1,S}
    3 H u0 p0 c0 {1,S}
    4 H u0 p0 c0 {1,S}
    5 H u0 p0 c0 {1,S}
    """)
    group_methane = Group().fromAdjacencyList("""
    1 C  u0 {2,S} {3,S} {4,S} {5,S}
    2 H  u0 {1,S}
    3 H  u0 {1,S}
    4 H  u0 {1,S}
    5 H  u0 {1,S}
    """)
    assert_true(methanei.isSubgraphIsomorphic(group_methane))
    assert_true(methane.isSubgraphIsomorphic(group_methane))
    assert_false(methanei.isIsomorphic(methane))
Esempio n. 9
0
    def testToAdjacencyList(self):
        """
        adjlist: Test the Molecule.toAdjacencyList() method.
        """
        inter_adjlist = """
1 *1 C 1 0  {2,S} {3,S} {4,S}
2    H 0 0  {1,S}
3    H 0 0  {1,S}
4 *2 N 0 0 {1,S} {5,S} {6,D}
5    O 0 3 {4,S}
6    O 0 2 {4,D}
            """

        adjlist = """
1 *1 C u1 p0 c0  {2,S} {3,S} {4,S}
2    H u0 p0 c0  {1,S}
3    H u0 p0 c0  {1,S}
4 *2 N u0 p0 c+1 {1,S} {5,S} {6,D}
5    O u0 p3 c-1 {4,S}
6    O u0 p2 c0  {4,D}
            """
        molecule = Molecule().fromAdjacencyList(adjlist)
        molecule2 = Molecule().fromAdjacencyList(inter_adjlist)
        adjlist_1 = molecule.toAdjacencyList(removeH=False)
        self.assertEqual(adjlist_1, molecule2.toAdjacencyList())
        newMolecule = Molecule().fromAdjacencyList(adjlist_1)
        self.assertTrue(molecule.isIsomorphic(newMolecule))
Esempio n. 10
0
    def testToAdjacencyList(self):
        """
        adjlist: Test the Molecule.toAdjacencyList() method.
        """
        inter_adjlist = """
1 *1 C 1 0  {2,S} {3,S} {4,S}
2    H 0 0  {1,S}
3    H 0 0  {1,S}
4 *2 N 0 0 {1,S} {5,S} {6,D}
5    O 0 3 {4,S}
6    O 0 2 {4,D}
            """
            
        adjlist = """
1 *1 C u1 p0 c0  {2,S} {3,S} {4,S}
2    H u0 p0 c0  {1,S}
3    H u0 p0 c0  {1,S}
4 *2 N u0 p0 c+1 {1,S} {5,S} {6,D}
5    O u0 p3 c-1 {4,S}
6    O u0 p2 c0  {4,D}
            """
        molecule = Molecule().fromAdjacencyList(adjlist)
        molecule2 = Molecule().fromAdjacencyList(inter_adjlist)
        adjlist_1 = molecule.toAdjacencyList(removeH=False)
        self.assertEqual(adjlist_1,molecule2.toAdjacencyList())
        newMolecule = Molecule().fromAdjacencyList(adjlist_1)
        self.assertTrue(molecule.isIsomorphic(newMolecule))
def test_isotope_subgraph_isomorphism_molecule_and_group():
    """
    Checks that subgraph isomorphism works with enriched molecules and groups
    """
    methanei = Molecule().fromAdjacencyList("""
    1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S}
    2 H u0 p0 c0 {1,S}
    3 H u0 p0 c0 {1,S}
    4 H u0 p0 c0 {1,S}
    5 H u0 p0 c0 {1,S}
    """)
    methane = Molecule().fromAdjacencyList("""
    1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
    2 H u0 p0 c0 {1,S}
    3 H u0 p0 c0 {1,S}
    4 H u0 p0 c0 {1,S}
    5 H u0 p0 c0 {1,S}
    """)
    group_methane = Group().fromAdjacencyList("""
    1 C  u0 {2,S} {3,S} {4,S} {5,S}
    2 H  u0 {1,S}
    3 H  u0 {1,S}
    4 H  u0 {1,S}
    5 H  u0 {1,S}
    """)
    assert_true(methanei.isSubgraphIsomorphic(group_methane))
    assert_true(methane.isSubgraphIsomorphic(group_methane))
    assert_false(methanei.isIsomorphic(methane))
Esempio n. 12
0
 def compare(self, adjlist, smiles):
     """
     Compare result of parsing an adjacency list and a SMILES string.
     
     The adjacency list is presumed correct and this is to test the SMILES parser.
     """
     mol1 = Molecule().fromAdjacencyList(adjlist)
     mol2 = Molecule(SMILES=smiles)
     self.assertTrue(mol1.isIsomorphic(mol2), "Parsing SMILES={!r} gave unexpected molecule\n{}".format(smiles, mol2.toAdjacencyList()))
    def test_assign_representative_molecule(self):

        smiles_like = 'RCR'
        fragment = afm.fragment.Fragment().from_SMILES_like_string(smiles_like)

        fragment.assign_representative_molecule()

        expected_repr_mol = Molecule().fromSMILES('CCCCC')

        self.assertTrue(expected_repr_mol.isIsomorphic(fragment.mol_repr))
Esempio n. 14
0
 def testFromOldAdjacencyList6(self):
     """
     Test we can read an old style adjacency list with implicit hydrogens 1
     """
     adjlist = """
     1 C 4T
     """  
     adjlist_new = """
     1 C u2 p1 c0 
     """
     molecule = Molecule().fromAdjacencyList(adjlist)
     molecule_new = Molecule().fromAdjacencyList(adjlist_new)
     self.assertTrue(molecule.isIsomorphic(molecule_new))
Esempio n. 15
0
 def testFromOldAdjacencyList6(self):
     """
     Test we can read an old style adjacency list with implicit hydrogens 1
     """
     adjlist = """
     1 C 4T
     """
     adjlist_new = """
     1 C u2 p1 c0 
     """
     molecule = Molecule().fromAdjacencyList(adjlist)
     molecule_new = Molecule().fromAdjacencyList(adjlist_new)
     self.assertTrue(molecule.isIsomorphic(molecule_new))
def testMultiplicity_mol_not_specified_mol_not_specified():
    '''
    Both multiplicities not set.
    '''
    mol = Molecule().fromAdjacencyList("""
    1 C u2 p0 c0
    """, saturateH=True)
    
    mol2 = Molecule().fromAdjacencyList("""
    1 C u2 p0 c0
    """, saturateH=True)
    
    assert_true(mol.isIsomorphic(mol2))
    assert_true(len(mol.findIsomorphism(mol2)) > 0)
Esempio n. 17
0
def testMultiplicity_mol_not_specified_mol_not_specified():
    '''
    Both multiplicities not set.
    '''
    mol = Molecule().fromAdjacencyList("""
    1 C u2 p0 c0
    """, saturateH=True)
    
    mol2 = Molecule().fromAdjacencyList("""
    1 C u2 p0 c0
    """, saturateH=True)
    
    assert_true(mol.isIsomorphic(mol2))
    assert_true(len(mol.findIsomorphism(mol2)) > 0)
Esempio n. 18
0
 def testAdjacencyList(self):
     """
     adjlist: Check the adjacency list read/write functions for a full molecule.
     """
     molecule1 = Molecule().fromAdjacencyList("""
     1  C u0 {2,D} {7,S} {8,S}
     2  C u0 {1,D} {3,S} {9,S}
     3  C u0 {2,S} {4,D} {10,S}
     4  C u0 {3,D} {5,S} {11,S}
     5  C u1 {4,S} {6,S} {12,S}
     6  C u0 {5,S} {13,S} {14,S} {15,S}
     7  H u0 {1,S}
     8  H u0 {1,S}
     9  H u0 {2,S}
     10 H u0 {3,S}
     11 H u0 {4,S}
     12 H u0 {5,S}
     13 H u0 {6,S}
     14 H u0 {6,S}
     15 H u0 {6,S}
     """)
     molecule2 = Molecule().fromSMILES('C=CC=C[CH]C')
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
Esempio n. 19
0
    def testPickle(self):
        """
        Test that a Molecule object can be successfully pickled and
        unpickled with no loss of information.
        """
        molecule0 = Molecule().fromSMILES('C=CC=C[CH2]C')
        molecule0.updateAtomTypes()
        molecule0.updateConnectivityValues()
        import cPickle
        molecule = cPickle.loads(cPickle.dumps(molecule0))

        self.assertEqual(len(molecule0.atoms), len(molecule.atoms))
        self.assertEqual(molecule0.getFormula(), molecule.getFormula())
        self.assertTrue(molecule0.isIsomorphic(molecule))
        self.assertTrue(molecule.isIsomorphic(molecule0))
Esempio n. 20
0
 def testFromOldAdjacencyList5(self):
     """
     Test we can read an old style adjacency list with implicit hydrogens 5
     """
     adjlist = """
     1 C 2S {2,T}
     2 O 2S {1,T}
     """
     adjlist_new = """
     1 C u0 p1 c-1 {2,T}
     2 O u0 p1 c+1 {1,T}
     """
     molecule = Molecule().fromAdjacencyList(adjlist)
     molecule_new = Molecule().fromAdjacencyList(adjlist_new)
     self.assertTrue(molecule.isIsomorphic(molecule_new))
Esempio n. 21
0
 def testFromOldAdjacencyList2(self):
     """
     Test we can read an old style adjacency list with implicit hydrogens 2
     """
     adjlist = """
     1 C 2S
     """  
     adjlist_new = """
     1 C u0 p1 c0 {2,S} {3,S}
     2 H u0 p0 c0 {1,S}
     3 H u0 p0 c0 {1,S}
     """
     molecule = Molecule().fromAdjacencyList(adjlist)  
     molecule_new = Molecule().fromAdjacencyList(adjlist_new)
     self.assertTrue(molecule.isIsomorphic(molecule_new))
Esempio n. 22
0
 def testFromOldAdjacencyList2(self):
     """
     Test we can read an old style adjacency list with implicit hydrogens 2
     """
     adjlist = """
     1 C 2S
     """
     adjlist_new = """
     1 C u0 p1 c0 {2,S} {3,S}
     2 H u0 p0 c0 {1,S}
     3 H u0 p0 c0 {1,S}
     """
     molecule = Molecule().fromAdjacencyList(adjlist)
     molecule_new = Molecule().fromAdjacencyList(adjlist_new)
     self.assertTrue(molecule.isIsomorphic(molecule_new))
Esempio n. 23
0
 def testPickle(self):
     """
     Test that a Molecule object can be successfully pickled and
     unpickled with no loss of information.
     """
     molecule0 = Molecule().fromSMILES('C=CC=C[CH2]C')
     molecule0.updateAtomTypes()
     molecule0.updateConnectivityValues()
     import cPickle
     molecule = cPickle.loads(cPickle.dumps(molecule0))
     
     self.assertEqual(len(molecule0.atoms), len(molecule.atoms))
     self.assertEqual(molecule0.getFormula(), molecule.getFormula())
     self.assertTrue(molecule0.isIsomorphic(molecule))
     self.assertTrue(molecule.isIsomorphic(molecule0))
Esempio n. 24
0
 def testFromOldAdjacencyList5(self):
     """
     Test we can read an old style adjacency list with implicit hydrogens 5
     """
     adjlist = """
     1 C 2S {2,T}
     2 O 2S {1,T}
     """  
     adjlist_new = """
     1 C u0 p1 c-1 {2,T}
     2 O u0 p1 c+1 {1,T}
     """
     molecule = Molecule().fromAdjacencyList(adjlist)  
     molecule_new = Molecule().fromAdjacencyList(adjlist_new)
     self.assertTrue(molecule.isIsomorphic(molecule_new))    
Esempio n. 25
0
 def testAdjacencyList(self):
     """
     Check the adjacency list read/write functions for a full molecule.
     """
     molecule1 = Molecule().fromAdjacencyList("""
     1  C u0 p0 c0 {2,D} {7,S} {8,S}
     2  C u0 p0 c0 {1,D} {3,S} {9,S}
     3  C u0 p0 c0 {2,S} {4,D} {10,S}
     4  C u0 p0 c0 {3,D} {5,S} {11,S}
     5  C u1 {4,S} {6,S} {12,S}
     6  C u0 p0 c0 {5,S} {13,S} {14,S} {15,S}
     7  H u0 p0 c0 {1,S}
     8  H u0 p0 c0 {1,S}
     9  H u0 p0 c0 {2,S}
     10 H u0 p0 c0 {3,S}
     11 H u0 p0 c0 {4,S}
     12 H u0 p0 c0 {5,S}
     13 H u0 p0 c0 {6,S}
     14 H u0 p0 c0 {6,S}
     15 H u0 p0 c0 {6,S}
     """)
     molecule2 = Molecule().fromSMILES('C=CC=C[CH]C')
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
Esempio n. 26
0
    def test_lone_pair_retention(self):
        """Test that we don't lose any lone pairs on round trip RDKit conversion."""
        mol = Molecule().fromAdjacencyList("""
1 C u0 p0 c0 {2,D} {3,S} {4,S}
2 O u0 p2 c0 {1,D}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
""")
        rdmol = toRDKitMol(mol)

        try:
            mol2 = fromRDKitMol(Molecule(), rdmol)
        except AtomTypeError as e:
            self.fail('Could not convert from RDKitMol: ' + e.message)
        else:
            self.assertTrue(mol.isIsomorphic(mol2))
def testMultiplicity_mol_mol_identical_multiplicity():
    '''
    identical multiplicity for both molecules set by user.
    '''
    mol = Molecule().fromAdjacencyList("""
    multiplicity 3
    1 C u2 p0 c0
    """, saturateH=True)
    
    mol2 = Molecule().fromAdjacencyList("""
    multiplicity 3
    1 C u2 p0 c0
    """, saturateH=True)
    
    assert_true(mol.isIsomorphic(mol2))
    assert_true(len(mol.findIsomorphism(mol2)) > 0)
Esempio n. 28
0
def testMultiplicity_mol_mol_identical_multiplicity():
    '''
    identical multiplicity for both molecules set by user.
    '''
    mol = Molecule().fromAdjacencyList("""
    multiplicity 3
    1 C u2 p0 c0
    """, saturateH=True)
    
    mol2 = Molecule().fromAdjacencyList("""
    multiplicity 3
    1 C u2 p0 c0
    """, saturateH=True)
    
    assert_true(mol.isIsomorphic(mol2))
    assert_true(len(mol.findIsomorphism(mol2)) > 0)
def testMultiplicity_mol_mol_distinct_multiplicity():
    '''
    distinct multiplicity for both molecules set by user.
    '''
    mol = Molecule().fromAdjacencyList("""
    multiplicity 1
    1 C u1 p0 c0 {2,S}
    2 C u0 p0 c0 {1,S} {3,S}
    3 C u1 p0 c0 {2,S}
    """, saturateH=True)
    
    mol2 = Molecule().fromAdjacencyList("""
    multiplicity 3
    1 C u1 p0 c0 {2,S}
    2 C u0 p0 c0 {1,S} {3,S}
    3 C u1 p0 c0 {2,S}
    """, saturateH=True)
    
    assert_false(mol.isIsomorphic(mol2))
    assert_false(len(mol.findIsomorphism(mol2)) > 0)
Esempio n. 30
0
def testMultiplicity_mol_mol_distinct_multiplicity():
    '''
    distinct multiplicity for both molecules set by user.
    '''
    mol = Molecule().fromAdjacencyList("""
    multiplicity 1
    1 C u1 p0 c0 {2,S}
    2 C u0 p0 c0 {1,S} {3,S}
    3 C u1 p0 c0 {2,S}
    """, saturateH=True)
    
    mol2 = Molecule().fromAdjacencyList("""
    multiplicity 3
    1 C u1 p0 c0 {2,S}
    2 C u0 p0 c0 {1,S} {3,S}
    3 C u1 p0 c0 {2,S}
    """, saturateH=True)
    
    assert_false(mol.isIsomorphic(mol2))
    assert_false(len(mol.findIsomorphism(mol2)) > 0)
#    min_dist_merge = params[0]
#    min_angle_merge = params[1]
#    min_width_merge = params[2]
#    split_tol = params[3]
#    min_dist_bond = params[4]
#    max_dist_bond = params[5]
#    max_angle_bond = params[6]
#    node_radius = params[7]
lines = lines_to_graph(lines, [0.08, .4, 0.2, 0.2, 0.1, 0.3, 0.3, .2])
#lines = lines_to_graph(lines_final, [0.05,.4,.1,0.2,0.06,0.8,0.1,.2])
print[line.order for line in lines]

plotLines(lines)
#plt.xlim((0, get_image_size(image)[1]/imdim))
#plt.ylim(( get_image_size(image)[0]/imdim,0))
print len(lines)
for line in lines:
    print line.pts
plt.title('Probabilistic Hough')

adj = getAdjMatrix(lines)
print adj
atomnames = ['C'] * adj.shape[0]
molecule = Adjacency(adj, atomnames)
molecule.addHydrogens()
rmgmol = molecule.toRMGmol()
print rmgmol.toSMILES()

print m.isIsomorphic(rmgmol)
Esempio n. 32
0
    def testVariousSpinAdjlists(self):
        """
        adjlist: Test that molecules with old or intermediate adjacency list formats containing unusual 
        spin states can get converted to the proper new adjlist format.
        """
        
        adjlist_2S = """
1 C 2S 0 {2,S} {3,S}
2 H 0  0 {1,S}
3 H 0  0 {1,S}
"""
        adjlist_2S_new ="""
1 C u0 p1 c0  {2,S} {3,S}
2 H u0 p0 c0  {1,S}
3 H u0 p0 c0  {1,S}
"""
        mol_2S = Molecule().fromAdjacencyList(adjlist_2S)
        mol_2S_new = Molecule().fromAdjacencyList(adjlist_2S_new)
        self.assertTrue(mol_2S.isIsomorphic(mol_2S_new))
        
        adjlist_2T = """
1 C 2T 0 {2,S} {3,S}
2 H 0  0 {1,S}
3 H 0  0 {1,S}
"""
        adjlist_2T_new ="""
1 C u2 p0 c0  {2,S} {3,S}
2 H u0 p0 c0  {1,S}
3 H u0 p0 c0  {1,S}
"""
        mol_2T = Molecule().fromAdjacencyList(adjlist_2T)
        mol_2T_new = Molecule().fromAdjacencyList(adjlist_2T_new)
        self.assertTrue(mol_2T.isIsomorphic(mol_2T_new))

        adjlist_3D = """
1 C 3D 0 {2,S}
2 H 0  0 {1,S}
"""
        adjlist_3D_new = """
1 C u1 p1 c0  {2,S}
2 H u0 p0 c0  {1,S}
"""
        mol_3D = Molecule().fromAdjacencyList(adjlist_3D)
        mol_3D_new = Molecule().fromAdjacencyList(adjlist_3D_new)
        self.assertTrue(mol_3D.isIsomorphic(mol_3D_new))

        adjlist_3Q = """
1 N 3Q 1
"""
        adjlist_3Q_new = """
1 N u3 p1 c0 
"""
        mol_3Q = Molecule().fromAdjacencyList(adjlist_3Q)
        mol_3Q_new = Molecule().fromAdjacencyList(adjlist_3Q_new)
        self.assertTrue(mol_3Q.isIsomorphic(mol_3Q_new))
        
        adjlist_4S = """
1 C 4S 0
        """
        adjlist_4S_new = """
1 C u0 p2 c0
"""
        mol_4S = Molecule().fromAdjacencyList(adjlist_4S)
        mol_4S_new = Molecule().fromAdjacencyList(adjlist_4S_new)
        self.assertTrue(mol_4S.isIsomorphic(mol_4S_new))
        
        adjlist_4T = """
1 C 4T 0
"""
        adjlist_4T_new = """
1 C u2 p1 c0
"""
        mol_4T = Molecule().fromAdjacencyList(adjlist_4T)
        mol_4T_new = Molecule().fromAdjacencyList(adjlist_4T_new)
        self.assertTrue(mol_4T.isIsomorphic(mol_4T_new))
        
        adjlist_4V = """
1 C 4V 0
"""
        adjlist_4V_new ="""
1 C u4 p0 c0        
"""
        mol_4V = Molecule().fromAdjacencyList(adjlist_4V)
        mol_4V_new = Molecule().fromAdjacencyList(adjlist_4V_new)
        self.assertTrue(mol_4V.isIsomorphic(mol_4V_new))
Esempio n. 33
0
    def testVariousSpinAdjlists(self):
        """
        adjlist: Test that molecules with old or intermediate adjacency list formats containing unusual 
        spin states can get converted to the proper new adjlist format.
        """

        adjlist_2S = """
1 C 2S 0 {2,S} {3,S}
2 H 0  0 {1,S}
3 H 0  0 {1,S}
"""
        adjlist_2S_new = """
1 C u0 p1 c0  {2,S} {3,S}
2 H u0 p0 c0  {1,S}
3 H u0 p0 c0  {1,S}
"""
        mol_2S = Molecule().fromAdjacencyList(adjlist_2S)
        mol_2S_new = Molecule().fromAdjacencyList(adjlist_2S_new)
        self.assertTrue(mol_2S.isIsomorphic(mol_2S_new))

        adjlist_2T = """
1 C 2T 0 {2,S} {3,S}
2 H 0  0 {1,S}
3 H 0  0 {1,S}
"""
        adjlist_2T_new = """
1 C u2 p0 c0  {2,S} {3,S}
2 H u0 p0 c0  {1,S}
3 H u0 p0 c0  {1,S}
"""
        mol_2T = Molecule().fromAdjacencyList(adjlist_2T)
        mol_2T_new = Molecule().fromAdjacencyList(adjlist_2T_new)
        self.assertTrue(mol_2T.isIsomorphic(mol_2T_new))

        adjlist_3D = """
1 C 3D 0 {2,S}
2 H 0  0 {1,S}
"""
        adjlist_3D_new = """
1 C u1 p1 c0  {2,S}
2 H u0 p0 c0  {1,S}
"""
        mol_3D = Molecule().fromAdjacencyList(adjlist_3D)
        mol_3D_new = Molecule().fromAdjacencyList(adjlist_3D_new)
        self.assertTrue(mol_3D.isIsomorphic(mol_3D_new))

        adjlist_3Q = """
1 N 3Q 1
"""
        adjlist_3Q_new = """
1 N u3 p1 c0 
"""
        mol_3Q = Molecule().fromAdjacencyList(adjlist_3Q)
        mol_3Q_new = Molecule().fromAdjacencyList(adjlist_3Q_new)
        self.assertTrue(mol_3Q.isIsomorphic(mol_3Q_new))

        adjlist_4S = """
1 C 4S 0
        """
        adjlist_4S_new = """
1 C u0 p2 c0
"""
        mol_4S = Molecule().fromAdjacencyList(adjlist_4S)
        mol_4S_new = Molecule().fromAdjacencyList(adjlist_4S_new)
        self.assertTrue(mol_4S.isIsomorphic(mol_4S_new))

        adjlist_4T = """
1 C 4T 0
"""
        adjlist_4T_new = """
1 C u2 p1 c0
"""
        mol_4T = Molecule().fromAdjacencyList(adjlist_4T)
        mol_4T_new = Molecule().fromAdjacencyList(adjlist_4T_new)
        self.assertTrue(mol_4T.isIsomorphic(mol_4T_new))

        adjlist_4V = """
1 C 4V 0
"""
        adjlist_4V_new = """
1 C u4 p0 c0        
"""
        mol_4V = Molecule().fromAdjacencyList(adjlist_4V)
        mol_4V_new = Molecule().fromAdjacencyList(adjlist_4V_new)
        self.assertTrue(mol_4V.isIsomorphic(mol_4V_new))