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


Python Poscar.from_string方法代码示例

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


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

示例1: test_init

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def test_init(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath,check_for_POTCAR=False)
        comp = poscar.structure.composition
        self.assertEqual(comp, Composition("Fe4P4O16"))

        # Vasp 4 type with symbols at the end.
        poscar_string = """Test1
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 F
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.structure.composition, Composition("SiF"))

        poscar_string = ""
        self.assertRaises(ValueError, Poscar.from_string, poscar_string)

        # Vasp 4 tyle file with default names, i.e. no element symbol found.
        poscar_string = """Test2
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000
0.750000 0.500000 0.750000
"""
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.structure.composition, Composition("HHe"))
        # Vasp 4 tyle file with default names, i.e. no element symbol found.
        poscar_string = """Test3
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
Selective dynamics
direct
0.000000 0.000000 0.000000 T T T Si
0.750000 0.500000 0.750000 F F F O
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.selective_dynamics, [[True, True, True],
                                                     [False, False, False]])
        self.selective_poscar = poscar
开发者ID:ExpHP,项目名称:pymatgen,代码行数:56,代码来源:test_inputs.py

示例2: get_prim_struct

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
def get_prim_struct(structure):
    """
    Get standard primitive
    """
    output = run_aconvasp_command(["aconvasp", "--std_prim"], structure)
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    tmp = Poscar.from_string(output[0])
    return {'struct': tmp.structure, 'comm': tmp.comment}
开发者ID:georgeyumnam,项目名称:pymatgen,代码行数:11,代码来源:aconvasp_caller.py

示例3: get_conv_struct

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
def get_conv_struct(structure):
    """
    Get a minkowski reduced structure
    """
    output = run_aconvasp_command(["aconvasp", "--std_conv"], structure)
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    tmp = Poscar.from_string(output[0])
    return {'struct': tmp.structure, 'comm': tmp.comment}
开发者ID:georgeyumnam,项目名称:pymatgen,代码行数:11,代码来源:aconvasp_caller.py

示例4: _get_structures

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def _get_structures(self, num_structs):
        structs = []
        rs = subprocess.Popen(["makestr.x",
                               "struct_enum.out", str(0),
                               str(num_structs - 1)],
                              stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE, close_fds=True)
        rs.communicate()
        if len(self.ordered_sites) > 0:
            original_latt = self.ordered_sites[0].lattice
            # Need to strip sites of site_properties, which would otherwise
            # result in an index error. Hence Structure is reconstructed in
            # the next step.
            ordered_structure = Structure(
                original_latt,
                [site.species_and_occu for site in self.ordered_sites],
                [site.frac_coords for site in self.ordered_sites])
            inv_org_latt = np.linalg.inv(original_latt.matrix)

        for n in range(1, num_structs + 1):
            with open("vasp.{:06d}".format(n)) as f:
                data = f.read()
                data = re.sub("scale factor", "1", data)
                data = re.sub("(\d+)-(\d+)", r"\1 -\2", data)
                poscar = Poscar.from_string(data, self.index_species)
                sub_structure = poscar.structure
                #Enumeration may have resulted in a super lattice. We need to
                #find the mapping from the new lattice to the old lattice, and
                #perform supercell construction if necessary.
                new_latt = sub_structure.lattice

                sites = []

                if len(self.ordered_sites) > 0:
                    transformation = np.dot(new_latt.matrix, inv_org_latt)
                    transformation = [[int(round(cell)) for cell in row]
                                      for row in transformation]
                    logger.debug("Supercell matrix: {}".format(transformation))
                    s = Structure.from_sites(ordered_structure)
                    s.make_supercell(transformation)
                    sites.extend([site.to_unit_cell for site in s])
                    super_latt = sites[-1].lattice
                else:
                    super_latt = new_latt

                for site in sub_structure:
                    if site.specie.symbol != "X":  # We exclude vacancies.
                        sites.append(PeriodicSite(site.species_and_occu,
                                                  site.frac_coords,
                                                  super_latt).to_unit_cell)
                structs.append(Structure.from_sites(sorted(sites)))

        logger.debug("Read in a total of {} structures.".format(num_structs))
        return structs
开发者ID:sonium0,项目名称:pymatgen,代码行数:56,代码来源:enumlib_caller.py

示例5: test_automatic_kpoint

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def test_automatic_kpoint(self):
        # s = PymatgenTest.get_structure("Li2O")
        p = Poscar.from_string("""Al1
1.0
2.473329 0.000000 1.427977
0.824443 2.331877 1.427977
0.000000 0.000000 2.855955
Al
1
direct
0.000000 0.000000 0.000000 Al""")
        kpoints = Kpoints.automatic_density(p.structure, 1000)
        self.assertArrayAlmostEqual(kpoints.kpts[0], [10, 10, 10])
开发者ID:ExpHP,项目名称:pymatgen,代码行数:15,代码来源:test_inputs.py

