# Amphiphile-oil-water system

Model was written in NetLogo 5.0.5
•
Viewed 616 times
•
Downloaded 29 times
•
Run 0 times

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

breed [amphicules amphicule] ; amphicule is here named a molecule/unit member of an amphiphilic chain ; "kind" specifies if the amphicule is either a lipophile (-1) or a hydrophile (+1). ; "leader" and "follower" gives the amphicule that precedes and follows in the chain. ; (arbitrarily, I assume the beginning of an amphiphile to be at its hydrophile end) amphicules-own [kind leader follower] ; the lipid molecules will be brown patches (with -1 as state, like the lipophiles) ; the water molecules are the blue patches (of +1 kind, like the hydrophiles). ; thus, the patch on where an amphicule sits must be of the same kind as itself patches-own [pkind] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to setup clear-all ask patches [ set pcolor blue + 2 set pkind 1 ] set-default-shape amphicules "circle" let lipids-number (max-pxcor + 1) * (max-pycor + 1) * lipids-fract ask patch 0 0 [ sprout-amphicules (lipophiles + hydrophiles) * amphiphiles ] ; the list of the patches which initially will host all amphicules, one on each patch if (lipophiles + hydrophiles) * amphiphiles > count patches [user-message (word "Amphiphiles are more than can fit in the world!")] let patch-list sublist (sort patches) 0 ((lipophiles + hydrophiles) * amphiphiles) ; initialization of the amphicules, mainly let i 0 ; for each of the amphiphiles while [i < amphiphiles] [ ; for each of the amphicules in each chain let j 0 while [j < lipophiles + hydrophiles] [ ask amphicule (j + (lipophiles + hydrophiles) * i) [ ;the first, a hydrophile (it is assumed that the minimum number of hydrophiles is 1) ifelse who = (lipophiles + hydrophiles) * i [ move-to item (j + (lipophiles + hydrophiles) * i) patch-list set kind 1 ask patch-here [set pkind 1] set leader nobody set follower amphicule (1 + (lipophiles + hydrophiles) * i) set color white set size 0.8 ] [ ; the last, a lipophile (it is assumed that the minimum number of lipophiles is 1) ifelse who = lipophiles + hydrophiles - 1 + (lipophiles + hydrophiles) * i [ move-to item (j + (lipophiles + hydrophiles) * i) patch-list set kind (- 1) ask patch-here [set pkind (- 1)] set color brown set leader amphicule (lipophiles + hydrophiles - 2 + (lipophiles + hydrophiles) * i) set follower nobody create-link-with leader [set thickness 0.2 set color black] ] [ ; for the intermediates move-to item (j + (lipophiles + hydrophiles) * i) patch-list ifelse j < hydrophiles [ set kind 1 ask patch-here [set pkind 1] set color white set size 0.8 ] [ set kind (- 1) ask patch-here [set pkind (- 1)] set color brown ] set leader amphicule (j - 1 + (lipophiles + hydrophiles) * i) set follower amphicule (j + 1 + (lipophiles + hydrophiles) * i) create-link-with leader [set thickness 0.2 set color black] ] ] ] set j (j + 1) ] set i (i + 1) ] ; initialization of the lipid, single sites if (lipids-number + count patches with [any? amphicules-here]) / count patches > 1 [user-message (word "Lipids are more than can fit in the world!")] ask n-of lipids-number patches with [not any? amphicules-here] [ set pcolor brown set pkind (- 1) ] reset-ticks end ; gives the fraction of the mixture that is occupied by amphiphile molecules to amphiphiles-fract clear-output output-print precision ((lipophiles + hydrophiles) * amphiphiles / (count patches)) 4 end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to go let option 0 let chosen1 nobody let neig-sum-1 0 let chosen2 nobody let Edif 0 let amphilist [] let plist [] let edge "back" let pchosen1 nobody let pchosen2 nobody let Eold 0 let Enew 0 let pchosen1kind 0 let pchosen2kind 0 let chosen1list [] let chosen2list [] let potentials [] ; !beware! !spaghetti code is following! ask one-of patches ; at each tick, a single proposal is made [ ;;;; First site selected is a lipid or water molecule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; if not any? amphicules-here [ ; it chose a single site firstly set chosen1 self set neig-sum-1 sum [pkind] of neighbors ask one-of other patches [ ;;;; Second site selected is a lipid or water molecule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ifelse not any? amphicules-here [ if pkind != [pkind] of chosen1 ; go on only if the second is of the other kind [ set chosen2 self set Edif 2 * (pkind * sum [pkind] of neighbors + [pkind] of chosen1 * neig-sum-1) if (Edif <= 0) or (temperature > 0 and (random-float 1.0 < exp ((- Edif) / temperature))) [ ; if the proposal is accepted, flip the states of the chosen two ask chosen1 [ set pkind (- pkind) ifelse pkind = 1 [set pcolor blue + 2][set pcolor brown] ] ask chosen2 [ set pkind (- pkind) ifelse pkind = 1 [set pcolor blue + 2][set pcolor brown] ] ] ] ] ;;;; Second site selected is amphicule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [ set option 1 ] ] ] ;;;; First site selected is an amphicule, or the second site selected previously was an amphicule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; In the latter case, disregard the first selection of a water or lipid molecule, and keep the second (the amphicule) as first ;;;;;;;;;;;;;; if (any? amphicules-here) or (option = 1) [ ask amphicules-here [ ;;;;; the first selected amphicule is either the hydrophilic or hydrophobic end of an amphiphilic chain ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; in this case, chain reptation is proposed ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ifelse leader = nobody or follower = nobody [ set chosen1 self set pchosen1 patch-here set pchosen1kind [pkind] of pchosen1 if leader = nobody [set edge "front"] set amphilist (give-chain chosen1) set plist (give-patches amphilist) ; continue only if the amphicule has at least one water or lipid molecules as neighbors ; (reptation is allowed only with a water/lipid site: the chain reptates to the water/lipid site, ; and the water/lipid molecule is sent to the emptied site) ask pchosen1 [ set potentials neighbors with [not any? amphicules-here] set pchosen2 one-of potentials if pchosen2 = nobody [stop] ] if pchosen2 = nobody [stop] foreach plist [ask ? [set Eold Eold - pkind * sum [pkind] of neighbors]] ask pchosen2 [ set pchosen2kind pkind set Eold Eold - pkind * sum [pkind] of neighbors ] ; from here on, chain reptation is developed foreach amphilist [ask ? [hide-turtle]] ask chosen1 [move-to pchosen2] ifelse edge = "front" [ let i 1 while [i < lipophiles + hydrophiles] [ ask item i amphilist [move-to item (i - 1) plist] ask item (i - 1) plist [ set pkind [kind] of item i amphilist set pcolor blue + 2 ] set i (i + 1) ] ] [ let i 0 while [i < lipophiles + hydrophiles - 1] [ ask item i amphilist [move-to item (i + 1) plist] ask item (i + 1) plist [ set pkind [kind] of item i amphilist set pcolor blue + 2 ] set i (i + 1) ] ] ifelse edge = "front" [ ask last plist [ set pkind [pkind] of pchosen2 ifelse ([pkind] of pchosen2) = 1 [set pcolor blue + 2][set pcolor brown] ] ] [ ask first plist [ set pkind [pkind] of pchosen2 ifelse ([pkind] of pchosen2) = 1 [set pcolor blue + 2][set pcolor brown] ] ] ask pchosen2 [ set pkind [kind] of chosen1 set pcolor blue + 2 ] foreach plist [ask ? [set Enew Enew - pkind * sum [pkind] of neighbors]] ask pchosen2 [set Enew Enew - pkind * sum [pkind] of neighbors] set Edif Enew - Eold ; chain reptation plus calculation of energies are done... ; in the following cases, the proposal is rejected, and everything returns to its original position if (proper-chain? amphilist = "False") or ((Edif > 0) and (((temperature > 0) and (random-float 1.0 > exp ((- Edif) / temperature))) or (temperature <= 0))) [ (foreach amphilist plist [ ask ?1 [move-to ?2] ask ?2 [ set pkind [kind] of ?1 set pcolor blue + 2 ] ]) ask pchosen1 [ set pkind pchosen1kind set pcolor blue + 2 ] ask pchosen2 [ set pkind pchosen2kind ifelse pchosen2kind = 1 [set pcolor blue + 2][set pcolor brown] ] ] foreach amphilist [ask ? [show-turtle]] ] ;;;;; the first selected amphicule is an intermediate amphiphilic chain member ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; in this case, chain twisting is proposed ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [ set chosen1 self set pchosen1 patch-here set pchosen1kind [pkind] of pchosen1 ask pchosen1 [ ; currently, only twisting with water/lipid molecules sites is allowed as proposals set potentials sort neighbors with [not any? amphicules-here] set potentials patch-set potentials set pchosen2 one-of potentials set Eold (- pkind * sum [pkind] of neighbors) if pchosen2 = nobody [stop] ] if pchosen2 = nobody [stop] ask pchosen2 [ set pchosen2kind pkind set Eold (Eold - pkind * sum [pkind] of neighbors) ] ; from here on, chain twisting is developed ask chosen1 [ hide-turtle move-to pchosen2 set chosen1list (give-chain chosen1) ] ask pchosen1 [ set pkind [pkind] of pchosen2 ifelse ([pkind] of pchosen2) = 1 [set pcolor blue + 2][set pcolor brown] ] ask pchosen2 [ set pkind [kind] of chosen1 set pcolor blue + 2 set Enew (- pkind * sum [pkind] of neighbors) ] ; chain twisting plus calculation of energies are done... ; in the following cases, the proposal is rejected, and everything returns to its original position if (proper-chain? chosen1list = "False") or ((Edif > 0) and (((temperature > 0) and (random-float 1.0 > exp ((- Edif) / temperature))) or (temperature <= 0))) [ ask chosen1 [ move-to pchosen1 ] ask pchosen1 [ set pkind pchosen1kind set pcolor blue + 2 ] ask pchosen2 [ set pkind pchosen2kind ifelse pchosen2kind = 1 [set pcolor blue + 2][set pcolor brown] ] ] ask chosen1 [show-turtle] ] ] ] ] tick end ;;; Three reporters are following ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; reports a list with all amphicules of a chain, from first to last, given an ; amphicule member of it to-report give-chain [amphicule] let previous [leader] of amphicule let current amphicule let chain [] while [previous != nobody] [ set current previous set previous [leader] of current ] set chain lput current chain let i 1 while [i < lipophiles + hydrophiles] [ set chain lput [follower] of last chain chain set i (i + 1) ] report chain end ; reports a list with all patches that a chain lies, from first to last, given the list ; of the amphicule chain members to-report give-patches [amphilist] let patch-list [] foreach amphilist [ask ? [set patch-list lput patch-here patch-list]] report patch-list end ; reports true or false depending on either the chain of the input, given as a ; list, has a proper configuration (each patch hosts one amphicule, and these ; patches are chain-like neighbors) to-report proper-chain? [amphiculelist] let proper? "True" foreach but-last amphiculelist [ask ? [if distance follower > 1.5 or distance follower < 0.1 [set proper? "False"]]] foreach amphiculelist [ask ? [if any? other amphicules-here [set proper? "False"]]] report proper? end

There is only one version of this model, created over 8 years ago by Danis Kiziridis.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Amphiphile-oil-water system.png | preview | Preview for 'Amphiphile-oil-water system' | over 8 years ago, by Danis Kiziridis | Download |

This model does not have any ancestors.

This model does not have any descendants.