本文整理汇总了Python中pymatgen.core.operations.SymmOp.from_rotation_and_translation方法的典型用法代码示例。如果您正苦于以下问题:Python SymmOp.from_rotation_and_translation方法的具体用法?Python SymmOp.from_rotation_and_translation怎么用?Python SymmOp.from_rotation_and_translation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.operations.SymmOp
的用法示例。
在下文中一共展示了SymmOp.from_rotation_and_translation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: align_axis
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def align_axis(structure, axis='c', direction=(0, 0, 1)):
"""
Rotates a structure so that the specified axis is along
the [001] direction. This is useful for adding vacuum, and
in general for using vasp compiled with no z-axis relaxation.
Args:
structure (Structure): Pymatgen Structure object to rotate.
axis: Axis to be rotated. Can be 'a', 'b', 'c', or a 1x3 vector.
direction (vector): Final axis to be rotated to.
Returns:
structure. Rotated to align axis along direction.
"""
if axis == 'a':
axis = structure.lattice._matrix[0]
elif axis == 'b':
axis = structure.lattice._matrix[1]
elif axis == 'c':
axis = structure.lattice._matrix[2]
proj_axis = np.cross(axis, direction)
if not(proj_axis[0] == 0 and proj_axis[1] == 0):
theta = (
np.arccos(np.dot(axis, direction)
/ (np.linalg.norm(axis) * np.linalg.norm(direction)))
)
R = get_rotation_matrix(proj_axis, theta)
rotation = SymmOp.from_rotation_and_translation(rotation_matrix=R)
structure.apply_operation(rotation)
if axis == 'c' and direction == (0, 0, 1):
structure.lattice._matrix[2][2] = abs(structure.lattice._matrix[2][2])
return structure
示例2: rotate
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def rotate(self, matrix, tol=1e-5):
matrix = SquareTensor(matrix)
if not matrix.is_rotation(tol):
raise ValueError("Rotation matrix is not valid.")
sop = SymmOp.from_rotation_and_translation(matrix,
[0., 0., 0.])
return self.transform(sop)
示例3: parse_symmetry_operations
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def parse_symmetry_operations(symmops_str_list):
"""
Help method to parse the symmetry operations.
Args:
symmops_str_list:
List of symmops strings of the form
['x, y, z', '-x, -y, z', '-y+1/2, x+1/2, z+1/2', ...]
Returns:
List of SymmOps
"""
ops = []
for op_str in symmops_str_list:
rot_matrix = np.zeros((3, 3))
trans = np.zeros(3)
toks = op_str.strip().split(",")
for i, tok in enumerate(toks):
for m in re.finditer("([\+\-]*)\s*([x-z\d]+)/*(\d*)", tok):
factor = -1 if m.group(1) == "-" else 1
if m.group(2) in ("x", "y", "z"):
j = ord(m.group(2)) - 120
rot_matrix[i, j] = factor
else:
num = float(m.group(2))
if m.group(3) != "":
num /= float(m.group(3))
trans[i] = factor * num
op = SymmOp.from_rotation_and_translation(rot_matrix, trans)
ops.append(op)
return ops
示例4: __init__
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def __init__(self, int_symbol):
"""
Initializes a Point Group from its international symbol.
Args:
int_symbol (str): International or Hermann-Mauguin Symbol.
"""
self.symbol = int_symbol
self.generators = [get_symm_data("generator_matrices")[c]
for c in get_symm_data("point_group_encoding")[int_symbol]]
self._symmetry_ops = set([SymmOp.from_rotation_and_translation(m)
for m in self._generate_full_symmetry_ops()])
self.order = len(self._symmetry_ops)
示例5: __init__
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def __init__(self, int_symbol):
"""
Initializes a Point Group from its international symbol.
Args:
int_symbol (str): International or Hermann-Mauguin Symbol.
"""
self.symbol = int_symbol
self.generators = [GENERATOR_MATRICES[c]
for c in POINT_GROUP_ENC[int_symbol]]
self._symmetry_ops = set([SymmOp.from_rotation_and_translation(m)
for m in self._generate_full_symmetry_ops()])
self.order = len(self._symmetry_ops)
示例6: rotate
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def rotate(self, matrix, tol=1e-3):
"""
Applies a rotation directly, and tests input matrix to ensure a valid
rotation.
Args:
matrix (3x3 array-like): rotation matrix to be applied to tensor
tol (float): tolerance for testing rotation matrix validity
"""
matrix = SquareTensor(matrix)
if not matrix.is_rotation(tol):
raise ValueError("Rotation matrix is not valid.")
sop = SymmOp.from_rotation_and_translation(matrix, [0.0, 0.0, 0.0])
return self.transform(sop)
示例7: get_rot
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def get_rot(slab):
"""
Gets the transformation to rotate the z axis into the miller index
"""
new_z = get_mi_vec(slab)
a, b, c = slab.lattice.matrix
new_x = a / np.linalg.norm(a)
new_y = np.cross(new_z, new_x)
x, y, z = np.eye(3)
rot_matrix = np.array([np.dot(*el) for el in
itertools.product([x, y, z],
[new_x, new_y, new_z])]).reshape(3, 3)
rot_matrix = np.transpose(rot_matrix)
sop = SymmOp.from_rotation_and_translation(rot_matrix)
return sop
示例8: get_point_group_operations
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def get_point_group_operations(self, cartesian=False):
"""
Return symmetry operations as a list of SymmOp objects.
By default returns fractional coord symmops.
But cartesian can be returned too.
"""
(rotation, translation) = self._get_symmetry()
symmops = []
mat = self._structure.lattice.matrix.T
invmat = np.linalg.inv(mat)
for rot, trans in zip(rotation, translation):
if cartesian:
rot = np.dot(mat, np.dot(rot, invmat))
op = SymmOp.from_rotation_and_translation(rot, np.array([0, 0, 0]))
symmops.append(op)
return symmops
示例9: test_find_mapping
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def test_find_mapping(self):
m = np.array([[0.1, 0.2, 0.3], [-0.1, 0.2, 0.7], [0.6, 0.9, 0.2]])
latt = Lattice(m)
op = SymmOp.from_origin_axis_angle([0, 0, 0], [2, 3, 3], 35)
rot = op.rotation_matrix
scale = np.array([[1, 1, 0], [0, 1, 0], [0, 0, 1]])
latt2 = Lattice(np.dot(rot, np.dot(scale, m).T).T)
(aligned_out, rot_out, scale_out) = latt2.find_mapping(latt)
self.assertAlmostEqual(abs(np.linalg.det(rot)), 1)
rotated = SymmOp.from_rotation_and_translation(rot_out).operate_multi(latt.matrix)
self.assertArrayAlmostEqual(rotated, aligned_out.matrix)
self.assertArrayAlmostEqual(np.dot(scale_out, latt2.matrix), aligned_out.matrix)
self.assertArrayAlmostEqual(aligned_out.lengths_and_angles, latt.lengths_and_angles)
self.assertFalse(np.allclose(aligned_out.lengths_and_angles,
latt2.lengths_and_angles))
示例10: get_symmetry_operations
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def get_symmetry_operations(self, cartesian=False):
"""
Return symmetry operations as a list of SymmOp objects.
By default returns fractional coord symmops.
But cartesian can be returned too.
Returns:
([SymmOp]): List of symmetry operations.
"""
rotation, translation = self._get_symmetry()
symmops = []
mat = self._structure.lattice.matrix.T
invmat = np.linalg.inv(mat)
for rot, trans in zip(rotation, translation):
if cartesian:
rot = np.dot(mat, np.dot(rot, invmat))
trans = np.dot(trans, self._structure.lattice.matrix)
op = SymmOp.from_rotation_and_translation(rot, trans)
symmops.append(op)
return symmops
示例11: transform_symmop
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def transform_symmop(self, symmop):
# type: (Union[SymmOp, MagSymmOp]) -> Union[SymmOp, MagSymmOp]
"""
Takes a symmetry operation and transforms it.
:param symmop: SymmOp or MagSymmOp
:return:
"""
W = symmop.rotation_matrix
w = symmop.translation_vector
Q = np.linalg.inv(self.P)
W_ = np.matmul(np.matmul(Q, W), self.P)
I = np.identity(3)
w_ = np.matmul(Q, (w + np.matmul(W - I, self.p)))
if isinstance(symmop, MagSymmOp):
return MagSymmOp.from_rotation_and_translation_and_time_reversal(rotation_matrix=W_,
translation_vec=w_,
time_reversal=symmop.time_reversal,
tol=symmop.tol)
elif isinstance(symmop, SymmOp):
return SymmOp.from_rotation_and_translation(rotation_matrix=W_, translation_vec=w_, tol=symmop.tol)
示例12: get_point_group_operations
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def get_point_group_operations(self, cartesian=False):
"""
Return symmetry operations as a list of SymmOp objects.
By default returns fractional coord symmops.
But cartesian can be returned too.
Args:
cartesian (bool): Whether to return SymmOps as cartesian or
direct coordinate operations.
Returns:
([SymmOp]): List of point group symmetry operations.
"""
rotation, translation = self._get_symmetry()
symmops = []
mat = self._structure.lattice.matrix.T
invmat = np.linalg.inv(mat)
for rot in rotation:
if cartesian:
rot = np.dot(mat, np.dot(rot, invmat))
op = SymmOp.from_rotation_and_translation(rot, np.array([0, 0, 0]))
symmops.append(op)
return symmops
示例13: align_c_axis_along_001
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def align_c_axis_along_001(structure):
"""
Given a structure with a c-axis not along [001],
returns the same structure rotated so that the c-axis is along
the [001] direction. This is useful for vasp compiled with no
z-axis relaxation.
Args:
structure (structure): Pymatgen Structure object to rotate.
Returns:
structure. Rotated to align c-axis along [001].
"""
c = structure.lattice._matrix[2]
z = [0, 0, 1]
axis = np.cross(c, z)
if not(axis[0] == 0 and axis[1] == 0):
theta = (np.arccos(np.dot(c, z) /
(np.linalg.norm(c) * np.linalg.norm(z))))
R = get_rotation_matrix(axis, theta)
rotation = SymmOp.from_rotation_and_translation(rotation_matrix=R)
structure.apply_operation(rotation)
return structure
示例14: __init__
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def __init__(self, struct, symprec=None):
format_str = "{:.8f}"
block = OrderedDict()
loops = []
spacegroup = ("P 1", 1)
if symprec is not None:
sf = SpacegroupAnalyzer(struct, symprec)
spacegroup = (sf.get_space_group_symbol(),
sf.get_space_group_number())
# Needs the refined struture when using symprec. This converts
# primitive to conventional structures, the standard for CIF.
struct = sf.get_refined_structure()
latt = struct.lattice
comp = struct.composition
no_oxi_comp = comp.element_composition
block["_symmetry_space_group_name_H-M"] = spacegroup[0]
for cell_attr in ['a', 'b', 'c']:
block["_cell_length_" + cell_attr] = format_str.format(
getattr(latt, cell_attr))
for cell_attr in ['alpha', 'beta', 'gamma']:
block["_cell_angle_" + cell_attr] = format_str.format(
getattr(latt, cell_attr))
block["_symmetry_Int_Tables_number"] = spacegroup[1]
block["_chemical_formula_structural"] = no_oxi_comp.reduced_formula
block["_chemical_formula_sum"] = no_oxi_comp.formula
block["_cell_volume"] = latt.volume.__str__()
reduced_comp, fu = no_oxi_comp.get_reduced_composition_and_factor()
block["_cell_formula_units_Z"] = str(int(fu))
if symprec is None:
block["_symmetry_equiv_pos_site_id"] = ["1"]
block["_symmetry_equiv_pos_as_xyz"] = ["x, y, z"]
else:
sf = SpacegroupAnalyzer(struct, symprec)
def round_symm_trans(i):
for t in TRANSLATIONS.values():
if abs(i - t) < symprec:
return t
if abs(i - round(i)) < symprec:
return 0
raise ValueError("Invalid translation!")
symmops = []
for op in sf.get_symmetry_operations():
v = op.translation_vector
v = [round_symm_trans(i) for i in v]
symmops.append(SymmOp.from_rotation_and_translation(
op.rotation_matrix, v))
ops = [op.as_xyz_string() for op in symmops]
block["_symmetry_equiv_pos_site_id"] = \
["%d" % i for i in range(1, len(ops) + 1)]
block["_symmetry_equiv_pos_as_xyz"] = ops
loops.append(["_symmetry_equiv_pos_site_id",
"_symmetry_equiv_pos_as_xyz"])
contains_oxidation = True
try:
symbol_to_oxinum = OrderedDict([
(el.__str__(), float(el.oxi_state))
for el in sorted(comp.elements)])
except AttributeError:
symbol_to_oxinum = OrderedDict([(el.symbol, 0) for el in
sorted(comp.elements)])
contains_oxidation = False
if contains_oxidation:
block["_atom_type_symbol"] = symbol_to_oxinum.keys()
block["_atom_type_oxidation_number"] = symbol_to_oxinum.values()
loops.append(["_atom_type_symbol", "_atom_type_oxidation_number"])
atom_site_type_symbol = []
atom_site_symmetry_multiplicity = []
atom_site_fract_x = []
atom_site_fract_y = []
atom_site_fract_z = []
atom_site_label = []
atom_site_occupancy = []
count = 1
if symprec is None:
for site in struct:
for sp, occu in site.species_and_occu.items():
atom_site_type_symbol.append(sp.__str__())
atom_site_symmetry_multiplicity.append("1")
atom_site_fract_x.append("{0:f}".format(site.a))
atom_site_fract_y.append("{0:f}".format(site.b))
atom_site_fract_z.append("{0:f}".format(site.c))
atom_site_label.append("{}{}".format(sp.symbol, count))
atom_site_occupancy.append(occu.__str__())
count += 1
else:
# The following just presents a deterministic ordering.
unique_sites = [
(sorted(sites, key=lambda s: tuple([abs(x) for x in
s.frac_coords]))[0],
#.........这里部分代码省略.........
示例15: test_symmops
# 需要导入模块: from pymatgen.core.operations import SymmOp [as 别名]
# 或者: from pymatgen.core.operations.SymmOp import from_rotation_and_translation [as 别名]
def test_symmops(self):
sg = SpaceGroup("Pnma")
op = SymmOp.from_rotation_and_translation([[1, 0, 0], [0, -1, 0],
[0, 0, -1]], [0.5, 0.5, 0.5])
self.assertIn(op, sg.symmetry_ops)