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


Python Structure.from_file方法代码示例

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


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

示例1: test_supercell_fit

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

示例2: test_electronegativity

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

示例3: test_predict

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

示例4: test_writebandstr

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

示例5: setUp

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

示例6: test_ignore_species

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

示例7: test_electronegativity

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

示例8: setUp

# 需要导入模块: from pymatgen.core import Structure [as 别名]
# 或者: from pymatgen.core.Structure import from_file [as 别名]
    def setUp(self):
        """
        1) Basic check for pymatgen configurations.
        2) Setup all test workflow.
        """
        super(TestNudgedElasticBandWorkflow, self).setUp()
        # Structures used for test:
        parent = PymatgenTest.get_structure("Li2O")
        parent.remove_oxidation_states()
        parent.make_supercell(2)
        ep0, ep1 = get_endpoints_from_index(parent, [0, 1])
        neb_dir = [os.path.join(module_dir, "..", "..", "test_files", "neb_wf", "4", "inputs", "{:02}",
                                "POSCAR").format(i) for i in range(5)]
        self.structures = [Structure.from_file(n) for n in neb_dir]

        # Run fake vasp
        test_yaml = os.path.join(module_dir, "../../test_files/neb_wf/config/neb_unittest.yaml")
        with open(test_yaml, 'r') as stream:
            self.config = yaml.safe_load(stream)
            # Use scratch directory as destination directory for testing
            self.config["common_params"]["_fw_env"] = {"run_dest_root": self.scratch_dir}

        # Config 1: The parent structure & two endpoint indexes provided; need relaxation first.
        self.config_1 = copy.deepcopy(self.config)
        self.config_1["common_params"]["is_optimized"] = False
        self.config_1["common_params"]["wf_name"] = "NEB_test_1"

        # Config 2: The parent structure & two endpoint indexes provided; no need to relax.
        self.config_2 = copy.deepcopy(self.config)
        del self.config_2["fireworks"][0]
        self.config_2["common_params"]["is_optimized"] = True
        self.config_2["common_params"]["wf_name"] = "NEB_test_2"

        # Config 3: Two endpoints provided; need to relax two endpoints.
        self.config_3 = copy.deepcopy(self.config)
        del self.config_3["fireworks"][0]
        self.config_3["common_params"]["is_optimized"] = False
        self.config_3["common_params"]["wf_name"] = "NEB_test_3"

        # Config 4: Two relaxed endpoints provided; no need to relax two endpoints.
        self.config_4 = copy.deepcopy(self.config_3)
        del self.config_4["fireworks"][0]
        self.config_4["common_params"]["is_optimized"] = True
        self.config_4["common_params"]["wf_name"] = "NEB_test_4"

        # Config 5: All images including two endpoints are provided.
        self.config_5 = copy.deepcopy(self.config)
        del self.config_5["fireworks"][0: 2]
        self.config_5["common_params"]["wf_name"] = "NEB_test_5"

        self.wf_1 = wf_nudged_elastic_band([parent], parent, self.config_1)
        self.wf_2 = wf_nudged_elastic_band([parent], parent, self.config_2)
        self.wf_3 = wf_nudged_elastic_band([ep0, ep1], parent, self.config_3)
        self.wf_4 = wf_nudged_elastic_band([ep0, ep1], parent, self.config_4)
        self.wf_5 = wf_nudged_elastic_band(self.structures, parent, self.config_5)

        # Workflow without the config file
        self.wf_6 = wf_nudged_elastic_band(self.structures, parent)
开发者ID:montoyjh,项目名称:MatMethods,代码行数:60,代码来源:test_neb_workflow.py

示例9: test_electronegativity

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

示例10: setUp

# 需要导入模块: from pymatgen.core import Structure [as 别名]
# 或者: from pymatgen.core.Structure import from_file [as 别名]
    def setUp(self):
        filepath = os.path.join(test_dir, 'Li.cif')
        self.s = Structure.from_file(filepath)

        self.bulk = MVLGBSet(self.s)
        self.slab = MVLGBSet(self.s, slab_mode=True)

        self.d_bulk = self.bulk.all_input
        self.d_slab = self.slab.all_input
开发者ID:matk86,项目名称:pymatgen,代码行数:11,代码来源:test_sets.py

示例11: setUp

# 需要导入模块: from pymatgen.core import Structure [as 别名]
# 或者: from pymatgen.core.Structure import from_file [as 别名]
    def setUp(self):
        filepath = self.TEST_FILES_DIR / 'Li.cif'
        self.s = Structure.from_file(filepath)

        self.bulk = MVLGBSet(self.s)
        self.slab = MVLGBSet(self.s, slab_mode=True)

        self.d_bulk = self.bulk.get_vasp_input()
        self.d_slab = self.slab.get_vasp_input()
        warnings.simplefilter("ignore")
开发者ID:adengz,项目名称:pymatgen,代码行数:12,代码来源:test_sets.py

示例12: handle_input_event

