Generates normalized Fractional Gaussian noise. This means that, in general: \[
<x^2(t) > = 2Dt^{alpha}
\]
and in particular: \[
<x^2(t = 1)> = 2D
\]
Type
Default
Details
alpha
float
Anomalous exponent
D
float
Diffusion coefficient
T
int
Number of displacements to generate
deltaT
int
1
Sampling time
Returns
numpy.array
Array containing T displacements of given parameters
Properties of FBM
Understanding the normalization
These lines show why we need to multiply by np.sqrt(T)**alpha. Our goal is to have a random number generator with standard deviation equal to one. This does not happen with FGN above, hence the extra line:
n_disp =10000alphas = np.linspace(0.2, 1.8, 20)std_og = [np.std(FGN(hurst = alpha/2).sample(n = n_disp)) for alpha in alphas]std_norm = [np.std(FGN(hurst = alpha/2).sample(n = n_disp)*(np.sqrt(n_disp)**alpha)) for alpha in alphas]plt.figure(figsize = (3,3))plt.plot(alphas, std_og, label ='Original')plt.plot(alphas, std_norm, label ='Normalized') plt.xlabel(r'$\alpha$'); plt.ylabel(r'STD($\xi$)')plt.legend()
<matplotlib.legend.Legend>
MSD and VACF
The following shows that the generated displacements have the desired properties. Namely, we can choose \(D\) and \(\alpha\) at will and the function will correctly normalize the displacements. For that, we generate trajectories and estimate parameters of the MSD and VACF from analysis class.
Given information of the anomalous exponents (alphas), diffusion coefficients (Ds), the function samples these from a bounded Gaussian distribution with the indicated constraints (epsilon_a, gamma_d). Outputs the list of demanded alphas and Ds.
Type
Details
alphas
list
List containing the parameters to sample anomalous exponent in state (adapt to sampling function)
Ds
list
List containing the parameters to sample the diffusion coefficient in state (adapt to sampling function).
num_states
int
Number of diffusive states.
epsilon_a
float
Minimum distance between anomalous exponents of various states.
gamma_d
float
Factor between diffusion coefficient of various states.
We can test that this distances are taken into account when generating trajectories:
N =1000; L =50; T =2;epsilon_a=[0.5]; gamma_d = [0.75]trajs, labels = models_phenom().multi_state( epsilon_a=epsilon_a, gamma_d = gamma_d, # This is the important part T = T, N = N, L = L, Ds = np.array([[2, 0], [2, 0.2]]), alphas = np.array([[1, 0], [0.75, 0.1]]), return_state_num=True)
fig, ax = plt.subplots(1,2,figsize = (6, 3), tight_layout =True)alphas = labels[:,:,0].flatten()Ds = labels[:,:,1].flatten()states_num = labels[:,:,3].flatten()for s in np.unique(states_num): ax[0].hist(alphas[states_num == s], bins =100, density =True); ax[1].hist(Ds[states_num == s], bins =100, density =True);ax[0].set_title(fr'Distribution of $\alpha$ - $\epsilon_a = {epsilon_a[0]}$')ax[1].set_title(fr'Distribution of $D$ - $\gamma_d = {gamma_d[0]}$')plt.setp(ax, ylim = [0,10])ax[0].set_xlim(0,1.1); ax[1].set_xlim(0,2.1)ax[0].set_ylabel('Frequency')
Text(0, 0.5, 'Frequency')
Single state model
Particles diffusing according to a single diffusion state, as observed for some lipids in the plasma membrane or for nanoparticles in the cellular environment.
Particles diffusing according to a time-dependent multi-state (2 or more) model of diffusion, as observed for example in proteins undergoing transient changes of \(D\) and/or \(\alpha\) as induced by, e.g., allosteric changes or ligand binding.
Generates a 2D multi state trajectory with given parameters.
Type
Default
Details
T
int
200
Length of the trajectory
M
list
[[0.95, 0.05], [0.05, 0.95]]
Transition matrix between diffusive states.
Ds
list
[1, 0.1]
Diffusion coefficients of the diffusive states. Must have as many Ds as states defined by M.
alphas
list
[1, 1]
Anomalous exponents of the diffusive states. Must have as many alphas as states defined by M.
L
NoneType
None
Length of the box acting as the environment
deltaT
int
1
Sampling time
return_state_num
bool
False
If True, returns as label the number assigned to the state at each time step.
init_state
NoneType
None
If True, the particle starts in state 0. If not, sample initial state.
Returns
tuple
- pos: position of the particle - alphas_t: anomalous exponent at each step - Ds_t: diffusion coefficient at each step. - label_diff_state: particle’s state (can be either free or directed for alpha ~ 2) at each step. - state (optional): state label at each step.
T =1000; L =100traj, labels = models_phenom._multiple_state_traj(T = T, L = L, alphas = [0.2, 0.7], Ds = [1.5, 2], return_state_num=True)fig, ax = plt.subplots(1, 3, figsize = (9, 3), tight_layout =True)ax[0].plot(traj[:, 0], traj[:, 1], alpha =0.5)plt.setp(ax[0], xlabel ='X', ylabel ='Y')ax[1].plot(traj[:, 0], label ='X')ax[1].plot(traj[:, 1], label ='Y', )plt.setp(ax[1], ylabel ='Position', xlabel ='Time')ax[1].legend()ax[2].plot(labels[:, 0], '.', label =r'$\alpha$')ax[2].plot(labels[:, 1], '.', label =r'$D$' )ax[2].plot(labels[:, 3], '.', label =r'$state \#$', alpha =0.3 )plt.setp(ax[2], ylabel ='Label', xlabel ='Time')ax[2].legend()for b in [0,L]: ax[0].axhline(b, ls ='--', alpha =0.3, c ='k') ax[0].axvline(b, ls ='--', alpha =0.3, c ='k') ax[1].axhline(b, ls ='--', alpha =0.3, c ='k')
Particles diffusing according to a 2-state model of diffusion, with transient changes of \(D\) and/or \(\alpha\) induced by encounters with other particles, observed for example in protein dimerization.
Given an unbinding probablity (Pu), the current labeling of particles (label) and the current state of particle (diff_state, either bound, 1, or unbound, 0), simulate an stochastic binding mechanism.
Type
Details
Pu
float
Unbinding probablity
label
array
Current labeling of the particles (i.e. to which condensate they belong)
Given a binding probability Pb, the current label of particles (label), their current diffusive state (diff_state), the particle size (r), their distances (distance) and the label from which binding is not possible (max_label), simulates a binding mechanism.
Type
Details
Pb
float
Binding probablity.
label
array
Current labeling of the particles (i.e. to which condensate they belong)
diff_state
array
Current state of the particles
r
float
Particle size.
distance
array
Distance between particles
max_label
int
Maximum label from which particles will not be considered for binding
Returns
tuple
New labeling and diffusive state of the particles
Here is a test in which some particles, distributed randomly through a bounded space, first bind and then unbind using the previous defined functions:
# Binding and unbinding probabilitiesPb =0.8; Pu =0.5# Generate the particlesN =200; L =10; r =1; max_n =2; Ds = np.ones(100)pos = np.random.rand(N, 2)*L # Put random labels (label = which condensate you belong). diff_state is zero because all are unbound)label = np.arange(N)#np.random.choice(range(500), N, replace = False)diff_state = np.zeros(N).astype(int)# Define max_label bigger than max of label so everybody bindsmax_label =max(label)+2# Calculate distance between particlesdistance = models_phenom._get_distance(pos)print('# of free particles:')print(f'Before binding: {len(label)}')# First make particle bind:lab, ds = models_phenom._make_condensates(Pb, label, diff_state, r, distance, max_label)print(f'After binding: {np.unique(lab[np.argwhere(ds ==0)], return_counts=True)[0].shape[0]}')# Then we do unbinding:lab, ds = models_phenom._make_escape(Pu, lab, ds)print(f'After unbinding: {np.unique(lab[np.argwhere(ds ==0)], return_counts=True)[0].shape[0]}')
# of free particles:
Before binding: 200
After binding: 4
After unbinding: 106
Generates a dataset of 2D trajectories of particles perfoming stochastic dimerization.
Type
Default
Details
N
int
10
Number of trajectories
T
int
200
Length of the trajectory
L
int
100
Length of the box acting as the environment
r
int
1
Radius of particles.
Pu
float
0.1
Unbinding probability.
Pb
float
0.01
Binding probability.
Ds
array
[[1, 0], [0.1, 0]]
List of means and variances from which to sample the diffusion coefficient of each state. If element size is one, we consider variance = 0.
alphas
array
[[1, 0], [1, 0]]
List of means and variances from which to sample the anomalous exponent of each state. If element size is one, we consider variance = 0.
epsilon_a
int
0
Distance between alpha of diffusive states (see ._sampling_diff_parameters)
stokes
bool
False
If True, applies a Stokes-Einstein like coefficient to calculate the diffusion coefficient of dimerized particles. If False, we use as D resulting from the dimerization the D assigned to the dimerized state of one of the two particles.
return_state_num
bool
False
If True, returns as label the number assigned to the state at each time step.
deltaT
int
1
Sampling time
Returns
tuple
- trajs (array TxNx2): particles’ position - labels (array TxNx2): particles’ labels (see ._multi_state for details on labels)
N =500; L =50; r =1; T =100Pu =0.1# Unbinding probabilityPb =1# Binding probability# Diffusion coefficients of two statesstokes =TrueDs = np.array([[2, 0.01], [1e-5, 0]]) # because stokes = True, we don't care about the second state# Anomalous exponents for two statesalphas = np.array([[1, 0], [1, 0.2]]) trajs, labels = models_phenom().dimerization(N = N, L = L, r = r, T = T, Pu = Pu, # Unbinding probability Pb = Pb, # Binding probability Ds = Ds, # Diffusion coefficients of two states alphas = alphas, # Anomalous exponents for two states, return_state_num =True, stokes =True, epsilon_a=0.2 )
plot_trajs(trajs, L, N, labels = labels, plot_labels =True)
Immobile traps
Particles diffusing according to a space-dependent 2-state model of diffusion, representing proteins being transiently immobilized at specific locations as induced by binding to immobile structures, such as cytoskeleton-induced molecular pinning.
Generates a dataset of 2D trajectories of particles diffusing in an environment with immobilizing traps.
Type
Default
Details
N
int
10
Number of trajectories
T
int
200
Length of the trajectory
L
int
100
Length of the box acting as the environment
r
int
1
Radius of particles.
Pu
float
0.1
Unbinding probability.
Pb
float
0.01
Binding probability.
Ds
list
[1, 0]
Mean and variance from which to sample the diffusion coefficient of the free state. If float, we consider variance = 0
alphas
list
[1, 0]
Mean and variance from which to sample the anomalous exponent of the free state. If float, we consider variance = 0
Nt
int
10
Number of traps
traps_pos
array
None
Positions of the traps. Can be given by array or sampled randomly if None.
deltaT
int
1
Sampling time.
Returns
tuple
- trajs (array TxNx2): particles’ position - labels (array TxNx2): particles’ labels (see ._multi_state for details on labels)
N =50; T =100; L =100# Binding and unbinding probsPb =1; Pu =0.1# D and alphaalpha =1.2D = [1, 0.2]# Traps propertiesNt =100r =1traps_pos = np.random.rand(Nt, 2)*L trajs, labels = models_phenom().immobile_traps(N = N, T = T, L = L, r = r, Pu = Pu, Pb = Pb, Ds = D, alphas = alpha, Nt = Nt, traps_pos = traps_pos )
plot_trajs(trajs, L, N, labels = labels, plot_labels =True, traps_positions=traps_pos)
Confinement
Particles diffusing according to a space-dependent 2-state model of diffusion, observed for example in proteins being transiently confined in regions where diffusion properties might change, e.g., the confinement induced by clathrin-coated pits on the cell membrane. In the limit of a high density of trapping regions, this model reproduces the picket-and-fence model used to describe the effect of the actin cytoskeleton on transmembrane proteins.
Distributes circular compartments over an environment without overlapping. Raises a warning and stops when no more compartments can be inserted.
Type
Details
Nc
float
Number of compartments
r
float
Size of the compartments
L
float
Side length of the squared environment.
Returns
array
Position of the centers of the compartments
fig, ax = plt.subplots(figsize = (5,5))Nc =60; r =10; L =256;comp_center = models_phenom._distribute_circular_compartments(Nc, r, L)for c in comp_center: circle = plt.Circle((c[0], c[1]), r) ax.add_patch(circle)ax.set_xlim(0,L)ax.set_ylim(0,L)
Given the begining and end of a segment crossing the boundary of a circle, calculates the new position considering that boundaries are fully reflective.
Type
Default
Details
circle_center
float
Center of the circle
circle_radius
float
Radius of the circle
beg
tuple
Position (in 2D) of the begining of the segment
end
tuple
Position (in 2D) of the begining of the segment
precision_boundary
float
0.0001
Small area around the real boundary which is also considered as boundary. For numerical stability