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 .

Enable Parallelization (OpenMP)

To enable multi-threading support for faster calculations, you need to compile with OpenMP.

macOS (requires libomp via Homebrew):

brew install libomp
CMAKE_ARGS="-DOpenMP_ROOT=$(brew --prefix libomp)" pip install .

Linux: Usually works out of the box. If not, install libomp-dev (Ubuntu/Debian) or libomp-devel (RHEL/Fedora).

Windows: Supported natively by MSVC.


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.2.0.tar.gz (8.7 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.2.0-cp312-abi3-win_amd64.whl (50.4 kB view details)

Uploaded CPython 3.12+Windows x86-64

pyvolgrid-0.2.0-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (163.8 kB view details)

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

pyvolgrid-0.2.0-cp312-abi3-macosx_11_0_arm64.whl (43.3 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

pyvolgrid-0.2.0-cp312-abi3-macosx_10_13_x86_64.whl (47.4 kB view details)

Uploaded CPython 3.12+macOS 10.13+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyvolgrid-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cd76195778bacb5e0d33d6ddc4cdb76a452df88b88f04829ba0db59a394941d3
MD5 bff37ada9cf11f2eb83ab37a7fcea109
BLAKE2b-256 27f0d6874b7672c5504f2171ef538d6bea7b266917fc8541d183e46041303120

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.2.0.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.2.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyvolgrid-0.2.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 50.4 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.2.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 96d2ab8b6b158861c2800ce939289ad87d6026c64b4a9383f07d36970c8f9d3b
MD5 6ef46503b1339cf432f5934412141141
BLAKE2b-256 8cccc455cd12edbac33992ec422e02e3132db39154b94c55e8f00d39c726eab3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.2.0-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.2.0-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvolgrid-0.2.0-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2dc7b52936f22f69be3047a56e9a543dc821c38449ed6a9ce50b74a2d7c2e344
MD5 de48c15bad913d7ffcd407948577af58
BLAKE2b-256 959b1e47e733d04b99c2f3cf694f361e8b893d743744e00140993a8ecb1b79bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.2.0-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.2.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvolgrid-0.2.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ebe1e666ab48ce39b934c5625e72995400dcc54e9d3ed1117050dc80e7e560fe
MD5 b094d0483638aa547b818c855ee076e2
BLAKE2b-256 b7101da96bd6fc6d05f72109063cc31499a7c0681c7d07f4d778f3e8618de257

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.2.0-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.2.0-cp312-abi3-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pyvolgrid-0.2.0-cp312-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 359134ad84b4f8ed81eb8e8d8512afea40bd96c260581d844004180b73eef203
MD5 d6ebc0a686cd61c5342395c07fd33c47
BLAKE2b-256 ceab69f05cf9dac74d3cd26c4fc5c044a7496535991e961a3e688f5cd06af10f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvolgrid-0.2.0-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