Skip to content

Commit 50f0483

Browse files
committed
Add a nicer visual example
1 parent 194a2fe commit 50f0483

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
'sphinx.ext.autodoc',
3434
'sphinx.ext.todo',
3535
'sphinx.ext.viewcode',
36-
'sphinx.ext.napoleon'
36+
'sphinx.ext.napoleon',
37+
'matplotlib.sphinxext.plot_directive',
38+
3739
]
3840

3941
# Add any paths that contain templates here, relative to this directory.

docs/doc-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sphinx>=1.3
2+
matplotlib

docs/index.rst

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,48 @@
66
Welcome to brainpy's documentation!
77
===================================
88

9-
:mod:`brainpy` is a small Python library implementing the *B*afflingly *R*ecursive
10-
*A*lgorithm for *I*sotopic Patter*N* generation. It includes three implementations,
9+
:mod:`brainpy` is a small Python library implementing the *B* afflingly *R* ecursive
10+
*A* lgorithm for *I* sotopic Patter *N* generation. It includes three implementations,
1111
a pure-Python object oriented implementation, a :title-reference:`Cython` accelerated
1212
version of the object oriented implementation, and a pure :title-reference:`C` implementation,
1313
listed in order of ascending speed. The C implementation is used by default when available.
1414

1515

1616
BRAIN takes an elemental composition represented by any :class:`Mapping`-like Python object
1717
and uses it to compute its aggregated isotopic distribution. All isotopic variants of the same
18-
number of neutrons are collapsed into a single peak, meaning it does not consider isotopic fine
19-
structure.
18+
number of neutrons are collapsed into a single centroid peak, meaning it does not consider
19+
isotopic fine structure.
2020

21-
.. code-block:: python
21+
.. plot::
22+
:include-source:
2223

2324
from brainpy import isotopic_variants
2425

25-
leucine = dict(C=6, H=13, O=2, N=1)
26-
theoretical_isotopic_cluster = isotopic_variants(leucine, n_peaks=6, charge=1)
26+
peptide = {'H': 53, 'C': 34, 'O': 15, 'N': 7}
27+
theoretical_isotopic_cluster = isotopic_variants(peptide, npeaks=5, charge=1)
2728
for peak in theoretical_isotopic_cluster:
2829
print(peak.mz, peak.intensity)
2930

31+
# produce a theoretical profile using a gaussian peak shape
32+
import numpy as np
33+
grid = np.arange(theoretical_isotopic_cluster[0].mz - 1,
34+
theoretical_isotopic_cluster[-1].mz + 1, 0.02)
35+
intensity = np.zeros_like(grid)
36+
sigma = 0.002
37+
for i, mz in enumerate(grid):
38+
for peak in theoretical_isotopic_cluster:
39+
intensity[i] += peak.intensity * np.exp(-(mz - peak.mz) ** 2 / (2 * sigma)
40+
) / (np.sqrt(2 * np.pi) * sigma)
41+
42+
intensity = (intensity / intensity.max()) * 100
43+
44+
# draw the profile
45+
from matplotlib import pyplot as plt
46+
plt.plot(grid, intensity)
47+
plt.xlabel("m/z")
48+
plt.ylabel("Relative intensity")
49+
50+
3051
.. automodule:: brainpy
3152

3253
.. autofunction:: isotopic_variants

0 commit comments

Comments
 (0)