Commit 01beff5a authored by Doak, Peter W's avatar Doak, Peter W
Browse files

netlogo 6.0.1 example added

parent 931c9c07
#!/bin/bash
#PBS -S /bin/bash
#PBS -m be
#PBS -M youremail@ornl.gov
#PBS -N sample_job
#PBS -q batch
#PBS -l nodes=1:ppn=32:hw32
#PBS -l walltime=0:10:00
#PBS -l naccesspolicy=singlejob
#PBS -W group_list=cades-cnms
#PBS -l qos=std
#PBS -A cnms
export OMP_NUM_THREADS=1
cd $PBS_O_WORKDIR
#this can be useful to see from outside shells
cat $PBS_NODEFILE >pbs_nodefile
module load env/cades-cnms
. $SOFTWARECNMS/spack/share/spack/setup-env.sh
spack load jdk
module load NetLogo/6.0.1
#each of these () surrounded commands launches in a subshell
(java -Xms8g -Xmx128g -Dfile.encoding=UTF-8 -Dnetlogo.extensions.dir=$NETLOGOROOT/app/extensions -classpath app/args4j-2.0.12.jar:$NETLOGOROOT/app/asm-5.0.3.jar:$NETLOGOROOT/app/asm-all-5.0.4.jar:$NETLOGOROOT/app/asm-analysis-5.0.3.jar:$NETLOGOROOT/app/asm-tree-5.0.3.jar:$NETLOGOROOT/app/asm-util-5.0.3.jar:$NETLOGOROOT/app/behaviorsearch.jar:$NETLOGOROOT/app/commons-codec-1.10.jar:$NETLOGOROOT/app/commons-logging-1.1.1.jar:$NETLOGOROOT/app/gluegen-rt-2.3.2.jar:$NETLOGOROOT/app/httpclient-4.2.jar:$NETLOGOROOT/app/httpcore-4.2.jar:$NETLOGOROOT/app/httpmime-4.2.jar:$NETLOGOROOT/app/jcommon-1.0.16.jar:$NETLOGOROOT/app/jfreechart-1.0.13.jar:$NETLOGOROOT/app/jhotdraw-6.0b1.jar:$NETLOGOROOT/app/jmf-2.1.1e.jar:$NETLOGOROOT/app/jogl-all-2.3.2.jar:$NETLOGOROOT/app/json-simple-1.1.1.jar:$NETLOGOROOT/app/log4j-1.2.16.jar:$NETLOGOROOT/app/macro-compat_2.12-1.1.1.jar:$NETLOGOROOT/app/netlogo-6.0.1.jar:$NETLOGOROOT/app/parboiled-core-1.1.7.jar:$NETLOGOROOT/app/parboiled-java-1.1.7.jar:$NETLOGOROOT/app/parboiled_2.12-2.1.3.jar:$NETLOGOROOT/app/pegdown-1.6.0.jar:$NETLOGOROOT/app/picocontainer-2.13.6.jar:$NETLOGOROOT/app/rsyntaxtextarea-2.6.0.jar:$NETLOGOROOT/app/scala-library-2.12.0.jar:$NETLOGOROOT/app/scala-library-2.12.1.jar:$NETLOGOROOT/app/scala-parser-combinators_2.12-1.0.5.jar:$NETLOGOROOT/app/shapeless_2.12-2.3.2.jar org.nlogo.headless.Main --model ./predator-prey.nlogo --experiment experiment1 2>&1 >out1) &
#wait for all subshells to complete
wait
......@@ -8,7 +8,8 @@
#PBS -l walltime=0:10:00
#PBS -l naccesspolicy=singlejob
#PBS -W group_list=cades-cnms
#PBS -l qos=condo
#PBS -l qos=std
#PBS -A cnms
export OMP_NUM_THREADS=1
......
extensions [pathdir]
; A bacteria is the predator, color green
; B bacteria is the prey, color red
globals [ total_bacteria total_bacteria_A total_bacteria_B
total_C_source
total_biomass total_biomass_A total_biomass_B
uptC ava_uptC
bacteria_t-1 bacteria_t biomass_t-1 biomass_t rate_bacteria rate_biomass
min_mass
file ]
turtles-own [ mass start_mass energy viab ]
patches-own [ local_C_source ]
breed [ A_bacterias A_bacteria ]
breed [ B_bacterias B_bacteria ]
;; INITIALIZATION
to check_make_directory [file_path]
let pos 0
let tfile file_path
let sep pathdir:get-separator
while [position sep tfile != false]
[
set pos (position sep tfile)
set tfile (substring tfile (pos + 1) (length tfile))
]
let tdir (substring file 0 (pos + 2))
if not pathdir:isDirectory? tdir
[
pathdir:create tdir
]
end
to setup
clear-all
; random-seed 1111 ;;;; TO MIMIC DIFFERENT REPLICATIONS, THIS LINE MUST BE INACTIVED (OTHERWISE, ALL THE REPETITIONS WILL PROVIDE EXACTLY THE SAME RANDOM VALUES, AND THUS, THE SAME RESULTS)
resize-world 0 square-cell-dimension 0 square-cell-dimension
set min_mass 0.5 * mass_reproduction
setup-bacteria
set total_C_source 0
setup-medium
do-plotting
reset-ticks
file-close
if length output-file-rootname < 1 [
set output-file-rootname user-new-file
]
set file (word output-file-rootname".dat")
if is-string? file
[
check_make_directory file
while [file-exists? file]
[
let pos 0
let tfile file
while [position "_" tfile != false]
[
set pos (position "_" tfile)
set tfile (substring tfile (pos + 1) (length tfile))
]
ifelse pos > 0
[
let posdat (position ".dat" file)
let run_index ((read-from-string (substring file (pos + 1) posdat)) + 1)
set file (word output-file-rootname "_" run_index ".dat")
]
[
set file (word output-file-rootname "_" 1 ".dat")
]
]
]
file-open file
if Output-files-with-results? = true [
file-print (word "# PARAMETERS OF THIS SIMULATION")
file-print (word "# -------------------------------------------------------")
file-print (word "# yield_C_source " yield_C_source)
file-print (word "# updtake_of_C_source " uptake_of_C_source)
file-print (word "# initial_local_C_source " initial_local_C_source)
file-print (word "# availability " availability)
file-print (word "# initial_predator " initial_predator)
file-print (word "# initial_prey " initial_prey)
file-print (word "# radius-movement " radius-movement)
file-print (word "# aggressiveness " aggressiveness)
file-print (word "# MovementType " MovementType)
file-print (word "# diff-coeff " diff-coeff)
file-print (word "# CV " CV)
file-print (word "# maintenance " maintenance)
file-print (word "# max_viability_time " max_viability_time)
file-print (word "# mass_reproduction " mass_reproduction)
file-print (word "# fed_C_source " fed_C_source)
file-print (word "# length_time_feed " length_time_feed)
file-print (word "# Output-files-with-results? " Output-files-with-results?)
file-print (word "# Hide-bacteria " Hide-bacteria)
file-print (word "# Show-products " Show-products)
file-print (word "# square-cell-dimension " square-cell-dimension)
file-print (word "# -------------------------------------------------------")
file-print (word "# POPULATIONS of PREDATOR AND PREY ")
file-print (word "# Tick Number " " #predator " " #prey ")
file-print ( word ticks " " count A_bacterias " " count B_bacterias )]
file-close
end
to setup-bacteria
set-default-shape turtles "dot"
create-turtles initial_predator ;; PREDATORS: GREEN BACTERIA A
[ set size 0.5
setxy random-xcor random-ycor
set mass abs ( random-normal (0.5 * mass_reproduction) (CV * mass_reproduction) )
set start_mass abs ( random-normal mass_reproduction (CV * mass_reproduction) )
set total_biomass total_biomass + mass
set energy 0
set viab 0
set breed A_bacterias set color green set total_biomass_A total_biomass_A + mass]
create-turtles initial_prey ;; PREY: RED BACTERIA B
[ set size 0.5
setxy random-xcor random-ycor
set mass abs ( random-normal (0.5 * mass_reproduction) (CV * mass_reproduction) )
set start_mass abs ( random-normal mass_reproduction (CV * mass_reproduction) )
set total_biomass total_biomass + mass
set energy 0
set viab 0
set breed B_bacterias set color red set total_biomass_B total_biomass_B + mass]
end
to setup-medium
ask patches [ set local_C_source ( abs(random-normal initial_local_C_source (CV * initial_local_C_source)) ) ]
set total_C_source sum [local_C_source] of patches
end
;; MAIN LOOP
to go
set bacteria_t-1 count turtles
;set bacteria_predator-1 count A_bacterias
;set bacteria_prey-1 count B_bacterias
set biomass_t-1 sum [mass] of turtles
;; TURTLES EXECUTE ACTIONS (e.g. move independly of its internal status, eat-metabolism, viabilitiy-die, reproduce, kill)
ask turtles [ move reproduce uptake ] ;;MARTA;; EL MISMO UPTAKE... NO HACE FALTA DISTINGUIR ENTRE A Y B
ask turtles [ viability ]
ask A_bacterias [ let prey one-of ( B_bacterias in-radius radius-movement ) ;;MARTA;; ALERTA NO TIENE SENTIDO QUE ESTE RADIO TOME VALORES DISTINTOS AL RADIO DE MOVIIENTO AHORA QUE LA AGRESIVIDAD SE EXPRESA CON UN COEFICIENTE PROPIO
;if prey != nobody [ ask prey [ die ] ] ]
if prey != nobody [ ask prey [ set energy (1 - aggressiveness) * energy ] ] ]
set total_biomass sum [mass] of turtles
set total_biomass_A sum [mass] of A_bacterias
set total_biomass_B sum [mass] of B_bacterias
set total_C_source sum [local_C_source] of patches
update_system
set bacteria_t count turtles
set biomass_t sum [mass] of turtles
if bacteria_t = 0 [
if Output-files-with-results? = true [ write-outputfile]
file-close stop ]
set rate_bacteria (bacteria_t - bacteria_t-1) / bacteria_t-1
set rate_biomass (biomass_t - biomass_t-1) / biomass_t-1
do-plotting
refresh-observation ;; to choose the outputs of the world
tick
end
to move
if MovementType = "Random" [ right random 360 forward abs(random-normal radius-movement (CV * radius-movement)) ]
if MovementType = "Random-Diffusion" [ right random 360 forward abs(random-normal (radius-movement * diff-coeff) (CV * radius-movement * diff-coeff)) ]
if MovementType = "Chemotaxis" [ ifelse random-float 1 < 0.5
[ let p max-one-of neighbors [local_C_source]
if [ local_C_source] of p > local_C_source [ face p forward abs(random-normal (radius-movement * diff-coeff) (CV * radius-movement * diff-coeff)) ] ]
[ right random 360 forward abs(random-normal (radius-movement * diff-coeff) (CV * radius-movement * diff-coeff)) ] ]
end
to uptake ;;MARTA;; EL MISMO UPTAKE... NO HACE FALTA DISTINGUIR ENTRE A Y B
let upC abs ( random-normal uptake_of_C_source (CV * uptake_of_C_source) )
set uptC upC * mass
set ava_uptC availability * [local_C_source] of patch-here
if uptC > ava_uptC [set uptC ava_uptC]
set local_C_source local_C_source - uptC
;; first the uptake of C_source to ahieve energy in orde to: 1) maintenain of celular structures, 2) producte cobamide
set energy energy + yield_C_source * uptC ;;MARTA;; CONTROL DE LA ENERGIA COMO UN RESERVOIR INTERNO QUE PUEDE SER ALTERADO POR LA DEPREDACION Y QUE POR TANTO NO SE REASIGNA CADA VEZ SINO QUE SE VA MODIFICANDO
set energy energy - maintenance * mass
if energy < 0 [ set energy 0 if mass > min_mass [ set mass (0.90 * mass) ] stop ]
set energy (0.5 * energy) ;;MARTA;; CONTROL DE LA ENERGIA, LA MITAD (POR SIMPLICIDAD) DARA BIOMASA Y LA OTRA MITAD SE ALMACENA COMO RESERVOIR INDIVIDUAL QUE PUEDE SER ALTERADO CON LA DEPREDACION...
let energy-mass energy
set mass mass + energy-mass
end
to viability
if energy = 0 [ set viab viab + 1 ]
let viab_death abs (random-normal max_viability_time (CV * max_viability_time))
if viab > viab_death [ die ]
end
to reproduce
if mass > start_mass
[ set mass mass / 2 set start_mass abs ( random-normal mass_reproduction (CV * mass_reproduction) ) set energy energy / 2 set viab viab / 2 hatch 1
[ set mass mass set start_mass abs ( random-normal mass_reproduction (CV * mass_reproduction) ) set energy energy set viab viab ] ]
end
to update_system
diffuse local_C_source diff-coeff
if (Protocol-of-feed = "Fed-batch") ;;; Input of C_source
[ if ticks mod length_time_feed = 0
[ ask patches [ set local_C_source local_C_source + fed_C_source ]
set total_C_source sum [local_C_source] of patches ] ]
end
to do-plotting
set-current-plot "Mass distribution of predator"
set-current-plot-pen "mass_A"
histogram [mass] of turtles with [color = green]
set-current-plot "Mass distribution of prey"
set-current-plot-pen "mass_B"
histogram [mass] of turtles with [color = red]
end
to refresh-observation
ask turtles [set hidden? Hide-bacteria]
ask patches
[ if Show-products = "C_source" ;; colors each patch a shade of color proportional to its value for the variable
[ let max-value max [local_C_source] of patches
if max-value > 0 [ set pcolor scale-color brown local_C_source 0 max-value ] ] ]
if Output-files-with-results? = true [ write-outputfile]
end
to write-outputfile
file-open file
file-print ( word ticks " " count A_bacterias " " count B_bacterias)
end
@#$#@#$#@
GRAPHICS-WINDOW
821
10
1351
541
-1
-1
16.84
1
10
1
1
1
0
0
0
1
0
30
0
30
1
1
1
ticks
30.0
BUTTON
977
568
1038
601
setup
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
SLIDER
245
10
446
43
Initial_predator
Initial_predator
0
100
56.0
1
1
NIL
HORIZONTAL
SLIDER
8
60
181
93
yield_C_source
yield_C_source
0.0
1
0.15
0.01
1
NIL
HORIZONTAL
PLOT
8
451
350
584
C_source
Time steps
NIL
0.0
10.0
0.0
100.0
true
false
"" ""
PENS
"" 1.0 0 -6459832 true "" "plot total_C_source"
MONITOR
487
591
574
640
# Bacteria
count turtles
1
1
12
SLIDER
8
133
219
166
initial_local_C_source
initial_local_C_source
0
10000
5000.0
10
1
NIL
HORIZONTAL
BUTTON
1046
568
1142
601
go one step
go
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
1152
568
1214
601
go
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
SLIDER
634
90
794
123
mass_reproduction
mass_reproduction
0
100
50.0
1
1
NIL
HORIZONTAL
MONITOR
576
591
691
640
C_source
total_C_source
1
1
12
SLIDER
8
95
235
128
uptake_of_C_source
uptake_of_C_source
0
1
0.1
0.01
1
NIL
HORIZONTAL
SLIDER
634
49
816
82
max_viability_time
max_viability_time
0
1000
500.0
5
1
NIL
HORIZONTAL
SLIDER
634
11
772
44
maintenance
maintenance
0
1
0.15
0.01
1
NIL
HORIZONTAL
CHOOSER
9
10
147
55
Protocol-of-feed
Protocol-of-feed
"Batch" "Fed-batch"
0
SLIDER
246
202
418
235
fed_C_source
fed_C_source
0
10000
5000.0
10
1
NIL
HORIZONTAL
SLIDER
423
202
595
235
length_time_feed
length_time_feed
1
500
100.0
1
1
NIL
HORIZONTAL
TEXTBOX
149
204
237
236
For Fed-batch:
13
0.0
0
PLOT
379
422
785
580
Biomass
Time steps
NIL
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
" Total" 1.0 0 -16777216 true "" "plot total_biomass"
"predator" 1.0 0 -10899396 true "" "plot total_biomass_A"
"prey" 1.0 0 -2674135 true "" "plot total_biomass_B"
SLIDER
9
171
135
204
availability
availability
0
1
0.15
0.01
1
NIL
HORIZONTAL
MONITOR
214
592
304
641
Rate of biomass
rate_biomass
4
1
12
MONITOR
120
593
211
642
Rate of bacteria
rate_bacteria
4
1
12
PLOT
372
253
590