Exemple #1
0
 def testSymmetryNumberGeneration(self):
     """
     Test we generate symmetry numbers correctly.
     
     This uses the new thermo database to generate the H298, used 
     to select the stablest resonance isomer.
     """
     for smiles, symm, H298, S298, Cp300, Cp400, Cp500, Cp600, Cp800, Cp1000, Cp1500 in self.testCases:
         molecule = Molecule(SMILES=smiles)
         species = Species(molecule=molecule)
         species.generateResonanceIsomers()
         thermoData = self.database.getThermoDataFromGroups(
             Species(molecule=[species.molecule[0]]))
         # pick the molecule with lowest H298
         molecule = species.molecule[0]
         for mol in species.molecule[1:]:
             thermoData0 = self.database.getAllThermoData(
                 Species(molecule=[mol]))[0][0]
             for data in self.database.getAllThermoData(
                     Species(molecule=[mol]))[1:]:
                 if data.getEnthalpy(298) < thermoData0.getEnthalpy(298):
                     thermoData0 = data
             if thermoData0.getEnthalpy(298) < thermoData.getEnthalpy(298):
                 thermoData = thermoData0
                 molecule = mol
         self.assertEqual(
             molecule.calculateSymmetryNumber(),
             symm,
             msg="Symmetry number error for {0}".format(smiles))
Exemple #2
0
    def testThermoForMonocyclicAndPolycyclicSameMolecule(self):
        """
        Test a molecule that has both a polycyclic and a monocyclic ring in the same molecule
        """
        spec = Species().fromSMILES('C(CCC1C2CCC1CC2)CC1CCC1')
        spec.generateResonanceIsomers()
        thermo = self.database.getThermoDataFromGroups(spec)
        ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(
            thermo)
        self.assertEqual(len(ringGroups), 1)
        self.assertEqual(len(polycyclicGroups), 1)

        expected_matchedRingsLabels = ['Cyclobutane']
        expected_matchedRings = [
            self.database.groups['ring'].entries[label]
            for label in expected_matchedRingsLabels
        ]
        self.assertEqual(set(ringGroups), set(expected_matchedRings))

        expected_matchedPolyringsLabels = ['s3_5_5_ane']
        expected_matchedPolyrings = [
            self.database.groups['polycyclic'].entries[label]
            for label in expected_matchedPolyringsLabels
        ]

        self.assertEqual(set(polycyclicGroups), set(expected_matchedPolyrings))
Exemple #3
0
 def testPolycyclicPicksBestThermo(self):
     """
     Test that RMG prioritizes thermo correctly and chooses the thermo from the isomer which
     has a non generic polycyclic ring correction
     """
     
     spec = Species().fromSMILES('C1=C[C]2CCC=C2C1')
     spec.generateResonanceIsomers()
     
     thermoDataList = []
     for molecule in spec.molecule:
         thermo = self.database.estimateRadicalThermoViaHBI(molecule, self.database.computeGroupAdditivityThermo)
         thermoDataList.append(thermo)
         
     thermoDataList.sort(key=lambda x: x.getEnthalpy(298))
     most_stable_thermo = thermoDataList[0]
     ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(most_stable_thermo)
     
     selected_thermo = self.database.getThermoDataFromGroups(spec)
     
     self.assertNotEqual(selected_thermo, thermoDataList)
     
     selected_ringGroups, selected_polycyclicGroups = self.database.getRingGroupsFromComments(selected_thermo)
     
     # The group used to estimate the most stable thermo is the generic polycyclic group and
     # therefore is not selected.  Note that this unit test will have to change if the correction is fixed later.
     self.assertEqual(polycyclicGroups[0].label, 'PolycyclicRing')
     self.assertEqual(selected_polycyclicGroups[0].label, 'C12CCC=C1CC=C2')
