本文整理汇总了Python中rmgpy.molecule.group.GroupAtom.makeSampleAtom方法的典型用法代码示例。如果您正苦于以下问题:Python GroupAtom.makeSampleAtom方法的具体用法?Python GroupAtom.makeSampleAtom怎么用?Python GroupAtom.makeSampleAtom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rmgpy.molecule.group.GroupAtom
的用法示例。
在下文中一共展示了GroupAtom.makeSampleAtom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGroupAtom
# 需要导入模块: from rmgpy.molecule.group import GroupAtom [as 别名]
# 或者: from rmgpy.molecule.group.GroupAtom import makeSampleAtom [as 别名]
#.........这里部分代码省略.........
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)
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))
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))
def testCopy(self):
"""
Test the GroupAtom.copy() method.
"""
atom = self.atom.copy()
self.assertEqual(len(self.atom.atomType), len(atom.atomType))
self.assertEqual(self.atom.atomType[0].label, atom.atomType[0].label)
self.assertEqual(self.atom.radicalElectrons, atom.radicalElectrons)
self.assertEqual(self.atom.charge, atom.charge)
self.assertEqual(self.atom.label, atom.label)
def testPickle(self):
"""
Test that a GroupAtom object can be successfully pickled and
unpickled with no loss of information.
"""
import cPickle
atom = cPickle.loads(cPickle.dumps(self.atom))
self.assertEqual(len(self.atom.atomType), len(atom.atomType))
self.assertEqual(self.atom.atomType[0].label, atom.atomType[0].label)
self.assertEqual(self.atom.radicalElectrons, atom.radicalElectrons)
self.assertEqual(self.atom.charge, atom.charge)
self.assertEqual(self.atom.label, atom.label)
def testHasWildcards(self):
"""
Tests the GroupAtom.hasWildcards() method
"""
self.assertFalse(self.atom.hasWildcards())
adjlist = """
1 *2 C u0 {2,[D,T]} {3,S}
2 *3 C u0 {1,[D,T]} {4,S}
3 C ux {1,S} {5,S}
4 C u[0,1] {2,S}
5 [C,O] u0 {3,S}
"""
group = Group().fromAdjacencyList(adjlist)
for index, atom in enumerate(group.atoms):
self.assertTrue(atom.hasWildcards(), 'GroupAtom with index {0} should have wildcards, but does not'.format(index))
def testMakeSampleAtom(self):
"""
Tests the GroupAtom.makeSampleAtom() method
"""
newAtom = self.atom.makeSampleAtom()
self.assertEquals(newAtom.element, elements.__dict__['C'])
self.assertEquals(newAtom.radicalElectrons, 1)
self.assertEquals(newAtom.charge, 0)