forked from skelton-group/Phonopy-Spectroscopy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxyz2poscar
More file actions
executable file
·91 lines (64 loc) · 2.26 KB
/
xyz2poscar
File metadata and controls
executable file
·91 lines (64 loc) · 2.26 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# -------
# Imports
# -------
from argparse import ArgumentParser;
import numpy as np;
from SpectroscoPy.Interfaces.Misc import ReadXYZ;
from SpectroscoPy.Interfaces.VASP import WritePOSCAR;
from SpectroscoPy.Utilities import CartesianToFractionalCoordinates;
# ----
# Main
# ----
if __name__ == "__main__":
# Parse command-line arguments.
parser = ArgumentParser("Convert an XYZ-format molecular structure to a VASP 5 POSCAR file");
parser.add_argument(
"XYZFile",
metavar = "<xyz_file>",
type = str,
help = "XYZ-format file to convert"
);
parser.add_argument(
"-o", "--output",
metavar = "<poscar_file>",
type = str, dest = "POSCARFile",
default = "POSCAR.vasp",
help = "Output POSCAR file"
);
parser.add_argument(
"--padding",
metavar = "<box_padding>",
type = float, dest = "Padding",
default = 15.0,
help = "Padding between periodic images (default: 15 A)"
);
parser.add_argument(
"--title",
metavar = "<title>",
type = str, dest = "TitleLine",
default = None,
help = "Override the title line (line 1) of the POSCAR file (default: read from XYZ file)"
);
args = parser.parse_args();
# Read XYZ file.
titleLine, atomicSymbols, atomPositions = ReadXYZ(args.XYZFile);
# Find minimum and maximum x, y and z coordinates and work out the lattice vectors using the supplied padding.
minPos = np.min(atomPositions, axis = 0);
maxPos = np.max(atomPositions, axis = 0);
latticeVectors = np.diag(
(maxPos - minPos) + args.Padding
);
# Adjust positions to place the atom at the centre of the cell.
translationVector = (-1.0 * minPos) + args.Padding / 2.0;
atomPositions = [
position + translationVector for position in atomPositions
];
# Convert positions from cartesian to fractional coordinates.
atomPositions = CartesianToFractionalCoordinates(atomPositions, latticeVectors);
# Write output file.
WritePOSCAR(
(latticeVectors, atomicSymbols, atomPositions),
args.POSCARFile,
titleLine = args.TitleLine if args.TitleLine != None else titleLine
);