AbstractPhysicalParticle

class plasmapy.particles.particle_class.AbstractPhysicalParticle

Bases: AbstractParticle

Base class for particles that are defined with physical units.

Attributes Summary

categories

Provide the particle's categories.

charge

Provide the particle's electric charge.

json_dict

A dictionary representation of the particle object that is JSON friendly (i.e.

mass

Provide the particle's mass.

Methods Summary

is_category(*category_tuple[, require, ...])

Determine if the particle meets categorization criteria.

json_dump(fp, **kwargs)

Write the particle's json_dict to the fp file object using json.dump.

json_dumps(**kwargs)

Serialize the particle's json_dict into a JSON formatted str using json.dumps.

Attributes Documentation

categories

Provide the particle’s categories.

charge

Provide the particle’s electric charge.

json_dict

A dictionary representation of the particle object that is JSON friendly (i.e. convertible to a JSON object).

The dictionary should maintain the following format so that ParticleJSONDecoder knows how to decode the resulting JSON object.

{"plasmapy_particle": {
    # string representation of the particle class
    "type": "Particle",

    # string representation of the module contains the particle class
    "module": "plasmapy.particles.particle_class",

    # date stamp of when the object was created
    "date_created": "2020-07-20 17:46:13 UTC",

    # parameters used to initialized the particle class
    "__init__": {
        # tuple of positional arguments
        "args": (),

        # dictionary of keyword arguments
        "kwargs": {},
    },
}}

Only the "__init__" entry should be modified by the subclass.

mass

Provide the particle’s mass.

Methods Documentation

is_category(*category_tuple, require: Optional[Union[str, Iterable[str]]] = None, any_of: Optional[Union[str, Iterable[str]]] = None, exclude: Optional[Union[str, Iterable[str]]] = None) bool

Determine if the particle meets categorization criteria.

Return True if the particle is consistent with the provided categories, and False otherwise.

Parameters
  • *category_tuple – Required categories in the form of one or more str objects or an iterable.

  • require (str or iterable of str, optional, keyword-only) – One or more particle categories. This method will return False if the particle does not belong to all of these categories.

  • any_of (str or iterable of str, optional, keyword-only) – One or more particle categories. This method will return False if the particle does not belong to at least one of these categories.

  • exclude (str or iterable of str, optional, keyword-only) – One or more particle categories. This method will return False if the particle belongs to any of these categories.

See also

valid_categories

A set containing all valid particle categories.

Notes

Valid particle categories are given in valid_categories and include: "actinide", "alkali metal", "alkaline earth metal", "antibaryon", "antilepton", "antimatter", "antineutrino", "baryon", "boson", "charged", "custom", "electron", "element", "fermion", "halogen", "ion", "isotope", "lanthanide", "lepton", "matter", "metal", "metalloid", "neutrino", "neutron", "noble gas", "nonmetal", "positron", "post-transition metal", "proton", "stable", "transition metal", "uncharged", and "unstable".

Examples

Required categories may be entered as positional arguments, including as a list, set, or tuple of required categories.

>>> electron = Particle("e-")
>>> electron.is_category("lepton")
True
>>> electron.is_category("lepton", "baryon")
False
>>> electron.is_category(["fermion", "matter"])
True

Required arguments may also be provided using the require keyword argument.

>>> electron.is_category(require="lepton")
True
>>> electron.is_category(require=["lepton", "baryon"])
False

This method will return False if the particle does not belong to at least one of the categories provided with the any_of keyword argument.

>>> electron.is_category(any_of=["lepton", "baryon"])
True
>>> electron.is_category(any_of=("noble gas", "lanthanide", "halogen"))
False

This method will return False if the particle belongs to any of the categories provided in the exclude keyword argument.

>>> electron.is_category(exclude="baryon")
True
>>> electron.is_category(exclude={"lepton", "baryon"})
False

The require, any_of, and exclude keywords may be combined. If the particle matches all of the provided criteria, then this method will return True.

>>> electron.is_category(
...     require="fermion", any_of={'lepton', 'baryon'}, exclude='charged',
... )
False
json_dump(fp, **kwargs)

Write the particle’s json_dict to the fp file object using json.dump.

Parameters
json_dumps(**kwargs) str

Serialize the particle’s json_dict into a JSON formatted str using json.dumps.

Parameters

**kwargs – Any keyword accepted by json.dumps.

Returns

JSON formatted str.

Return type

str