Using the Python API
This page documents the Python API.
The main API is in the apitofsim.api module, most of which is re-exported from apitofsim.
Data classes
These classes input data to the simulation, as well as output data from intermediate steps in the simulation.
apitofsim.api.ClusterLike
Bases: ABC
A base class for cluster-like things.
get_frequencies
abstractmethod
This method returns an array of vibrational temperatures in Kelvin. In the case of an atom-like product this will return None.
apitofsim.ClusterData
dataclass
ClusterData(
mass: Quantity[float],
electronic_energy: Quantity[float],
rotations: ndarray,
frequencies: ndarray,
)
Bases: ClusterLike
The basic physical data for a cluster.
electronic_energy
instance-attribute
The cluster's electronic energy
frequencies
instance-attribute
From quantum chemistry calcuations, the vibrational temperatures in Kelvin for the cluster.
rotations
instance-attribute
From quantum chemistry calcuations, the rotational temperatures in Kelvin for the cluster. This is a 3 element array.
get_frequencies
into_cpp
Source code in python/apitofsim/api.py
apitofsim.ProductsCluster
dataclass
ProductsCluster(
cluster1: ClusterData, cluster2: ClusterData
)
Bases: ClusterLike
A combination of two clusters representing the products of a fragmentation pathway. This is used to compute the density of states and derived quantities for the pathway products at the point of collision.
get_frequencies
Source code in python/apitofsim/api.py
apitofsim.Gas
dataclass
The physical quantities related to gas in the mass spectrometer
apitofsim.Histogram
dataclass
A container for histogrammed data used to store precomputed density of states and rate constants.
You should not typically need to construc this yourself.
from_cpp
classmethod
from_mesh
classmethod
apitofsim.Quadrupole
dataclass
Quadrupole(
dc_field: Quantity[float],
ac_field: Quantity[float],
radiofrequency: Quantity[float],
r_quadrupole: Quantity[float],
)
Configuration values related to the quadrupole mass filter in the mass spectrometer, if present
-
Reference
Using the Python API
Data classes
MassSpectrometer
r_quadrupole
instance-attribute
The distance from the center of the quadrupole to the rods
radiofrequency
instance-attribute
The radiofrequency of the AC voltage applied to the quadrupole rods
into_cpp
apitofsim.MassSpecInputFragmentationPathway
Construct a MassSpecInputFragmentationPathway
Source code in python/apitofsim/api.py
apitofsim.MassSpecSubstanceInput
Construct a MassSpecSubstanceInput
Source code in python/apitofsim/api.py
apitofsim.MassSpectrometer
dataclass
MassSpectrometer(
skimmer: ndarray,
lengths: Quantity[ndarray],
voltages: Quantity[ndarray],
T: Quantity[float],
pressures: Quantity[ndarray],
*,
mesh_skimmer: Quantity[float] | None = None,
quadrupole: Quadrupole | None = None,
radius_pinhole: Quantity[float] | None = Q_(1, "mm"),
)
The configuration values needed to simulate the mass spectrometer as well as the precomputed, histogrammed skimmer values.
lengths
instance-attribute
An array of the lengths of the different sections of the mass spectrometer
mesh_skimmer
class-attribute
instance-attribute
The histogram mesh size used for the precomputed, histogrammed skimmer quantities. If not given this will be computed from the skimmer array if it has 6 columns, otherwise it must be supplied.
pressures
instance-attribute
The pressures in the two chambers of the mass spectrometer
quadrupole
class-attribute
instance-attribute
quadrupole: Quadrupole | None = None
The quadrupole configuration, if a quadrupole is present in the mass spectrometer.
radius_pinhole
class-attribute
instance-attribute
The radius of the pinhole in the skimmer, if present.
skimmer
instance-attribute
A 2D array of values along the skimmer, with either XXXXCHECK 3 columns (r, vel, T) or 6 columns (x, r, vel, T, P, rho)
voltages
instance-attribute
The voltages applied at different points on the mass spectrometer
__post_init__
Source code in python/apitofsim/api.py
into_cpp
Source code in python/apitofsim/api.py
Workflow interface
The apitofsim.workflow module, contains functions to keep cluster data in a database, convenient for running scaled-up simulations.
Typically an ExperimentDatabase is created and its tables created with db.create_tables(...) and then clusters are ingested e.g. with ingest_tree(...).
After this, multiple simulation can be run using the ExperimentRunner class.
apitofsim.workflow.ClusterDatabase
Source code in python/apitofsim/workflow/db.py
__del__
_cluster_obj_from_tuple
staticmethod
_setup_db
close
clusters_df
clusters_dicts_indexed
clusters_objects_indexed
Source code in python/apitofsim/workflow/db.py
clusters_query
Source code in python/apitofsim/workflow/db.py
create_tables
get_all_lookups
Source code in python/apitofsim/workflow/db.py
insert_ase
Source code in python/apitofsim/workflow/db.py
insert_cluster
insert_cluster(
name,
atomic_mass,
charge,
electronic_energy,
rotational_temperatures,
vibrational_temperatures,
import_info=None,
*,
ase_id=None,
allow_duplicates=False,
)
Source code in python/apitofsim/workflow/db.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
insert_pathway
iter_clusters_dicts
iter_clusters_objects
pathways_ids
Source code in python/apitofsim/workflow/db.py
pathways_objs
Source code in python/apitofsim/workflow/db.py
pathways_query
Source code in python/apitofsim/workflow/db.py
apitofsim.workflow.SuperClusterDatabase
apitofsim.workflow.ExperimentDatabase
Bases: SuperClusterDatabase
Source code in python/apitofsim/workflow/db.py
TABLES
class-attribute
instance-attribute
forget
Source code in python/apitofsim/workflow/db.py
insert_config
Source code in python/apitofsim/workflow/db.py
insert_run
Source code in python/apitofsim/workflow/db.py
is_experiment_db
iter_configs
Source code in python/apitofsim/workflow/db.py
record_failure
Source code in python/apitofsim/workflow/db.py
record_result
Source code in python/apitofsim/workflow/db.py
apitofsim.workflow.ingest_tree
ingest_tree(
db: ClusterDatabase,
pathways,
path_base,
descriptor=None,
ingest_ase=None,
)
Ingest a tree of fragmentation pathways into the database.
-
pathwayscan be a list or single element, and matches the configuration -
path_baseis used to resolve relative paths in the config -
descriptoris used in case the config is parsed from TOML, to provide line numbers for errors, and so not typically used outside apitofsim itself. -
ingest_aseis a boolean that controls whether to ingest ASE information. By default, it will be be true iff you pass aClusterDatabase.
Source code in python/apitofsim/workflow/ingest.py
apitofsim.workflow.ExperimentRunner
ExperimentRunner(db: ExperimentDatabase)
This class helps with running the simulation across configs and clusters/pathways in an ExperimentDatabase.
It also records results and failures back into the database, and can optionally print progress tables to the terminal.
It precomputes all histograms of density of states and rate constants as needed, and caches them in the database for future runs.
Source code in python/apitofsim/workflow/runners.py
_guard_run_started
_mk_update_from_counters
Source code in python/apitofsim/workflow/runners.py
_run_cluster_grouped
_run_cluster_grouped(
mass_spec,
config,
cluster_indexed,
name_lookup,
pathway_lookup,
k_rates,
cluster_dos,
strict_dos=True,
verbose=False,
)
Source code in python/apitofsim/workflow/runners.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
_run_pathways_at_a_time
_run_pathways_at_a_time(
mass_spec,
config,
cluster_indexed,
name_lookup,
pathway_lookup,
k_rates,
cluster_dos,
strict_dos=True,
parent=None,
verbose=False,
)
Source code in python/apitofsim/workflow/runners.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
run_from_config
run_from_config(
config,
run_started=False,
strict_dos=True,
pathway_at_a_time=False,
parent=None,
pathways=None,
verbose=False,
)
Source code in python/apitofsim/workflow/runners.py
run_mass_spec
run_mass_spec(
*args,
pathway_id=None,
cluster_id=None,
pathway_ids=None,
strict=False,
strict_dos=True,
**kwargs,
)
Source code in python/apitofsim/workflow/runners.py
run_prepared_config
Run from an experiment config that has been inserted into an ExperimentDatabase.
nameis the name of an experiment config, a list thereof, or None to run all configs
Source code in python/apitofsim/workflow/runners.py
Individual simulation functions
The individual simulation functions are the low level interface to the simulation.
apitofsim.mass_spec
mass_spec(
mass_spec: MassSpectrometer,
subs: MassSpecSubstanceInput,
N: int,
*,
sample_mode: SampleMode = rejection,
strict=True,
loglevel: int = 0,
seed: int = 42,
log_callback: Callable[[str, str], None] | None = None,
result_callback: Callable[[ndarray], None]
| None = None,
named_tuple_counters=False,
output_timings=False,
)
This function runs the main simulation of the APi-ToF mass spectrometer.
Source code in python/apitofsim/api.py
apitofsim.compute_density_of_states_batch
compute_density_of_states_batch(
clusters: List[ClusterLike],
energy_max: MaybeQuantity,
bin_width: MaybeQuantity,
use_old_impl=False,
*,
quantities_strict=True,
)
Source code in python/apitofsim/api.py
apitofsim.precompute_mesh
precompute_mesh(
energy_max_rate: MaybeQuantity,
bin_width: MaybeQuantity,
mesh_mode: MeshMode = compute_mesh_diagonal_multithreaded,
*,
quantities_strict=True,
)
Source code in python/apitofsim/api.py
apitofsim.compute_k_total_batch
compute_k_total_batch(
inputs: List[KTotalInput],
energy_max_rate: MaybeQuantity,
bin_width: MaybeQuantity,
mesh: MeshMode
| ndarray = compute_mesh_diagonal_multithreaded,
progress_callback: Callable[[int], None] | None = None,
*,
quantities_strict=True,
)
Source code in python/apitofsim/api.py
apitofsim.densityandrate
densityandrate(
cluster_0: ClusterData,
cluster_1: ClusterData,
cluster_2: ClusterData,
energy_max: MaybeQuantity,
energy_max_rate: MaybeQuantity,
bin_width: MaybeQuantity,
fragmentation_energy: MaybeQuantity | None = None,
*,
quantities_strict=True,
)
This function precomputes the density of states and rate constants histograms for a given set of clusters.
Source code in python/apitofsim/api.py
apitofsim.skimmer
skimmer(
T0: MaybeQuantity,
P0: MaybeQuantity,
rmax: MaybeQuantity,
dc: MaybeQuantity,
alpha_factor: MaybeQuantity,
gas: Gas | Gas,
N: int,
M: int,
resolution: int,
tolerance: float,
*,
output_pandas=False,
quantities_strict=True,
)
This function precomputes various parameters including gas velocity, temperature and pressure at fixed points along the skimmer's' length.