-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathase_get_ir_inputs
More file actions
executable file
·87 lines (67 loc) · 2.63 KB
/
ase_get_ir_inputs
File metadata and controls
executable file
·87 lines (67 loc) · 2.63 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
#! /usr/bin/env python3
from pathlib import Path
from typing import List
import typer
from rich import print as echo
from rich.progress import track
app = typer.Typer(pretty_exceptions_show_locals=False)
@app.command()
def main(
files: List[Path],
file_reference: Path = "geometry.in",
outfile_forces: str = "outfile_forces.dat",
outfile_dipoles: str = "outfile_dipoles.dat",
outfile_displacements: str = "outfile_displacements.dat",
fmt="%20.10e",
decimals: int = 10,
format_in: str = None,
format_out: str = None,
):
"""Get forces, dipoles, and displacements from DFT output files
Args:
files: DFT output files with dipoles
file_reference: reference structure
outfile_forces: output file for forces
outfile_dipoles: output file for dipoles
outfile_displacements: output file for displacements
fmt: format for array output
decimals: round to this number of decimals
format_in: ASE input file format
format_out: ASE output file format
"""
from ase import __version__ as ase_version
from ase.io import read
import numpy as np
assert int(ase_version.split(".")[1]) >= 23, "ASE >= 3.23 required!"
echo(f"Input files: {files}")
echo(f'Reading reference structure from "{file_reference}"')
atoms_reference = read(file_reference, format=format_in)
echo(f"... {atoms_reference}")
forces = []
dipoles = []
displacements = []
for file in track(files, description="Processing files"):
_atoms = read(file, format=format_out)
f = _atoms.get_forces()
p = _atoms.get_dipole_moment()
d = _atoms.get_positions() - atoms_reference.get_positions()
forces.append(f)
dipoles.append(p)
displacements.append(d)
forces = np.array(forces).round(decimals)
dipoles = np.array(dipoles).round(decimals)
displacements = np.array(displacements).round(decimals)
echo(f'... write forces to "{outfile_forces}"')
_header = " ".join([str(x) for x in forces.shape])
_array = forces.reshape(-1, 3)
np.savetxt(outfile_forces, _array, fmt=fmt, header=_header)
echo(f'... write dipoles to "{outfile_dipoles}"')
_header = " ".join([str(x) for x in dipoles.shape])
_array = dipoles.reshape(-1, 3)
np.savetxt(outfile_dipoles, _array, fmt=fmt, header=_header)
echo(f'... write displacements to "{outfile_displacements}"')
_header = " ".join([str(x) for x in displacements.shape])
_array = displacements.reshape(-1, 3)
np.savetxt(outfile_displacements, _array, fmt=fmt, header=_header)
if __name__ == "__main__":
app()