本文整理汇总了Python中rmgpy.molecule.group.GroupAtom类的典型用法代码示例。如果您正苦于以下问题:Python GroupAtom类的具体用法?Python GroupAtom怎么用?Python GroupAtom使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GroupAtom类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testApplyActionLoseRadical
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], charge=[0], label='*1', lonePairs=[0])
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.decrementRadical))
for a in atomType.incrementRadical:
self.assertTrue(a in atom.atomType, "LOSE_RADICAL on {0} gave {1} not {2}".format(atomType, atom.atomType, atomType.decrementRadical))
self.assertEqual(atom0.radicalElectrons, [r + 1 for r in atom.radicalElectrons])
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
self.assertEqual(atom0.lonePairs, atom.lonePairs)
except ActionError:
self.assertEqual(len(atomType.decrementRadical), 0)
#test when radicals unspecified
group = Group().fromAdjacencyList("""
1 R ux
""") #ux causes a wildcare for radicals
atom1 = group.atoms[0]
atom1.applyAction(action)
self.assertListEqual(atom1.radicalElectrons, [0,1,2,3])
示例2: testEquivalent
def testEquivalent(self):
"""
Test the GroupAtom.equivalent() method.
"""
for label1, atomType1 in atomTypes.iteritems():
for label2, atomType2 in atomTypes.iteritems():
atom1 = GroupAtom(atomType=[atomType1], radicalElectrons=[1], charge=[0], label="*1")
atom2 = GroupAtom(atomType=[atomType2], radicalElectrons=[1], charge=[0], label="*1")
if label1 == label2 or atomType2 in atomType1.generic or atomType1 in atomType2.generic:
self.assertTrue(atom1.equivalent(atom2), "{0!s} is not equivalent to {1!s}".format(atom1, atom2))
self.assertTrue(atom2.equivalent(atom1), "{0!s} is not equivalent to {1!s}".format(atom2, atom1))
else:
self.assertFalse(atom1.equivalent(atom2), "{0!s} is equivalent to {1!s}".format(atom1, atom2))
self.assertFalse(atom2.equivalent(atom1), "{0!s} is equivalent to {1!s}".format(atom2, atom1))
# Now see if charge and radical count are checked properly
for charge in range(3):
for radicals in range(2):
atom3 = GroupAtom(atomType=[atomType1], radicalElectrons=[radicals], charge=[charge], label="*1")
if radicals == 1 and charge == 0:
self.assertTrue(
atom1.equivalent(atom3), "{0!s} is not equivalent to {1!s}".format(atom1, atom3)
)
self.assertTrue(
atom1.equivalent(atom3), "{0!s} is not equivalent to {1!s}".format(atom3, atom1)
)
else:
self.assertFalse(atom1.equivalent(atom3), "{0!s} is equivalent to {1!s}".format(atom1, atom3))
self.assertFalse(atom1.equivalent(atom3), "{0!s} is equivalent to {1!s}".format(atom3, atom1))
示例3: testIsSpecificCaseOf
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], charge=[0], label="*1")
atom2 = GroupAtom(atomType=[atomType2], radicalElectrons=[1], charge=[0], label="*1")
# And make more generic types of these two atoms
atom1gen = GroupAtom(atomType=[atomType1], radicalElectrons=[0, 1], charge=[0, 1], label="*1")
atom2gen = GroupAtom(atomType=[atomType2], radicalElectrons=[0, 1], charge=[0, 1], label="*1")
if label1 == label2 or atomType2 in atomType1.generic:
self.assertTrue(
atom1.isSpecificCaseOf(atom2), "{0!s} is not a specific case of {1!s}".format(atom1, atom2)
)
self.assertTrue(
atom1.isSpecificCaseOf(atom2gen),
"{0!s} is not a specific case of {1!s}".format(atom1, atom2gen),
)
self.assertFalse(
atom1gen.isSpecificCaseOf(atom2), "{0!s} is a specific case of {1!s}".format(atom1gen, atom2)
)
else:
self.assertFalse(
atom1.isSpecificCaseOf(atom2), "{0!s} is a specific case of {1!s}".format(atom1, atom2)
)
self.assertFalse(
atom1.isSpecificCaseOf(atom2gen), "{0!s} is a specific case of {1!s}".format(atom1, atom2gen)
)
self.assertFalse(
atom1gen.isSpecificCaseOf(atom2), "{0!s} is a specific case of {1!s}".format(atom1gen, atom2)
)
示例4: testApplyActionDecrementBond
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], 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.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.decrementBond), 0)
示例5: testApplyActionLoseRadical
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], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.decrementRadical))
for a in atomType.incrementRadical:
self.assertTrue(a in atom.atomType, "LOSE_RADICAL on {0} gave {1} not {2}".format(atomType, atom.atomType, atomType.decrementRadical))
self.assertEqual(atom0.radicalElectrons, [r + 1 for r in atom.radicalElectrons])
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.decrementRadical), 0)
示例6: testApplyActionFormBond
def testApplyActionFormBond(self):
"""
Test the GroupAtom.applyAction() method for a FORM_BOND action.
"""
action = ["FORM_BOND", "*1", "S", "*2"]
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label="*1")
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.formBond))
for a in atomType.formBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.formBond), 0)
示例7: testApplyActionLosePair
def testApplyActionLosePair(self):
"""
Test the GroupAtom.applyAction() method for a LOSE_PAIR action when lonePairs is either specified or not.
"""
action = ['LOSE_PAIR', '*1', 1]
# lonePairs specified:
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label='*1', lonePairs=[1])
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.decrementLonePair))
for a in atomType.decrementLonePair:
self.assertTrue(a in atom.atomType,
"LOSE_PAIR on {0} gave {1} not {2}".format(atomType, atom.atomType,
atomType.decrementLonePair))
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
self.assertEqual(atom0.lonePairs, [r + 1 for r in atom.lonePairs])
except ActionError:
self.assertEqual(len(atomType.decrementLonePair), 0)
#lonePairs unspecified:
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.decrementLonePair))
for a in atomType.decrementLonePair:
self.assertTrue(a in atom.atomType,
"LOSE_PAIR on {0} gave {1} not {2}".format(atomType, atom.atomType,
atomType.decrementLonePair))
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
self.assertEqual([1,2,3,4], [r + 1 for r in atom.lonePairs])
except ActionError:
self.assertEqual(len(atomType.decrementLonePair), 0)
示例8: testApplyActionBreakBond
def testApplyActionBreakBond(self):
"""
Test the GroupAtom.applyAction() method for a BREAK_BOND action.
"""
action = ['BREAK_BOND', '*1', 1, '*2']
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label='*1', lonePairs=[0])
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.breakBond))
for a in atomType.breakBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
self.assertEqual(atom0.label, atom.label)
self.assertEqual(atom0.lonePairs, atom.lonePairs)
except ActionError:
self.assertEqual(len(atomType.breakBond), 0)
示例9: setUp
def setUp(self):
"""
A method called before each unit test in this class.
"""
self.atom = GroupAtom(atomType=[atomTypes['Cd']], radicalElectrons=[1], charge=[0], label='*1')
示例10: TestGroupAtom
class TestGroupAtom(unittest.TestCase):
"""
Contains unit tests of the GroupAtom class.
"""
def setUp(self):
"""
A method called before each unit test in this class.
"""
self.atom = GroupAtom(atomType=[atomTypes['Cd']], radicalElectrons=[1], charge=[0], label='*1')
def testApplyActionBreakBond(self):
"""
Test the GroupAtom.applyAction() method for a BREAK_BOND action.
"""
action = ['BREAK_BOND', '*1', 1, '*2']
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.breakBond))
for a in atomType.breakBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.breakBond), 0)
def testApplyActionFormBond(self):
"""
Test the GroupAtom.applyAction() method for a FORM_BOND action.
"""
action = ['FORM_BOND', '*1', 1, '*2']
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.formBond))
for a in atomType.formBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.formBond), 0)
def testApplyActionIncrementBond(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], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.incrementBond))
for a in atomType.incrementBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.incrementBond), 0)
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], 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.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.decrementBond), 0)
def testApplyActionGainRadical(self):
"""
Test the GroupAtom.applyAction() method for a GAIN_RADICAL action.
"""
action = ['GAIN_RADICAL', '*1', 1]
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], 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, "GAIN_RADICAL on {0} gave {1} not {2}".format(atomType, atom.atomType, atomType.incrementRadical))
#.........这里部分代码省略.........
示例11: TestGroupAtom
class TestGroupAtom(unittest.TestCase):
"""
Contains unit tests of the GroupAtom class.
"""
def setUp(self):
"""
A method called before each unit test in this class.
"""
self.atom = GroupAtom(atomType=[atomTypes['Cd']], radicalElectrons=[1], charge=[0], label='*1')
def testApplyActionBreakBond(self):
"""
Test the GroupAtom.applyAction() method for a BREAK_BOND action.
"""
action = ['BREAK_BOND', '*1', 'S', '*2']
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.breakBond))
for a in atomType.breakBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.breakBond), 0)
def testApplyActionFormBond(self):
"""
Test the GroupAtom.applyAction() method for a FORM_BOND action.
"""
action = ['FORM_BOND', '*1', 'S', '*2']
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.formBond))
for a in atomType.formBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.formBond), 0)
def testApplyActionIncrementBond(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], charge=[0], label='*1')
atom = atom0.copy()
try:
atom.applyAction(action)
self.assertEqual(len(atom.atomType), len(atomType.incrementBond))
for a in atomType.incrementBond:
self.assertTrue(a in atom.atomType)
self.assertEqual(atom0.radicalElectrons, atom.radicalElectrons)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.incrementBond), 0)
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], 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.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)
except ActionError:
self.assertEqual(len(atomType.decrementBond), 0)
def testApplyActionGainRadical(self):
"""
Test the GroupAtom.applyAction() method for a GAIN_RADICAL action.
"""
action = ['GAIN_RADICAL', '*1', 1]
for label, atomType in atomTypes.iteritems():
atom0 = GroupAtom(atomType=[atomType], radicalElectrons=[1], 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, "GAIN_RADICAL on {0} gave {1} not {2}".format(atomType, atom.atomType, atomType.incrementRadical))
#.........这里部分代码省略.........