Skip to content

Commit

Permalink
update constructors in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mastrof committed Sep 28, 2024
1 parent 0bf5635 commit a4f5a2e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/Chemotaxis/1_linear_ramp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/Chemotaxis/2_celani_gauss2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/Chemotaxis/3_xie_response-function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

#=
Expand Down
6 changes: 3 additions & 3 deletions examples/Chemotaxis/4_response_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion examples/Chemotaxis/5_drift_exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions examples/RandomWalks/1_randomwalk1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#=
Expand Down
10 changes: 5 additions & 5 deletions examples/RandomWalks/2_randomwalk2D_motilepatterns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples/RandomWalks/3_randomwalk3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/Validation/msd_runtumble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/Validation/velocity_autocorrelations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4f5a2e

Please sign in to comment.