Skip to content

Commit

Permalink
Fix parsing logic for CREST runs
Browse files Browse the repository at this point in the history
  • Loading branch information
smcolby committed Dec 26, 2024
1 parent 3398844 commit b3bb053
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions isicle/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,41 +922,40 @@ def _crest_timing(self):
"""

def grab_time(line):
line = line.replace(" ", "")
line = line.split(":")

return ":".join(line[1:]).strip("\n")
# Regular expression pattern
pattern = r"(?:(\d+)\s*d,\s*)?(?:(\d+)\s*h,\s*)?(?:(\d+)\s*min,\s*)?([\d.]+)\s*sec"
match = re.search(pattern, line)
return {
"days": int(match.group(1)) if match.group(1) else 0,
"hours": int(match.group(2)) if match.group(2) else 0,
"minutes": int(match.group(3)) if match.group(3) else 0,
"seconds": float(match.group(4))
}

ready = False
timing = {}
for line in self.lines:
if "test MD wall time" in line:
test_MD = grab_time(line)
ready = True
if "CREST runtime (total)" in line:
timing["CREST runtime (total)"] = grab_time(line)

if "MTD wall time" in line:
MTD_time = grab_time(line)
if "Trial metadynamics (MTD)" in line:
timing["Trial metadynamics (MTD)"] = grab_time(line)

if "multilevel OPT wall time" in line:
multilevel_OPT = grab_time(line)
if "Metadynamics (MTD)" in line:
timing["Metadynamics (MTD)"] = grab_time(line)

if "MD wall time" in line and ready is True:
MD = grab_time(line)
ready = False
if "Geometry optimization" in line:
timing["Geometry optimization"] = grab_time(line)

if "GC wall time" in line:
GC = grab_time(line)
if "Molecular dynamics (MD)" in line:
timing["Molecular dynamics (MD)"] = grab_time(line)

if "Overall wall time" in line:
overall = grab_time(line)
if "Genetic crossing (GC)" in line:
timing["Genetic crossing (GC)"] = grab_time(line)

if "I/O and setup" in line:
timing["I/O and setup"] = grab_time(line)

return {
"test MD wall time": test_MD,
"metadynamics wall time": MTD_time,
"multilevel opt wall time": multilevel_OPT,
"molecular dynamics wall time": MD,
"genetic z-matrix crossing wall time": GC,
"overall wall time": overall,
}
return timing

def _isomer_energy(self):
"""
Expand Down Expand Up @@ -1060,10 +1059,12 @@ def _parse_protocol(self):
protocol = None

for line in self.lines:
if " > " in line:
if "$ crest" in line:
protocol = line.strip("\n")
return protocol
if "program call" in line:
protocol = (line.split(":")[1]).strip("\n")
return protocol
return protocol

def _parse_geometry(self):
Expand Down Expand Up @@ -1100,15 +1101,15 @@ def parse(self):

# Check that the file is valid first
if len(self.lines) == 0:
raise RuntimeError("No contents to parse: {}".format(self.path))
raise RuntimeError("No contents to parse.")

last_lines = "".join(self.lines[-10:])
if (
("terminat" not in last_lines)
& ("normal" not in last_lines)
& ("ratio" not in last_lines)
):
raise RuntimeError("XTB job failed: {}".format(self.path))
raise RuntimeError("XTB job failed.")

# Initialize result object to store info
result = {
Expand Down

0 comments on commit b3bb053

Please sign in to comment.