-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow.py
2826 lines (2451 loc) · 102 KB
/
flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Module flow provides classes to compute and analyse displacements, velocities,
and orientations in order to characterise the flow of systems of active
particles.
(see https://yketa.github.io/DAMTP_MSC_2019_Wiki/#ABP%20flow%20characteristics)
"""
import numpy as np
from scipy.stats import norm as norm_gen
from scipy.special import lambertw
from collections import OrderedDict
from operator import itemgetter
import struct
from coll_dyn_activem.read import Dat
from coll_dyn_activem.structure import Positions
from coll_dyn_activem.maths import pycpp, Distribution, JointDistribution,\
mean_sterr, linspace, logspace, angle, divide_arrays, wo_mean,\
wave_vectors_dq, normalise1D
from coll_dyn_activem.rotors import nu_pdf_th as nu_pdf_th_ABP
from coll_dyn_activem._pycpp import getBondsBrokenBonds
# CLASSES
class Displacements(Positions):
"""
Compute and analyse displacements from simulation data.
(see https://yketa.github.io/DAMTP_MSC_2019_Wiki/#Active%20Brownian%20particles)
"""
def getDisplacements(self, time0, time1, *particle, jump=1, norm=False,
remove_cm=False, cage_relative=False, neighbours=None):
"""
Returns displacements of particles between `time0' and `time1'.
Parameters
----------
time0 : int
Initial frame.
time1 : int
Final frame.
particle : int
Indexes of particles.
NOTE: if none is given, then all particles are returned.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1)
NOTE: `jump' must be chosen so that particles do not move a distance
greater than half the box size during this time.
NOTE: This is only relevant for .dat files since these do not embed
unfolded positions.
norm : bool
Return norm of displacements rather than 2D displacements.
(default: False)
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours determined by Voronoi tesselation at `time0'.
(default: False)
neighbours : coll_dyn_activem.maths.DictList or None
Neighbour list (see self.getNeighbourList) to use if
`cage_relative'. (default: None)
NOTE: if neighbours == None, then it is computed with
self.getNeighbourList.
Returns
-------
displacements : [not(norm)] (*, 2) float Numpy array
[norm] (*,) float Numpy array
Displacements between `time0' and `time1'.
"""
if particle == (): particle = range(self.N)
if not(cage_relative):
return super().getDisplacements(
time0, time1, *particle, jump=jump, norm=norm,
remove_cm=remove_cm)
origDisplacements = super().getDisplacements(
time0, time1, jump=jump, norm=False, remove_cm=remove_cm)
if type(neighbours) == type(None):
neighbours = self.getNeighbourList(time0)
displacements = np.array(
itemgetter(*particle)(origDisplacements.copy()))
for i, index in zip(particle, range(len(particle))):
if not(i in neighbours): continue # no neighbours
nNeighbours = len(neighbours[i])
for (j, _) in neighbours[i]:
displacements[index] -= origDisplacements[j]/nNeighbours
if norm: return np.sqrt(np.sum(displacements**2, axis=-1))
return displacements
def nDisplacements(self, dt, int_max=None, jump=1, norm=False,
remove_cm=False, cage_relative=False):
"""
Returns array of displacements with lag time `dt'.
Parameters
----------
dt : int
Displacement lag time.
int_max : int or None
Maximum number of intervals to consider. (default: None)
NOTE: If int_max == None, then take the maximum number of intervals.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
norm : bool
Return norm of displacements rather than 2D displacement.
(default: False)
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
Returns
-------
displacements : [not(norm)] (*, self.N, 2) float numpy array
[norm] (*, self.N) float numpy array
Array of computed displacements.
"""
displacements = []
for time0 in self._time0(dt, int_max=int_max):
displacements += [
self.getDisplacements(time0, time0 + dt, jump=jump, norm=norm,
remove_cm=remove_cm, cage_relative=cage_relative)]
displacements = np.array(displacements)
return displacements
def displacementsPDF(self, dt, int_max=None, jump=1,
remove_cm=False, cage_relative=False):
"""
Returns probability density function of displacement norm over lag time
`dt'.
Parameters
----------
dt : int
Displacement lag time.
int_max : int or None
Maximum number of intervals to consider. (default: None)
NOTE: If int_max == None, then take the maximum number of intervals.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
Returns
-------
axes : numpy array
Values at which the probability density function is evaluated.
pdf : float numpy array
Values of the probability density function.
"""
return Distribution(
self.nDisplacements(
dt, int_max=int_max, jump=jump, norm=True,
remove_cm=remove_cm, cage_relative=cage_relative)).pdf()
def displacementsHist(self,
dt, nBins, int_max=None, jump=1, remove_cm=False, cage_relative=False,
vmin=None, vmax=None, log=False, rescaled_to_max=False):
"""
Returns histogram with `nBins' bins of displacement norm over lag time
`dt'.
Parameters
----------
dt : int
Displacement lag time.
nBins : int
Number of bins of the histogram.
int_max : int or None
Maximum number of intervals to consider. (default: None)
NOTE: If int_max == None, then take the maximum number of intervals.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
vmin : float
Minimum value of the bins. (default: minimum computed displacement)
vmax : float
Maximum value of the bins. (default: maximum computed displacement)
log : bool
Consider the log of the occupancy of the bins. (default: False)
rescaled_to_max : bool
Rescale occupancy of the bins by its maximum over bins.
(default: False)
Returns
-------
bins : float numpy array
Values of the bins.
hist : float numpy array
Occupancy of the bins.
"""
return Distribution(self.nDisplacements(
dt, int_max=int_max, jump=jump, norm=True,
remove_cm=remove_cm, cage_relative=cage_relative)).hist(
nBins, vmin=vmin, vmax=vmax, log=log,
rescaled_to_max=rescaled_to_max)
def dtDisplacements(self, dt, int_max=100, jump=1, norm=False,
remove_cm=False, cage_relative=False, initial_times=False):
"""
Returns array of displacements with lag times `dt'.
Parameters
----------
dt : int array-like
Displacement lag times.
int_max : int
Maximum number of intervals to consider. (default: 100)
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
norm : bool
Return norm of displacements rather than 2D displacement.
(default: False)
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
initial_times : bool
Return initial times at which displacements are computed.
(default: False)
Returns
-------
displacements : [not(norm)] (*, dt.size, self.N, 2) float numpy array
[norm] (*, dt.size, self.N) float numpy array
Array of computed displacements.
time0 : [initial_times] (*,) int numpy array
Initial times at which displacements are computed.
"""
dt = np.array(dt)
# array of initial times
if self._type == 'datN':
time0 = self.time0 if self.time0.size == 1 else np.array(itemgetter(
*linspace(self.skip, len(self.time0) - 1, int_max,
endpoint=True))(
self.time0),
ndmin=1)
else:
time0 = np.array(list(OrderedDict.fromkeys(
np.linspace(self.skip, self.frames - dt.max() - 1, int_max,
endpoint=False, dtype=int))),
ndmin=1)
if self._type == 'dat':
displacements = np.empty((time0.size, dt.size, self.N, 2))
for j in range(dt.size):
if j > 0:
for i in range(time0.size):
displacements[i][j] = ( # displacements between time0[i] and time0[i] + dt[j]
displacements[i][j - 1] # displacements between time0[i] and time0[i] + dt[j - 1]
+ self.getDisplacements( # displacements between time0[i] + dt[j - 1] and time0[i] + dt[j]
time0[i] + dt[j - 1], time0[i] + dt[j],
jump=jump,
remove_cm=remove_cm,
cage_relative=cage_relative))
else:
for i in range(time0.size):
displacements[i][0] = self.getDisplacements( # displacements between time0[i] and time0[i] + dt[0]
time0[i], time0[i] + dt[0],
jump=jump,
remove_cm=remove_cm,
cage_relative=cage_relative)
else:
if cage_relative:
neighbours = list(map(
lambda t0: self.getNeighbourList(t0),
time0))
else: neighbours = np.full(time0.shape, fill_value=None)
displacements = np.array(list(map(
lambda t0: list(map(
lambda t: self.getDisplacements(t0, t0 + t,
remove_cm=remove_cm,
cage_relative=cage_relative,
neighbours=neighbours[time0.tolist().index(t0)]),
dt)),
time0)))
if norm: return np.sqrt(np.sum(displacements**2, axis=-1))
if initial_times: return displacements, time0
return displacements
def msd(self, n_max=100, int_max=100, min=None, max=None, jump=1,
cage_relative=False, dtDisplacements=None):
"""
Compute mean square displacement.
(see https://yketa.github.io/DAMTP_MSC_2019_Wiki/#ABP%20flow%20characteristics)
Parameters
----------
n_max : int
Maximum number of lag times at which to compute the displacements.
(default: 100)
NOTE: This is overridden if dtDisplacements != None.
int_max : int
Maximum number of different intervals to consider when computing
displacements for a given lag time. (default: 100)
NOTE: This is overridden if dtDisplacements != None.
min : int or None
Minimum lag time at which to compute the displacements.
(default: None)
NOTE: if min == None, then min = 1.
NOTE: This is overridden if dtDisplacements != None.
max : int or None
Maximum lag time at which to compute the displacements.
(default: None)
NOTE: if max == None, then max is taken to be the maximum according
to the choice of int_max.
NOTE: This is overridden if dtDisplacements != None.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
NOTE: This is overridden if dtDisplacements != None.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
NOTE: This is overridden if dtDisplacements != None.
dtDisplacements : ((*,) int array-like,
(**, *, self.N, 2) float array-like) or None
Lag time and displacements at these lag times from which to compute
quantity.
NOTE: if dtDisplacements == None, then compute with
self._displacements.
Returns
-------
msd_stderr_chi : (*, 4) float numpy array
Array of:
(0) lag time,
(1) mean square displacement,
(2) standard error on the computed mean square displacement,
(3) susceptibility of the computed mean square displacement.
(see self._mean_stderr_chi)
"""
if type(dtDisplacements) == type(None):
dt, displacements = self._displacements(
n_max=n_max, int_max=int_max, min=min, max=max, jump=jump,
cage_relative=cage_relative,
initial_times=False)
else:
dt, displacements = dtDisplacements
quantities = (wo_mean(displacements, axis=-2)**2).sum(axis=-1)
return self._mean_stderr_chi(dt, quantities)
def msd_th_ABP(self, dt):
"""
Returns value of theoretical mean squared displacement at lag time `dt'
for a single ABP.
(see https://yketa.github.io/DAMTP_MSC_2019_Wiki/#One%20ABP)
Parameters
----------
dt : float
Lag time at which to evaluate the theoretical mean squared
displacement.
Returns
-------
msd : float
Mean squared displacement.
"""
if self._type == 'dat': # custom relations between parameters
return msd_th_ABP(self.v0, 1./(3.*self.lp), 1./self.lp, dt)
else: # general parameters
return msd_th_ABP(self.v0, self.D, self.Dr, dt)
def msd_th_AOUP(self, dt):
"""
Returns value of theoretical mean squared displacement at lag time `dt'
for a single AOUP.
Parameters
----------
dt : float
Lag time at which to evaluate the theoretical mean squared
displacement.
Returns
-------
msd : float
Mean squared displacement.
"""
return msd_th_AOUP(self.D, self.Dr, dt)
def displacementsCor(self, dt, nBins, int_max=100, min=None, max=None,
jump=1, transformation=(lambda disp: disp), remove_cm=False,
rescale_pair_distribution=False):
"""
Compute radial correlations of particles' displacements.
Parameters
----------
dt : int
Lag time at which to compute displacements.
nBins : int
Number of intervals of distances on which to compute the
correlations.
int_max : int
Maximum number of different intervals to consider when computing
displacements for a given lag time. (default: 100)
min : float or None
Minimum distance (included) at which to compute the correlations.
(default: None)
NOTE: if min == None then min = 0.
max : float or None
Maximum distance (excluded) at which to compute the correlations.
(default: None)
NOTE: if max == None then max = self.L/2.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
transformation : function of numpy array to numpy array
Transformation to apply on individual particles' displacement
((2,) float numpy array) before computing the correlations.
(default: (lambda disp: disp))
NOTE: transformed displacements are then divided by their root mean
square.
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
rescale_pair_distribution : bool
Rescale correlations by pair distribution function. (default: False)
Returns
-------
Cuu : (*, 3) float Numpy array
Array of (r, Cuu(r), errCuu(r)) with Cuu(r) the cylindrically
averaged spatial correlations of displacement and errCuu(r) the
standard error on this measure.
zeta : (2,) float Numpy array
Cooperativity and standard error on this measure.
"""
time0 = self._time0(dt, int_max=int_max)
displacements = np.array(list(map(
lambda t: (lambda d: d/np.sqrt((d**2).sum(axis=-1).mean()))(
np.array(list(map(
lambda disp: np.array(transformation(disp), ndmin=1),
self.getDisplacements(t, t + dt,
jump=jump, norm=False, remove_cm=remove_cm,
cage_relative=False, neighbours=None))))),
time0)))
corZeta = list(map(
lambda t, d: self.getRadialCorrelations(
t, d, nBins, min=min, max=max,
rescale_pair_distribution=rescale_pair_distribution),
*(time0, displacements)))
correlations = np.array([corZeta[t][0] for t in range(len(corZeta))])
zeta = np.array([corZeta[t][1] for t in range(len(corZeta))])
return (
np.array([
[correlations[0, bin, 0],
*mean_sterr(correlations[:, bin, 1])]
for bin in range(nBins)]),
mean_sterr(zeta))
def overlap(self, a=1, n_max=100, int_max=100, min=None, max=None, jump=1,
cage_relative=False, dtDisplacements=None, heaviside=False):
"""
Compute dynamical overlap function.
Parameters
----------
a : float
Parameter of the dynamical overlap function. (default: 1)
n_max : int
Maximum number of lag times at which to compute the displacements.
(default: 100)
NOTE: This is overridden if dtDisplacements != None.
int_max : int
Maximum number of different intervals to consider when computing
displacements for a given lag time. (default: 100)
NOTE: This is overridden if dtDisplacements != None.
min : int or None
Minimum lag time at which to compute the displacements.
(default: None)
NOTE: if min == None, then min = 1.
NOTE: This is overridden if dtDisplacements != None.
max : int or None
Maximum lag time at which to compute the displacements.
(default: None)
NOTE: if max == None, then max is taken to be the maximum according
to the choice of int_max.
NOTE: This is overridden if dtDisplacements != None.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
NOTE: This is overridden if dtDisplacements != None.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
NOTE: This is overridden if dtDisplacements != None.
heaviside : bool
Use Heaviside function rather than exponential of square as window
function. (default: False)
dtDisplacements : ((*,) int array-like,
(**, *, self.N, 2) float array-like) or None
Lag time and displacements at these lag times from which to compute
quantity.
NOTE: if dtDisplacements == None, then compute with
self._displacements.
Returns
-------
Q_stderr_chi : (*, 4) float numpy array
Array of:
(0) lag time,
(1) dynamical overlap,
(2) standard error on the computed dynamical overlap,
(3) susceptibility of the computed dynamical overlap.
(see self._mean_stderr_chi)
"""
if type(dtDisplacements) == type(None):
dt, displacements = self._displacements(
n_max=n_max, int_max=int_max, min=min, max=max, jump=jump,
cage_relative=cage_relative,
initial_times=False)
else:
dt, displacements = dtDisplacements
displacements2 = (wo_mean(displacements/a, axis=-2)**2).sum(axis=-1)
if heaviside: quantities = (displacements2 > 1)*1.0
else: quantities = np.exp(-displacements2)
return self._mean_stderr_chi(dt, quantities)
def overlap_relaxation_free_AOUP(q=0.5, a=1):
"""
Returns relaxation time for a free Ornstein-Uhlenbeck particle, given as
the time for the dynamical overlap function to decrease below threshold
`q'.
Parameters
----------
q : float
Dynamical overlap function threshold. (default: 0.5)
a : float
Parameter of the dynamical overlap function. (default: 1)
Returns
-------
t : float
Relaxation time.
"""
return overlap_relaxation_free_AOUP(self.D, self.Dr, q=q, a=a)
def selfIntScattFunc(self, k, dk=0.1,
n_max=100, int_max=100, min=None, max=None,
jump=1, cage_relative=False, dtDisplacements=None):
"""
Compute self-intermediate scattering function.
Parameters
----------
k : float
Wave-vector norm.
dk : float
Width of the wave-vector norm interval. (default: 0.1)
(see coll_dyn_activem.maths.wave_vectors_dq)
n_max : int
Maximum number of lag times at which to compute the displacements.
(default: 100)
NOTE: This is overridden if dtDisplacements != None.
int_max : int
Maximum number of different intervals to consider when computing
displacements for a given lag time. (default: 100)
NOTE: This is overridden if dtDisplacements != None.
min : int or None
Minimum lag time at which to compute the displacements.
(default: None)
NOTE: if min == None, then min = 1.
NOTE: This is overridden if dtDisplacements != None.
max : int or None
Maximum lag time at which to compute the displacements.
(default: None)
NOTE: if max == None, then max is taken to be the maximum according
to the choice of int_max.
NOTE: This is overridden if dtDisplacements != None.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
NOTE: This is overridden if dtDisplacements != None.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
NOTE: This is overridden if dtDisplacements != None.
dtDisplacements : ((*,) int array-like,
(**, *, self.N, 2) float array-like) or None
Lag time and displacements at these lag times from which to compute
quantity.
NOTE: if dtDisplacements == None, then compute with
self._displacements.
Returns
-------
Fs_stderr_chi : (*, 4) float numpy array
Array of:
(0) lag time,
(1) self-intermediate scattering function,
(2) standard error on the computed self-intermediate scattering
function,
(3) susceptibility of the computed self-intermediate scattering
function.
(see self._mean_stderr_chi)
wv : (*, 2) float Numpy array
Array of (2\\pi/L nx, 2\\pi/L ny) wave vectors corresponding to the
interval.
"""
if type(dtDisplacements) == type(None):
dt, displacements = self._displacements(
n_max=n_max, int_max=int_max, min=min, max=max, jump=jump,
cage_relative=cage_relative,
initial_times=False)
else:
dt, displacements = dtDisplacements
wave_vectors = wave_vectors_dq(self.L, k, dq=dk)
dx, dy = (
np.transpose(wo_mean(displacements, axis=-2), axes=(3, 0, 1, 2)))
_msc = np.array(list(map(
lambda kx, ky: self._mean_stderr_chi(dt, np.cos(kx*dx + ky*dy)),
*np.transpose(wave_vectors))))
assert _msc[:, :, 0].var(axis=0).sum() < 1e-12 # check Fs are computed at the same lag times
msc = np.transpose([
_msc[0, :, 0], # lag times
_msc[:, :, 1].mean(axis=0), # self-intermediate scattering function
np.sqrt((_msc[:, :, 2]**2).mean(axis=0)), # standard error
_msc[:, :, 3].mean(axis=0)]) # susceptibility
return msc, wave_vectors
def selfIntScattFunc_relaxation_free_AOUP(k):
"""
Returns structural relaxation time for a free Ornstein-Uhlenbeck
particle, given as the time for the self-intermediate scattering
function to decrease below \\exp(-1).
Parameters
----------
k : float
Wave-vector norm.
Returns
-------
t : float
Relaxation time.
"""
return selfIntScattFunc_relaxation_free_AOUP(k, self.D, self.Dr)
def vanHove(self, dt, nBins, int_max=None, jump=1, remove_cm=False,
cage_relative=False, vmin=None, vmax=None):
"""
Compute van Hove function.
Parameters
----------
dt : int
Displacement lag time.
nBins : int
Number of bins of the histogram.
int_max : int or None
Maximum number of intervals to consider. (default: None)
NOTE: If int_max == None, then take the maximum number of intervals.
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1) (see self.getDisplacements)
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
cage_relative : bool
Remove displacement of the centre of mass given by nearest
neighbours at initial time. (default: False)
(see self.getDisplacements)
vmin : float
Minimum value of the bins. (default: None)
NOTE: if vmin == None, then vmin = 0.
vmax : float
Maximum value of the bins. (default: None)
NOTE: if vmax == None, then vmax = self.L/2.
Returns
-------
G : (*, 2) float numpy array
Array of:
(0) distance,
(1) radial van Hove function,
(2) standard error on this measure.
Gs : (*, 2) float numpy array
Array of:
(0) distance,
(1) self part of the radial van Hove function,
(2) standard error on this measure.
"""
time0 = self._time0(dt, int_max=int_max)
vmin = 0 if vmin == None else vmin
vmax = self.L/2 if vmax == None else vmax
_G, _Gs = [], []
for t0 in time0:
positions = self.getPositions(t0)
displacements = self.getDisplacements(t0, t0 + dt,
jump=jump, norm=False,
remove_cm=remove_cm, cage_relative=cage_relative)
distances = pycpp.getVanHoveDistances(
positions, displacements, self.L)
for dist, _list in zip(
(distances, np.sqrt((displacements**2).sum(axis=-1))),
(_G, _Gs)):
bins, hist = Distribution(dist).hist(
nBins, vmin=vmin, vmax=vmax,
log=False, rescaled_to_max=False, occupation=True)
hist = hist[bins > 0]
hist /= distances.size
bins = bins[bins > 0]
_list += [
(hist/(2*np.pi*bins)) # radial
*(self.N/((vmax - vmin)/nBins))] # normalisation
G = np.array([[b, *mean_sterr(g)]
for b, g in zip(bins, np.transpose(_G))])
Gs = np.array([[b, *mean_sterr(gs)]
for b, gs in zip(bins, np.transpose(_Gs))])
return G, Gs
def orientationNeighbours(self, time0, *dt, A1=1.15, jump=1,
remove_cm=False):
"""
Returns arrays of number of neighbouring particles which have the same
displacement orientation between `time0' and `time0' + `dt'.
Parameters
----------
time0 : int
Initial time.
dt : int
Lag time.
A1 : float
Distance relative to their diameters below which particles are
considered bonded. (default: 1.15)
jump : int
Period in number of frames at which to check if particles have
crossed any boundary. (default: 1)
NOTE: `jump' must be chosen so that particles do not move a distance
greater than half the box size during this time.
NOTE: This is only relevant for .dat files since these do not embed
unfolded positions.
remove_cm : bool
Remove centre of mass displacement. (default: False)
NOTE: does not affect result if self.N == 1.
Returns
-------
oneigbours : (**, self.N) int numpy array
Number of neighbouring particles with same displacement orientation
between `time0' and `time0' + `dt' with ** the number of `dt'
provided.
"""
return pycpp.getOrientationNeighbours(A1, self.L, self.diameters,
self.getPositions(time0),
*[self.getDisplacements(
time0, time0 + t, jump=jump, remove_cm=remove_cm)
for t in dt])
def brokenBonds(self, time0, *dt, A1=1.15, A2=1.5, diameters=True):
"""
Returns arrays of number of broken bonds for each particle, defined by
the number of particles at distance lesser than `A1' at `time0' and
greater than `A2' at `time0' + `dt'.
Parameters
----------
time0 : int
Initial time.
dt : int
Lag time.
A1 : float
Distance below which particles are considered bonded.
(default: 1.15)
A2 : float
Distance above which particles are considered unbonded.
(default: 1.5)
diameters : bool
Rescale distances by respective average diameters. (default: True)
Returns
-------
brokenBonds : (**, self.N) int numpy array
Number of broken bonds between `time0' and `time0' + `dt' with **
the number of `dt' provided.
"""
if diameters: sigma = self.diameters
else: sigma = np.full(self.diameters.shape, fill_value=1)
return pycpp.getBrokenBonds(A1, A2, self.L, sigma,
self.getPositions(time0),
*[self.getPositions(time0 + t) for t in dt])
def brokenBondsCor(self, dt, nBins, brokenBondsMin=1, A1=1.15, A2=1.5,
int_max=100, min=None, max=None, rescale_pair_distribution=False):
"""
Compute radial correlations of broken bonds.
Parameters
----------
dt : int
Lag time at which to compute broken bonds.
nBins : int
Number of intervals of distances on which to compute the
correlations.
brokenBondsMin : int
Threshold on the number of broken bonds. (default: 1)
A1 : float
Distance relative to their diameters below which particles are
considered bonded. (default: 1.15)
A2 : float
Distance relative to their diameters above which particles are
considered unbonded. (default: 1.5)
int_max : int
Maximum number of different intervals to consider when computing
broken boonds for a given lag time. (default: 100)
min : float or None
Minimum distance (included) at which to compute the correlations.
(default: None)
NOTE: if min == None then min = 0.
max : float or None
Maximum distance (excluded) at which to compute the correlations.
(default: None)
NOTE: if max == None then max = self.L/2.
rescale_pair_distribution : bool
Rescale correlations by pair distribution function. (default: False)
Returns
-------
bb : (*,) float Numpy array
Array of proportion of particles with at least brokenBondsMin broken
bonds.
Cbb : (*, 3) float Numpy array
Array of (r, Cbb(r), errCbb(r)) with Cbb(r) the cylindrically
averaged spatial correlations of broken bonds and errCbb(r) the
standard error on this measure.
zeta : (2,) float Numpy array
Cooperativity and standard error on this measure.
chi : float
Susceptibility of broken bonds.
"""
time0 = self._time0(dt, int_max=int_max)
bonds = np.array(list(map(
lambda t:
(self.brokenBonds(t, dt, A1=A1, A2=A2)[0] >= brokenBondsMin)*1,
time0)))
corZeta = list(map(
lambda t, b: self.getRadialCorrelations(
t, b/((lambda B: 1 if B == 0 else B)(np.sqrt((b**2).mean()))),
nBins, min=min, max=max,
rescale_pair_distribution=rescale_pair_distribution),
*(time0, bonds)))
correlations = np.array([corZeta[t][0] for t in range(len(corZeta))])
zeta = np.array([corZeta[t][1] for t in range(len(corZeta))])
chi = self.N*bonds.mean(axis=-1).var()
return (
bonds.mean(axis=-1),
np.array([
[correlations[0, bin, 0],
*mean_sterr(correlations[:, bin, 1])]
for bin in range(nBins)]),
mean_sterr(zeta),
chi)
def bondBreakingCor(self, A1=1.15, A2=1.5,
n_max=100, int_max=100, min=None, max=None):
"""
Compute bond breaking correlation function.
Parameters
----------
A1 : float
Distance relative to their diameters below which particles are
considered bonded. (default: 1.15)
A2 : float
Distance relative to their diameters above which particles are
considered unbonded. (default: 1.5)
n_max : int
Maximum number of lag times at which to compute the broken bonds.
(default: 100)
int_max : int
Maximum number of different intervals to consider when computing
broken bonds for a given lag time. (default: 100)
min : int or None
Minimum lag time at which to compute the broken bonds.
(default: None)
NOTE: if min == None, then min = 1.
max : int or None
Maximum lag time at which to compute the broken bonds.
(default: None)
NOTE: if max == None, then max is taken to be the maximum according
to the choice of int_max.
Returns
-------
Fb : (*, 3) float Numpy array
Array of:
(0) lag time,
(1) velocity correlation at this lag time,
(2) standard error on this measure.
"""
# LAG TIMES AND INITIAL TIMES
time0, dt = self._dt(n_max=n_max, int_max=int_max, min=min, max=max)
# COMPUTE CORRELATIONS
bb = np.array(list(map(
lambda t0: (
lambda pos0: list(map(
lambda dt: (
lambda ini, fin: 1 - fin.sum()/ini.sum())(
*getBondsBrokenBonds(
pos0,
self.getDisplacements(t0, t0 + dt, remove_cm=True),
self.diameters, self.L, A1=A1, A2=A2)),
dt)))(
self.getPositions(t0)),
time0)))
return np.array(list(map(
lambda i, b: [dt[i], *mean_sterr(b)],
*(range(bb.shape[1]), np.transpose(bb)))))
def brokenPairs(self, time0, time1, A1=1.15, A2=1.5):
"""
Returns array of broken bond truth values for each pair, where particles
in the pair are at distance lesser than `A1' at `time0' and greater than
`A2' at `time1'.
(see pycpp.pairIndex)
Parameters
----------