Skip to content

Commit f6c9777

Browse files
committed
Measurements.jl simulation
1 parent 6ebe896 commit f6c9777

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/simulators.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Custom simulators should implement this function.
7575
using_constraints = length(sys.constraints) > 0
7676
println(sim.log_stream, "Step 0 - potential energy ", E, " - max force N/A - N/A")
7777
hn = sim.step_size
78-
coords_copy = similar(sys.coords)
79-
F_nounits = ustrip_vec.(similar(sys.coords))
78+
coords_copy = zero(sys.coords)
79+
F_nounits = ustrip_vec.(zero(sys.coords))
8080
F = F_nounits .* sys.force_units
8181
forces_buffer = init_forces_buffer!(sys, F_nounits, n_threads)
8282

@@ -154,14 +154,14 @@ end
154154
n_threads=n_threads)
155155
forces_t = forces_nounits_t .* sys.force_units
156156
accels_t = forces_t ./ masses(sys)
157-
forces_nounits_t_dt = ustrip_vec.(similar(sys.coords))
157+
forces_nounits_t_dt = ustrip_vec.(zero(sys.coords))
158158
forces_t_dt = forces_nounits_t_dt .* sys.force_units
159159
accels_t_dt = zero(accels_t)
160160
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads, current_forces=forces_t)
161161
using_constraints = length(sys.constraints) > 0
162162
if using_constraints
163-
cons_coord_storage = similar(sys.coords)
164-
cons_vel_storage = similar(sys.velocities)
163+
cons_coord_storage = zero(sys.coords)
164+
cons_vel_storage = zero(sys.velocities)
165165
end
166166

167167
for step_n in 1:n_steps
@@ -240,13 +240,13 @@ end
240240
!iszero(sim.remove_CM_motion) && remove_CM_motion!(sys)
241241
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads)
242242
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads)
243-
forces_nounits_t = ustrip_vec.(similar(sys.coords))
243+
forces_nounits_t = ustrip_vec.(zero(sys.coords))
244244
forces_t = forces_nounits_t .* sys.force_units
245245
forces_buffer = init_forces_buffer!(sys, forces_nounits_t, n_threads)
246246
accels_t = forces_t ./ masses(sys)
247247
using_constraints = length(sys.constraints) > 0
248248
if using_constraints
249-
cons_coord_storage = similar(sys.coords)
249+
cons_coord_storage = zero(sys.coords)
250250
end
251251

252252
for step_n in 1:n_steps
@@ -315,8 +315,8 @@ StormerVerlet(; dt, coupling=NoCoupling()) = StormerVerlet(dt, coupling)
315315
sys.coords .= wrap_coords.(sys.coords, (sys.boundary,))
316316
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads)
317317
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads)
318-
coords_last, coords_copy = similar(sys.coords), similar(sys.coords)
319-
forces_nounits_t = ustrip_vec.(similar(sys.coords))
318+
coords_last, coords_copy = zero(sys.coords), zero(sys.coords)
319+
forces_nounits_t = ustrip_vec.(zero(sys.coords))
320320
forces_t = forces_nounits_t .* sys.force_units
321321
forces_buffer = init_forces_buffer!(sys, forces_nounits_t, n_threads)
322322
accels_t = forces_t ./ masses(sys)
@@ -400,15 +400,15 @@ end
400400
!iszero(sim.remove_CM_motion) && remove_CM_motion!(sys)
401401
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads)
402402
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads)
403-
forces_nounits_t = ustrip_vec.(similar(sys.coords))
403+
forces_nounits_t = ustrip_vec.(zero(sys.coords))
404404
forces_t = forces_nounits_t .* sys.force_units
405405
forces_buffer = init_forces_buffer!(sys, forces_nounits_t, n_threads)
406406
accels_t = forces_t ./ masses(sys)
407-
noise = similar(sys.velocities)
407+
noise = zero(sys.velocities)
408408
using_constraints = length(sys.constraints) > 0
409409
if using_constraints
410-
cons_coord_storage = similar(sys.coords)
411-
cons_vel_storage = similar(sys.velocities)
410+
cons_coord_storage = zero(sys.coords)
411+
cons_vel_storage = zero(sys.velocities)
412412
end
413413

414414
for step_n in 1:n_steps
@@ -508,13 +508,13 @@ end
508508
!iszero(sim.remove_CM_motion) && remove_CM_motion!(sys)
509509
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads)
510510
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads)
511-
forces_nounits_t = ustrip_vec.(similar(sys.coords))
511+
forces_nounits_t = ustrip_vec.(zero(sys.coords))
512512
forces_buffer = init_forces_buffer!(sys, forces_nounits_t, n_threads)
513513
forces_nounits_t .= forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0;
514514
n_threads=n_threads)
515515
forces_t = forces_nounits_t .* sys.force_units
516516
accels_t = forces_t ./ masses(sys)
517-
noise = similar(sys.velocities)
517+
noise = zero(sys.velocities)
518518

519519
effective_dts = [sim.dt / count(c, sim.splitting) for c in sim.splitting]
520520

@@ -630,11 +630,11 @@ end
630630
!iszero(sim.remove_CM_motion) && remove_CM_motion!(sys)
631631
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads)
632632
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads)
633-
forces_nounits_t = ustrip_vec.(similar(sys.coords))
633+
forces_nounits_t = ustrip_vec.(zero(sys.coords))
634634
forces_t = forces_nounits_t .* sys.force_units
635635
forces_buffer = init_forces_buffer!(sys, forces_nounits_t, n_threads)
636636
accels_t = forces_t ./ masses(sys)
637-
noise = similar(sys.velocities)
637+
noise = zero(sys.velocities)
638638

639639
for step_n in 1:n_steps
640640
forces_nounits_t .= forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, step_n;
@@ -710,7 +710,7 @@ end
710710
n_threads=n_threads)
711711
forces_t = forces_nounits_t .* sys.force_units
712712
accels_t = forces_t ./ masses(sys)
713-
forces_nounits_t_dt = ustrip_vec.(similar(sys.coords))
713+
forces_nounits_t_dt = ustrip_vec.(zero(sys.coords))
714714
forces_t_dt = forces_nounits_t_dt .* sys.force_units
715715
accels_t_dt = zero(accels_t)
716716
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads, current_forces=forces_t)
@@ -1064,7 +1064,7 @@ end
10641064
rng=Random.default_rng())
10651065
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads)
10661066
E_old = potential_energy(sys, neighbors; n_threads=n_threads)
1067-
coords_old = similar(sys.coords)
1067+
coords_old = zero(sys.coords)
10681068

10691069
for step_n in 1:n_steps
10701070
coords_old .= sys.coords

test/simulation.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ end
252252
@test eltype(eltype(forces(sys_unc; n_threads=n_threads))) ==
253253
typeof((1.0 ± 0.1)u"kJ * mol^-1 * nm^-1")
254254
end
255+
simulator_unc = VelocityVerlet(dt=0.002u"ps")
256+
for n_threads in n_threads_list
257+
simulate!(sys_unc, simulator_unc, 1; n_threads=n_threads,
258+
run_loggers=false)
259+
end
255260
end
256261
end
257262
end

0 commit comments

Comments
 (0)