-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC: show how to combine
ReactionInfo
objects
- Loading branch information
Showing
2 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,263 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": true, | ||
"hidePrompt": true, | ||
"jupyter": { | ||
"source_hidden": true | ||
}, | ||
"slideshow": { | ||
"slide_type": "skip" | ||
}, | ||
"tags": [ | ||
"remove-cell", | ||
"skip-execution" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# WARNING: advised to install a specific version, e.g. qrules==0.1.2\n", | ||
"%pip install -q qrules[doc,viz] IPython" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": true, | ||
"hidePrompt": true, | ||
"jupyter": { | ||
"source_hidden": true | ||
}, | ||
"slideshow": { | ||
"slide_type": "skip" | ||
}, | ||
"tags": [ | ||
"remove-cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%config InlineBackend.figure_formats = ['svg']\n", | ||
"import os\n", | ||
"\n", | ||
"STATIC_WEB_PAGE = {\"EXECUTE_NB\", \"READTHEDOCS\"}.intersection(os.environ)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"```{autolink-concat}\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Combining reactions" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"This notebooks shows how to combine two {class}`.ReactionInfo` objects that describe transitions for one equivalent initial-to-final state reaction. In this example, we have one {class}`.ReactionInfo` object that is generated all selection rules for the strong force and one that is generated for with {ref}`specific interaction types per node <usage/reaction#Select interaction types>`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import qrules\n", | ||
"\n", | ||
"initial_state = [(\"J/psi(1S)\", [-1, +1])]\n", | ||
"final_state = [\"eta\", \"p\", \"p~\"]\n", | ||
"reaction = qrules.generate_transitions(\n", | ||
" initial_state,\n", | ||
" final_state,\n", | ||
" allowed_intermediate_particles=[\"N\"],\n", | ||
" allowed_interaction_types=\"strong\",\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"editable": true, | ||
"jupyter": { | ||
"source_hidden": true | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"hide-input" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import graphviz\n", | ||
"\n", | ||
"src = qrules.io.asdot(reaction.transitions, collapse_graphs=True)\n", | ||
"graphviz.Source(src)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qrules.particle import Particle\n", | ||
"\n", | ||
"PDG = qrules.load_pdg()\n", | ||
"X1835 = Particle(\n", | ||
" # https://pdglive.lbl.gov/Particle.action?init=0&node=M085&home=MXXX005\n", | ||
" name=\"X(1835)\",\n", | ||
" pid=9999991,\n", | ||
" mass=1.8265,\n", | ||
" width=0.242,\n", | ||
" spin=0,\n", | ||
" parity=-1,\n", | ||
" c_parity=+1,\n", | ||
")\n", | ||
"PDG.add(X1835)\n", | ||
"reaction_x1835 = qrules.generate_transitions(\n", | ||
" initial_state,\n", | ||
" final_state,\n", | ||
" allowed_intermediate_particles=[X1835.name],\n", | ||
" particle_db=PDG,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"editable": true, | ||
"jupyter": { | ||
"source_hidden": true | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"hide-input" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import graphviz\n", | ||
"\n", | ||
"src = qrules.io.asdot(reaction_x1835.transitions, collapse_graphs=True)\n", | ||
"graphviz.Source(src)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from collections import defaultdict\n", | ||
"\n", | ||
"from qrules.transition import ReactionInfo, StateTransitionCollection\n", | ||
"\n", | ||
"\n", | ||
"def merge_reactions(*reactions: ReactionInfo) -> ReactionInfo:\n", | ||
" old_groups = []\n", | ||
" for reaction in reactions:\n", | ||
" old_groups.extend(reaction.transition_groups)\n", | ||
" merged_transitions = defaultdict(list)\n", | ||
" for group in old_groups:\n", | ||
" merged_transitions[group.topology].extend(group.transitions)\n", | ||
" transition_groups = {\n", | ||
" topology: StateTransitionCollection(transitions)\n", | ||
" for topology, transitions in merged_transitions.items()\n", | ||
" }\n", | ||
" return ReactionInfo(transition_groups.values(), formalism=reaction.formalism)\n", | ||
"\n", | ||
"\n", | ||
"merged_reaction = merge_reactions(reaction, reaction_x1835)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"editable": true, | ||
"jupyter": { | ||
"source_hidden": true | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"hide-input" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import graphviz\n", | ||
"\n", | ||
"src = qrules.io.asdot(merged_reaction.transitions, collapse_graphs=True)\n", | ||
"graphviz.Source(src)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |