Skip to content

Commit 0e385b6

Browse files
authored
Merge pull request #98 from m3g/celllistmap-0.10.0
Celllistmap 0.10.0
2 parents 3a323b6 + dece8a5 commit 0e385b6

13 files changed

Lines changed: 77 additions & 94 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ MolSimToolkit.jl Changelog
1212

1313
Version 2.0.1-DEV
1414
--------------
15+
- ![INFO][badge-info] Requires CellListMap 0.10.0 (and thus PDBTools 3.25.2)
1516

1617
Version 2.0.0
1718
--------------

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Plotting = "Plots"
3636
[compat]
3737
Aqua = "0.8.13"
3838
BenchmarkTools = "1.3"
39-
CellListMap = "0.9.11"
39+
CellListMap = "0.10.0"
4040
Chemfiles = "0.10.31"
4141
ChunkSplitters = "3.1.1"
4242
Dates = "1.10"
@@ -50,7 +50,7 @@ MDLovoFit_jll = "20.1"
5050
MolSimToolkitShared = "1.5"
5151
OffsetArrays = "1.13"
5252
OrderedCollections = "1.8.1"
53-
PDBTools = "3.21.0"
53+
PDBTools = "3.25.2"
5454
Plots = "1.40"
5555
Printf = "1.10"
5656
ProgressMeter = "1.10"

