Coder Social home page Coder Social logo

diffeqbiological.jl's Introduction

DiffEqBiological.jl

Join the chat at https://gitter.im/JuliaDiffEq/Lobby Build Status Build status

Here we give a brief introduction to using the DiffEqBiological package. Full documentation is in the DifferentialEquations.jl Chemical Reaction Models documentation.

The Reaction DSL

The @reaction_network DSL allows for the definition of reaction networks using a simple format. Its input is a set of chemical reactions, from which it generates a reaction network object which can be used as input to ODEProblem, SteadyStateProblem, SDEProblem and JumpProblem constructors.

The basic syntax is

rn = @reaction_network rType begin
  2.0, X + Y --> XY               
  1.0, XY --> Z            
end

where each line corresponds to a chemical reaction. The (optional) input rType designates the type of this instance (all instances will inherit from the abstract type AbstractReactionNetwork).

The DSL has many features:

  • It supports many different arrow types, corresponding to different directions of reactions and different rate laws:
    rn = @reaction_network begin
      1.0, X + Y --> XY               
      1.0, X + Y  XY      
      1.0, XY  X + Y      
      2.0, X + Y  XY               
    end
  • It allows multiple reactions to be defined simultaneously on one line. The following two networks are equivalent:
    rn1 = @reaction_network begin
      (1.0,2.0), (S1,S2)  P             
    end
    rn2 = @reaction_network begin
      1.0, S1  P     
      2.0, S2  P
    end
  • It allows the use of symbols to represent reaction rate parameters, with their numeric values specified during problem construction. i.e., the previous example could be given by
    rn2 = @reaction_network begin
      k1, S1  P     
      k2, S2  P
    end k1 k2 
    with k1 and k2 corresponding to the reaction rates.
  • Rate law functions can be pre-defined and used within the DSL:
    @reaction_func myHill(x) = 2.0*x^3/(x^3+1.5^3)
    rn = @reaction_network begin
      myHill(X), ∅  X
    end
  • Pre-made rate laws for Hill and Michaelis-Menten reactions are provided:
    rn1 = @reaction_network begin
      hill(X,v,K,n), ∅  X
      mm(X,v,K), ∅  X
    end v K n
  • Simple rate law functions of the species populations can be used within the DSL:
    rn = @reaction_network begin
      2.0*X^2, 0  X + Y
      gamma(Y)/5, X pi*X/Y, Y end
  • It is possible to access expressions corresponding to the functions determining the deterministic and stochastic terms within resulting ODE, SDE or jump models using
      f_expr = rn.f_func
      g_expr = rn.g_func
      affects = rn.jump_affect_expr
      rates = rn.jump_rate_expr
    These can be used to generate LaTeX code corresponding to the system using packages such as Latexify.

Simulating ODE, Steady-State, SDE and Jump Problems

Once a reaction network has been created it can be passed as input to either one of the ODEProblem, SteadyStateProblem, SDEProblem or JumpProblem constructors.

  probODE = ODEProblem(rn, args...; kwargs...)      
  probSS = SteadyStateProblem(rn, args...; kwargs...)
  probSDE = SDEProblem(rn, args...; kwargs...)
  probJump = JumpProblem(prob, Direct(), rn)

The output problems may then be used as input to the solvers of DifferentialEquations.jl. Note, the noise used by the SDEProblem will correspond to the Chemical Langevin Equations.

As an example, consider models for a simple birth-death process:

rs = @reaction_network begin
  c1, X --> 2X
  c2, X --> 0
  c3, 0 --> X
end c1 c2 c3
params = (1.0,2.0,50.)
tspan = (0.,4.)
u0 = [5.]

# solve ODEs
oprob = ODEProblem(rs, u0, tspan, params)
osol  = solve(oprob, Tsit5())

# solve for Steady-States
ssprob = SteadyStateProblem(rs, u0, params)
sssol  = solve(ssprob, SSRootfind())

# solve Chemical Langevin SDEs
sprob = SDEProblem(rs, u0, tspan, params)
ssol  = solve(sprob, EM(), dt=.01)

# solve JumpProblem
u0 = [5]
dprob = DiscreteProblem(u0, tspan, params)
jprob = JumpProblem(dprob, Direct(), rs)
jsol = solve(jprob, SSAStepper())

diffeqbiological.jl's People

Contributors

chrisrackauckas avatar torkele avatar isaacsas avatar alanderos91 avatar korsbo avatar spcornelius avatar weilandtd avatar scottpjones avatar femtocleaner[bot] avatar staticfloat avatar

Watchers

James Cloos avatar Hieu Tran avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.