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


Python structure.Structure方法代码示例

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


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

示例1: from_dict

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def from_dict(dictionary: dict)-> 'flare.struc.Structure':
        """
        Assembles a Structure object from a dictionary parameterizing one.

        :param dictionary: dict describing structure parameters.
        :return: FLARE structure assembled from dictionary
        """
        struc = Structure(cell=np.array(dictionary['cell']),
                          positions=np.array(dictionary['positions']),
                          species=dictionary['coded_species'],
                          forces=dictionary.get('forces'),
                          mass_dict=dictionary.get('mass_dict'),
                          species_labels=dictionary.get('species_labels'))

        struc.energy = dictionary.get('energy')
        struc.stress = dictionary.get('stress')
        struc.stds = np.array(dictionary.get('stds'))

        return struc 
开发者ID:mir-group,项目名称:flare,代码行数:21,代码来源:struc.py

示例2: to_pmg_structure

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def to_pmg_structure(self):
        """
        Returns FLARE structure as a pymatgen structure.

        :return: Pymatgen structure corresponding to current FLARE structure
        """

        if not _pmg_present:
            raise ModuleNotFoundError("Pymatgen is not present. Please "
                                      "install Pymatgen and try again")

        site_properties = {'force:': self.forces, 'std': self.stds}

        return pmgstruc.Structure(lattice=self.cell,
                                  species=self.species_labels,
                                  coords=self.positions,
                                  coords_are_cartesian=True,
                                  site_properties=site_properties
                                  ) 
开发者ID:mir-group,项目名称:flare,代码行数:21,代码来源:struc.py

示例3: test_prev_positions_arg

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def test_prev_positions_arg():
    np.random.seed(0)
    positions = []
    prev_positions = []
    species = [1] * 5
    cell = np.eye(3)
    for n in range(5):
        positions.append(np.random.uniform(-1, 1, 3))
        prev_positions.append(np.random.uniform(-1, 1, 3))

    test_structure1 = Structure(cell, species, positions)
    test_structure2 = Structure(cell, species, positions,
                                prev_positions=positions)
    test_structure3 = Structure(cell, species, positions,
                                prev_positions=prev_positions)

    assert np.equal(test_structure1.positions, test_structure2.positions).all()
    assert np.equal(test_structure1.prev_positions,
                    test_structure2.prev_positions).all()
    assert np.equal(test_structure2.positions,
                    test_structure2.prev_positions).all()
    assert not np.equal(test_structure3.positions,
                        test_structure3.prev_positions).all() 
开发者ID:mir-group,项目名称:flare,代码行数:25,代码来源:test_struc.py

示例4: test_raw_to_relative

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def test_raw_to_relative():
    """ Test that Cartesian and relative coordinates are equal. """

    cell = np.random.rand(3, 3)
    noa = 10
    positions = np.random.rand(noa, 3)
    species = ['Al'] * len(positions)

    test_struc = Structure(cell, species, positions)
    rel_vals = test_struc.raw_to_relative(test_struc.positions,
                                          test_struc.cell_transpose,
                                          test_struc.cell_dot_inverse)

    ind = np.random.randint(0, noa)
    assert (np.isclose(positions[ind], rel_vals[ind, 0] * test_struc.vec1 +
                       rel_vals[ind, 1] * test_struc.vec2 +
                       rel_vals[ind, 2] * test_struc.vec3).all()) 
开发者ID:mir-group,项目名称:flare,代码行数:19,代码来源:test_struc.py

示例5: test_wrapped_coordinates

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def test_wrapped_coordinates():
    """ Check that wrapped coordinates are equivalent to Cartesian coordinates
    up to lattice translations. """

    cell = np.random.rand(3, 3)
    positions = np.random.rand(10, 3)
    species = ['Al'] * len(positions)

    test_struc = Structure(cell, species, positions)

    wrap_diff = test_struc.positions - test_struc.wrapped_positions
    wrap_rel = test_struc.raw_to_relative(wrap_diff,
                                          test_struc.cell_transpose,
                                          test_struc.cell_dot_inverse)

    assert (np.isclose(np.round(wrap_rel) - wrap_rel,
                       np.zeros(positions.shape)).all()) 
开发者ID:mir-group,项目名称:flare,代码行数:19,代码来源:test_struc.py

示例6: print_all

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def print_all(self):
        """
        Prints useful information about the generated crystal.
        """
        print("--Random Crystal--")
        print("Dimension: "+str(self.dim))
        print("Group: "+self.group.symbol)
        print("Volume factor: "+str(self.factor))
        if self.valid is True:
            print("Wyckoff sites:")
            for x in self.wyckoff_sites:
                print("  "+str(x))
            print("Pymatgen Structure:")
            print(self.struct)
        elif self.valid is False:
            print("Structure not generated.") 
开发者ID:qzhu2017,项目名称:PyXtal,代码行数:18,代码来源:crystal.py

示例7: __init__

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def __init__(self, structure, symprec=1e-3):
        self.structure = structure

        # use sym as a quick way to access the cell data
        sym = SpacegroupAnalyzer(structure, symprec=symprec)
        self._spg_data = sym.get_symmetry_dataset()

        # make primitive and conventional cell from seekpath output
        std = spglib.refine_cell(sym._cell, symprec=symprec)
        self._seek_data = seekpath.get_path(std)

        prim_lattice = self._seek_data['primitive_lattice']
        prim_scaled_positions = self._seek_data['primitive_positions']
        prim_numbers = self._seek_data['primitive_types']
        prim_atoms = [sym._unique_species[i - 1] for i in prim_numbers]
        self.prim = Structure(prim_lattice, prim_atoms, prim_scaled_positions)

        conv_lattice = self._seek_data['conv_lattice']
        conv_scaled_positions = self._seek_data['conv_positions']
        conv_numbers = self._seek_data['conv_types']
        conv_atoms = [sym._unique_species[i - 1] for i in conv_numbers]
        self.conv = Structure(conv_lattice, conv_atoms, conv_scaled_positions) 
