本文整理汇总了Python中pymatgen.transformations.advanced_transformations.MagOrderingTransformation类的典型用法代码示例。如果您正苦于以下问题:Python MagOrderingTransformation类的具体用法?Python MagOrderingTransformation怎么用?Python MagOrderingTransformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MagOrderingTransformation类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ferrimagnetic
def test_ferrimagnetic(self):
trans = MagOrderingTransformation({"Fe": 5}, 0.75, max_cell_size=1)
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
check_for_POTCAR=False)
s = p.structure
alls = trans.apply_transformation(s, 10)
self.assertEqual(len(alls), 2)
示例2: test_zero_spin_case
def test_zero_spin_case(self):
#ensure that zero spin case maintains sites and formula
s = self.get_structure('Li2O')
trans = MagOrderingTransformation({"Li+": 0.0}, 0.5)
alls = trans.apply_transformation(s)
#Ensure s does not have a spin property
self.assertFalse('spin' in s.sites[0].specie._properties)
#ensure sites are assigned a spin property in alls
self.assertTrue('spin' in alls.sites[0].specie._properties)
示例3: test_as_from_dict
def test_as_from_dict(self):
trans = MagOrderingTransformation({"Fe": 5}, 0.75)
d = trans.as_dict()
#Check json encodability
s = json.dumps(d)
trans = MagOrderingTransformation.from_dict(d)
self.assertEqual(trans.mag_species_spin, {"Fe": 5})
from pymatgen.analysis.energy_models import SymmetryModel
self.assertIsInstance(trans.energy_model, SymmetryModel)
示例4: test_zero_spin_case
def test_zero_spin_case(self):
# ensure that zero spin case maintains sites and formula
s = self.get_structure('Li2O')
trans = MagOrderingTransformation({"Li+": 0.0}, order_parameter=0.5)
alls = trans.apply_transformation(s)
Li_site = alls.indices_from_symbol('Li')[0]
# Ensure s does not have a spin property
self.assertFalse('spin' in s.sites[Li_site].specie._properties)
# ensure sites are assigned a spin property in alls
self.assertTrue('spin' in alls.sites[Li_site].specie._properties)
self.assertEqual(alls.sites[Li_site].specie._properties['spin'], 0)
示例5: test_zero_spin_case
def test_zero_spin_case(self):
#ensure that zero spin case maintains sites and formula
from pymatgen.io.smartio import read_structure
s = read_structure(os.path.join(test_dir, 'Li2O.cif'))
trans = MagOrderingTransformation({"Li+": 0.0}, 0.5)
alls = trans.apply_transformation(s)
#compositions will not be equal due to spin assignment
#structure representations will be the same
self.assertEqual(str(s), str(alls))
#Ensure s does not have a spin property
self.assertFalse('spin' in s.sites[0].specie._properties)
#ensure sites are assigned a spin property in alls
self.assertTrue('spin' in alls.sites[0].specie._properties)
示例6: test_apply_transformation
def test_apply_transformation(self):
trans = MagOrderingTransformation({"Fe": 5})
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
check_for_POTCAR=False)
s = p.structure
alls = trans.apply_transformation(s, 10)
self.assertEqual(len(alls), 3)
f = SpacegroupAnalyzer(alls[0]["structure"], 0.1)
self.assertEqual(f.get_space_group_number(), 31)
model = IsingModel(5, 5)
trans = MagOrderingTransformation({"Fe": 5},
energy_model=model)
alls2 = trans.apply_transformation(s, 10)
# Ising model with +J penalizes similar neighbor magmom.
self.assertNotEqual(alls[0]["structure"], alls2[0]["structure"])
self.assertEqual(alls[0]["structure"], alls2[2]["structure"])
s = self.get_structure('Li2O')
# Li2O doesn't have magnetism of course, but this is to test the
# enumeration.
trans = MagOrderingTransformation({"Li+": 1}, max_cell_size=3)
alls = trans.apply_transformation(s, 100)
# TODO: check this is correct, unclear what len(alls) should be
self.assertEqual(len(alls), 12)
trans = MagOrderingTransformation({"Ni": 5})
alls = trans.apply_transformation(self.NiO.get_primitive_structure(),
return_ranked_list=10)
self.assertEqual(self.NiO_AFM_111.lattice, alls[0]["structure"].lattice)
self.assertEqual(self.NiO_AFM_001.lattice, alls[1]["structure"].lattice)
示例7: test_apply_transformation
def test_apply_transformation(self):
trans = MagOrderingTransformation({"Fe": 5})
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
check_for_POTCAR=False)
s = p.structure
alls = trans.apply_transformation(s, 10)
self.assertEqual(len(alls), 3)
f = SymmetryFinder(alls[0]["structure"], 0.1)
self.assertEqual(f.get_spacegroup_number(), 31)
model = IsingModel(5, 5)
trans = MagOrderingTransformation({"Fe": 5},
energy_model=model)
alls2 = trans.apply_transformation(s, 10)
#Ising model with +J penalizes similar neighbor magmom.
self.assertNotEqual(alls[0]["structure"], alls2[0]["structure"])
self.assertEqual(alls[0]["structure"], alls2[2]["structure"])
from pymatgen.io.smartio import read_structure
s = read_structure(os.path.join(test_dir, 'Li2O.cif'))
#Li2O doesn't have magnetism of course, but this is to test the
# enumeration.
trans = MagOrderingTransformation({"Li+": 1}, max_cell_size=3)
alls = trans.apply_transformation(s, 100)
self.assertEqual(len(alls), 10)
示例8: test_advanced_usage
def test_advanced_usage(self):
# test spin on just one oxidation state
magtypes = {"Fe2+": 5}
trans = MagOrderingTransformation(magtypes)
alls = trans.apply_transformation(self.Fe3O4_oxi)
self.assertIsInstance(alls, Structure)
self.assertEqual(str(alls[0].specie), "Fe2+,spin=5")
self.assertEqual(str(alls[2].specie), "Fe3+")
# test multiple order parameters
# this should only order on Fe3+ site, but assign spin to both
magtypes = {"Fe2+": 5, "Fe3+": 5}
order_parameters = [
MagOrderParameterConstraint(1, species_constraints="Fe2+"),
MagOrderParameterConstraint(0.5, species_constraints="Fe3+")
]
trans = MagOrderingTransformation(magtypes, order_parameter=order_parameters)
alls = trans.apply_transformation(self.Fe3O4_oxi)
# using this 'sorted' syntax because exact order of sites in first
# returned structure varies between machines: we just want to ensure
# that the order parameter is accurate
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(0,2)]),
sorted(["Fe2+,spin=5", "Fe2+,spin=5"]))
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(2, 6)]),
sorted(["Fe3+,spin=5", "Fe3+,spin=5",
"Fe3+,spin=-5", "Fe3+,spin=-5"]))
self.assertEqual(str(alls[0].specie), "Fe2+,spin=5")
# this should give same results as previously
# but with opposite sign on Fe2+ site
magtypes = {"Fe2+": -5, "Fe3+": 5}
order_parameters = [
MagOrderParameterConstraint(1, species_constraints="Fe2+"),
MagOrderParameterConstraint(0.5, species_constraints="Fe3+")
]
trans = MagOrderingTransformation(magtypes, order_parameter=order_parameters)
alls = trans.apply_transformation(self.Fe3O4_oxi)
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(0,2)]),
sorted(["Fe2+,spin=-5", "Fe2+,spin=-5"]))
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(2, 6)]),
sorted(["Fe3+,spin=5", "Fe3+,spin=5",
"Fe3+,spin=-5", "Fe3+,spin=-5"]))
# while this should order on both sites
magtypes = {"Fe2+": 5, "Fe3+": 5}
order_parameters = [
MagOrderParameterConstraint(0.5, species_constraints="Fe2+"),
MagOrderParameterConstraint(0.25, species_constraints="Fe3+")
]
trans = MagOrderingTransformation(magtypes, order_parameter=order_parameters)
alls = trans.apply_transformation(self.Fe3O4_oxi)
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(0,2)]),
sorted(["Fe2+,spin=5", "Fe2+,spin=-5"]))
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(2, 6)]),
sorted(["Fe3+,spin=5", "Fe3+,spin=-5",
"Fe3+,spin=-5", "Fe3+,spin=-5"]))
# add coordination numbers to our test case
# don't really care what these are for the test case
cns = [6, 6, 6, 6, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0]
self.Fe3O4.add_site_property('cn', cns)
# this should give FM ordering on cn=4 sites, and AFM ordering on cn=6 sites
magtypes = {"Fe": 5}
order_parameters = [
MagOrderParameterConstraint(0.5, species_constraints="Fe",
site_constraint_name="cn", site_constraints=6),
MagOrderParameterConstraint(1.0, species_constraints="Fe",
site_constraint_name="cn", site_constraints=4)
]
trans = MagOrderingTransformation(magtypes, order_parameter=order_parameters)
alls = trans.apply_transformation(self.Fe3O4)
alls.sort(key=lambda x: x.properties['cn'], reverse=True)
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(0, 4)]),
sorted(["Fe,spin=-5", "Fe,spin=-5",
"Fe,spin=5", "Fe,spin=5"]))
self.assertEqual(sorted([str(alls[idx].specie) for idx in range(4,6)]),
sorted(["Fe,spin=5", "Fe,spin=5"]))
# now ordering on both sites, equivalent to order_parameter = 0.5
magtypes = {"Fe2+": 5, "Fe3+": 5}
order_parameters = [
MagOrderParameterConstraint(0.5, species_constraints="Fe2+"),
MagOrderParameterConstraint(0.5, species_constraints="Fe3+")
]
trans = MagOrderingTransformation(magtypes, order_parameter=order_parameters)
alls = trans.apply_transformation(self.Fe3O4_oxi, return_ranked_list=10)
struct = alls[0]["structure"]
self.assertEqual(sorted([str(struct[idx].specie) for idx in range(0,2)]),
sorted(["Fe2+,spin=5", "Fe2+,spin=-5"]))
self.assertEqual(sorted([str(struct[idx].specie) for idx in range(2, 6)]),
sorted(["Fe3+,spin=5", "Fe3+,spin=-5",
"Fe3+,spin=-5", "Fe3+,spin=5"]))
self.assertEqual(len(alls), 4)
# now mixed orderings where neither are equal or 1
magtypes = {"Fe2+": 5, "Fe3+": 5}
order_parameters = [
MagOrderParameterConstraint(0.5, species_constraints="Fe2+"),
#.........这里部分代码省略.........