本文整理汇总了Python中diffpy.Structure.Structure.tolist方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.tolist方法的具体用法?Python Structure.tolist怎么用?Python Structure.tolist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffpy.Structure.Structure
的用法示例。
在下文中一共展示了Structure.tolist方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test___isub__
# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import tolist [as 别名]
def test___isub__(self):
"""check Structure.__isub__()
"""
cdse = Structure(filename=cdsefile)
lat = cdse.lattice
lst = cdse.tolist()
cdse -= cdse[2:]
self.assertEqual(2, len(cdse))
self.assertEqual(4, len(lst))
self.assertEqual('Cd', cdse[0].element)
self.assertEqual('Cd', cdse[1].element)
self.assertEqual(lat, cdse.lattice)
self.assertEqual(lst[:2], cdse.tolist())
return
示例2: test___imul__
# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import tolist [as 别名]
def test___imul__(self):
"""check Structure.__imul__()
"""
cdse = Structure(filename=cdsefile)
lat = cdse.lattice
els = cdse.element
xyz = cdse.xyz
lst = cdse.tolist()
cdse *= 2
self.assertEqual(8, len(cdse))
self.assertEqual(lst, cdse[:4].tolist())
self.assertEqual(numpy.tile(els, 2).tolist(), cdse.element.tolist())
self.failUnless(numpy.array_equal(numpy.tile(xyz, (2, 1)), cdse.xyz))
self.assertEqual(8, len(set(cdse)))
self.assertEqual(8 * [lat], [a.lattice for a in cdse])
return
示例3: test___getitem__
# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import tolist [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 tolist [as 别名]
#.........这里部分代码省略.........
def test_placeInLattice(self):
"""check Structure.placeInLattice() -- conversion of coordinates
"""
stru = self.stru
new_lattice = Lattice(.5, .5, .5, 90, 90, 60)
stru.placeInLattice(new_lattice)
a0 = stru[0]
self.assertListAlmostEqual(a0.xyz, 3*[0.0])
a1 = stru[1]
self.assertListAlmostEqual(a1.xyz, [2.0, 0.0, 2.0])
# def test_read(self):
# """check Structure.read()
# """
# return
#
# def test_readStr(self):
# """check Structure.readStr()
# """
# return
#
# def test_write(self):
# """check Structure.write()
# """
# return
#
# def test_writeStr(self):
# """check Structure.writeStr()
# """
# return
def test_aslist(self):
"""check Structure.tolist()
"""
lst = self.stru.tolist()
self.assertEqual(tuple(lst), tuple(self.stru))
self.assertEqual(list, type(lst))
return
def test_append(self):
"""check Structure.append()
"""
a = Atom("Si", (0.1, 0.2, 0.3))
lat = self.stru.lattice
self.stru.append(a)
alast = self.stru[-1]
self.assertEqual(3, len(self.stru))
self.assertEqual('Si', alast.element)
self.failUnless(lat is alast.lattice)
self.failUnless(numpy.array_equal(a.xyz, alast.xyz))
self.failIf(a is alast)
self.failIf(lat is a.lattice)
return
def test_insert(self):
"""check Structure.insert()
"""
a = Atom("Si", (0.1, 0.2, 0.3))
lat = self.stru.lattice
self.stru.insert(1, a)
a1 = self.stru[1]
self.assertEqual(3, len(self.stru))
self.assertEqual('Si', a1.element)