-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henry Isaacson
committed
Jul 29, 2024
1 parent
aa1ccd1
commit 1d17283
Showing
6 changed files
with
1,143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import torch | ||
from torch import Tensor | ||
|
||
|
||
def soft_sphere_potential(input: Tensor, | ||
sigma: Tensor = 1, | ||
epsilon: Tensor = 1, | ||
alpha: Tensor = 2, | ||
**unused_kwargs) -> Tensor: | ||
r""" | ||
Finite ranged repulsive interaction between soft spheres. | ||
Parameters | ||
---------- | ||
input : Tensor | ||
A tensor of shape `[n, m]` of pairwise distances between particles. | ||
sigma : Tensor, optional | ||
Particle diameter. Should either be a floating point scalar or a tensor | ||
whose shape is `[n, m]`. Default is 1. | ||
epsilon : Tensor, optional | ||
Interaction energy scale. Should either be a floating point scalar or a tensor | ||
whose shape is `[n, m]`. Default is 1. | ||
alpha : Tensor, optional | ||
Exponent specifying interaction stiffness. Should either be a floating point scalar | ||
or a tensor whose shape is `[n, m]`. Default is 2. | ||
unused_kwargs : dict, optional | ||
Allows extra data (e.g. time) to be passed to the energy. | ||
Returns | ||
------- | ||
Tensor | ||
Matrix of energies whose shape is `[n, m]`. | ||
""" | ||
input = input / sigma | ||
fn = lambda dr: epsilon / alpha * (1.0 - dr) ** alpha | ||
|
||
if isinstance(alpha, int) or issubclass(type(alpha.dtype), torch.int): | ||
return torch.where(input < 1.0, fn(input), torch.tensor(0.0, dtype=input.dtype)) | ||
|
||
return torch.where(input < 1.0, fn(input), torch.tensor(0.0, dtype=input.dtype)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.