-
Notifications
You must be signed in to change notification settings - Fork 2
/
Psi4.py
81 lines (72 loc) · 2.79 KB
/
Psi4.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 1 15:35:15 2018
@author: alex
"""
import re
import numpy as np
import logging
#from .ParserData import MolecularOrbitals, Amplitudes
from .QCBase import QCMethod, VarNames as V
from .QCBase import var_tag
# create module logger
mLogger = logging.getLogger("CCParser.Psi4")
class General(QCMethod):
"""Parse quantities related to Symmetry-Adapted Perturbation Theory."""
def __init__(self):
super().__init__()# necessary for every derived class of QCMethod
# hooks as {function_name : hook_string}
# [!!!!] just temporary fix since I can't make out a has_finished hook!
self.hooks = {"has_finished" : "Warning! sapt0 does not have an associated derived wavefunction."}
@var_tag(V.has_finished)
def has_finished(self, i, data):
""" Parse final statement that indicates if Gaussian finished
without errors. """
mLogger.info("whether Psi4 has finished successfully",
extra={"Parsed": V.has_finished})
return True
class SAPT(QCMethod):
"""Parse quantities related to Symmetry-Adapted Perturbation Theory."""
def __init__(self):
super().__init__()# necessary for every derived class of QCMethod
# hooks as {function_name : hook_string}
self.hooks = {"sapt_components" : "SAPT Results",
"sapt0_total" : "Total SAPT0"}
@var_tag(V.sapt_components)
def sapt_components(self, i, data):
""" Parse SAPT components in [mEh] from SAPT results section.
Returns
-------
l : list
List of SAPT components in form [elst, exch, indc, disp]
"""
keys = ["Electrostatics", "Exchange", "Induction", "Dispersion"]
l = [0,0,0,0]
n = 0
while True:#dirrrty
curr_line = data[i+n+1].split()
if len(curr_line) > 0:
if "Total" in data[i+n+1].split()[0]:
break
descriptor = data[i+n+1].split()[0]
if descriptor in keys:
l[keys.index(descriptor)] = float(data[i+n+1].split()[1])
n += 1
mLogger.info("SAPT components in [mEh]",
extra={"Parsed":V.sapt_components})
if l == [0, 0, 0, 0]:
raise ValueError("Could not determine SAPT0 components!")
return l
@var_tag(V.sapt0_total)
def sapt0_total(self, n, data):
""" Parse total interaction energy at SAPT0 level.
Returns
-------
sapt0 : float
Total interaction energy at SAPT0 level in
"""
sapt0 = float(data[n].split()[2])
mLogger.info("SAPT0 interaction energy in [mEh]",
extra={"Parsed":V.sapt0_total})
return sapt0