Skip to main content

Python package for estimating the total volume of overlapping spheres using a grid-based numerical approach.

Project description

PyVolGrid

PyVolGrid is a Python package for estimating the total volume of overlapping spheres using a grid-based numerical approach. It is intended for applications in computational chemistry, molecular modeling, and structural bioinformatics.

(Besides its potential usefullness, this package also served as a learning project for me to get more familiar with Python packaging and distribution of precompiled wheels.)


Installation

pip install pyvolgrid

Or clone the repository and install manually (requires a C++ compiler such as clang or gcc, and cmake to be installed):

git clone https://github.com/ugSUBMARINE/pyvolgrid.git
cd pyvolgrid
pip install .

Usage

Basic Example

import numpy as np
from pyvolgrid import volume_from_spheres

# Define sphere centers and radii
coords = [[0, 0, 0], [1.5, 0, 0], [0, 1.5, 0]]
radii = [1.0, 0.8, 0.6]

# Calculate total volume
volume = volume_from_spheres(coords, radii, grid_spacing=0.1)
print(f"Total volume: {volume:.2f} cubic units")

Scalar Radius

Apply the same radius to all spheres by passing a single number:

# All spheres have radius 1.2
coords = [[0, 0, 0], [3, 0, 0], [0, 3, 0]]
radius = 1.2  # Single value for all spheres

volume = volume_from_spheres(coords, radius)
print(f"Volume with uniform radius: {volume:.2f}")

Flexible Input Types

PyVolGrid accepts various input formats - lists, tuples, or numpy arrays:

# Using tuples
coords = ((0, 0, 0), (2, 0, 0))
radii = (1.0, 0.5)
volume = volume_from_spheres(coords, radii)

# Using numpy arrays (any dtype, will be converted automatically)
coords = np.array([[0, 0, 0]], dtype=np.int32)
radius = np.float32(1.0)
volume = volume_from_spheres(coords, radius)

# Mixed types work too
coords = [[0, 0, 0]]  # List
radius = 1  # Integer (converted to float)
volume = volume_from_spheres(coords, radius)

Performance Tips

# For optimal performance, use C-contiguous float64 arrays
coords = np.array([[0, 0, 0], [2, 0, 0]], dtype=np.float64, order='C')
radii = np.array([1.0, 0.5], dtype=np.float64)

# No copying will occur, maximizing performance
volume = volume_from_spheres(coords, radii)

Grid Spacing

Adjust the grid spacing to balance accuracy vs. performance:

coords = [[0, 0, 0]]
radius = 1.0

# Coarse grid (faster, less accurate)
volume_coarse = volume_from_spheres(coords, radius, grid_spacing=0.2)

# Fine grid (slower, more accurate)
volume_fine = volume_from_spheres(coords, radius, grid_spacing=0.05)

print(f"Coarse: {volume_coarse:.2f}, Fine: {volume_fine:.2f}")

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

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

pyvolgrid-0.1.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distributions

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

pyvolgrid-0.1.3-cp312-abi3-win_amd64.whl (50.1 kB view details)

Uploaded CPython 3.12+Windows x86-64

pyvolgrid-0.1.3-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (52.0 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyvolgrid-0.1.3-cp312-abi3-macosx_11_0_arm64.whl (43.1 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

pyvolgrid-0.1.3-cp312-abi3-macosx_10_13_x86_64.whl (47.2 kB view details)

Uploaded CPython 3.12+macOS 10.13+ x86-64

File details

Details for the file pyvolgrid-0.1.3.tar.gz.

File metadata

  • Download URL: pyvolgrid-0.1.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyvolgrid-0.1.3.tar.gz
Algorithm Hash digest
SHA256 788f63794c08021f562271e56d7de634d8a755f6a62946e69e776f3c43a29e95
MD5 ac3dd4d2878fd247b272e60b48d8e3a8
BLAKE2b-256 b0a8cbaee08a2c47fa882d6236478e9cfc03dfa4cd1bdf9279bf363014f89abf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.1.3.tar.gz:

Publisher: build-wheels.yml on ugSUBMARINE/pyvolgrid

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

File details

Details for the file pyvolgrid-0.1.3-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyvolgrid-0.1.3-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyvolgrid-0.1.3-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 782246218fddddbb5bc9e7bf4c17c9fb32d7743ab47621c6bfa740ff5e34b3d8
MD5 c1791d6992ceae1744740a96341782e6
BLAKE2b-256 3930012ef5a8bd35ccfd090abc4e2c7f4cbcf9e1eea0eb320817771c4e621766

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.1.3-cp312-abi3-win_amd64.whl:

Publisher: build-wheels.yml on ugSUBMARINE/pyvolgrid

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

File details

Details for the file pyvolgrid-0.1.3-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvolgrid-0.1.3-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8cd4afbc20a53734ca4da64abcb5146868cbb303046b951ecec7b2c30485a7c8
MD5 c92cc98bfbf368414044f3066566c767
BLAKE2b-256 ea212474201e01c56e85cf89c4ddeb1e64ac53b608f3f49bfafce039610b01de

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.1.3-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on ugSUBMARINE/pyvolgrid

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

File details

Details for the file pyvolgrid-0.1.3-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvolgrid-0.1.3-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31309b0cdedc81bd82887b23cb0562d15a90ae18dc13d388e029f0d74f3b3d0b
MD5 03880555acc362b42d89daccb8800aea
BLAKE2b-256 55cf770eab9dc32bc979efbef082a9bdea8cb1d8cfa6fadcfcf815e91e1f8587

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.1.3-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on ugSUBMARINE/pyvolgrid

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

File details

Details for the file pyvolgrid-0.1.3-cp312-abi3-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pyvolgrid-0.1.3-cp312-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 9e50a6b7a126e8ca617514a3104b304f59979681bd4be9825a04f5e2c14bbc8c
MD5 3f612ca5f9dd6f9a34f4505ac771d5fe
BLAKE2b-256 3f1d9c1033500fd9f6aedb15305b133709a09903b2b720a037563aa1699a46f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.1.3-cp312-abi3-macosx_10_13_x86_64.whl:

Publisher: build-wheels.yml on ugSUBMARINE/pyvolgrid

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