Building Ion Tables

interferences core funciton is to generate, filter and visualise tables of isotope-specified small inorganic ionic molecules. This example demonstrates how to build a small table of ions, and some of the options available. Note that as interferences is largely built around pandas, you can expect to be working with DataFrame objects most of the time.

import pandas as pd
from interferences.table import build_table

In the simplest case, where you have a list of elments you want to find viable set of ions which they may produce, you can simply specify these elements in a call to build_table():

df = build_table(["Ca", "O", "Ar", "H"])
df.info()

Out:

  0%|          | 0/34 [00:00<?, ?it/s]
                         :   0%|          | 0/34 [00:00<?, ?it/s]
O @ 6 rows               :   0%|          | 0/34 [00:00<?, ?it/s]
H @ 4 rows               :   0%|          | 0/34 [00:00<?, ?it/s]
Ca @ 12 rows             :   0%|          | 0/34 [00:00<?, ?it/s]
Ar @ 6 rows              :   0%|          | 0/34 [00:00<?, ?it/s]
O-O @ 12 rows            :   0%|          | 0/34 [00:00<?, ?it/s]
H-O @ 12 rows            :   0%|          | 0/34 [00:00<?, ?it/s]
H-H @ 6 rows             :   0%|          | 0/34 [00:00<?, ?it/s]
Ca-O @ 36 rows           :   0%|          | 0/34 [00:00<?, ?it/s]
Ca-H @ 24 rows           :   0%|          | 0/34 [00:00<?, ?it/s]
Ca-Ca @ 42 rows          :   0%|          | 0/34 [00:00<?, ?it/s]
Ar-O @ 18 rows           :   0%|          | 0/34 [00:00<?, ?it/s]
Ar-H @ 12 rows           :   0%|          | 0/34 [00:00<?, ?it/s]
Ar-Ca @ 36 rows          :   0%|          | 0/34 [00:00<?, ?it/s]
Ar-Ar @ 12 rows          :   0%|          | 0/34 [00:00<?, ?it/s]
O-O-O @ 20 rows          :   0%|          | 0/34 [00:00<?, ?it/s]
H-O-O @ 24 rows          :   0%|          | 0/34 [00:00<?, ?it/s]
H-H-O @ 18 rows          :   0%|          | 0/34 [00:00<?, ?it/s]
H-H-H @ 8 rows           :   0%|          | 0/34 [00:00<?, ?it/s]
H-H-H @ 8 rows           :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ca-O-O @ 72 rows         :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ca-H-O @ 72 rows         :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ca-H-H @ 36 rows         :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ca-Ca-O @ 126 rows       :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ca-Ca-H @ 84 rows        :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ca-Ca-Ca @ 112 rows      :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-O-O @ 36 rows         :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-H-O @ 36 rows         :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-H-H @ 18 rows         :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ca-O @ 108 rows       :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ca-H @ 72 rows        :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ca-Ca @ 126 rows      :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ar-O @ 36 rows        :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ar-H @ 24 rows        :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ar-Ca @ 72 rows       :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ar-Ar @ 20 rows       :  53%|#####2    | 18/34 [00:00<00:00, 178.23it/s]
Ar-Ar-Ar @ 20 rows       : 100%|##########| 34/34 [00:00<00:00, 151.69it/s]
<class 'pandas.core.frame.DataFrame'>
Index: 1344 entries, H[1]++ to Ca[48]Ca[48]Ca[48]+
Data columns (total 4 columns):
 #   Column       Non-Null Count  Dtype
---  ------       --------------  -----
 0   m_z          1344 non-null   float64
 1   mass         1344 non-null   float64
 2   charge       1344 non-null   int64
 3   iso_product  1344 non-null   float64
dtypes: float64(3), int64(1)
memory usage: 52.5+ KB

Note that the table is indexed by the ions themselves, with the respective mass/charge ratio found under the m_z column. Even with a small set of elements, with the combination of isotopes, we’ve generated a fair number of potential ions:

Out:

1344

As this is probably more ions than you want to consider, let’s narrow the foucs using a mass window (here for \(39 \ge m/z \le 41\)):

df = build_table(["Ca", "O", "Ar", "H"], window=(39, 41))
df.index.size

Out:

48

While you can use m/z ratios if you know them specifically, it’s likely more useful to specify an ion mass and a mass-window either side, which you can do as follows:

df = build_table(["Ca", "O", "Ar", "H"], window=("Ca[40]", 0.01))
df.index.size

Out:

6

By default, interferences builds ions for molecules with up to three atoms with ionic charges of either +1 or +2 (note the sign of the charge is largely irrelevant, given a mass spectrometer will be set up for either positive or negative ions). If you wanted to use different parameters to generate a table, you can use the max_atoms and charges keyword arguemnts:

df = build_table(["Ca", "O", "Ar", "H"], charges=[1], max_atoms=2)
df.index.size

Out:

119

Also, to save time for futher computation, interferences uses a local HDFStore to cache results. You can disable this behaviour and gain some speed if you’re generating one-off large tables by using cache_results=False:

df = build_table(["Ca", "O", "Ar", "H"], cache_results=False)

If you’re finding that you end up with a table which includes minor ions which likely have too low an isotopic abundance to influence results, you can use the threshold keyword argument to adjust the isotopic abundance threshold for isotopes used to build the table. Note that these won’t be added to the cached reference:

df = build_table(["N", "K"], threshold=0.5)
df.index.size

Out:

  0%|          | 0/9 [00:00<?, ?it/s]
                         :   0%|          | 0/9 [00:00<?, ?it/s]
N @ 2 rows               :   0%|          | 0/9 [00:00<?, ?it/s]
K @ 4 rows               :   0%|          | 0/9 [00:00<?, ?it/s]
N-N @ 2 rows             :   0%|          | 0/9 [00:00<?, ?it/s]
K-N @ 4 rows             :   0%|          | 0/9 [00:00<?, ?it/s]
K-K @ 6 rows             :   0%|          | 0/9 [00:00<?, ?it/s]
N-N-N @ 2 rows           :   0%|          | 0/9 [00:00<?, ?it/s]
K-N-N @ 4 rows           :   0%|          | 0/9 [00:00<?, ?it/s]
K-K-N @ 6 rows           :   0%|          | 0/9 [00:00<?, ?it/s]
K-K-K @ 8 rows           :   0%|          | 0/9 [00:00<?, ?it/s]
K-K-K @ 8 rows           : 100%|##########| 9/9 [00:00<00:00, 194.34it/s]

35

Finally, if you’re likely to do some plotting with the ion data, you can specify this using the add_labels keyword argument, which will add nicely formatted labels comapatible with matplotlib:

df = build_table(["Ca", "O", "Ar", "H"], add_labels=True)

Total running time of the script: ( 0 minutes 3.216 seconds)

Gallery generated by Sphinx-Gallery