hklforge
Diffractometer angle calculations for any geometry, with solvers that are generated exactly from the geometry rather than hand-written for one instrument (diffcalc) or found by numerical search (libhkl, ad_hoc_diffractometer).
Status: the geometry model, the exact sub-problems, the planner (geometry + mode -> all solutions) and all of diffcalc's virtual angles (psi, naz, qaz, alpha/beta, betain/betaout, omega/bisect, ...) exist and are tested against diffcalc (all 194 modes), libhkl (all 13 E6C modes), xrayutilities and the Bernina two-reflection solver.
Documentation: docs/ - virtual angles
with 3D figures, modes, verification.
Example notebooks: examples/. Design notes and roadmap: CLAUDE.md.
from hklforge import Geometry
psic = Geometry.builtin("psic") # You (1999) six-circle, as diffcalc
custom = Geometry.from_xrayutilities( # xrayutilities' QConversion syntax
sample=["x+", "z-", "y+", "z-"], detector=["x+", "z-"], r_i=(0, 1, 0))
psic.q_phi({"mu": 0, "eta": 10, "chi": 0, "phi": 0, "nu": 0, "delta": 20}, k=4.5)
from hklforge import Diffractometer
from hklforge.lattice import b_matrix
ub = b_matrix(5.431, 5.431, 5.431) # phi frame, q = UB h (U = 1)
d = Diffractometer(psic, ub, energy=9000, surface_hkl=(0, 0, 1), reference_hkl=(0, 0, 1))
d.solve((1, 1, 2), {"eta": 0, "chi": 0, "phi": 0}) # every branch, as dicts of degrees
d.solve((1, 1, 2), {"chi": 10, "phi": 20, "betain": 5})
d.solve((1, 1, 1), {"mu": 0, "nu": 0, "h2": (2, 2, 0)}) # double diffraction, detector on h1
d.solve((1, 1, 1), {"eta": 0, "chi": 0, "h2": (2, 2, 0)}, detector="between")
d.solve((1, 1, 2), {"mu": 0, "nu": 0, "psi": 30}) # needs reference= / reference_hkl=
d.solve((1, 1, 2), {"nu": 0, "bisect": True, "omega": 0}) # bisecting
print(d.plan({"chi": 10, "phi": 20, "betain": 5}).describe())
angles = d.solve((1, 1, 2), {"mu": 0, "nu": 0, "betain": 2})[0]
d.pseudo(angles) # all virtual angles of a position
from hklforge.draw import draw # 3D drawing (matplotlib)
draw(d, angles, show=("ttheta", "psi"))
Tests (pytest) compare against diffcalc-core and xrayutilities.
License
BSD 3-Clause, see LICENSE. The software is provided "as is", without warranty of any kind. Check computed angles against your instrument's limits before moving motors.
Metadata
Release files for hklforge 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| hklforge-0.0.1.tar.gz | 33.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hklforge-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 60.8 kB
Release files / hklforge-0.0.1.tar.gz
| Download URL | hklforge-0.0.1.tar.gz |
|---|---|
| Size | 33.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
950de85f132c9554b19f6fc64d8eecd7137536ff77d2a47471a9e26fd480e31e
|
|
BLAKE2b-256 checksum How to use checksums |
777c8c918898964fd8f4706156213eddb88aa1b7edf1fd409990cc23874dcdc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logRelease files / hklforge-0.0.1-py3-none-any.whl
| Download URL | hklforge-0.0.1-py3-none-any.whl |
|---|---|
| Size | 27.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
694c25e9560dbab6de7dc3c2f4caee2f585c70edefe5e623addc39d752977c66
|
|
BLAKE2b-256 checksum How to use checksums |
b982952d305b75d352748ae0b5d14fb6ca1fd152fde6f6eb78f3b95f758a0a67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logSecurity for hklforge 0.0.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for hklforge-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logA 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.