Adaptive Immunity

Adaptive Immunity preview image

1 collaborator

170905_jeff_k_headshot_office Jeff Klemens (Author)

Tags

antibodies 

Tagged by Jeff Klemens over 6 years ago

b cells 

Tagged by Jeff Klemens over 6 years ago

immune system 

Tagged by Jeff Klemens over 6 years ago

measles 

Tagged by Jeff Klemens over 6 years ago

vaccine 

Tagged by Jeff Klemens over 6 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.1 • Viewed 815 times • Downloaded 28 times • Run 0 times
Download the 'Adaptive Immunity' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [death-rate reg-repro antibody-movement infected active-color]
     ; death-rate = chance of the turtle dying
     ; antibody-movement = how many spaces the antibody has moved
     ; reg-repro = the chance a lymphocyte will reproduce when it is not active or a memory cell
     ; infected = records whether antigens have been inputted
     ; active-color = the color of the lymphocyte that responds to the antigen
breed [lymphocytes lymphocyte]  ; creating a set of lymphocytes
breed [antigens antigen]        ; creating a set of antigens
breed [antibodies antibody]     ; creating a set of antibodies
breed [measles measle]          ; creating special measles antigen
breed [vaccines vaccine]        ; creating special vaccine antigen
lymphocytes-own [active active-time reproduction-rate memory]
     ; active = whether the cell is active ( 0 is no ; 1 is yes )
     ; active-time = how much time left the cell has to be active
     ; reproduction-rate = how fast the cell reproduces
     ; memory = records whether the lymphocyte is a memory cell (0 is no ; 1 is yes)
antibodies-own [energy]
     ; energy = how many ticks the antibody has left to live
measles-own [measles-duration]
vaccines-own [vaccine-duration]
     ; vaccine-duration = for how many ticks will the vaccines persist in the system

to setup
  clear-all
  clear-output
  ask patches [set pcolor white]
  set infected 0      ; at setup, the system is not infected with any antigens
  set death-rate 15   ; values fit to give best response, no inherent meaning to these rates
  set reg-repro 15
  set active-color one-of base-colors        ;set active color to a random lymphocyte color
  set-default-shape lymphocytes "circle"     ; lymphocytes are circles
  set-default-shape antigens "monster"       ; antigens are monsters
  set-default-shape measles "monster"        ; measles are monsters, big red ones
  set-default-shape vaccines "monster"       ; vaccines are greyed-out monsters
  set-default-shape antibodies "Y"           ; antibodies are Y-shaped
  create-lymphocytes 250  ; create the lymphocytes, then initialize their variables
  [
    set color one-of base-colors
    set active 0 ; all lymphocytes are initially inactive
    set active-time -1
    set reproduction-rate reg-repro ; all lymphocytes are initially inactive, so reproduce at regular rate
    set size 1.5  ; easier to see
    set label-color blue - 2
    setxy random-xcor random-ycor
    set memory 0
  ]
  reset-ticks
end 

to go
  if not any? turtles [ stop ]
  replace-extinct
  ask antigens[
    move
    antigen-reproduce
  ]
  ask lymphocytes [
    bind
    activated
    move
    reproduce
    lymph-death
  ]
  ask antibodies [
    antibody-move
    set energy energy - 1
    antibody-death
  ]
  measles-death
  vaccine-death
  antigen-extinct
  tick
end 

to replace-extinct           ; this is a "rescue effect", if any lymphocyte types (colors) go extinct we add one more to the population
  let counter 5
  while [counter < 140]      ; check all the colors
  [
    if count lymphocytes with [color = counter] = 0
  [
      create-lymphocytes 1  ; create the replacement lymphocyte, then initialize its variables
      [
        set color counter
        set active-time -1
        set active 0
        set reproduction-rate reg-repro
        set size 1.5
        set label-color blue - 2
        setxy random-xcor random-ycor
        ask n-of 1 lymphocytes [ die ]   ; kill a random lympohcyte to make up for the replacement
      ]
  ]
  set counter counter + 10
]
end 

to move  ; antigen and lymphocyte procedure
  rt random 50
  lt random 50
  fd 1
end 

to antigen-reproduce
   if random 100 < 20 and color != grey   ;; and statement keeps grey "vaccine antigens" from reproducing
    [
      hatch 1 [ rt random 360 fd 1]
    ]
end 

to bind                                          ; active-color lymphocytes are activated by the antigen
 if color = active-color[
   if (one-of antigens in-radius 1 != nobody) or (one-of vaccines in-radius 1 != nobody)
   [
     set active 1
     set active-time 10   ;; length of typical cell lifespan if death rate is 10
   ]
  ]
