Some of the demos assume you have run python -m pip install particle
. The demos use Python 3, though the package also supports Python 2 for now. You can view the demo here or run it here on Binder.
There are two modules in Particle
:
!python -m particle -h
!python -m particle --version
!python -m particle pdgid 211
!python -m particle search 211
!python -m particle search "pi+"
!python -m particle search "pi(1400)+"
We also have released a new ZipApp version - one file that runs on any computer with Python, no other dependencies! Find it attached to releases starting with version 0.4.4.
Example:
./particle.pyz search gamma
All dependencies (including the two backports) are installed inside the ZipApp, and the data lookup is handled in a zip-safe way inside particle. Python 3 is used to make the zipapp, but including the backports makes it work on Python 2 as well.
The command line mode could be enhanced to make it a useful tool in bash scripts! Stay tuned...
from particle import PDGID, Particle, Charge
p = PDGID(211)
p
print(p.info())
Particle
has literals, as well; these are dynamically generated on import for both PDGID and Particle classes!
import particle.pdgid.literals as pdgid_literals
pdgid_literals.phi_1020
There are lots of ways to create a particle:
Particle.from_pdgid(211)
import particle.literals as particle_literals
particle_literals.phi_1020
The most powerful methods: findall
and finditer
.
(p,) = Particle.finditer(
"phi(1020)"
) # syntax (p,) throws an error if < 1 or > 1 particle is found
p
You can specify search terms as keywords - any particle property:
p = Particle.finditer(latex_name=r"\phi(1020)")
next(p)
Some properties have enums available. For example, you can directly check the numeric charge:
Particle.findall("pi", charge=-1)
Or you can use the enum (for charge, this is 3 times the charge, hence the name three_charge
)
Particle.findall("pi", three_charge=Charge.p)
Or use a lambda function for the ultimate in generality! For example, to find all the neutral particles with a bottom quark between 5.2 and 5.3 GeV:
from hepunits import GeV, s # Units are good. Use them.
Particle.findall(
lambda p: p.pdgid.has_bottom and p.charge == 0 and 5.2 * GeV < p.mass < 5.3 * GeV
)
Another lambda function example: You can use the width or the lifetime:
Particle.findall(lambda p: p.lifetime > 1000 * s)
If you want infinite lifetime, you could just use the keyword search instead:
Particle.findall(lifetime=float("inf"))
Nice display in Jupyter notebooks, as well as str
and repr
support:
p = particle_literals.D_0
p
print(p)
print(repr(p))
Full descriptions:
print(p.describe())
You may find LaTeX or HTML to be more useful in your program, both are supported:
print(p.latex_name, p.html_name)
It is easy to get hold of the whole list of particle (instances) as a list:
all_particles = Particle.all()
print(f'The package "DB" contains {len(all_particles)} particles:')
all_particles
And it is just as easy to rather get a list of PDG IDs (as int
s):
[int(p.pdgid) for p in all_particles]
You can do things to particles, like invert them:
~p
There are a plethora of properties you can access:
p.spin_type
You can quickly access the PDGID of a particle:
p.pdgid
You can:
Particle
Now let's look at one of the users of Particle
: the DecayLanguage package!