Interactive NMR DemoΒΆ
There are many ways to create interactive plots in a Juypter notebook, and the visualization ecosystem is constantly changing. For example the Holoviz tool suite (http://holoviz.org/) looks promising (especially the possibility of creating a web application using Panel). Another interesting option is nbinteract (https://www.nbinteract.com/).
This notebook currently uses ipywidgets and bokeh to create some simple NMR demonstrations.
[1]:
import os
import sys
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
sys.path.append(module_path)
[2]:
from nmrsim.dnmr import dnmr_AB
help(dnmr_AB)
Help on function dnmr_AB in module nmrsim.dnmr:
dnmr_AB(va, vb, J, k, w, limits=None, points=800)
Simulate the DNMR lineshape for two coupled nuclei undergoing exchange
(AB or AX pattern at the slow-exchange limit).
Parameters
---------
va, vb : float
frequencies of a and b nuclei (at the slow exchange limit,
in the absence of coupling)
J : float
the coupling constant between the two nuclei.
k : float
rate constant for state A--> state B
w : float
peak widths at half height (at the slow-exchange limit).
limits : (int or float, int or float), optional
The minimum and maximum frequencies (in any order) for the simulation.
points : int
The length of the returned arrays (i.e. the number of points plotted).
Returns
-------
x, y : numpy.array, numpy.array
Arrays for the x (frequency) and y (intensity) lineshape data points.
See Also
--------
DnmrAB : A class representation for this simulation.
References
----------
See the documentation for the nmrsim.dnmr module.
[3]:
args = (
200, # va
100, # vb
10, # J
0.1, # k
0.5 # w
)
[4]:
from ipywidgets import interact
[5]:
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook()
[6]:
# get initial xy data
x, y = dnmr_AB(*args)
[7]:
p = figure(title = 'DNMR AB Interactive Plot',
height=300,
width=600)
r = p.line(x, y)
[8]:
def interactive_ab(va=110, vb=100, J=10, k=0.1, w=0.5):
args = (va, vb, J, k, w)
x, y = dnmr_AB(*args)
r.data_source.data['y'] = y
r.data_source.data['x'] = x
push_notebook()
[9]:
show(p, notebook_handle=True)
interact(interactive_ab, k=(0.1, 100))
[9]:
<function __main__.interactive_ab(va=110, vb=100, J=10, k=0.1, w=0.5)>
[ ]: