def testIsSpecificCaseOf(self): """ Test the GroupAtom.isSpecificCaseOf() method. """ for label1, atomType1 in atomTypes.iteritems(): for label2, atomType2 in atomTypes.iteritems(): atom1 = GroupAtom(atomType=[atomType1], radicalElectrons=[1], spinMultiplicity=[2], charge=[0], label='*1') atom2 = GroupAtom(atomType=[atomType2], radicalElectrons=[1], spinMultiplicity=[2], charge=[0], label='*1') if label1 == label2 or atomType2 in atomType1.generic: self.assertTrue(atom1.isSpecificCaseOf(atom2)) else: self.assertFalse(atom1.isSpecificCaseOf(atom2))
def testApplyActionDecrementBond(self): """ Test the GroupAtom.applyAction() method for a CHANGE_BOND action. """ action = ['CHANGE_BOND', '*1', -1, '*2'] for label, atomType in atomTypes.iteritems(): atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], spinMultiplicity=[2], charge=[0], label='*1') atom = atom0.copy() try: atom.applyAction(action) self.assertEqual(len(atom.atomType), len(atomType.decrementBond)) for a in atomType.decrementBond: self.assertTrue(a in atom.atomType) self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons) self.assertEqual(atom0.spinMultiplicity, atom.spinMultiplicity) self.assertEqual(atom0.charge, atom.charge) self.assertEqual(atom0.label, atom.label) except ActionError: self.assertEqual(len(atomType.decrementBond), 0)
def testApplyActionLoseRadical(self): """ Test the GroupAtom.applyAction() method for a LOSE_RADICAL action. """ action = ['LOSE_RADICAL', '*1', 1] for label, atomType in atomTypes.iteritems(): atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], spinMultiplicity=[2], charge=[0], label='*1') atom = atom0.copy() try: atom.applyAction(action) self.assertEqual(len(atom.atomType), len(atomType.incrementRadical)) for a in atomType.incrementRadical: self.assertTrue(a in atom.atomType) self.assertEqual(atom0.radicalElectrons, [r + 1 for r in atom.radicalElectrons]) self.assertEqual(atom0.spinMultiplicity, [s + 1 for s in atom.spinMultiplicity]) self.assertEqual(atom0.charge, atom.charge) self.assertEqual(atom0.label, atom.label) except ActionError: self.assertEqual(len(atomType.incrementRadical), 0)