Skip to content

Commit 75a534e

Browse files
committed
fixes and cleaning
1 parent 9181790 commit 75a534e

11 files changed

Lines changed: 32 additions & 57 deletions

File tree

cclib/attribute_parsers/aonames.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def natural_orbital_single_spin_parsing(fh):
7979
# New atom.
8080
if len(parts) > 1:
8181
if i > 0:
82-
this_aonames.append(basisonatom)
82+
this_aonames.append(basisonatom) # noqa: F821
8383
basisonatom = []
8484
orbital = line[11:20].strip() # noqa: F841
8585
basisonatom.append(i)
@@ -127,17 +127,20 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
127127
# when the parsing gets rough. This is what we do below with a regex, and a case
128128
# like this is tested in regression ORCA/ORCA4.0/invalid-literal-for-float.out
129129
# which was reported in https://github.com/cclib/cclib/issues/629
130+
dependency_list = ["moenergies", "nbasis"]
131+
if not base_parser.check_dependencies(dependency_list, ccdata, "atombasis"):
132+
return None
130133
line = file_handler.last_line
131134
if line[0:18] == "MOLECULAR ORBITALS":
132-
line = file_handler.virtual_next() # dashes
135+
line = file_handler.virtual_next() # dashes
133136

134137
parsed_aonames = []
135-
for spin in range(len(self.moenergies)):
138+
for spin in range(len(ccdata.moenergies)):
136139
if spin == 1:
137-
line = file_handler.virtual_next() # blank
138-
for i in range(0, self.nbasis, 6):
139-
file_handler.skip_lines(["numbers", "energies, "occs", "d"], virtual=True)
140-
for j in range(self.nbasis):
140+
line = file_handler.virtual_next() # blank
141+
for i in range(0, ccdata.nbasis, 6):
142+
file_handler.skip_lines(["numbers", "energies", "occs", "d"], virtual=True)
143+
for j in range(ccdata.nbasis):
141144
line = file_handler.virtual_next()
142145
# Only need this in the first iteration.
143146
if spin == 0 and i == 0:
@@ -148,7 +151,6 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
148151
return {aonames.__name__: parsed_aonames}
149152
return None
150153

151-
152154
@staticmethod
153155
def parse(file_handler, program: str, ccdata) -> Optional[dict]:
154156
constructed_data = None

cclib/attribute_parsers/aooverlaps.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
5757
dashes = file_handler.virtual_next() # noqa: F841
5858
constructed_aooverlaps = np.zeros((ccdata.nbasis, ccdata.nbasis), "d")
5959
for i in range(0, ccdata.nbasis, 6):
60-
#self.updateprogress(inputfile, "Overlap")
60+
# self.updateprogress(inputfile, "Overlap")
6161
header = file_handler.virtual_next()
6262
size = len(header.split())
6363
for j in range(ccdata.nbasis):
6464
line = file_handler.virtual_next()
6565
broken = line.split()
66-
constructed_aooverlaps[j, i : i + size] = list(map(float, broken[1 : size + 1]))
66+
constructed_aooverlaps[j, i : i + size] = list(
67+
map(float, broken[1 : size + 1])
68+
)
6769
return {aooverlaps.__name__: constructed_aooverlaps}
6870
return None
6971

cclib/attribute_parsers/atombasis.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,17 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
145145
return None
146146
if line[0:18] == "MOLECULAR ORBITALS":
147147
file_handler.skip_lines(["dashes"], virtual=True)
148-
#constructed_aonames = []
149148
constructed_atombasis = [[] for i in range(ccdata.natom)]
150-
#constructed_mocoeffs = [numpy.zeros((ccdata.nbasis, ccdata.nbasis), "d")]
151149
for spin in range(len(ccdata.moenergies)):
152150
if spin == 1:
153151
file_handler.skip_lines(["blank"], virtual=True)
154152
for i in range(0, ccdata.nbasis, 6):
155-
#self.updateprogress(inputfile, "Coefficients")
156153
file_handler.skip_lines(["numbers", "energies", "occs", "d"], virtual=True)
157154
for j in range(ccdata.nbasis):
158155
line = file_handler.virtual_next()
159156
# Only need this in the first iteration.
160157
if spin == 0 and i == 0:
161-
atomname = line[3:5].split()[0]
162158
num = int(line[0:3])
163-
orbital = line.split()[1].upper()
164159
constructed_atombasis[num].append(j)
165160
constructed_data = {atombasis.__name__: constructed_atombasis}
166161
return constructed_data

cclib/attribute_parsers/atomcoords.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def gaussian(file_handler, ccdata) -> Optional[dict]:
3535

3636
@staticmethod
3737
def ORCA(file_handler, ccdata) -> Optional[dict]:
38-
""" Grab cartesian coordinates
38+
"""Grab cartesian coordinates
3939
---------------------------------
4040
CARTESIAN COORDINATES (ANGSTROEM)
4141
---------------------------------
@@ -55,10 +55,9 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
5555
curr_atomcoords.append([float(x), float(y), float(z)])
5656
line = file_handler.virtual_next()
5757
constructed_atomcoords.append(curr_atomcoords)
58-
return {atomcoords.__name__ : np.array(constructed_atomcoords)}
58+
return {atomcoords.__name__: np.array(constructed_atomcoords)}
5959
return None
6060

61-
6261
@staticmethod
6362
def psi4(file_handler, ccdata) -> Optional[dict]:
6463
line = file_handler.last_line

cclib/attribute_parsers/atomnos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
5353
if atom[-1] != ">":
5454
constructed_atomnos.append(table.number[atom])
5555
line = file_handler.virtual_next()
56-
return {atomnos.__name__ : np.array(constructed_atomnos)}
56+
return {atomnos.__name__: np.array(constructed_atomnos)}
5757
return None
5858

5959
@staticmethod

cclib/attribute_parsers/charge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
5252
if not base_parser.check_dependencies(dependency_list, ccdata, "charge"):
5353
return None
5454
if "input_file_contents" in ccdata.metadata:
55-
#parsed from inputfile content
56-
lines = ccdata.metdata["input_file_contents"].split('\n')
55+
# parsed from inputfile content
56+
lines = ccdata.metdata["input_file_contents"].split("\n")
5757
lines_iter = iter(lines[:-1])
5858
for line in lines_iter:
5959
line = line.strip()

cclib/attribute_parsers/gbasis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def gaussian(file_handler, ccdata) -> Optional[dict]:
122122
@staticmethod
123123
def ORCA(file_handler, ccdata) -> Optional[dict]:
124124
line = file_handler.last_line
125-
if not "gbasis_tmp_atnames" in ccdata.parser_state:
125+
if "gbasis_tmp_atnames" not in ccdata.parser_state:
126126
return None
127127
# Basis set information
128128
# ORCA prints this out in a somewhat indirect fashion.

cclib/attribute_parsers/mocoeffs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
#
33
# This file is part of cclib (http://cclib.github.io) and is distributed under
44
# the terms of the BSD 3-Clause License.
5+
import re
56
from typing import Optional
67

78
from cclib.attribute_parsers.base_parser import base_parser
89

10+
import numpy
11+
912

1013
class mocoeffs(base_parser):
1114
"""
@@ -100,7 +103,7 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
100103
file_handler.skip_lines(["blank"], virtual=True)
101104
constructed_mocoeffs.append(numpy.zeros((ccdata.nbasis, ccdata.nbasis), "d"))
102105
for i in range(0, ccdata.nbasis, 6):
103-
#self.updateprogress(inputfile, "Coefficients")
106+
# self.updateprogress(inputfile, "Coefficients")
104107
file_handler.skip_lines(["numbers", "energies", "occs", "d"], virtual=True)
105108
for j in range(ccdata.nbasis):
106109
line = file_handler.virtual_next()
@@ -109,12 +112,13 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
109112
coeffs = re.findall(r"-?\d+\.\d{6}", line)
110113
# Something is very wrong if this does not hold.
111114
assert len(coeffs) <= 6
112-
constructed_mocoeffs[spin][i : i + len(coeffs), j] = [float(c) for c in coeffs]
115+
constructed_mocoeffs[spin][i : i + len(coeffs), j] = [
116+
float(c) for c in coeffs
117+
]
113118
constructed_data = {mocoeffs.__name__: constructed_mocoeffs}
114119
return constructed_data
115120
return None
116121

117-
118122
@staticmethod
119123
def parse(file_handler, program: str, ccdata) -> Optional[dict]:
120124
constructed_data = None

cclib/attribute_parsers/moenergies.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,23 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
5757
line = file_handler.last_line
5858
if line[0:16] == "ORBITAL ENERGIES":
5959
file_handler.skip_lines(["d", "text", "text"], virtual=True)
60-
#constructed_mooccnos = [[]]
6160
constructed_moenergies = [[]]
62-
#constructed_mosyms = [[]]
6361
line = file_handler.virtual_next()
6462
while len(line) > 20: # restricted calcs are terminated by ------
6563
info = line.split()
66-
#mooccno = int(float(info[1]))
6764
moenergy = float(info[2])
68-
#mosym = "A"
69-
#if self.uses_symmetry:
70-
# mosym = self.normalisesym(info[4].split("-")[1])
71-
#self.mooccnos[0].append(mooccno)
7265
constructed_moenergies[0].append(moenergy)
73-
#self.mosyms[0].append(mosym)
7466
line = file_handler.virtual_next()
7567
line = file_handler.virtual_next()
7668
# handle beta orbitals for UHF
7769
if line[17:35] == "SPIN DOWN ORBITALS":
7870
file_handler.skip_lines(["text"], virtual=True)
79-
#constructed_mooccnos.append([])
8071
constructed_moenergies.append([])
81-
#constructed_mosyms.append([])
8272
line = file_handler.virtual_next()
8373
while len(line) > 20: # actually terminated by ------
8474
info = line.split()
85-
#mooccno = int(float(info[1]))
8675
moenergy = float(info[2])
87-
#mosym = "A"
88-
#if self.uses_symmetry:
89-
# mosym = self.normalisesym(info[4].split("-")[1])
90-
#constructed_mooccnos[1].append(mooccno)
9176
constructed_moenergies[1].append(moenergy)
92-
#constructed_mosyms[1].append(mosym)
9377
line = file_handler.virtual_next()
9478
constructed_moenergies = [np.array(x, "d") for x in constructed_moenergies]
9579
return {moenergies.__name__: constructed_moenergies}

cclib/attribute_parsers/mosyms.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def gaussian_normalizesym(label):
3030
ans = label.replace("U", "u").replace("G", "g")
3131
return ans
3232

33+
3334
def orca_normalizesym(label):
34-
"""ORCA does not require normalizing symmetry labels."""
35-
return label
35+
"""ORCA does not require normalizing symmetry labels."""
36+
return label
3637

37-
3838

3939
def qchem_parse_orbital_energies_and_symmetries(file_handler):
4040
"""Parse the 'Orbital Energies (a.u.)' block appearing after SCF converges,
@@ -209,14 +209,10 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
209209
uses_symmetry = ccdata.parser_state["uses_symmetry"]
210210
if line[0:16] == "ORBITAL ENERGIES":
211211
file_handler.skip_lines(["d", "text", "text"], virtual=True)
212-
#constructed_mooccnos = [[]]
213-
#constructed_moenergies = [[]]
214212
constructed_mosyms = [[]]
215213
line = file_handler.virtual_next()
216214
while len(line) > 20: # restricted calcs are terminated by ------
217215
info = line.split()
218-
#mooccno = int(float(info[1]))
219-
#moenergy = float(info[2])
220216
mosym = "A"
221217
if uses_symmetry:
222218
mosym = orca_normalizesym(info[4].split("-")[1])
@@ -226,25 +222,18 @@ def ORCA(file_handler, ccdata) -> Optional[dict]:
226222
# handle beta orbitals for UHF
227223
if line[17:35] == "SPIN DOWN ORBITALS":
228224
file_handler.skip_lines(["text"], virtual=True)
229-
#constructed_mooccnos.append([])
230-
#constructed_moenergies.append([])
231225
constructed_mosyms.append([])
232226
line = file_handler.virtual_next()
233227
while len(line) > 20: # actually terminated by ------
234228
info = line.split()
235-
#mooccno = int(float(info[1]))
236-
#moenergy = float(info[2])
237229
mosym = "A"
238230
if uses_symmetry:
239231
mosym = orca_normalizesym(info[4].split("-")[1])
240-
#constructed_mooccnos[1].append(mooccno)
241-
#constructed_moenergies[1].append(moenergy)
242232
constructed_mosyms[1].append(mosym)
243233
line = file_handler.virtual_next()
244234
return {mosyms.__name__: constructed_mosyms}
245235
return None
246236

247-
248237
@staticmethod
249238
def parse(file_handler, program: str, ccdata) -> Optional[dict]:
250239
constructed_data = None

0 commit comments

Comments
 (0)