Skip to main content

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.

Metadata

Release files for sphericart 2.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 sphericart 2.0.4
File Size Uploaded
sphericart-2.0.4.tar.gz 67.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for sphericart 2.0.4
File
sphericart-2.0.4-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
sphericart-2.0.4-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
sphericart-2.0.4-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
sphericart-2.0.4-py3-none-macosx_11_0_x86_64.whl Python 3 none macOS 11.0+ x86-64 Details
sphericart-2.0.4-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 1.6 MB

Release files / sphericart-2.0.4.tar.gz

Download URL sphericart-2.0.4.tar.gz
Size 67.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1672460878d51e34a0edf25421c31390c183e91e26b8165072b816255c8e7a02
BLAKE2b-256 checksum
How to use checksums
c74e62ca3fb7b71e8caa3c90f9a40f22af825e03322250b9564eb81601118928
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / sphericart-2.0.4-py3-none-win_amd64.whl

Download URL sphericart-2.0.4-py3-none-win_amd64.whl
Size 233.7 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
f7462b29dc7844e6389ee37d9a6a69a033c3a5e7dd32cb9c1daeb55ef8accb2f
BLAKE2b-256 checksum
How to use checksums
be60975da7dfae3ce287d52c0d80ff1e07461dfe4bfa9761ba8b3ef44831f9c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / sphericart-2.0.4-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL sphericart-2.0.4-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 432.8 kB
Tags Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
f39d586daa0800cb8424727f9b1794a35e5e00cb19f47b01b42cd4971814b934
BLAKE2b-256 checksum
How to use checksums
b0ebea6ba48a6b9e83d08b673b5a5b77b820b63d91fb77688fd9790fcfddaaa5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / sphericart-2.0.4-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL sphericart-2.0.4-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 413.7 kB
Tags Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
2add1fe60cf270b97745156fb0b67dfb9d2d77f30df75588c6bc9f0370a99d19
BLAKE2b-256 checksum
How to use checksums
40dcc2a7378af83c75bf8108429ab8b9d37265110ed9830a4cfec9bbd548348d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / sphericart-2.0.4-py3-none-macosx_11_0_x86_64.whl

Download URL sphericart-2.0.4-py3-none-macosx_11_0_x86_64.whl
Size 283.3 kB
Tags Python 3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
06243223337c8ccfdbebf609bbe3bf62e374e9291267e80ff3ca66ddf048e3c4
BLAKE2b-256 checksum
How to use checksums
bf3e10ee44c050f841350c13c31764b39aa509928c1eea4b5d70e663b4f86ce0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / sphericart-2.0.4-py3-none-macosx_11_0_arm64.whl

Download URL sphericart-2.0.4-py3-none-macosx_11_0_arm64.whl
Size 158.0 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7fddf696240288385fb834d30e059f46dc399b89a286b3c70b2d493dd8f45c66
BLAKE2b-256 checksum
How to use checksums
d016e45e70247ff0e91e3b65c22d7ddcf56800cf93ff2662e9896f5494c5341a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4
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