Skip to content

Commit

Permalink
Update unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajocher committed Apr 21, 2019
1 parent c92c756 commit 6ed0fc6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 102 deletions.
2 changes: 1 addition & 1 deletion rmgpy/rmg/modelTest.py
Expand Up @@ -396,7 +396,7 @@ def testInflate(self):
"""
spcA = Species().fromSMILES('[OH]')
spcs = [Species().fromSMILES('CC'), Species().fromSMILES('[CH3]')]
spcTuples = [(spcA, spc) for spc in spcs]
spcTuples = [((spcA, spc), 'H_Abstraction') for spc in spcs]

rxns = list(react(*spcTuples))

Expand Down
102 changes: 1 addition & 101 deletions rmgpy/rmg/reactTest.py
Expand Up @@ -38,7 +38,7 @@
from rmgpy.species import Species

from rmgpy.rmg.main import RMG
from rmgpy.rmg.react import react, react_all, deflate, deflateReaction
from rmgpy.rmg.react import react, react_all

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

Expand Down Expand Up @@ -85,68 +85,6 @@ def testReactMultiproc(self):
self.assertIsNotNone(reactionList)
self.assertTrue(all([isinstance(rxn, TemplateReaction) for rxn in reactionList]))

def testDeflate(self):
"""
Test that reaction deflate function works.
"""
molA = Species().fromSMILES('[OH]')
molB = Species().fromSMILES('CC')
molC = Species().fromSMILES('[CH3]')

reactants = [molA, molB]

# both reactants were already part of the core:
reactantIndices = [1, 2]

rxn = Reaction(reactants=[molA, molB], products=[molC],
pairs=[(molA, molC), (molB, molC)])

deflate([rxn], reactants, reactantIndices)

for spc, t in zip(rxn.reactants, [int, int]):
self.assertTrue(isinstance(spc, t))
self.assertEquals(rxn.reactants, reactantIndices)
for spc in rxn.products:
self.assertTrue(isinstance(spc, Species))

# one of the reactants was not yet part of the core:
reactantIndices = [-1, 2]

rxn = Reaction(reactants=[molA, molB], products=[molC],
pairs=[(molA, molC), (molB, molC)])

deflate([rxn], reactants, reactantIndices)

for spc, t in zip(rxn.reactants, [Species, int]):
self.assertTrue(isinstance(spc, t))
for spc in rxn.products:
self.assertTrue(isinstance(spc, Species))

def testReactStoreIndices(self):
"""
Test that reaction generation keeps track of the original species indices.
"""

indices = {'[OH]':1, 'CC':2, '[CH3]':3}

# make it bidirectional so that we can look-up indices as well:
revd=dict([reversed(i) for i in indices.items()])
indices.update(revd)

spcA = Species(index=indices['[OH]']).fromSMILES('[OH]')
spcs = [Species(index=indices['CC']).fromSMILES('CC'),
Species(index=indices['[CH3]']).fromSMILES('[CH3]')]

spcTuples = [(spcA, spc) for spc in spcs]

reactionList = list(react(*spcTuples))
self.assertIsNotNone(reactionList)
self.assertEquals(len(reactionList), 3)
for rxn in reactionList:
for i, reactant in enumerate(rxn.reactants):
rxn.reactants[i] = Molecule().fromSMILES(indices[reactant])
self.assertTrue(rxn.isBalanced())

def testReactAll(self):
"""
Test that the reactAll function works.
Expand All @@ -166,44 +104,6 @@ def testReactAll(self):
self.assertIsNotNone(rxns)
self.assertTrue(all([isinstance(rxn, TemplateReaction) for rxn in rxns]))

def testDeflateReaction(self):
"""
Test if the deflateReaction function works.
"""

molA = Species().fromSMILES('[OH]')
molB = Species().fromSMILES('CC')
molC = Species().fromSMILES('[CH3]')

# both reactants were already part of the core:
reactantIndices = [1, 2]
molDict = {molA.molecule[0]: 1, molB.molecule[0]: 2}

rxn = Reaction(reactants=[molA, molB], products=[molC],
pairs=[(molA, molC), (molB, molC)])

deflateReaction(rxn, molDict)

for spc, t in zip(rxn.reactants, [int, int]):
self.assertTrue(isinstance(spc, t))
self.assertEquals(rxn.reactants, reactantIndices)
for spc in rxn.products:
self.assertTrue(isinstance(spc, Species))

# one of the reactants was not yet part of the core:
reactantIndices = [-1, 2]
molDict = {molA.molecule[0]: molA, molB.molecule[0]: 2}

rxn = Reaction(reactants=[molA, molB], products=[molC],
pairs=[(molA, molC), (molB, molC)])

deflateReaction(rxn, molDict)

for spc, t in zip(rxn.reactants, [Species, int]):
self.assertTrue(isinstance(spc, t), 'Species {} is not of type {}'.format(spc,t))
for spc in rxn.products:
self.assertTrue(isinstance(spc, Species))

def tearDown(self):
"""
Reset the loaded database
Expand Down

0 comments on commit 6ed0fc6

Please sign in to comment.