コード例 #1
0
ファイル: moleculeTest.py プロジェクト: rwest/ChemPy
 def testSymmetryNumber(self):
     """Overall symmetry number"""
     test_set = [('CC', 18), # ethane
                 ('C=C=[C]C(C)(C)[C]=C=C', 'Who knows?'),
                 ('C(=CC(c1ccccc1)C([CH]CCCCCC)C=Cc1ccccc1)[CH]CCCCCC', 1),
                 ('[OH]', 1),#hydroxyl radical
                 ('O=O', 2),#molecular oxygen
                 ('[C]#[C]', 2),#C2
                 ('[H][H]', 2),#H2
                 ('C#C', 2),#acetylene
                 ('C#CC#C', 2),#1,3-butadiyne
                 ('C', 12),#methane
                 ('C=O', 2),#formaldehyde
                 ('[CH3]', 6),#methyl radical
                 ('O', 2),#water
                 ('C=C',4),#ethylene
                 ('C1=C=C=1', '6?')#cyclic, cumulenic C3 species
                 ]
     fail_message = ''
     for smile,should_be in test_set:
         molecule = Molecule().fromSMILES(smile)
         molecule.makeHydrogensExplicit()
         symmetryNumber = molecule.calculateSymmetryNumber()
         if symmetryNumber!=should_be:
             fail_message+="Got total symmetry number of %s for %s (expected %s)\n"%(symmetryNumber,smile,should_be)
     self.assertEqual(fail_message,'',fail_message)
コード例 #2
0
ファイル: moleculeTest.py プロジェクト: rwest/ChemPy
    def testAxisSymmetryNumber(self):
        """Axis symmetry number"""
        test_set = [('C=C=C', 2), # ethane
                    ('C=C=C=C', 2),
                    ('C=C=C=[CH]', 2), # =C-H is straight
                    ('C=C=[C]', 2),
                    ('CC=C=[C]', 1),
                    ('C=C=CC(CC)', 1),
                    ('CC(C)=C=C(CC)CC', 2),
                    ('C=C=C(C(C(C(C=C=C)=C=C)=C=C)=C=C)', 2),
                    ('C=C=[C]C(C)(C)[C]=C=C', 1),
                    ('C=C=C=O', 2),
                    ('CC=C=C=O', 1),
                    ('C=C=C=N', 1), # =N-H is bent
                    ('C=C=C=[N]', 2)
                    ]
        # http://cactus.nci.nih.gov/chemical/structure/C=C=C(C(C(C(C=C=C)=C=C)=C=C)=C=C)/image
        fail_message = ''

        for smile,should_be in test_set:
            molecule = Molecule().fromSMILES(smile)
            molecule.makeHydrogensExplicit()
            symmetryNumber = molecule.calculateAxisSymmetryNumber()
            if symmetryNumber!=should_be:
                fail_message+="Got axis symmetry number of %s for %s (expected %s)\n"%(symmetryNumber,smile,should_be)
        self.assertEqual(fail_message,'',fail_message)
コード例 #3
0
ファイル: moleculeTest.py プロジェクト: jwallen/ChemPy
 def testAdjacencyList(self):
     """
     Check the adjacency list read/write functions for a full molecule.
     """
     molecule1 = Molecule().fromAdjacencyList("""
     1 C 0       {2,D}
     2 C 0 {1,D} {3,S}
     3 C 0 {2,S} {4,D}
     4 C 0 {3,D} {5,S}
     5 C 1 {4,S} {6,S}
     6 C 0 {5,S}
     """)
     molecule2 = Molecule().fromSMILES('C=CC=C[CH]C')
     
     molecule1.makeHydrogensExplicit()
     molecule2.makeHydrogensExplicit()
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
     
     molecule1.makeHydrogensImplicit()
     molecule2.makeHydrogensImplicit()
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
     
     molecule1.makeHydrogensExplicit()
     molecule2.makeHydrogensImplicit()
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
     
     molecule1.makeHydrogensImplicit()
     molecule2.makeHydrogensExplicit()
     self.assertTrue(molecule1.isIsomorphic(molecule2))
     self.assertTrue(molecule2.isIsomorphic(molecule1))
