Skip to main content

Fast calculation of spherical harmonics

Project description

sphericart

Test

This is sphericart, a multi-language library for the efficient calculation of real spherical harmonics and their derivatives in Cartesian coordinates.

For instructions and examples on the usage of the library, please refer to our documentation.

A plot of the +-1 isosurfaces of the Y^0\_3 solid harmonic, including also gradients.

If you are using sphericart for your academic work, you can cite it as

@article{sphericart,
    title={Fast evaluation of spherical harmonics with sphericart},
    author={Bigi, Filippo and Fraux, Guillaume and Browning, Nicholas J. and Ceriotti, Michele},
    journal={J. Chem. Phys.},
    year={2023},
    number={159},
    pages={064802},
}

This library is dual-licensed under the Apache License 2.0 and the MIT license. You can use to use it under either of the two licenses.

Installation

Python

Pre-built (https://pypi.org/project/sphericart/).

pip install sphericart             # numpy interface, CPU only
pip install sphericart[torch]      # Torch (and TorchScript) interface, CPU and GPU
pip install sphericart[jax]        # JAX interface, CPU and GPU

Note that the pre-built packages are compiled for a generic CPU, and might be less performant than they could be on a specific processor. To generate libraries that are optimized for the target system, you can build from source:

git clone https://github.com/lab-cosmo/sphericart
pip install .

# if you also want the torch bindings (CPU and GPU)
pip install .[torch]

# torch bindings, CPU-only version
pip install --extra-index-url https://download.pytorch.org/whl/cpu .[torch]

If you want to enable the CUDA version of the code when builing from source, you'll need to set the CUDA_HOME environement variable. You can build a CUDA enabled sphericart, but the calculations though numpy will only run on CPU.

Julia

A native Julia implementation of sphericart is provided, called SpheriCart. Install the package by opening a REPL, switch to the package manager by typing ] and then add SpheriCart. See julia/README.md for usage. SpheriCart.jl is compatible with ChainRules.jl and Lux.jl and provides GPU kernels via KernelAbstractions.jl.

C and C++

From source

git clone https://github.com/lab-cosmo/sphericart
cd sphericart

mkdir build && cd build

cmake .. <cmake configuration options>
cmake --build . --target install

The following cmake configuration options are available:

  • -DSPHERICART_BUILD_TORCH=ON/OFF: build the torch bindings in addition to the main library
  • -DSPHERICART_BUILD_TESTS=ON/OFF: build C++ unit tests
  • -DSPHERICART_BUILD_EXAMPLES=ON/OFF: build C++ examples and benchmarks
  • -DSPHERICART_OPENMP=ON/OFF: enable OpenMP parallelism
  • -DCMAKE_INSTALL_PREFIX=<where/you/want/to/install> set the root path for installation

GPU Support

The support for GPU offload could be controled with the following CMake variables at configuration:

  • -DSPHERICART_ENABLE_CUDA=ON/OFF: build with CUDA support also set CUDA_HOME environement variable.
  • -DSPHERICART_ENABLE_SYCL=ON/OFF: build with SYCL support, configure tool will search for sycl/sycl.h header.
  • -DSPHERICART_SYCL_DEVICE=all/cpu/gpu: target architecute for SYCL support, check which devices are available with sycl-ls, for all (default) is possible to control at execution with export ONEAPI_DEVICE_SELECTOR=opencl:gpu or export ONEAPI_DEVICE_SELECTOR=opencl:cpu.

The following flags have been tested with Intel OneAPI 2025.3 for enabling SYCL support:

  • -DCMAKE_CXX_COMPILER=icpx
  • -DCMAKE_C_COMPILER=icx
  • -DCMAKE_CXX_FLAGS=" -qopenmp --intel -fsycl -fsycl-targets=spir64 -Wno-deprecated-declarations -Wno-macro-redefined -Wno-unused-parameter -w"

Note: Only tested in C++, python/JAX/Torch support is in progress.

Running tests and documentation

Tests and the local build of the documentation can be run with tox. The default tests, which are also run on the CI, can be executed by simply running

tox

in the main folder of the repository.

