Skip to content
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
13 changes: 12 additions & 1 deletion src/forces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,25 @@ forcecomponents(seq, interactions::InteractionList, residueindexes=eachindex(seq
forcecomponents(collectresidues(seq), interactions, residueindexes; kwargs...)

function forcecomponents(mgmms::AbstractVector{<:IsotropicMultiGMM{N}}, interactions::InteractionList, residueindexes=eachindex(mgmms)) where N
GaussianMixtureAlignment.validate_interactions(Dict(interactions)) || throw(ArgumentError("interactions must appear in only one order, got $interactions"))
interactionsdict = Dict(interactions)
GaussianMixtureAlignment.validate_interactions(interactionsdict) || throw(ArgumentError("interactions must appear in only one order, got $interactions"))
# We don't support (:Ionic, x) where x != :Ionic
for interaction in interactions
key1, key2 = getfeatures(interaction)
if (key1 === :Ionic && key2 !== :Ionic) || (key1 !== :Ionic && key2 === :Ionic)
throw(ArgumentError("(:Ionic, x) is not supported unless x=:Ionic, got $interaction"))
end
end
cionic = get(interactionsdict, (:Ionic, :Ionic), nothing)
if cionic !== nothing
# If (:Ionic, :Ionic) is present, the code below will handle the signs. But we need to ensure consistency with other interactions
for (key, sprod) in ((:Steric, :Steric) => 1, (:Hydrophobe, :Hydrophobe) => -1, (:Donor, :Acceptor) => -1)
c = get(interactionsdict, key, nothing)
if c !== nothing
sign(cionic) * sign(c) != sprod && throw(ArgumentError("(:Ionic, :Ionic) is not sign-compatible with $key"))
end
end
end
forces = [zeros(N, eachindex(interactions)) for _ in residueindexes]
for (k, interaction) in pairs(interactions)
key1, key2 = getfeatures(interaction)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ using Test
w = optimize_weights(forces)
@test all(>=(0), w)
@test sum(w) ≈ 1 atol=1e-6
badinteractions = [(:Steric, :Steric) => 1, (:Hydrophobe, :Hydrophobe) => -1, (:Ionic, :Ionic) => -1]
@test_throws "is not sign-compatible" forcecomponents([mgmmx, mgmmy], badinteractions)
weighted_interactions = [key => w0*wi for ((key, w0), wi) in zip(interactions, w)]
wforces = forcecomponents([mgmmx, mgmmy], weighted_interactions)
@test all(f .* w' ≈ wf for (f, wf) in zip(forces, wforces))
Expand Down
Loading