Пример #1
0
def test_animate(file_3frames):
    m = molecule.load("pdb", file_3frames)
    assert molecule.numframes(m) == 3
    molecule.set_frame(m, 0)

    with pytest.raises(ValueError):
        animate.activate(-3000, True)

    animate.activate(molid=m, active=False)
    assert not animate.is_active(m)

    animate.activate(m, True)
    assert animate.is_active(m)

    animate.goto(0)
    display.update()
    assert molecule.get_frame(m) == 0

    animate.goto(1)
    display.update()
    assert molecule.get_frame(m) == 1

    animate.forward()
    animate.reverse()
    animate.next()
    animate.prev()
    animate.pause()

    molecule.delete(m)
Пример #2
0
def test_animate(file_3frames):
    m = molecule.load("pdb", file_3frames)
    assert molecule.numframes(m) == 3
    molecule.set_frame(m, 0)

    with pytest.raises(ValueError):
        animate.activate(-3000, True)

    animate.activate(molid=m, active=False)
    assert not animate.is_active(m)

    animate.activate(m, True)
    assert animate.is_active(m)

    animate.goto(0)
    display.update()
    assert molecule.get_frame(m) == 0

    animate.goto(1)
    display.update()
    assert molecule.get_frame(m) == 1

    animate.forward()
    animate.reverse()
    animate.next()
    animate.prev()
    animate.pause()

    molecule.delete(m)
Пример #3
0
def generate_rotation_movie(molecule,
                            filename,
                            save_dir='.',
                            frame=0,
                            angle=360,
                            division=1.0,
                            renderer='Tachyon',
                            render_ext='dat'):
    """Function for generating movies where a static molecule frame is
    rotated through an angle. Individual files for each subrotation
    are generated, which can then be processed and combined into a
    movie file.

    Parameters
    ----------
    molecule : VMDMolecule
        Molecule for which the movie is made.
    filename : str
        The basename of the individual files for each subrotation
    save_dir : str (default='.')
        The directory in which generated files will be saved.
    frame : int (default=0)
        The trajectory frame that is rotated about.
    angle : float (default=360.0)
        The angle through which the molecule is rotated through.
    division : float (default=1.0)
        The angular (degree) for each subrotation.
    renderer : str (default='Tachyon')
        Program for rendering individual images. Must be a valid
        rendering program bundled with VMD. For available rendering
        programs, see:

            https://www.ks.uiuc.edu/Research/vmd/vmd-1.7.1/ug/node89.html
    render_ext : str (default='dat')
        filename extension for indivudally rendered files.
    """

    check = dir_check(save_dir)
    if not check:
        return None

    print("generating rotation movie...")
    if angle % division != 0:
        raise RuntimeError("Angle must be evenly divisble by dvision")
    else:
        if frame == -1:
            frame = mol.numframes(molecule.molid) - 1
        mol.set_frame(molecule.molid, frame)
        display.update()
        sub_rotations = int(angle / division)
        current_angle = 0.0
        for i in range(0, sub_rotations):
            render.render(
                renderer, save_dir + '/' + filename +
                '{:0>9}.{}'.format(int(i), render_ext))
            trans.rotate_scene('y', division)
            display.update()
            current_angle += division
Пример #4
0
 def self_align(self):
     """Method for align trajectory frames to the initial frame
     to prevent the molecule from drifting out of focus during the
     simulation visualiation. This method can only be called after
     trajectory frames have been loaded into the VMDMolecule.
     """
     print("Self aligning molecule...")
     mol.set_frame(self.molid, 0)
     base_selection = atomsel('all', frame=0)
     current_selection = atomsel('all')
     for i in range(mol.numframes(self.molid)):
         mol.set_frame(self.molid, i)
         current_selection.update()
         trans_matrix = current_selection.fit(base_selection)
         current_selection.move(trans_matrix)
         display.update()
Пример #5
0
def init_display(display_options, axes_options):
    """Function for initializing VMD scene options

    Parameters
    ----------
    display_options : dict
        scene/display options for VMD. These are specified as key-value
        pairs for each attribute in the VMD display options list. For
        this complete list, see the following:

            https://www.ks.uiuc.edu/Research/vmd/current/ug/node126.html

    """

    display.set(**display_options)
    if 'set_location' in axes_options.keys():
        axes.set_location(axes_options['set_location'])
    display.update()
Пример #6
0
def test_update():

    display.update_off()
    display.update()
    display.update_on()
Пример #7
0
def test_update():

    display.update_off()
    display.update()
    display.update_on()
Пример #8
0
def generate_trajectory_movie(molecule,
                              filename,
                              save_dir='.',
                              start=0,
                              stop=-1,
                              step=1,
                              smoothing=0,
                              renderer='Tachyon',
                              render_ext='dat'):
    """Function for generating movies of molecular trajectories

    Parameters
    ----------
    molecule : VMDMolecule
        Molecule for which the movie is made.
    filename : str
        The basename of the individual files for each subrotation
    save_dir : str (default='.')
        The directory in which generated files will be saved.
    start : int (default=0)
        The starting frame
    stop : float (default=360.0)
        The ending frame
    step : float (default=1.0)
        The the step stride of the loaded frames
    smoothing : int (default=0)
        Size of smoothing window in frames to be applied to all
        representations of the VMDMolecule
    renderer : str (default='Tachyon')
        Program for rendering individual images. Must be a valid
        rendering program bundled with VMD. For available rendering
        programs, see:

            https://www.ks.uiuc.edu/Research/vmd/vmd-1.7.1/ug/node89.html

    render_ext : str (default='dat')
        filename extension for indivudally rendered files.
    """

    # Perform checks
    check = dir_check(save_dir)
    if not check:
        return None

    if stop < 0:
        if stop != -1:
            raise ValueError("negative values for 'stop' can only be -1, "
                             "in which case the stop frame is the final "
                             "loaded frame.")
    num_loaded_frames = mol.numframes(molecule.molid)
    # explicitly switch 'stop' to the last frame index
    if stop == -1:
        stop = num_loaded_frames - 1

    if smoothing > 0:
        reps = molrep.num(molecule.molid)
        for i in range(reps):
            molrep.set_smoothing(molecule.molid, i, smoothing)

    print("generating '{}' trajectory movie...".format(filename))
    frames = np.arange(start, stop, step)
    mol.set_frame(molecule.molid, start)
    current_frame = start
    display.update()
    for i in frames:
        mol.set_frame(molecule.molid, i)
        display.update()
        render.render(
            renderer, save_dir + '/' + filename +
            '_{:0>9}.{}'.format(int(i), render_ext))