Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lennard-Jones potential #36

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
::: beignet.invert_quaternion
::: beignet.invert_rotation_matrix
::: beignet.invert_rotation_vector
::: beignet.lennard_jones_potential
::: beignet.quaternion_identity
::: beignet.quaternion_magnitude
::: beignet.quaternion_mean
Expand Down
2 changes: 2 additions & 0 deletions src/beignet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ._invert_rotation_matrix import invert_rotation_matrix
from ._invert_rotation_vector import invert_rotation_vector
from ._invert_transform import invert_transform
from ._lennard_jones_potential import lennard_jones_potential
from ._quaternion_identity import quaternion_identity
from ._quaternion_magnitude import quaternion_magnitude
from ._quaternion_mean import quaternion_mean
Expand Down Expand Up @@ -91,6 +92,7 @@
"invert_rotation_matrix",
"invert_rotation_vector",
"invert_transform",
"lennard_jones_potential",
"quaternion_identity",
"quaternion_magnitude",
"quaternion_mean",
Expand Down
33 changes: 33 additions & 0 deletions src/beignet/_lennard_jones_potential.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from torch import Tensor


def lennard_jones_potential(
input: Tensor,
sigma: float | Tensor,
epsilon: float | Tensor,
) -> Tensor:
r"""
Lennard-Jones potential.

Parameters
----------
input : Tensor, shape=(n, m)
Pairwise distances between particles.

sigma : float | Tensor, shape=(n, m)
Distance where the potential energy, :math:`V`, is zero.

epsilon : float | Tensor, shape=(n, m)
Depth of the potential well.

Returns
-------
output : Tensor, shape=(n, m)
Energies.
"""
a = sigma / input

b = a**6.0
c = b**2.0

return 4.0 * epsilon * (c - b)
37 changes: 37 additions & 0 deletions tests/beignet/test__lennard_jones_potential.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import beignet
import torch
import torch.testing


def test__lennard_jones_potential():
x = beignet.lennard_jones_potential(
torch.tensor(
[
[1.0, 2.0],
[3.0, 4.0],
],
),
1.0,
1.0,
)

print(x)

torch.testing.assert_close(
beignet.lennard_jones_potential(
torch.tensor(
[
[1.0, 2.0],
[3.0, 4.0],
],
),
1.0,
1.0,
),
torch.tensor(
[
[+0.0000000000000000, -0.0615234375000000],
[-0.0054794428870082, -0.0009763240814209],
],
),
)
Loading