aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx
diff options
context:
space:
mode:
authorGravatar Edoardo Zoni <59625522+EZoni@users.noreply.github.com> 2022-08-08 15:03:20 -0700
committerGravatar GitHub <noreply@github.com> 2022-08-08 15:03:20 -0700
commitb13e7f53959656a8d47adc63f20d9ed055288be0 (patch)
treedcd8eb73d031b99e1670c756f60663f9bab6cc97 /Python/pywarpx
parentad50d85130c48919578ff56cd42221356b488f89 (diff)
downloadWarpX-b13e7f53959656a8d47adc63f20d9ed055288be0.tar.gz
WarpX-b13e7f53959656a8d47adc63f20d9ed055288be0.tar.zst
WarpX-b13e7f53959656a8d47adc63f20d9ed055288be0.zip
PICMI: Fix Bug in Class `Species` Init (#3286)
Diffstat (limited to 'Python/pywarpx')
-rw-r--r--Python/pywarpx/picmi.py37
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)