How to use the plasmapy.particles.exceptions.MissingAtomicDataError function in plasmapy

To help you get started, we’ve selected a few plasmapy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PlasmaPy / PlasmaPy / plasmapy / particles / atomic.py View on Github external
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
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
If the lepton number is unavailable, then this attribute will
        raise a `~plasmapy.utils.MissingAtomicDataError`.

        Examples
        --------
        >>> Particle('e-').lepton_number
        1
        >>> Particle('mu+').lepton_number
        -1
        >>> Particle('He-4 0+').lepton_number
        0

        """
        if self._attributes["lepton number"] is None:  # coverage: ignore
            raise MissingAtomicDataError(
                f"The lepton number for {self.particle} is not available."
            )
        return self._attributes["lepton number"]
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
if self.isotope == "H-1":
            return const.m_p
        elif self.isotope == "D":
            return _special_ion_masses["D 1+"]
        elif self.isotope == "T":
            return _special_ion_masses["T 1+"]
        elif self.particle == "n":
            return const.m_n

        if not self.isotope:
            raise InvalidIsotopeError(_category_errmsg(self, "isotope"))

        base_mass = self._attributes["isotope mass"]

        if base_mass is None:  # coverage: ignore
            raise MissingAtomicDataError(
                f"The mass of a {self.isotope} nuclide is not available."
            )

        _nuclide_mass = (
            self._attributes["isotope mass"] - self.atomic_number * const.m_e
        )

        return _nuclide_mass.to(u.kg)
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
This attribute will return the number of protons and neutrons
        minus the number of antiprotons and antineutrons. The baryon
        number is equivalent to the mass number for isotopes.

        If the baryon number is unavailable, then this attribute will
        raise a `~plasmapy.utils.MissingAtomicDataError`.

        Examples
        --------
        >>> alpha = Particle('alpha')
        >>> alpha.baryon_number
        4

        """
        if self._attributes["baryon number"] is None:  # coverage: ignore
            raise MissingAtomicDataError(
                f"The baryon number for '{self.particle}' is not available."
            )
        return self._attributes["baryon number"]
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
def spin(self) -> Real:
        """
        Return the spin of the particle.

        If the spin is unavailable, then a
        `~plasmapy.utils.MissingAtomicDataError` will be raised.

        Examples
        --------
        >>> positron = Particle('e+')
        >>> positron.spin
        0.5

        """
        if self._attributes["spin"] is None:
            raise MissingAtomicDataError(
                f"The spin of particle '{self.particle}' is unavailable."
            )

        return self._attributes["spin"]
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
>>> protium = Particle('H-1 0+')
        >>> protium.mass_energy
        

        >>> electron = Particle('electron')
        >>> electron.mass_energy.to('MeV')
        

        """
        try:
            mass = self.nuclide_mass if self.isotope else self.mass
            energy = mass * const.c ** 2
            return energy.to(u.J)
        except MissingAtomicDataError:
            raise MissingAtomicDataError(
                f"The mass energy of {self.particle} is not available "
                f"because the mass is unknown."
            ) from None
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
>>> neutron.half_life
        

        """
        if self.element and not self.isotope:
            raise InvalidIsotopeError(_category_errmsg(self.particle, "isotope"))

        if isinstance(self._attributes["half-life"], str):
            warnings.warn(
                f"The half-life for {self.particle} is not known precisely; "
                "returning string with estimated value.",
                MissingAtomicDataWarning,
            )

        if self._attributes["half-life"] is None:
            raise MissingAtomicDataError(
                f"The half-life of '{self.particle}' is not available."
            )
        return self._attributes["half-life"]
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
>>> protium = Particle('H-1 0+')
        >>> protium.mass_energy
        

        >>> electron = Particle('electron')
        >>> electron.mass_energy.to('MeV')
        

        """
        try:
            mass = self.nuclide_mass if self.isotope else self.mass
            energy = mass * const.c ** 2
            return energy.to(u.J)
        except MissingAtomicDataError:
            raise MissingAtomicDataError(
                f"The mass energy of {self.particle} is not available "
                f"because the mass is unknown."
            ) from None
github PlasmaPy / PlasmaPy / plasmapy / particles / particle_class.py View on Github external
If the element does not have a defined standard atomic weight,
        this attribute will raise a
        `~plasmapy.utils.MissingAtomicDataError`.

        Examples
        --------
        >>> oxygen = Particle('O')
        >>> oxygen.standard_atomic_weight
        

        """
        if self.isotope or self.is_ion or not self.element:
            raise InvalidElementError(_category_errmsg(self, "element"))
        if self._attributes["standard atomic weight"] is None:  # coverage: ignore
            raise MissingAtomicDataError(
                f"The standard atomic weight of {self} is unavailable."
            )
        return self._attributes["standard atomic weight"].to(u.kg)