Beispiel #1
0
def test_coordinates_meta():
    from mdtraj.testing import get_fn
    fn, tn = [get_fn('frame0.pdb'),] * 2
    trajs = [pt.load(fn, tn), md.load(fn, top=tn), pmd.load_file(tn, fn)]

    N_FRAMES = trajs[0].n_frames

    from MDAnalysis import Universe
    u = Universe(tn, fn)
    trajs.append(Universe(tn, fn))

    views = [nv.show_pytraj(trajs[0]), nv.show_mdtraj(trajs[1]), nv.show_parmed(trajs[2])]
    views.append(nv.show_mdanalysis(trajs[3]))

    for index, (view, traj) in enumerate(zip(views, trajs)):
        view.frame = 3
        
        nt.assert_equal(view.trajlist[0].n_frames, N_FRAMES)
        nt.assert_equal(len(view.trajlist[0].get_coordinates_dict().keys()), N_FRAMES)

        if index in [0, 1]:
            # pytraj, mdtraj
            if index == 0:
                aa_eq(view.coordinates[0], traj.xyz[3], decimal=4)
            else:
                aa_eq(view.coordinates[0],10*traj.xyz[3], decimal=4)
            view.coordinates = traj.xyz[2]
Beispiel #2
0
def view_nucl(*args,gui=False):
    nuclMD=mda.Universe(*args)
    #prot = nuclMD.select_atoms("protein")
    show=nv.show_mdanalysis(nuclMD,gui=gui)
    show.representations = [
    {"type": "cartoon", "params": {
        "sele": ":A :E", "color": 0x020AED,"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":B :F", "color": "green","aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":C :G", "color": 0xE0F705,"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":D :H", "color": 0xCE0000,"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": "nucleic", "color": "grey","aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "base", "params": {
        "sele": "nucleic", "color": "grey",
    }},
    ]
    show.camera = 'orthographic'
    return show
Beispiel #3
0
    def affinity_propagation(self, preference=-6.0):
        '''Performing Affinity Propagation clustering of AMOEBA-run Trp-Cage folding trajectory:-

           Default parameter values from MDAnalysis - damping=0.9, max_iter=500, convergence_iter=50
           Preference reduced to -10 from -1 to reflect local homogenity within the trajectory'''

        print("Performing Affinity Propagation with input preference = %f" %
              preference)
        clust = encore.cluster(self.univ_cut,
                               method=encore.AffinityPropagation(
                                   preference=preference, verbose=True))
        centroids = [cluster.centroid * self.ncut for cluster in clust]
        ids = [cluster.id for cluster in clust]

        print(
            "Clustering complete! - %d clusters formed with average size = %d frames"
            % (len(ids), np.average([cluster.size for cluster in clust])))

        coords_centroids = np.zeros((len(centroids), 304, 3), dtype=np.float64)
        coords_centroids[:, :, :] = [
            self.coords_protein[centroids[i], :, :]
            for i in np.arange(0, len(centroids))
        ]

        protein = self.univ2.select_atoms("protein")

        univ_centroids = mda.Merge(protein)
        univ_centroids.load_new(coords_centroids, format=MemoryReader)

        ref = mda.Universe("folded.pdb")

        nframes = len(univ_centroids.trajectory)

        alignment = align.AlignTraj(univ_centroids,
                                    ref,
                                    select='protein and name CA',
                                    in_memory=True,
                                    verbose=True)
        alignment.run()

        idvscenter = {
            'Cluster ID': [ids[i] for i in range(0, len(ids))],
            'Centroid Time (ps)':
            [centroids[i] * 10 for i in range(0, len(centroids))],
            'Cluster Size': [cluster.size for cluster in clust]
        }

        idtable = pd.DataFrame(data=idvscenter)

        #Visualisation representation set for Trp-Cage - will expand to general proteins later
        view = nglview.show_mdanalysis(univ_centroids)
        view.add_cartoon(selection="protein")
        view.add_licorice('TRP')
        view.add_licorice('PRO')
        view.center(selection='protein', duration=nframes)
        view.player.parameters = dict(frame=True)
        return view, idtable, univ_centroids
Beispiel #4
0
def view_nucl(*args,gui=False,chconv={},selection='all',color=False):
    ch_conv={'A':'A','B':'B','C':'C','D':'D','E':'E','F':'F','G':'G','H':'H','I':'I','J':'J'}
    ch_conv.update(chconv)
    if(isinstance(args[0],mda.Universe)):
        nuclMD=args[0]
    else:
        nuclMD=mda.Universe(*args)
    #prot = nuclMD.select_atoms("protein")
    sel=nuclMD.select_atoms(selection)
    show=nv.show_mdanalysis(sel,gui=gui)
    if(color==False):
        color={'A':0x020AED,'B':"green",'C':0xE0F705,'D':0xCE0000,'DNA':"grey"}
    show.representations = [
    {"type": "cartoon", "params": {
        "sele": ":%s"%(ch_conv['A']), "color": color['A'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":%s"%(ch_conv['B']), "color": color['B'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":%s"%(ch_conv['C']), "color": color['C'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":%s"%(ch_conv['D']), "color": color['D'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":%s"%(ch_conv['E']), "color": color['A'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":%s "%(ch_conv['F']), "color": color['B'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":%s"%(ch_conv['G']), "color": color['C'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": ":%s "%(ch_conv['H']), "color": color['D'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "cartoon", "params": {
        "sele": "nucleic", "color": color['DNA'],"aspectRatio":2, "radius":1.5,"radiusSegments":1,"capped":1
    }},
    {"type": "base", "params": {
        "sele": "nucleic", "color": color['DNA'],
    }},
    ]
    show.camera = 'orthographic'
    return show
Beispiel #5
0
def test_coordinates_meta():
    from mdtraj.testing import get_fn
    fn, tn = [get_fn('frame0.pdb'),] * 2
    trajs = [pt.load(fn, tn), md.load(fn, top=tn), pmd.load_file(tn, fn)]

    N_FRAMES = trajs[0].n_frames

    from MDAnalysis import Universe
    u = Universe(tn, fn)
    trajs.append(Universe(tn, fn))

    views = [nv.show_pytraj(trajs[0]), nv.show_mdtraj(trajs[1]), nv.show_parmed(trajs[2])]
    views.append(nv.show_mdanalysis(trajs[3]))

    for index, (view, traj) in enumerate(zip(views, trajs)):
        view.frame = 3
        
        nt.assert_equal(view._trajlist[0].n_frames, N_FRAMES)
Beispiel #6
0
def _show_trajectory(pdb_path, dcd_path):
    """
    Show the MD trajectory that is the bases for the dynophore.

    Parameters
    ----------
    dcd_path : None or str or pathlib.Path
        Optionally: Path to DCD file (trajectory).

    Returns
    -------
    nglview.widget.NGLWidget
        Visualization with the NGL Viewer.
    """

    md_universe = mda.Universe(str(pdb_path), str(dcd_path))
    view = nv.show_mdanalysis(md_universe)
    return view
def test_coordinates_meta():
    from mdtraj.testing import get_fn
    fn, tn = [get_fn('frame0.pdb'),] * 2
    trajs = [pt.load(fn, tn), md.load(fn, top=tn), pmd.load_file(tn, fn)]

    N_FRAMES = trajs[0].n_frames

    from MDAnalysis import Universe
    u = Universe(tn, fn)
    trajs.append(Universe(tn, fn))

    views = [nv.show_pytraj(trajs[0]), nv.show_mdtraj(trajs[1]), nv.show_parmed(trajs[2])]
    views.append(nv.show_mdanalysis(trajs[3]))

    for index, (view, traj) in enumerate(zip(views, trajs)):
        view.frame = 3
        
        nt.assert_equal(view._trajlist[0].n_frames, N_FRAMES)
Beispiel #8
0
def draw_fragments(*fragments):
    """Draw many fragments in a Jupyter notebook

    Will make molecules whole and choose the image of each
    which makes them as close as possible

    Parameters
    ----------
    fragments : list of AtomGroup
      the thing to draw
    """
    import nglview as nv

    u, _ = _copy_universe(sum(fragments))

    # gather network into same image
    g = _gather_network(u.atoms.fragments)

    v = nv.show_mdanalysis(sum(g.nodes()))

    return v
Beispiel #9
0
def _show_trajectory(pdb_path, dcd_path):
    """
    Show the MD trajectory that is the bases for the dynophore.

    Parameters
    ----------
    pdb_path : str or pathlib.Path
        Path to PDB file (structure/topology)
    dcd_path : None or str or pathlib.Path
        Optionally: Path to DCD file (trajectory).
    frame_range : list of in
        Select frame range to display (list of two integers). If None (default), use all points.

    Returns
    -------
    nglview.widget.NGLWidget
        Visualization with the NGL Viewer.
    """

    md_universe = mda.Universe(str(pdb_path), str(dcd_path))
    view = nv.show_mdanalysis(md_universe)
    return view
Beispiel #10
0
def to_nglview_NGLWidget(item,
                         atom_indices='all',
                         structure_indices='all',
                         check=True):

    if check:

        digest_item(item, 'mdanalysis.Universe')
        atom_indices = digest_atom_indices(atom_indices)
        structure_indices = digest_structure_indices(structure_indices)

    from . import extract
    from nglview import show_mdanalysis

    tmp_item = extract(item,
                       atom_indices=atom_indices,
                       structure_indices=structure_indices,
                       copy_if_all=False,
                       check=False)
    tmp_item = show_mdanalysis(tmp_item)

    return tmp_item
Beispiel #11
0
    def visualise_structures(self, traj, protein_ref):
        '''Visualisation of a set of structures using NGLView:-
            protein_ref - Reference structure used to align the input structures based 
            on rotational and translational matricies'''

        ref = mda.Universe(protein_ref)

        nframes = len(traj.trajectory)

        alignment = align.AlignTraj(traj,
                                    ref,
                                    select='protein and name CA',
                                    in_memory=True,
                                    verbose=True)
        alignment.run()

        #Visualisation representation set for Trp-Cage - will expand to general proteins later
        view = nglview.show_mdanalysis(traj)
        view.add_cartoon(selection="protein")
        view.add_licorice('TRP')
        view.add_licorice('PRO')
        view.center(selection='protein', duration=nframes)
        view
def test_show_MDAnalysis():
    from MDAnalysis import Universe
    tn, fn = nv.datafiles.PDB, nv.datafiles.PDB
    u = Universe(fn, tn)
    view = nv.show_mdanalysis(u)
Beispiel #13
0
def test_show_MDAnalysis():
    from MDAnalysis import Universe
    tn, fn = nv.datafiles.PDB, nv.datafiles.PDB
    u = Universe(fn, tn)
    view = nv.show_mdanalysis(u)
Beispiel #14
0
# %%
import MDAnalysis as mda
import nglview as nv
from funcs import unwrap_traj, add_elements_to_universe
# %%
u = mda.Universe('pack.lmps', 'traj.dcd', topology_format='DATA')
add_elements_to_universe(u, 'pack.lmps')
unwrap_traj(u)
nv.show_mdanalysis(u)