AbstractPhysicalParticle
- class plasmapy.particles.particle_class.AbstractPhysicalParticle[source]
Bases:
AbstractParticleBase 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_dictto thefpfile object usingjson.dump.json_dumps(**kwargs)Serialize the particle's
json_dictinto a JSON formattedstrusingjson.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
ParticleJSONDecoderknows 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
Trueif the particle is consistent with the provided categories, andFalseotherwise.- Parameters:
*category_tuple – Required categories in the form of one or more
strobjects or an iterable.require (
stror iterable ofstr, keyword-only, optional) – One or more particle categories. This method will returnFalseif the particle does not belong to all of these categories.any_of (
stror iterable ofstr, keyword-only, optional) – One or more particle categories. This method will returnFalseif the particle does not belong to at least one of these categories.exclude (
stror iterable ofstr, keyword-only, optional) – One or more particle categories. This method will returnFalseif the particle belongs to any of these categories.
See also
valid_categoriesA
setcontaining all valid particle categories.
Notes
Valid particle categories are given in
valid_categoriesand 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, ortupleof 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
requirekeyword argument.>>> electron.is_category(require="lepton") True >>> electron.is_category(require=["lepton", "baryon"]) False
This method will return
Falseif the particle does not belong to at least one of the categories provided with theany_ofkeyword argument.>>> electron.is_category(any_of=["lepton", "baryon"]) True >>> electron.is_category(any_of=("noble gas", "lanthanide", "halogen")) False
This method will return
Falseif the particle belongs to any of the categories provided in theexcludekeyword argument.>>> electron.is_category(exclude="baryon") True >>> electron.is_category(exclude={"lepton", "baryon"}) False
The
require,any_of, andexcludekeywords 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_dictto thefpfile 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_dictinto a JSON formattedstrusingjson.dumps.- Parameters:
**kwargs – Any keyword accepted by
json.dumps.- Returns:
JSON formatted
str.- Return type: