Skip to content

Commit 3a73cff

Browse files
committed
added aromaticity recognition for symmetry calcs
Aromaticity is now perceived in calculating cyclic symmetry numbers. This commit copies a molecule inside `calculateCyclicSymmetryNumber`, turns it into an rdkit object, finds all the aromatic bonds and atoms. The same bonds and atoms in the corresponding rmg molecule object are then redifined so that the alogorithm is using the correct information. There is one strange thing about this fix that I dont yet understand. The unittest thinks cyclic symmetry number of dimethylbenzene is 1 (should be 2). On my local machine, the same `calculateCyclicSymmetryNumber` function gets it correct, at 2. Also, i'm inadvertantly printing a bit to stdout, and not sure why it's happening? relevant to issues ReactionMechanismGenerator#12, ReactionMechanismGenerator#24, ReactionMechanismGenerator#119, ReactionMechanismGenerator#70, ReactionMechanismGenerator#141
1 parent d48aac9 commit 3a73cff

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

rmgpy/molecule/molecule.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ def applyAction(self, action):
567567
self.incrementOrder()
568568
elif action[2] == -1:
569569
self.decrementOrder()
570+
elif action[2] == 'B':
571+
self.order = 'B'
570572
else:
571573
raise ActionError('Unable to update Bond due to CHANGE_BOND action: Invalid order "{0}".'.format(action[2]))
572574
else:

rmgpy/molecule/symmetry.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,31 @@ def calculateCyclicSymmetryNumber(molecule):
343343
Get the symmetry number correction for cyclic regions of a molecule.
344344
For complicated fused rings the smallest set of smallest rings is used.
345345
"""
346-
346+
from rdkit.Chem.rdmolops import SanitizeMol
347+
from rdkit.Chem.rdchem import Mol
348+
mcopy = molecule.toRDKitMol(removeHs=True, returnMapping=False)
349+
SanitizeMol(mcopy)
347350
symmetryNumber = 1
348-
351+
349352
# Get symmetry number for each ring in structure
350353
rings = molecule.getSmallestSetOfSmallestRings()
351354
for ring0 in rings:
352355

353356
# Make copy of structure
354357
structure = molecule.copy(True)
355358
ring = [structure.atoms[molecule.atoms.index(atom)] for atom in ring0]
356-
359+
# Figure out which atoms and bonds are aromatic and reassign appropriately:
360+
for i, atom1 in enumerate(ring0):
361+
for atom2 in ring0[i+1:]:
362+
if molecule.hasBond(atom1, atom2):
363+
if str(mcopy.GetBondBetweenAtoms(i,i+1)) != 'None':
364+
if str(mcopy.GetBondBetweenAtoms(i,i+1).GetBondType()) == 'AROMATIC':
365+
bond = molecule.getBond(atom1, atom2)
366+
bond.applyAction(['CHANGE_BOND', atom1, 'B', atom2])
367+
atom1.atomType.label = 'Cb'
368+
atom2.atomType.label = 'Cb'
369+
else:
370+
pass
357371
# Remove bonds of ring from structure
358372
for i, atom1 in enumerate(ring):
359373
for atom2 in ring[i+1:]:

rmgpy/molecule/symmetryTest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ def testCyclicSymmetryNumberCyclohexane(self):
244244
symmetryNumber = calculateCyclicSymmetryNumber(molecule)
245245
self.assertEqual(symmetryNumber, 12)
246246

247-
@work_in_progress
248247
def testCyclicSymmetryNumberBenzene(self):
249248
"""
250249
Test the Molecule.calculateCyclicSymmetryNumber() method.

0 commit comments

Comments
 (0)