Skip to content

import statements in unit tests outdated. #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 13, 2012
1 change: 1 addition & 0 deletions rmgpy/species.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cdef class Species:
cpdef bint isIsomorphic(self, other)

cpdef fromAdjacencyList(self, adjlist)
cpdef fromSMILES(self, smiles)

cpdef toAdjacencyList(self)

Expand Down
11 changes: 11 additions & 0 deletions rmgpy/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
133 changes: 132 additions & 1 deletion unittest/atomtypeTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import rmgpy.atomtype
from rmgpy.atomtype import AtomType, getAtomType
from rmgpy.molecule import Molecule

################################################################################

Expand Down Expand Up @@ -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__':
Expand Down
5 changes: 3 additions & 2 deletions unittest/cantherm/gaussianTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy
import unittest
import os

from rmgpy.cantherm.gaussian import *
from rmgpy.statmech import *
Expand All @@ -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()

Expand All @@ -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()

Expand Down
10 changes: 6 additions & 4 deletions unittest/data/datatest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

################################################################################

Expand All @@ -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
Expand Down Expand Up @@ -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))

################################################################################

Expand Down
21 changes: 12 additions & 9 deletions unittest/data/thermoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions unittest/kineticsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the KineticsData.isPressureDependent() method.

"""
self.assertFalse(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -195,7 +194,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the Arrhenius.isPressureDependent() method.

"""
self.assertFalse(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -305,7 +303,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the ArrheniusEP.isPressureDependent() method.

"""
self.assertFalse(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -429,7 +426,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the MultiKinetics.isPressureDependent() method.

"""
self.assertFalse(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -536,7 +532,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the PDepArrhenius.isPressureDependent() method.

"""
self.assertTrue(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -669,7 +664,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the Chebyshev.isPressureDependent() method.

"""
self.assertTrue(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -804,7 +798,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the ThirdBody.isPressureDependent() method.

"""
self.assertTrue(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -937,7 +930,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the Lindemann.isPressureDependent() method.

"""
self.assertTrue(self.kinetics.isPressureDependent())

Expand Down Expand Up @@ -1072,7 +1064,6 @@ def setUp(self):
def testIsPressureDependent(self):
"""
Test the Troe.isPressureDependent() method.

"""
self.assertTrue(self.kinetics.isPressureDependent())

Expand Down
2 changes: 1 addition & 1 deletion unittest/rmg/atomtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
sys.path.append('.')

from rmg.chem import *
from rmgpy.molecule import *

################################################################################

Expand Down
2 changes: 1 addition & 1 deletion unittest/rmg/bondtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
sys.path.append('.')

from rmg.chem import *
from rmgpy.molecule import *

################################################################################

Expand Down
4 changes: 2 additions & 2 deletions unittest/rmg/datatest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Loading