# 需要导入模块: from pymatgen.core import Structure [as 别名]
# 或者: from pymatgen.core.Structure import from_file [as 别名]
 def handle_input_event(self, abiinput, outdir, event):
     try:
         old_abiinput = abiinput.deepcopy()
         # Read the last structure dumped by ABINIT before aborting.
         filepath = outdir.has_abiext("DILATMX_STRUCT.nc")
         last_structure = Structure.from_file(filepath)
         abiinput.set_structure(last_structure)
         return Correction(self, self.compare_inputs(abiinput, old_abiinput), event, False)
     except Exception as exc:
         logger.warning('Error while trying to apply the handler {}.'.format(str(self)), exc)
         return None
开发者ID:rousseab,项目名称:pymatgen,代码行数:13,代码来源:events.py

示例13: test_mix

# 需要导入模块: from pymatgen.core import Structure [as 别名]
# 或者: from pymatgen.core.Structure import from_file [as 别名]
 def test_mix(self):
     structures = [self.get_structure("Li2O"), self.get_structure("Li2O2"), self.get_structure("LiFePO4")]
     for fname in ["POSCAR.Li2O", "POSCAR.LiFePO4"]:
         structures.append(Structure.from_file(os.path.join(test_dir, fname)))
     sm = StructureMatcher(comparator=ElementComparator())
     groups = sm.group_structures(structures)
     for g in groups:
         formula = g[0].composition.reduced_formula
         if formula in ["Li2O", "LiFePO4"]:
             self.assertEqual(len(g), 2)
         else:
             self.assertEqual(len(g), 1)
开发者ID:dcossey014,项目名称:pymatgen,代码行数:14,代码来源:test_structure_matcher.py

示例14: test_ordering_enumeration

# 需要导入模块: from pymatgen.core import Structure [as 别名]
# 或者: from pymatgen.core.Structure import from_file [as 别名]
    def test_ordering_enumeration(self):
        
        # simple afm
        structure = Structure.from_file(
            os.path.join(test_dir, "magnetic_orderings/LaMnO3.json"))
        enumerator = MagneticStructureEnumerator(structure)
        self.assertEqual(enumerator.input_origin, "afm")

        # ferrimagnetic (Cr produces net spin)
        structure = Structure.from_file(
            os.path.join(test_dir, "magnetic_orderings/Cr2NiO4.json"))
        enumerator = MagneticStructureEnumerator(structure)
        self.assertEqual(enumerator.input_origin, "ferri_by_Cr")

        # antiferromagnetic on single magnetic site
        structure = Structure.from_file(
            os.path.join(test_dir, "magnetic_orderings/Cr2WO6.json"))
        enumerator = MagneticStructureEnumerator(structure)
        self.assertEqual(enumerator.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"))
        # enumerator = MagneticOrderingsenumerator(structure, default_magmoms={'Cu': 1.73},
        #                         transformation_kwargs={'max_cell_size': 4})
        # self.assertEqual(enumerator.input_origin, "afm")

        # antiferromagnetic by structural motif
        structure = Structure.from_file(
            os.path.join(test_dir, "magnetic_orderings/Ca3Co2O6.json"))
        enumerator = MagneticStructureEnumerator(
            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(enumerator.input_origin, "afm_by_motif_2a")
开发者ID:blondegeek,项目名称:pymatgen,代码行数:41,代码来源:test_analyzer.py

示例15: setup

# 需要导入模块: from pymatgen.core import Structure [as 别名]
# 或者: from pymatgen.core.Structure import from_file [as 别名]
    def setup(self):
        """
        Performs initial setup for VaspJob, including overriding any settings
        and backing up.
        """
        files = os.listdir(".")
        num_structures = 0
        if not set(files).issuperset({"INCAR", "POSCAR", "POTCAR", "KPOINTS"}):
            for f in files:
                try:
                    struct = Structure.from_file(f)
                    num_structures += 1
                except:
                    pass
            if num_structures != 1:
                raise RuntimeError("{} structures found. Unable to continue."
                                   .format(num_structures))
            else:
                self.default_vis.write_input(struct, ".")

        if self.backup:
            for f in VASP_INPUT_FILES:
                shutil.copy(f, "{}.orig".format(f))

        if self.auto_npar:
            try:
                incar = Incar.from_file("INCAR")
                #Only optimized NPAR for non-HF and non-RPA calculations.
                if not (incar.get("LHFCALC") or incar.get("LRPA") or
                        incar.get("LEPSILON")):
                    if incar.get("IBRION") in [5, 6, 7, 8]:
                        # NPAR should not be set for Hessian matrix
                        # calculations, whether in DFPT or otherwise.
                        del incar["NPAR"]
                    else:
                        import multiprocessing
                        # try sge environment variable first
                        # (since multiprocessing counts cores on the current machine only)
                        ncores = os.environ.get('NSLOTS') or multiprocessing.cpu_count()
                        ncores = int(ncores)
                        for npar in range(int(round(math.sqrt(ncores))),
                                          ncores):
                            if ncores % npar == 0:
                                incar["NPAR"] = npar
                                break
                    incar.write_file("INCAR")
            except:
                pass

        if self.settings_override is not None:
            VaspModder().apply_actions(self.settings_override)
开发者ID:rtrottie,项目名称:VTST-Tools,代码行数:53,代码来源:Classes_Custodian.py


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