-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
31 lines (24 loc) · 1.27 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Install pymatgen if not already installed
# pip install pymatgen
# Import required libraries
from pymatgen.core import Structure
import numpy as np
# Function to process files and compute the transformation matrix
def calculate_transformation_matrix():
# Prompt the user to input the file paths
primitive_file_path = input("Enter the path to the primitive cell POSCAR file (e.g., primitive.vasp): ").strip()
supercell_file_path = input("Enter the path to the supercell POSCAR file (e.g., supercell.vasp): ").strip()
# Load structures from the provided file paths
primitive_structure = Structure.from_file(primitive_file_path)
supercell_structure = Structure.from_file(supercell_file_path)
# Extract the lattice matrices
primitive_lattice = primitive_structure.lattice.matrix # 3x3 matrix for primitive cell
supercell_lattice = supercell_structure.lattice.matrix # 3x3 matrix for supercell
# Compute the transformation matrix
transformation_matrix = np.linalg.inv(primitive_lattice).dot(supercell_lattice)
transformation_matrix = np.rint(transformation_matrix).astype(int) # Round for precision
# Print the result
print("\nTransformation Matrix:")
print(transformation_matrix)
# Call the function
calculate_transformation_matrix()