-
Notifications
You must be signed in to change notification settings - Fork 854
/
gaussian_analyzer.py
executable file
·112 lines (97 loc) · 2.98 KB
/
gaussian_analyzer.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.
"""
A convenience script engine to read Gaussian output in a directory tree.
"""
import argparse
import logging
import multiprocessing
import os
import re
from tabulate import tabulate
from pymatgen.apps.borg.hive import GaussianToComputedEntryDrone
from pymatgen.apps.borg.queen import BorgQueen
save_file = "gau_data.gz"
def get_energies(rootdir, reanalyze, verbose):
"""
:param rootdir:
:param reanalyze:
:param verbose:
:return:
"""
if verbose:
FORMAT = "%(relativeCreated)d msecs : %(message)s"
logging.basicConfig(level=logging.INFO, format=FORMAT)
drone = GaussianToComputedEntryDrone(inc_structure=True, parameters=["filename"])
ncpus = multiprocessing.cpu_count()
logging.info("Detected {} cpus".format(ncpus))
queen = BorgQueen(drone, number_of_drones=ncpus)
if os.path.exists(save_file) and not reanalyze:
msg = (
"Using previously assimilated data from {}.".format(save_file)
+ " Use -f to force re-analysis."
)
queen.load_data(save_file)
else:
queen.parallel_assimilate(rootdir)
msg = "Results saved to {} for faster reloading.".format(save_file)
queen.save_data(save_file)
entries = queen.get_data()
entries = sorted(entries, key=lambda x: x.parameters["filename"])
all_data = [
(
e.parameters["filename"].replace("./", ""),
re.sub(r"\s+", "", e.composition.formula),
"{}".format(e.parameters["charge"]),
"{}".format(e.parameters["spin_mult"]),
"{:.5f}".format(e.energy),
"{:.5f}".format(e.energy_per_atom),
)
for e in entries
]
headers = ("Directory", "Formula", "Charge", "Spin Mult.", "Energy", "E/Atom")
print(tabulate(all_data, headers=headers))
print("")
print(msg)
def main():
"""
Main function
"""
desc = """
Convenient Gaussian run analyzer which can recursively go into a directory
to search results.
Author: Shyue Ping Ong
Version: 1.0
Last updated: Jul 6 2012"""
parser = argparse.ArgumentParser(description=desc)
parser.add_argument(
"directories",
metavar="dir",
default=".",
type=str,
nargs="*",
help="directory to process",
)
parser.add_argument(
"-v",
"--verbose",
dest="verbose",
action="store_const",
const=True,
help="Verbose mode. Provides detailed output on progress.",
)
parser.add_argument(
"-f",
"--force",
dest="reanalyze",
action="store_const",
const=True,
help="Force reanalysis, instead of reusing gaussian_analyzer_data.gz.",
)
args = parser.parse_args()
for d in args.directories:
get_energies(d, args.reanalyze, args.verbose)
if __name__ == "__main__":
main()