src/BlockAverages.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ function block_average(
247247
tau_int = 1 + 2 * sum(_autocor[i] for i in 2:i95-1; init=0.0)
248248
n_eff = n / tau_int
249249
xmean_stderr_neff = std(x) / sqrt(n_eff)
250-
251250
return BlockAverageData{TINPUT,DT}(
252251
x_input,
253252
xmean * oneunit(TINPUT),

src/MolecularMinimumDistances/AllPairs.jl

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ struct AllPairs{T,F1<:Function,F2<:Function} <: SystemPairs
44
ymol_indices::F2
55
end
66

7+
_uround(x) = round(x / oneunit(x); digits = 2) * oneunit(x)
8+
79
import Base.show
810
function Base.show(io::IO, ::MIME"text/plain", sys::AllPairs)
911
print(io,chomp("""
@@ -42,7 +44,7 @@ more general `xmol_indices` and/or `ymol_indices` functions,
4244
which, for each atomic index, returns the corresponding
4345
molecular index (which is `mol_indices(i) = (i-1)%n + 1` where `n` is the
4446
number of atoms per molecule if all molecules have the same number of
45-
atoms and are continously stored in the array of positions).
47+
atoms and are continuously stored in the array of positions).
4648
4749
# Examples
4850
@@ -105,18 +107,12 @@ function AllPairs(;
105107
end
106108

107109
#=
108-
function update_list!(
109-
i, j, d2,
110-
mol_indices_i::Fi,
111-
mol_indices_j::Fj,
112-
lists::Tuple{T,T}
113-
) where {Fi<:Function, Fj<:Function, T<:AbstractVector{<:MinimumDistance}}
114-
115110
116111
Function to update the minimum distance in the case where two lists are being constructed.
117112
118113
=#
119-
function update_list!(i, j, d2, lists, system::AllPairs)
114+
function update_list!(pair, lists, system::AllPairs)
115+
(;i, j, d2) = pair
120116
x_list = lists[1]
121117
y_list = lists[2]
122118
d = sqrt(d2)
@@ -141,11 +137,11 @@ end
141137
MolSimToolkit.Testing.namd_pdb,
142138
MolSimToolkit.Testing.namd_traj,
143139
)
144-
first_frame!(simulation)
145-
p = positions(current_frame(simulation))
146-
uc = unitcell(current_frame(simulation))
147-
xsolvent = zeros(eltype(p), length(popc))
148-
xsolute = zeros(eltype(p), length(protein))
140+
f = first_frame!(simulation)
141+
p = positions(f)
142+
uc = unitcell(f)
143+
xsolvent = p[popc]
144+
xsolute = p[protein]
149145
sys = AllPairs(
150146
xpositions = xsolvent,
151147
ypositions = xsolute,
@@ -159,17 +155,17 @@ end
159155
for (iframe, frame) in enumerate(simulation)
160156
pos = positions(frame)
161157
local uc = unitcell(current_frame(simulation))
162-
sys.xpositions .= @view(pos[popc])
163-
sys.ypositions .= @view(pos[protein])
164-
sys.unitcell = uc.orthorhombic ? diag(uc.matrix) : uc.matrix
158+
sys.system.xpositions .= @view(pos[popc])
159+
sys.system.ypositions .= @view(pos[protein])
160+
sys.system.unitcell = uc.orthorhombic ? diag(uc.matrix) : uc.matrix
165161
md = minimum_distances!(sys)
166162
xmd_min[iframe] = minimum(p -> p.d, md[1])
167163
ymd_indices[iframe] = minimum(p -> p.i, md[2])
168164
# Test direct (out-of-place) call
169165
if iframe == 1
170166
md_out = minimum_distances(
171-
xpositions = sys.xpositions,
172-
ypositions = sys.ypositions,
167+
xpositions = xsolvent,
168+
ypositions = xsolute,
173169
xn_atoms_per_molecule = 134,
174170
yn_atoms_per_molecule = length(protein),
175171
cutoff = 6.0,

src/MolecularMinimumDistances/CrossPairs.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ more general `mol_indices` function, which, for each atomic index, returns the
3838
corresponding
3939
molecular index (which is `mol_indices(i) = (i-1)%n + 1` where `n` is the
4040
number of atoms per molecule if all molecules have the same number of
41-
atoms and are continously stored in the array of positions).
41+
atoms and are continuously stored in the array of positions).
4242
4343
# Examples
4444
@@ -96,8 +96,8 @@ end
9696
# Functions that return the atoms of the second set that are closer to
9797
# each molecule of the first set (only one list is returned).
9898
#
99-
function update_list!(i, j, d2, list, system::CrossPairs)
100-
d = sqrt(d2)
99+
function update_list!(pair, list, system::CrossPairs)
100+
(; i, j, d) = pair
101101
imol = system.mol_indices(i)
102102
if d < list[imol].d
103103
list[imol] = MinimumDistance(true, i, j, d)
@@ -115,11 +115,11 @@ end
115115
MolSimToolkit.Testing.namd_pdb,
116116
MolSimToolkit.Testing.namd_traj,
117117
)
118-
first_frame!(simulation)
119-
p = positions(current_frame(simulation))
120-
uc = unitcell(current_frame(simulation))
121-
xsolvent = zeros(eltype(p), length(popc))
122-
xsolute = zeros(eltype(p), length(protein))
118+
f = first_frame!(simulation)
119+
p = positions(f)
120+
uc = unitcell(f)
121+
xsolvent = p[popc]
122+
xsolute = p[protein]
123123
sys = CrossPairs(
124124
xpositions = xsolvent,
125125
ypositions = xsolute,
@@ -131,19 +131,19 @@ end
131131
for (iframe, frame) in enumerate(simulation)
132132
pos = positions(frame)
133133
local uc = unitcell(frame)
134-
sys.xpositions .= @view(pos[popc])
135-
sys.ypositions .= @view(pos[protein])
136-
sys.unitcell = uc.orthorhombic ? diag(uc.matrix) : uc.matrix
134+
sys.system.xpositions .= @view(pos[popc])
135+
sys.system.ypositions .= @view(pos[protein])
136+
sys.system.unitcell = uc.orthorhombic ? diag(uc.matrix) : uc.matrix
137137
md = minimum_distances!(sys)
138138
md_count[iframe] = count(p -> p.within_cutoff, md)
139139
# Test direct (out-of-place) call
140140
if iframe == 1
141141
md_out = minimum_distances(
142-
xpositions = sys.xpositions,
143-
ypositions = sys.ypositions,
142+
xpositions = xsolvent,
143+
ypositions = xsolute,
144144
xn_atoms_per_molecule = 134,
145145
cutoff = 6.0,
146-
unitcell = sys.unitcell
146+
unitcell = sys.system.unitcell
147147
)
148148
@test all(md_out .≈ md)
149149
end

src/MolecularMinimumDistances/MolecularMinimumDistances.jl

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
module MolecularMinimumDistances
22

3-
import TestItems: @testitem
4-
import DocStringExtensions: TYPEDEF, TYPEDFIELDS
3+
using TestItems: @testitem
4+
using DocStringExtensions: TYPEDEF, TYPEDFIELDS
55

6-
import LinearAlgebra: diag
6+
using LinearAlgebra: diag
7+
using StaticArrays: SVector
8+
using CellListMap: ParticleSystem, pairwise!, update!
79
import PDBTools: distance
8-
import StaticArrays: SVector
9-
import CellListMap: _uround # interal function, used for showing the unitcell
10-
import CellListMap: ParticleSystem, map_pairwise, map_pairwise!,
11-
update_cutoff!, update_unitcell!
1210

1311
export MinimumDistance
1412
export SelfPairs, CrossPairs, AllPairs
@@ -205,7 +203,7 @@ julia> init_list(x, i -> (i-1)÷2 + 1)
205203
206204
```
207205
208-
The above annonymous function `i -> (i-1)÷2 + 1` is equivalent to `i -> mol_indices(i,2)`,
206+
The above anonymous function `i -> (i-1)÷2 + 1` is equivalent to `i -> mol_indices(i,2)`,
209207
and can be generalized if the the number of atoms of each molecule is not the same.
210208
211209
=#
@@ -231,7 +229,7 @@ init_list(::Type{T}, n::Integer) where {T} = fill(zero(MinimumDistance{T}), n)
231229
# Note that we have two types of output variables here: List, and a tuple of List.
232230
# The List is simply an array of `MinimumDistance{T}`, and we have defined above
233231
# `copy` and `zero` methods for this type, such that we only need to define
234-
# that reseting this variable consists of returing its zero, and set up the reducer.
232+
# that resetting this variable consists of returning its zero, and set up the reducer.
235233
# The methods for abstract arrays will take care of the rest.
236234
#
237235
# For the Tuple of lists, we need to be more explicit, and define appropriate copy_output,
@@ -263,7 +261,7 @@ end
263261
Function that computes the minimum distances for an initialized system,
264262
of `SelfPairs`, `CrossPairs`, or `AllPairs` types.
265263
266-
The function returs a `Vector{MinimumDistance}` cor `SelfPairs` and `CrossPairs`
264+
The function returns a `Vector{MinimumDistance}` cor `SelfPairs` and `CrossPairs`
267265
inputs, and a Tuple of two of such vectors for the `AllPairs` input types.
268266
269267
This function is used as an advanced alternative from preallocated system inputs. Only a few allocations
@@ -303,10 +301,7 @@ julia> @btime minimum_distances!(\$sys);
303301
304302
"""
305303
function minimum_distances!(sys)
306-
map_pairwise!(
307-
(x, y, i, j, d2, list) -> update_list!(i, j, d2, list, sys),
308-
sys.system
309-
)
304+
pairwise!((pair, list) -> update_list!(pair, list, sys), sys.system)
310305
return sys.minimum_distances
311306
end
312307

@@ -482,24 +477,12 @@ abstract type SystemPairs end
482477

483478
import Base: getproperty, propertynames
484479
getproperty(sys::SystemPairs, s::Symbol) = getproperty(sys, Val(s))
480+
getproperty(sys::SystemPairs, ::Val{:minimum_distances}) = sys.system.output
485481
getproperty(sys::SystemPairs, ::Val{:system}) = getfield(sys, :system)
486482
getproperty(sys::SystemPairs, ::Val{:mol_indices}) = getfield(sys, :mol_indices)
487483
getproperty(sys::SystemPairs, ::Val{:xmol_indices}) = getfield(sys, :xmol_indices)
488484
getproperty(sys::SystemPairs, ::Val{:ymol_indices}) = getfield(sys, :ymol_indices)
489-
getproperty(sys::SystemPairs, ::Val{:minimum_distances}) = sys.system.output
490-
getproperty(sys::SystemPairs, ::Val{:xpositions}) = sys.system.xpositions
491-
getproperty(sys::SystemPairs, ::Val{:ypositions}) = sys.system.ypositions
492-
getproperty(sys::SystemPairs, ::Val{:cutoff}) = sys.system.cutoff
493-
getproperty(sys::SystemPairs, ::Val{:unitcell}) = sys.system.unitcell
494-
getproperty(sys::SystemPairs, ::Val{:parallel}) = sys.system.parallel
495-
propertynames(sys::SystemPairs, private::Bool) =
496-
(:system, :mol_indices, :minimum_distances, :xpositions, :ypositions, :unitcell, :cutoff)
497-
498-
import Base: setproperty!
499-
setproperty!(sys::SystemPairs, s::Symbol, value) = setproperty!(sys, Val(s), value)
500-
setproperty!(sys::SystemPairs, ::Val{:cutoff}, cutoff) = update_cutoff!(sys.system, cutoff)
501-
setproperty!(sys::SystemPairs, ::Val{:unitcell}, unitcell) = update_unitcell!(sys.system, unitcell)
502-
setproperty!(sys::SystemPairs, ::Val{:parallel}, parallel) = sys.system.parallel = parallel
485+
propertynames(sys::SystemPairs, private::Bool) = (:system, :minimum_distances)
503486

504487
#
505488
# Functions for when the lists of minimum-distances is that of a single

src/MolecularMinimumDistances/SelfPairs.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ more general `mol_indices` function, which, for each atomic index, returns the
3333
corresponding
3434
molecular index (which is `mol_indices(i) = (i-1)%n + 1` where `n` is the
3535
number of atoms per molecule if all molecules have the same number of
36-
atoms and are continously stored in the array of positions).
36+
atoms and are continuously stored in the array of positions).
3737
3838
# Examples
3939
@@ -84,10 +84,11 @@ function SelfPairs(;
8484
end
8585

8686
#
87-
# This file containst the functions for single-sets, that is for those cases where
87+
# This file contains the functions for single-sets, that is for those cases where
8888
# the list of minimum-distances is between the molecules of a single component.
8989
#
90-
function update_list!(i, j, d2, list::List, system::SelfPairs)
90+
function update_list!(pair, list::List, system::SelfPairs)
91+
(; i, j, d2) = pair
9192
imol = system.mol_indices(i)
9293
jmol = system.mol_indices(j)
9394
if imol != jmol
@@ -111,10 +112,10 @@ end
111112
MolSimToolkit.Testing.namd_pdb,
112113
MolSimToolkit.Testing.namd_traj,
113114
)
114-
first_frame!(simulation)
115-
p = positions(current_frame(simulation))
116-
uc = unitcell(current_frame(simulation))
117-
xsolvent = zeros(eltype(p), length(popc))
115+
f = first_frame!(simulation)
116+
p = positions(f)
117+
uc = unitcell(f)
118+
xsolvent = p[popc]
118119
sys = SelfPairs(
119120
xpositions = xsolvent,
120121
cutoff = 6.0,
@@ -125,17 +126,17 @@ end
125126
for (iframe, frame) in enumerate(simulation)
126127
pos = positions(frame)
127128
local uc = unitcell(frame)
128-
sys.xpositions .= @view(pos[popc])
129-
sys.unitcell = uc.orthorhombic ? diag(uc.matrix) : uc.matrix
129+
sys.system.xpositions .= @view(pos[popc])
130+
sys.system.unitcell = uc.orthorhombic ? diag(uc.matrix) : uc.matrix
130131
md = minimum_distances!(sys)
131132
md_min[iframe] = minimum(p -> p.d, md)
132133
# Test direct (out-of-place) call
133134
if iframe == 1
134135
md_out = minimum_distances(
135-
xpositions = sys.xpositions,
136+
xpositions = xsolvent,
136137
xn_atoms_per_molecule = 134,
137138
cutoff = 6.0,
138-
unitcell = sys.unitcell
139+
unitcell = sys.system.unitcell
139140
)
140141
@test all(md_out .≈ md)
141142
end

src/Reweighting/Reweight.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function reweight(
127127
output = 0.0,
128128
output_name = :total_energy
129129
)
130-
energy_vec[iframe] = map_pairwise!((x, y, i, j, d2, total_energy) -> total_energy + f_perturbation(i, j, sqrt(d2)/10), system)
130+
energy_vec[iframe] = pairwise!((pair, total_energy) -> total_energy + f_perturbation(pair.i, pair.j, pair.d/10), system)
131131
end
132132
@. prob_rel_vec = exp(-(energy_vec)/k*T)
133133
prob_vec = prob_rel_vec/sum(prob_rel_vec)
@@ -159,7 +159,7 @@ function reweight(
159159
output = 0.0,
160160
output_name = :total_energy
161161
)
162-
energy_vec[iframe] = map_pairwise!((x, y, i, j, d2, total_energy) -> total_energy + f_perturbation(i, j, sqrt(d2)/10), system)
162+
energy_vec[iframe] = pairwise!((pair, total_energy) -> total_energy + f_perturbation(pair.i, pair.j, pair.d/10), system)
163163
end
164164
@. prob_rel_vec = exp(-(energy_vec)/k*T)
165165
prob_vec = prob_rel_vec/sum(prob_rel_vec)

src/Reweighting/Reweighting.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Reweighting
22

33
using LinearAlgebra: diag
4-
using CellListMap: ParticleSystem, map_pairwise, map_pairwise!
4+
using CellListMap: ParticleSystem, pairwise!
55
using ..MolSimToolkit: Simulation, positions, unitcell
66

77
export reweight, lennard_jones_perturbation, poly_decay_perturbation, gaussian_decay_perturbation

src/hydrogen_bonds/hydrogen_bonds.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Base.Threads: @threads
22
using ChunkSplitters: index_chunks
3-
using CellListMap: CellListMap, ParticleSystem, map_pairwise!, update_unitcell!
3+
using CellListMap: CellListMap, ParticleSystem, pairwise!, update!
44
using OrderedCollections: OrderedDict
55

66
include("./internals.jl")
@@ -119,7 +119,7 @@ function PDBTools.hydrogen_bonds(
119119
if sel1 == sel2
120120
s1 = selection_data[sel1]
121121
sys.xpositions .= @view(current_positions[s1.inds])
122-
update_unitcell!(sys, uc.matrix)
122+
update!(sys; unitcell=uc.matrix)
123123
number_of_hbonds = count_hbonds(
124124
sys, s1, angle_cutoff, electronegative_elements
125125
)
@@ -128,7 +128,7 @@ function PDBTools.hydrogen_bonds(
128128
s2 = selection_data[sel2]
129129
sys.xpositions .= @view(current_positions[s1.inds])
130130
sys.ypositions .= @view(current_positions[s2.inds])
131-
update_unitcell!(sys, uc.matrix)
131+
update!(sys; unitcell=uc.matrix)
132132
number_of_hbonds = count_hbonds(
133133
sys, s1, s2, sel1, sel2, angle_cutoff, electronegative_elements
134134
)

0 commit comments

Comments
 (0)