Welcome to NGLView’s documentation!¶
Please wait ...
Contents:
-
class
nglview.
ASEStructure
(ase_atoms, ext='pdb', params={})[source]¶ Bases:
nglview.base_adaptor.Structure
-
class
nglview.
ASETrajectory
(ase_traj)[source]¶ Bases:
nglview.base_adaptor.Trajectory
,nglview.base_adaptor.Structure
asetraj adaptor.
>>> import nglview as nv >>> from ase.io.trajectory import Trajectory >>> traj = Trajectory(nv.datafiles.ASE_Traj) >>> t = nv.ASETrajectory(traj) >>> w = nv.NGLWidget(t) >>> w.add_spacefill() >>> w
-
property
n_frames
¶
-
property
-
class
nglview.
BiopythonStructure
(entity, ext='pdb', params={})[source]¶ Bases:
nglview.base_adaptor.Structure
-
class
nglview.
HTMDTrajectory
(mol)[source]¶ Bases:
nglview.base_adaptor.Trajectory
HTMD adaptor.
Takes a Molecule object.
>>> import nglview as nv >>> from htmd import Molecule >>> mol = Molecule(nv.datafiles.PDB) >>> t = nv.HTMDTrajectory(mol) >>> w = nv.NGLWidget(t) >>> w
-
property
n_frames
¶
-
property
-
class
nglview.
IOTBXStructure
(obj, ext='pdb', params={})[source]¶ Bases:
nglview.base_adaptor.Structure
-
class
nglview.
MDAnalysisTrajectory
(atomgroup)[source]¶ Bases:
nglview.base_adaptor.Trajectory
,nglview.base_adaptor.Structure
MDAnalysis adaptor.
Can take either a Universe or AtomGroup.
>>> import nglview as nv >>> import MDAnalysis as mda >>> u = mda.Universe(nv.datafiles.GRO, nv.datafiles.XTC) >>> prot = u.select_atoms('protein') >>> t = nv.MDAnalysisTrajectory(prot) >>> w = nv.NGLWidget(t) >>> w
-
property
n_frames
¶
-
property
-
class
nglview.
MDTrajTrajectory
(trajectory)[source]¶ Bases:
nglview.base_adaptor.Trajectory
,nglview.base_adaptor.Structure
mdtraj adaptor.
>>> import nglview as nv >>> import mdtraj as md >>> traj = md.load(nv.datafiles.XTC, nv.datafiles.GRO) >>> t = MDTrajTrajectory(traj) >>> w = nv.NGLWidget(t) >>> w
-
property
n_frames
¶
-
property
-
class
nglview.
NGLWidget
(*args, **kwargs)[source]¶ Bases:
ipywidgets.widgets.domwidget.DOMWidget
-
add_component
(filename, **kwargs)[source]¶ add component from file/trajectory/struture
filename : str or Trajectory or Structure or their derived class or url **kwargs : additional arguments, optional
>>> import nglview >>> view = nglview.NGLWidget() >>> view ... filename = 'somefile.ccp4' ... view.add_component(filename)
If you want to load binary file such as density data, mmtf format, it is faster to load file from current or subfolder.
-
add_pdbid
(pdbid, **kwargs)[source]¶ add new Structure view by fetching pdb id from rcsb
>>> import nglview >>> view = nglview.NGLWidget() >>> c = view.add_pdbid('1tsu') >>> # which is equal to >>> # view.add_component('rcsb://1tsu.pdb')
-
add_representation
(repr_type, selection='all', **kwargs)[source]¶ Add structure representation (cartoon, licorice, …) for given atom selection.
- repr_typestr
type of representation. Please see http://nglviewer.org/ngl/ for further info.
- selectionstr or 1D array (atom indices) or any iterator that returns integer, default ‘all’
atom selection
**kwargs: additional arguments for representation
>>> import nglview as nv >>> import pytraj >>> t = pytraj.datafiles.load_tz2() >>> w = nv.show_pytraj(t) >>> w.add_representation('cartoon', selection='protein', color='blue') >>> w.add_representation('licorice', selection=[3, 8, 9, 11], color='red') >>> w
User can also use shortcut
>>> selection = 'protein' >>> w.add_cartoon(selection) # w.add_representation('cartoon', selection)
-
add_structure
(structure, **kwargs)[source]¶ add structure to view
structure : nglview.Structure object
>>> view.add_trajectory(traj0) ... view.add_trajectory(traj1) ... # then add Structure ... view.add_structure(s)
nglview.NGLWidget.add_component
-
add_trajectory
(trajectory, **kwargs)[source]¶ add new trajectory to view
- trajectory: nglview.Trajectory or its derived class or
a supported object, eg pytraj.Trajectory-like, mdtraj.Trajectory, MDAnalysis objects, etc
nglview.NGLWidget.add_component
>>> import nglview as nv, pytraj as pt >>> traj = pt.load(nv.datafiles.TRR, nv.datafiles.PDB) >>> view = nv.show_pytraj(traj) >>> # show view first >>> view >>> # add new Trajectory >>> traj2 = pt.datafiles.load_tz2() >>> c = view.add_trajectory(traj2)
-
background
¶ A trait for unicode strings.
-
property
camera
¶
-
center
(selection='*', duration=0, component=0, **kwargs)[source]¶ center view for given atom selection
view.center_view(selection=’1-4’)
-
clear_representations
(component=0)[source]¶ clear all representations for given component
- componentint, default 0 (first model)
You need to keep track how many components you added.
-
color_by
(color_scheme, component=0)[source]¶ update color for all representations of given component
Unstable feature
color_scheme : str component : int, default 0
component index
>>> import nglview >>> view = nglview.demo() >>> # component 0 >>> view.color_by('atomindex')
>>> # component 1 >>> view.color_by('atomindex', component=1)
-
display
(gui=False, style='ngl')[source]¶ - guibool
If True: turn on GUI
- stylestr, {‘ngl’, ‘ipywidgets}, default ‘ngl’
GUI style (with gui=True)
-
download_image
(filename='screenshot.png', factor=4, antialias=True, trim=False, transparent=False)[source]¶ render and download scene at current frame
filename : str, default ‘screenshot.png’ factor : int, default 4
quality of the image, higher is better
antialias : bool, default True trim : bool, default False transparent : bool, default False
-
frame
¶ An int trait.
-
gui_style
¶ An enum of strings where the case should be ignored.
-
loaded
¶ A boolean (True, False) trait.
-
max_frame
¶ An int trait.
-
n_components
¶ An int trait.
-
on_loaded
¶
-
property
parameters
¶
-
picked
¶ An instance of a Python dict.
-
remove_component
(c)[source]¶ remove component by its uuid. If isinstance(c, ComponentViewer), c won’t be associated with self
c : Union[int, ComponentViewer]
>>> c0 = view.add_trajectory(traj0) ... c1 = view.add_trajectory(traj1) ... c2 = view.add_struture(structure) ... # remove last component ... view.remove_component(c2) ... assert c2._view is None
-
render_image
(frame=None, factor=4, antialias=True, trim=False, transparent=False)[source]¶ render and get image as ipywidgets.widget_image.Image
- frameint or None, default None
if None, use current frame if specified, use this number.
- factorint, default 4
quality of the image, higher is better
antialias : bool, default True trim : bool, default False transparent : bool, default False
# tell NGL to render send image data to notebook. view.render_image()
# make sure to call get_image method view.get_image()
You need to call render_image and get_image in different notebook’s Cells
-
property
representations
¶
-
set_coordinates
(arr_dict, movie_making=False, render_params=None)[source]¶ Used for update coordinates of a given trajectory >>> # arr: numpy array, ndim=2 >>> # update coordinates of 1st trajectory >>> view.set_coordinates({0: arr})# doctest: +SKIP
-
-
class
nglview.
ParmEdTrajectory
(trajectory)[source]¶ Bases:
nglview.base_adaptor.Trajectory
,nglview.adaptor.ParmEdStructure
ParmEd adaptor.
-
property
n_frames
¶
-
property
-
class
nglview.
ProdyTrajectory
(obj)[source]¶ Bases:
nglview.base_adaptor.Trajectory
,nglview.adaptor.ProdyStructure
-
property
n_frames
¶
-
property
-
class
nglview.
PyTrajTrajectory
(trajectory)[source]¶ Bases:
nglview.base_adaptor.Trajectory
,nglview.base_adaptor.Structure
PyTraj adaptor.
>>> import nglview as nv >>> import pytraj as pt >>> traj = pt.load(nv.datafiles.TRR, nv.datafiles.PDB) >>> t = nv.PyTrajTrajectory(traj) >>> w = nv.NGLWidget(t) >>> w
-
property
n_frames
¶
-
property
-
class
nglview.
RdkitStructure
(rdkit_mol, ext='pdb', conf_id=- 1)[source]¶ Bases:
nglview.base_adaptor.Structure
-
class
nglview.
RosettaStructure
(pose, ext='pdb', params={})[source]¶ Bases:
nglview.base_adaptor.Structure
-
class
nglview.
SchrodingerStructure
(structure, ext='pdb')[source]¶ Bases:
nglview.base_adaptor.Structure
Only read first structure
-
class
nglview.
SchrodingerTrajectory
(structure, traj)[source]¶ Bases:
nglview.adaptor.SchrodingerStructure
,nglview.base_adaptor.Trajectory
Require parmed package.
-
property
n_frames
¶
-
property
-
class
nglview.
SimpletrajTrajectory
(path, structure_path)[source]¶ Bases:
nglview.base_adaptor.Trajectory
,nglview.base_adaptor.Structure
simpletraj adaptor.
>>> import nglview as nv >>> t = nv.SimpletrajTrajectory(nv.datafiles.XTC, nv.datafiles.GRO) >>> w = nv.NGLWidget(t) >>> w
-
property
n_frames
¶
-
property
-
class
nglview.
TextStructure
(text, ext='pdb', params={})[source]¶ Bases:
nglview.base_adaptor.Structure
-
nglview.
show_ase
(ase_atoms, **kwargs)[source]¶ >>> import nglview as nv >>> from ase import Atom, Atoms >>> dimer = Atoms([Atom('X', (0, 0, 0)), ... Atom('X', (0, 0, 1))]) >>> dimer.set_positions([(1, 2, 3), (4, 5, 6.2)]) >>> w = nv.show_ase(dimer) >>> w
-
nglview.
show_asetraj
(ase_traj, **kwargs)[source]¶ Show ase trajectory and structure file.
>>> import nglview as nv >>> from ase.io.trajectory import Trajectory >>> traj = Trajectory(nv.datafiles.ASE_Traj) >>> view = nv.show_asetraj(traj) >>> view.add_spacefill() >>> view
-
nglview.
show_biopython
(entity, **kwargs)[source]¶ Show NGL widget with Biopython structural entity.
Takes a Structure, Model, Chain, Residue or Atom from Bio.PDB as its data input.
>>> import nglview as nv ... from Bio.PDB import PDBParser ... parser = PDBParser() ... structure = parser.get_structure("protein", "protein.pdb") ... w = nv.show_biopython(structure[0]["A"]) ... w
-
nglview.
show_file
(path, **kwargs)[source]¶ Show any supported file format (e.g: .gro, .dx, …)
>>> import nglview as nv ... w = nv.show_file('my.dx') ... w
-
nglview.
show_htmd
(mol, **kwargs)[source]¶ Show NGL widget with HTMD Molecule.
Takes a Molecule object as its data input.
>>> import nglview as nv ... from htmd import Molecule ... mol = Molecule(nv.datafiles.PDB) ... mol.filter('protein') ... w = nv.show_htmd(mol) ... w
-
nglview.
show_iodata
(obj, **kwargs)[source]¶ Show iodata’s IOData (require ase package).
>>> import nglview as nv >>> from iodata import IOData ... obj = IOData.from_file('what.xyz') ... view = nv.show_iodata(obj) ... view
-
nglview.
show_iotbx
(mol, **kwargs)[source]¶ >>> import iotbx.pdb ... x = iotbx.pdb.hierarchy.input('file.pdb') ... mol = x.construct_hierarchy() ... view = nglview.show_iotbx(hi) ... view
-
nglview.
show_mdanalysis
(atomgroup, **kwargs)[source]¶ Show NGL widget with MDAnalysis AtomGroup.
Can take either a Universe or AtomGroup as its data input.
>>> import nglview as nv ... import MDAnalysis as mda ... u = mda.Universe(nv.datafiles.GRO, nv.datafiles.XTC) ... prot = u.select_atoms('protein') ... w = nv.show_mdanalysis(prot) ... w
-
nglview.
show_mdtraj
(mdtraj_trajectory, **kwargs)[source]¶ Show mdtraj trajectory.
>>> import nglview as nv ... import mdtraj as md ... t = md.load(nv.datafiles.XTC, top=nv.datafiles.GRO) ... w = nv.show_mdtraj(t) ... w
-
nglview.
show_openbabel
(obj, **kwargs)[source]¶ Show openbabel’s Omol
>>> import nglview >>> mol = openbabel.OBMol() ... obConversion = openbabel.OBConversion() ... obConversion.SetInFormat('xyz') ... obConversion.ReadFile(mol, 'what.xyz') ... nglview.show_openbabel(mol)
-
nglview.
show_parmed
(parmed_structure, **kwargs)[source]¶ Show pytraj trajectory.
>>> import nglview as nv >>> import parmed as pmd >>> t = pmd.load_file(nv.datafiles.PDB) >>> w = nv.show_parmed(t) >>> w
-
nglview.
show_pdbid
(pdbid, **kwargs)[source]¶ Show PDB entry.
>>> import nglview as nv >>> w = nv.show_pdbid("3pqr") >>> w
-
nglview.
show_prody
(obj, **kwargs)[source]¶ >>> import nglview as nv ... import prody ... structure = prody.parsePDB('what.pdb') ... ensemble = prody.parseDCD('what.dcd') ... ensemble.setAtoms(structure) ... nv.show_prody(ensemble) ... # nv.show_prody(structure)
-
nglview.
show_psi4
(obj, **kwargs)[source]¶ Show Psi4’s Molecule.
>>> import nglview as nv >>> import psi4 ... mol = psi4.geometry('xyz content here') ... view = nv.show_psi4(mol) ... view
-
nglview.
show_pymatgen
(struct, **kwargs)[source]¶ Require ase package.
>>> import nglview as nv ... import pymatgen as mg ... lattice = mg.Lattice.cubic(4.2) ... structure = mg.Structure(lattice, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) ... view = nv.show_pymatgen(structure) ... view
-
nglview.
show_pytraj
(pytraj_trajectory, **kwargs)[source]¶ Show pytraj trajectory.
>>> import nglview as nv >>> import pytraj as pt >>> t = pt.load(nv.datafiles.TRR, nv.datafiles.PDB) >>> w = nv.show_pytraj(t) >>> w
-
nglview.
show_qcelemental
(obj, **kwargs)[source]¶ Show QCElemental’s Molecule.
>>> import nglview as nv >>> import qcelemental as qcel ... mol = qcel.models.Molecule.from_data("He 0 0 0") ... view = nv.show_qcelemental(mol) ... view
-
nglview.
show_rdkit
(rdkit_mol, **kwargs)[source]¶ Show rdkit’s Mol.
rdkit_mol : rdkit.Chem.rdchem.Mol kwargs : additional keyword argument If kwargs contains the “conf_id” key, this will be passed to the RDKit Chem.MolToXXXBlock function as the confId parameter. If the “conf_id” key is not provided, -1 will be used as confId. If kwargs contains the “fmt” key, this will be used to decide whether rdkit_mol should be visualized as a PDB block (fmt == “pdb”) or as a SDF block (fmt == “sdf”). If the “fmt” key is not provided, a simple heuristic is used: if the first atom contains PDB residue information, rdkit_mol is visualized as a PDB block, otherwise as a SDF block.
>>> import nglview as nv >>> from rdkit import Chem ... from rdkit.Chem import AllChem ... m = Chem.AddHs(Chem.MolFromSmiles('COc1ccc2[C@H](O)[C@@H](COc2c1)N3CCC(O)(CC3)c4ccc(F)cc4')) ... _ = AllChem.EmbedMultipleConfs(m, useExpTorsionAnglePrefs=True, useBasicKnowledge=True) ... view = nv.show_rdkit(m) ... view
>>> # add component m2 >>> # create file-like object >>> from nglview.show import StringIO >>> m2 = Chem.AddHs(Chem.MolFromSmiles('N[C@H](C)C(=O)O')) ... fh = StringIO(Chem.MolToPDBBlock(m2)) ... view.add_component(fh, ext='pdb')
>>> # load as trajectory, need to have ParmEd >>> view = nv.show_rdkit(m, parmed=True)
-
nglview.
show_rosetta
(pose, **kwargs)[source]¶ >>> from pyrosetta import pose_from_sequence, init ... init() ... pose = pose_from_sequence('AAAAAA') ... view = nglview.show_rosetta(pose) ... view
-
nglview.
show_schrodinger
(mol, traj=None, **kwargs)[source]¶ Show NGL widget with Schrodinger’s Structure
EXPERIMENTAL
>>> import nglview as nv ... from schrodinger.structure import StructureReader ... for s in StructureReader(fn): ... break ... w = nv.show_schrodinger(s) ... w
-
nglview.
show_simpletraj
(traj, **kwargs)[source]¶ Show simpletraj trajectory and structure file.
>>> import nglview as nv >>> traj = nv.SimpletrajTrajectory(nv.datafiles.XTC, nv.datafiles.GRO) >>> view = nv.show_simpletraj(traj) >>> view
-
nglview.
show_structure_file
(path, **kwargs)[source]¶ Show structure file. Allowed are text-based structure file formats that are by supported by NGL, including pdb, gro, mol2, sdf.
>>> import nglview as nv >>> w = nv.show_structure_file(nv.datafiles.GRO) >>> w
-
nglview.
write_html
(fp, views, frame_range=None)[source]¶ EXPERIMENTAL. Likely will be changed.
Make html file to display a list of views. For further options, please check ipywidgets.embed module.
fp : str or file handle views : a DOMWidget view or a list of views. frame_range : None or a tuple of int
>>> import nglview >>> view = nglview.show_pdbid('1tsu') >>> view >>> nglview.write_html('index.html', [view]) >>> nglview.write_html('index.html', [view], frame_range=(0, 5))