CustomParticle¶
-
class
plasmapy.particles.
CustomParticle
(mass: Unit("kg") = None, charge: (Unit("C"), <class 'numbers.Real'>) = None)¶ Bases:
plasmapy.particles.particle_class.AbstractParticle
A class to represent custom particles.
Example use cases for this class include representing an average ion in a multi-component plasma, molecules, or dust grains.
Parameters: - mass (Quantity, optional) – The mass of the custom particle in units of mass.
- charge (Quantity or Real) – The electric charge of the custom particle. If provided as a
Quantity
, then it must be in units of electric charge. If provided as a real number, then it is treated as the ratio of the charge to the elementary charge.
Raises: InvalidParticleError
– If the charge or mass provided is invalid so that the custom particle cannot be created.See also
~plasmapy.particles.Particle ~plasmapy.particles.DimensionlessParticle
Notes
If the charge or mass is not specified, then the corresponding value will be set to
numpy.nan
in the appropriate units.Examples
>>> from astropy import units as u >>> from plasmapy.particles import CustomParticle >>> custom_particle = CustomParticle(mass=1.5e-26 * u.kg, charge=-1) >>> custom_particle.mass <Quantity 1.5e-26 kg> >>> custom_particle.charge <Quantity -1.60217...e-19 C>
Attributes Summary
charge
Return the custom particle’s electric charge in coulombs. json_dict
A json
friendly dictionary representation of the particle.mass
Return the custom particle’s mass. Methods Summary
json_dump
(fp, **kwargs)Writes 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
-
charge
¶ Return the custom particle’s electric charge in coulombs.
-
json_dict
¶ A
json
friendly dictionary representation of the particle. (seeAbstractParticle.json_dict
for more details)Examples
>>> custom_particle = CustomParticle(mass=5.12 * u.kg, charge=6.2 * u.C) >>> custom_particle.json_dict {'plasmapy_particle': {'type': 'CustomParticle', 'module': 'plasmapy.particles.particle_class', 'date_created': '...', '__init__': {'args': (), 'kwargs': {'mass': '5.12 kg', 'charge': '6.2 C'}}}} >>> custom_particle = CustomParticle(mass=1.5e-26 * u.kg) >>> custom_particle.json_dict {'plasmapy_particle': {'type': 'CustomParticle', 'module': 'plasmapy.particles.particle_class', 'date_created': '...', '__init__': {'args': (), 'kwargs': {'mass': '1.5e-26 kg', 'charge': 'nan C'}}}}
-
mass
¶ Return the custom particle’s mass.
Methods Documentation
-
json_dump
(fp, **kwargs)¶ Writes 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
.
- fp (file object) – Destination file object to write the JSON serialized
-
json_dumps
(**kwargs) → 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: str