To run tests in a CPU-only environment you can set the environment variable PIP_EXTRA_INDEX_URL before calling tox, e.g.

PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu tox -e docs

will build the documentation in a CPU-only environment.

Other flavors of spherical harmonics

Although sphericart natively calculates real solid and spherical harmonics from Cartesian positions, it is easy to manipulate its output it to calculate complex spherical harmonics and/or to accept spherical coordinates as inputs. You can see examples here.

Maintainers

This project is maintained by @frostedoyster and @Luthaf. The maintainers will reply to issues and pull requests opened on this repository as soon as possible. You can mention them directly if you have not received an answer after a couple of days.

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

sphericart-2.0.3.tar.gz (67.7 kB view details)

Uploaded Source

Built Distributions

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

sphericart-2.0.3-py3-none-win_amd64.whl (233.7 kB view details)

Uploaded Python 3Windows x86-64

sphericart-2.0.3-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (428.9 kB view details)

Uploaded Python 3manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

sphericart-2.0.3-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (412.4 kB view details)

Uploaded Python 3manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

sphericart-2.0.3-py3-none-macosx_11_0_x86_64.whl (283.3 kB view details)

Uploaded Python 3macOS 11.0+ x86-64

sphericart-2.0.3-py3-none-macosx_11_0_arm64.whl (158.0 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file sphericart-2.0.3.tar.gz.

File metadata

  • Download URL: sphericart-2.0.3.tar.gz
  • Upload date:
  • Size: 67.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for sphericart-2.0.3.tar.gz
Algorithm Hash digest
SHA256 c956c55561a7ef7b0dac68f2127bacab24364816f02a51fbd62ef2d18613615f
MD5 99efc33ff1eefce0bd75879111221190
BLAKE2b-256 17c834b0554accb0b05e82c66e9124e6dfe87924e93b5fd97d353712c8a6e4a7

See more details on using hashes here.

File details

Details for the file sphericart-2.0.3-py3-none-win_amd64.whl.

File metadata

  • Download URL: sphericart-2.0.3-py3-none-win_amd64.whl
  • Upload date:
  • Size: 233.7 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for sphericart-2.0.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 35431409e7cfb405f90978817078243f2bf739da15993fbdb2baa4a86a788a95
MD5 3c5f772cf3d41eda95c75c6eee5105e0
BLAKE2b-256 85950641b4704e4ce969d999b7f0ab44b3d9f5a345bf84634f922cfd8cd8622f

See more details on using hashes here.

File details

Details for the file sphericart-2.0.3-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sphericart-2.0.3-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b7de562391ae622bf382e29bc64d7a5f6a858b1ec41e238feea5d1e368a7a73c
MD5 0ff7c2de70cc2f8a46f8c67a2ccae1c7
BLAKE2b-256 ad9d0b72724b4a0488b0ea1efd9d7d4889268893b5f001c7d457f4c76c2e12ef

See more details on using hashes here.

File details

Details for the file sphericart-2.0.3-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for sphericart-2.0.3-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 26470c7975a7cddb9865ae08d5bb0675cd178b150264d87b49e3d1c2a831963c
MD5 9d618c5ca50f4f8951c5d3b8e1ed94e5
BLAKE2b-256 9d192aab6074a9f26e1fad58a9c1d8dc4aeb1f05d8226e4cc1724e3e343ef3ab

See more details on using hashes here.

File details

Details for the file sphericart-2.0.3-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for sphericart-2.0.3-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2ba620991fc746d202337d443cdd5d07342cd79052b69c98e3b93342324d0d37
MD5 2519a072a8d7d0b59f682582ed6a3e5a
BLAKE2b-256 81e801838fbd1328f2d00fdae742ad1c6b940b7cb1e2a1787dc9358da09599c1

See more details on using hashes here.

File details

Details for the file sphericart-2.0.3-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sphericart-2.0.3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9d9edf5397b20ebf55fbedc3f65e7f8d995387d1020ae418f43d925897f0aab2
MD5 51d5249cf5911c50c1f3ed75e50cb544
BLAKE2b-256 2a80b783633a752f09c2f39b32a41a5af1658e1cfaeaac29b9bdfaf28516b383

See more details on using hashes here.

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