Skip to content

Commit

Permalink
Improve interact functions in logparser
Browse files Browse the repository at this point in the history
Improve the docstrings. Add a `continuous_update` option to avoid rendering intermediate frames when sliding the bar.
  • Loading branch information
xiaoruiDong committed Sep 7, 2023
1 parent 947db70 commit 5a0ddd1
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions rdmc/external/logparser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,21 @@ def plot_opt_convergence(self,
df.loc[[highlight_index]].plot(marker='o', ax=ax, legend=False)
return ax

def interact_opt(self, sanitize: bool = True, backend: str = 'openbabel'):
def interact_opt(self,
sanitize: bool = True,
backend: str = 'openbabel',
continuous_update: bool = False,
) -> interact:
"""
Create a IPython interactive widget to investigate the optimization convergence.
Args:
sanitize (bool, optional): Whether to sanitize the molecule. Defaults to True.
backend (str): The backend engine for parsing XYZ. Defaults to ``'openbabel'``.
continuous_update (bool): Whether to update the widget continuously. Defaults to ``False``.
Returns:
interact
"""
mol = self.get_mol(converged=False, sanitize=sanitize, backend=backend)
xyzs = self.get_xyzs(converged=False)
Expand All @@ -696,7 +704,7 @@ def visual(idx):
)
if self.opt_convergence.shape[0] - 1 < self.num_all_geoms:
print('Warning: The last geometry doesn\'t has convergence information due to error.')
return interact(visual, idx=slider)
return interact(visual, idx=slider, continuous_update=continuous_update)

###################################################################
#### ####
Expand Down Expand Up @@ -802,14 +810,20 @@ def view_freq(self,
mode_idx: int = 0,
frames: int = 10,
amplitude: float = 1.0,
*args, **kwargs):
*args,
**kwargs,
) -> interact:
"""
Create a Py3DMol viewer for the frequency mode.
mode_idx (int): The index of the frequency mode to display.
frames (int): The number of frames of the animation. The larger the value,
the slower the change of the animation.
amplitude (float): The magnitude of the mode change.
Args:
mode_idx (int): The index of the frequency mode to display. Defaults to 0.
frames (int): The number of frames of the animation. The larger the value,
the slower the change of the animation. Defaults to 10.
amplitude (float): The magnitude of the mode change. Defaults to 1.0.
Returns:
interact
"""
xyz = self.get_xyzs(converged=True)[0]
lines = xyz.splitlines()
Expand Down Expand Up @@ -973,13 +987,20 @@ def plot_irc_energies(self,
def interact_irc(self,
sanitize: bool = False,
converged: bool = True,
backend: str = 'openbabel'):
backend: str = 'openbabel',
continuous_update: bool = False,
) -> interact:
"""
Create a IPython interactive widget to investigate the IRC results.
Args:
sanitize (bool): Whether to sanitize the molecule. Defaults to ``False``.
converged (bool): Whether to only embed converged conformers to the mol. Defaults to ``True``.
backend (str): The backend engine for parsing XYZ. Defaults to ``'openbabel'``.
continuous_update (bool): Whether to update the widget continuously. Defaults to ``False``.
Returns:
interact
"""
mol = self._process_irc_mol(sanitize=sanitize, converged=converged, backend=backend)
sdfs = [mol.ToMolBlock(confId=i) for i in range(mol.GetNumConformers())]
Expand Down Expand Up @@ -1009,7 +1030,7 @@ def visual(idx):
description='Index',
)

return interact(visual, idx=slider)
return interact(visual, idx=slider, continuous_update=continuous_update)

###################################################################
#### ####
Expand Down Expand Up @@ -1133,7 +1154,9 @@ def interact_scan(self,
align_scan: bool = True,
align_frag_idx: int = 1,
backend: str = 'openbabel',
**kwargs):
continuous_update: bool = False,
**kwargs,
) -> interact:
"""
Create a IPython interactive widget to investigate the scan results.
Expand All @@ -1144,6 +1167,10 @@ def interact_scan(self,
align_frag_idx (int): Value should be either 1 or 2. Assign which of the part to be
aligned. Defaults to ``1``.
backend (str): The backend engine for parsing XYZ. Defaults to ``'openbabel'``.
continuous_update (bool): Whether to update the widget continuously. Defaults to ``False``.
Returns:
interact
"""
mol = self._process_scan_mol(align_scan=align_scan,
align_frag_idx=align_frag_idx,
Expand Down Expand Up @@ -1182,7 +1209,7 @@ def visual(idx):
description='Index',
)

return interact(visual, idx=slider)
return interact(visual, idx=slider, continuous_update=continuous_update)

def plot_scan_energies(self,
converged: bool = True,
Expand Down

0 comments on commit 5a0ddd1

Please sign in to comment.