end 

to activated
  if active-time = 0                                 ; kills activated after time is up
    [
       die
      ]

  if active = 1
  [
    set reproduction-rate (reproduction-multiplier-when-active * reg-repro) ; start rapid reproduction
    set size 2               ; increase size
    set shape "bold-circle"  ; outline circle
    hatch-antibodies 2       ; create antibodies
    [
      set color black
      rt random-float 360 fd 1  ; randomly pick a direction and move forward
      if antibody-effectiveness = "high"
      [
          set energy 8
      ]

      if antibody-effectiveness = "low"
      [
        set energy 4 ; for antibodies, energy tracks how many ticks the antibodies have left to live
      ]
    ]
   set active-time active-time - 1    ;; counts back down to inactivity
  ]
end 

to reproduce  ; determine if the lymphocyte reproduces

 if random 100 < reproduction-rate
  [ ifelse memory = 1
    [
      hatch 1 [
        set shape "M-circle"
        rt random-float 360 fd 1]
    ]
    [
       ifelse active = 1 ; if active, produce both a memory cell and an active cell ; else, produce regular cell
        [
                  hatch-lymphocytes 1 [ set shape "M-circle"
                  set color active-color
                  set active 0
                  set reproduction-rate 2
                  set size 2.5  ; easier to see
                  set label-color blue - 2
                  set memory 1
                  rt random-float 360 fd 1 ]

                  hatch 1 [ rt random-float 360 fd 1]
        ]
        [
            ifelse count lymphocytes < 235
               [
                        hatch 2 [ rt random-float 360 fd 1]
               ]
                [
                        hatch 1 [ rt random-float 360 fd 1]
                 ]
        ]
    ]
  ]
end 

to lymph-death  ; determine if the lymphocyte dies
  if memory = 0 and random 100 < death-rate
      [
        die
      ]
  if memory = 1 and random 100 < 2
  [
    die
  ]
end 

to antibody-move  ; the speed (distance moved each time step) ends up being a measure of potency of each activated cell
  set antibody-movement 0
  if antibody-effectiveness = "high"
  [
     while [antibody-movement < 10]
     [fd 1
     kill-antigen  ; check to see if it is on the same spot as an antigen and if so, kill it
     set antibody-movement antibody-movement + 1
     ]
  ]

  if antibody-effectiveness = "low"
  [
     while [antibody-movement < 5]
     [fd 1
     kill-antigen
     set antibody-movement antibody-movement + 1
     ]
  ]
end 

to antibody-death
  if energy < 1
  [ die ]
end 

to kill-antigen
  let prey one-of antigens-here
  if prey != nobody
  [ask prey[die]]
end 

to measles-death
  ask measles
  [
    if measles-duration < 1
     [  die  ]
     set measles-duration measles-duration - 1
  ]
end 

to vaccine-death
  ask vaccines
  [
    move
    if vaccine-duration < 1 [die]
    set vaccine-duration vaccine-duration - 1
  ]
end 

to antigen-extinct
  if (count antigens = 0) and (infected = 1)
  [
     output-type "antigen clearance time "  output-print ticks
    set infected 0
  ]
end 

to insert-antigens                               ; create an infection every button push
  output-type "antigen infection time "  output-print ticks
  set infected 1 ; noting that antigens have been put into the cell
    create-antigens antigen-load
    [
     set color black
     set size 2  ; easier to see
     set label-color blue - 2
     setxy random-xcor random-ycor
    ]
end 

to infect-measles
  output-type "measles infection time "  output-print ticks
   create-measles 1
    [
     set color red
     set size 50
     set label-color blue - 2
     setxy 0 0
     set measles-duration 5
    ]

  ask lymphocytes
      [
        if random 100 < 95
        [ die ]
      ]
end 

to insert-vaccine
  output-type "vaccine injection time "  output-print ticks
  create-vaccines vaccine-load
    [
     set color grey
     set size 2  ; easier to see
     set label-color blue - 2
     setxy random-xcor random-ycor
     set vaccine-duration 10
    ]
end 

There is only one version of this model, created over 6 years ago by Jeff Klemens.

Attached files

File Type Description Last updated
Adaptive Immunity.png preview Preview for 'Adaptive Immunity' over 6 years ago, by Jeff Klemens Download
LESSON_PLAN 13 July 2018.pdf pdf Lesson plan for using the model in a classroom setting over 6 years ago, by Jeff Klemens Download

This model does not have any ancestors.

This model does not have any descendants.