Skip to main content

Fast Kearsley 3D superposition (RMSD minimization) using Numba JIT

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kearsley_numba-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kearsley_numba-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file kearsley_numba-0.1.0.tar.gz.

File metadata

  • Download URL: kearsley_numba-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kearsley_numba-0.1.0.tar.gz
Algorithm Hash digest
SHA256 16ba9e3540b74d68464a8bfc709492c7169a7fe0e3fb13baa1988668e95863f7
MD5 b908a543fae8e7b42016f9c7d8eb935b
BLAKE2b-256 1bfd51f5d85c4f27656fb9f4a89bf949a131ba40da686f47e6aa9ad019ecfa9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for kearsley_numba-0.1.0.tar.gz:

Publisher: ci.yml on bigbigdumdum/kearsley_numbajit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kearsley_numba-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kearsley_numba-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kearsley_numba-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1d257cff9af71981b175828fc2a80ac3b63a2569f7c099309ed26e0b8bb923f
MD5 5877ea5e1445211dbe7b0807878b83d8
BLAKE2b-256 e4d9c3233a87af9c3847ea280cf16e53562d076ab47778387647529cecf17990

See more details on using hashes here.

Provenance

The following attestation bundles were made for kearsley_numba-0.1.0-py3-none-any.whl:

Publisher: ci.yml on bigbigdumdum/kearsley_numbajit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page