Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise ChargeError(
f"{self.particle} cannot undergo recombination because "
f"its charge is not specified."
)
if not isinstance(n, Integral):
raise TypeError("n must be a positive integer.")
if n <= 0:
raise ValueError("n must be a positive number.")
base_particle = self.isotope if self.isotope else self.element
new_integer_charge = self.integer_charge - n
if inplace:
self.__init__(base_particle, Z=new_integer_charge)
else:
return Particle(base_particle, Z=new_integer_charge)
# Convert the argument to a Particle object if it is not
# already one.
if not already_particle:
if not isinstance(argval, (numbers.Integral, str, tuple, list)):
raise TypeError(
f"The argument {argname} to {funcname} must be "
f"a string, an integer or a tuple or list of them "
f"corresponding to an atomic number, or a "
f"Particle object."
)
try:
particle = Particle(argval, Z=Z, mass_numb=mass_numb)
except InvalidParticleError as e:
raise InvalidParticleError(
_particle_errmsg(argname, argval, Z, mass_numb, funcname)
) from e
# We will need to do the same error checks whether or not the
# argument is already an instance of the Particle class.
if already_particle:
particle = argval
# If the name of the argument annotated with Particle in the
# decorated function is element, isotope, or ion; then this
# decorator should raise the appropriate exception when the
# particle ends up not being an element, isotope, or ion.
from plasmapy.particles.particle_input import particle_input
from plasmapy.particles.special_particles import ParticleZoo
from plasmapy.particles.symbols import (
atomic_symbol,
element_name,
ionic_symbol,
isotope_symbol,
particle_symbol,
)
# Create instances of the most commonly used particles
proton = Particle("p+")
electron = Particle("e-")
neutron = Particle("n")
positron = Particle("e+")
deuteron = Particle("D 1+")
triton = Particle("T 1+")
alpha = Particle("He-4 2+")
Particle,
)
from plasmapy.particles.particle_input import particle_input
from plasmapy.particles.special_particles import ParticleZoo
from plasmapy.particles.symbols import (
atomic_symbol,
element_name,
ionic_symbol,
isotope_symbol,
particle_symbol,
)
# Create instances of the most commonly used particles
proton = Particle("p+")
electron = Particle("e-")
neutron = Particle("n")
positron = Particle("e+")
deuteron = Particle("D 1+")
triton = Particle("T 1+")
alpha = Particle("He-4 2+")
from plasmapy.particles.symbols import (
atomic_symbol,
element_name,
ionic_symbol,
isotope_symbol,
particle_symbol,
)
# Create instances of the most commonly used particles
proton = Particle("p+")
electron = Particle("e-")
neutron = Particle("n")
positron = Particle("e+")
deuteron = Particle("D 1+")
triton = Particle("T 1+")
alpha = Particle("He-4 2+")
def get_particle_mass(particle) -> u.Quantity:
"""Return the mass of a particle.
Take a representation of a particle and returns the mass in
kg. If the input is a `~astropy.units.Quantity` or
`~astropy.constants.Constant` with units of mass already, then
this returns that mass converted to kg.
"""
try:
if isinstance(particle, (u.Quantity, const.Constant)):
return particle.to(u.kg)
if not isinstance(particle, Particle):
particle = Particle(particle)
return particle.mass.to(u.kg)
except u.UnitConversionError as exc1:
raise u.UnitConversionError(f"Incorrect units in reduced_mass.") from exc1
except MissingAtomicDataError:
raise MissingAtomicDataError(
f"Unable to find the reduced mass because the mass of "
f"{particle} is not available."
) from None
def __getitem__(self, value) -> State:
"""Return information for a single ionization level."""
if isinstance(value, slice):
raise TypeError("IonizationState instances cannot be sliced.")
if isinstance(value, Integral) and 0 <= value <= self.atomic_number:
result = State(
value,
self.ionic_fractions[value],
self.ionic_symbols[value],
self.number_densities[value],
)
else:
if not isinstance(value, Particle):
try:
value = Particle(value)
except InvalidParticleError as exc:
raise InvalidParticleError(
f"{value} is not a valid integer charge or " f"particle."
) from exc
same_element = value.element == self.element
same_isotope = value.isotope == self.isotope
has_charge_info = value.is_category(any_of=["charged", "uncharged"])
if same_element and same_isotope and has_charge_info:
Z = value.integer_charge
result = State(
Z,
self.ionic_fractions[Z],
if np.isnan(self.n):
new_n = 0 * u.m ** -3
for key in _elements_and_isotopes:
new_n += n_elems[key]
self.n = new_n
new_abundances = {}
for key in _elements_and_isotopes:
new_abundances[key] = np.float(n_elems[key] / self.n)
self._pars["abundances"] = new_abundances
elif isinstance(inputs, (list, tuple)):
try:
_particle_instances = [Particle(particle) for particle in inputs]
except (InvalidParticleError, TypeError) as exc:
raise AtomicError("Invalid inputs to IonizationStates.") from exc
_particle_instances.sort(
key=lambda p: (p.atomic_number, p.mass_number if p.isotope else 0)
)
_elements_and_isotopes = [
particle.particle for particle in _particle_instances
]
new_ionic_fractions = {
particle.particle: np.full(
particle.atomic_number + 1, fill_value=np.nan, dtype=np.float64
)
for particle in _particle_instances
}
else: