-
Notifications
You must be signed in to change notification settings - Fork 0
/
Property.py
165 lines (128 loc) · 11.7 KB
/
Property.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
Copyright (c) 2013-2014 Benedicte Ofstad
Distributed under the GNU Lesser General Public License v3.0.
For full terms see the file LICENSE.md.
"""
import Molecule as mol
import numpy as np
import read_input as ri
import pydoc
class Property:
"""The superclass for calculating properties of a molecule"""
def __init__(self, molecule, property_name):
self.m_e = 1822.8884796 # conversion factor from a.m.u to a.u
self.prefactor = 1/(4*self.m_e)
self.molecule = molecule
self.freq = self.molecule.frequencies
def __call__():
"""The superclass for the call function, raises a NotImplementedError."""
raise NotImplementedError\
('___call__ missing in class %s' % self.__class__.__name__)
def quartic_precision(cff_norm, qff_norm, prop_deriv):
"""The superclass for the quartic_precision function, raises a NotImplementedError."""
raise NotImplementedError\
('___call__ missing in class %s' % self.__class__.__name__)
def get_quartic_force_field(self):
"""Returns the quartic force field in cartessian coordinates as
a 4D np.array"""
qff = ri.read_quartic_force_field1(self.molecule.input_name + "/quartic", self.molecule.n_coordinates)
return(qff)
def write_to_file(self, property_type, n_atom = None):
""" Writes the resutls to file. It writes the uncorrected property
the property corrections and the corrected property. Instead of
producing its own lable. This method writes the table in LaTeX code.
property_type: This will be written in the header of the table.
n_atom: The number of atoms making up the molecule.
return: A file with the results written out in LaTeX code.
"""
filename = self.molecule.get_output_name()
f = open(filename, "a")
atom_list = self.molecule.atom_list
#f.write("& & Effective geometry & $<P^{(0)}_2>_{eff}$ & Vibrationally corrected \\\\" + "\n")
corrected_property = np.around(self.corrected_property, decimals=4)
correction_property = np.around(self.correction_property, decimals=4)
uncorrected_property = np.around(self.uncorrected_property, decimals=4)
f.write(property_type)
if(property_type == "Optical rotation"):
corrected_property = np.around(self.corrected_property1, decimals=4)
correction_property = np.around(self.correction_property1, decimals=4)
uncorrected_property = np.around(self.uncorrected_property1, decimals=4)
f.write(property_type)
f.write( "& XX " + "&"+ str(uncorrected_property[0][0]) + "&" + str(correction_property[0][0]) + "&" +str(corrected_property[0][0])+ "\\\\ \n")
f.write( "& XY " + "&"+ str(uncorrected_property[0][1]) + "&" + str(correction_property[0][1]) + "&" +str(corrected_property[0][1])+ "\\\\ \n")
f.write( "& XZ " + "&"+ str(uncorrected_property[0][2]) + "&" + str(correction_property[0][2]) + "&" +str(corrected_property[0][2])+ " \\\\ \n")
f.write(" & YX " + "&"+ str(uncorrected_property[1][0]) + "&" + str(correction_property[1][0]) + "&" +str(corrected_property[1][0])+ "\\\\ \n")
f.write(" & YY " + "&"+ str(uncorrected_property[1][1]) + "&" + str(correction_property[1][1]) + "&" +str(corrected_property[1][1])+ "\\\\ \n")
f.write(" & YZ " + "&"+ str(uncorrected_property[1][2]) + "&" + str(correction_property[1][2]) + "&" +str(corrected_property[1][2])+ "\\\\ \n")
f.write(" & ZX " + "&" +str(uncorrected_property[2][0]) + "&" + str(correction_property[2][0]) + "&" +str(corrected_property[2][0])+ "\\\\ \n")
f.write(" & ZY " + "&"+ str(uncorrected_property[2][1]) + "&" + str(correction_property[2][1]) + "&" +str(corrected_property[2][1])+ "\\\\ \n")
f.write(" & ZZ "+ "&"+ str(uncorrected_property[2][2]) + "&" + str(correction_property[2][2]) + "&" +str(corrected_property[2][2]) + "\\\\ \n")
f.write("\hline" + "\n")
corrected_property = np.around(self.corrected_property2, decimals=4)
correction_property = np.around(self.correction_property2, decimals=4)
uncorrected_property = np.around(self.uncorrected_property2, decimals=4)
f.write(property_type)
f.write( "& XX " + "&"+ str(uncorrected_property[0][0]) + "&" + str(correction_property[0][0]) + "&" +str(corrected_property[0][0])+ "\\\\ \n")
f.write( "& XY " + "&"+ str(uncorrected_property[0][1]) + "&" + str(correction_property[0][1]) + "&" +str(corrected_property[0][1])+ "\\\\ \n")
f.write( "& XZ " + "&"+ str(uncorrected_property[0][2]) + "&" + str(correction_property[0][2]) + "&" +str(corrected_property[0][2])+ " \\\\ \n")
f.write(" & YX " + "&"+ str(uncorrected_property[1][0]) + "&" + str(correction_property[1][0]) + "&" +str(corrected_property[1][0])+ "\\\\ \n")
f.write(" & YY " + "&"+ str(uncorrected_property[1][1]) + "&" + str(correction_property[1][1]) + "&" +str(corrected_property[1][1])+ "\\\\ \n")
f.write(" & YZ " + "&"+ str(uncorrected_property[1][2]) + "&" + str(correction_property[1][2]) + "&" +str(corrected_property[1][2])+ "\\\\ \n")
f.write(" & ZX " + "&" +str(uncorrected_property[2][0]) + "&" + str(correction_property[2][0]) + "&" +str(corrected_property[2][0])+ "\\\\ \n")
f.write(" & ZY " + "&"+ str(uncorrected_property[2][1]) + "&" + str(correction_property[2][1]) + "&" +str(corrected_property[2][1])+ "\\\\ \n")
f.write(" & ZZ "+ "&"+ str(uncorrected_property[2][2]) + "&" + str(correction_property[2][2]) + "&" +str(corrected_property[2][2]) + "\\\\ \n")
corrected_property = np.around(self.corrected_property3, decimals=4)
correction_property = np.around(self.correction_property3, decimals=4)
uncorrected_property = np.around(self.uncorrected_property3, decimals=4)
f.write(property_type)
f.write( "& XX " + "&"+ str(uncorrected_property[0][0]) + "&" + str(correction_property[0][0]) + "&" +str(corrected_property[0][0])+ "\\\\ \n")
f.write( "& XY " + "&"+ str(uncorrected_property[0][1]) + "&" + str(correction_property[0][1]) + "&" +str(corrected_property[0][1])+ "\\\\ \n")
f.write( "& XZ " + "&"+ str(uncorrected_property[0][2]) + "&" + str(correction_property[0][2]) + "&" +str(corrected_property[0][2])+ " \\\\ \n")
f.write(" & YX " + "&"+ str(uncorrected_property[1][0]) + "&" + str(correction_property[1][0]) + "&" +str(corrected_property[1][0])+ "\\\\ \n")
f.write(" & YY " + "&"+ str(uncorrected_property[1][1]) + "&" + str(correction_property[1][1]) + "&" +str(corrected_property[1][1])+ "\\\\ \n")
f.write(" & YZ " + "&"+ str(uncorrected_property[1][2]) + "&" + str(correction_property[1][2]) + "&" +str(corrected_property[1][2])+ "\\\\ \n")
f.write(" & ZX " + "&" +str(uncorrected_property[2][0]) + "&" + str(correction_property[2][0]) + "&" +str(corrected_property[2][0])+ "\\\\ \n")
f.write(" & ZY " + "&"+ str(uncorrected_property[2][1]) + "&" + str(correction_property[2][1]) + "&" +str(corrected_property[2][1])+ "\\\\ \n")
f.write(" & ZZ "+ "&"+ str(uncorrected_property[2][2]) + "&" + str(correction_property[2][2]) + "&" +str(corrected_property[2][2]) + "\\\\ \n")
f.close()
return
if(corrected_property.ndim == 1):
#line = str(results).strip('[]')
#line = re.sub("\\s+", "&", line)
#line = line + "\\\\"
f.write("& X & " + str(uncorrected_property[0]) + "&" + str(correction_property[0]) + "&" +str(corrected_property[0])+"\\\\ \n")
f.write("& Y &" + str(uncorrected_property[1]) + "&" +str(correction_property[1]) + "&" +str(corrected_property[1])+"\\\\ \n")
f.write("& Z &" + str(uncorrected_property[2]) + "&" +str(correction_property[2]) + "&" +str(corrected_property[2])+"\\\\ \n")
#f.write(line + "\n")
f.write("\hline" + "\n")
f.close()
if(corrected_property.ndim == 2):
f.write( "& XX " + "&"+ str(uncorrected_property[0][0]) + "&" + str(correction_property[0][0]) + "&" +str(corrected_property[0][0])+ "\\\\ \n")
f.write( "& XY " + "&"+ str(uncorrected_property[0][1]) + "&" + str(correction_property[0][1]) + "&" +str(corrected_property[0][1])+ "\\\\ \n")
f.write( "& XZ " + "&"+ str(uncorrected_property[0][2]) + "&" + str(correction_property[0][2]) + "&" +str(corrected_property[0][2])+ " \\\\ \n")
f.write(" & YX " + "&"+ str(uncorrected_property[1][0]) + "&" + str(correction_property[1][0]) + "&" +str(corrected_property[1][0])+ "\\\\ \n")
f.write(" & YY " + "&"+ str(uncorrected_property[1][1]) + "&" + str(correction_property[1][1]) + "&" +str(corrected_property[1][1])+ "\\\\ \n")
f.write(" & YZ " + "&"+ str(uncorrected_property[1][2]) + "&" + str(correction_property[1][2]) + "&" +str(corrected_property[1][2])+ "\\\\ \n")
f.write(" & ZX " + "&" +str(uncorrected_property[2][0]) + "&" + str(correction_property[2][0]) + "&" +str(corrected_property[2][0])+ "\\\\ \n")
f.write(" & ZY " + "&"+ str(uncorrected_property[2][1]) + "&" + str(correction_property[2][1]) + "&" +str(corrected_property[2][1])+ "\\\\ \n")
f.write(" & ZZ "+ "&"+ str(uncorrected_property[2][2]) + "&" + str(correction_property[2][2]) + "&" +str(corrected_property[2][2]) + "\\\\ \n")
f.write("\hline" + "\n")
f.close()
if(corrected_property.ndim == 3):
f.write(property_type + "\\\\" + "\n")
for atom in range(n_atom):
f.write("\hline"+ "\n" )
f.write("Atom: "+ atom_list[atom] )
f.write( "& XX " + "&"+ str(uncorrected_property[atom][0][0]) + "&" + str(correction_property[atom][0][0]) + "&" +str(corrected_property[atom][0][0])+ "\\\\ \n")
f.write( "& XY " + "&"+ str(uncorrected_property[atom][0][1]) + "&" + str(correction_property[atom][0][1]) + "&" +str(corrected_property[atom][0][1])+ "\\\\ \n")
f.write( "& XZ " + "&"+ str(uncorrected_property[atom][0][2]) + "&" + str(correction_property[atom][0][2]) + "&" +str(corrected_property[atom][0][2])+ " \\\\ \n")
f.write(" & YX " + "&"+ str(uncorrected_property[atom][1][0]) + "&" + str(correction_property[atom][1][0]) + "&" +str(corrected_property[atom][1][0])+ "\\\\ \n")
f.write(" & YY " + "&"+ str(uncorrected_property[atom][1][1]) + "&" + str(correction_property[atom][1][1]) + "&" +str(corrected_property[atom][1][1])+ "\\\\ \n")
f.write(" & YZ " + "&"+ str(uncorrected_property[atom][1][2]) + "&" + str(correction_property[atom][1][2]) + "&" +str(corrected_property[atom][1][2])+ "\\\\ \n")
f.write(" & ZX " + "&"+ str(uncorrected_property[atom][2][0]) + "&" + str(correction_property[atom][2][0]) + "&" +str(corrected_property[atom][2][0])+ "\\\\ \n")
f.write(" & ZY " + "&"+ str(uncorrected_property[atom][2][1]) + "&" + str(correction_property[atom][2][1]) + "&" +str(corrected_property[atom][2][1])+ "\\\\ \n")
f.write(" & ZZ "+ "&"+ str(uncorrected_property[atom][2][2]) + "&" + str(correction_property[atom][2][2]) + "&" +str(corrected_property[atom][2][2]) + "\\\\ \n")
f.write("\n") # Seperates the 2D matrices making up the 3D matrix
f.write("\hline" + "\n")
#f.write("\\end{tabular}")
f.close()