File: isotopes.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (80 lines) | stat: -rw-r--r-- 2,810 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# fmt: off

"""Isotope data extracted from NIST public website.

Source data has been compiled by NIST:

    https://www.nist.gov/pml/atomic-weights-and-isotopic-compositions-relative-atomic-masses

The atomic weights data were published in:

    J. Meija et al, Atomic weights of the elements 2013,
    Pure and Applied Chemistry 88, 265-291 (2016).
    https://doi.org/10.1515/pac-2015-0305
    http://www.ciaaw.org/atomic-weights.htm

Isotopic compositions data were published in:

    Michael Berglund and Michael E. Wieser,
    Isotopic compositions of the elements 2009 (IUPAC Technical Report)
    Pure Appl. Chem., 2011, Vol. 83, No. 2, pp. 397-410
    https://doi.org/10.1351/PAC-REP-10-06-02

The relative atomic masses of the isotopes data were published in:

    M. Wang, G. Audi, A.H. Wapstra, F.G. Kondev, M. MacCormick, X. Xu,
    and B. Pfeiffer, The AME2012 Atomic Mass Evaluation,
    Chinese Phys. C 36 1603
    https://doi.org/10.1088/1674-1137/36/12/003
    http://amdc.impcas.ac.cn/evaluation/data2012/ame.html
"""
from urllib import request


def download_isotope_data():
    """Download isotope data from NIST public website.

    Relative atomic masses of individual isotopes their abundance
    (mole fraction) are compiled into a dictionary. Individual items can be
    indexed by the atomic number and mass number, e.g. titanium-48:

    >>> from ase.data.isotopes import download_isotope_data
    >>> isotopes = download_isotope_data()
    >>> isotopes[22][48]['mass']
    47.94794198
    >>> isotopes[22][48]['composition']
    0.7372
    """

    url = 'http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl' \
        '?ele=&ascii=ascii&isotype=all'

    with request.urlopen(url) as fd:
        txt = fd.read()

    raw_data = txt.decode().splitlines()

    return parse_isotope_data(raw_data)


def parse_isotope_data(raw_data):
    # In the list of raw data, a string containing only a series of underscores
    # preceeds the data for each element. So by getting the indexes of these
    # strings, we are recording where in the data each element starts
    indexes = [idx for (idx, line) in enumerate(raw_data) if "_____" in line]

    isotopes = {}
    for idx1, idx2 in zip(indexes, indexes[1:]):
        atomic_number = int(raw_data[idx1 + 1].split()[0])
        isotopes[atomic_number] = dct = {}
        for isotope_idx in range(idx1 + 1, idx2):
            mass_number = int(raw_data[isotope_idx][8:12])
            # drop uncertainty
            mass = float(raw_data[isotope_idx][13:31].split('(')[0])
            try:
                composition = float(raw_data[isotope_idx][32:46].split('(')[0])
            except ValueError:
                composition = 0.0
            dct[mass_number] = {'mass': mass, 'composition': composition}

    return isotopes