Skip to content

Commit

Permalink
fix GaussianOutput bug with multiple route lines (#2937)
Browse files Browse the repository at this point in the history
* fix GaussianOutput bug
when multiple completed lines in route parameters

* fix GaussianOutput bug
delete only one space at the start of line

* zip test_files/molecules/EC.log

* rename var, tweak doc str

---------

Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
xjf729 and janosh authored Apr 27, 2023
1 parent 33b3195 commit 51280b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pymatgen/io/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def _parse(self, filename):
geom_orientation = None
opt_structures = []

with zopen(filename) as f:
with zopen(filename, mode="rt") as f:
for line in f:
if parse_stage == 0:
if start_patt.search(line):
Expand All @@ -842,7 +842,8 @@ def _parse(self, filename):
self.dieze_tag = params[3]
parse_stage = 1
else:
routeline += line.strip()
line = line.replace(" ", "", 1).rstrip("\n")
routeline += line
elif parse_stage == 1:
if set(line.strip()) == {"-"} and self.title is None:
self.title = ""
Expand Down
21 changes: 21 additions & 0 deletions pymatgen/io/tests/test_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,27 @@ def test_multiple_parameters(self):
assert gout.charge == 0
assert gout.spin_multiplicity == 1

def test_multiple_parameters_with_multiple_completed_lines(self):
"""
This test makes sure that input files with multi-parameter keywords
and route cards with multiple completed lines which are split by line break parse correctly.
"""
filepath = os.path.join(test_dir, "EC.log.gz")
route_params = {
"opt": {"loose": None, "maxcyc": "400"},
"freq": None,
"SCRF": "(SMD,READ)",
"EmpiricalDispersion": "GD3BJ",
}
gout = GaussianOutput(filepath)
assert gout.dieze_tag == "#N"
assert gout.functional == "B3LYP"
assert gout.basis_set == "6-311++G(2d,p)"
assert gout.route_parameters == route_params
assert gout.title == "H4 C3 O3"
assert gout.charge == 0
assert gout.spin_multiplicity == 1


if __name__ == "__main__":
unittest.main()
Binary file added test_files/molecules/EC.log.gz
Binary file not shown.

0 comments on commit 51280b9

Please sign in to comment.