Exemple #4
0
    def testPolycyclicPicksBestThermo(self):
        """
        Test that RMG prioritizes thermo correctly and chooses the thermo from the isomer which
        has a non generic polycyclic ring correction
        """

        spec = Species().fromSMILES('C1=C[C]2CCC=C2C1')
        spec.generateResonanceIsomers()

        thermoDataList = []
        for molecule in spec.molecule:
            thermo = self.database.estimateRadicalThermoViaHBI(
                molecule, self.database.computeGroupAdditivityThermo)
            thermoDataList.append(thermo)

        thermoDataList.sort(key=lambda x: x.getEnthalpy(298))
        most_stable_thermo = thermoDataList[0]
        ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(
            most_stable_thermo)

        selected_thermo = self.database.getThermoDataFromGroups(spec)

        self.assertNotEqual(selected_thermo, thermoDataList)

        selected_ringGroups, selected_polycyclicGroups = self.database.getRingGroupsFromComments(
            selected_thermo)

        # The group used to estimate the most stable thermo is the generic polycyclic group and
        # therefore is not selected.  Note that this unit test will have to change if the correction is fixed later.
        self.assertEqual(polycyclicGroups[0].label, 'PolycyclicRing')
        self.assertEqual(selected_polycyclicGroups[0].label, 'C12CCC=C1CC=C2')
Exemple #5
0
 def testNewThermoGeneration(self):
     """
     Test that the new ThermoDatabase generates appropriate thermo data.
     """
     
     for smiles, symm, H298, S298, Cp300, Cp400, Cp500, Cp600, Cp800, Cp1000, Cp1500 in self.testCases:
         Cplist = [Cp300, Cp400, Cp500, Cp600, Cp800, Cp1000, Cp1500]
         molecule=Molecule(SMILES=smiles)
         species = Species(molecule=molecule)
         species.generateResonanceIsomers()
         species.molecule[0]
         thermoData = self.database.getThermoDataFromGroups(species)
         molecule = species.molecule[0]
         for mol in species.molecule[1:]:
             thermoData0 = self.database.getAllThermoData(Species(molecule=[mol]))[0][0]
             for data in self.database.getAllThermoData(Species(molecule=[mol]))[1:]:
                 if data.getEnthalpy(298) < thermoData0.getEnthalpy(298):
                     thermoData0 = data
             if thermoData0.getEnthalpy(298) < thermoData.getEnthalpy(298):
                 thermoData = thermoData0
                 molecule = mol
         self.assertAlmostEqual(H298, thermoData.getEnthalpy(298) / 4184, places=1, msg="H298 error for {0}".format(smiles))
         self.assertAlmostEqual(S298, thermoData.getEntropy(298) / 4.184, places=1, msg="S298 error for {0}".format(smiles))
         for T, Cp in zip(self.Tlist, Cplist):
             self.assertAlmostEqual(Cp, thermoData.getHeatCapacity(T) / 4.184, places=1, msg="Cp{1} error for {0}".format(smiles,T))
