-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from JuliaMolSim/acutils
Generic codes to AtomsCalculatorsUtils and Update to AC@0.2
- Loading branch information
Showing
21 changed files
with
856 additions
and
1,178 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
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/docs/Manifest.toml | ||
/docs/build/ | ||
tune.json | ||
.vscode |
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
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
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 |
---|---|---|
@@ -1,10 +1,30 @@ | ||
module EmpiricalPotentials | ||
|
||
# Write your package code here. | ||
using Unitful, ForwardDiff, StaticArrays, Bumper | ||
|
||
using ForwardDiff: Dual | ||
|
||
import AtomsCalculators: energy_unit, length_unit, force_unit | ||
|
||
import AtomsCalculatorsUtilities | ||
import AtomsCalculatorsUtilities.SitePotentials | ||
import AtomsCalculatorsUtilities.SitePotentials: eval_site, eval_grad_site, | ||
hessian_site, block_hessian_site, | ||
cutoff_radius, SitePotential, | ||
ad_block_hessian_site, ad_hessian_site, | ||
cutoff_radius | ||
|
||
import AtomsCalculatorsUtilities.PairPotentials: PairPotential, | ||
eval_pair | ||
|
||
include("utils.jl") | ||
|
||
include("lennardjones.jl") | ||
include("morse.jl") | ||
include("zbl.jl") | ||
|
||
include("stillingerweber.jl") | ||
|
||
include("sitepotentials.jl") | ||
include("pairpotentials.jl") | ||
include("stillingerweber/stillingerweber.jl") | ||
|
||
|
||
end |
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,93 @@ | ||
|
||
|
||
export LennardJones | ||
|
||
|
||
# ----------- Lennard-Jones potential | ||
# to make this parametric, all we have to do is move the emins and rmins | ||
# into a `ps` parameter NamedTuple. I suggest to do this in the next iteration | ||
# and first stabilize the non-parametric potentials. | ||
|
||
""" | ||
LennardJones | ||
Basic implementation of a (multi-species) Lennard-Jones potential with finite | ||
cutoff radius that is imposed by "shifting and tilting" the potential at the | ||
cutoff. It can be constructed as follows. | ||
```julia | ||
emins = Dict( (z1, z1) => -1.0u"eV", | ||
(z1, z2) => -0.5u"eV", | ||
(z2, z2) => -0.25u"eV" ) | ||
rmins = Dict( (z1, z1) => 2.7u"Å", | ||
(z1, z2) => 3.2u"Å", | ||
(z2, z2) => 3.0u"Å" ) | ||
rcut = 6.0u"Å" | ||
lj = LennardJones(emins, rmins, rcut) | ||
``` | ||
It is assumed that the potential is symmetric, i.e. | ||
`emins[(z1, z2)] == emins[(z2, z1)]` and so forth. | ||
""" | ||
mutable struct LennardJones{NZ, TZ, T, UL, UE} <: PairPotential | ||
zlist::NTuple{NZ, TZ} | ||
emins::SMatrix{NZ, NZ, T} | ||
rmins::SMatrix{NZ, NZ, T} | ||
rcut::T | ||
end | ||
|
||
_fltype(::LennardJones{NZ, TZ, T}) where {NZ, TZ, T} = T | ||
|
||
length_unit(::LennardJones{NZ, TZ, T, UL, UE}) where {NZ, TZ, T, UL, UE} = UL | ||
|
||
energy_unit(::LennardJones{NZ, TZ, T, UL, UE}) where {NZ, TZ, T, UL, UE} = UE | ||
|
||
cutoff_radius(V::LennardJones) = V.rcut * length_unit(V) | ||
|
||
|
||
function eval_pair(V::LennardJones, r, z1, z2) | ||
iz1 = _z2i(V.zlist, z1) | ||
iz2 = _z2i(V.zlist, z2) | ||
if iz1 == 0 || iz1 == 0 || r > V.rcut | ||
return zero(_fltype(V)) | ||
end | ||
|
||
_lj(s) = s^12 - 2 * s^6 | ||
_dlj(s) = 12 * s^11 - 12 * s^5 | ||
_lj_tilt(s, scut) = _lj(s) - _lj(scut) - (s - scut) * _dlj(scut) | ||
|
||
rmin = V.rmins[iz1, iz2] | ||
emin = V.emins[iz1, iz2] | ||
s = rmin / r | ||
scut = rmin / V.rcut | ||
|
||
return emin * _lj_tilt(s, scut) | ||
end | ||
|
||
|
||
function LennardJones(emins::Dict, rmins::Dict, rcut::Unitful.Length) | ||
|
||
zlist = tuple( unique(reduce(vcat, collect.(keys(emins))))... ) | ||
NZ = length(zlist) | ||
TZ = typeof(first(zlist)) | ||
UL = unit(rcut) | ||
UE = unit(first(values(emins))) | ||
T = typeof(ustrip(rcut)) | ||
@assert all(typeof(v) == TZ for v in zlist) | ||
@assert all(unit(v) == UL for v in values(rmins)) | ||
@assert all(unit(v) == UE for v in values(emins)) | ||
@assert all(typeof(ustrip(v)) == T for v in values(rmins)) | ||
@assert all(typeof(ustrip(v)) == T for v in values(emins)) | ||
|
||
_emin(z1, z2) = haskey(emins, (z1, z2)) ? emins[(z1, z2)] : emins[(z2, z1)] | ||
_rmin(z1, z2) = haskey(rmins, (z1, z2)) ? rmins[(z1, z2)] : rmins[(z2, z1)] | ||
|
||
emins = SMatrix{NZ, NZ}([ ustrip(_emin(z1, z2)) | ||
for z1 in zlist, z2 in zlist ]) | ||
rmins = SMatrix{NZ, NZ}([ ustrip(_rmin(z1, z2)) | ||
for z1 in zlist, z2 in zlist ]) | ||
|
||
|
||
return LennardJones{NZ, TZ, T, UL, UE}(zlist, emins, rmins, ustrip(rcut)) | ||
end | ||
|
||
|
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,87 @@ | ||
|
||
|
||
export Morse | ||
|
||
|
||
|
||
# ----------- Lennard-Jones potential | ||
# to make this parametric, all we have to do is move the emins and rmins | ||
# into a `ps` parameter NamedTuple. I suggest to do this in the next iteration | ||
# and first stabilize the non-parametric potentials. | ||
|
||
""" | ||
Morse | ||
Basic implementation of a (multi-species) Morse potential with finite | ||
cutoff radius that is imposed by "shifting and tilting" the potential at the | ||
cutoff. It can be constructed as follows. The parameters are | ||
(energy scale, equilibrium bond length, stiffness parameter) | ||
```julia | ||
params = Dict( (z1, z1) => ( -1.0u"eV", 2.7u"Å", 4.1 ), | ||
(z1, z2) => ( -0.5u"eV", 3.2u"Å", 3.5 ), | ||
(z2, z2) => ( -0.25u"eV", 3.0u"Å", 4.3 ) ) | ||
rcut = 6.0u"Å" | ||
V = Morse(params, rcut) | ||
``` | ||
It is assumed that the potential is symmetric, i.e. | ||
`params[(z1, z2)] == params[(z2, z1)]`. | ||
""" | ||
mutable struct Morse{NZ, TZ, T, UL, UE} <: PairPotential | ||
zlist::NTuple{NZ, TZ} | ||
params::SMatrix{NZ, NZ, Tuple{T, T, T}} | ||
rcut::T | ||
end | ||
|
||
_fltype(::Morse{NZ, TZ, T}) where {NZ, TZ, T} = T | ||
|
||
length_unit(::Morse{NZ, TZ, T, UL, UE}) where {NZ, TZ, T, UL, UE} = UL | ||
|
||
energy_unit(::Morse{NZ, TZ, T, UL, UE}) where {NZ, TZ, T, UL, UE} = UE | ||
|
||
cutoff_radius(V::Morse) = V.rcut * length_unit(V) | ||
|
||
|
||
function eval_pair(V::Morse, r, z1, z2) | ||
iz1 = _z2i(V.zlist, z1) | ||
iz2 = _z2i(V.zlist, z2) | ||
if iz1 == 0 || iz1 == 0 || r > V.rcut | ||
return zero(_fltype(V)) | ||
end | ||
|
||
_m(s) = exp(-2 * s) - 2 * exp(-s) | ||
_dm(s) = - 2 * exp(-2 * s) + 2 * exp(-s) | ||
_m_tilt(s, scut) = _m(s) - _m(scut) - (s - scut) * _dm(scut) | ||
|
||
emin, r0, α = V.params[iz1, iz2] | ||
s = α * (r / r0 - 1) | ||
scut = α * (V.rcut / r0 - 1) | ||
|
||
return emin * _m_tilt(s, scut) | ||
end | ||
|
||
|
||
function Morse(params::Dict, rcut::Unitful.Length) | ||
|
||
zlist = tuple( unique(reduce(vcat, collect.(keys(params))))... ) | ||
NZ = length(zlist) | ||
TZ = typeof(first(zlist)) | ||
UL = unit(rcut) | ||
UE = unit(first(values(params))[1]) | ||
T = typeof(ustrip(rcut)) | ||
@assert all(typeof(v) == TZ for v in zlist) | ||
@assert all(unit(v[1]) == UE for v in values(params)) | ||
@assert all(unit(v[2]) == UL for v in values(params)) | ||
@assert all(typeof(ustrip(v[1])) == T for v in values(params)) | ||
@assert all(typeof(ustrip(v[2])) == T for v in values(params)) | ||
@assert all(typeof(v[3]) == T for v in values(params)) | ||
|
||
_params(z1, z2) = haskey(params, (z1, z2)) ? params[(z1, z2)] : params[(z2, z1)] | ||
|
||
P = SMatrix{NZ, NZ, Tuple{T, T, T}}( | ||
[ustrip.(_params(z1, z2)) for z1 in zlist, z2 in zlist]) | ||
|
||
return Morse{NZ, TZ, T, UL, UE}(zlist, P, ustrip(rcut)) | ||
end | ||
|
||
|
Oops, something went wrong.