Skip to main content

A Python package interfacing with the CO2CO2 shared library.

Project description

CO₂–CO₂ Potential Energy Library

High-performance C++ routines for computing CO₂ dimer potentials (1-body, 2-body, SAPT-S), exposed to Python via a ctypes wrapper (and optionally a pybind11 module).

Repository Layout

CO2_AUTODIFF/                    # Project root
├── src/                         # All C++ source + Makefile
│   ├── mbCO2CO2.cpp             # C-API exports (energies, grads, Hessians)
│   ├── mbCO2CO2.h               # Function declarations
│   ├── x1b.cpp/.h               # 1-body poly routines
│   ├── x2b.cpp/.h               # 2-body poly routines
│   ├── sapt-s.cpp/.h            # SAPT-S routines
│   ├── poly-*.cpp/.h            # polynomial basis eval
│   └── Makefile                 # builds `libCO2CO2.so`
├── co2_potential/               # Python package
│   ├── __init__.py
│   ├── libCO2CO2.so             # copied in by setup.py
│   └── wrapper.py               # ctypes wrapper + convenience functions
├── setup.py                     # pip install / build‐ext hook
├── pyproject.toml               # PEP 517 build config
├── MANIFEST.in                  # include shared lib & .py files
├── README.md
└── LICENSE

Installation

1. Prerequisites

  • C++ compiler (GCC/Clang) supporting C++17
  • Python 3.6+ and pip
  • (Optional) ccache for faster recompiles

2. Install via pip

From project root:

pip install .

This will:

  1. Invoke the custom build_ext command in setup.py
  2. cd src-autodiff && make clean && make
  3. Copy libCO2CO2.so into the co2_potential/ package
  4. Build & install the Python wheel

3. Manual Build (if needed)

If you want to rebuild by hand:

cd src-autodiff
make clean
make -j$(sysctl -n hw.ncpu)
# or add OP=-O2 in Makefile for faster debug builds

Then copy the resulting libCO2CO2.so into the Python package:

cp libCO2CO2.so ../co2_potential/

Usage

import numpy as np
from co2_potential.wrapper import p1b, p2b_4, p2b_5, sapt

# Example: 6-atom dimer → 18 coordinates
xyz = np.array([
    0.0,   0.0,  0.000,    # monomer A: C, O, O
    0.0,   0.0, -1.162,
    0.0,   0.0,  1.162,
    3.75,  0.0,  0.000,    # monomer B: C, O, O
    3.75,  0.0, -1.162,
    3.75,  0.0,  1.162
], dtype=np.double)

E1 = p1b(xyz)        # 1-body energy
E2_4 = p2b_4(xyz)    # 2-body 4th‐order
E2_5 = p2b_5(xyz)    # 2-body 5th‐order
Es = sapt(xyz)       # SAPT-S energy

print(f"E1 = {E1:.6f}, E2(5) = {E2_5:.6f}, SAPT = {Es:.6f}")

If you built a pybind11 module under co2_potential/python/module.cpp, simply:

import co2_potential
# co2_potential.p1b, co2_potential.p2b_5, co2_potential.sapt, …

Functionality

The library provides the following Python functions via co2_potential.wrapper:

Dimension and Version Getters

  • get_p1b_dim(): Returns the number of coordinates for monomer (should be 9).
  • get_p2b_dim(): Returns the number of coordinates for dimer (should be 18).
  • get_p2b_4_dim(): Returns the number of coordinates for 2-body 4th-order.
  • get_p2b_5_dim(): Returns the number of coordinates for 2-body 5th-order.
  • get_sapt_dim(): Returns the number of coordinates for SAPT-S.
  • get_version(): Returns the version string of the underlying C++ library.

1B (Monomer) Functions

  • p1b(xyz): Monomer energy. xyz is a numpy array of shape (9,).
  • p1b_gradient(xyz): Monomer gradient. Returns numpy array of shape (9,).
  • p1b_hessian_rev(xyz): Monomer Hessian (reverse-mode autodiff). Returns numpy array of shape (9, 9).
  • p1b_hessian_fwd(xyz): Monomer Hessian (forward-mode autodiff). Returns numpy array of shape (9, 9).

2B (Dimer) Functions – 4th Order

  • p2b_4(xyz): Dimer 2-body 4th-order energy. xyz is a numpy array of shape (18,).
  • p2b_gradient_4(xyz): Dimer 2-body 4th-order gradient. Returns numpy array of shape (18,).
  • p2b_hessian_4_rev(xyz): Dimer 2-body 4th-order Hessian (reverse-mode). Returns numpy array of shape (18, 18).
  • p2b_hessian_4_fwd(xyz): Dimer 2-body 4th-order Hessian (forward-mode). Returns numpy array of shape (18, 18).

2B (Dimer) Functions – 5th Order

  • p2b_5(xyz): Dimer 2-body 5th-order energy. xyz is a numpy array of shape (18,).
  • p2b_gradient_5(xyz): Dimer 2-body 5th-order gradient. Returns numpy array of shape (18,).
  • p2b_hessian_5_rev(xyz): Dimer 2-body 5th-order Hessian (reverse-mode). Returns numpy array of shape (18, 18).
  • p2b_hessian_5_fwd(xyz): Dimer 2-body 5th-order Hessian (forward-mode). Returns numpy array of shape (18, 18).

SAPT-S Dimer Functions

  • sapt(xyz): SAPT-S dimer energy. xyz is a numpy array of shape (18,).
  • sapt_gradient(xyz): SAPT-S dimer gradient. Returns numpy array of shape (18,).
  • sapt_hessian_rev(xyz): SAPT-S dimer Hessian (reverse-mode). Returns numpy array of shape (18, 18).
  • sapt_hessian_fwd(xyz): SAPT-S dimer Hessian (forward-mode). Returns numpy array of shape (18, 18).

The core computations are implemented in C++ for performance and exposed to Python via a ctypes wrapper.

Contributing

Contributions are welcome! If you have suggestions for improvements or new features, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

co2_potential-0.3.1.tar.gz (11.8 MB view details)

Uploaded Source

Built Distribution

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

co2_potential-0.3.1-py3-none-any.whl (12.1 MB view details)

Uploaded Python 3

File details

Details for the file co2_potential-0.3.1.tar.gz.

File metadata

  • Download URL: co2_potential-0.3.1.tar.gz
  • Upload date:
  • Size: 11.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for co2_potential-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8886b3c2e47b136b5de5fb98219df073295e64f9c3dd306765f6e87e57000dc0
MD5 292f46e3ea1e36eae953c6b695a812b0
BLAKE2b-256 6deca4bc200f728ef5a638cead31418e516c4ceb2f764259615921a341bb44c9

See more details on using hashes here.

File details

Details for the file co2_potential-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: co2_potential-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for co2_potential-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04aaeceb987615bce085b2b32c7c3100f363b6af37b1ba390a534f1bab2215f6
MD5 3dd289bd80fc45b04ccd8eae45caf8ff
BLAKE2b-256 b097a76b4c7e812642b0fd8cafe3fcc02bc848a4586ee22ad1e87641ed9d55fe

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