From b13e7f53959656a8d47adc63f20d9ed055288be0 Mon Sep 17 00:00:00 2001 From: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> Date: Mon, 8 Aug 2022 15:03:20 -0700 Subject: PICMI: Fix Bug in Class `Species` Init (#3286) --- Python/pywarpx/picmi.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'Python/pywarpx/picmi.py') 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#[\d+])*(?P[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#[\d+])*(?P[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) -- cgit v1.2.3