Skip to content

Commit

Permalink
Make parse_1d_scan_coords() more robust (#607)
Browse files Browse the repository at this point in the history
The `parse_1d_scan_coords()` crashed for a specific TS scan output file
for two independent reasons.
Both bugs were fixed now, and a test was added.
  • Loading branch information
kfir4444 committed Mar 10, 2023
2 parents a9bc6ad + 1c2f580 commit b7fc76f
Show file tree
Hide file tree
Showing 3 changed files with 38,041 additions and 3 deletions.
10 changes: 7 additions & 3 deletions arc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,21 @@ def parse_1d_scan_coords(path: str) -> List[Dict[str, tuple]]:
if i >= len(lines) or 'Normal termination of Gaussian' in lines[i] or 'Error termination via' in lines[i]:
done = True
elif 'Optimization completed' in lines[i]:
while len(lines) and 'Input orientation:' not in lines[i]:
while i < len(lines) + 10 and 'Input orientation:' not in lines[i] or 'Forces (Hartrees/Bohr)' in lines [i + 7]:
i += 1
if 'Error termination via' in lines[i]:
return traj
i += 5
xyz_str = ''
xyz_str, skip_traj = '', False
while len(lines) and '--------------------------------------------' not in lines[i]:
if 'DIIS: error' in lines[i]:
skip_traj = True
break
splits = lines[i].split()
xyz_str += f'{qcel.periodictable.to_E(int(splits[1]))} {splits[3]} {splits[4]} {splits[5]}\n'
i += 1
traj.append(str_to_xyz(xyz_str))
if not skip_traj:
traj.append(str_to_xyz(xyz_str))
i += 1
return traj

Expand Down
7 changes: 7 additions & 0 deletions arc/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ def test_parse_1d_scan_coords(self):
self.assertEqual(len(traj_3), 45)
self.assertEqual(traj_3[0]['symbols'], ('C', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'))

path_4 = os.path.join(ARC_PATH, 'arc', 'testing', 'rotor_scans', 'TS_scan.out')
traj_4 = parser.parse_1d_scan_coords(path_4)
self.assertEqual(len(traj_4), 8) # output file trimmed
self.assertEqual(traj_4[0]['symbols'], ('C', 'C', 'H', 'H', 'H', 'H', 'H', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
'C', 'C', 'C', 'C', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H',
'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H'))

def test_parse_t1(self):
"""Test T1 diagnostic parsing"""
path = os.path.join(ARC_PATH, 'arc', 'testing', 'sp', 'mehylamine_CCSD(T).out')
Expand Down

0 comments on commit b7fc76f

Please sign in to comment.