本文整理汇总了Python中diffpy.Structure.Structure.assignUniqueLabels方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.assignUniqueLabels方法的具体用法?Python Structure.assignUniqueLabels怎么用?Python Structure.assignUniqueLabels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffpy.Structure.Structure
的用法示例。
在下文中一共展示了Structure.assignUniqueLabels方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_angle
# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import assignUniqueLabels [as 别名]
def test_angle(self):
"""check Structure.angle()
"""
cdse = Structure(filename=cdsefile)
cdse.assignUniqueLabels()
self.assertEqual(109, round(cdse.angle(0, 2, 1)))
self.assertEqual(109, round(cdse.angle("Cd1", "Se1", "Cd2")))
return
示例2: test_label
# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import assignUniqueLabels [as 别名]
def test_label(self):
"""check Structure.label
"""
cdse = Structure(self.cdse)
self.assertEqual(4 * [''], cdse.label.tolist())
cdse.assignUniqueLabels()
self.assertEqual('Cd1 Cd2 Se1 Se2'.split(), cdse.label.tolist())
cdse.label = cdse.label.lower()
self.assertEqual('cd1 cd2 se1 se2'.split(), cdse.label.tolist())
return
示例3: test___getitem__
# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import assignUniqueLabels [as 别名]
def test___getitem__(self):
"""check Structure.__getitem__()
"""
stru = self.stru
self.failUnless(stru[0] is stru.tolist()[0])
intidx = range(len(stru))[::-1]
self.assertEqual(stru[intidx].tolist(), stru.tolist()[::-1])
flagidx = (numpy.arange(len(stru)) > 0)
self.assertEqual(stru[flagidx].tolist(), stru.tolist()[1:])
cdse = Structure(self.cdse)
self.assertEqual([cdse[0], cdse[-2]], cdse[0, -2].tolist())
cdse013 = cdse.tolist()
cdse013.pop(2)
self.assertEqual(cdse013, cdse[:2,3].tolist())
self.assertRaises(IndexError, cdse.__getitem__, 'Cd1')
cdse.assignUniqueLabels()
self.failUnless(cdse[0] is cdse['Cd1'])
cdse[0].label = 'Hohenzollern'
self.assertRaises(IndexError, cdse.__getitem__, 'Cd1')
self.failUnless(cdse[0] is cdse['Hohenzollern'])
self.assertEqual([cdse[0], cdse[3], cdse[1]],
cdse['Hohenzollern', 3:0:-2].tolist())
return
示例4: TestStructure
# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import assignUniqueLabels [as 别名]
class TestStructure(unittest.TestCase):
"""test methods of Structure class"""
_loaded_structures = {}
def setUp(self):
self.stru = Structure( [ Atom('C', [0,0,0]), Atom('C', [1,1,1]) ],
lattice=Lattice(1, 1, 1, 90, 90, 120) )
if not self._loaded_structures:
self._loaded_structures.update([
('cdse', Structure(filename=cdsefile)),
('tei', Structure(filename=teifile)),
('pbte', Structure(filename=pbtefile)),
])
self.__dict__.update(self._loaded_structures)
self.places = 12
return
def assertListAlmostEqual(self, l1, l2, places=None):
"""wrapper for list comparison"""
if places is None: places = self.places
self.assertEqual(len(l1), len(l2))
for i in range(len(l1)):
self.assertAlmostEqual(l1[i], l2[i], places)
# FIXME move into TestAtom
def test_cartesian(self):
"""check conversion to cartesian coordinates"""
from math import sqrt
stru = self.stru
s_rc0 = stru[0].xyz_cartn
f_rc0 = 3*[0.0]
s_rc1 = stru[1].xyz_cartn
f_rc1 = [sqrt(0.75), 0.5, 1.]
self.assertListAlmostEqual(s_rc0, f_rc0)
self.assertListAlmostEqual(s_rc1, f_rc1)
# def test___init__(self):
# """check Structure.__init__()
# """
# return
def test___copy__(self):
"""check Structure.__copy__()
"""
cdse = Structure(filename=cdsefile)
cdse_str = cdse.writeStr('pdffit')
cdse2 = copy.copy(cdse)
self.assertEqual(cdse_str, cdse2.writeStr('pdffit'))
self.failIf(cdse.lattice is cdse2.lattice)
sameatoms = set(cdse).intersection(cdse2)
self.failIf(sameatoms)
return
# def test___str__(self):
# """check Structure.__str__()
# """
# return
#
# def test_addNewAtom(self):
# """check Structure.addNewAtom()
# """
# return
#
# def test_getLastAtom(self):
# """check Structure.getLastAtom()
# """
# return
def test_assignUniqueLabels(self):
"""check Structure.assignUniqueLabels()
"""
self.assertEqual('', ''.join([a.label for a in self.stru]))
self.stru.assignUniqueLabels()
self.assertEqual('C1', self.stru[0].label)
self.assertEqual('C2', self.stru[1].label)
return
def test_distance(self):
"""check Structure.distance()
"""
from math import sqrt
self.stru.assignUniqueLabels()
self.assertRaises(IndexError, self.stru.distance, 333, "C1")
self.assertRaises(IndexError, self.stru.distance, "C", "C1")
self.assertAlmostEqual(sqrt(2.0),
self.stru.distance(0, 1), self.places)
self.assertAlmostEqual(sqrt(2.0),
self.stru.distance("C1", "C2"), self.places)
self.assertEqual(0, self.stru.distance(0, "C1"))
return
def test_angle(self):
"""check Structure.angle()
"""
cdse = Structure(filename=cdsefile)
cdse.assignUniqueLabels()
#.........这里部分代码省略.........