Skip to content

Commit ca3b3bc

Browse files
committed
Added (failing) radical detection test to unittest/moleculeTest.py
When reading in from the smiles '[CH]' the carbon ends up with a radicalElectrons count of 0 instead of 3. Strangely, [CH2] and [CH3] work fine. This causes problems in data/thermo.py when trying to find the thermo for [CH].
1 parent 05c9e44 commit ca3b3bc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

rmgpy/data/thermo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def getThermoDataFromGroups(self, molecule):
582582

583583
thermoData = None
584584

585-
if sum([atom.radicalElectrons for atom in molecule.atoms]) > 0:
585+
if sum([atom.radicalElectrons for atom in molecule.atoms]) > 0: # radical species
586586

587587
# Make a copy of the structure so we don't change the original
588588
saturatedStruct = molecule.copy(deep=True)
@@ -646,7 +646,7 @@ def getThermoDataFromGroups(self, molecule):
646646

647647
# Correct the entropy for the symmetry number
648648

649-
else:
649+
else: # non-radical species
650650
# Generate estimate of thermodynamics
651651
for atom in molecule.atoms:
652652
# Iterate over heavy (non-hydrogen) atoms

unittest/moleculeTest.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,22 @@ def testPickle(self):
856856
self.assertEqual(molecule0.getFormula(), molecule.getFormula())
857857
self.assertTrue(molecule0.isIsomorphic(molecule))
858858
self.assertTrue(molecule.isIsomorphic(molecule0))
859-
859+
860+
def testRadicalCH(self):
861+
"""
862+
Test that the species [CH] has three radical electrons and a spin multiplicity of 4.
863+
"""
864+
molecule = Molecule().fromSMILES('[CH]')
865+
self.assertEqual(molecule.atoms[0].radicalElectrons, 3)
866+
self.assertEqual(molecule.atoms[0].spinMultiplicity, 4)
867+
868+
def testRadicalCH2(self):
869+
"""
870+
Test that the species [CH2] has two radical electrons and a spin multiplicity of 3.
871+
"""
872+
molecule = Molecule().fromSMILES('[CH2]')
873+
self.assertEqual(molecule.atoms[0].radicalElectrons, 2)
874+
self.assertEqual(molecule.atoms[0].spinMultiplicity, 3)
860875
################################################################################
861876

862877
class TestMoleculeSymmetry(unittest.TestCase):

0 commit comments

Comments
 (0)