本文整理匯總了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)