本文整理汇总了Python中pymatgen.core.Structure类的典型用法代码示例。如果您正苦于以下问题:Python Structure类的具体用法?Python Structure怎么用?Python Structure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Structure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: run_task
def run_task(self, fw_spec):
user_incar_settings = self["user_incar_settings"]
interpolation_type = self.get("interpolation_type", "IDPP")
idpp_species = fw_spec.get("idpp_species")
user_kpoints_settings = self.get("user_kpoints_settings")
try:
ep0 = Structure.from_dict(fw_spec["ep0"])
ep1 = Structure.from_dict(fw_spec["ep1"])
except:
ep0 = fw_spec["ep0"]
ep1 = fw_spec["ep1"]
# Get number of images.
nimages = user_incar_settings.get("IMAGES", self._get_nimages(ep0, ep1))
if interpolation_type == "IDPP":
from pymatgen_diffusion.neb.pathfinder import IDPPSolver
obj = IDPPSolver.from_endpoints([ep0, ep1], nimages=nimages)
images = obj.run(species=idpp_species)
images_dic_list = [image.as_dict() for image in images]
elif interpolation_type == "linear":
images = self._get_images_by_linear_interp(nimages, ep0, ep1)
images_dic_list = [i.as_dict() for i in images]
else:
raise ValueError("The interpolation method must either be 'linear' or 'IDPP'!")
write = WriteNEBFromImages(neb_label='1', user_incar_settings=user_incar_settings,
user_kpoints_settings=user_kpoints_settings)
fw_spec["neb"] = [images_dic_list]
write.run_task(fw_spec=fw_spec)
示例3: 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)
示例4: test_supercell_fit
def test_supercell_fit(self):
sm = StructureMatcher(attempt_supercell=False)
s1 = Structure.from_file(os.path.join(test_dir, "Al3F9.json"))
s2 = Structure.from_file(os.path.join(test_dir, "Al3F9_distorted.json"))
self.assertFalse(sm.fit(s1, s2))
sm = StructureMatcher(attempt_supercell=True)
self.assertTrue(sm.fit(s1, s2))
self.assertTrue(sm.fit(s2, s1))
示例5: test_get_supercell_matrix
def test_get_supercell_matrix(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True)
l = Lattice.orthorhombic(1, 2, 3)
s1 = Structure(l, ['Si', 'Si', 'Ag'],
[[0,0,0.1],[0,0,0.2],[.7,.4,.5]])
s1.make_supercell([2,1,1])
s2 = Structure(l, ['Si', 'Si', 'Ag'],
[[0,0.1,0],[0,0.1,-0.95],[-.7,.5,.375]])
result = sm.get_supercell_matrix(s1, s2)
self.assertTrue((result == [[-2,0,0],[0,1,0],[0,0,1]]).all())
示例6: test_electronegativity
def test_electronegativity(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5)
s1 = Structure.from_file(os.path.join(test_dir, "Na2Fe2PAsO4S4.json"))
s2 = Structure.from_file(os.path.join(test_dir, "Na2Fe2PNO4Se4.json"))
self.assertEqual(sm.get_best_electronegativity_anonymous_mapping(s1, s2),
{Element('S'): Element('Se'),
Element('As'): Element('N'),
Element('Fe'): Element('Fe'),
Element('Na'): Element('Na'),
Element('P'): Element('P'),
Element('O'): Element('O'),})
self.assertEqual(len(sm.get_all_anonymous_mappings(s1, s2)), 2)
示例7: test_predict
def test_predict(self):
s = PymatgenTest.get_structure("CsCl")
nacl = PymatgenTest.get_structure("CsCl")
nacl.replace_species({"Cs": "Na"})
nacl.scale_lattice(184.384551033)
p = RLSVolumePredictor(radii_type="ionic")
self.assertAlmostEqual(p.predict(s, nacl), 342.84905395082535)
p = RLSVolumePredictor(radii_type="atomic")
self.assertAlmostEqual(p.predict(s, nacl), 391.884366481)
lif = PymatgenTest.get_structure("CsCl")
lif.replace_species({"Cs": "Li", "Cl": "F"})
p = RLSVolumePredictor(radii_type="ionic")
self.assertAlmostEqual(p.predict(lif, nacl), 74.268402413690467)
p = RLSVolumePredictor(radii_type="atomic")
self.assertAlmostEqual(p.predict(lif, nacl), 62.2808125839)
lfpo = PymatgenTest.get_structure("LiFePO4")
lmpo = PymatgenTest.get_structure("LiFePO4")
lmpo.replace_species({"Fe": "Mn"})
p = RLSVolumePredictor(radii_type="ionic")
self.assertAlmostEqual(p.predict(lmpo, lfpo), 310.08253254420134)
p = RLSVolumePredictor(radii_type="atomic")
self.assertAlmostEqual(p.predict(lmpo, lfpo), 299.607967711)
sto = PymatgenTest.get_structure("SrTiO3")
scoo = PymatgenTest.get_structure("SrTiO3")
scoo.replace_species({"Ti4+": "Co4+"})
p = RLSVolumePredictor(radii_type="ionic")
self.assertAlmostEqual(p.predict(scoo, sto), 56.162534974936463)
p = RLSVolumePredictor(radii_type="atomic")
self.assertAlmostEqual(p.predict(scoo, sto), 57.4777835108)
# Use Ag7P3S11 as a test case:
# (i) no oxidation states are assigned and CVP-atomic scheme is selected.
aps = Structure.from_file(os.path.join(dir_path,
"Ag7P3S11_mp-683910_primitive.cif"))
apo = Structure.from_file(os.path.join(dir_path,
"Ag7P3S11_mp-683910_primitive.cif"))
apo.replace_species({"S": "O"})
p = RLSVolumePredictor(radii_type="atomic", check_isostructural=False)
self.assertAlmostEqual(p.predict(apo, aps), 1196.31384276)
# (ii) Oxidation states are assigned.
apo.add_oxidation_state_by_element({"Ag": 1, "P": 5, "O": -2})
aps.add_oxidation_state_by_element({"Ag": 1, "P": 5, "S": -2})
p = RLSVolumePredictor(radii_type="ionic")
self.assertAlmostEqual(p.predict(apo, aps), 1165.23259079)
p = RLSVolumePredictor(radii_type="atomic")
self.assertAlmostEqual(p.predict(apo, aps), 1196.31384276)
示例8: test_find_match2
def test_find_match2(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True, attempt_supercell=False)
l = Lattice.orthorhombic(1, 2, 3)
s1 = Structure(l, ["Si", "Si"], [[0, 0, 0.1], [0, 0, 0.2]])
s2 = Structure(l, ["Si", "Si"], [[0, 0.1, 0], [0, 0.1, -0.95]])
s1, s2, fu, s1_supercell = sm._preprocess(s1, s2, False)
match = sm._strict_match(s1, s2, fu, s1_supercell=False, use_rms=True, break_on_match=False)
scale_matrix = match[2]
s2.make_supercell(scale_matrix)
s2.translate_sites(range(len(s2)), match[3])
self.assertAlmostEqual(np.sum(s2.frac_coords), 0.3)
self.assertAlmostEqual(np.sum(s2.frac_coords[:, :2]), 0)
示例9: test_writebandstr
def test_writebandstr(self):
filepath = os.path.join(test_dir, 'CsI3Pb.cif')
structure = Structure.from_file(filepath)
excin = ExcitingInput(structure)
string = excin.write_string('primitive', bandstr=True)
bandstr = string.split('<properties>')[1].split('</properties>')[0]
coord = []
label = []
coord_ref = [[0.0, 0.0, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.0],
[0.0, 0.5, 0.0],
[0.0, 0.0, 0.0], [0.0, 0.0, 0.5], [0.5, 0.0, 0.5],
[0.5, 0.5, 0.5],
[0.0, 0.5, 0.5], [0.0, 0.0, 0.5], [0.0, 0.5, 0.0],
[0.0, 0.5, 0.5],
[0.5, 0.0, 0.5], [0.5, 0.0, 0.0], [0.5, 0.5, 0.0],
[0.5, 0.5, 0.5]]
label_ref = ['GAMMA', 'X', 'S', 'Y', 'GAMMA', 'Z', 'U', 'R', 'T', 'Z',
'Y', 'T',
'U', 'X', 'S', 'R']
root = ET.fromstring(bandstr)
for plot1d in root.iter('plot1d'):
for point in plot1d.iter('point'):
coord.append([float(i) for i in point.get('coord').split()])
label.append(point.get('label'))
self.assertEqual(label, label_ref)
self.assertEqual(coord, coord_ref)
示例10: setUp
def setUp(self):
with open(os.path.join(test_dir, "TiO2_entries.json"), 'r') as fp:
entries = json.load(fp, cls=MontyDecoder)
self.struct_list = [e.structure for e in entries]
self.oxi_structs = [self.get_structure("Li2O"),
Structure.from_file(os.path.join(
test_dir, "POSCAR.Li2O"))]
示例11: from_dict
def from_dict(cls, d):
structure = Structure.from_dict(d["structure"])
return cls(structure, np.array(d["displacements"]), specie=d["specie"],
temperature=d["temperature"], time_step=d["time_step"],
step_skip=d["step_skip"], min_obs=d["min_obs"],
smoothed=d.get("smoothed", "max"),
avg_nsteps=d.get("avg_nsteps", 1000))
示例12: test_find_match1
def test_find_match1(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True, attempt_supercell=False)
l = Lattice.orthorhombic(1, 2, 3)
s1 = Structure(l, ["Si", "Si", "Ag"], [[0, 0, 0.1], [0, 0, 0.2], [0.7, 0.4, 0.5]])
s2 = Structure(l, ["Si", "Si", "Ag"], [[0, 0.1, 0], [0, 0.1, -0.95], [0.7, 0.5, 0.375]])
s1, s2, fu, s1_supercell = sm._preprocess(s1, s2, False)
match = sm._strict_match(s1, s2, fu, s1_supercell=True, use_rms=True, break_on_match=False)
scale_matrix = match[2]
s2.make_supercell(scale_matrix)
fc = s2.frac_coords + match[3]
fc -= np.round(fc)
self.assertAlmostEqual(np.sum(fc), 0.9)
self.assertAlmostEqual(np.sum(fc[:, :2]), 0.1)
cart_dist = np.sum(match[1] * (l.volume / 3) ** (1 / 3))
self.assertAlmostEqual(cart_dist, 0.15)
示例13: test_find_match2
def test_find_match2(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=True, scale=True,
attempt_supercell=False)
l = Lattice.orthorhombic(1, 2, 3)
s1 = Structure(l, ['Si', 'Si'], [[0,0,0.1],[0,0,0.2]])
s2 = Structure(l, ['Si', 'Si'], [[0,0.1,0],[0,0.1,-0.95]])
match = sm._find_match(s1, s2, break_on_match = False,
use_rms = True, niggli = False)
scale_matrix = np.round(np.dot(match[2].matrix,
s2.lattice.inv_matrix)).astype('int')
s2.make_supercell(scale_matrix)
fc = s2.frac_coords + match[3]
fc -= np.round(fc)
self.assertAlmostEqual(np.sum(fc), 0.3)
self.assertAlmostEqual(np.sum(fc[:,:2]), 0)
示例14: test_electronegativity
def test_electronegativity(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5)
s1 = Structure.from_file(os.path.join(test_dir, "Na2Fe2PAsO4S4.json"))
s2 = Structure.from_file(os.path.join(test_dir, "Na2Fe2PNO4Se4.json"))
self.assertEqual(
sm.get_best_electronegativity_anonymous_mapping(s1, s2),
{
Element("S"): Element("Se"),
Element("As"): Element("N"),
Element("Fe"): Element("Fe"),
Element("Na"): Element("Na"),
Element("P"): Element("P"),
Element("O"): Element("O"),
},
)
self.assertEqual(len(sm.get_all_anonymous_mappings(s1, s2)), 2)
示例15: test_ignore_species
def test_ignore_species(self):
s1 = Structure.from_file(os.path.join(test_dir, "LiFePO4.cif"))
s2 = Structure.from_file(os.path.join(test_dir, "POSCAR"))
m = StructureMatcher(ignored_species=["Li"], primitive_cell=False, attempt_supercell=True)
self.assertTrue(m.fit(s1, s2))
self.assertTrue(m.fit_anonymous(s1, s2))
groups = m.group_structures([s1, s2])
self.assertEqual(len(groups), 1)
s2.make_supercell((2, 1, 1))
ss1 = m.get_s2_like_s1(s2, s1, include_ignored_species=True)
self.assertAlmostEqual(ss1.lattice.a, 20.820740000000001)
self.assertEqual(ss1.composition.reduced_formula, "LiFePO4")
self.assertEqual(
{k.symbol: v.symbol for k, v in m.get_best_electronegativity_anonymous_mapping(s1, s2).items()},
{"Fe": "Fe", "P": "P", "O": "O"},
)