try pytraj online:

http://mybinder.org/badge.svg

Radial distribution function of watersΒΆ

../_images/rdf_tz2_ortho.png
In [1]:
import warnings
warnings.filterwarnings('ignore', category=DeprecationWarning)
# load pytraj
import pytraj as pt
In [2]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'  # high resolution
import matplotlib
matplotlib.rcParams['savefig.dpi'] = 2 * matplotlib.rcParams['savefig.dpi'] # larger image
from matplotlib import pyplot as plt
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/haichit/miniconda3/lib/python3.5/site-packages/matplotlib/rcsetup.py in validate_dpi(s)
    206     try:
--> 207         return float(s)
    208     except ValueError:

ValueError: could not convert string to float: 'figurefigure'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
/Users/haichit/miniconda3/lib/python3.5/site-packages/matplotlib/__init__.py in __setitem__(self, key, val)
    925             try:
--> 926                 cval = self.validate[key](val)
    927             except ValueError as ve:

/Users/haichit/miniconda3/lib/python3.5/site-packages/matplotlib/rcsetup.py in validate_dpi(s)
    209         raise ValueError('"%s" is not string "figure" or'
--> 210             ' could not convert "%s" to float' % (s, s))
    211 

ValueError: "figurefigure" is not string "figure" or could not convert "figurefigure" to float

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-2-0f80b74f90a2> in <module>()
      2 get_ipython().magic("config InlineBackend.figure_format = 'retina'  # high resolution")
      3 import matplotlib
----> 4 matplotlib.rcParams['savefig.dpi'] = 2 * matplotlib.rcParams['savefig.dpi'] # larger image
      5 from matplotlib import pyplot as plt

/Users/haichit/miniconda3/lib/python3.5/site-packages/matplotlib/__init__.py in __setitem__(self, key, val)
    926                 cval = self.validate[key](val)
    927             except ValueError as ve:
--> 928                 raise ValueError("Key %s: %s" % (key, str(ve)))
    929             dict.__setitem__(self, key, cval)
    930         except KeyError:

ValueError: Key savefig.dpi: "figurefigure" is not string "figure" or could not convert "figurefigure" to float
In [3]:
# load trajectory
traj = pt.load_sample_data('tz2')
traj
Out[3]:
pytraj.TrajectoryIterator, 10 frames: 
Size: 0.001183 (GB)
<Topology: 5293 atoms, 1704 residues, 1692 mols, PBC with box type = ortho>
           
In [4]:
# perform RDF calculation for water

rdf_data = pt.rdf(traj, solvent_mask=':WAT@O', solute_mask=':WAT@O', bin_spacing=0.2, maximum=12.)
In [5]:
rdf_data
Out[5]:
(array([  0.1,   0.3,   0.5, ...,  11.5,  11.7,  11.9]),
 array([ 0.        ,  0.        ,  0.        , ...,  0.95114901,
         0.94740952,  0.95099495]))
In [6]:
plt.plot(rdf_data[0], rdf_data[1])
plt.xlabel(r"r ( $\AA$ )")
plt.ylabel('g(r)')
#plt.savefig('rdf_tz2_ortho.png')
Out[6]:
<matplotlib.text.Text at 0x10a6e6e48>

(radial_distribution_function_of_water.ipynb; radial_distribution_function_of_water_evaluated.ipynb; radial_distribution_function_of_water.py)