本文整理匯總了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
示例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
)
示例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()
示例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())
示例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())
示例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.")
示例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)
示例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)
示例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))
示例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
示例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
示例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
示例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()
示例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())
示例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())