Skip to main content

NeRF

A Numpy Implementation of the NeRF Algoritm for Global and Internal Molecular Coordinate Conversion

Installation

pip install pynerf

Format

import numpy as np

# Global coordinates for the molecule: CCCCC(C)CCCc1ccccc1
# X, Y, Z
XYZ = np.array([
    [-3.85918113,  1.96727702, -0.90964251],
    [-3.18010648,  0.73561076, -1.50023432],
    [-2.59821482, -0.0276012 , -0.32047649],
    [-1.89223409, -1.27462464, -0.74157415],
    [-1.36589543, -1.96407604,  0.4887215 ],
    [-2.5080429 , -2.32882212,  1.43590953],
    [-0.42564473, -1.07397927,  1.26079092],
    [ 0.74822042, -0.69585885,  0.37285949],
    [ 1.64031545,  0.1825755 ,  1.22863933],
    [ 2.84575382,  0.63093342,  0.47241165],
    [ 2.86522176,  1.79613148, -0.26713038],
    [ 3.99177109,  2.19435562, -0.96077995],
    [ 5.14810842,  1.44285119, -0.9439963 ],
    [ 5.1362438 ,  0.27652072, -0.20673226],
    [ 4.0076203 , -0.12008426,  0.48671673]
])

# Internal coordinates for the molecule: CCCCC(C)CCC
# BondLength, BondAngle (Deg/Rad), BondTorsion (Deg/Rad)
DOF = np.array([
    [0.000,   0.000,    0.000],
    [1.525,   0.000,    0.000],
    [1.521, 105.973,    0.000],
    [1.494, 112.404, -180.000],
    [1.505, 108.496, -179.436],
    [1.528, 110.770,   60.154],
    [1.507, 111.484, -118.831],
    [1.520, 109.236,  -59.789],
    [1.517, 105.593, -179.530],
    [1.492, 111.304,  179.999],
    [1.380, 122.458,   89.997],
    [1.382, 121.590,  179.999],
    [1.379, 121.364,    0.000],
    [1.380, 117.378,    0.000],
    [1.383, 121.159,    0.000],
])

# Custom dependencies with branch
# PrevAtom1, PrevAtom2, PrevAtom3
DEP = np.array([
    [ 0,  0,  0],
    [ 0,  0,  0],
    [ 1,  0,  0],
    [ 2,  1,  0],
    [ 3,  2,  1],
    [ 4,  3,  2],
    [ 4,  3,  5], # <- Branch Point
    [ 6,  4,  3],
    [ 7,  6,  4],
    [ 8,  7,  6],
    [ 9,  8,  7],
    [10,  9,  8],
    [11, 10,  9],
    [12, 11, 10],
    [13, 12, 11]
])

# Note: Default assumes all atoms are sequential

BONDS = [
    [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
]

Example

from nerf import NeRF, iNeRF

xyz = NeRF(DOF, deps=DEP)
dof = iNeRF(xyz, deps=DEP)

assert np.all(np.absolute(xyz - XYZ) < 0.001)
assert np.all(np.absolute(dof - DOF) < 0.001)

Vectorized Example

from nerf import NeRF, iNeRF, perturb_dofs

repeats = 100000 # ~2 seconds on my computer for both calculations

DOFS = perturb_dofs(
    np.repeat(DOF[np.newaxis], repeats, axis=0),
    bond_length_factor=0.01 * np.ones(1),
    bond_angle_factor=0.1 * np.ones(len(DOF)),
    bond_torsion_factor=1.0 * np.ones((repeats,len(DOF)))
)

xyzs = NeRF(DOFS, deps=DEP)
dofs = iNeRF(xyzs, deps=DEP)

xyzs_delta = xyzs - ORIGIN_XYZ

dofs_delta = dofs - DOF
dofs_delta[np.where(dofs_delta > 180.0)] -= 360.0
dofs_delta[np.where(dofs_delta < -180.0)] += 360.0

assert np.all(np.absolute(np.mean(xyzs_delta, axis=0)) < 0.05)
assert np.all(np.absolute(np.mean(dofs_delta, axis=0)) < 0.05)

Deps Example

assert np.array_equal(build_deps(BONDS), DEP)

Citation

Parsons J, Holmes JB, Rojas JM, Tsai J, Strauss CE. Practical conversion from torsion space to Cartesian space for in silico protein synthesis. J Comput Chem. 2005;26(10):1063-1068. doi:10.1002/jcc.20237

Metadata

Release files for pynerf 1.0.4

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

Source distribution (sdist)

Source distribution for pynerf 1.0.4
File Size Uploaded Provenance Actions
pynerf-1.0.4.tar.gz 5.2 kB Without provenance Details for pynerf-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pynerf 1.0.4
File Interpreter ABI Platform Actions
pynerf-1.0.4-py3-none-any.whl Python 3 none any Details for pynerf-1.0.4-py3-none-any.whl

Total release size: 9.7 kB

Release files / pynerf-1.0.4.tar.gz

Download URL pynerf-1.0.4.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
20c92ff5b9b39d51e2217d4e174c6894fbc09711512da7f2def3127bbe667690
BLAKE2b-256 checksum
How to use checksums
1f70c84bf3028bddd9a03d094a13d06af1e1465034ea7a19cf9fbf0f99d35684
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pynerf-1.0.4-py3-none-any.whl

Download URL pynerf-1.0.4-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49855a4a4a272aa907198d54c9aed7c4bd2ba15136dc8c8e799b6b62cf0b026b
BLAKE2b-256 checksum
How to use checksums
5ac38966a4280b26729594430ed76d8ce0a1f8a7121f91ff2d5804fb887b2a78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Security for pynerf 1.0.4

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