Skip to content

Commit f6e4082

Browse files
committed
Add vasp_snake/src/report_status.py
1 parent 28046eb commit f6e4082

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

vasp_snake/src/report_status.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import json
2+
import os
3+
4+
import click
5+
6+
try:
7+
import yaml
8+
except ImportError:
9+
yaml = None
10+
11+
from ..src.force import parse_forces_and_check_zero
12+
13+
14+
@click.command()
15+
@click.option(
16+
"--format",
17+
"out_format",
18+
type=click.Choice(["json", "yaml"], case_sensitive=False),
19+
default="json",
20+
help="Output format (json or yaml)",
21+
)
22+
@click.option("--folders", default=".", help="Root directory containing folders")
23+
def main(out_format, folders):
24+
status = {}
25+
folders_list = [
26+
d
27+
for d in os.listdir(folders)
28+
if os.path.isdir(os.path.join(folders, d)) and not d.startswith(".")
29+
]
30+
for folder in sorted(folders_list):
31+
outcar = os.path.join(folders, folder, "OUTCAR")
32+
if not os.path.exists(outcar):
33+
status[folder] = {"status": "not_run", "reason": "OUTCAR missing"}
34+
else:
35+
forces_sum, close = parse_forces_and_check_zero(outcar)
36+
if close is None:
37+
status[folder] = {
38+
"status": "not_converged",
39+
"reason": "No force block found",
40+
}
41+
elif close:
42+
status[folder] = {
43+
"status": "done",
44+
"forces_sum": [float(f) for f in forces_sum],
45+
}
46+
else:
47+
status[folder] = {
48+
"status": "not_converged",
49+
"forces_sum": [float(f) for f in forces_sum],
50+
}
51+
52+
if out_format == "json":
53+
print(json.dumps(status, indent=2))
54+
elif out_format == "yaml":
55+
if yaml is None:
56+
print("pyyaml not installed. Please install pyyaml.")
57+
exit(1)
58+
print(yaml.dump(status, sort_keys=False))
59+
60+
61+
if __name__ == "__main__":
62+
main()

0 commit comments

Comments
 (0)