-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxyz_to_POSCAR.py
45 lines (35 loc) · 1.1 KB
/
xyz_to_POSCAR.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
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# coding: utf-8
import os
import numpy as np
import ase
from ase.io import read, write
from ase import Atoms
import MDAnalysis as mda
prefix_path = os.getcwd()
print(prefix_path)
# Create cell vectors from A, B, C
cell = [[15.0, 0, 0],
[0, 15.0, 0],
[0, 0, 15.0]]
# Path to the XYZ trajectory file
trajectory_file = 'centered_structure.xyz'
# Output directory for Quantum Espresso input files
output_dir = 'poscar_files'
# Ensure output directory exists
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Read the trajectory
universe = mda.Universe(trajectory_file)
# Iterate over each frame
for ts in universe.trajectory:
# Convert MDAnalysis universe to ASE atoms
print(f"# Convert xyz to POSCAR using MDAnalysis for structure {ts}")
atoms = Atoms(symbols=universe.atoms.names,
positions=universe.atoms.positions,
cell=cell,
pbc=True)
# print(ts.frame)
outdir = os.path.join(output_dir, str(ts.frame))
os.mkdir(outdir)
write(os.path.join(outdir,f"POSCAR"), atoms, format='vasp')