示例6: test_str

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def test_str(self):
        si = 14
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])

        # Silicon structure for testing.
        latt = [[3.8401979337, 0.00, 0.00],
                [1.9200989668, 3.3257101909, 0.00],
                [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(latt, [si, si], coords)
        poscar = Poscar(struct)
        expected_str = '''Si2
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
Si
2
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 Si
'''

        self.assertEqual(str(poscar), expected_str, "Wrong POSCAR output!")

        # Vasp 4 type with symbols at the end.
        poscar_string = """Test1
1.0
-3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 F
"""

        expected = """Test1
1.0
3.840198 -0.000000 -0.000000
-1.920099 -3.325710 -0.000000
-0.000000 2.217138 -3.135509
Si F
1 1
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 F
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(str(poscar), expected)
开发者ID:ExpHP,项目名称:pymatgen,代码行数:53,代码来源:test_inputs.py

示例7: test_cart_scale

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def test_cart_scale(self):
        poscar_string = """Test1
1.1
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
Si F
1 1
cart
0.000000   0.00000000   0.00000000
3.840198   1.50000000   2.35163175
"""
        p = Poscar.from_string(poscar_string)
        site = p.structure[1]
        self.assertArrayAlmostEqual(site.coords, np.array([3.840198, 1.5, 2.35163175]) * 1.1)
开发者ID:gpetretto,项目名称:pymatgen,代码行数:17,代码来源:test_inputs.py

示例8: get_minkowski_red

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
def get_minkowski_red(structure):
    """
    Get a minkowski reduced structure
    """
    output = run_aconvasp_command(["aconvasp", "--kpath"], structure)
    started = False
    poscar_string = ""
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    for line in output[0].split("\n"):
        if started or line.find("KPOINTS TO RUN") != -1:
            poscar_string = poscar_string + line + "\n"
        if line.find("STRUCTURE TO RUN") != -1:
            started = True
        if line.find("KPOINTS TO RUN") != -1:
            started = False
    return Poscar.from_string(poscar_string).structure
开发者ID:georgeyumnam,项目名称:pymatgen,代码行数:19,代码来源:aconvasp_caller.py

示例9: test_to_from_dict

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def test_to_from_dict(self):
        poscar_string = """Test3
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
Selective dynamics
direct
0.000000 0.000000 0.000000 T T T Si
0.750000 0.500000 0.750000 F F F O
"""
        poscar = Poscar.from_string(poscar_string)
        d = poscar.as_dict()
        poscar2 = Poscar.from_dict(d)
        self.assertEqual(poscar2.comment, "Test3")
        self.assertTrue(all(poscar2.selective_dynamics[0]))
        self.assertFalse(all(poscar2.selective_dynamics[1]))
开发者ID:ExpHP,项目名称:pymatgen,代码行数:20,代码来源:test_inputs.py

示例10: from_poscar_string

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def from_poscar_string(poscar_string, transformations=None):
        """
        Generates TransformedStructure from a poscar string.

        Args:
            poscar_string (str): Input POSCAR string.
            transformations ([Transformations]): Sequence of transformations
                to be applied to the input structure.
        """
        p = Poscar.from_string(poscar_string)
        if not p.true_names:
            raise ValueError("Transformation can be craeted only from POSCAR "
                             "strings with proper VASP5 element symbols.")
        raw_string = re.sub("'", "\"", poscar_string)
        s = p.structure
        source_info = {"source": "POSCAR",
                       "datetime": str(datetime.datetime.now()),
                       "original_file": raw_string}
        return TransformedStructure(s, transformations, history=[source_info])
开发者ID:AtlasL,项目名称:pymatgen,代码行数:21,代码来源:materials.py

示例11: _get_structures

# 需要导入模块: from pymatgen.io.vasp.inputs import Poscar [as 别名]
# 或者: from pymatgen.io.vasp.inputs.Poscar import from_string [as 别名]
    def _get_structures(self, num_structs):
        structs = []

        if ".py" in makestr_cmd:
            options = ["-input", "struct_enum.out", str(1), str(num_structs)]
        else:
            options = ["struct_enum.out", str(0), str(num_structs - 1)]

        rs = subprocess.Popen([makestr_cmd] + options,
                              stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE, close_fds=True)
        stdout, stderr = rs.communicate()
        if stderr:
            logger.warning(stderr.decode())
        if len(self.ordered_sites) > 0:
            original_latt = self.ordered_sites[0].lattice
            # Need to strip sites of site_properties, which would otherwise
            # result in an index error. Hence Structure is reconstructed in
            # the next step.
            site_properties = {}
            for site in self.ordered_sites:
                for k, v in site.properties.items():
                    if k in site_properties:
                        site_properties[k].append(v)
                    else:
                        site_properties[k] = [v]
            ordered_structure = Structure(
                original_latt,
                [site.species_and_occu for site in self.ordered_sites],
                [site.frac_coords for site in self.ordered_sites],
                site_properties=site_properties
            )
            inv_org_latt = np.linalg.inv(original_latt.matrix)

        for file in glob.glob('vasp.*'):
            with open(file) as f:
                data = f.read()
                data = re.sub(r'scale factor', "1", data)
                data = re.sub(r'(\d+)-(\d+)', r'\1 -\2', data)
                poscar = Poscar.from_string(data, self.index_species)
                sub_structure = poscar.structure
                # Enumeration may have resulted in a super lattice. We need to
                # find the mapping from the new lattice to the old lattice, and
                # perform supercell construction if necessary.
                new_latt = sub_structure.lattice

                sites = []

                if len(self.ordered_sites) > 0:
                    transformation = np.dot(new_latt.matrix, inv_org_latt)
                    transformation = [[int(round(cell)) for cell in row]
                                      for row in transformation]
                    logger.debug("Supercell matrix: {}".format(transformation))
                    s = ordered_structure * transformation
                    sites.extend([site.to_unit_cell for site in s])
                    super_latt = sites[-1].lattice
                else:
                    super_latt = new_latt

                for site in sub_structure:
                    if site.specie.symbol != "X":  # We exclude vacancies.
                        sites.append(PeriodicSite(site.species_and_occu,
                                                  site.frac_coords,
                                                  super_latt).to_unit_cell)
                    else:
                        warnings.warn("Skipping sites that include species X.")
                structs.append(Structure.from_sites(sorted(sites)))

        logger.debug("Read in a total of {} structures.".format(num_structs))
        return structs
开发者ID:setten,项目名称:pymatgen,代码行数:72,代码来源:enumlib_caller.py


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