Coverage for /builds/kinetik161/ase/ase/data/isotopes.py: 77.27%

22 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

1"""Isotope data extracted from NIST public website. 

2 

3Source data has been compiled by NIST: 

4 

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

6 

7The atomic weights data were published in: 

8 

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 

13 

14Isotopic compositions data were published in: 

15 

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 

20 

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

22 

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""" 

29from urllib import request 

30 

31 

32def download_isotope_data(): 

33 """Download isotope data from NIST public website. 

34 

35 Relative atomic masses of individual isotopes their abundance 

36 (mole fraction) are compiled into a dictionary. Individual items can be 

37 indexed by the atomic number and mass number, e.g. titanium-48: 

38 

39 >>> from ase.data.isotopes import download_isotope_data 

40 >>> isotopes = download_isotope_data() 

41 >>> isotopes[22][48]['mass'] 

42 47.94794198 

43 >>> isotopes[22][48]['composition'] 

44 0.7372 

45 """ 

46 

47 url = 'http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl' \ 

48 '?ele=&ascii=ascii&isotype=all' 

49 

50 with request.urlopen(url) as fd: 

51 txt = fd.read() 

52 

53 raw_data = txt.decode().splitlines() 

54 

55 return parse_isotope_data(raw_data) 

56 

57 

58def parse_isotope_data(raw_data): 

59 # In the list of raw data, a string containing only a series of underscores 

60 # preceeds the data for each element. So by getting the indexes of these 

61 # strings, we are recording where in the data each element starts 

62 indexes = [idx for (idx, line) in enumerate(raw_data) if "_____" in line] 

63 

64 isotopes = {} 

65 for idx1, idx2 in zip(indexes, indexes[1:]): 

66 atomic_number = int(raw_data[idx1 + 1].split()[0]) 

67 isotopes[atomic_number] = dct = {} 

68 for isotope_idx in range(idx1 + 1, idx2): 

69 mass_number = int(raw_data[isotope_idx][8:12]) 

70 # drop uncertainty 

71 mass = float(raw_data[isotope_idx][13:31].split('(')[0]) 

72 try: 

73 composition = float(raw_data[isotope_idx][32:46].split('(')[0]) 

74 except ValueError: 

75 composition = 0.0 

76 dct[mass_number] = {'mass': mass, 'composition': composition} 

77 

78 return isotopes