Exemple #6
0
    def testAddPolyRingCorrectionThermoDataFromHeuristicUsingPyrene(self):

        # create testing molecule: Pyrene with two ring of aromatic version
        # the other two ring of kekulized version
        #
        # creating it seems not natural in RMG, that's because
        # RMG cannot parse the adjacencyList of that isomer correctly
        # so here we start with pyrene radical and get the two aromatic ring isomer
        # then saturate it.
        smiles = '[C]1C=C2C=CC=C3C=CC4=CC=CC=1C4=C23'
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        mols = []
        for mol in spe.molecule:
            sssr0 = mol.getSmallestSetOfSmallestRings()
            aromaticRingNum = 0
            for sr0 in sssr0:
                sr0mol = Molecule(atoms=sr0)
                if isAromaticRing(sr0mol):
                    aromaticRingNum += 1
            if aromaticRingNum == 2:
                mol.saturate()
                mols.append(mol)

        ringGroupLabels = []
        polycyclicGroupLabels = []
        for mol in mols:
            polyring = mol.getDisparateRings()[1][0]

            thermoData = ThermoData(
                Tdata=([300, 400, 500, 600, 800, 1000, 1500], "K"),
                Cpdata=([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "J/(mol*K)"),
                H298=(0.0, "kJ/mol"),
                S298=(0.0, "J/(mol*K)"),
            )

            self.database._ThermoDatabase__addPolyRingCorrectionThermoDataFromHeuristic(
                thermoData, polyring)

            ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(
                thermoData)

            ringGroupLabels += [ringGroup.label for ringGroup in ringGroups]
            polycyclicGroupLabels += [
                polycyclicGroup.label for polycyclicGroup in polycyclicGroups
            ]

        self.assertIn('Benzene', ringGroupLabels)
        self.assertIn('six-inringtwodouble-12', ringGroupLabels)
        self.assertIn('Cyclohexene', ringGroupLabels)
        self.assertIn('1,3-Cyclohexadiene', ringGroupLabels)
        self.assertIn('s2_6_6_ben_ene_1', polycyclicGroupLabels)
        self.assertIn('s2_6_6_ben_ene_2', polycyclicGroupLabels)
        self.assertIn('s2_6_6_naphthalene', polycyclicGroupLabels)
Exemple #7
0
    def testSpeciesThermoGenerationHBIGAV(self):
        """Test thermo generation for species objects.

        Ensure that molecule list is only reordered, and not changed after group additivity"""
        spec = Species().fromSMILES('CCC[CH]c1ccccc1')
        spec.generateResonanceIsomers()
        initial = list(spec.molecule)  # Make a copy of the list
        thermo = self.database.getThermoData(spec)

        self.assertEqual(len(initial), len(spec.molecule))
        self.assertEqual(set(initial), set(spec.molecule))
        self.assertTrue('group additivity' in thermo.comment, 'Thermo not found from GAV, test purpose not fulfilled.')
Exemple #8
0
    def testBicyclicDecompositionForPolyringUsingPyrene(self):

        # create testing molecule: Pyrene with two ring of aromatic version
        # the other two ring of kekulized version
        #
        # creating it seems not natural in RMG, that's because
        # RMG cannot parse the adjacencyList of that isomer correctly
        # so here we start with pyrene radical and get the two aromatic ring isomer
        # then saturate it.
        smiles = '[C]1C=C2C=CC=C3C=CC4=CC=CC=1C4=C23'
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        for mol in spe.molecule:
            sssr0 = mol.getSmallestSetOfSmallestRings()
            aromaticRingNum = 0
            for sr0 in sssr0:
                sr0mol = Molecule(atoms=sr0)
                if isAromaticRing(sr0mol):
                    aromaticRingNum += 1
            if aromaticRingNum == 2:
                break
        mol.saturate()

        # extract polyring from the molecule
        polyring = mol.getDisparateRings()[1][0]

        bicyclicList, ringOccurancesDict = bicyclicDecompositionForPolyring(
            polyring)

        # 1st test: number of cores
        self.assertEqual(len(bicyclicList), 5)

        # 2nd test: ringOccurancesDict
        ringInCoreOccurances = sorted(ringOccurancesDict.values())
        expectedRingInCoreOccurances = [2, 2, 3, 3]
        self.assertEqual(ringInCoreOccurances, expectedRingInCoreOccurances)

        # 3rd test: size of each bicyclic core
        bicyclicSizes = sorted(
            [len(bicyclic.atoms) for bicyclic in bicyclicList])
        expectedBicyclicSizes = [10, 10, 10, 10, 10]
        self.assertEqual(bicyclicSizes, expectedBicyclicSizes)

        # 4th test: bond info for members of each core
        aromaticBondNumInBicyclics = []
        for bicyclic in bicyclicList:
            aromaticBondNum = len(findAromaticBondsFromSubMolecule(bicyclic))
            aromaticBondNumInBicyclics.append(aromaticBondNum)
        aromaticBondNumInBicyclics = sorted(aromaticBondNumInBicyclics)
        expectedAromaticBondNumInBicyclics = [0, 6, 6, 6, 11]
        self.assertEqual(aromaticBondNumInBicyclics,
                         expectedAromaticBondNumInBicyclics)
Exemple #9
0
    def testAddPolyRingCorrectionThermoDataFromHeuristicUsingPyrene(self):

        # create testing molecule: Pyrene with two ring of aromatic version
        # the other two ring of kekulized version
        #
        # creating it seems not natural in RMG, that's because
        # RMG cannot parse the adjacencyList of that isomer correctly
        # so here we start with pyrene radical and get the two aromatic ring isomer
        # then saturate it.
        smiles = '[C]1C=C2C=CC=C3C=CC4=CC=CC=1C4=C23'
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        mols = []
        for mol in spe.molecule:
            sssr0 = mol.getSmallestSetOfSmallestRings()
            aromaticRingNum = 0
            for sr0 in sssr0:
                sr0mol = Molecule(atoms=sr0)
                if isAromaticRing(sr0mol):
                    aromaticRingNum += 1
            if aromaticRingNum == 2:
                mol.saturate()
                mols.append(mol)
        
        ringGroupLabels = []
        polycyclicGroupLabels = []
        for mol in mols:
            polyring = mol.getDisparateRings()[1][0]

            thermoData = ThermoData(
                Tdata = ([300,400,500,600,800,1000,1500],"K"),
                Cpdata = ([0.0,0.0,0.0,0.0,0.0,0.0,0.0],"J/(mol*K)"),
                H298 = (0.0,"kJ/mol"),
                S298 = (0.0,"J/(mol*K)"),
            )

            self.database._ThermoDatabase__addPolyRingCorrectionThermoDataFromHeuristic(
                thermoData, polyring)

            ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(thermoData)

            ringGroupLabels += [ringGroup.label for ringGroup in ringGroups]
            polycyclicGroupLabels += [polycyclicGroup.label for polycyclicGroup in polycyclicGroups]

        self.assertIn('Benzene', ringGroupLabels)
        self.assertIn('six-inringtwodouble-12', ringGroupLabels)
        self.assertIn('Cyclohexene', ringGroupLabels)
        self.assertIn('1,3-Cyclohexadiene', ringGroupLabels)
        self.assertIn('s2_6_6_ben_ene_1', polycyclicGroupLabels)
        self.assertIn('s2_6_6_ben_ene_2', polycyclicGroupLabels)
        self.assertIn('s2_6_6_naphthalene', polycyclicGroupLabels)
Exemple #10
0
    def testSpeciesThermoGenerationHBIGAV(self):
        """Test thermo generation for species objects.

        Ensure that molecule list is only reordered, and not changed after group additivity"""
        spec = Species().fromSMILES('CCC[CH]c1ccccc1')
        spec.generateResonanceIsomers()
        initial = list(spec.molecule)  # Make a copy of the list
        thermo = self.database.getThermoData(spec)

        self.assertEqual(len(initial), len(spec.molecule))
        self.assertEqual(set(initial), set(spec.molecule))
        self.assertTrue(
            'group additivity' in thermo.comment,
            'Thermo not found from GAV, test purpose not fulfilled.')
Exemple #11
0
    def testBicyclicDecompositionForPolyringUsingPyrene(self):

        # create testing molecule: Pyrene with two ring of aromatic version
        # the other two ring of kekulized version
        #
        # creating it seems not natural in RMG, that's because
        # RMG cannot parse the adjacencyList of that isomer correctly
        # so here we start with pyrene radical and get the two aromatic ring isomer
        # then saturate it.
        smiles = '[C]1C=C2C=CC=C3C=CC4=CC=CC=1C4=C23'
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        for mol in spe.molecule:
            sssr0 = mol.getSmallestSetOfSmallestRings()
            aromaticRingNum = 0
            for sr0 in sssr0:
                sr0mol = Molecule(atoms=sr0)
                if isAromaticRing(sr0mol):
                    aromaticRingNum += 1
            if aromaticRingNum == 2:
                break
        mol.saturate()
        
        # extract polyring from the molecule
        polyring = mol.getDisparateRings()[1][0]

        bicyclicList, ringOccurancesDict = bicyclicDecompositionForPolyring(polyring)

        # 1st test: number of cores
        self.assertEqual(len(bicyclicList), 5)

        # 2nd test: ringOccurancesDict
        ringInCoreOccurances = sorted(ringOccurancesDict.values())
        expectedRingInCoreOccurances = [2, 2, 3, 3]
        self.assertEqual(ringInCoreOccurances, expectedRingInCoreOccurances)

        # 3rd test: size of each bicyclic core
        bicyclicSizes = sorted([len(bicyclic.atoms) for bicyclic in bicyclicList])
        expectedBicyclicSizes = [10, 10, 10, 10, 10]
        self.assertEqual(bicyclicSizes, expectedBicyclicSizes)

        # 4th test: bond info for members of each core
        aromaticBondNumInBicyclics = []
        for bicyclic in bicyclicList:
            aromaticBondNum = len(findAromaticBondsFromSubMolecule(bicyclic))
            aromaticBondNumInBicyclics.append(aromaticBondNum)
        aromaticBondNumInBicyclics = sorted(aromaticBondNumInBicyclics)
        expectedAromaticBondNumInBicyclics = [0, 6, 6, 6, 11]
        self.assertEqual(aromaticBondNumInBicyclics, expectedAromaticBondNumInBicyclics)
Exemple #12
0
    def testAddPolyRingCorrectionThermoDataFromHeuristicUsingAromaticTricyclic(
            self):

        # create testing molecule
        #
        # creating it seems not natural in RMG, that's because
        # RMG cannot parse the adjacencyList of that isomer correctly
        # so here we start with kekulized version and generateResonanceIsomers
        # and pick the one with two aromatic rings
        smiles = 'C1=CC2C=CC=C3C=CC(=C1)C=23'
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        for mol in spe.molecule:
            sssr0 = mol.getSmallestSetOfSmallestRings()
            aromaticRingNum = 0
            for sr0 in sssr0:
                sr0mol = Molecule(atoms=sr0)
                if isAromaticRing(sr0mol):
                    aromaticRingNum += 1
            if aromaticRingNum == 2:
                break

        # extract polyring from the molecule
        polyring = mol.getDisparateRings()[1][0]

        thermoData = ThermoData(
            Tdata=([300, 400, 500, 600, 800, 1000, 1500], "K"),
            Cpdata=([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "J/(mol*K)"),
            H298=(0.0, "kJ/mol"),
            S298=(0.0, "J/(mol*K)"),
        )

        self.database._ThermoDatabase__addPolyRingCorrectionThermoDataFromHeuristic(
            thermoData, polyring)

        ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(
            thermoData)

        ringGroupLabels = [ringGroup.label for ringGroup in ringGroups]
        polycyclicGroupLabels = [
            polycyclicGroup.label for polycyclicGroup in polycyclicGroups
        ]

        self.assertIn('Benzene', ringGroupLabels)
        self.assertIn('Cyclopentene', ringGroupLabels)
        self.assertIn('s2_5_6_indene', polycyclicGroupLabels)
        self.assertIn('s2_6_6_naphthalene', polycyclicGroupLabels)
Exemple #13
0
    def testComputeGroupAdditivityThermoForTwoRingMolecule(self):
        """
        The molecule being tested has two rings, one is 13cyclohexadiene5methylene
        the other is benzene ring. This method is to test thermo estimation will
        give two different corrections accordingly. 
        """
        spec = Species().fromSMILES('CCCCCCCCCCCC(CC=C1C=CC=CC1)c1ccccc1')
        spec.generateResonanceIsomers()
        thermo = self.database.getThermoDataFromGroups(spec)

        ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(thermo)
        self.assertEqual(len(ringGroups),2)
        self.assertEqual(len(polycyclicGroups),0)

        expected_matchedRingsLabels = ['13cyclohexadiene5methylene', 'Benzene']
        expected_matchedRings = [self.database.groups['ring'].entries[label] for label in expected_matchedRingsLabels]

        self.assertEqual(set(ringGroups), set(expected_matchedRings))
Exemple #14
0
    def testNewThermoGeneration(self):
        """
        Test that the new ThermoDatabase generates appropriate thermo data.
        """

        for smiles, symm, H298, S298, Cp300, Cp400, Cp500, Cp600, Cp800, Cp1000, Cp1500 in self.testCases:
            Cplist = [Cp300, Cp400, Cp500, Cp600, Cp800, Cp1000, Cp1500]
            species = Species().fromSMILES(smiles)
            species.generateResonanceIsomers()
            thermoData = self.database.getThermoDataFromGroups(species)
            molecule = species.molecule[0]
            for mol in species.molecule[1:]:
                thermoData0 = self.database.getAllThermoData(
                    Species(molecule=[mol]))[0][0]
                for data in self.database.getAllThermoData(
                        Species(molecule=[mol]))[1:]:
                    if data[0].getEnthalpy(298) < thermoData0.getEnthalpy(298):
                        thermoData0 = data[0]
                if thermoData0.getEnthalpy(298) < thermoData.getEnthalpy(298):
                    thermoData = thermoData0
                    molecule = mol
            self.assertAlmostEqual(
                H298,
                thermoData.getEnthalpy(298) / 4184,
                places=1,
                msg="H298 error for {0}. Expected {1}, but calculated {2}.".
                format(smiles, H298,
                       thermoData.getEnthalpy(298) / 4184))
            self.assertAlmostEqual(
                S298,
                thermoData.getEntropy(298) / 4.184,
                places=1,
                msg="S298 error for {0}. Expected {1}, but calculated {2}.".
                format(smiles, S298,
                       thermoData.getEntropy(298) / 4.184))
            for T, Cp in zip(self.Tlist, Cplist):
                self.assertAlmostEqual(
                    Cp,
                    thermoData.getHeatCapacity(T) / 4.184,
                    places=1,
                    msg="Cp{3} error for {0}. Expected {1} but calculated {2}."
                    .format(smiles, Cp,
                            thermoData.getHeatCapacity(T) / 4.184, T))
Exemple #15
0
    def testFindAromaticBondsFromSubMolecule(self):

        smiles = "C1=CC=C2C=CC=CC2=C1"
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        mol = spe.molecule[1]

        # get two SSSRs
        SSSR = mol.getSmallestSetOfSmallestRings()
        ring1 = SSSR[0]
        ring2 = SSSR[1]

        # create two testing submols
        submol1 = Molecule(atoms=ring1)
        submol2 = Molecule(atoms=ring2)

        # check with expected results
        self.assertEqual(len(findAromaticBondsFromSubMolecule(submol1)), 6)
        self.assertEqual(len(findAromaticBondsFromSubMolecule(submol2)), 6)
Exemple #16
0
    def testAddPolyRingCorrectionThermoDataFromHeuristicUsingAromaticTricyclic(self):

        # create testing molecule
        #
        # creating it seems not natural in RMG, that's because
        # RMG cannot parse the adjacencyList of that isomer correctly
        # so here we start with kekulized version and generateResonanceIsomers
        # and pick the one with two aromatic rings
        smiles = 'C1=CC2C=CC=C3C=CC(=C1)C=23'
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        for mol in spe.molecule:
            sssr0 = mol.getSmallestSetOfSmallestRings()
            aromaticRingNum = 0
            for sr0 in sssr0:
                sr0mol = Molecule(atoms=sr0)
                if isAromaticRing(sr0mol):
                    aromaticRingNum += 1
            if aromaticRingNum == 2:
                break
        
        # extract polyring from the molecule
        polyring = mol.getDisparateRings()[1][0]

        thermoData = ThermoData(
            Tdata = ([300,400,500,600,800,1000,1500],"K"),
            Cpdata = ([0.0,0.0,0.0,0.0,0.0,0.0,0.0],"J/(mol*K)"),
            H298 = (0.0,"kJ/mol"),
            S298 = (0.0,"J/(mol*K)"),
        )

        self.database._ThermoDatabase__addPolyRingCorrectionThermoDataFromHeuristic(
            thermoData, polyring)

        ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(thermoData)

        ringGroupLabels = [ringGroup.label for ringGroup in ringGroups]
        polycyclicGroupLabels = [polycyclicGroup.label for polycyclicGroup in polycyclicGroups]

        self.assertIn('Benzene', ringGroupLabels)
        self.assertIn('Cyclopentene', ringGroupLabels)
        self.assertIn('s2_5_6_indene', polycyclicGroupLabels)
        self.assertIn('s2_6_6_naphthalene', polycyclicGroupLabels)
Exemple #17
0
    def testThermoForMonocyclicAndPolycyclicSameMolecule(self):
        """
        Test a molecule that has both a polycyclic and a monocyclic ring in the same molecule
        """
        spec = Species().fromSMILES('C(CCC1C2CCC1CC2)CC1CCC1')
        spec.generateResonanceIsomers()
        thermo = self.database.getThermoDataFromGroups(spec)
        ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(thermo)
        self.assertEqual(len(ringGroups),1)
        self.assertEqual(len(polycyclicGroups),1)
        
        expected_matchedRingsLabels = ['Cyclobutane']
        expected_matchedRings = [self.database.groups['ring'].entries[label] for label in expected_matchedRingsLabels]
        self.assertEqual(set(ringGroups), set(expected_matchedRings))
        
        expected_matchedPolyringsLabels = ['s3_5_5_ane']
        expected_matchedPolyrings = [self.database.groups['polycyclic'].entries[label] for label in expected_matchedPolyringsLabels]

        self.assertEqual(set(polycyclicGroups), set(expected_matchedPolyrings))
Exemple #18
0
    def testFindAromaticBondsFromSubMolecule(self):

        smiles = "C1=CC=C2C=CC=CC2=C1"
        spe = Species().fromSMILES(smiles)
        spe.generateResonanceIsomers()
        mol = spe.molecule[1]

        # get two SSSRs
        SSSR = mol.getSmallestSetOfSmallestRings()
        ring1 = SSSR[0]
        ring2 = SSSR[1]

        # create two testing submols
        submol1 = Molecule(atoms=ring1)
        submol2 = Molecule(atoms=ring2)

        # check with expected results
        self.assertEqual(len(findAromaticBondsFromSubMolecule(submol1)), 6)
        self.assertEqual(len(findAromaticBondsFromSubMolecule(submol2)), 6)
Exemple #19
0
    def testComputeGroupAdditivityThermoForTwoRingMolecule(self):
        """
        The molecule being tested has two rings, one is 13cyclohexadiene5methylene
        the other is benzene ring. This method is to test thermo estimation will
        give two different corrections accordingly. 
        """
        spec = Species().fromSMILES('CCCCCCCCCCCC(CC=C1C=CC=CC1)c1ccccc1')
        spec.generateResonanceIsomers()
        thermo = self.database.getThermoDataFromGroups(spec)

        ringGroups, polycyclicGroups = self.database.getRingGroupsFromComments(
            thermo)
        self.assertEqual(len(ringGroups), 2)
        self.assertEqual(len(polycyclicGroups), 0)

        expected_matchedRingsLabels = ['13cyclohexadiene5methylene', 'Benzene']
        expected_matchedRings = [
            self.database.groups['ring'].entries[label]
            for label in expected_matchedRingsLabels
        ]

        self.assertEqual(set(ringGroups), set(expected_matchedRings))
Exemple #20
0
 def testSymmetryNumberGeneration(self):
     """
     Test we generate symmetry numbers correctly.
     
     This uses the new thermo database to generate the H298, used 
     to select the stablest resonance isomer.
     """
     for smiles, symm, H298, S298, Cp300, Cp400, Cp500, Cp600, Cp800, Cp1000, Cp1500 in self.testCases:
         molecule=Molecule(SMILES=smiles)
         species = Species(molecule=molecule)
         species.generateResonanceIsomers()
         thermoData = self.database.getThermoDataFromGroups(Species(molecule=[species.molecule[0]]))
         # pick the molecule with lowest H298
         molecule = species.molecule[0]
         for mol in species.molecule[1:]:
             thermoData0 = self.database.getAllThermoData(Species(molecule=[mol]))[0][0]
             for data in self.database.getAllThermoData(Species(molecule=[mol]))[1:]:
                 if data.getEnthalpy(298) < thermoData0.getEnthalpy(298):
                     thermoData0 = data
             if thermoData0.getEnthalpy(298) < thermoData.getEnthalpy(298):
                 thermoData = thermoData0
                 molecule = mol
         self.assertEqual(molecule.calculateSymmetryNumber(), symm, msg="Symmetry number error for {0}".format(smiles))