Coverage for ase/data/isotopes.py: 73.91%
23 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1"""Isotope data extracted from NIST public website.
3Source data has been compiled by NIST:
5 https://www.nist.gov/pml/atomic-weights-and-isotopic-compositions-relative-atomic-masses
7The atomic weights data were published in:
9 J. Meija et al, Atomic weights of the elements 2013,
10 Pure and Applied Chemistry 88, 265-291 (2016).
11 https://doi.org/10.1515/pac-2015-0305
12 http://www.ciaaw.org/atomic-weights.htm
14Isotopic compositions data were published in:
16 Michael Berglund and Michael E. Wieser,
17 Isotopic compositions of the elements 2009 (IUPAC Technical Report)
18 Pure Appl. Chem., 2011, Vol. 83, No. 2, pp. 397-410
19 https://doi.org/10.1351/PAC-REP-10-06-02
21The relative atomic masses of the isotopes data were published in:
23 M. Wang, G. Audi, A.H. Wapstra, F.G. Kondev, M. MacCormick, X. Xu,
24 and B. Pfeiffer, The AME2012 Atomic Mass Evaluation,
25 Chinese Phys. C 36 1603
26 https://doi.org/10.1088/1674-1137/36/12/003
27 http://amdc.impcas.ac.cn/evaluation/data2012/ame.html
28"""
30from urllib import request
33def download_isotope_data():
34 """Download isotope data from NIST public website.
36 Relative atomic masses of individual isotopes their abundance
37 (mole fraction) are compiled into a dictionary. Individual items can be
38 indexed by the atomic number and mass number, e.g. titanium-48:
40 >>> from ase.data.isotopes import download_isotope_data
41 >>> isotopes = download_isotope_data() # doctest: +SKIP
42 >>> isotopes[22][48]['mass'] # doctest: +SKIP
43 47.94794198
44 >>> isotopes[22][48]['composition'] # doctest: +SKIP
45 0.7372
46 """
47 # Do not enable the doctest because we do not want to download stuff.
49 url = (
50 'http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl'
51 '?ele=&ascii=ascii&isotype=all'
52 )
54 req = request.Request(
55 url,
56 headers={
57 'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127'
58 'Firefox/2.0.0.11'
59 },
60 )
62 with request.urlopen(req) as fd:
63 txt = fd.read()
65 raw_data = txt.decode().splitlines()
67 return parse_isotope_data(raw_data)
70def parse_isotope_data(raw_data):
71 # In the list of raw data, a string containing only a series of underscores
72 # preceeds the data for each element. So by getting the indexes of these
73 # strings, we are recording where in the data each element starts
74 indexes = [idx for (idx, line) in enumerate(raw_data) if '_____' in line]
76 isotopes = {}
77 for idx1, idx2 in zip(indexes, indexes[1:]):
78 atomic_number = int(raw_data[idx1 + 1].split()[0])
79 isotopes[atomic_number] = dct = {}
80 for isotope_idx in range(idx1 + 1, idx2):
81 mass_number = int(raw_data[isotope_idx][8:12])
82 # drop uncertainty
83 mass = float(raw_data[isotope_idx][13:31].split('(')[0])
84 try:
85 composition = float(raw_data[isotope_idx][32:46].split('(')[0])
86 except ValueError:
87 composition = 0.0
88 dct[mass_number] = {'mass': mass, 'composition': composition}
90 return isotopes