Skip to content

Commit c19c573

Browse files
committed
Add type system to potentials
1 parent 4b16a13 commit c19c573

File tree

11 files changed

+106
-30
lines changed

11 files changed

+106
-30
lines changed

src/energy.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,10 @@ function potential_energy(sys::System, neighbors, step_n::Integer=0;
8282
n_threads::Integer=Threads.nthreads())
8383
# Allow types like those from Measurements.jl
8484
T = typeof(ustrip(zero(eltype(eltype(sys.coords)))))
85-
pairwise_inters_nonl = filter(!use_neighbors, values(sys.pairwise_inters))
86-
pairwise_inters_nl = filter( use_neighbors, values(sys.pairwise_inters))
87-
sils_1_atoms = filter(il -> il isa InteractionList1Atoms, values(sys.specific_inter_lists))
88-
sils_2_atoms = filter(il -> il isa InteractionList2Atoms, values(sys.specific_inter_lists))
89-
sils_3_atoms = filter(il -> il isa InteractionList3Atoms, values(sys.specific_inter_lists))
90-
sils_4_atoms = filter(il -> il isa InteractionList4Atoms, values(sys.specific_inter_lists))
9185

9286
if length(sys.pairwise_inters) > 0
87+
pairwise_inters_nonl = filter(!use_neighbors, values(sys.pairwise_inters))
88+
pairwise_inters_nl = filter( use_neighbors, values(sys.pairwise_inters))
9389
if n_threads > 1
9490
pe = pairwise_pe_threads(sys.atoms, sys.coords, sys.velocities, sys.boundary,
9591
neighbors, sys.energy_units, length(sys), pairwise_inters_nonl,
@@ -104,6 +100,10 @@ function potential_energy(sys::System, neighbors, step_n::Integer=0;
104100
end
105101

106102
if length(sys.specific_inter_lists) > 0
103+
sils_1_atoms = filter(il -> il isa InteractionList1Atoms, values(sys.specific_inter_lists))
104+
sils_2_atoms = filter(il -> il isa InteractionList2Atoms, values(sys.specific_inter_lists))
105+
sils_3_atoms = filter(il -> il isa InteractionList3Atoms, values(sys.specific_inter_lists))
106+
sils_4_atoms = filter(il -> il isa InteractionList4Atoms, values(sys.specific_inter_lists))
107107
pe += specific_pe(sys.atoms, sys.coords, sys.velocities, sys.boundary, sys.energy_units,
108108
sils_1_atoms, sils_2_atoms, sils_3_atoms, sils_4_atoms, T, step_n)
109109
end

src/force.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,11 @@ end
169169

170170
function forces_nounits!(fs_nounits, sys::System, neighbors, fs_chunks=nothing,
171171
step_n::Integer=0; n_threads::Integer=Threads.nthreads())
172-
pairwise_inters_nonl = filter(!use_neighbors, values(sys.pairwise_inters))
173-
pairwise_inters_nl = filter( use_neighbors, values(sys.pairwise_inters))
174-
sils_1_atoms = filter(il -> il isa InteractionList1Atoms, values(sys.specific_inter_lists))
175-
sils_2_atoms = filter(il -> il isa InteractionList2Atoms, values(sys.specific_inter_lists))
176-
sils_3_atoms = filter(il -> il isa InteractionList3Atoms, values(sys.specific_inter_lists))
177-
sils_4_atoms = filter(il -> il isa InteractionList4Atoms, values(sys.specific_inter_lists))
178-
172+
179173
if length(sys.pairwise_inters) > 0
174+
pairwise_inters_nonl = filter(!use_neighbors, values(sys.pairwise_inters))
175+
pairwise_inters_nl = filter( use_neighbors, values(sys.pairwise_inters))
176+
180177
if n_threads > 1
181178
pairwise_forces_threads!(fs_nounits, fs_chunks, sys.atoms, sys.coords, sys.velocities,
182179
sys.boundary, neighbors, sys.force_units, length(sys),
@@ -191,6 +188,11 @@ function forces_nounits!(fs_nounits, sys::System, neighbors, fs_chunks=nothing,
191188
end
192189

193190
if length(sys.specific_inter_lists) > 0
191+
sils_1_atoms = filter(il -> il isa InteractionList1Atoms, values(sys.specific_inter_lists))
192+
sils_2_atoms = filter(il -> il isa InteractionList2Atoms, values(sys.specific_inter_lists))
193+
sils_3_atoms = filter(il -> il isa InteractionList3Atoms, values(sys.specific_inter_lists))
194+
sils_4_atoms = filter(il -> il isa InteractionList4Atoms, values(sys.specific_inter_lists))
195+
194196
specific_forces!(fs_nounits, sys.atoms, sys.coords, sys.velocities, sys.boundary,
195197
sys.force_units, sils_1_atoms, sils_2_atoms, sils_3_atoms, sils_4_atoms, step_n)
196198
end

src/interactions/buckingham.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ C_{ij} &= (C_{ii} C_{jj})^{1/2}
4545
```
4646
so atoms that use this interaction should have fields `A`, `B` and `C` available.
4747
"""
48-
@kwdef struct Buckingham{C, S, A, B, M, W}
48+
@kwdef struct Buckingham{C, S, A, B, M, W} <: PairwiseInteraction
4949
cutoff::C = NoCutoff()
5050
use_neighbors::Bool = false
5151
shortcut::S = buckingham_zero_shortcut

src/interactions/coulomb.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The potential energy is defined as
1616
V(r_{ij}) = \frac{q_i q_j}{4 \pi \varepsilon_0 r_{ij}}
1717
```
1818
"""
19-
@kwdef struct Coulomb{C, W, T}
19+
@kwdef struct Coulomb{C, W, T} <: PairwiseInteraction
2020
cutoff::C = NoCutoff()
2121
use_neighbors::Bool = false
2222
weight_special::W = 1
@@ -116,7 +116,7 @@ V(r_{ij}) = \frac{q_i q_j}{4 \pi \varepsilon_0 (r_{ij}^6 + \alpha \sigma_{ij}^6
116116
```
117117
If ``\alpha`` or ``\lambda`` are zero this gives the standard [`Coulomb`](@ref) potential.
118118
"""
119-
@kwdef struct CoulombSoftCore{C, A, L, P, S, W, T, R}
119+
@kwdef struct CoulombSoftCore{C, A, L, P, S, W, T, R} <: PairwiseInteraction
120120
cutoff::C = NoCutoff()
121121
α::A = 1
122122
λ::L = 0
@@ -224,7 +224,7 @@ const crf_solvent_dielectric = 78.3
224224
The Coulomb electrostatic interaction modified using the reaction field approximation
225225
between two atoms.
226226
"""
227-
@kwdef struct CoulombReactionField{D, S, W, T}
227+
@kwdef struct CoulombReactionField{D, S, W, T} <: PairwiseInteraction
228228
dist_cutoff::D
229229
solvent_dielectric::S = crf_solvent_dielectric
230230
use_neighbors::Bool = false
@@ -356,7 +356,7 @@ and the force on each atom by
356356
F(r_{ij}) = \frac{q_i q_j}{4 \pi \varepsilon_0 r_{ij}^2} \exp(-\kappa r_{ij})\left(\kappa r_{ij} + 1\right) \vec{r}_{ij}
357357
```
358358
"""
359-
@kwdef struct Yukawa{C, W, T, K}
359+
@kwdef struct Yukawa{C, W, T, K} <: PairwiseInteraction
360360
cutoff::C = NoCutoff()
361361
use_neighbors::Bool = false
362362
weight_special::W = 1

src/interactions/gravity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The potential energy is defined as
1010
V(r_{ij}) = -\frac{G m_i m_j}{r_{ij}}
1111
```
1212
"""
13-
@kwdef struct Gravity{T}
13+
@kwdef struct Gravity{T} <: PairwiseInteraction
1414
G::T = Unitful.G
1515
use_neighbors::Bool = false
1616
end

src/interactions/implicit_solvent.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ hydrophobic solvent accessible surface area (SA) term.
1313
1414
Custom GBSA methods should sub-type this abstract type.
1515
"""
16-
abstract type AbstractGBSA end
16+
abstract type AbstractGBSA <: GeneralInteraction end
1717

1818
# Default solvent dielectric is 78.5 for consistency with AMBER
1919
# Elsewhere it is 78.3

src/interactions/lennard_jones.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ and the force on each atom by
2020
\end{aligned}
2121
```
2222
"""
23-
@kwdef struct LennardJones{C, H, S, E, W}
23+
@kwdef struct LennardJones{C, H, S, E, W, NF} <: PairwiseInteraction
2424
cutoff::C = NoCutoff()
2525
use_neighbors::Bool = false
2626
shortcut::H = lj_zero_shortcut
@@ -153,7 +153,7 @@ r_{ij}^{\text{sc}} = \left(r_{ij}^6 + \alpha \sigma_{ij}^6 \lambda^p \right)^{1/
153153
```
154154
If ``\alpha`` or ``\lambda`` are zero this gives the standard [`LennardJones`](@ref) potential.
155155
"""
156-
@kwdef struct LennardJonesSoftCore{C, A, L, P, H, S, E, W, R}
156+
@kwdef struct LennardJonesSoftCore{C, A, L, P, H, S, E, W, R} <: PairwiseInteraction
157157
cutoff::C = NoCutoff()
158158
α::A = 1
159159
λ::L = 0
@@ -299,7 +299,7 @@ where
299299
300300
If ``\lambda`` is one this gives the standard [`LennardJones`](@ref) potential.
301301
"""
302-
@kwdef struct AshbaughHatch{C, H, S, E, L, W}
302+
@kwdef struct AshbaughHatch{C, H, S, E, L, W} <: PairwiseInteraction
303303
cutoff::C = NoCutoff()
304304
use_neighbors::Bool = false
305305
shortcut::H = lj_zero_shortcut

src/interactions/mie.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515
C = \frac{n}{n - m} \left( \frac{n}{m} \right) ^\frac{m}{n - m}
1616
```
1717
"""
18-
struct Mie{T, W, C, H, S, E}
18+
struct Mie{T, W, C, H, S, E} <: PairwiseInteraction
1919
m::T
2020
n::T
2121
cutoff::C

src/interactions/muller_brown.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ It is often used for testing algorithms that find transition states or explore
1616
minimum energy pathways.
1717
There are 3 minima and 2 saddle points with the default parameters.
1818
"""
19-
struct MullerBrown{D, T, L, F, E}
19+
struct MullerBrown{D, T, L, F, E} <: GeneralInteraction
2020
A::D # Units of energy
2121
a::T # Units of 1/L^2
2222
b::T # Units of 1/L^2

src/interactions/soft_sphere.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The potential energy is defined as
1010
V(r_{ij}) = 4\varepsilon_{ij} \left(\frac{\sigma_{ij}}{r_{ij}}\right)^{12}
1111
```
1212
"""
13-
@kwdef struct SoftSphere{C, H, S, E}
13+
@kwdef struct SoftSphere{C, H, S, E} <: PairwiseInteraction
1414
cutoff::C = NoCutoff()
1515
use_neighbors::Bool = false
1616
shortcut::H = lj_zero_shortcut

0 commit comments

Comments
 (0)