Skip to content

Commit

Permalink
Fixed makeNewSpecies() to handle both Species and Molecule objects.
Browse files Browse the repository at this point in the history
This is needed because reactions generated from a kinetics library are given
in terms of Species objects, not Molecule objects. Therefore we must be able
to handle both cases.

Closes #35.
  • Loading branch information
jwallen committed Jun 10, 2011
1 parent d83ccfa commit 2e54320
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rmgpy/rmg/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def database(path, thermoLibraries=None, reactionLibraries=None, frequenciesLibr
def species(label, structure, reactive=True):
global speciesDict, reactionModel
logging.debug('Found {0} species "{1}" ({2})'.format('reactive' if reactive else 'nonreactive', label, structure.toSMILES()))
speciesDict[label], isNew = reactionModel.makeNewSpecies(label=label, molecule=structure, reactive=reactive)
speciesDict[label], isNew = reactionModel.makeNewSpecies(structure, label=label, reactive=reactive)

def CML(string):
return Molecule().fromCML(string)
Expand Down
19 changes: 14 additions & 5 deletions rmgpy/rmg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,20 @@ def checkForExistingSpecies(self, molecule):
# At this point we can conclude that the structure does not exist
return False, None

def makeNewSpecies(self, molecule, label='', reactive=True, checkForExisting=True):
def makeNewSpecies(self, object, label='', reactive=True, checkForExisting=True):
"""
Create a new species.
Formally create a new species from the specified `object`, which can be
either a :class:`Molecule` object or an :class:`rmgpy.species.Species`
object.
"""

if isinstance(object, rmgpy.species.Species):
molecule = object.molecule[0]
label = label if label != '' else object.label
reactive = object.reactive
else:
molecule = object

molecule.clearLabeledAtoms()
molecule.makeHydrogensImplicit()

Expand Down Expand Up @@ -744,9 +753,9 @@ def makeNewReaction(self, forward, checkExisting=True):
made such that the forward reaction is exothermic at 298K.
"""

# Convert the reactants and products to species objects
forward.reactants = [self.makeNewSpecies(molecule)[0] for molecule in forward.reactants]
forward.products = [self.makeNewSpecies(molecule)[0] for molecule in forward.products]
# Determine the proper species objects for all reactants and products
forward.reactants = [self.makeNewSpecies(reactant)[0] for reactant in forward.reactants]
forward.products = [self.makeNewSpecies(product)[0] for product in forward.products ]

if checkExisting:
found, rxn = self.checkForExistingReaction(forward)
Expand Down

0 comments on commit 2e54320

Please sign in to comment.