Skip to content

Commit

Permalink
Merge pull request #167 from bbuesser/master
Browse files Browse the repository at this point in the history
Add and modify calls for generateTransportData() and add updateLonePairs to fix adjacency lists generated by fromSMILES
  • Loading branch information
rwest committed Dec 12, 2013
2 parents d8e7734 + eb1c544 commit 8531027
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
26 changes: 24 additions & 2 deletions rmgpy/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ def fromRDKitMol(self, rdkitmol):
"""
# Below are the declared variables for cythonizing the module
cython.declare(i=cython.int)
cython.declare(radicalElectrons=cython.int, spinMultiplicity=cython.int, charge=cython.int)
cython.declare(radicalElectrons=cython.int, spinMultiplicity=cython.int, charge=cython.int, lonePairs=cython.int)
cython.declare(atom=Atom, atom1=Atom, atom2=Atom, bond=Bond)

self.vertices = []
Expand Down Expand Up @@ -1076,7 +1076,7 @@ def fromRDKitMol(self, rdkitmol):
# Process charge
charge = rdkitatom.GetFormalCharge()

atom = Atom(element, radicalElectrons, spinMultiplicity, charge)
atom = Atom(element, radicalElectrons, spinMultiplicity, charge, '', 0)
self.vertices.append(atom)

# Add bonds by iterating again through atoms
Expand All @@ -1098,6 +1098,7 @@ def fromRDKitMol(self, rdkitmol):

# Set atom types and connectivity values
self.updateConnectivityValues()
self.updateLonePairs()
self.updateAtomTypes()

return self
Expand Down Expand Up @@ -1790,4 +1791,25 @@ def getRadicalAtoms(self):
if atom.radicalElectrons > 0:
radicalAtomsList.append(atom)
return radicalAtomsList

def updateLonePairs(self):
"""
Iterate through the atoms in the structure and calcualte the
number of lone electron pairs, assumin a neutral molecule.
"""
for atom1 in self.vertices:
order = 0
if not atom1.isHydrogen():
for atom2, bond12 in atom1.edges.items():
if bond12.isSingle():
order = order + 1
if bond12.isDouble():
order = order + 2
if bond12.isTriple():
order = order + 3

atom1.lonePairs = 4 - atom1.radicalElectrons - order

else:
atom1.lonePairs = 0

3 changes: 0 additions & 3 deletions rmgpy/rmg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ def initialize(self, args):
# DON'T generate any more reactions for the seed species at this time
for seedMechanism in self.seedMechanisms:
self.reactionModel.addSeedMechanismToCore(seedMechanism, react=False)

for spec in self.reactionModel.core.species:
spec.generateTransportData(self.database)

# Reaction libraries: add species and reactions from reaction library to the edge so
# that RMG can find them if their rates are large enough
Expand Down
2 changes: 2 additions & 0 deletions rmgpy/rmg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ def addSeedMechanismToCore(self, seedMechanism, react=False):
r, isNew = self.makeNewReaction(rxn) # updates self.newSpeciesList and self.newReactionlist
for spec in self.newSpeciesList:
if spec.reactive: spec.generateThermoData(database, quantumMechanics=self.quantumMechanics)
spec.generateTransportData(database)
for spec in self.newSpeciesList:
self.addSpeciesToCore(spec)

Expand Down Expand Up @@ -1327,6 +1328,7 @@ def addReactionLibraryToEdge(self, reactionLibrary):
if not isNew: logging.info("This library reaction was not new: {0}".format(rxn))
for spec in self.newSpeciesList:
if spec.reactive: spec.generateThermoData(database, quantumMechanics=self.quantumMechanics)
spec.generateTransportData(database)
for spec in self.newSpeciesList:
self.addSpeciesToEdge(spec)

Expand Down

0 comments on commit 8531027

Please sign in to comment.