@@ -68,15 +68,15 @@ Custom simulators should implement this function.
68
68
run_loggers= false ,
69
69
rng= Random. default_rng ())
70
70
# @inline needed to avoid Enzyme error
71
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
71
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
72
72
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
73
73
E = potential_energy (sys, neighbors; n_threads= n_threads)
74
74
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads, current_potential_energy= E)
75
75
using_constraints = length (sys. constraints) > 0
76
76
println (sim. log_stream, " Step 0 - potential energy " , E, " - max force N/A - N/A" )
77
77
hn = sim. step_size
78
- coords_copy = zero (sys. coords)
79
- F_nounits = ustrip_vec .(zero (sys. coords))
78
+ coords_copy = similar (sys. coords)
79
+ F_nounits = ustrip_vec .(similar (sys. coords))
80
80
F = F_nounits .* sys. force_units
81
81
forces_buffer = init_forces_buffer! (sys, F_nounits, n_threads)
82
82
@@ -89,7 +89,7 @@ Custom simulators should implement this function.
89
89
coords_copy .= sys. coords
90
90
sys. coords .+ = hn .* F ./ max_force
91
91
using_constraints && apply_position_constraints! (sys, coords_copy; n_threads= n_threads)
92
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
92
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
93
93
94
94
neighbors_copy = neighbors
95
95
neighbors = find_neighbors (sys, sys. neighbor_finder, neighbors, step_n;
@@ -145,23 +145,23 @@ end
145
145
n_threads:: Integer = Threads. nthreads (),
146
146
run_loggers= true ,
147
147
rng= Random. default_rng ())
148
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
148
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
149
149
! iszero (sim. remove_CM_motion) && remove_CM_motion! (sys)
150
150
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
151
151
forces_nounits_t = ustrip_vec .(zero (sys. coords))
152
152
forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
153
- forces_nounits_t . = forces_nounits! (forces_nounits_t, sys, neighbors, forces_buffer, 0 ;
154
- n_threads= n_threads)
153
+ forces_nounits_t = forces_nounits! (forces_nounits_t, sys, neighbors, forces_buffer, 0 ;
154
+ n_threads= n_threads)
155
155
forces_t = forces_nounits_t .* sys. force_units
156
156
accels_t = forces_t ./ masses (sys)
157
- forces_nounits_t_dt = ustrip_vec .(zero (sys. coords))
157
+ forces_nounits_t_dt = ustrip_vec .(similar (sys. coords))
158
158
forces_t_dt = forces_nounits_t_dt .* sys. force_units
159
159
accels_t_dt = zero (accels_t)
160
160
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads, current_forces= forces_t)
161
161
using_constraints = length (sys. constraints) > 0
162
162
if using_constraints
163
- cons_coord_storage = zero (sys. coords)
164
- cons_vel_storage = zero (sys. velocities)
163
+ cons_coord_storage = similar (sys. coords)
164
+ cons_vel_storage = similar (sys. velocities)
165
165
end
166
166
167
167
for step_n in 1 : n_steps
172
172
sys. coords .+ = sys. velocities .* sim. dt .+ ((accels_t .* sim. dt .^ 2 ) ./ 2 )
173
173
using_constraints && apply_position_constraints! (sys, cons_coord_storage, cons_vel_storage,
174
174
sim. dt; n_threads= n_threads)
175
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
175
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
176
176
177
177
forces_nounits_t_dt .= forces_nounits! (forces_nounits_t_dt, sys, neighbors, forces_buffer,
178
178
step_n; n_threads= n_threads)
@@ -236,17 +236,17 @@ end
236
236
n_threads:: Integer = Threads. nthreads (),
237
237
run_loggers= true ,
238
238
rng= Random. default_rng ())
239
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
239
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
240
240
! iszero (sim. remove_CM_motion) && remove_CM_motion! (sys)
241
241
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
242
242
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads)
243
- forces_nounits_t = ustrip_vec .(zero (sys. coords))
243
+ forces_nounits_t = ustrip_vec .(similar (sys. coords))
244
244
forces_t = forces_nounits_t .* sys. force_units
245
245
forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
246
246
accels_t = forces_t ./ masses (sys)
247
247
using_constraints = length (sys. constraints) > 0
248
248
if using_constraints
249
- cons_coord_storage = zero (sys. coords)
249
+ cons_coord_storage = similar (sys. coords)
250
250
end
251
251
252
252
for step_n in 1 : n_steps
268
268
sys. velocities .= (sys. coords .- cons_coord_storage) ./ sim. dt
269
269
end
270
270
271
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
271
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
272
272
273
273
if ! iszero (sim. remove_CM_motion) && step_n % sim. remove_CM_motion == 0
274
274
remove_CM_motion! (sys)
@@ -312,11 +312,11 @@ StormerVerlet(; dt, coupling=NoCoupling()) = StormerVerlet(dt, coupling)
312
312
n_threads:: Integer = Threads. nthreads (),
313
313
run_loggers= true ,
314
314
rng= Random. default_rng ())
315
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
315
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
316
316
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
317
317
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads)
318
- coords_last, coords_copy = zero (sys. coords), zero (sys. coords)
319
- forces_nounits_t = ustrip_vec .(zero (sys. coords))
318
+ coords_last, coords_copy = similar (sys. coords), similar (sys. coords)
319
+ forces_nounits_t = ustrip_vec .(similar (sys. coords))
320
320
forces_t = forces_nounits_t .* sys. force_units
321
321
forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
322
322
accels_t = forces_t ./ masses (sys)
@@ -339,7 +339,7 @@ StormerVerlet(; dt, coupling=NoCoupling()) = StormerVerlet(dt, coupling)
339
339
340
340
using_constraints && apply_position_constraints! (sys, coords_copy; n_threads= n_threads)
341
341
342
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
342
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
343
343
# This is accurate to O(dt)
344
344
sys. velocities .= vector .(coords_copy, sys. coords, (sys. boundary,)) ./ sim. dt
345
345
@@ -396,19 +396,19 @@ end
396
396
n_threads:: Integer = Threads. nthreads (),
397
397
run_loggers= true ,
398
398
rng= Random. default_rng ())
399
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
399
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
400
400
! iszero (sim. remove_CM_motion) && remove_CM_motion! (sys)
401
401
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
402
402
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads)
403
- forces_nounits_t = ustrip_vec .(zero (sys. coords))
403
+ forces_nounits_t = ustrip_vec .(similar (sys. coords))
404
404
forces_t = forces_nounits_t .* sys. force_units
405
405
forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
406
406
accels_t = forces_t ./ masses (sys)
407
- noise = zero (sys. velocities)
407
+ noise = similar (sys. velocities)
408
408
using_constraints = length (sys. constraints) > 0
409
409
if using_constraints
410
- cons_coord_storage = zero (sys. coords)
411
- cons_vel_storage = zero (sys. velocities)
410
+ cons_coord_storage = similar (sys. coords)
411
+ cons_vel_storage = similar (sys. velocities)
412
412
end
413
413
414
414
for step_n in 1 : n_steps
432
432
433
433
using_constraints && apply_position_constraints! (sys, cons_coord_storage, cons_vel_storage,
434
434
sim. dt; n_threads= n_threads)
435
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
435
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
436
436
437
437
if ! iszero (sim. remove_CM_motion) && step_n % sim. remove_CM_motion == 0
438
438
remove_CM_motion! (sys)
@@ -504,17 +504,15 @@ end
504
504
α_eff = exp .(- sim. friction * sim. dt .* M_inv / count (' O' , sim. splitting))
505
505
σ_eff = sqrt .((1 * unit (eltype (α_eff))) .- (α_eff .^ 2 ))
506
506
507
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
507
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
508
508
! iszero (sim. remove_CM_motion) && remove_CM_motion! (sys)
509
509
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
510
510
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads)
511
- forces_nounits_t = ustrip_vec .(zero (sys. coords))
512
- forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
513
- forces_nounits_t .= forces_nounits! (forces_nounits_t, sys, neighbors, forces_buffer, 0 ;
514
- n_threads= n_threads)
511
+ forces_nounits_t = ustrip_vec .(similar (sys. coords))
515
512
forces_t = forces_nounits_t .* sys. force_units
513
+ forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
516
514
accels_t = forces_t ./ masses (sys)
517
- noise = zero (sys. velocities)
515
+ noise = similar (sys. velocities)
518
516
519
517
effective_dts = [sim. dt / count (c, sim. splitting) for c in sim. splitting]
520
518
553
551
step! (args... , neighbors, step_n)
554
552
end
555
553
556
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
554
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
557
555
if ! iszero (sim. remove_CM_motion) && step_n % sim. remove_CM_motion == 0
558
556
remove_CM_motion! (sys)
559
557
end
568
566
569
567
function A_step! (sys, dt_eff, neighbors, step_n)
570
568
sys. coords .+ = sys. velocities .* dt_eff
571
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
569
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
572
570
return sys
573
571
end
574
572
@@ -626,15 +624,15 @@ end
626
624
@warn " OverdampedLangevin is not currently compatible with constraints, " *
627
625
" constraints will be ignored"
628
626
end
629
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
627
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
630
628
! iszero (sim. remove_CM_motion) && remove_CM_motion! (sys)
631
629
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
632
630
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads)
633
- forces_nounits_t = ustrip_vec .(zero (sys. coords))
631
+ forces_nounits_t = ustrip_vec .(similar (sys. coords))
634
632
forces_t = forces_nounits_t .* sys. force_units
635
633
forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
636
634
accels_t = forces_t ./ masses (sys)
637
- noise = zero (sys. velocities)
635
+ noise = similar (sys. velocities)
638
636
639
637
for step_n in 1 : n_steps
640
638
forces_nounits_t .= forces_nounits! (forces_nounits_t, sys, neighbors, forces_buffer, step_n;
644
642
645
643
random_velocities! (noise, sys, sim. temperature; rng= rng)
646
644
sys. coords .+ = (accels_t ./ sim. friction) .* sim. dt .+ sqrt ((2 / sim. friction) * sim. dt) .* noise
647
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
645
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
648
646
649
647
if ! iszero (sim. remove_CM_motion) && step_n % sim. remove_CM_motion == 0
650
648
remove_CM_motion! (sys)
@@ -701,16 +699,16 @@ end
701
699
@warn " NoseHoover is not currently compatible with constraints, " *
702
700
" constraints will be ignored"
703
701
end
704
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
702
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
705
703
! iszero (sim. remove_CM_motion) && remove_CM_motion! (sys)
706
704
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
707
705
forces_nounits_t = ustrip_vec .(zero (sys. coords))
708
706
forces_buffer = init_forces_buffer! (sys, forces_nounits_t, n_threads)
709
- forces_nounits_t . = forces_nounits! (forces_nounits_t, sys, neighbors, forces_buffer, 0 ;
710
- n_threads= n_threads)
707
+ forces_nounits_t = forces_nounits! (forces_nounits_t, sys, neighbors, forces_buffer, 0 ;
708
+ n_threads= n_threads)
711
709
forces_t = forces_nounits_t .* sys. force_units
712
710
accels_t = forces_t ./ masses (sys)
713
- forces_nounits_t_dt = ustrip_vec .(zero (sys. coords))
711
+ forces_nounits_t_dt = ustrip_vec .(similar (sys. coords))
714
712
forces_t_dt = forces_nounits_t_dt .* sys. force_units
715
713
accels_t_dt = zero (accels_t)
716
714
apply_loggers! (sys, neighbors, 0 , run_loggers; n_threads= n_threads, current_forces= forces_t)
721
719
v_half .= sys. velocities .+ (accels_t .- (sys. velocities .* zeta)) .* (sim. dt ./ 2 )
722
720
723
721
sys. coords .+ = v_half .* sim. dt
724
- sys. coords, sys . img_flags . = wrap_coords .(sys. coords, (sys. boundary,), sys . img_flags )
722
+ sys. coords . = wrap_coords .(sys. coords, (sys. boundary,))
725
723
726
724
zeta_half = zeta + (sim. dt / (2 * (sim. damping^ 2 ))) *
727
725
((temperature (sys) / sim. temperature) - 1 )
@@ -1064,7 +1062,7 @@ end
1064
1062
rng= Random. default_rng ())
1065
1063
neighbors = find_neighbors (sys, sys. neighbor_finder; n_threads= n_threads)
1066
1064
E_old = potential_energy (sys, neighbors; n_threads= n_threads)
1067
- coords_old = zero (sys. coords)
1065
+ coords_old = similar (sys. coords)
1068
1066
1069
1067
for step_n in 1 : n_steps
1070
1068
coords_old .= sys. coords
0 commit comments