diff options
author | 2022-08-08 15:03:20 -0700 | |
---|---|---|
committer | 2022-08-08 15:03:20 -0700 | |
commit | b13e7f53959656a8d47adc63f20d9ed055288be0 (patch) | |
tree | dcd8eb73d031b99e1670c756f60663f9bab6cc97 /Python | |
parent | ad50d85130c48919578ff56cd42221356b488f89 (diff) | |
download | WarpX-b13e7f53959656a8d47adc63f20d9ed055288be0.tar.gz WarpX-b13e7f53959656a8d47adc63f20d9ed055288be0.tar.zst WarpX-b13e7f53959656a8d47adc63f20d9ed055288be0.zip |
PICMI: Fix Bug in Class `Species` Init (#3286)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pywarpx/picmi.py | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index 95c0d452a..be227e182 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -61,23 +61,26 @@ class Species(picmistandard.PICMI_Species): self.charge = '-q_e' else: self.charge = self.charge_state*constants.q_e - # Match a string of the format '#nXx', with the '#n' optional isotope number. - m = re.match(r'(?P<iso>#[\d+])*(?P<sym>[A-Za-z]+)', self.particle_type) - if m is not None: - element = periodictable.elements.symbol(m['sym']) - if m['iso'] is not None: - element = element[m['iso'][1:]] - if self.charge_state is not None: - assert self.charge_state <= element.number, Exception('%s charge state not valid'%self.particle_type) - try: - element = element.ion[self.charge_state] - except ValueError: - # Note that not all valid charge states are defined in elements, - # so this value error can be ignored. - pass - self.element = element - if self.mass is None: - self.mass = element.mass*periodictable.constants.atomic_mass_constant + if self.particle_type is not None: + # Match a string of the format '#nXx', with the '#n' optional isotope number. + m = re.match(r'(?P<iso>#[\d+])*(?P<sym>[A-Za-z]+)', self.particle_type) + if m is not None: + element = periodictable.elements.symbol(m['sym']) + if m['iso'] is not None: + element = element[m['iso'][1:]] + if self.charge_state is not None: + assert self.charge_state <= element.number, Exception('%s charge state not valid'%self.particle_type) + try: + element = element.ion[self.charge_state] + except ValueError: + # Note that not all valid charge states are defined in elements, + # so this value error can be ignored. + pass + self.element = element + if self.mass is None: + self.mass = element.mass*periodictable.constants.atomic_mass_constant + else: + raise Exception('The species "particle_type" is not known') self.boost_adjust_transverse_positions = kw.pop('warpx_boost_adjust_transverse_positions', None) |