JuliaMolSim / Molly.jl

Molecular simulation in Julia
Other
394 stars 53 forks source link

Implement cubic spline cutoff #54

Closed noeblassel closed 2 years ago

noeblassel commented 2 years ago

Cubic Spline implementation

This is a suggestion to add a spline cutoff, which interpolates between the true potential at a set activation distance and zero at a cutoff distance. The interpolation itself is based on a cubic Hermite spline.

Main addition

The main addition consists in a new cutoff type, CubicSplineCutoff :

struct CubicSplineCutoff{D,S,I}
    dist_cutoff::D
    sqdist_cutoff::S
    inv_sqdist_cutoff::I

    dist_activation::D
    sqdist_activation::S
    inv_sqdist_activation::I
end

This cutoff comes with two methods

force_divr_cutoff(cutoff::CubicSplineCutoff, r2, inter, params) potential_cutoff(cutoff::CubicSplineCutoff, r2, inter, params)

which define the behaviour of the cutoff within the cutoff region, between dist_activation and dist_cutoff

Small adjustments

The naming convention used above required changing some of the code in the "interactions" folder, specifically the potential_energy and force methods defined in coulomb.jl, lennard_jones.jl, mie.jl and soft_sphere.jl. This is because originally, these methods enforce the cutoff in the case of two cutoff points (as is the case here) if the squared distance between two atoms is between cutoff.activation_dist and cutoff.sqdist_cutoff, which is misleading.

codecov[bot] commented 2 years ago

Codecov Report

Merging #54 (087b78f) into master (24ee999) will increase coverage by 0.48%. The diff coverage is 74.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #54      +/-   ##
==========================================
+ Coverage   84.18%   84.66%   +0.48%     
==========================================
  Files          28       28              
  Lines        2453     2472      +19     
==========================================
+ Hits         2065     2093      +28     
+ Misses        388      379       -9     
Impacted Files Coverage Δ
src/interactions/coulomb.jl 77.77% <0.00%> (ø)
src/interactions/mie.jl 67.27% <0.00%> (ø)
src/interactions/soft_sphere.jl 62.50% <0.00%> (ø)
src/cutoffs.jl 93.75% <94.73%> (+0.64%) :arrow_up:
src/interactions/lennard_jones.jl 100.00% <100.00%> (+16.94%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 24ee999...087b78f. Read the comment docs.

noeblassel commented 2 years ago

Thanks for the pointers, I made the changes

jgreener64 commented 2 years ago

:+1: