From a4f5a2e6b8c43f705e19f3e9de02b6906a58df5c Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Sat, 28 Sep 2024 21:09:04 +0200 Subject: [PATCH] update constructors in examples --- examples/Chemotaxis/1_linear_ramp.jl | 2 +- examples/Chemotaxis/2_celani_gauss2D.jl | 2 +- examples/Chemotaxis/3_xie_response-function.jl | 4 ++-- examples/Chemotaxis/4_response_functions.jl | 6 +++--- examples/Chemotaxis/5_drift_exponential.jl | 2 +- examples/RandomWalks/1_randomwalk1D.jl | 9 +++++---- examples/RandomWalks/2_randomwalk2D_motilepatterns.jl | 10 +++++----- examples/RandomWalks/3_randomwalk3D.jl | 6 +++--- examples/Validation/msd_runtumble.jl | 2 +- examples/Validation/velocity_autocorrelations.jl | 4 ++-- 10 files changed, 24 insertions(+), 23 deletions(-) diff --git a/examples/Chemotaxis/1_linear_ramp.jl b/examples/Chemotaxis/1_linear_ramp.jl index 45cf040..9110f13 100644 --- a/examples/Chemotaxis/1_linear_ramp.jl +++ b/examples/Chemotaxis/1_linear_ramp.jl @@ -84,7 +84,7 @@ for i in 1:n p0 = spacesize(model) ./ 2 delta = rand(abmrng(model), SVector{2}) .* 10 pos = p0 .+ delta # random scatter around center - motility = RunTumble(0.67, [30.0], Isotropic(2), 0.1) + motility = RunTumble([30.0], 0.67, Isotropic(2); tumble_duration=0.1) add_agent!(pos, model; motility) end model diff --git a/examples/Chemotaxis/2_celani_gauss2D.jl b/examples/Chemotaxis/2_celani_gauss2D.jl index a6d4e83..77348bc 100644 --- a/examples/Chemotaxis/2_celani_gauss2D.jl +++ b/examples/Chemotaxis/2_celani_gauss2D.jl @@ -32,7 +32,7 @@ properties = Dict( ) model = StandardABM(Celani{2,2}, space, timestep; properties) -motility = RunTumble(0.67, [30.0], Isotropic(2), 0.1) +motility = RunTumble([30.0], 0.67, Isotropic(2); tumble_duration=0.1) for _ in 1:300 add_agent!(model; motility, diff --git a/examples/Chemotaxis/3_xie_response-function.jl b/examples/Chemotaxis/3_xie_response-function.jl index 7c8dc90..f366673 100644 --- a/examples/Chemotaxis/3_xie_response-function.jl +++ b/examples/Chemotaxis/3_xie_response-function.jl @@ -68,8 +68,8 @@ To keep the microbes in these motile states for the entire experiment duration, we suppress their tumbles, and (just for total consistency with experiments) we also set their speed to 0. =# -add_agent!(model; motility=RunReverseFlick(Inf, [0], 0.0, [0])) -add_agent!(model; motility=RunReverseFlick(0.0, [0], Inf, [0])) +add_agent!(model; motility=RunReverseFlick([0], Inf, [0], 0.0)) +add_agent!(model; motility=RunReverseFlick([0], Inf, [0], 0.0)) model[2].motility.current_state = 3 # manually set to backward run state #= diff --git a/examples/Chemotaxis/4_response_functions.jl b/examples/Chemotaxis/4_response_functions.jl index 367f5b6..2f5b626 100644 --- a/examples/Chemotaxis/4_response_functions.jl +++ b/examples/Chemotaxis/4_response_functions.jl @@ -57,11 +57,11 @@ properties = Dict( model = StandardABM(Union{BrownBerg{3},Celani{3}}, space, dt; properties) -add_agent!(BrownBerg{3}, model; motility=RunTumble(1.0, [0], Isotropic(3)), +add_agent!(BrownBerg{3}, model; motility=RunTumble([0], 1.0, Isotropic(3)), memory=1, ) -add_agent!(Celani{3}, model; motility=RunTumble(1.0, [0], Isotropic(3)), gain=4) -add_agent!(Celani{3}, model; motility=RunTumble(1.0, [0], Isotropic(3)), gain=4, +add_agent!(Celani{3}, model; motility=RunTumble([0], 1.0, Isotropic(3)), gain=4) +add_agent!(Celani{3}, model; motility=RunTumble([0], 1.0, Isotropic(3)), gain=4, chemotactic_precision=50.0 ) diff --git a/examples/Chemotaxis/5_drift_exponential.jl b/examples/Chemotaxis/5_drift_exponential.jl index be56682..14412d9 100644 --- a/examples/Chemotaxis/5_drift_exponential.jl +++ b/examples/Chemotaxis/5_drift_exponential.jl @@ -76,7 +76,7 @@ n = 200 for Π in Πs for i in 1:n pos = SVector{3}(0.0, rand()*Ly, rand()*Lz) - motility = RunReverseFlick(0.45, [46.5], 0.45, [46.5]) + motility = RunReverseFlick([46.5], 0.45, [46.5], 0.45) add_agent!(pos, model; chemotactic_precision=Π, motility) end end diff --git a/examples/RandomWalks/1_randomwalk1D.jl b/examples/RandomWalks/1_randomwalk1D.jl index b5e91a2..ccd7d91 100644 --- a/examples/RandomWalks/1_randomwalk1D.jl +++ b/examples/RandomWalks/1_randomwalk1D.jl @@ -34,22 +34,23 @@ from position `(0,)`. Moreover, it's always required to specify the motility of the microbes via the keyword argument `motility`. -For example, `RunTumble` needs as inputs the average duration of runs, -the distribution of run speeds and the distribution of reorientation angles. +For example, `RunTumble` needs as inputs the distribution of run speed, +the average run duration and the distribution of reorientation angles. The latter is irrelevant in 1D, since the bacterium can only revert its direction along the line, but we still have to pass it. We can just use an empty vector. Passing a one-element vector `[U]` as the speed distribution means that all runs will have the same velocity `U`. We could have also specified the average duration of tumbles -(equal to reversals in 1 dimension) via an optional 4th argument (try it! e.g. 0.5); +(equal to reversals in 1 dimension) via a keyword argument +`tumble_duration`. when unspecified, the tumbles are taken to be instantaneous. =# n = 10 # number of microbes to add τ_run = 1.0 # average run duration in s U = 30.0 # swimming speed in μm/s -motility = RunTumble(τ_run, [U], [], 0.5) +motility = RunTumble([U], τ_run, []; tumble_duration=0.2) foreach(_ -> add_agent!((0,), model; motility), 1:n) #= diff --git a/examples/RandomWalks/2_randomwalk2D_motilepatterns.jl b/examples/RandomWalks/2_randomwalk2D_motilepatterns.jl index 62e542d..c96d71a 100644 --- a/examples/RandomWalks/2_randomwalk2D_motilepatterns.jl +++ b/examples/RandomWalks/2_randomwalk2D_motilepatterns.jl @@ -21,11 +21,11 @@ The motile pattern can be customized through the `motility` keyword. The `RunTumble` motility consists of straight runs interspersed with reorientations (tumbles). -With the first argument, we set the average duration of tumbles, 1 s in this case. -We can then define the speed to follow a a `Normal` distribution +With the first argument, we set the speed to follow a a `Normal` distribution (from Distributions.jl) with mean 30 μm/s and standard deviation 6 μm/s. This means that, after every tumble, the microbe will change its speed following this distribution. +With the second argument, we set the average duration of tumbles, 1 s in this case. We should then specify the distribution of angular reorientations. For convenience, MicrobeAgents implements an `Isotropic` function which produces the appropriate distribution to have isotropic reorientations @@ -34,7 +34,7 @@ In this case, using `Isotropic(2)` produces a `Uniform` distribution of angles between -π and +π. Finally, we can set tumbles to also have a finite duration, let's say 0.1 s. =# -add_agent!(model; motility=RunTumble(1.0, Normal(30,6), Isotropic(2), 0.1)) +add_agent!(model; motility=RunTumble(Normal(30,6), 1.0, Isotropic(2); tumble_duration=0.1)) #= The `RunReverse` motility consists of alternating straight runs and 180-degree reversals. @@ -48,7 +48,7 @@ Further, we set the `rotational_diffusivity` of the microbe to 0.2 rad²/s; in a rotational diffusion, the run reverse motility is pathologically incapable of exploring space efficiently. =# -add_agent!(model; motility=RunReverse(1.0, [30.0], 0.7, [20.0]), rotational_diffusivity=0.2) +add_agent!(model; motility=RunReverse([30.0], 1.0, [20.0], 0.7), rotational_diffusivity=0.2) #= The `RunReverseFlick` motility consists of a straight run, a 180-degree reversal, then another @@ -58,7 +58,7 @@ a `RunReverse` where the reorientation after the "backward" run is 90 instead of Again, we will set only run durations and speeds. We also set the rotational diffusivity to 0.1 rad²/s. =# -add_agent!(model; motility=RunReverseFlick(2.0, [25.0], 0.5, [25.0]), rotational_diffusivity=0.1) +add_agent!(model; motility=RunReverseFlick([25.0], 2.0, [25.0], 0.5), rotational_diffusivity=0.1) #= Now we can run (collecting the microbe positions at each timestep), unfold the trajectories, diff --git a/examples/RandomWalks/3_randomwalk3D.jl b/examples/RandomWalks/3_randomwalk3D.jl index 960d416..a3b204c 100644 --- a/examples/RandomWalks/3_randomwalk3D.jl +++ b/examples/RandomWalks/3_randomwalk3D.jl @@ -13,9 +13,9 @@ space = ContinuousSpace((L,L,L)) dt = 0.1 model = StandardABM(Microbe{3}, space, dt) -add_agent!(model; motility=RunReverse(1.0, [55], 1.0, [55]), rotational_diffusivity=0.2) -add_agent!(model; motility=RunTumble(2.0, Normal(30,6), Isotropic(3))) -add_agent!(model; motility=RunReverseFlick(1.0, [30], 1.0, [6]), rotational_diffusivity=0.1) +add_agent!(model; motility=RunReverse([55], 1.0, [55], 1.0), rotational_diffusivity=0.2) +add_agent!(model; motility=RunTumble(Normal(30,6), 2.0, Isotropic(3))) +add_agent!(model; motility=RunReverseFlick([30], 1.0, [6], 1.0), rotational_diffusivity=0.1) nsteps = 600 adata = [position] diff --git a/examples/Validation/msd_runtumble.jl b/examples/Validation/msd_runtumble.jl index 3f51adf..9ced030 100644 --- a/examples/Validation/msd_runtumble.jl +++ b/examples/Validation/msd_runtumble.jl @@ -36,7 +36,7 @@ U = 30.0 # μm/s models = map(_ -> StandardABM(Microbe{3}, space, dt; container=Vector), θs) nmicrobes = 100 for (i,θ) in enumerate(θs) - motility = RunTumble(τ, [U], [θ,-θ]) + motility = RunTumble([U], τ, [θ,-θ]) foreach(_ -> add_agent!(models[i]; motility), 1:nmicrobes) end diff --git a/examples/Validation/velocity_autocorrelations.jl b/examples/Validation/velocity_autocorrelations.jl index b3f2e01..4b4d4f7 100644 --- a/examples/Validation/velocity_autocorrelations.jl +++ b/examples/Validation/velocity_autocorrelations.jl @@ -32,9 +32,9 @@ model = StandardABM(Microbe{3}, space, Δt; container=Vector) n = 200 for Mot in (RunTumble, RunReverse, RunReverseFlick), i in 1:n if Mot == RunTumble - motility = RunTumble(τ_run, [U], Isotropic(3), 0.0) + motility = RunTumble([U], τ_run, Isotropic(3)) else - motility = Mot(τ_run, [U], τ_run, [U]) + motility = Mot([U], τ_run, [U], τ_run) end add_agent!(model; motility) end