@@ -190,6 +190,7 @@ def compute_vaf(
190190 fft : bool = False ,
191191 index : SliceLike = (0 , None , 1 ),
192192 filter_atoms : MaybeSequence [MaybeSequence [int ]] = ((),),
193+ time_step : float = 1. ,
193194) -> NDArray [float64 ]:
194195 """
195196 Compute the velocity autocorrelation function (VAF) of `data`.
@@ -212,6 +213,9 @@ def compute_vaf(
212213 filter_atoms : MaybeSequence[MaybeSequence[int]]
213214 Compute the VAF averaged over subsets of the system.
214215 Default is all atoms.
216+ time_step : float
217+ Time step for scaling lags to align with input data.
218+ Default is 1 (i.e. no scaling).
215219
216220 Returns
217221 -------
@@ -238,9 +242,7 @@ def compute_vaf(
238242 data = data [slice (* index )]
239243
240244 if use_velocities :
241- momenta = np .asarray (
242- [datum .get_momenta () / datum .get_masses () for datum in data ]
243- )
245+ momenta = np .asarray ([datum .get_velocities () for datum in data ])
244246 else :
245247 momenta = np .asarray ([datum .get_momenta () for datum in data ])
246248
@@ -270,17 +272,21 @@ def compute_vaf(
270272
271273 vafs /= n_steps - np .arange (n_steps )
272274
275+ lags = np .arange (n_steps ) * time_step
276+
273277 if fft :
274278 vafs = np .fft .fft (vafs , axis = 0 )
279+ lags = 1. / lags
275280
276- vafs = [
281+ vafs = ( lags , [
277282 np .average ([vafs [used_atoms [i ]] for i in atoms ], axis = 0 )
278283 for atoms in filter_atoms
279- ]
284+ ])
280285
281286 if filenames :
282- for filename , vaf in zip (filenames , vafs ):
287+ for vaf , filename in zip (vafs [ 1 ], filenames ):
283288 with open (filename , "w" , encoding = "utf-8" ) as out_file :
284- print (* vaf , file = out_file , sep = "\n " )
289+ for lag , dat in zip (lags , vaf ):
290+ print (lag , dat , file = out_file )
285291
286292 return vafs
0 commit comments