Buffer

Buffer preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Mike Stieff (Author)

Tags

chemical reactions 

Tagged by Reuven M. Lerner about 11 years ago

chemistry and physics 

Tagged by Reuven M. Lerner about 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 586 times • Downloaded 93 times • Run 0 times
Download the 'Buffer' 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

Click to Run Model

breed [waters water]             ;; water molecules
breed [hydroniums hydronium]     ;; hydronium ions (green)
breed [hydroxides hydroxide]     ;; base molecules (red)
breed [acids acid]               ;; parent acid molecules (yellow)
breed [conj-bases conj-base]     ;; conjugate base molecules of parent acid (orange)

globals [
  pH
]

to setup
  clear-all
  set-default-shape waters "molecule2"
  set-default-shape hydroniums "molecule3"
  set-default-shape hydroxides "molecule1"
  set-default-shape acids "molecule2"
  set-default-shape conj-bases "molecule1"
  create-acids starting-acid  ;; creates variable amount of acid
    [ set color yellow ]
  ask acids [
    ;; initializes amount of dissociated acid
    if random-float 100 > 98
      [ dissociate ] ]
  if see-starting-water?
    [ create-waters 100    ;; creates constant volume of water
        [ set color blue ] ]
  create-conj-bases starting-conj-base  ;; creates variable amount of conjugate base
    [ set color orange ]
  ask turtles                   ;; randomize position and heading of turtles
    [ setxy random-xcor random-ycor ]
  calculate-pH
  reset-ticks
end 

;; dissociate an acid molecule into hydronium and conj-base
;; this should only be called by turtles that are acids

to dissociate  ;; turtle procedure
  hatch-hydroniums 1 [ set color green ]
  set breed conj-bases
  set color orange
end 

to go
  ask hydroxides [ react-hydroxide ]
  ask hydroniums [ react-hydronium ]
  ;; move turtles randomly around the world
  ask turtles
    [ fd 1
      rt random 10
      lt random 10 ]
  tick
  calculate-pH
end 

to react-hydroxide  ;; hydroxide procedure
  let partner one-of hydroniums-here
  ifelse partner != nobody
    [ react partner ]
    [ set partner one-of acids-here
      if partner != nobody
        [ react partner ] ]
end 

to react-hydronium  ;; hydronium procedure
  let partner one-of hydroxides-here
  ifelse partner != nobody
    [ react partner ]
    [ set partner one-of conj-bases-here
      if partner != nobody
        [ react partner ] ]
end 

to react [ partner ]  ;; turtle procedure
  ;; all hydroxide molecules will instantly react with
  ;; hydronium molecules and form water
  ifelse ([breed] of partner) = hydroniums or ([breed] of partner) = hydroxides
    [ set breed waters
      set color blue
      ask partner
        [ set breed waters
          set color blue ] ]
    [ ;; hydroxide molecules have a high probability of
      ;; reacting with acid molecules
      ifelse ([breed] of partner) = acids
        [ if random-float 100 > 80
          [ set breed waters
            set color blue
            ask partner
              [ set breed conj-bases
                set color orange ] ] ]
        ;; hydronium ions will react with conjugate base to form acid
        [ if ([breed] of partner) = conj-bases
          [ if random-float 100 > 80
            [ set breed waters
              set color blue
              ask partner
                [ set breed acids
                  set color yellow ] ] ] ] ]
end 

;; calculates the pH from the amount of the various ions in solution;
;; note that for simplicity the calculations don't take the true molar
;; concentration of water into account; instead we simply divide by
;; a factor of 1000 to bring the numbers into a reasonable range

to calculate-pH
  let volume count turtles
  let concH (count hydroniums / volume)
  let concOH (count hydroxides / volume)
  ifelse (concH = concOH)
    [ set pH 7 ]
    [ ifelse (concH > concOH)
      [ set pH (- log (concH / 1000) 10) ]
      [ let pOH (- log (concOH / 1000) 10)
        set pH 14 - pOH ] ]
end 

;; add more base to the system

to add-base
  create-hydroxides added-base
    [ set color red
      fd 1 ]
end 

;; add more acid to the system

to add-acid
  create-hydroniums added-acid
    [ set color green
      fd 1 ]
end 


; Copyright 2001 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky almost 12 years ago Updated version tag Download this version
Uri Wilensky almost 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Buffer Download this version

Attached files

File Type Description Last updated
Buffer.png preview Preview for 'Buffer' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.