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


Python Structure.from_file方法代码示例

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


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

示例1: test_ordering_enumeration

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
    def test_ordering_enumeration(self):

        # simple afm
        structure = Structure.from_file(os.path.join(ref_dir, "ordering/LaMnO3.json"))
        wf = MagneticOrderingsWF(structure)
        self.assertEqual(wf.input_origin, "afm")

        # ferrimagnetic (Cr produces net spin)
        structure = Structure.from_file(os.path.join(ref_dir, "ordering/Cr2NiO4.json"))
        wf = MagneticOrderingsWF(structure)
        self.assertEqual(wf.input_origin, "ferri_by_Cr")

        # antiferromagnetic on single magnetic site
        structure = Structure.from_file(os.path.join(ref_dir, "ordering/Cr2WO6.json"))
        wf = MagneticOrderingsWF(structure)
        self.assertEqual(wf.input_origin, "afm_by_Cr")

        # afm requiring large cell size
        # (enable for further development of workflow, too slow for CI)

        # structure = Structure.from_file(os.path.join(ref_dir, "CuO.json"))
        # wf = MagneticOrderingsWF(structure, default_magmoms={'Cu': 1.73},
        #                         transformation_kwargs={'max_cell_size': 4})
        # self.assertEqual(wf.input_origin, "afm")

        # antiferromagnetic by structural motif
        structure = Structure.from_file(os.path.join(ref_dir, "ordering/Ca3Co2O6.json"))
        wf = MagneticOrderingsWF(
            structure,
            strategies=("antiferromagnetic_by_motif",),
            # this example just misses default cut-off, so do not truncate
            truncate_by_symmetry=False,
            transformation_kwargs={"max_cell_size": 2},
        )
        self.assertEqual(wf.input_origin, "afm_by_motif_2a")
开发者ID:montoyjh,项目名称:MatMethods,代码行数:37,代码来源:test_magnetism_workflow.py

示例2: test_supercell_fit

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
    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))
开发者ID:gmatteo,项目名称:pymatgen,代码行数:13,代码来源:test_structure_matcher.py

示例3: run

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
 def run(self):
     if os.path.exists("CONTCAR"):
         structure = Structure.from_file("CONTCAR")
     elif (not self.contcar_only) and os.path.exists("POSCAR"):
         structure = Structure.from_file("POSCAR")
     else:
         raise RuntimeError("No CONTCAR/POSCAR detected to generate input!")
     modname, classname = self.input_set.rsplit(".", 1)
     mod = __import__(modname, globals(), locals(), [classname], 0)
     vis = getattr(mod, classname)(structure, **self.kwargs)
     vis.write_input(".")
开发者ID:materialsproject,项目名称:custodian,代码行数:13,代码来源:jobs.py

示例4: test_get_interstitial_sites_with_octahedra

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
 def test_get_interstitial_sites_with_octahedra(self):
     os.chdir(ROOT)
     structure = Structure.from_file("POSCAR_Cu")
     test_ints = get_interstitial_sites(structure, octahedra=True)
     self.assertTrue(len(test_ints["tetrahedral"]) != 0)
     self.assertTrue(len(test_ints["hexahedral"]) != 0)
     self.assertTrue(len(test_ints["octahedral"]) != 0)
开发者ID:henniggroup,项目名称:MPInterfaces,代码行数:9,代码来源:test_intercalation.py

示例5: run_task

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
    def run_task(self, fw_spec):

        prev_dir = fw_spec.get('PREV_DIR', None)
        self.custom_params = self.get('custom_params', None)   

        if isinstance(self["structure"], Structure):
            s = self["structure"]
        elif isinstance(self["structure"], dict):
            s = Structure.from_dict(self["structure"])
        else:
            s = Structure.from_file(os.path.join(prev_dir, self["structure"]))


        vis = load_class("pymatgen.io.vasp.sets", self["vasp_input_set"])(
                         **self.get("input_set_params", {}))
        vis.write_input(s, ".")


        # Write Custom KPOINTS settings if necessary
        ksettings = self.custom_params.get('user_kpts_settings', None) if isinstance(
                self.custom_params, dict) else None
        if ksettings:
            style = ksettings.get('kpts_style', 'Gamma')
            kpoints = ksettings.get('kpts', [16,16,16])
            shift = ksettings.get('kpts_shift', [0,0,0])
            k = Kpoints(kpts=[kpoints], kpts_shift=shift)
            k.style = style
            k.write_file("KPOINTS")
