Using Jupyter notebook for interactive development

url: http://jupyter.org/

How to run this notebook?

Click Cell and then Run All

How to run it online?

mybinder.org/repo/hainm/notebook-pytraj

See also

protein viewer example

Install

conda install parmed -c ambermd # Python package for topology editing and force field development
conda install pytraj-dev -c ambermd # Python interface for cpptraj (MD trajectory data analysis)
conda install pysander -c ambermd # Python interface for SANDER
# all above will be also available in AMBER16 release (next few months)

conda install nglview -c ambermd # Protein/DNA/RAN viewer in notebook

# notebook
conda install jupyter notebook

ParmEd: Cross-program parameter and topology file editor and molecular mechanical simulator engine.

url: https://github.com/ParmEd/ParmEd (AMBER16)

In [1]:
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning) 
warnings.filterwarnings("ignore", category=UserWarning) 

import parmed as pmd

x = pmd.load_file('tz2.pdb')
[res.name for res in x.residues]


Out[1]:
['SER',
 'TRP',
 'THR',
 'TRP',
 'GLU',
 'ASN',
 'GLY',
 'LYS',
 'TRP',
 'THR',
 'TRP',
 'LYS',
 'NME']

In [2]:
[atom.name for atom in x.residues[0]]


Out[2]:
['N', 'H1', 'H2', 'H3', 'CA', 'HA', 'CB', 'HB2', 'HB3', 'OG', 'HG', 'C', 'O']

PYTRAJ: Interactive data analysis for molecular dynamics simulations

url: https://github.com/Amber-MD/pytraj (AMBER 16)

Compute distances and plot


In [3]:
import pytraj as pt

traj = pt.load('tz2.nc', 'tz2.parm7')
distances = pt.distances(traj, ':1 :12', dtype='dataframe')
distances.head()


Out[3]:
Dis_00000
0 19.596637
1 17.348018
2 17.844973
3 15.645448
4 14.393131

In [4]:
%matplotlib inline 

distances.hist()


Out[4]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2aaac75a1438>]], dtype=object)

Compute multiple dihedrals


In [5]:
dihedrals = pt.multidihedral(traj, resrange='1-3', dtype='dataframe')
dihedrals.head(3) # show only first 3 snapshots


Out[5]:
psi_1 phi_2 psi_2 chip_2 omega_2 phi_3 psi_3 omega_3
0 -86.697506 -52.781235 -37.458655 -167.770537 -170.555872 -79.867366 117.355933 -179.707558
1 -91.159994 -40.620800 -41.199817 -178.620425 177.860923 -120.154899 108.983575 -178.763975
2 -67.937422 -51.215481 -49.467222 -179.101253 160.530607 -52.189986 132.574742 164.425577

In [6]:
%matplotlib inline

from matplotlib import pyplot as plt

plt.plot(dihedrals['phi_2'], dihedrals['psi_2'], '-bo', linewidth=0)
plt.xlim([-180, 180])
plt.ylim([-180, 180])


Out[6]:
(-180, 180)

get help?


In [7]:
help(pt.multidihedral)


Help on function calc_multidihedral in module pytraj.all_actions:

calc_multidihedral(traj=None, dhtypes=None, resrange=None, define_new_type=None, range360=False, dtype='dataset', top=None, frame_indices=None)
    perform dihedral search
    
    Parameters
    ----------
    traj : Trajectory-like object
    dhtypes : dihedral type, default None
        if None, calculate all supported dihedrals
    resrange : str | array-like
        residue range for searching. If `resrange` is string, use index starting with 1
        (cpptraj convertion)
        if `resrange` is array-like, use index starting from 0 (python convention)
    define_new_type : str
        define new type for searching
    range360 : bool, default False
        if True: use 0-360
    top : Topology | str, optional
        only need to have 'top' if can not find it in `traj`
    
    
    Returns
    -------
    pytraj.DatasetList (use `values` attribute to get raw `numpy` array)
    
    Notes
    -----
        Dataset lables show residue number in 1-based index
    
    Examples
    --------
    >>> import pytraj as pt
    >>> traj = pt.datafiles.load_tz2_ortho()
    >>> data = pt.multidihedral(traj)
    >>> data = pt.multidihedral(traj, 'phi psi')
    >>> data = pt.multidihedral(traj, resrange=range(8))
    >>> data = pt.multidihedral(traj, range360=True)
    >>> data = pt.multidihedral(traj, resrange='1,3,5')
    >>> data = pt.multidihedral(traj, dhtypes='phi psi')
    >>> data = pt.multidihedral(traj, dhtypes='phi psi', resrange='3-7')
    >>> data = pt.multidihedral(traj, dhtypes='phi psi', resrange=[3, 4, 8])

Protein/DNA/RNA viewer in notebook

  • Written in Python/Javascript
  • super light (~3 MB)
  • super easy to install (pip install nglview)

In [8]:
import warnings
warnings.filterwarnings('ignore')

import nglview as nv
view = nv.show_pytraj(traj)
view

In [9]:
view.representations = []
view.add_representation('cartoon', color='residueindex')
view.add_representation('licorice')

In [10]:
t0 = pt.fetch_pdb('3pqr')
view0 = pt.view.to_nglview(t0)
view0

In [11]:
view0.representations = []
view0.add_representation('cartoon', selection='protein', color='residueindex')
view0.add_representation('surface', selection='protein', opacity='0.2')

Not yet ported to Python

Phenix wishlist (for developers)

  • phenix.conda install jupyter notebook
  • phenix.ipython