Molecular Self-Organization

No preview image

1 collaborator

Default-person Paul Sherratt (Author)

Tags

(This model has yet to be categorized with any tags)
Model group EECS-372 Spring 2009 | Visible to everyone | Changeable by the author
Model was written in NetLogo 4.1beta1 • Viewed 487 times • Downloaded 49 times • Run 12 times
Download the 'Molecular Self-Organization' modelDownload this modelEmbed this model

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


WHAT IS IT?

This example demonstrates how to create a square grid for turtles to walk around on using links. When turtles come into contact they merge and become one. Different colors represent different charges (-/+/netural : red/blue/black). The total energy is calculated at each step according to nearest neighbor interactions.

Comments and Questions

First Steps.

Ok - so I have a square grid for turtles (walkers) to explore. The next step was to see if I could get them to merge. I can but the method I use has problems now which I can fix using a sightly different approach. This will be online soon.

Posted over 15 years ago

Click to Run Model

globals [
  colors           ;; colors we are using
  energy           ;; total energy of the system
]
breed [nodes node]
breed [walkers walker]
walkers-own [location leader agg_id]  ;; holds a node

; Set up routine: creates a grid of patches. Puts nodes on each patch, links them and then puts 
; a number of walkers on the nodes. 

to setup
  clear-all
  set-default-shape nodes "square"
  ask patches
  [ sprout-nodes 1
    [ set color white ;; white
      set size 1.2
     ] 
   ]
  ;; connect the nodes to make a lattice
  ask nodes
  [ 
      create-links-with nodes-on patches at-points [[0 1] [1 0] ]    
  ]  
  ask links [ hide-link ]
 
 
  ;; put some "walker" turtles on the lattice
  set-default-shape walkers "square"
  set colors [red blue black] ; different colors represent -/+/neutral charges.
  let countr 0
  create-walkers number 
  [
    set color item random 3 colors
    set location one-of nodes
    set leader self
    set agg_id countr
    move-to location
    set countr countr + 1
  ]
end 

;Main loop.

to go
  
choose_direction
    
ask walkers 
[
    let cands_on_neighbs walkers-on neighbors4
    let candidates cands_on_neighbs with [leader != [leader] of myself]  
            
    if any? candidates[
     create-links-with candidates [tie]
     ask candidates [merge]
     ] 
]
 
find_energy 
update-plot 
tick
end 

;Takes test steps in each of the four directions.

to choose_direction
 
ask walkers with [leader = self] 
      [
        find_energy
        let energy_zero energy
        let left_right 0 let up_down 0
        set-location one-of [link-neighbors at-points [[0 -1] ] ] of location
        find_energy
        if energy < energy_zero [set up_down -1 set left_right 0 set energy_zero energy] 
        
        set-location one-of [link-neighbors at-points [[0 1] ] ] of location
        set-location one-of [link-neighbors at-points [[0 1] ] ] of location
        find_energy
        if energy < energy_zero [set up_down 1 set left_right 0 set energy_zero energy] 
        
        set-location one-of [link-neighbors at-points [[0 -1] ] ] of location
        set-location one-of [link-neighbors at-points [[1 0] ] ] of location
        find_energy
        if energy < energy_zero [set up_down 0 set left_right 1 set energy_zero energy]
                
        set-location one-of [link-neighbors at-points [[-1 0] ] ] of location
        set-location one-of [link-neighbors at-points [[-1 0] ] ] of location
        find_energy
        if energy < energy_zero [set up_down 0 set left_right -1 set energy_zero energy]
        set-location one-of [link-neighbors at-points [[1 0] ] ] of location
        
;        show up_down
;        show left_right
        
        if left_right = 0 and up_down = 1 [
        set-location one-of [link-neighbors at-points [[0 1] ] ] of location
        rt (random 4) * 90 
        ]
        if left_right = 1 and up_down = 0 [
        set-location one-of [link-neighbors at-points [[1 0] ] ] of location
        rt (random 4) * 90 
        ]
        if left_right = -1 and up_down = 0 [
        set-location one-of [link-neighbors at-points [[-1 0] ] ] of location
        rt (random 4) * 90 
        ]
        if left_right = 0 and up_down = -1 [
        set-location one-of [link-neighbors at-points [[0 -1] ] ] of location
        rt (random 4) * 90 
        ]
        if left_right = 0 and up_down = 0 [
        set-location one-of [link-neighbors] of location
        rt (random 4) * 90 
        ]
        
;        rt (random 4) * 90 
      ]      
end 

;Finds the total energy (Note the /2 is to avoid double counting).

to find_energy
  set energy  0
  ask walkers [
    let cands_on_neighbs walkers-on neighbors4
    if [color] of self  = blue [                     ;show "blue"
      if any? cands_on_neighbs with [color = blue] [set energy energy + (9 / 2)]
      if any? cands_on_neighbs with [color = red] [set energy energy - (11 / 2)]
      if any? cands_on_neighbs with [color = black] [set energy energy - (1 / 2)]
      ]
    
    if [color] of self  = red [ 
      if any? cands_on_neighbs with [color = blue] [set energy energy - (11 / 2)]
      if any? cands_on_neighbs with [color = red] [set energy energy + (9 / 2)]
      if any? cands_on_neighbs with [color = black] [set energy energy - (1 / 2)]
      ]
    
    if [color] of self  = black [ 
      if any? cands_on_neighbs with [color = blue] [set energy energy - (1 / 2)]
      if any? cands_on_neighbs with [color = red] [set energy energy - (1 / 2)]
      if any? cands_on_neighbs with [color = black] [set energy energy - (1 / 2)]
      ]
  ]
end 

; Merges agents when they are next to each other.

to merge 
      set leader [leader] of myself
      set agg_id [agg_id] of myself 
      ask link-neighbors with [leader != [leader] of myself]
      [ merge ]
end 


; Required to move agants on the grid

to set-location [new-location]  ;; walker procedure
  set location new-location
  move-to new-location
end 


;Basic plotting.

to update-plot
  set-current-plot "Energy"
  plot energy
end 


There are 12 versions of this model.

Uploaded by When Description Download
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago Initial upload Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version
Paul Sherratt over 14 years ago (Default description) Download this version

Attached files

No files

This model does not have any ancestors.

Children:

Graph of models related to 'Molecular Self-Organization'