Skip to content

Commit

Permalink
Merge pull request #67 from m3g/ignore_frames_with_zero_frameweight
Browse files Browse the repository at this point in the history
skip frames with zero frame weight, and use the enabled option of Pro…
  • Loading branch information
lmiq authored Dec 17, 2024
2 parents 3248fbf + eca178e commit 91bce28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
32 changes: 17 additions & 15 deletions src/mddf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,21 @@ end
# reading of the coordinates by Chemfiles
#
function goto_nextframe!(iframe, R, trajectory, to_compute_frames, options)
frame_weight = 1.0
compute = false
while iframe < R.files[1].lastframe_read && !compute
nextframe!(trajectory)
iframe += 1
if iframe in to_compute_frames
frame_weight = isempty(R.files[1].frame_weights) ? 1.0 : R.files[1].frame_weights[iframe]
if iframe in to_compute_frames && !iszero(frame_weight)
compute = true
end
# Run GC if memory is getting full: this is related to issues with Chemfiles reading scheme
if options.GC && (Sys.free_memory() / Sys.total_memory() < options.GC_threshold)
GC.gc()
# Run GC if memory is getting full: this is related to issues with Chemfiles reading scheme
if options.GC && (Sys.free_memory() / Sys.total_memory() < options.GC_threshold)
GC.gc()
end
end
end
return iframe, compute
return iframe, frame_weight, compute
end

"""
Expand Down Expand Up @@ -230,13 +232,13 @@ function mddf(
firstframe!(trajectory)

# Skip initial frames if desired
progress = Progress(options.firstframe; dt=1)
progress = Progress(options.firstframe; dt=1, enabled=!options.silent)
for _ in 1:options.firstframe-1
nextframe!(trajectory)
if options.GC && (Sys.free_memory() / Sys.total_memory() < options.GC_threshold)
GC.gc()
end
options.silent || next!(progress)
next!(progress)
end
iframe = options.firstframe - 1

Expand All @@ -253,12 +255,15 @@ function mddf(
println(" - Number of parallel minimum-distance computations: $nchunks")
println(" - Each minimum-distance computation will use $(nbatches_cl[2]) threads.")
end
progress = Progress(R.files[1].nframes_read; dt=1)
end

# Frames to be read and frames for which the MDDF will be computed
to_read_frames = options.firstframe:R.files[1].lastframe_read
to_compute_frames = options.firstframe:options.stride:R.files[1].lastframe_read
progress = Progress(
count(i -> isempty(frame_weights) ? true : !iszero(frame_weights[i]), to_compute_frames);
dt=1, enabled=!options.silent
)

# Loop over the trajectory
read_lock = ReentrantLock()
Expand All @@ -272,32 +277,29 @@ function mddf(
buff_chunk = Buffer(trajectory, R)
r_chunk = Result(trajectory, options; trajectory_data, frame_weights)
# Reset the number of frames read by each chunk
nframes_read = 0
for _ in frame_range
local compute, frame_weight
# Read frame coordinates
@lock read_lock begin
iframe, compute = goto_nextframe!(iframe, R, trajectory, to_compute_frames, options)
iframe, frame_weight, compute = goto_nextframe!(iframe, R, trajectory, to_compute_frames, options)
if compute
# Read frame for computing
# The solute coordinates must be read in intermediate arrays, because the
# solute molecules will be considered one at a time in the computation of the
# minimum distances
@. buff_chunk.solute_read = trajectory.x_solute
@. buff_chunk.solvent_read = trajectory.x_solvent
# Read weight of this frame
unitcell = convert_unitcell(trajectory_data.unitcell, getunitcell(trajectory))
update_unitcell!(system_chunk, unitcell)
# Read weight of this frame.
frame_weight = r_chunk.files[1].frame_weights[iframe]
# Display progress bar
options.silent || next!(progress)
next!(progress)
end
end # release reading lock
#
# Perform MDDF computation
#
if compute
nframes_read += 1
# Compute distances in this frame and update results
if !coordination_number_only
mddf_frame!(r_chunk, system_chunk, buff_chunk, options, frame_weight, RNG)
Expand Down
4 changes: 2 additions & 2 deletions src/tools/grid3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ function grid3D(
AtomType = typeof(PDBTools.Atom()) # to support PDBTools < 2 (which does not have a Atom{T} constructor)
grid = AtomType[]
grid_lock = ReentrantLock()
silent || (p = Progress(prod(n); desc="Building grid..."))
p = Progress(prod(n); desc="Building grid...", enabled=!silent)
Threads.@threads for ix_inds in ChunkSplitters.chunks(1:n[1]; n=Threads.nthreads())
for ix in ix_inds, iy in 1:n[2], iz in 1:n[3]
silent || next!(p)
next!(p)
x = lims.xmin[1] - dmax + step * (ix - 1)
y = lims.xmin[2] - dmax + step * (iy - 1)
z = lims.xmin[3] - dmax + step * (iz - 1)
Expand Down

0 comments on commit 91bce28

Please sign in to comment.