Extend the Visualize solutions notebook with an example that renders only the $J^{PC}$ numbers (spin, parity, $C$ parity; see also #272). It's essentially just an example like the one with the render_mass() converter, but now for render_jpc(). Optionally, one can include $I^G$ (isospin, $G$ parity).
As a bonus, we can render the transitions with qrules.io.asdot(..., collapse_graphs=True). This requires some minor generalizations to the implementation of the io._dot module.
Implementation sketch
Modified version of `render_mass()` from [Visualize solutions](https://qrules.readthedocs.io/0.10.x/usage/visualize.html#other-state-renderings) for $J^{PC}$:
```python
from fractions import Fraction
def render_jpc(state: State, digits: int = 3) -> str:
particle = state.particle
text = render_fraction(particle.spin)
if particle.parity is not None:
text += render_sign(particle.parity)
if particle.parity is not None:
text += render_sign(particle.c_parity)
return text
def render_fraction(value: float) -> str:
fraction = Fraction(value)
if fraction.denominator == 1:
return str(fraction.numerator)
return f"{fraction.numerator}/{fraction.denominator}"
def render_sign(parity: int) -> str:
if parity == -1:
return "⁻"
if parity == +1:
return "⁺"
raise NotImplementedError
jpc_transitions = sorted({
t.convert(
state_converter=render_jpc,
interaction_converter=lambda _: None,
)
for t in reaction.transitions
})
dot = qrules.io.asdot(jpc_transitions)
graphviz.Source(dot)
```
### Tasks
- [ ] Write example with `render_jpc()`
- [ ] Modify `asdot()` implementation so that it can handle `str` on the edges
- [ ] [Optional] Include I^G
Extend the Visualize solutions notebook with an example that renders only the $J^{PC}$ numbers (spin, parity, $C$ parity; see also #272). It's essentially just an example like the one with the
render_mass()
converter, but now forrender_jpc()
. Optionally, one can include $I^G$ (isospin, $G$ parity).For an example, see the PDG entry for $\pi^0$: https://pdglive.lbl.gov/Particle.action?init=0&node=S009&home=MXXX005
As a bonus, we can render the transitions with
qrules.io.asdot(..., collapse_graphs=True)
. This requires some minor generalizations to the implementation of theio._dot
module.Implementation sketch
Modified version of `render_mass()` from [Visualize solutions](https://qrules.readthedocs.io/0.10.x/usage/visualize.html#other-state-renderings) for $J^{PC}$: ```python from fractions import Fraction def render_jpc(state: State, digits: int = 3) -> str: particle = state.particle text = render_fraction(particle.spin) if particle.parity is not None: text += render_sign(particle.parity) if particle.parity is not None: text += render_sign(particle.c_parity) return text def render_fraction(value: float) -> str: fraction = Fraction(value) if fraction.denominator == 1: return str(fraction.numerator) return f"{fraction.numerator}/{fraction.denominator}" def render_sign(parity: int) -> str: if parity == -1: return "⁻" if parity == +1: return "⁺" raise NotImplementedError jpc_transitions = sorted({ t.convert( state_converter=render_jpc, interaction_converter=lambda _: None, ) for t in reaction.transitions }) dot = qrules.io.asdot(jpc_transitions) graphviz.Source(dot) ```