Skip to content

Commit

Permalink
Add function updateLonePairs() and call in fromRDKitMol()
Browse files Browse the repository at this point in the history
- setting the number of lone electron pairs
- also fixes fromSMILES and similar functions using fromRDKitMol()
  • Loading branch information
bbuesser committed Dec 12, 2013
1 parent 7b84153 commit eb1c544
Showing 1 changed file with 24 additions and 2 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

0 comments on commit eb1c544

Please sign in to comment.