Hi, I had the structure imported from cif file and just want to switch the y and z-axis. I tried to apply a 90-degree rotation around the x-axis to switch the y and z directions, however, trying it several times still got the original crystal structure exported. Could someone help me with it? Thanks a lot. Following is the code I use. Thanks a lot for any help in advance.
I had the same issue.
I tried several ways via Pymatgen as below. The trial (1) and (2) did not work, they just produce the original crystal structure. And I found a function, “swap_axes” in “doped” python software. They used the “SupercellTransformation” class in Pymatgen, and it works!
I have no ideal why the trial (1) and (2) is not working, but (3) is working. Does anyone explain why and why not these works like that?
# Import necessary libraries
import pymatgen.core as mg
# Load a cif file
struct = mg.Structure.from_file(cif_filename)
# Define a rotation matrix to swap b and c axes
rotation_matrix = [[1, 0, 0], [0, 0, 1], [0, -1, 0]]
(1) Using “DeformStructureTransformation”
from pymatgen.transformations.standard_transformations import DeformStructureTransformation
dst = DeformStructureTransformation(rotation_matrix)
rotated_struct = dst.apply_transformation(struct)
(2) Using “SymmOp.from_rotation_and_translation”
from pymatgen.core.operations import SymmOp
rotation_op = SymmOp.from_rotation_and_translation(rotation_matrix, [0, 0, 0])
rotated_structure = struct.copy()
rotated_structure.apply_operation(rotation_op)
(3) Using “SupercellTransformation”
from pymatgen.transformations.standard_transformations import SupercellTransformation
transformation = SupercellTransformation(rotation_matrix)
rotated_struct = transformation.apply_transformation(struct)