开发者ID:dcossey014,项目名称:pymatgen,代码行数:30,代码来源:interfaces.py

示例6: test_partial_disorder

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
    def test_partial_disorder(self):
        s = Structure.from_file(filename=os.path.join(test_dir, "garnet.cif"))
        a = SpacegroupAnalyzer(s, 0.1)
        prim = a.find_primitive()
        s = prim.copy()
        s["Al3+"] = {"Al3+": 0.5, "Ga3+": 0.5}
        adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
        adaptor.run()
        structures = adaptor.structures
        self.assertEqual(len(structures), 7)
        for s in structures:
            self.assertEqual(s.formula, 'Ca12 Al4 Ga4 Si12 O48')
        s = prim.copy()
        s["Ca2+"] = {"Ca2+": 1/3, "Mg2+": 2/3}
        adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
        adaptor.run()
        structures = adaptor.structures
        self.assertEqual(len(structures), 20)
        for s in structures:
            self.assertEqual(s.formula, 'Ca4 Mg8 Al8 Si12 O48')

        s = prim.copy()
        s["Si4+"] = {"Si4+": 1/3, "Ge4+": 2/3}
        adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
        adaptor.run()
        structures = adaptor.structures
        self.assertEqual(len(structures), 18)
        for s in structures:
            self.assertEqual(s.formula, 'Ca12 Al8 Si4 Ge8 O48')
开发者ID:albalu,项目名称:pymatgen,代码行数:31,代码来源:test_enumlib_caller.py

示例7: generate_diffraction_plot

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
def generate_diffraction_plot(args):
    s = Structure.from_file(args.filenames[0])
    c = XRDCalculator()
    if args.outfile:
        c.get_xrd_plot(s).savefig(args.outfile[0])
    else:
        c.show_xrd_plot(s)
开发者ID:czhengsci,项目名称:tscccommand,代码行数:9,代码来源:pmg_example.py

示例8: setUp

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
 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"))]
开发者ID:gmatteo,项目名称:pymatgen,代码行数:9,代码来源:test_structure_matcher.py

示例9: test_timeout

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
 def test_timeout(self):
     s = Structure.from_file(filename=os.path.join(test_dir, "garnet.cif"))
     a = SpacegroupAnalyzer(s, 0.1)
     s["Al3+"] = {"Al3+": 0.5, "Ga3+": 0.5}
     adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01,
                              timeout=0.0000000000001)
     self.assertRaises(TimeoutError, adaptor._run_multienum)
开发者ID:albalu,项目名称:pymatgen,代码行数:9,代码来源:test_enumlib_caller.py

示例10: parse_view

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
def parse_view(args):
    from pymatgen.vis.structure_vtk import StructureVis
    excluded_bonding_elements = args.exclude_bonding[0].split(",") \
        if args.exclude_bonding else []
    s = Structure.from_file(args.filename[0])
    vis = StructureVis(excluded_bonding_elements=excluded_bonding_elements)
    vis.set_structure(s)
    vis.show()
开发者ID:adozier,项目名称:pymatgen,代码行数:10,代码来源:pmg.py

示例11: test_align_c_axis_for_non_aligned_structure

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
 def test_align_c_axis_for_non_aligned_structure(self):
     os.chdir(ROOT)
     structure = Structure.from_file('POSCAR_SF6')
     structure = align_axis(structure, 'c', (0, 0, 1))
     control_axis = [9.04099732e-13, -2.42627092e-13, 8.3829076073038635]
     for i in range(3):
         self.assertAlmostEqual(structure.lattice.matrix[2][i],
                                control_axis[i])
开发者ID:henniggroup,项目名称:MPInterfaces,代码行数:10,代码来源:test_utils.py

示例12: test_large_systems

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
 def test_large_systems(self):
     struct = Structure.from_file(os.path.join(test_dir, "La4Fe4O12.cif"))
     user_tag_settings = {"RECIPROCAL": "", "KMESH": "1000"}
     elnes = MPELNESSet("Fe", struct, user_tag_settings=user_tag_settings)
     self.assertNotIn("RECIPROCAL", elnes.tags)
     self.assertNotIn("KMESH", elnes.tags)
     self.assertNotIn("CIF", elnes.tags)
     self.assertNotIn("TARGET", elnes.tags)