开发者ID:SMTG-UCL,项目名称:sumo,代码行数:24,代码来源:kpath.py

示例8: get_band_structure

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def get_band_structure(self):
        lattice = Lattice(self.header['cell'])
        structure = Structure(lattice, species=self.header['symbols'],
                              coords=self.header['positions'])

        # I think this is right? Need to test somehow...
        mass_weights = 1 / np.sqrt(self.header['masses'])
        displacements = self.eigenvectors * mass_weights[np.newaxis,
                                                         np.newaxis,
                                                         :,
                                                         np.newaxis]

        return PhononBandStructureSymmLine(self.qpts, self.frequencies,
                                           lattice.reciprocal_lattice,
                                           structure=structure,
                                           eigendisplacements=displacements,
                                           labels_dict=self.labels) 
开发者ID:SMTG-UCL,项目名称:sumo,代码行数:19,代码来源:castep.py

示例9: __str__

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def __str__(self) -> str:
        """
        Simple descriptive string of structure.

        :return: One-line descriptor of number of atoms and species present.
        :rtype: str
        """

        return 'Structure with {} atoms of types {}'\
            .format(self.nat, set(self.species_labels)) 
开发者ID:mir-group,项目名称:flare,代码行数:12,代码来源:struc.py

示例10: from_ase_atoms

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def from_ase_atoms(atoms: 'ase.Atoms')-> 'flare.struc.Structure':
        """
        From an ASE Atoms object, return a FLARE structure

        :param atoms: ASE Atoms object
        :type atoms: ASE Atoms object
        :return: A FLARE structure from an ASE atoms object
        """
        struc = Structure(cell=np.array(atoms.cell),
                          positions=atoms.positions,
                          species=atoms.get_chemical_symbols())
        return struc 
开发者ID:mir-group,项目名称:flare,代码行数:14,代码来源:struc.py

示例11: from_pmg_structure

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def from_pmg_structure(structure: 'pymatgen Structure')-> \
            'flare Structure':
        """
        Returns Pymatgen structure as FLARE structure.

        :param structure: Pymatgen Structure
        :type structure: Pymatgen Structure
        :return: FLARE Structure
        """

        cell = structure.lattice.matrix.copy()
        species = [str(spec) for spec in structure.species]
        positions = structure.cart_coords.copy()

        new_struc = Structure(cell=cell, species=species,
                              positions=positions)

        site_props = structure.site_properties

        if 'force' in site_props.keys():
            forces = site_props['force']
            new_struc.forces = [np.array(force) for force in forces]

        if 'std' in site_props.keys():
            stds = site_props['std']
            new_struc.stds = [np.array(std) for std in stds]

        return new_struc 
开发者ID:mir-group,项目名称:flare,代码行数:30,代码来源:struc.py

示例12: varied_test_struc

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def varied_test_struc():
    struc = Structure(np.eye(3), species=[1, 2, 2, 3, 3, 4, 4, 4,
                                          4, 3],
                      positions=np.array([np.random.uniform(-1, 1, 3) for i
                                          in range(10)]))
    struc.forces = np.array([np.random.uniform(-1, 1, 3) for _ in
                             range(10)])
    return struc 
开发者ID:mir-group,项目名称:flare,代码行数:10,代码来源:test_struc.py

示例13: test_to_from_methods

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def test_to_from_methods(varied_test_struc):
    test_dict = varied_test_struc.as_dict()

    assert isinstance(test_dict, dict)
    assert (test_dict['forces'] == varied_test_struc.forces).all()

    new_struc_1 = Structure.from_dict(test_dict)
    new_struc_2 = Structure.from_dict(loads(varied_test_struc.as_str()))

    for new_struc in [new_struc_1, new_struc_2]:
        assert np.equal(varied_test_struc.positions, new_struc.positions).all()
        assert np.equal(varied_test_struc.cell, new_struc.cell).all()
        assert np.equal(varied_test_struc.forces, new_struc.forces).all() 
开发者ID:mir-group,项目名称:flare,代码行数:15,代码来源:test_struc.py

示例14: test_struc_from_ase

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def test_struc_from_ase():
    from ase import Atoms
    uc = Atoms(['Pd' for i in range(10)]+['Ag' for i in range(10)],
               positions=np.random.rand(20, 3),
               cell=np.random.rand(3, 3))
    new_struc = Structure.from_ase_atoms(uc)
    assert np.all(new_struc.species_labels == uc.get_chemical_symbols())
    assert np.all(new_struc.positions == uc.get_positions())
    assert np.all(new_struc.cell == uc.get_cell()) 
开发者ID:mir-group,项目名称:flare,代码行数:11,代码来源:test_struc.py

示例15: test_struc_to_ase

# 需要导入模块: from pymatgen.core import structure [as 别名]
# 或者: from pymatgen.core.structure import Structure [as 别名]
def test_struc_to_ase():
    from ase import Atoms
    uc = Structure(species=['Pd' for i in range(10)]+['Ag' for i in range(10)],
                   positions=np.random.rand(20, 3),
                   cell=np.random.rand(3, 3))
    new_atoms = Structure.to_ase_atoms(uc)
    assert np.all(uc.species_labels == new_atoms.get_chemical_symbols())
    assert np.all(uc.positions == new_atoms.get_positions())
    assert np.all(uc.cell == new_atoms.get_cell()) 
开发者ID:mir-group,项目名称:flare,代码行数:11,代码来源:test_struc.py


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