Kearsley's algorithm
Kearsley's algorithm calculates the rotaiton and translation required to superimposed two sets of cordinates by minimizing their RMSD.
This is a faster implementation of the python implementation by Marcelo Moreno (martxelo) (https://github.com/martxelo/kearsley-algorithm) using numba njit.
Benchmarks by %timeit for fitting 10 atoms
Original version: 215 µs ± 27.9 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
This version: 9.62 µs ± 124 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
A cpython implementation might be faster.
Usage
My application needed fit_tansform to also computer structure overlap, which is the percentage of atoms withing a distance cutoff.
u,v = read_from_data()
# these have to be of the numpy arrays of shape (N,3) where the N must be the same for both u and v
# so_dc is the distance cutoff used to compute structure overlap. Has to be a float.
so_dc = 1.0
from kearsley import fit_transform
# get cordinates of v transformedt to u, RMSD, SO, and the rotation and translation matrices as numpy arrays
transformed_v, rmsd , so, rotation, translation = fit_transform(u, v, so_dc)
If only rmsd needs to be computed
from kearsley import fit
rmsd, q, centroid_u, centroid_v = fit(u, v)
# rotation and translation matrices can be computed by
from kearsley import fill_rot_and_trans
centroid_u_ = np.empty(3,dtype=float)
rotation = np.empty((3,3),dtype=float)
rotation,translation = fill_rot_and_trans(q,centroid_u,centroid_v,rotation,centroid_u_)
If rotationand translation matrices are already computed transform function can transform an array of shape (M,3). Note that the M can be different to N. This function, for example, allows fitting a subset of coordinates and then applying that transformation to all coordinates.
from kearsley import fit_transform,transform
u,v = read_from_data() # shape (N,3)
w = read_all_cordinantes() # w is the superset of v. and is of the shape (M,3) M>N
transformed_v, rmsd , so, rotation, translation = fit_transform(u, v, so_dc)
# get transformed w
tra_v = transform(w,rotation,translation)
Packages and version used
The following are the packages and version which this script was last tested with.
python = 3.12.2
numpy = 1.26.4
numba = 0.59.1
Metadata
Release files for kearsley-numba 0.1.0
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 | Actions |
|---|---|---|---|---|
| kearsley_numba-0.1.0.tar.gz | 5.8 kB | With provenance | Details for kearsley_numba-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kearsley_numba-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for kearsley_numba-0.1.0-py3-none-any.whl |
Total release size: 11.8 kB
Release files / kearsley_numba-0.1.0.tar.gz
| Download URL | kearsley_numba-0.1.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16ba9e3540b74d68464a8bfc709492c7169a7fe0e3fb13baa1988668e95863f7
|
|
BLAKE2b-256 checksum How to use checksums |
1bfd51f5d85c4f27656fb9f4a89bf949a131ba40da686f47e6aa9ad019ecfa9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 7, 2026.
Transparency logRelease files / kearsley_numba-0.1.0-py3-none-any.whl
| Download URL | kearsley_numba-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1d257cff9af71981b175828fc2a80ac3b63a2569f7c099309ed26e0b8bb923f
|
|
BLAKE2b-256 checksum How to use checksums |
e4d9c3233a87af9c3847ea280cf16e53562d076ab47778387647529cecf17990
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 7, 2026.
Transparency logSecurity for kearsley-numba 0.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for kearsley_numba-0.1.0.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 May 7, 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.