Open gakabani opened 5 days ago
Looks like the periodic table file might not be installing correctly.
!pip install nist-calculators
import xcom
data = xcom.calculate_cross_section("He", [1e6, 2e6, 5e6]) # Energy in eV
On the first run, produces the following error
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
[<ipython-input-2-986b26968135>](https://localhost:8080/#) in <cell line: 3>()
1 import xcom
2
----> 3 data = xcom.calculate_cross_section("He", [1e6, 2e6, 5e6]) # Energy in eV
4 # or
5 import numpy as np
[/usr/local/lib/python3.10/dist-packages/xcom/xcom.py](https://localhost:8080/#) in calculate_cross_section(element, energy)
99
100 if not isinstance(element, int):
--> 101 element = MaterialFactory.get_element_from_symbol(element)
102
103 n = len(energy)
[/usr/local/lib/python3.10/dist-packages/xcom/interpolators.py](https://localhost:8080/#) in get_element_from_symbol(cls, element)
149 """
150 if cls.element_symbols is None:
--> 151 cls._prepare_element_symbol()
152 return cls.element_symbols[element]
153
[/usr/local/lib/python3.10/dist-packages/xcom/interpolators.py](https://localhost:8080/#) in _prepare_element_symbol(cls)
136 def _prepare_element_symbol(cls):
137 cls.element_symbols = {}
--> 138 with open(PERIODIC_TABLE_PATH, newline='') as csvfile:
139 reader = csv.reader(csvfile, delimiter=",")
140 next(reader)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.10/dist-packages/xcom/data/PeriodicTableofElements.csv'
On subsequent runs, produces the following error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
[<ipython-input-3-986b26968135>](https://localhost:8080/#) in <cell line: 3>()
1 import xcom
2
----> 3 data = xcom.calculate_cross_section("He", [1e6, 2e6, 5e6]) # Energy in eV
4 # or
5 import numpy as np
[/usr/local/lib/python3.10/dist-packages/xcom/xcom.py](https://localhost:8080/#) in calculate_cross_section(element, energy)
99
100 if not isinstance(element, int):
--> 101 element = MaterialFactory.get_element_from_symbol(element)
102
103 n = len(energy)
[/usr/local/lib/python3.10/dist-packages/xcom/interpolators.py](https://localhost:8080/#) in get_element_from_symbol(cls, element)
150 if cls.element_symbols is None:
151 cls._prepare_element_symbol()
--> 152 return cls.element_symbols[element]
153
154 @staticmethod
KeyError: 'He'
@gakabani You can probably manually fix the installation by placing the PeriodicTableofElements.csv
file in the right place, but this package has some other problems as well. I would suggest cloning either this repository or the fork that I have been trying to maintain:
https://github.com/lynntf/nist-calculators
Or, if you don't need that much data, use the XCOM web application:
https://www.physics.nist.gov/PhysRefData/Xcom/html/xcom1.html
I do not believe that @Zelenyy is still maintaining this package.
I am getting the following error. I think it is related to the installation process. A file may be missing for the conversion from the Element symbol to Atomic number.
data = xcom.calculate_cross_section("H", [1e6]) # Energy in eV
KeyError Traceback (most recent call last) Cell In[13], line 1 ----> 1 data = xcom.calculate_cross_section("H", [1e6]) # Energy in eV
File ~/miniconda3/lib/python3.11/site-packages/xcom/xcom.py:101, in calculate_cross_section(element, energy) 98 energy = ENERGY_GRID_DEFAULT 100 if not isinstance(element, int): --> 101 element = MaterialFactory.get_element_from_symbol(element) 103 n = len(energy) 104 dtype = np.dtype([("energy", "d"), 105 (NameProcess.COHERENT, 'd'), 106 (NameProcess.INCOHERENT, 'd'), (...) 110 ("total_without_coherent", "d"), 111 ("total", "d")])
File ~/miniconda3/lib/python3.11/site-packages/xcom/interpolators.py:152, in MaterialFactory.get_element_from_symbol(cls, element) 150 if cls.element_symbols is None: 151 cls._prepare_element_symbol() --> 152 return cls.element_symbols[element]
KeyError: 'H'