本文整理匯總了Python中spglib.get_spacegroup方法的典型用法代碼示例。如果您正苦於以下問題:Python spglib.get_spacegroup方法的具體用法?Python spglib.get_spacegroup怎麽用?Python spglib.get_spacegroup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類spglib
的用法示例。
在下文中一共展示了spglib.get_spacegroup方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_spacegroup
# 需要導入模塊: import spglib [as 別名]
# 或者: from spglib import get_spacegroup [as 別名]
def get_spacegroup(structure,
symprec=1e-3,
symbol_type=0):
"""
Get the space group symbol and number of a crystal structure.
Args:
structure: :class:`qmpy.Structure` object with the crystal structure.
symprec: Float with the Cartesian distance tolerance.
symbol_type: Integer with the type: 0 - Schoenflies, 1 - ITC short
Returns:
String with the space group symbol and number. E.g. u"R-3m (166)"
None if `spglib` fails to determine the space group.
Raises:
ImportError: If `spglib` cannot be imported.
"""
_check_spglib_install()
return spglib.get_spacegroup(
_structure_to_cell(structure),
symprec=symprec,
symbol_type=symbol_type
)
示例2: get_spacegroup
# 需要導入模塊: import spglib [as 別名]
# 或者: from spglib import get_spacegroup [as 別名]
def get_spacegroup(self, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
symprec:
angle_tolerance:
Returns:
https://atztogo.github.io/spglib/python-spglib.html
"""
lattice = np.array(self.get_cell(), dtype="double", order="C")
positions = np.array(
self.get_scaled_positions(wrap=False), dtype="double", order="C"
)
numbers = np.array(self.get_atomic_numbers(), dtype="intc")
space_group = spglib.get_spacegroup(
cell=(lattice, positions, numbers),
symprec=symprec,
angle_tolerance=angle_tolerance,
).split()
if len(space_group) == 1:
return {"Number": ast.literal_eval(space_group[0])}
else:
return {
"InternationalTableSymbol": space_group[0],
"Number": ast.literal_eval(space_group[1]),
}
示例3: get_primitive_cell
# 需要導入模塊: import spglib [as 別名]
# 或者: from spglib import get_spacegroup [as 別名]
def get_primitive_cell(self, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
symprec:
angle_tolerance:
Returns:
"""
el_dict = {}
for el in set(self.get_chemical_elements()):
el_dict[el.AtomicNumber] = el
lattice = np.array(self.get_cell().T, dtype="double", order="C")
positions = np.array(
self.get_scaled_positions(wrap=False), dtype="double", order="C"
)
numbers = np.array(self.get_atomic_numbers(), dtype="intc")
cell, coords, atomic_numbers = spglib.find_primitive(
cell=(lattice, positions, numbers),
symprec=symprec,
angle_tolerance=angle_tolerance,
)
# print atomic_numbers, type(atomic_numbers)
el_lst = [el_dict[i_a] for i_a in atomic_numbers]
# convert lattice vectors to standard (experimental feature!) TODO:
red_structure = Atoms(elements=el_lst, scaled_positions=coords, cell=cell)
space_group = red_structure.get_spacegroup(symprec)["Number"]
# print "space group: ", space_group
if space_group == 225: # fcc
alat = np.max(cell[0])
amat_fcc = alat * np.array([[1, 0, 1], [1, 1, 0], [0, 1, 1]])
red_structure.cell = amat_fcc
return red_structure
示例4: get_lattice_type
# 需要導入模塊: import spglib [as 別名]
# 或者: from spglib import get_spacegroup [as 別名]
def get_lattice_type(cryst):
'''Find the symmetry of the crystal using spglib symmetry finder.
Derive name of the space group and its number extracted from the result.
Based on the group number identify also the lattice type and the Bravais
lattice of the crystal. The lattice type numbers are
(the numbering starts from 1):
Triclinic (1), Monoclinic (2), Orthorombic (3),
Tetragonal (4), Trigonal (5), Hexagonal (6), Cubic (7)
:param cryst: ASE Atoms object
:returns: tuple (lattice type number (1-7), lattice name, space group
name, space group number)
'''
# Table of lattice types and correcponding group numbers dividing
# the ranges. See get_lattice_type method for precise definition.
lattice_types = [
[3, "Triclinic"],
[16, "Monoclinic"],
[75, "Orthorombic"],
[143, "Tetragonal"],
[168, "Trigonal"],
[195, "Hexagonal"],
[231, "Cubic"]
]
sg = spg.get_spacegroup(cryst)
m = re.match(r'([A-Z].*\b)\s*\(([0-9]*)\)', sg)
sg_name = m.group(1)
sg_nr = int(m.group(2))
for n, l in enumerate(lattice_types):
if sg_nr < l[0]:
bravais = l[1]
lattype = n+1
break
return lattype, bravais, sg_name, sg_nr
示例5: get_spacegroup
# 需要導入模塊: import spglib [as 別名]
# 或者: from spglib import get_spacegroup [as 別名]
def get_spacegroup(self, symprec=1e-5):
return spg.get_spacegroup(cell=self.spglib_cell, symprec=symprec)
示例6: _make_atoms_dict
# 需要導入模塊: import spglib [as 別名]
# 或者: from spglib import get_spacegroup [as 別名]
def _make_atoms_dict(atoms):
'''
Convert an ase.Atoms object into a dictionary for json storage.
Arg:
atoms ase.Atoms object
Returns:
atoms_dict A dictionary with various atoms information stored
'''
# If the atoms object is relaxed, then get the magnetic moments from the
# calculator. We do this because magnetic moments of individual atoms
# within a structure are mutable and actually change when the atom is
# pulled from the structure (even inside a list comprehension).
try:
magmoms = atoms.get_magnetic_moments()
atoms_dict = OrderedDict(atoms=[{'symbol': atom.symbol,
'position': json.loads(encode(atom.position)),
'tag': atom.tag,
'index': atom.index,
'charge': atom.charge,
'momentum': json.loads(encode(atom.momentum)),
'magmom': magmoms[i]}
for i, atom in enumerate(atoms)],
cell=atoms.cell,
pbc=atoms.pbc,
info=atoms.info,
constraints=[c.todict() for c in atoms.constraints])
# If the atoms object is unrelaxed, then get the magnetic moment from the
# individual atom
except RuntimeError:
atoms_dict = OrderedDict(atoms=[{'symbol': atom.symbol,
'position': json.loads(encode(atom.position)),
'tag': atom.tag,
'index': atom.index,
'charge': atom.charge,
'momentum': json.loads(encode(atom.momentum)),
'magmom': atom.magmom}
for atom in atoms],
cell=atoms.cell,
pbc=atoms.pbc,
info=atoms.info,
constraints=[c.todict() for c in atoms.constraints])
# Redundant information for search convenience.
atoms_dict['natoms'] = len(atoms)
cell = atoms.get_cell()
atoms_dict['mass'] = sum(atoms.get_masses())
syms = atoms.get_chemical_symbols()
atoms_dict['spacegroup'] = spglib.get_spacegroup(make_spglib_cell_from_atoms(atoms))
atoms_dict['chemical_symbols'] = list(set(syms))
atoms_dict['symbol_counts'] = {sym: syms.count(sym) for sym in syms}
if cell is not None and np.linalg.det(cell) > 0:
atoms_dict['volume'] = atoms.get_volume()
return json.loads(encode(atoms_dict))