当前位置: 首页>>代码示例>>Python>>正文


Python Structure.distance方法代码示例

本文整理汇总了Python中diffpy.Structure.Structure.distance方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.distance方法的具体用法?Python Structure.distance怎么用?Python Structure.distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在diffpy.Structure.Structure的用法示例。


在下文中一共展示了Structure.distance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestStructure

# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import distance [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()
#.........这里部分代码省略.........
开发者ID:benfrandsen,项目名称:diffpy.Structure,代码行数:103,代码来源:TestStructure.py


注:本文中的diffpy.Structure.Structure.distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。