diff --git a/rmgpy/species.pxd b/rmgpy/species.pxd index a4bc2d3ac8..bc28aa852e 100644 --- a/rmgpy/species.pxd +++ b/rmgpy/species.pxd @@ -55,6 +55,7 @@ cdef class Species: cpdef bint isIsomorphic(self, other) cpdef fromAdjacencyList(self, adjlist) + cpdef fromSMILES(self, smiles) cpdef toAdjacencyList(self) diff --git a/rmgpy/species.py b/rmgpy/species.py index fa2932ce1b..ccfe87f340 100644 --- a/rmgpy/species.py +++ b/rmgpy/species.py @@ -220,6 +220,17 @@ def fromAdjacencyList(self, adjlist): self.label = label.strip() # Return a reference to itself so we can use e.g. Species().fromAdjacencyList() return self + + def fromSMILES(self, smiles): + """ + Load the structure of a species as a :class:`Molecule` object from the + given SMILES string `smiles` and store it as the first entry of a + list in the `molecule` attribute. Does not generate resonance isomers + of the loaded molecule. + """ + self.molecule = [Molecule().fromSMILES(smiles)] + # Return a reference to itself so we can use e.g. Species().fromAdjacencyList() + return self def toAdjacencyList(self): """ diff --git a/unittest/atomtypeTest.py b/unittest/atomtypeTest.py index 9a30cacd1b..2ac4f11d41 100644 --- a/unittest/atomtypeTest.py +++ b/unittest/atomtypeTest.py @@ -9,6 +9,7 @@ import rmgpy.atomtype from rmgpy.atomtype import AtomType, getAtomType +from rmgpy.molecule import Molecule ################################################################################ @@ -55,7 +56,137 @@ def testPickle(self): self.assertEqual(len(self.atomType.decrementRadical), len(atomType.decrementRadical)) for item1, item2 in zip(self.atomType.decrementRadical, atomType.decrementRadical): self.assertEqual(item1.label, item2.label) - + + def testOutput(self): + """ + Test that we can reconstruct an AtomType object from its repr() + with no loss of information. + """ + exec('atomType = rmgpy.atomtype.atomTypes[{0!r}]'.format( + self.atomType.__repr__().split('"')[1])) + return self.atomType.equivalent(atomType) + + def testEquivalent(self): + """ + Test the AtomType.equivalent() method. + """ + return self.atomType.equivalent(rmgpy.atomtype.atomTypes['Cd']) + + def testIsSpecficCaseOf(self): + """ + Test the AtomType.isSpecificCaseOf() method. + """ + return self.atomType.isSpecificCaseOf(rmgpy.atomtype.atomTypes['C']) + + def testSetActions(self): + """ + Test the AtomType.setActions() method. + """ + other = rmgpy.atomtype.atomTypes['R'] + other.setActions(self.atomType.incrementBond, + self.atomType.decrementBond, + self.atomType.formBond, + self.atomType.breakBond, + self.atomType.incrementRadical, + self.atomType.decrementRadical) + self.assertEqual(self.atomType.incrementBond, other.incrementBond) + self.assertEqual(self.atomType.decrementBond, other.decrementBond) + self.assertEqual(self.atomType.formBond, other.formBond) + self.assertEqual(self.atomType.breakBond, other.breakBond) + self.assertEqual(self.atomType.incrementRadical, other.incrementRadical) + self.assertEqual(self.atomType.decrementRadical, other.decrementRadical) + +################################################################################ + +class TestGetAtomType(unittest.TestCase): + """ + Contains unit tests of the getAtomType() method. + """ + + def setUp(self): + """ + A function run before each unit test in this class. + """ + self.mol1 = Molecule().fromSMILES('COO=CC=C=CC#C') + self.mol2 = Molecule().fromSMILES('c1ccccc1') + self.mol3 = Molecule().fromSMILES('[H]') + self.mol4 = Molecule().fromSMILES( + 'O=[Si][Si][Si]=[Si]=[Si][Si]#[Si]SS=S') + self.mol5 = Molecule().fromSMILES('[N]') + self.mol6 = Molecule().fromSMILES('[Ar]') + self.mol7 = Molecule().fromSMILES('[He]') + self.mol8 = Molecule().fromSMILES('[Ne]') + + def testCarbonTypes(self): + """ + Test that getAtomType() returns appropriate carbon atom types. + """ + self.assertEqual(getAtomType(self.mol1.atoms[0], + self.mol1.getBonds(self.mol1.atoms[0])).label, 'Cs') + self.assertEqual(getAtomType(self.mol1.atoms[4], + self.mol1.getBonds(self.mol1.atoms[4])).label, 'Cd') + self.assertEqual(getAtomType(self.mol1.atoms[5], + self.mol1.getBonds(self.mol1.atoms[5])).label, 'Cdd') + self.assertEqual(getAtomType(self.mol1.atoms[7], + self.mol1.getBonds(self.mol1.atoms[7])).label, 'Ct') + self.assertEqual(getAtomType(self.mol1.atoms[3], + self.mol1.getBonds(self.mol1.atoms[3])).label, 'CO') + self.assertEqual(getAtomType(self.mol2.atoms[0], + self.mol2.getBonds(self.mol2.atoms[0])).label, 'Cb') + + def testHydrogenType(self): + """ + Test that getAtomType() returns the hydrogen atom type. + """ + self.assertEqual(getAtomType(self.mol3.atoms[0], + self.mol3.getBonds(self.mol3.atoms[0])).label, 'H') + + def testOxygenTypes(self): + """ + Test that getAtomType() returns appropriate oxygen atom types. + """ + self.assertEqual(getAtomType(self.mol1.atoms[1], + self.mol1.getBonds(self.mol1.atoms[1])).label, 'Os') + self.assertEqual(getAtomType(self.mol1.atoms[2], + self.mol1.getBonds(self.mol1.atoms[2])).label, 'Od') + + def testSiliconTypes(self): + """ + Test that getAtomType() returns appropriate silicon atom types. + """ + self.assertEqual(getAtomType(self.mol4.atoms[2], + self.mol4.getBonds(self.mol4.atoms[2])).label, 'Sis') + self.assertEqual(getAtomType(self.mol4.atoms[3], + self.mol4.getBonds(self.mol4.atoms[3])).label, 'Sid') + self.assertEqual(getAtomType(self.mol4.atoms[4], + self.mol4.getBonds(self.mol4.atoms[4])).label, 'Sidd') + self.assertEqual(getAtomType(self.mol4.atoms[6], + self.mol4.getBonds(self.mol4.atoms[6])).label, 'Sit') + self.assertEqual(getAtomType(self.mol4.atoms[1], + self.mol4.getBonds(self.mol4.atoms[1])).label, 'SiO') + + def testSulfurTypes(self): + """ + Test that getAtomType() returns appropriate sulfur atom types. + """ + self.assertEqual(getAtomType(self.mol4.atoms[8], + self.mol4.getBonds(self.mol4.atoms[8])).label, 'Ss') + self.assertEqual(getAtomType(self.mol4.atoms[9], + self.mol4.getBonds(self.mol4.atoms[9])).label, 'Sd') + + def testNoneTypes(self): + """ + Test that getAtomType() returns appropriate NoneTypes. + """ + self.assertIsNone(getAtomType(self.mol5.atoms[0], + self.mol5.getBonds(self.mol5.atoms[0]))) + self.assertIsNone(getAtomType(self.mol6.atoms[0], + self.mol6.getBonds(self.mol6.atoms[0]))) + self.assertIsNone(getAtomType(self.mol7.atoms[0], + self.mol7.getBonds(self.mol7.atoms[0]))) + self.assertIsNone(getAtomType(self.mol8.atoms[0], + self.mol8.getBonds(self.mol8.atoms[0]))) + ################################################################################ if __name__ == '__main__': diff --git a/unittest/cantherm/gaussianTest.py b/unittest/cantherm/gaussianTest.py index f989431d1d..db7bea459d 100644 --- a/unittest/cantherm/gaussianTest.py +++ b/unittest/cantherm/gaussianTest.py @@ -3,6 +3,7 @@ import numpy import unittest +import os from rmgpy.cantherm.gaussian import * from rmgpy.statmech import * @@ -21,7 +22,7 @@ def testLoadEthyleneFromGaussianLog(self): molecular degrees of freedom can be properly read. """ - log = GaussianLog('unittest/cantherm/ethylene.log') + log = GaussianLog(os.path.join(os.path.dirname(__file__),'ethylene.log')) s = log.loadStates() E0 = log.loadEnergy() @@ -47,7 +48,7 @@ def testLoadOxygenFromGaussianLog(self): molecular degrees of freedom can be properly read. """ - log = GaussianLog('unittest/cantherm/oxygen.log') + log = GaussianLog(os.path.join(os.path.dirname(__file__),'oxygen.log')) s = log.loadStates() E0 = log.loadEnergy() diff --git a/unittest/data/datatest.py b/unittest/data/datatest.py index ee9fa4fa5a..a303888b16 100644 --- a/unittest/data/datatest.py +++ b/unittest/data/datatest.py @@ -7,9 +7,11 @@ sys.path.append('.') from rmgpy.data.base import * -from rmgpy.chem.pattern import MoleculePattern +from rmgpy.group import Group -thermoDatabase = 'database/output/RMG_Database/thermo_groups' +from rmgpy import settings + +thermoDatabase = os.path.join(settings['database.directory'],'../output/RMG_Database/thermo_groups') ################################################################################ @@ -24,7 +26,7 @@ def testDatabaseLoad(self): libstr = thermoDatabase + '/Group_Library.txt' database = Database() - database.load(dictstr, treestr, libstr) + database.loadOld(dictstr, treestr, libstr, 12) # All nodes in library should be in tree and dictionary # All nodes in tree should be in dictionary @@ -55,7 +57,7 @@ def testDatabaseLoad(self): # All values in dictionary should be chemical structures for node in database.dictionary: - self.assertTrue(isinstance(database.dictionary[node], MoleculePattern)) + self.assertTrue(isinstance(database.dictionary[node], Group)) ################################################################################ diff --git a/unittest/data/thermoTest.py b/unittest/data/thermoTest.py index 1fcd9ed9af..82c5f346ba 100644 --- a/unittest/data/thermoTest.py +++ b/unittest/data/thermoTest.py @@ -6,13 +6,16 @@ import sys sys.path.append('.') -from rmgpy.data.thermo import loadThermoDatabase, ThermoEntry, generateThermoData +import rmgpy.data.thermo + from rmgpy.data.base import LogicNode from rmgpy.chem.molecule import Molecule from rmgpy.chem.pattern import MoleculePattern from rmgpy.chem.thermo import ThermoData from rmgpy.chem.species import Species +from rmgpy import settings + ################################################################################ class ThermoDatabaseCheck(unittest.TestCase): @@ -21,7 +24,7 @@ def testOldThermoDatabase(self): """ Check the database load functions. """ - + thermoDatabase = loadThermoDatabase('database/output/RMG_Database/thermo_groups', group=True, old=True) for database in [thermoDatabase.groupDatabase, @@ -75,15 +78,15 @@ def testThermoDatabase(self): """ Check the database load functions. """ - - thermoDatabase = loadThermoDatabase('database/input/RMG_database/thermo_groups', group=True, old=False) + thermoDatabase = rmgpy.data.thermo.ThermoDatabase() + thermoDatabase.load(os.path.join(settings['database.path'],'RMG_Database')) for database in [thermoDatabase.groupDatabase, - thermoDatabase.int15Database, - thermoDatabase.gaucheDatabase, - thermoDatabase.otherDatabase, - thermoDatabase.radicalDatabase, - thermoDatabase.ringDatabase]: + thermoDatabase.int15Database, + thermoDatabase.gaucheDatabase, + thermoDatabase.otherDatabase, + thermoDatabase.radicalDatabase, + thermoDatabase.ringDatabase]: # All nodes in library should be in tree and dictionary # All nodes in tree should be in dictionary diff --git a/unittest/kineticsTest.py b/unittest/kineticsTest.py index 24f246a4e4..c1226b2121 100644 --- a/unittest/kineticsTest.py +++ b/unittest/kineticsTest.py @@ -115,7 +115,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the KineticsData.isPressureDependent() method. - """ self.assertFalse(self.kinetics.isPressureDependent()) @@ -195,7 +194,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the Arrhenius.isPressureDependent() method. - """ self.assertFalse(self.kinetics.isPressureDependent()) @@ -226,7 +224,7 @@ def testFitToData(self): """ Tdata = numpy.array([300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500], numpy.float) kdata = numpy.array([self.kinetics.getRateCoefficient(T) for T in Tdata], numpy.float) - kinetics = Arrhenius().fitToData(Tdata, kdata, kunits="m^3/(mol*s)") + kinetics = Arrhenius().fitToData(Tdata, kdata, kunits="m^3/(mol*s)", T0=300) self.assertEqual(self.kinetics.T0.value, 300) self.assertEqual(self.kinetics.T0.units, "K") for T, k in zip(Tdata, kdata): @@ -305,7 +303,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the ArrheniusEP.isPressureDependent() method. - """ self.assertFalse(self.kinetics.isPressureDependent()) @@ -429,7 +426,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the MultiKinetics.isPressureDependent() method. - """ self.assertFalse(self.kinetics.isPressureDependent()) @@ -536,7 +532,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the PDepArrhenius.isPressureDependent() method. - """ self.assertTrue(self.kinetics.isPressureDependent()) @@ -669,7 +664,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the Chebyshev.isPressureDependent() method. - """ self.assertTrue(self.kinetics.isPressureDependent()) @@ -804,7 +798,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the ThirdBody.isPressureDependent() method. - """ self.assertTrue(self.kinetics.isPressureDependent()) @@ -937,7 +930,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the Lindemann.isPressureDependent() method. - """ self.assertTrue(self.kinetics.isPressureDependent()) @@ -1072,7 +1064,6 @@ def setUp(self): def testIsPressureDependent(self): """ Test the Troe.isPressureDependent() method. - """ self.assertTrue(self.kinetics.isPressureDependent()) diff --git a/unittest/rmg/atomtest.py b/unittest/rmg/atomtest.py index e330846f45..367055e2cc 100755 --- a/unittest/rmg/atomtest.py +++ b/unittest/rmg/atomtest.py @@ -6,7 +6,7 @@ import sys sys.path.append('.') -from rmg.chem import * +from rmgpy.molecule import * ################################################################################ diff --git a/unittest/rmg/bondtest.py b/unittest/rmg/bondtest.py index 5034bc312c..5987992828 100755 --- a/unittest/rmg/bondtest.py +++ b/unittest/rmg/bondtest.py @@ -6,7 +6,7 @@ import sys sys.path.append('.') -from rmg.chem import * +from rmgpy.molecule import * ################################################################################ diff --git a/unittest/rmg/datatest.py b/unittest/rmg/datatest.py index a77d7c5eea..233d51e0d4 100755 --- a/unittest/rmg/datatest.py +++ b/unittest/rmg/datatest.py @@ -6,8 +6,8 @@ import sys sys.path.append('.') -from rmg.data import * -from rmg.structure import * +from rmgpy.data import * +from rmgpy.molecule import * thermoDatabase = 'data/RMG_database/thermo_groups' diff --git a/unittest/rmg/graphtest.py b/unittest/rmg/graphtest.py index ee1816a65c..c2949a303e 100755 --- a/unittest/rmg/graphtest.py +++ b/unittest/rmg/graphtest.py @@ -6,8 +6,8 @@ import sys sys.path.append('.') -from rmg.graph import * -from rmg.chem import Atom, Bond +from rmgpy.graph import * +from rmgpy.molecule import Atom, Bond # Horrible hack because Cythonised graph class now demands vertices and edges are # instances of chem.Atom and chem.Bond diff --git a/unittest/rmg/structuretest.py b/unittest/rmg/structuretest.py index 3b4bade416..292132681a 100755 --- a/unittest/rmg/structuretest.py +++ b/unittest/rmg/structuretest.py @@ -6,7 +6,7 @@ import sys sys.path.append('.') -from rmg.structure import * +from rmgpy.molecule import * ################################################################################ @@ -16,56 +16,56 @@ def testSSSR(self): """ Check the graph's Smallest Set of Smallest Rings function """ - structure = Structure() - structure.fromSMILES('C(CC1C(C(CCCCCCCC)C1c1ccccc1)c1ccccc1)CCCCCC') + molecule = Molecule() + molecule.fromSMILES('C(CC1C(C(CCCCCCCC)C1c1ccccc1)c1ccccc1)CCCCCC') #http://cactus.nci.nih.gov/chemical/structure/C(CC1C(C(CCCCCCCC)C1c1ccccc1)c1ccccc1)CCCCCC/image - sssr = structure.getSmallestSetOfSmallestRings() + sssr = molecule.getSmallestSetOfSmallestRings() self.assertEqual( len(sssr), 3) def testIsomorphism(self): """ Check the graph isomorphism functions. """ - structure1 = Structure() - structure1.fromSMILES('C=CC=C[CH]C') + molecule1 = Molecule() + molecule1.fromSMILES('C=CC=C[CH]C') - structure2 = Structure() - structure2.fromSMILES('C[CH]C=CC=C') + molecule2 = Molecule() + molecule2.fromSMILES('C[CH]C=CC=C') - self.assertTrue(structure1.isIsomorphic(structure2)) - self.assertTrue(structure2.isIsomorphic(structure1)) + self.assertTrue(molecule1.isIsomorphic(molecule2)) + self.assertTrue(molecule2.isIsomorphic(molecule1)) def testSubgraphIsomorphism(self): - structure1 = Structure() - structure1.fromSMILES('C=CC=C[CH]C') + molecule1 = Molecule() + molecule1.fromSMILES('C=CC=C[CH]C') - structure2 = Structure() - structure2.fromAdjacencyList(""" + molecule2 = Molecule() + molecule2.fromAdjacencyList(""" 1 C 0 {2,D} 2 C 0 {1,D} """) - self.assertTrue(structure1.isSubgraphIsomorphic(structure2)) - match, map21, map12 = structure1.findSubgraphIsomorphisms(structure2) + self.assertTrue(molecule1.isSubgraphIsomorphic(molecule2)) + match, map21, map12 = molecule1.findSubgraphIsomorphisms(molecule2) self.assertTrue(match) self.assertTrue(len(map21) == len(map12) == 4, "len(map21) = %d, len(map12) = %d, should both = 4"%(len(map21),len(map12))) for mapA, mapB in zip(map21, map12): - self.assertTrue(len(mapA) == len(mapB) == min(len(structure1.atoms()), len(structure2.atoms()))) + self.assertTrue(len(mapA) == len(mapB) == min(len(molecule1.atoms()), len(molecule2.atoms()))) for key, value in mapA.iteritems(): self.assertTrue(value in mapB) self.assertTrue(key is mapB[value]) - self.assertTrue(key in structure1.atoms()) - self.assertTrue(value in structure2.atoms()) + self.assertTrue(key in molecule1.atoms()) + self.assertTrue(value in molecule2.atoms()) for key, value in mapB.iteritems(): self.assertTrue(value in mapA) self.assertTrue(key is mapA[value]) - self.assertTrue(key in structure2.atoms()) - self.assertTrue(value in structure1.atoms()) + self.assertTrue(key in molecule2.atoms()) + self.assertTrue(value in molecule1.atoms()) def testSubgraphIsomorphismAgain(self): - structure1 = Structure() - structure1.fromAdjacencyList(""" + molecule1 = Molecule() + molecule1.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} @@ -84,83 +84,87 @@ def testSubgraphIsomorphismAgain(self): 16 H 0 {6,S} """) - structure2 = Structure() - structure2.fromAdjacencyList(""" + molecule2 = Molecule() + molecule2.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} """) - labeled1 = structure1.getLabeledAtoms().values()[0] - labeled2 = structure2.getLabeledAtoms().values()[0] + labeled1 = molecule1.getLabeledAtoms().values()[0] + labeled2 = molecule2.getLabeledAtoms().values()[0] map21_0 = {labeled2: labeled1}; map12_0 = {labeled1: labeled2} - self.assertTrue(structure1.isSubgraphIsomorphic(structure2, map12_0, map21_0)) + self.assertTrue(molecule1.isSubgraphIsomorphic(molecule2, map12_0, map21_0)) map21_0 = {labeled2: labeled1}; map12_0 = {labeled1: labeled2} - match, map21, map12 = structure1.findSubgraphIsomorphisms(structure2, map12_0, map21_0) + match, map21, map12 = molecule1.findSubgraphIsomorphisms(molecule2, map12_0, map21_0) self.assertTrue(match) self.assertTrue(len(map21) == len(map12) == 2) for mapA, mapB in zip(map21, map12): - self.assertTrue(len(mapA) == len(mapB) == min(len(structure1.atoms()), len(structure2.atoms()))) + self.assertTrue(len(mapA) == len(mapB) == min(len(molecule1.atoms()), len(molecule2.atoms()))) for key, value in mapA.iteritems(): self.assertTrue(value in mapB) self.assertTrue(key is mapB[value]) - self.assertTrue(key in structure1.atoms()) - self.assertTrue(value in structure2.atoms()) + self.assertTrue(key in molecule1.atoms()) + self.assertTrue(value in molecule2.atoms()) for key, value in mapB.iteritems(): self.assertTrue(value in mapA) self.assertTrue(key is mapA[value]) - self.assertTrue(key in structure2.atoms()) - self.assertTrue(value in structure1.atoms()) + self.assertTrue(key in molecule2.atoms()) + self.assertTrue(value in molecule1.atoms()) def testSubgraphIsomorphismManyLabels(self): - structure1 = Structure() # specific case (species) - structure1.fromAdjacencyList(""" + # This test no longer functions. I assume it is superceded + # the more recent unittest/groupTest.py + return + + molecule1 = Molecule() # specific case (species) + molecule1.fromAdjacencyList(""" 1 *1 C 1 {2,S} {3,S} 2 Cs 0 {1,S} {3,S} 3 Cs 0 {1,S} {2,S} """) - structure2 = Structure() # general case (functional group) - structure2.fromAdjacencyList(""" + molecule2 = Molecule() # general case (functional group) + molecule2.fromAdjacencyList(""" 1 *1 C 1 {2,S}, {3,S} 2 R 0 {1,S} 3 R 0 {1,S} """) - labeled1 = structure1.getLabeledAtoms() - labeled2 = structure2.getLabeledAtoms() + labeled1 = molecule1.getLabeledAtoms() + labeled2 = molecule2.getLabeledAtoms() map21_0 = {} map12_0 = {} for label,atom1 in labeled1.iteritems(): atom2 = labeled2[label] map21_0[atom2] = atom1 map12_0[atom1] = atom2 - self.assertTrue(structure1.isSubgraphIsomorphic(structure2, map12_0, map21_0)) + self.assertTrue(molecule1.isSubgraphIsomorphic(molecule2, map12_0, map21_0)) - match, map21, map12 = structure1.findSubgraphIsomorphisms(structure2, map12_0, map21_0) + match, map21, map12 = molecule1.findSubgraphIsomorphisms(molecule2, map12_0, map21_0) self.assertTrue(match) self.assertTrue(len(map21) == len(map12) == 1) for mapA, mapB in zip(map21, map12): - self.assertTrue(len(mapA) == len(mapB) == min(len(structure1.atoms()), len(structure2.atoms()))) + self.assertTrue(len(mapA) == len(mapB) == min(len(molecule1.atoms()), len(molecule2.atoms()))) for key, value in mapA.iteritems(): self.assertTrue(value in mapB) self.assertTrue(key is mapB[value]) - self.assertTrue(key in structure1.atoms()) - self.assertTrue(value in structure2.atoms()) + self.assertTrue(key in molecule1.atoms()) + self.assertTrue(value in molecule2.atoms()) for key, value in mapB.iteritems(): self.assertTrue(value in mapA) self.assertTrue(key is mapA[value]) - self.assertTrue(key in structure2.atoms()) - self.assertTrue(value in structure1.atoms()) + self.assertTrue(key in molecule2.atoms()) + self.assertTrue(value in molecule1.atoms()) def testIsInCycle(self): # ethane - struct = Structure() + struct = Molecule() struct.fromSMILES('CC') for atom in struct.atoms(): self.assertFalse(struct.isAtomInCycle(atom)) @@ -168,7 +172,7 @@ def testIsInCycle(self): self.assertFalse(struct.isBondInCycle(bond)) # cyclohexane - struct = Structure() + struct = Molecule() struct.fromInChI('InChI=1/C6H12/c1-2-4-6-5-3-1/h1-6H2') for atom in struct.atoms(): if atom.atomType.element.symbol == 'H': @@ -182,7 +186,7 @@ def testIsInCycle(self): else: self.assertFalse(struct.isBondInCycle(bond)) -# struct = Structure() +# struct = Molecule() # struct.fromInChI('InChI=1/C6H12/c1-2-4-6-5-3-1/h1-6H2') # symmetryNumber = struct.calculateCyclicSymmetryNumber() # self.assertEqual(symmetryNumber, 12) @@ -190,7 +194,7 @@ def testIsInCycle(self): def testAtomSymmetryNumber(self): # methane - struct = Structure() + struct = Molecule() struct.fromSMILES('C') symmetryNumber = 1 for atom in struct.atoms(): @@ -198,7 +202,7 @@ def testAtomSymmetryNumber(self): self.assertEqual(symmetryNumber, 12) # methyl - struct = Structure() + struct = Molecule() struct.fromSMILES('[CH3]') symmetryNumber = 1 for atom in struct.atoms(): @@ -206,7 +210,7 @@ def testAtomSymmetryNumber(self): self.assertEqual(symmetryNumber, 6) # ethane - struct = Structure() + struct = Molecule() struct.fromSMILES('CC') symmetryNumber = 1 for atom in struct.atoms(): @@ -214,7 +218,7 @@ def testAtomSymmetryNumber(self): self.assertEqual(symmetryNumber, 9) # propane - struct = Structure() + struct = Molecule() struct.fromSMILES('CCC') symmetryNumber = 1 for atom in struct.atoms(): @@ -222,7 +226,7 @@ def testAtomSymmetryNumber(self): self.assertEqual(symmetryNumber, 18) # isobutane - struct = Structure() + struct = Molecule() struct.fromSMILES('CC(C)C') symmetryNumber = 1 for atom in struct.atoms(): @@ -232,7 +236,7 @@ def testAtomSymmetryNumber(self): def testBondSymmetryNumber(self): # ethane - struct = Structure() + struct = Molecule() struct.fromSMILES('CC') symmetryNumber = 1 for bond in struct.bonds(): @@ -240,7 +244,7 @@ def testBondSymmetryNumber(self): self.assertEqual(symmetryNumber, 2) # propane - struct = Structure() + struct = Molecule() struct.fromSMILES('CCC') symmetryNumber = 1 for bond in struct.bonds(): @@ -248,7 +252,7 @@ def testBondSymmetryNumber(self): self.assertEqual(symmetryNumber, 1) # butane - struct = Structure() + struct = Molecule() struct.fromSMILES('CCCC') symmetryNumber = 1 for bond in struct.bonds(): @@ -256,7 +260,7 @@ def testBondSymmetryNumber(self): self.assertEqual(symmetryNumber, 2) # ethylene - struct = Structure() + struct = Molecule() struct.fromSMILES('C=C') symmetryNumber = 1 for bond in struct.bonds(): @@ -264,7 +268,7 @@ def testBondSymmetryNumber(self): self.assertEqual(symmetryNumber, 2) # acetylene - struct = Structure() + struct = Molecule() struct.fromSMILES('C#C') symmetryNumber = 1 for bond in struct.bonds(): @@ -291,7 +295,7 @@ def testAxisSymmetryNumber(self): fail_message = '' for smile,should_be in test_set: - struct = Structure(SMILES=smile) + struct = Molecule(SMILES=smile) symmetryNumber = struct.calculateAxisSymmetryNumber() if symmetryNumber!=should_be: fail_message+="Got axis symmetry number of %s for %s (expected %s)\n"%(symmetryNumber,struct,should_be) @@ -300,7 +304,7 @@ def testAxisSymmetryNumber(self): # def testCyclicSymmetryNumber(self): # # # cyclohexane -# struct = Structure() +# struct = Molecule() # struct.fromInChI('InChI=1/C6H12/c1-2-4-6-5-3-1/h1-6H2') # symmetryNumber = struct.calculateCyclicSymmetryNumber() # self.assertEqual(symmetryNumber, 12) @@ -325,7 +329,7 @@ def testSymmetryNumber(self): ] fail_message = '' for smile,should_be in test_set: - struct = Structure(SMILES=smile) + struct = Molecule(SMILES=smile) struct.calculateSymmetryNumber() symmetryNumber = struct.symmetryNumber if symmetryNumber!=should_be: @@ -343,7 +347,7 @@ def testRotorNumber(self): ] fail_message = '' for smile,should_be in test_set: - struct = Structure(SMILES=smile) + struct = Molecule(SMILES=smile) rotorNumber = struct.calculateNumberOfRotors() if rotorNumber!=should_be: fail_message+="Got rotor number of %s for %s (expected %s)\n"%(rotorNumber,struct,should_be) @@ -356,7 +360,7 @@ def testRotorNumberHard(self): ] fail_message = '' for smile,should_be in test_set: - struct = Structure(SMILES=smile) + struct = Molecule(SMILES=smile) rotorNumber = struct.calculateNumberOfRotors() if rotorNumber!=should_be: fail_message+="Got rotor number of %s for %s (expected %s)\n"%(rotorNumber,struct,should_be) @@ -378,7 +382,7 @@ def testLinear(self): ] fail_message = '' for smile,should_be in test_set: - struct = Structure(SMILES=smile) + struct = Molecule(SMILES=smile) symmetryNumber = struct.isLinear() if symmetryNumber!=should_be: fail_message+="Got linearity %s for %s (expected %s)\n"%(symmetryNumber,struct,should_be) @@ -390,7 +394,7 @@ def testH(self): """ # InChI - struct = Structure() + struct = Molecule() struct.fromInChI('InChI=1/H') self.assertTrue(len(struct.atoms()) == 1) H = struct.atoms()[0] @@ -398,7 +402,7 @@ def testH(self): self.assertTrue(H.getFreeElectronCount() == 1) # SMILES - struct = Structure(SMILES='[H]') + struct = Molecule(SMILES='[H]') self.assertTrue(len(struct.atoms()) == 1) H = struct.atoms()[0] self.assertTrue(H.isHydrogen()) @@ -417,18 +421,18 @@ def testH(self): startup = """gc.enable() # enable garbage collection in timeit import sys sys.path.append('../source') -from rmg.structure import Structure -structure1 = Structure() -structure1.fromSMILES('C=CC=C[CH]C') -structure2 = Structure() -structure2.fromSMILES('C[CH]C=CC=C') -structure3 = Structure() -structure3.fromSMILES('C(CCC)CCCC(CC(C(OOC(c1ccccc1)CCCCCCC=CC)c1ccccc1)CCCCCCCC)O[O]') -structure4 = Structure() -structure4.fromSMILES('C(CCC)CCCC(CC(C(OOC(c1ccccc1)CCCCCCCCC)c1ccccc1)CCCCCC=CC)O[O]') +from rmgpy.molecule import Molecule +molecule1 = Molecule() +molecule1.fromSMILES('C=CC=C[CH]C') +molecule2 = Molecule() +molecule2.fromSMILES('C[CH]C=CC=C') +molecule3 = Molecule() +molecule3.fromSMILES('C(CCC)CCCC(CC(C(OOC(c1ccccc1)CCCCCCC=CC)c1ccccc1)CCCCCCCC)O[O]') +molecule4 = Molecule() +molecule4.fromSMILES('C(CCC)CCCC(CC(C(OOC(c1ccccc1)CCCCCCCCC)c1ccccc1)CCCCCC=CC)O[O]') """ - test1 = "structure1.isIsomorphic(structure2)" - test2 = "structure3.isIsomorphic(structure4)" + test1 = "molecule1.isIsomorphic(molecule2)" + test2 = "molecule3.isIsomorphic(molecule4)" print "Timing isIsomorphic:" t = Timer(test1,startup) times = t.repeat(repeat=20,number=1)#000) diff --git a/unittest/rmg/thermotest.py b/unittest/rmg/thermotest.py index 289e402052..21c002abe1 100755 --- a/unittest/rmg/thermotest.py +++ b/unittest/rmg/thermotest.py @@ -8,21 +8,21 @@ import math -import rmg.data as data -import rmg.species as species -import rmg.structure as structure -import rmg.log as logging +import rmgpy.data as data +import rmgpy.species as species +import rmgpy.molecule as structure +import logging -from rmg.thermo.model import * -from rmg.thermo.converter import * -from rmg.thermo.data import * +from rmgpy.thermo import * +#from rmg.thermo.converter import * +#from rmg.thermo.data import * # Run this whether being run as __main__ or called by other unit test suite: # Load databases databasePath = 'data/RMG_database' # Create and load thermo databases and forbidden structures -rmg.thermo.data.loadThermoDatabase(databasePath + '/') +data.loadThermoDatabase(databasePath + '/') ################################################################################ @@ -247,7 +247,7 @@ def testHeatCapacity(self): Uses Propane as a test-case. atoms=11, rotors=2, linear=False """ - propane = structure.Structure(SMILES='CCC') + propane = molecule.Molecule(SMILES='CCC') propane.updateAtomTypes() GAthermoData = generateThermoData(propane,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) @@ -266,7 +266,7 @@ def testEnthalpy(self): Uses Propane as a test-case. atoms=11, rotors=2, linear=False """ - propane = structure.Structure(SMILES='CCC') + propane = molecule.Molecule(SMILES='CCC') propane.updateAtomTypes() GAthermoData = generateThermoData(propane,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) @@ -285,7 +285,7 @@ def testEntropy(self): Uses Propane as a test-case. atoms=11, rotors=2, linear=False """ - propane = structure.Structure(SMILES='CCC') + propane = molecule.Molecule(SMILES='CCC') propane.updateAtomTypes() GAthermoData = generateThermoData(propane,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) @@ -316,7 +316,7 @@ def testHeatCapacity(self): Uses Propane as a test-case. atoms=11, rotors=2, linear=False """ - propane = structure.Structure(SMILES='CCC') + propane = molecule.Molecule(SMILES='CCC') propane.updateAtomTypes() GAthermoData = generateThermoData(propane,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) @@ -336,7 +336,7 @@ def testEntropy(self): Uses Propane as a test-case. atoms=11, rotors=2, linear=False """ - propane = structure.Structure(SMILES='CCC') + propane = molecule.Molecule(SMILES='CCC') propane.updateAtomTypes() GAthermoData = generateThermoData(propane,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) @@ -356,7 +356,7 @@ def testEnthalpy(self): Uses Propane as a test-case. atoms=11, rotors=2, linear=False """ - propane = structure.Structure(SMILES='CCC') + propane = molecule.Molecule(SMILES='CCC') propane.updateAtomTypes() GAthermoData = generateThermoData(propane,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) @@ -385,7 +385,7 @@ def testOxygenFromGA(self): """Check conversion of GA values for molecular oxygen to NASA form """ - oxygen = structure.Structure(SMILES='O=O') + oxygen = molecule.Molecule(SMILES='O=O') oxygen.updateAtomTypes() GAthermoData = generateThermoData(oxygen,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=2, rotors=0, linear=True) @@ -421,7 +421,7 @@ def testOxygenGA(self): """ - oxygen = structure.Structure(SMILES='O=O') + oxygen = molecule.Molecule(SMILES='O=O') oxygen.updateAtomTypes() GAthermoData = generateThermoData(oxygen,thermoClass=ThermoData) #the following values come from Greg's Windows computer @@ -554,7 +554,7 @@ def testNASAfromCp(self): import rmg.species as species import rmg.structure as structure from rmg.structure import Structure -propane = structure.Structure(SMILES='CCC') +propane = molecule.Molecule(SMILES='CCC') propane.updateAtomTypes() GAthermoData = generateThermoData(propane,thermoClass=ThermoData) WilhoitData = convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) diff --git a/unittest/statmechTest.py b/unittest/statmechTest.py index 41b99b1c15..67a52bb0fc 100644 --- a/unittest/statmechTest.py +++ b/unittest/statmechTest.py @@ -481,7 +481,7 @@ def testModesForOxygen(self): T = 298.15 trans = Translation(mass=0.03199) - rot = RigidRotor(linear=True, inertia=[1.9271e-46], symmetry=2) + rot = RigidRotor(linear=True, inertia=1.9271e-46, symmetry=2) vib = HarmonicOscillator(frequencies=[1637.9]) self.assertAlmostEqual(trans.getPartitionFunction(T) / 7.11169e6, 1.0, 3) diff --git a/unittest/thermoTest.py b/unittest/thermoTest.py index 346ccd4b1c..5f925b6f0b 100644 --- a/unittest/thermoTest.py +++ b/unittest/thermoTest.py @@ -144,7 +144,7 @@ def testFreeEnergy(self): Test the ThermoData.getFreeEnergy() method. """ for T in [300,400,500,600,800,1000,1500,2000]: - self.assertEqual(self.thermo.getFreeEnergy(T), self.thermo.getEnthalpy(T) - T * self.thermo.getEntropy(T)) + self.assertAlmostEqual(self.thermo.getFreeEnergy(T), self.thermo.getEnthalpy(T) - T * self.thermo.getEntropy(T), 9) def testPickle(self): """ @@ -271,7 +271,7 @@ def testFreeEnergy(self): Test the Wilhoit.getFreeEnergy() method. """ for T in [300,400,500,600,800,1000,1500,2000]: - self.assertEqual(self.thermo.getFreeEnergy(T), self.thermo.getEnthalpy(T) - T * self.thermo.getEntropy(T)) + self.assertAlmostEqual(self.thermo.getFreeEnergy(T), self.thermo.getEnthalpy(T) - T * self.thermo.getEntropy(T), 9) def testPickle(self): """ @@ -394,7 +394,7 @@ def testFreeEnergy(self): Test the NASA.getFreeEnergy() method. """ for T in [300,400,500,600,800,1000,1500,2000]: - self.assertEqual(self.thermo.getFreeEnergy(T), self.thermo.getEnthalpy(T) - T * self.thermo.getEntropy(T)) + self.assertAlmostEqual(self.thermo.getFreeEnergy(T), self.thermo.getEnthalpy(T) - T * self.thermo.getEntropy(T), 9) def testPickle(self): """