コード例 #4
0
ファイル: moleculeTest.py プロジェクト: rwest/ChemPy
    def testSubgraphIsomorphismAgain(self):
        molecule = Molecule()
        molecule.fromAdjacencyList("""
        1 * C 0 {2,D} {7,S} {8,S}
        2 C 0 {1,D} {3,S} {9,S}
        3 C 0 {2,S} {4,D} {10,S}
        4 C 0 {3,D} {5,S} {11,S}
        5 C 0 {4,S} {6,S} {12,S} {13,S}
        6 C 0 {5,S} {14,S} {15,S} {16,S}
        7 H 0 {1,S}
        8 H 0 {1,S}
        9 H 0 {2,S}
        10 H 0 {3,S}
        11 H 0 {4,S}
        12 H 0 {5,S}
        13 H 0 {5,S}
        14 H 0 {6,S}
        15 H 0 {6,S}
        16 H 0 {6,S}
        """)

        pattern = MoleculePattern()
        pattern.fromAdjacencyList("""
        1 * C 0 {2,D} {3,S} {4,S}
        2   C 0 {1,D}
        3   H 0 {1,S}
        4   H 0 {1,S}
        """)

        molecule.makeHydrogensExplicit()

        labeled1 = molecule.getLabeledAtoms().values()[0]
        labeled2 = pattern.getLabeledAtoms().values()[0]

        initialMap = {labeled1: labeled2}
        self.assertTrue(molecule.isSubgraphIsomorphic(pattern, initialMap))

        initialMap = {labeled1: labeled2}
        match, mapping = molecule.findSubgraphIsomorphisms(pattern, initialMap)
        self.assertTrue(match)
        self.assertTrue(len(mapping) == 2,  "len(mapping) = %d, should be = 2" % (len(mapping)))
        for map in mapping:
            self.assertTrue(len(map) == min(len(molecule.atoms), len(pattern.atoms)))
            for key, value in map.iteritems():
                self.assertTrue(key in molecule.atoms)
                self.assertTrue(value in pattern.atoms)
コード例 #5
0
ファイル: moleculeTest.py プロジェクト: rwest/ChemPy
    def testAtomSymmetryNumber(self):

        testSet = [
            ['C', 12],
            ['[CH3]', 6],
            ['CC', 9],
            ['CCC', 18],
            ['CC(C)C', 81],
        ]
        failMessage = ''

        for SMILES, symmetry in testSet:
            molecule = Molecule().fromSMILES(SMILES)
            molecule.makeHydrogensExplicit()
            symmetryNumber = 1
            for atom in molecule.atoms:
                if not molecule.isAtomInCycle(atom):
                    symmetryNumber *= molecule.calculateAtomSymmetryNumber(atom)
            if symmetryNumber != symmetry:
                failMessage += 'Expected symmetry number of %i for %s, got %i\n' % (symmetry, SMILES, symmetryNumber)
        self.assertEqual(failMessage, '', failMessage)
コード例 #6
0
ファイル: moleculeTest.py プロジェクト: rwest/ChemPy
    def testBondSymmetryNumber(self):

        testSet = [
            ['CC', 2],
            ['CCC', 1],
            ['CCCC', 2],
            ['C=C', 2],
            ['C#C', 2],
        ]
        failMessage = ''

        for SMILES, symmetry in testSet:
            molecule = Molecule().fromSMILES(SMILES)
            molecule.makeHydrogensExplicit()
            symmetryNumber = 1
            for atom1 in molecule.bonds:
                for atom2 in molecule.bonds[atom1]:
                    if molecule.atoms.index(atom1) < molecule.atoms.index(atom2):
                        symmetryNumber *= molecule.calculateBondSymmetryNumber(atom1, atom2)
            if symmetryNumber != symmetry:
                failMessage += 'Expected symmetry number of %i for %s, got %i\n' % (symmetry, SMILES, symmetryNumber)
        self.assertEqual(failMessage, '', failMessage)