AbstractPhysicalParticle
- class plasmapy.particles.particle_class.AbstractPhysicalParticle[source]
Bases:
AbstractParticle
Base class for particles that are defined with physical units.
Attributes Summary
Provide the particle's categories.
Provide the particle's electric charge.
A dictionary representation of the particle object that is JSON friendly (i.e. convertible to a JSON object).
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 thefp
file object usingjson.dump
.json_dumps
(**kwargs)Serialize the particle's
json_dict
into a JSON formattedstr
usingjson.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: str | Iterable[str] | None = None,
- any_of: str | Iterable[str] | None = None,
- exclude: str | Iterable[str] | None = None,
Determine if the particle meets categorization criteria.
Return
True
if the particle is consistent with the provided categories, andFalse
otherwise.- Parameters:
*category_tuple – Required categories in the form of one or more
str
objects or an iterable.require (
str
or iterable ofstr
, keyword-only, optional) – One or more particle categories. This method will returnFalse
if the particle does not belong to all of these categories.any_of (
str
or iterable ofstr
, keyword-only, optional) – One or more particle categories. This method will returnFalse
if the particle does not belong to at least one of these categories.exclude (
str
or iterable ofstr
, keyword-only, optional) – One or more particle categories. This method will returnFalse
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
, ortuple
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 theany_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 theexclude
keyword argument.>>> electron.is_category(exclude="baryon") True >>> electron.is_category(exclude={"lepton", "baryon"}) False
The
require
,any_of
, andexclude
keywords may be combined. If the particle matches all of the provided criteria, then this method will returnTrue
.>>> electron.is_category( ... require="fermion", ... any_of={"lepton", "baryon"}, ... exclude="charged", ... ) False
- json_dump(fp, **kwargs: dict[str, Any]) None
Write the particle’s
json_dict
to thefp
file object usingjson.dump
.- Parameters:
fp (file object) – Destination file object to write the JSON serialized
json_dict
.**kwargs – Any keyword accepted by
json.dump
.
- json_dumps(**kwargs: object) str
Serialize the particle’s
json_dict
into a JSON formattedstr
usingjson.dumps
.- Parameters:
**kwargs – Any keyword accepted by
json.dumps
.- Returns:
JSON formatted
str
.- Return type: