Skip to main content

diatomic-py

Code Quality Status Test Suite Status

Python package to calculate the hyperfine energy levels of singlet sigma diatomic molecules (e.g. RbCs, KCs and KRb) under various applied fields. The hyperfine structure can be calculated in static electric and magnetic fields and, when provided the polarisability, oscillating electric fields.

More detailed information can be found in the documentation at https://diatomic-py.readthedocs.io .

Diatomic-py is licensed under a BSD 3 clause license, a copy can be found here.

If you use our work for academic purposes you can cite us using:

J.A.Blackmore et al. Diatomic-py: A python module for calculating the rotational and hyperfine structure of \(^1\Sigma\) molecules, [Arxiv e-prints 2205.05686](https://arxiv.org/abs/2205.05686) (2022).

This work has continued to evolve since the release of the paper, and so the API is different.

PyPi Installation

python -m pip install diatomic-py

Manual Installation

Clone the repository:

git clone https://github.com/durham-qlm/diatomic-py.git
cd diatomic-py

It is recommended to then install the python package into virtual environment:

# You may need to substitute `python` for `python3` if you're on macOS
python -m venv ./venv
source ./venv/bin/activate
# After activating the virtual env you should only need `python`
python --version
which python

The below installation commands assume you are active in such an environment. You can then install the package, adding optional user-facing features with extras:

# Installs essentials only
python -m pip install .

# Installs essentials + plotting support
python -m pip install ".[plotting]"

# Installs plotting support and optional progress bars
python -m pip install ".[plotting,progress]"

Development dependencies are managed with dependency groups. With uv:

uv sync --group dev
uv run pre-commit install
uv run pytest

Example

import numpy as np
import matplotlib.pyplot as plt
import scipy.constants

from diatomic.systems import SingletSigmaMolecule
import diatomic.operators as operators
import diatomic.calculate as solver

GAUSS = 1e-4  # T
MHz = scipy.constants.h * 1e6

# Generate Molecule
mol = SingletSigmaMolecule.from_preset("Rb87Cs133")
mol.Nmax = 2

# Generate Hamiltonians
H0 = operators.hyperfine_ham(mol)
Hz = operators.zeeman_ham(mol)

# Parameter Space
B = np.linspace(0.001, 300, 50) * GAUSS

# Overall Hamiltonian
Htot = H0 + Hz * B[:, None, None]

# Solve (diagonalise) Hamiltonians
eigenenergies, eigenstates = solver.solve_system(Htot)

# Plot results
fig, (ax_up, ax_down) = plt.subplots(2, 1, sharex=True)

ax_down.plot(B / GAUSS, eigenenergies[:, 0:32] / MHz, c="k", lw=0.5, alpha=0.3)
ax_up.plot(B / GAUSS, eigenenergies[:, 32:128] / MHz, c="k", lw=0.5, alpha=0.3)

ax_down.set_xlabel("Magnetic Field (G)")
fig.supylabel("Energy / h (MHz)")

plt.show()
Resulting plot of above example

For more examples of usage, see the ./examples folder.

Metadata

Release files for diatomic-py 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for diatomic-py 2.1.0
File Size Uploaded Provenance Actions
diatomic_py-2.1.0.tar.gz 34.2 kB Without provenance Details for diatomic_py-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for diatomic-py 2.1.0
File Interpreter ABI Platform Actions
diatomic_py-2.1.0-py3-none-any.whl Python 3 none any Details for diatomic_py-2.1.0-py3-none-any.whl

Total release size: 63.4 kB

Release files / diatomic_py-2.1.0.tar.gz

Download URL diatomic_py-2.1.0.tar.gz
Size 34.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7924a8a0524de41e2f102d41e29d94dfd829c2ad1c17ab370d7b0ba1d1af1eae
BLAKE2b-256 checksum
How to use checksums
50e9186f01f32c5047331a4dab499ac94caffe6b99de1b9da7f1da8e032e5b5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / diatomic_py-2.1.0-py3-none-any.whl

Download URL diatomic_py-2.1.0-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2478e2736e88368645ae33ac05d9d059ea120cb4b7726e92e7af85dfb94f86c8
BLAKE2b-256 checksum
How to use checksums
05edb11eb62991d7f2a48b41d56d81a0ad05c9713913240a1284b0477321a013
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for diatomic-py 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page