<commit_before>import mdtraj as md
import IPython

from mdtraj.html import TrajectoryView, enable_notebook
from IPython.html.widgets.widget_int import IntSliderWidget


def view_traj(traj, topology_file=None, stride=1, **kwargs):
    r"""Opens a trajectory viewer (from mdtraj).

    Parameters
    ----------

    traj : `mdtraj.Trajectory` or string
        mdtraj.Trajectory object or file name for MD trajectory
    topology_file : string (default=None)
        If traj is a file name, topology_file is the file name
        of the accompanying topology file (.pdb/.mol2/...)
    stride : int
       If traj is a file name, this is the number of frames
       to skip between two successive trajectory reads.
    **kwargs : optional arguments
       are passed to `mdtraj.html.TrajectoryView`
    """
    if isinstance(traj, str):
        traj = md.load(traj, top=topology_file, stride=stride)

    # ensure we're able to use TrajectoryView
    enable_notebook()
    
    if not 'colorBy' in kwargs:
        kwargs['colorBy'] = 'atom'

    widget = TrajectoryView(traj, **kwargs)
    IPython.display.display(widget)
    slider = IntSliderWidget(max=traj.n_frames - 1)

    def on_value_change(name, val):
        widget.frame = val
    slider.on_trait_change(on_value_change, 'value')
    IPython.display.display(slider)
    None<commit_msg>[viewer] moved imports into function<commit_after>import mdtraj as md
from mdtraj.html import TrajectoryView, enable_notebook


def view_traj(traj, topology_file=None, stride=1, **kwargs):
    r"""Opens a trajectory viewer (from mdtraj).

    Parameters
    ----------

    traj : `mdtraj.Trajectory` or string
        mdtraj.Trajectory object or file name for MD trajectory
    topology_file : string (default=None)
        If traj is a file name, topology_file is the file name
        of the accompanying topology file (.pdb/.mol2/...)
    stride : int
       If traj is a file name, this is the number of frames
       to skip between two successive trajectory reads.
    **kwargs : optional arguments
       are passed to `mdtraj.html.TrajectoryView`
    """
    import IPython
    from IPython.html.widgets.widget_int import IntSliderWidget

    if isinstance(traj, str):
        traj = md.load(traj, top=topology_file, stride=stride)

    # ensure we're able to use TrajectoryView
    enable_notebook()

    if not 'colorBy' in kwargs:
        kwargs['colorBy'] = 'atom'

    widget = TrajectoryView(traj, **kwargs)
    IPython.display.display(widget)
    slider = IntSliderWidget(max=traj.n_frames - 1)

    def on_value_change(name, val):
        widget.frame = val
    slider.on_trait_change(on_value_change, 'value')
    IPython.display.display(slider)
{'fraction_non_alphanumeric': 0.09231905465288036, 'fraction_numerical': 0.0022156573116691287, 'mean_word_length': 3.0798192771084336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3065025', 'n_tokens_mistral': 870, 'n_tokens_neox': 832, 'n_words': 250}