Skip to main content

Python bindings and ASE adapters for potlib

Project description

pypotlib Contributor Covenant Builds Wheels

Python bindings and ASE adapters for potlib.

Details

The library consists of thin wrappers to potlib under cpot and a PyPotLibCalc class which is an ase calculator under ase_adapters.

Installation

This is on PyPI, with wheels, so usage is simply:

pip install pypotlib

Users are advised to not try to build from source, since the underlying potlib code includes fortran and cpp dependencies which can be slightly tricky to work with.

Local Development

The easiest way is to use the environment file, compatible with conda, mamba, micromamba etc.

mamba env create -f environment.yml
mamba activate rgpotpy
pdm install

Production

As such, due to the compiled extensions and what not, cibuildwheel is used to generate macos and linux wheels. Locally this may be emulated (on linux) by:

cibuildwheel --output-dir wheelhouse --platform linux

Usage examples

The simplest usage is just:

import pypotlib as ppl
import numpy as np
ljpot = ppl.cpot.LJPot()
pos = np.array([1, 2, 3, 1.2, 2.3, 3.6]).reshape(-1, 3)
atm_types = [0, 0]
cell_dim = np.eye(3)*50
print(ljpot(pos, atm_types, cell_dim))

For using the ASE calculator we need an instantiated class.

from ase import Atoms
from pypotlib import cpot
from pypotlib.ase_adapters import PyPotLibCalc
atoms = Atoms(symbols=['Cu', 'H'], positions=[[0, 0, 0], [0.5, 0.5, 0.5]])
calc = PyPotLibCalc(cpot.CuH2Pot())
atoms.set_calculator(calc)
print(atoms.get_potential_energy())
print(atoms.get_forces())

To run an NEB with this, consider the following toy example:

from ase import Atoms
from ase.neb import NEB
from ase.optimize import BFGS

from pypotlib import cpot
from pypotlib.ase_adapters import PyPotLibCalc

atoms_initial = Atoms(symbols=['H', 'H'], positions=[(0, 0, 0), (0, 0, 1)])
atoms_final = Atoms(symbols=['H', 'H'], positions=[(0, 0, 2), (0, 0, 3)])

images = [atoms_initial]
images += [atoms_initial.copy() for idx in range(3)]
images += [atoms_final]

for image in images:
    image.calc = PyPotLibCalc(cpot.LJPot())

neb = NEB(images)
neb.interpolate(method = 'idpp')
optimizer = BFGS(neb)
optimizer.run(fmax=0.04)

Contributions

All contributions are welcome, this includes code and documentation contributions but also questions or other clarifications. Note that we expect all contributors to follow our Code of Conduct.

License

MIT.

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

pypotlib-0.0.13.tar.gz (18.7 kB view hashes)

Uploaded Source

Built Distributions

pypotlib-0.0.13-cp311-cp311-musllinux_1_1_x86_64.whl (3.3 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pypotlib-0.0.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pypotlib-0.0.13-cp311-cp311-macosx_10_9_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pypotlib-0.0.13-cp310-cp310-musllinux_1_1_x86_64.whl (3.3 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pypotlib-0.0.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pypotlib-0.0.13-cp310-cp310-macosx_10_9_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pypotlib-0.0.13-cp39-cp39-musllinux_1_1_x86_64.whl (3.3 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pypotlib-0.0.13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pypotlib-0.0.13-cp39-cp39-macosx_10_9_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pypotlib-0.0.13-cp38-cp38-musllinux_1_1_x86_64.whl (3.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pypotlib-0.0.13-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pypotlib-0.0.13-cp38-cp38-macosx_10_9_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page