本文整理汇总了Python中pymatgen.core.sites.PeriodicSite.__repr__方法的典型用法代码示例。如果您正苦于以下问题:Python PeriodicSite.__repr__方法的具体用法?Python PeriodicSite.__repr__怎么用?Python PeriodicSite.__repr__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.sites.PeriodicSite
的用法示例。
在下文中一共展示了PeriodicSite.__repr__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PeriodicSiteTest
# 需要导入模块: from pymatgen.core.sites import PeriodicSite [as 别名]
# 或者: from pymatgen.core.sites.PeriodicSite import __repr__ [as 别名]
#.........这里部分代码省略.........
6.22494979899, 5)
self.assertAlmostEqual(self.site.distance_from_point([0.1, 0.1, 0.1]),
6.0564015718906887, 5)
def test_distance_and_image(self):
other_site = PeriodicSite("Fe", np.array([1, 1, 1]), self.lattice)
(distance, image) = self.site.distance_and_image(other_site)
self.assertAlmostEqual(distance, 6.22494979899, 5)
self.assertTrue(([-1, -1, -1] == image).all())
(distance, image) = self.site.distance_and_image(other_site, [1, 0, 0])
self.assertAlmostEqual(distance, 19.461500456028563, 5)
# Test that old and new distance algo give the same ans for
# "standard lattices"
lattice = Lattice(np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))
site1 = PeriodicSite("Fe", np.array([0.01, 0.02, 0.03]), lattice)
site2 = PeriodicSite("Fe", np.array([0.99, 0.98, 0.97]), lattice)
self.assertAlmostEqual(get_distance_and_image_old(site1, site2)[0],
site1.distance_and_image(site2)[0])
lattice = Lattice.from_parameters(1, 0.01, 1, 10, 10, 10)
site1 = PeriodicSite("Fe", np.array([0.01, 0.02, 0.03]), lattice)
site2 = PeriodicSite("Fe", np.array([0.99, 0.98, 0.97]), lattice)
self.assertTrue(get_distance_and_image_old(site1, site2)[0] >
site1.distance_and_image(site2)[0])
site2 = PeriodicSite("Fe", np.random.rand(3), lattice)
(dist_old, jimage_old) = get_distance_and_image_old(site1, site2)
(dist_new, jimage_new) = site1.distance_and_image(site2)
self.assertTrue(dist_old - dist_new > -1e-8,
"New distance algo should give smaller answers!")
self.assertFalse((abs(dist_old - dist_new) < 1e-8) ^
(jimage_old == jimage_new).all(),
"If old dist == new dist, images must be the same!")
latt = Lattice.from_parameters(3.0, 3.1, 10.0, 2.96, 2.0, 1.0)
site = PeriodicSite("Fe", [0.1, 0.1, 0.1], latt)
site2 = PeriodicSite("Fe", [0.99, 0.99, 0.99], latt)
(dist, img) = site.distance_and_image(site2)
self.assertAlmostEqual(dist, 0.15495358379511573)
self.assertEqual(list(img), [-11, 6, 0])
def test_is_periodic_image(self):
other = PeriodicSite("Fe", np.array([1.25, 2.35, 4.45]), self.lattice)
self.assertTrue(self.site.is_periodic_image(other),
"This other site should be a periodic image.")
other = PeriodicSite("Fe", np.array([1.25, 2.35, 4.46]), self.lattice)
self.assertFalse(self.site.is_periodic_image(other),
"This other site should not be a periodic image.")
other = PeriodicSite("Fe", np.array([1.25, 2.35, 4.45]),
Lattice.rhombohedral(2, 60))
self.assertFalse(self.site.is_periodic_image(other),
"Different lattices should not be periodic images.")
def test_equality(self):
other_site = PeriodicSite("Fe", np.array([1, 1, 1]), self.lattice)
self.assertTrue(self.site.__eq__(self.site))
self.assertFalse(other_site.__eq__(self.site))
self.assertFalse(self.site.__ne__(self.site))
self.assertTrue(other_site.__ne__(self.site))
def test_as_from_dict(self):
d = self.site2.as_dict()
site = PeriodicSite.from_dict(d)
self.assertEqual(site, self.site2)
self.assertNotEqual(site, self.site)
d = self.propertied_site.as_dict()
site3 = PeriodicSite({"Si": 0.5, "Fe": 0.5}, [0, 0, 0], self.lattice)
d = site3.as_dict()
site = PeriodicSite.from_dict(d)
self.assertEqual(site.species, site3.species)
d = self.dummy_site.as_dict()
site = PeriodicSite.from_dict(d)
self.assertEqual(site.species, self.dummy_site.species)
def test_to_unit_cell(self):
site = PeriodicSite("Fe", np.array([1.25, 2.35, 4.46]), self.lattice)
site.to_unit_cell(in_place=True)
val = [0.25, 0.35, 0.46]
self.assertArrayAlmostEqual(site.frac_coords, val)
def test_setters(self):
site = self.propertied_site
site.species = "Cu"
self.assertEqual(site.species, Composition("Cu"))
site.x = 1.25
site.y = 1.35
self.assertEqual(site.coords[0], 1.25)
self.assertEqual(site.coords[1], 1.35)
self.assertEqual(site.a, 0.125)
self.assertEqual(site.b, 0.135)
site.lattice = Lattice.cubic(100)
self.assertEqual(site.x, 12.5)
def set_bad_species():
site.species = {"Cu": 0.5, "Gd": 0.6}
self.assertRaises(ValueError, set_bad_species)
site.frac_coords = [0, 0, 0.1]
self.assertArrayAlmostEqual(site.coords, [0, 0, 10])
def test_repr(self):
self.assertEqual(self.propertied_site.__repr__(), "PeriodicSite: Fe2+ (2.5000, 3.5000, 4.5000) [0.2500, 0.3500, 0.4500]")