@@ -16,15 +16,15 @@ export
16
16
DensityLogger,
17
17
VirialLogger,
18
18
PressureLogger,
19
+ DisplacementsLogger,
19
20
write_structure,
20
21
TrajectoryWriter,
21
22
StructureWriter,
22
23
TimeCorrelationLogger,
23
24
AutoCorrelationLogger,
24
25
AverageObservableLogger,
25
26
ReplicaExchangeLogger,
26
- MonteCarloLogger,
27
- DisplacementsLogger
27
+ MonteCarloLogger
28
28
29
29
"""
30
30
apply_loggers!(system, neighbors=nothing, step_n=0, run_loggers=true;
@@ -301,7 +301,6 @@ function virial_wrapper(sys, neighbors, step_n; n_threads, kwargs...)
301
301
return virial (sys, neighbors, step_n; n_threads= n_threads)
302
302
end
303
303
304
-
305
304
"""
306
305
VirialLogger(n_steps)
307
306
VirialLogger(T, n_steps)
@@ -342,6 +341,58 @@ function Base.show(io::IO, pl::GeneralObservableLogger{T, typeof(pressure_wrappe
342
341
pl. n_steps, " , " , length (values (pl)), " pressures recorded" )
343
342
end
344
343
344
+ """
345
+ DisplacementsLogger(n_steps, coords_start; n_steps_update::Integer=10)
346
+
347
+ Log the displacements of atoms in a system throughout a simulation, useful for calculating
348
+ properties like mean square displacement in periodic systems.
349
+
350
+ Displacements are updated every `n_steps_update` steps and a copy is saved every
351
+ `n_steps` steps.
352
+ `coords_start` are the initial reference positions and should match the coordinate type
353
+ in the system.
354
+
355
+ It is assumed that a particle does not cross half the box size in `n_steps_update` steps.
356
+ By default `n_steps_update` is set to 10 to mitigate this assumption, but it can be
357
+ set to a higher value to reduce cost.
358
+ `n_steps` must be a multiple of `n_steps_update`.
359
+ """
360
+ mutable struct DisplacementsLogger{D, C}
361
+ displacements:: D
362
+ coords_ref:: C
363
+ last_displacements:: C
364
+ n_steps:: Int
365
+ n_steps_update:: Int
366
+ end
367
+
368
+ function DisplacementsLogger (n_steps:: Integer , coords_start; n_steps_update:: Integer = 10 )
369
+ if n_steps % n_steps_update != 0
370
+ throw (ArgumentError (" DisplacementsLogger n_steps ($n_steps ) must be a multiple of " *
371
+ " n_steps_update ($n_steps_update )" ))
372
+ end
373
+ displacements = typeof (from_device (coords_start))[]
374
+ return DisplacementsLogger (displacements, copy (coords_start), zero (coords_start),
375
+ n_steps, n_steps_update)
376
+ end
377
+
378
+ Base. values (dl:: DisplacementsLogger ) = dl. displacements
379
+
380
+ function log_property! (dl:: DisplacementsLogger , sys:: System , neighbors= nothing ,
381
+ step_n:: Integer = 0 ; kwargs... )
382
+ if (step_n % dl. n_steps_update) == 0
383
+ dl. last_displacements .+ = vector .(dl. coords_ref, sys. coords, (sys. boundary,))
384
+ dl. coords_ref .= sys. coords
385
+ if (step_n % dl. n_steps) == 0
386
+ push! (dl. displacements, Array (dl. last_displacements))
387
+ end
388
+ end
389
+ end
390
+
391
+ function Base. show (io:: IO , dl:: DisplacementsLogger )
392
+ print (io, " DisplacementsLogger with update n_steps " , dl. n_steps_update, " , saving n_steps " ,
393
+ dl. n_steps, " , " , length (dl. displacements), " displacements recorded" )
394
+ end
395
+
345
396
pdb_cryst1_length (l_Å) = lpad (round (l_Å; digits= 3 ), 9 )
346
397
pdb_cryst1_angle (θ_rad) = lpad (round (rad2deg (θ_rad); digits= 2 ), 7 )
347
398
@@ -958,54 +1009,3 @@ function log_property!(mcl::MonteCarloLogger{T},
958
1009
push! (mcl. state_changed, success)
959
1010
push! (mcl. energy_rates, energy_rate)
960
1011
end
961
-
962
-
963
- """
964
- DisplacementsLogger(n_steps, r0; n_update::Integer=1, dims::Integer=3)
965
-
966
- Log the displacements of atoms in a system throughout a simulation. Displacements are
967
- updated every `n_update` steps and saved every `n_steps` steps. `r0` are the
968
- intitial refernce positions and should match the coords type in your `System` object.
969
-
970
- The logger assumes a particle does not cross 2 periodic boxes in `n_update` steps.
971
- By default `n_update` is set to one to mitigate this assumption, but it can be
972
- set to a higher value to reduce cost. `n_steps` must be a multiple of `n_update`.
973
- """
974
- mutable struct DisplacementsLogger{A, B}
975
- displacements:: Vector{A}
976
- reference:: Vector{B}
977
- last_displacements:: Vector{B}
978
- n_steps:: Int
979
- n_update:: Int
980
- end
981
-
982
-
983
- function DisplacementsLogger (n_steps:: Integer , r0; n_update:: Integer = 1 , dims:: Integer = 3 )
984
- T = eltype (first (r0))
985
- B = SArray{Tuple{dims}, T, 1 , dims}
986
- A = Array{B, 1 }
987
- if n_steps % n_update != 0
988
- throw (ArgumentError (" DisplacementsLogger: n_steps ($n_steps ) must be a multiple n_update ($(n_update) )" ))
989
- end
990
- return DisplacementsLogger {A, B} (A[], copy (r0), zero (r0), n_steps, n_update)
991
- end
992
-
993
- Base. values (dl:: DisplacementsLogger ) = dl. displacements
994
-
995
- function log_property! (dl:: DisplacementsLogger , s:: System , neighbors= nothing ,
996
- step_n:: Integer = 0 ; kwargs... )
997
-
998
- if (step_n % dl. n_update) == 0
999
- dl. last_displacements .+ = vector .(dl. reference, s. coords, Ref (s. boundary))
1000
- dl. reference .= s. coords
1001
- if (step_n % dl. n_steps) == 0
1002
- push! (dl. displacements, copy (dl. last_displacements))
1003
- end
1004
- end
1005
- end
1006
-
1007
- function Base. show (io:: IO , dl:: DisplacementsLogger )
1008
- print (io, " DisplacementsLogger with updating every " , dl. n_update, " steps, saving every " ,
1009
- dl. n_steps, " steps with " , length (dl. displacements), " displacements in storage." )
1010
- end
1011
-
0 commit comments