From 0daee903a822c1cc515fc7aad5a86366629b4e5e Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Thu, 28 Dec 2023 14:45:36 +0100 Subject: [PATCH] rename `cwbias` to `tumblebias` and only take `microbe` as input --- src/api.jl | 2 +- src/chemotaxis/brown-berg.jl | 2 +- src/chemotaxis/brumley.jl | 2 +- src/chemotaxis/celani.jl | 2 +- src/chemotaxis/xie.jl | 4 ++-- src/microbe_step.jl | 13 ++++--------- test/model-creation.jl | 4 ++-- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/api.jl b/src/api.jl index 42bf784..61d4fd7 100644 --- a/src/api.jl +++ b/src/api.jl @@ -1,6 +1,6 @@ export position, direction, speed, velocity, motilepattern, turnrate, rotational_diffusivity, radius, state, - cwbias, + tumblebias, distance, distancevector Base.position(m::AbstractMicrobe) = m.pos diff --git a/src/chemotaxis/brown-berg.jl b/src/chemotaxis/brown-berg.jl index 04db08c..09f4beb 100644 --- a/src/chemotaxis/brown-berg.jl +++ b/src/chemotaxis/brown-berg.jl @@ -45,7 +45,7 @@ function affect!(microbe::BrownBerg, model) chemotaxis!(microbe, model) end -function cwbias(microbe::BrownBerg, model) +function tumblebias(microbe::BrownBerg) g = microbe.gain S = microbe.state return exp(-g*S) diff --git a/src/chemotaxis/brumley.jl b/src/chemotaxis/brumley.jl index 09310b0..4c7eb51 100644 --- a/src/chemotaxis/brumley.jl +++ b/src/chemotaxis/brumley.jl @@ -55,7 +55,7 @@ function affect!(microbe::Brumley, model) chemotaxis!(microbe, model) end -function cwbias(microbe::Brumley, model) +function tumblebias(microbe::Brumley) Γ = microbe.gain S = microbe.state return (1 + exp(-Γ*S))/2 diff --git a/src/chemotaxis/celani.jl b/src/chemotaxis/celani.jl index 71b6162..a9e4f97 100644 --- a/src/chemotaxis/celani.jl +++ b/src/chemotaxis/celani.jl @@ -53,7 +53,7 @@ function affect!(microbe::Celani, model) chemotaxis!(microbe, model) end -function cwbias(microbe::Celani, model) +function tumblebias(microbe::Celani) β = microbe.gain S = microbe.state return (1 - β*S) diff --git a/src/chemotaxis/xie.jl b/src/chemotaxis/xie.jl index 7e817ea..8d418d0 100644 --- a/src/chemotaxis/xie.jl +++ b/src/chemotaxis/xie.jl @@ -84,7 +84,7 @@ function affect!(microbe::Xie, model) chemotaxis!(microbe, model) end -function cwbias(microbe::Xie, model) +function tumblebias(microbe::Xie) S = state(microbe) if state(motilepattern(microbe)) == Forward β = microbe.gain_forward @@ -94,7 +94,7 @@ function cwbias(microbe::Xie, model) return (1 + β*S) end -function turnrate(microbe::Xie, model) +function turnrate(microbe::Xie) if state(motilepattern(microbe)) == Forward return microbe.turn_rate_forward else diff --git a/src/microbe_step.jl b/src/microbe_step.jl index 9849586..728e0c6 100644 --- a/src/microbe_step.jl +++ b/src/microbe_step.jl @@ -18,7 +18,7 @@ function microbe_step!(microbe::AbstractMicrobe, model) # update microbe state affect!(microbe, model) # evaluate instantaneous turn rate - ω = turnrate(microbe, model) + ω = turnrate(microbe) * tumblebias(microbe) if rand(abmrng(model)) < ω * dt # if true reorient microbe turn!(microbe, model) end @@ -39,20 +39,15 @@ function microbe_pathfinder_step!(microbe::AbstractMicrobe, model) # update microbe state affect!(microbe, model) # evaluate instantaneous turn rate - ω = turnrate(microbe, model) + ω = turnrate(microbe) * tumblebias(microbe) if rand(abmrng(model)) < ω * dt # if true reorient microbe turn!(microbe, model) end nothing end -""" - turnrate(microbe, model) -Evaluate instantaneous turn rate of `microbe`. -""" -turnrate(microbe::AbstractMicrobe, model) = turnrate(microbe) * cwbias(microbe, model) -# no CW bias for generic non-chemotactic microbe -cwbias(microbe::AbstractMicrobe, model) = 1.0 +# no bias for generic non-chemotactic microbe +tumblebias(microbe::AbstractMicrobe) = 1.0 """ affect!(microbe, model) Can be used to arbitrarily update `microbe` state. diff --git a/test/model-creation.jl b/test/model-creation.jl index 00c6a58..2afaa42 100644 --- a/test/model-creation.jl +++ b/test/model-creation.jl @@ -71,7 +71,7 @@ using LinearAlgebra: norm fieldnames(T) ) - φ(microbe, model) = turnrate(microbe) * cwbias(microbe, model) + φ(microbe, model) = turnrate(microbe) * tumblebias(microbe) if T == BrownBerg @test φ(m, model) == m.turn_rate * exp(-m.gain*m.state) elseif T == Brumley @@ -96,7 +96,7 @@ using LinearAlgebra: norm S = m.state ω = m.turn_rate_forward β = m.gain_forward - @test turnrate(m, model) == ω * (1 + β*S) + @test turnrate(m) == ω * (1 + β*S) end end end