本文整理汇总了Python中pymatgen.Lattice类的典型用法代码示例。如果您正苦于以下问题:Python Lattice类的具体用法?Python Lattice怎么用?Python Lattice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lattice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5),
["Ni"], [[0, 0, 0]])
lattice = Lattice.cubic(3.010)
frac_coords = [[0.00000, 0.00000, 0.00000],
[0.00000, 0.50000, 0.50000],
[0.50000, 0.00000, 0.50000],
[0.50000, 0.50000, 0.00000],
[0.50000, 0.00000, 0.00000],
[0.50000, 0.50000, 0.50000],
[0.00000, 0.00000, 0.50000],
[0.00000, 0.50000, 0.00000]]
species = ['Mg', 'Mg', 'Mg', 'Mg', 'O', 'O', 'O', 'O']
self.MgO = Structure(lattice, species, frac_coords)
slabs = generate_all_slabs(self.structure, max_index=2,
min_slab_size=6.0, min_vacuum_size=15.0,
max_normal_search=1, center_slab=True)
self.slab_dict = {''.join([str(i) for i in slab.miller_index]):
slab for slab in slabs}
self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"])
self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"])
self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"])
self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"])
self.asf_struct = AdsorbateSiteFinder(
Structure.from_sites(self.slab_dict["111"].sites))
示例2: test_ordered_primitive_to_disordered_supercell
def test_ordered_primitive_to_disordered_supercell(self):
sm_atoms = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size='num_atoms',
comparator=OrderDisorderElementComparator())
sm_sites = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size='num_sites',
comparator=OrderDisorderElementComparator())
lp = Lattice.orthorhombic(10, 20, 30)
pcoords = [[0, 0, 0],
[0.5, 0.5, 0.5]]
ls = Lattice.orthorhombic(20, 20, 30)
scoords = [[0, 0, 0],
[0.5, 0, 0],
[0.25, 0.5, 0.5],
[0.75, 0.5, 0.5]]
s1 = Structure(lp, ['Na', 'Cl'], pcoords)
s2 = Structure(ls, [{'Na': 0.5}, {'Na': 0.5}, {'Cl': 0.5}, {'Cl': 0.5}],
scoords)
self.assertTrue(sm_sites.fit(s1, s2))
self.assertFalse(sm_atoms.fit(s1, s2))
示例3: test_disordered_primitive_to_ordered_supercell
def test_disordered_primitive_to_ordered_supercell(self):
sm_atoms = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size='num_atoms',
comparator=OrderDisorderElementComparator())
sm_sites = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size='num_sites',
comparator=OrderDisorderElementComparator())
lp = Lattice.orthorhombic(10, 20, 30)
pcoords = [[0, 0, 0],
[0.5, 0.5, 0.5]]
ls = Lattice.orthorhombic(20, 20, 30)
scoords = [[0, 0, 0],
[0.75, 0.5, 0.5]]
prim = Structure(lp, [{'Na': 0.5}, {'Cl': 0.5}], pcoords)
supercell = Structure(ls, ['Na', 'Cl'], scoords)
supercell.make_supercell([[-1, 1, 0], [0, 1, 1], [1, 0, 0]])
self.assertFalse(sm_sites.fit(prim, supercell))
self.assertTrue(sm_atoms.fit(prim, supercell))
self.assertRaises(ValueError, sm_atoms.get_s2_like_s1, prim, supercell)
self.assertEqual(len(sm_atoms.get_s2_like_s1(supercell, prim)), 4)
示例4: test_get_supercell_size
def test_get_supercell_size(self):
l = Lattice.cubic(1)
l2 = Lattice.cubic(0.9)
s1 = Structure(l, ['Mg', 'Cu', 'Ag', 'Cu', 'Ag'], [[0] * 3] * 5)
s2 = Structure(l2, ['Cu', 'Cu', 'Ag'], [[0] * 3] * 3)
sm = StructureMatcher(supercell_size='volume')
self.assertEqual(sm._get_supercell_size(s1, s2),
(1, True))
self.assertEqual(sm._get_supercell_size(s2, s1),
(1, True))
sm = StructureMatcher(supercell_size='num_sites')
self.assertEqual(sm._get_supercell_size(s1, s2),
(2, False))
self.assertEqual(sm._get_supercell_size(s2, s1),
(2, True))
sm = StructureMatcher(supercell_size='Ag')
self.assertEqual(sm._get_supercell_size(s1, s2),
(2, False))
self.assertEqual(sm._get_supercell_size(s2, s1),
(2, True))
sm = StructureMatcher(supercell_size='wfieoh')
self.assertRaises(ValueError, sm._get_supercell_size, s1, s2)
示例5: test_lattice_2_lmpbox
def test_lattice_2_lmpbox(self):
matrix = np.diag(np.random.randint(5, 14, size=(3,))) \
+ np.random.rand(3, 3) * 0.2 - 0.1
init_latt = Lattice(matrix)
frac_coords = np.random.rand(10, 3)
init_structure = Structure(init_latt, ["H"] * 10, frac_coords)
origin = np.random.rand(3) * 10 - 5
box, symmop = lattice_2_lmpbox(lattice=init_latt, origin=origin)
boxed_latt = box.to_lattice()
np.testing.assert_array_almost_equal(init_latt.abc, boxed_latt.abc)
np.testing.assert_array_almost_equal(init_latt.angles,
boxed_latt.angles)
cart_coords = symmop.operate_multi(init_structure.cart_coords) \
- origin
boxed_structure = Structure(boxed_latt, ["H"] * 10, cart_coords,
coords_are_cartesian=True)
np.testing.assert_array_almost_equal(boxed_structure.frac_coords,
frac_coords)
tetra_latt = Lattice.tetragonal(5, 5)
tetra_box, _ = lattice_2_lmpbox(tetra_latt)
self.assertIsNone(tetra_box.tilt)
ortho_latt = Lattice.orthorhombic(5, 5, 5)
ortho_box, _ = lattice_2_lmpbox(ortho_latt)
self.assertIsNone(ortho_box.tilt)
rot_tetra_latt = Lattice([[5, 0, 0], [0, 2, 2], [0, -2, 2]])
_, rotop = lattice_2_lmpbox(rot_tetra_latt)
np.testing.\
assert_array_almost_equal(rotop.rotation_matrix,
[[1, 0, 0],
[0, 2 ** 0.5 / 2, 2 ** 0.5 / 2],
[0, -2 ** 0.5 / 2, 2 ** 0.5 / 2]])
示例6: test_structure
def test_structure(self):
quartz = self.quartz.structure
np.testing.assert_array_equal(quartz.lattice.matrix,
[[4.913400, 0, 0],
[-2.456700, 4.255129, 0],
[0, 0, 5.405200]])
self.assertEqual(quartz.formula, "Si3 O6")
self.assertNotIn("molecule-ID", self.quartz.atoms.columns)
ethane = self.ethane.structure
np.testing.assert_array_equal(ethane.lattice.matrix,
np.diag([10.0] * 3))
lbounds = np.array(self.ethane.box.bounds)[:, 0]
coords = self.ethane.atoms[["x", "y", "z"]].values - lbounds
np.testing.assert_array_equal(ethane.cart_coords, coords)
np.testing.assert_array_equal(ethane.site_properties["charge"],
self.ethane.atoms["q"])
tatb = self.tatb.structure
frac_coords = tatb.frac_coords[381]
real_frac_coords = frac_coords - np.floor(frac_coords)
np.testing.assert_array_almost_equal(real_frac_coords,
[0.01553397,
0.71487872,
0.14134139])
co = Structure.from_spacegroup(194,
Lattice.hexagonal(2.50078, 4.03333),
["Co"], [[1/3, 2/3, 1/4]])
ld_co = LammpsData.from_structure(co)
self.assertEqual(ld_co.structure.composition.reduced_formula, "Co")
ni = Structure.from_spacegroup(225, Lattice.cubic(3.50804),
["Ni"], [[0, 0, 0]])
ld_ni = LammpsData.from_structure(ni)
self.assertEqual(ld_ni.structure.composition.reduced_formula, "Ni")
示例7: test_fit
def test_fit(self):
"""
Take two known matched structures
1) Ensure match
2) Ensure match after translation and rotations
3) Ensure no-match after large site translation
4) Ensure match after site shuffling
"""
sm = StructureMatcher()
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
# Test rotational/translational invariance
op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False,
np.array([0.4, 0.7, 0.9]))
self.struct_list[1].apply_operation(op)
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
# Test failure under large atomic translation
self.struct_list[1].translate_sites([0], [.4, .4, .2],
frac_coords=True)
self.assertFalse(sm.fit(self.struct_list[0], self.struct_list[1]))
self.struct_list[1].translate_sites([0], [-.4, -.4, -.2],
frac_coords=True)
# random.shuffle(editor._sites)
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
# Test FrameworkComporator
sm2 = StructureMatcher(comparator=FrameworkComparator())
lfp = self.get_structure("LiFePO4")
nfp = self.get_structure("NaFePO4")
self.assertTrue(sm2.fit(lfp, nfp))
self.assertFalse(sm.fit(lfp, nfp))
# Test anonymous fit.
self.assertEqual(sm.fit_anonymous(lfp, nfp), True)
self.assertAlmostEqual(sm.get_rms_anonymous(lfp, nfp)[0],
0.060895871160262717)
# Test partial occupancies.
s1 = Structure(Lattice.cubic(3),
[{"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
s2 = Structure(Lattice.cubic(3),
[{"Fe": 0.25}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.75}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
self.assertFalse(sm.fit(s1, s2))
self.assertFalse(sm.fit(s2, s1))
s2 = Structure(Lattice.cubic(3),
[{"Mn": 0.5}, {"Mn": 0.5}, {"Mn": 0.5},
{"Mn": 0.5}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
self.assertEqual(sm.fit_anonymous(s1, s2), True)
self.assertAlmostEqual(sm.get_rms_anonymous(s1, s2)[0], 0)
示例8: setUp
def setUp(self):
c1 = [[0.5] * 3, [0.9] * 3]
c2 = [[0.5] * 3, [0.9, 0.1, 0.1]]
s1 = Structure(Lattice.cubic(5), ['Si', 'Si'], c1)
s2 = Structure(Lattice.cubic(5), ['Si', 'Si'], c2)
structs = []
for s in s1.interpolate(s2, 3, pbc=True):
structs.append(Structure.from_sites(s.sites, to_unit_cell=True))
self.structures = structs
self.vis = MITNEBSet(self.structures)
示例9: test_write_inputs
def test_write_inputs(self):
c1 = [[0.5] * 3, [0.9] * 3]
c2 = [[0.5] * 3, [0.9, 0.1, 0.1]]
s1 = Structure(Lattice.cubic(5), ['Si', 'Si'], c1)
s2 = Structure(Lattice.cubic(5), ['Si', 'Si'], c2)
structs = []
for s in s1.interpolate(s2, 3, pbc=True):
structs.append(Structure.from_sites(s.sites, to_unit_cell=True))
fc = self.vis._process_structures(structs)[2].frac_coords
self.assertTrue(np.allclose(fc, [[0.5]*3,[0.9, 1.033333, 1.0333333]]))
示例10: setUp
def setUp(self):
# trivial example, simple square lattice for testing
structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H'], [[0, 0, 0]])
self.square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
# body-centered square lattice for testing
structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'], [[0, 0, 0], [0.5, 0.5, 0.5]])
self.bc_square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0))
self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, -1, 0))
self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
# body-centered square lattice for testing
# directions reversed, should be equivalent to as bc_square
structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'], [[0, 0, 0], [0.5, 0.5, 0.5]])
self.bc_square_sg_r = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
self.bc_square_sg_r.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0))
self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, 0, 0), to_jimage=(0, 0, 0))
self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, -1, 0), to_jimage=(0, 0, 0))
self.bc_square_sg_r.add_edge(1, 0, from_jimage=(0, -1, 0), to_jimage=(0, 0, 0))
# MoS2 example, structure graph obtained from critic2
# (not ground state, from mp-1023924, single layer)
stdout_file = os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files/critic2/MoS2_critic2_stdout.txt')
with open(stdout_file, 'r') as f:
reference_stdout = f.read()
self.structure = Structure.from_file(os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files/critic2/MoS2.cif'))
c2o = Critic2Output(self.structure, reference_stdout)
self.mos2_sg = c2o.structure_graph(edge_weight="bond_length", edge_weight_units="Å")
latt = Lattice.cubic(4.17)
species = ["Ni", "O"]
coords = [[0, 0, 0],
[0.5, 0.5, 0.5]]
self.NiO = Structure.from_spacegroup(225, latt, species, coords).get_primitive_structure()
示例11: test_get_mapping
def test_get_mapping(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=False,
allow_subset=True)
l = Lattice.orthorhombic(1, 2, 3)
s1 = Structure(l, ['Ag', 'Si', 'Si'],
[[.7, .4, .5], [0, 0, 0.1], [0, 0, 0.2]])
s1.make_supercell([2, 1, 1])
s2 = Structure(l, ['Si', 'Si', 'Ag'],
[[0, 0.1, -0.95], [0, 0.1, 0], [-.7, .5, .375]])
shuffle = [2, 0, 1, 3, 5, 4]
s1 = Structure.from_sites([s1[i] for i in shuffle])
# test the mapping
s2.make_supercell([2, 1, 1])
# equal sizes
for i, x in enumerate(sm.get_mapping(s1, s2)):
self.assertEqual(s1[x].species,
s2[i].species)
del s1[0]
# s1 is subset of s2
for i, x in enumerate(sm.get_mapping(s2, s1)):
self.assertEqual(s1[i].species,
s2[x].species)
# s2 is smaller than s1
del s2[0]
del s2[1]
self.assertRaises(ValueError, sm.get_mapping, s2, s1)
示例12: test_process_entry_peroxide
def test_process_entry_peroxide(self):
latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510)
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o]
coords = [[0.666656, 0.666705, 0.750001],
[0.333342, 0.333378, 0.250001],
[0.000001, 0.000041, 0.500001],
[0.000001, 0.000021, 0.000001],
[0.333347, 0.333332, 0.649191],
[0.333322, 0.333353, 0.850803],
[0.666666, 0.666686, 0.350813],
[0.666665, 0.666684, 0.149189]]
struct = Structure(latt, elts, coords)
li2o2_entry = ComputedStructureEntry(struct, -3,
parameters={'is_hubbard': False,
'hubbards': None,
'run_type': 'GGA',
'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003',
'hash': '9658a0ffb28da97ee7b36709966a0d1c'},
{'titel': 'PAW_PBE O 08Apr2002',
'hash': '7af704ddff29da5354831c4609f1cbc5'}]})
li2o2_entry_corrected = self.compat.process_entry(li2o2_entry)
self.assertAlmostEqual(li2o2_entry_corrected.energy, -3 - 0.44317 * 4, 4)
示例13: test_aqueous_compat
def test_aqueous_compat(self):
el_li = Element("Li")
el_o = Element("O")
el_h = Element("H")
latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000)
elts = [el_h, el_h, el_li, el_li, el_o, el_o]
coords = [[0.000000, 0.500000, 0.413969],
[0.500000, 0.000000, 0.586031],
[0.000000, 0.000000, 0.000000],
[0.500000, 0.500000, 0.000000],
[0.000000, 0.500000, 0.192672],
[0.500000, 0.000000, 0.807328]]
struct = Structure(latt, elts, coords)
lioh_entry = ComputedStructureEntry(struct, -3,
parameters={'is_hubbard': False,
'hubbards': None,
'run_type': 'GGA',
'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003',
'hash': '9658a0ffb28da97ee7b36709966a0d1c'},
{'titel': 'PAW_PBE O 08Apr2002',
'hash': '7af704ddff29da5354831c4609f1cbc5'},
{"titel": 'PAW_PBE H 15Jun2001',
'hash': "57732e53d8a424e5b3721d0277f14ef0"}]})
lioh_entry_compat = self.compat.process_entry(lioh_entry)
lioh_entry_compat_aqcorr = self.aqcorr.correct_entry(lioh_entry_compat)
lioh_entry_aqcompat = self.aqcompat.process_entry(lioh_entry)
self.assertAlmostEqual(lioh_entry_compat_aqcorr.energy, lioh_entry_aqcompat.energy, 4)
示例14: test_apply_transformation
def test_apply_transformation(self):
l = Lattice.cubic(4)
s_orig = Structure(l, [{"Li": 0.19, "Na": 0.19, "K": 0.62}, {"O": 1}],
[[0, 0, 0], [0.5, 0.5, 0.5]])
cct = ChargedCellTransformation(charge=3)
s = cct.apply_transformation(s_orig)
self.assertEqual(s.charge, 3)
示例15: test_unique_structure_substitutions_in_two_steps_gives_full_degeneracies
def test_unique_structure_substitutions_in_two_steps_gives_full_degeneracies( self ):
# integration test
# Create a pymatgen structure with 16 sites in a 4x4 square grid
coords = np.array( [ [ 0.0, 0.0, 0.0 ],
[ 0.25, 0.0, 0.0 ],
[ 0.5, 0., 0.0 ],
[ 0.75, 0.0, 0.0 ],
[ 0.0, 0.25, 0.0 ],
[ 0.25, 0.25, 0.0 ],
[ 0.5, 0.25, 0.0 ],
[ 0.75, 0.25, 0.0 ],
[ 0.0, 0.5, 0.0 ],
[ 0.25, 0.5, 0.0 ],
[ 0.5, 0.5, 0.0 ],
[ 0.75, 0.5, 0.0 ],
[ 0.0, 0.75, 0.0 ],
[ 0.25, 0.75, 0.0 ],
[ 0.5, 0.75, 0.0 ],
[ 0.75, 0.75, 0.0 ] ] )
atom_list = [ 'Li' ] * len( coords )
lattice = Lattice.from_parameters( a = 3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90 )
parent_structure = Structure( lattice, atom_list, coords )
us = unique_structure_substitutions( parent_structure, 'Li', { 'Na':1, 'Li':15 } )
ns = unique_structure_substitutions( us[0], 'Li', { 'Mg':1, 'Li':14 } )
self.assertEqual( len( ns ), 5 )
distances = np.array( sorted( [ s.get_distance( s.indices_from_symbol('Mg')[0], s.indices_from_symbol('Na')[0] ) for s in ns ] ) )
np.testing.assert_array_almost_equal( distances, np.array( [ 0.75 , 1.06066 , 1.5 , 1.677051, 2.12132 ] ) )
np.testing.assert_array_equal( np.array( sorted( [ s.number_of_equivalent_configurations for s in ns ] ) ), np.array( [ 1, 2, 4, 4, 4 ] ) )
np.testing.assert_array_equal( np.array( sorted( [ s.full_configuration_degeneracy for s in ns ] ) ), np.array( [ 16, 32, 64, 64, 64 ] ) )