开发者ID:albalu,项目名称:pymatgen,代码行数:10,代码来源:test_sets.py

示例13: test_postfeffset

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
    def test_postfeffset(self):
        self.mp_xanes.write_input(os.path.join('.', 'xanes_3'))
        feff_dict_input = FEFFDictSet.from_directory(os.path.join('.', 'xanes_3'))
        self.assertTrue(feff_dict_input.tags == Tags.from_file(os.path.join('.', 'xanes_3/feff.inp')))
        self.assertTrue(str(feff_dict_input.header()) == str(Header.from_file(os.path.join('.', 'xanes_3/HEADER'))))
        feff_dict_input.write_input('xanes_3_regen')
        origin_tags = Tags.from_file(os.path.join('.', 'xanes_3/PARAMETERS'))
        output_tags = Tags.from_file(os.path.join('.', 'xanes_3_regen/PARAMETERS'))
        origin_mole = Atoms.cluster_from_file(os.path.join('.', 'xanes_3/feff.inp'))
        output_mole = Atoms.cluster_from_file(os.path.join('.', 'xanes_3_regen/feff.inp'))
        original_mole_dist = np.array(origin_mole.distance_matrix[0, :]).astype(np.float64)
        output_mole_dist = np.array(output_mole.distance_matrix[0, :]).astype(np.float64)
        original_mole_shell = [x.species_string for x in origin_mole]
        output_mole_shell = [x.species_string for x in output_mole]

        self.assertTrue(np.allclose(original_mole_dist, output_mole_dist))
        self.assertTrue(origin_tags == output_tags)
        self.assertTrue(original_mole_shell == output_mole_shell)

        shutil.rmtree(os.path.join('.', 'xanes_3'))
        shutil.rmtree(os.path.join('.', 'xanes_3_regen'))

        reci_mp_xanes = MPXANESSet(self.absorbing_atom, self.structure,
                                   user_tag_settings={"RECIPROCAL": ""})
        reci_mp_xanes.write_input('xanes_reci')
        feff_reci_input = FEFFDictSet.from_directory(os.path.join('.', 'xanes_reci'))
        self.assertTrue("RECIPROCAL" in feff_reci_input.tags)

        feff_reci_input.write_input('Dup_reci')
        self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'HEADER')))
        self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'feff.inp')))
        self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'PARAMETERS')))
        self.assertFalse(os.path.exists(os.path.join('.', 'Dup_reci', 'ATOMS')))
        self.assertFalse(os.path.exists(os.path.join('.', 'Dup_reci', 'POTENTIALS')))

        tags_original = Tags.from_file(os.path.join('.', 'xanes_reci/feff.inp'))
        tags_output = Tags.from_file(os.path.join('.', 'Dup_reci/feff.inp'))
        self.assertTrue(tags_original == tags_output)

        stru_orig = Structure.from_file(os.path.join('.', 'xanes_reci/Co2O2.cif'))
        stru_reci = Structure.from_file(os.path.join('.', 'Dup_reci/Co2O2.cif'))
        self.assertTrue(stru_orig.__eq__(stru_reci))

        shutil.rmtree(os.path.join('.', 'Dup_reci'))
        shutil.rmtree(os.path.join('.', 'xanes_reci'))
开发者ID:albalu,项目名称:pymatgen,代码行数:47,代码来源:test_sets.py

示例14: test_ignore_species

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
    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"})
开发者ID:gmatteo,项目名称:pymatgen,代码行数:20,代码来源:test_structure_matcher.py

示例15: test_electronegativity

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import from_file [as 别名]
    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)

        # test include_dist
        dists = {Element('N'): 0, Element('P'): 0.0010725064}
        for mapping, d in sm.get_all_anonymous_mappings(s1, s2, include_dist=True):
            self.assertAlmostEqual(dists[mapping[Element('As')]], d)
开发者ID:albalu,项目名称:pymatgen,代码行数:20,代码来源:test_structure_matcher.py


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