本文整理汇总了Python中pymatgen.Structure方法的典型用法代码示例。如果您正苦于以下问题:Python pymatgen.Structure方法的具体用法?Python pymatgen.Structure怎么用?Python pymatgen.Structure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen
的用法示例。
在下文中一共展示了pymatgen.Structure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def __init__(self, document):
super(TabularData, self).__init__()
from pymatgen import Structure
scope = []
for key, value in document.iterate():
if isinstance(value, Table):
self[scope[0]].rec_update({".".join(scope[1:]): value})
elif not isinstance(value, Structure):
level, key = key
level_reduction = bool(level < len(scope))
if level_reduction:
del scope[level:]
if value is None:
scope.append(key)
if scope[0] not in self:
self[scope[0]] = Tables()
示例2: to_pymatgen_structure
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def to_pymatgen_structure(self):
'''
convert System to Pymatgen Structure obj
'''
structures=[]
try:
from pymatgen import Structure
except:
raise ImportError('No module pymatgen.Structure')
for system in self.to_list():
species=[]
for name,numb in zip(system.data['atom_names'],system.data['atom_numbs']):
species.extend([name]*numb)
structure=Structure(system.data['cells'][0],species,system.data['coords'][0],coords_are_cartesian=True)
structures.append(structure)
return structures
示例3: test___dr_ij
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def test___dr_ij(self):
coords = np.array([[0.5, 0.5, 0.5],
[0.0, 0.0, 0.0]])
atom_list = ['Na', 'Cl']
lattice = Lattice.from_parameters(a=4.0, b=4.0, c=4.0,
alpha=90, beta=90, gamma=90)
structure = Structure(lattice, atom_list, coords)
mock_structures = [Mock(spec=Structure)]
for s in mock_structures:
s.lattice = Mock(spec=Lattice)
s.lattice.volume = 1.0
indices_i = [0, 1]
with patch('vasppy.rdf.RadialDistributionFunction._RadialDistributionFunction__dr_ij') as mock_dr_ij:
rdf = RadialDistributionFunction(structures=mock_structures,
indices_i=indices_i)
rdf.self_reference = True
np.testing.assert_array_almost_equal(rdf._RadialDistributionFunction__dr_ij(structure),
np.array([3.46410162, 3.46410162]))
rdf.self_reference = False
np.testing.assert_array_almost_equal(np.sort(rdf._RadialDistributionFunction__dr_ij(structure)),
np.array([0.0, 0.0, 3.46410162, 3.46410162]))
rdf.indices_i = [0]
rdf.indices_j = [1]
np.testing.assert_array_almost_equal(rdf._RadialDistributionFunction__dr_ij(structure),
np.array([3.46410162]))
示例4: test_model_load
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def test_model_load(self):
model = MEGNetDescriptor(model_name=DEFAULT_MODEL)
self.assertTrue(model.model, Model)
s = Structure(Lattice.cubic(3.6), ['Mo', 'Mo'], [[0.5, 0.5, 0.5], [0, 0, 0]])
atom_features = model.get_atom_features(s)
bond_features = model.get_bond_features(s)
glob_features = model.get_global_features(s)
atom_set2set = model.get_set2set(s, ftype='atom')
bond_set2set = model.get_set2set(s, ftype='bond')
s_features = model.get_structure_features(s)
self.assertListEqual(list(atom_features.shape), [2, 32])
self.assertListEqual(list(bond_features.shape), [28, 32])
self.assertListEqual(list(glob_features.shape), [1, 32])
self.assertListEqual(list(atom_set2set.shape), [1, 32])
self.assertListEqual(list(bond_set2set.shape), [1, 32])
self.assertListEqual(list(s_features.shape), [1, 96])
示例5: test_RadialDistributionFunction_raises_ValueError_if_weights_doesnt_match_structures
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def test_RadialDistributionFunction_raises_ValueError_if_weights_doesnt_match_structures(self):
mock_structures = [Mock(spec=Structure), Mock(spec=Structure)]
weights = [1, 2, 3]
indices_i = [0, 1]
with self.assertRaises(ValueError):
RadialDistributionFunction(structures=mock_structures,
indices_i=indices_i,
weights=weights)
示例6: pychemia2pymatgen
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def pychemia2pymatgen(structure):
"""
Converts an pychemia structure into a pymatgen structure object
:param structure: (pychemia.Structure) Structure to convert into pymatgen Structure object
:return:
"""
lattice = structure.cell
coords = structure.reduced
species = structure.symbols
return PMG_Structure(lattice, species, coords)
示例7: to_pymatgen_structure
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def to_pymatgen_structure( self ):
lattice = pmg_Lattice( self.cell.matrix * self.scaling )
structure = pmg_Structure( lattice, self.labels(), self.coordinates )
return structure
示例8: test_RadialDistributionFunction_init
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def test_RadialDistributionFunction_init(self):
mock_structures = [Mock(spec=Structure), Mock(spec=Structure)]
for s in mock_structures:
s.lattice = Mock(spec=Lattice)
s.lattice.volume = 1.0
indices_i = [0, 1]
with patch('vasppy.rdf.RadialDistributionFunction._RadialDistributionFunction__dr_ij') as mock_dr_ij:
mock_dr_ij.side_effect = [np.array([5.0, 6.0]), np.array([6.0, 7.0])]
with patch('vasppy.rdf.shell_volumes') as mock_shell_volumes:
mock_shell_volumes.return_value = np.ones(500)
rdf = RadialDistributionFunction(structures=mock_structures,
indices_i=indices_i)
self.assertEqual(rdf.indices_i, [0,1])
self.assertEqual(rdf.indices_j, [0,1])
self.assertEqual(rdf.nbins, 500)
self.assertEqual(rdf.range, (0.0, 10.0))
np.testing.assert_array_equal(rdf.intervals, np.linspace(0, 10, 501))
self.assertEqual(rdf.dr, 0.02)
np.testing.assert_array_equal(rdf.r, np.linspace(0.01, 9.99, 500))
expected_rdf = np.zeros_like(rdf.r)
expected_rdf[250] = 0.125
expected_rdf[300] = 0.25
expected_rdf[350] = 0.125
expected_coordination_number = np.cumsum(expected_rdf)*2.0
np.testing.assert_array_almost_equal(rdf.rdf, expected_rdf)
np.testing.assert_array_almost_equal(rdf.coordination_number, expected_coordination_number)
mock_dr_ij.assert_has_calls([call(mock_structures[0]), call(mock_structures[1])])
示例9: get_nn_info
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def get_nn_info(self, structure: Structure,
n: int) -> List[Dict]:
"""
Get all near-neighbor sites as well as the associated image locations
and weights of the site with index n using the closest neighbor
distance-based method.
Args:
structure (Structure): input structure.
n (integer): index of site for which to determine near
neighbors.
Returns:
siw (list of tuples (Site, array, float)): tuples, each one
of which represents a neighbor site, its image location,
and its weight.
"""
site = structure[n]
neighs_dists = structure.get_neighbors(site, self.cutoff)
siw = []
for nn in neighs_dists:
siw.append({'site': nn,
'image': self._get_image(structure, nn),
'weight': nn.nn_distance,
'site_index': self._get_original_site(structure, nn)})
return siw
示例10: convert
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def convert(self, structure: Structure, state_attributes: List = None) -> Dict:
"""
Take a pymatgen structure and convert it to a index-type graph representation
The graph will have node, distance, index1, index2, where node is a vector of Z number
of atoms in the structure, index1 and index2 mark the atom indices forming the bond and separated by
distance.
For state attributes, you can set structure.state = [[xx, xx]] beforehand or the algorithm would
take default [[0, 0]]
Args:
state_attributes: (list) state attributes
structure: (pymatgen structure)
(dictionary)
"""
state_attributes = state_attributes or getattr(structure, 'state', None) or \
np.array([[0.0, 0.0]], dtype='float32')
index1 = []
index2 = []
bonds = []
if self.nn_strategy is None:
raise RuntimeError("NearNeighbor strategy is not provided!")
for n, neighbors in enumerate(self.nn_strategy.get_all_nn_info(structure)):
index1.extend([n] * len(neighbors))
for neighbor in neighbors:
index2.append(neighbor['site_index'])
bonds.append(neighbor['weight'])
atoms = self.get_atom_features(structure)
if np.size(np.unique(index1)) < len(atoms):
raise RuntimeError("Isolated atoms found in the structure")
else:
return {'atom': atoms,
'bond': bonds,
'state': state_attributes,
'index1': index1,
'index2': index2
}
示例11: get_atom_features
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def get_atom_features(structure) -> List[int]:
"""
Get atom features from structure, may be overwritten
Args:
structure: (Pymatgen.Structure) pymatgen structure
Returns:
List of atomic numbers
"""
return np.array([i.specie.Z for i in structure],
dtype='int32').tolist()
示例12: __call__
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def __call__(self, structure: Structure) -> Dict:
return self.convert(structure)
示例13: get_input
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def get_input(self, structure: Structure) -> List[np.ndarray]:
"""
Turns a structure into model input
"""
graph = self.convert(structure)
return self.graph_to_input(graph)
示例14: convert
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def convert(self, structure: Structure, state_attributes: List = None) -> Dict:
graph = super().convert(structure, state_attributes=state_attributes)
return self._get_bond_type(graph)
示例15: get_graphs_within_cutoff
# 需要导入模块: import pymatgen [as 别名]
# 或者: from pymatgen import Structure [as 别名]
def get_graphs_within_cutoff(structure: StructureOrMolecule,
cutoff: float = 5.0,
numerical_tol: float = 1e-8) \
-> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
"""
Get graph representations from structure within cutoff
Args:
structure (pymatgen Structure or molecule)
cutoff (float): cutoff radius
numerical_tol (float): numerical tolerance
Returns:
center_indices, neighbor_indices, images, distances
"""
if isinstance(structure, Structure):
lattice_matrix = np.ascontiguousarray(
np.array(structure.lattice.matrix), dtype=float)
pbc = np.array([1, 1, 1], dtype=int)
elif isinstance(structure, Molecule):
lattice_matrix = np.array(
[[1000.0, 0., 0.],
[0., 1000., 0.],
[0., 0., 1000.]], dtype=float)
pbc = np.array([0, 0, 0], dtype=int)
else:
raise ValueError('structure type not supported')
r = float(cutoff)
cart_coords = np.ascontiguousarray(
np.array(structure.cart_coords), dtype=float)
center_indices, neighbor_indices, images, distances = \
find_points_in_spheres(cart_coords, cart_coords, r=r, pbc=pbc,
lattice=lattice_matrix, tol=numerical_tol)
center_indices = center_indices.astype(DataType.np_int)
neighbor_indices = neighbor_indices.astype(DataType.np_int)
images = images.astype(DataType.np_int)
distances = distances.astype(DataType.np_float)
exclude_self = (center_indices != neighbor_indices) | (distances > numerical_tol)
return center_indices[exclude_self], neighbor_indices[exclude_self], \
images[exclude_self], distances[exclude_self]