Skip to content

Commit

Permalink
Merge pull request #424 from ReactionMechanismGenerator/scan_fixes
Browse files Browse the repository at this point in the history
Scan fixes
  • Loading branch information
alongd committed Sep 26, 2020
2 parents 95d6d8f + 534ccdb commit 648d74f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
14 changes: 12 additions & 2 deletions arc/job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ def __init__(self,
self.xyz = check_xyz_dict(xyz)
self.radius = radius
self.directed_scan_type = directed_scan_type
self.directed_dihedrals = None
if directed_dihedrals is not None:
if isinstance(directed_dihedrals[0], list):
self.directed_dihedrals = [[float(d) for d in dd] for dd in directed_dihedrals]
else:
self.directed_dihedrals = [float(d) for d in directed_dihedrals] # it's a string in the restart dict

self.rotor_index = rotor_index
self.directed_scans = directed_scans
self.directed_dihedrals = [float(d) for d in directed_dihedrals] if directed_dihedrals is not None \
Expand Down Expand Up @@ -394,7 +401,9 @@ def as_dict(self) -> dict:
if self.occ is not None:
job_dict['occ'] = self.occ
if self.directed_dihedrals is not None:
job_dict['directed_dihedrals'] = ['{0:.2f}'.format(dihedral) for dihedral in self.directed_dihedrals]
job_dict['directed_dihedrals'] = ['{0:.2f}'.format(dihedral) if not isinstance(dihedral, list)
else ['{0:.2f}'.format(d) for d in dihedral]
for dihedral in self.directed_dihedrals]
if self.directed_scans is not None:
job_dict['directed_scans'] = self.directed_scans
if self.directed_scan_type is not None:
Expand Down Expand Up @@ -1290,7 +1299,8 @@ def run(self):
if self.fine:
logger.info(f'Running job {self.job_name} for {self.species_name} (fine opt)')
elif self.directed_dihedrals is not None and self.directed_scans is not None:
dihedrals = ['{0:.2f}'.format(dihedral) for dihedral in self.directed_dihedrals]
dihedrals = ['{0:.2f}'.format(dihedral) if not isinstance(dihedral, list)
else ['{0:.2f}'.format(d) for d in dihedral] for dihedral in self.directed_dihedrals]
logger.info(f'Running job {self.job_name} for {self.species_name} (pivots: {self.directed_scans}, '
f'dihedrals: {dihedrals})')
elif self.pivots:
Expand Down
9 changes: 9 additions & 0 deletions arc/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,14 @@ def plot_2d_rotor_scan(results, path=None, label='', cmap='Blues', resolution=90
zero_phi0, zero_phi1 = list(), list()
energies = np.zeros(shape=(phis0.size, phis1.size), dtype=np.float64)
keys_list = list(results['directed_scan'].keys())
e_min = None
for i, phi0 in enumerate(phis0):
for j, phi1 in enumerate(phis1):
key = tuple(f'{dihedral:.2f}' for dihedral in [phi0, phi1])
if key in keys_list:
energies[i, j] = results['directed_scan'][key]['energy']
if e_min is None or energies[i, j] < e_min:
e_min = energies[i, j]
else:
keys = list()
keys.append(tuple(f'{dihedral:.2f}' for dihedral in [360.0 - phi0, phi1]))
Expand All @@ -1159,6 +1162,8 @@ def plot_2d_rotor_scan(results, path=None, label='', cmap='Blues', resolution=90
keys.append(tuple(f'{dihedral:.2f}' for dihedral in [phi0 - 360.0, phi1]))
keys.append(tuple(f'{dihedral:.2f}' for dihedral in [phi0, phi1 - 360.0]))
keys.append(tuple(f'{dihedral:.2f}' for dihedral in [phi0 - 360.0, phi1 - 360.0]))
keys.append(tuple(f'{dihedral:.2f}' for dihedral in [phi0 - 360.0, phi1 + 360.0]))
keys.append(tuple(f'{dihedral:.2f}' for dihedral in [phi0 + 360.0, phi1 - 360.0]))
for key_ in keys:
if key_ in keys_list:
energies[i, j] = results['directed_scan'][key_]['energy']
Expand All @@ -1170,6 +1175,10 @@ def plot_2d_rotor_scan(results, path=None, label='', cmap='Blues', resolution=90
zero_phi0.append(phi0)
zero_phi1.append(phi1)

for i, phi0 in enumerate(phis0):
for j, phi1 in enumerate(phis1):
energies[i, j] -= e_min

fig = plt.figure(num=None, figsize=(12, 8), dpi=resolution, facecolor='w', edgecolor='k')

plt.contourf(phis0, phis1, energies, 20, cmap=cmap)
Expand Down
4 changes: 3 additions & 1 deletion arc/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def schedule_jobs(self):
and self.job_dict[label]['scan'][job_name].job_id not in self.servers_jobs_ids:
job = self.job_dict[label]['scan'][job_name]
successful_server_termination = self.end_job(job=job, label=label, job_name=job_name)
if successful_server_termination:
if successful_server_termination and job.directed_scans is None:
self.check_scan_job(label=label, job=job)
self.timer = False
break
Expand Down Expand Up @@ -3008,6 +3008,8 @@ def troubleshoot_ess(self,
shift=shift,
directed_dihedrals=job.directed_dihedrals,
directed_scans=job.directed_scans,
directed_scan_type=job.directed_scan_type,
rotor_index = job.rotor_index,
cpu_cores=cpu_cores,
)
self.save_restart_dict()
Expand Down
2 changes: 2 additions & 0 deletions arc/species/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def calculate_dihedral_angle(coords: Union[list, tuple, dict],
raise TypeError(f'coords must be a list or a tuple, got\n{coords}\nwhich is a {type(coords)}')
if index not in [0, 1]:
raise VectorsError(f'index must be either 0 or 1, got {index}')
if torsion is None:
raise VectorsError(f'torsion cannot be None')
if len(torsion) != 4:
raise VectorsError(f'torsion atom list must be of length four, got {len(torsion)}')
if len(set(torsion)) < 4:
Expand Down

0 comments on commit 648d74f

Please sign in to comment.