-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2D_Crypto_Vertical_Cross_Section.nlogo
executable file
·1699 lines (1511 loc) · 40.9 KB
/
2D_Crypto_Vertical_Cross_Section.nlogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;-----------------------------line-width-of-80-----------------------------
;; This source file acts as the view and controller.
__includes ["Cell-Instructions.nls" "Cell-Positions.nls"]
globals [crypt_circumference]
breed [cells cell]
cells-own [
force_x
force_y
cell_state ; can be "immature", "mature", "wholly-mature", or "dead"
age ; number of cycles since birth of cell
split_direction ; number from 0 to stem-mc which determines the direction of the next split
; see "Defining the Model - Division Angles" in the "Info" tab for directional conventions
cell_mc ; maturation cycle of the cell
cell_wm ; time to whole maturation of the cell
cell_ls ; life span of the cell
is_stem? ; flags whether or not the cell is a stem cell
generation ; number of generations removed from stem cell
branch_direction ; number corresponding to the branch number that cell belongs to. Convention is the same as
; split_direction's [- so it's parent?]<-Ben
neighbor_cells ; ordered list of cells immediately linked as neighbors (or "nobody"). The index of the cell
; on the list defines the direction of the neighbor according to the same convention as the
; split_direction
cxcor2D ; theoretical x coordinate of the cell as laid out in two dimensions
cycor2D ; theoretical y coordinate of the cell as laid out in two dimensions
visited? ; multi-use flag that can be set/reset for the purposes of tree traversal
]
breed [anchors anchor]
undirected-link-breed [springs spring]
undirected-link-breed [anchor-links anchor-link]
springs-own [affinity]
anchors-own [
force_x force_y
neighbor_cells
]
to Setup
clear-all
SetupCellInstructions ; from Cell-Instructions.nls; creates initial stem cell
FormatCells
set-default-shape cells "circle"
set-default-shape anchors "square"
ask cells [ set size 5 ]
reset-ticks
end
to update-springs
if link-type = "spring-child"[
;shouldn't need to do anything here
]
if link-type = "spring-radius"[
clear-links
ask cells [
ask other cells in-radius spring-radius [
create-spring-with myself
]
]
]
if link-type = "gravity"[
clear-links
ask cells [
let parent self
ask other cells in-radius spring-radius [
let child self
create-spring-with myself [ set affinity [distance parent] of child ]
]
]
]
if link-type = "spring-left-right" [
clear-links
ask cells[
if count cells with [xcor < [xcor] of myself] != 0 [
create-spring-with max-one-of cells with [xcor < [xcor] of myself] [xcor]
]
if count cells with [xcor > [xcor] of myself] != 0 [
create-spring-with min-one-of cells with [xcor > [xcor] of myself] [xcor]
]
]
]
end
to apply-springs
ask cells [
set force_x 0
set force_y 0
if count anchors = 2[
;set force_y out-side-force
set force_x sin heading * outside-force
set force_y cos heading * outside-force
]
]
ask links [
if true[
let spring-force 0
if-else link-length = 0
[
set spring-force spring-strength * explode-force
show "boom"
]
[
ifelse (link-length - resting-distance) < max-distance
[set spring-force spring-strength * ln (link-length / resting-distance)]
[set spring-force spring-strength * (((link-length - max-distance) / increased-spring-scale) * ln (link-length / resting-distance) + ln (max-distance))]
; if spring-force > 10 [show spring-force]
;set spring-force spring-strength * ln (link-length / resting-distance)
let displacement link-length - resting-distance
; ifelse displacement < 0 [
; set spring-force -1 * spring-strength * (-1 * displacement) ^ (2 / 3)
; ][
; set spring-force spring-strength * (displacement) ^ (2 / 3)
; ]
;set spring-force spring-strength * (displacement ^ 3)
;set spring-force spring-strength / (displacement * (1 - displacement))
;set spring-force spring-strength * ln (abs(link-length - resting-distance) / resting-distance)
;set spring-force spring-strength * ((link-length - resting-distance) ^ 3 )
if link-type = "gravity" [set spring-force spring-force * gravity-pull / affinity]
]
let force_vector (list 0 0)
ifelse link-length > 0
[set force_vector (list ((sin link-heading) * spring-force) ((cos link-heading) * spring-force))]
[set force_vector (list (spring-force) (spring-force))]
ask end1 [set force_x force_x + first force_vector]
ask end1 [set force_y force_y + first but-first force_vector]
ask end2 [set force_x force_x - first force_vector]
ask end2 [set force_y force_y - first but-first force_vector]
]
]
ask cells [
ask other cells in-radius 5 [
if distance myself != 0[
let xdiff abs ([xcor] of myself - [xcor] of self)
let ydiff abs ([ycor] of myself - [ycor] of self)
let xforce 0
let yforce 0
if xdiff != 0
[set xforce repulsion-strength / (((1 + xdiff) ^ 6) ^ (1 / 3))]
if ydiff != 0
[set yforce repulsion-strength / (((1 + ydiff) ^ 6) ^ (1 / 3))]
ifelse [xcor] of myself < [xcor] of self [
ask myself [set force_x force_x - xforce]
][
ask myself [set force_x force_x + xforce]
]
ifelse [ycor] of myself < [ycor] of self [
ask myself [set force_y force_y - yforce]
][
ask myself [set force_y force_y + yforce]
]
]
]
]
; ask cells with [count my-links = 2] [
; let hding heading
; ask my-links [
; if link-heading > (180 + hding) or link-heading < hding[
; let goal 270 + hding
;
; ]
; if link-heading < hding[
; let temp link-heading + 360
; ]
;
;
;
; let lhead (link-heading - hding) mod 360
; if (lhead > 90 and lhead < 180) or (lhead > 270 and lhead < 360)[
; ask other-end [set force_x force_x - (sin hding) / 4]
; ask other-end [set force_y force_y - (cos hding) / 4]
; ]
; if (lhead > 180 and lhead < 270) or (lhead > 0 and lhead < 90)[
; ask other-end [set force_x force_x + (sin hding) / 4]
; ask other-end [set force_y force_y + (cos hding) / 4]
; ]
; ]
; ]
; ask cells with [count my-links = 2] [
; let goal (heading + 90) mod 180
; let headx sin heading * straightening
; let heady cos heading * straightening
; let lhead 0
; ask one-of my-links [
; set lhead link-heading
; ]
; ifelse lhead < 180 [
; ifelse lhead < goal [
; ;move forward
; set force_x force_x + headx
; set force_y force_y + heady
; ][
; set force_x force_x - headx
; set force_y force_y - heady
; ;move backward
; ]
; ][
; ifelse lhead > goal + 180 [
; ;move backward
; set force_x force_x - headx
; set force_y force_y - heady
; ][
; ;move forward
; set force_x force_x + headx
; set force_y force_y + heady
; ]
; ]
; ]
ask cells [
let newx max (list (min-pxcor) (min list (xcor + (adjustment-rate * force_x)) (max-pxcor) ))
let newy max (list (min-pycor) (min list (ycor + (adjustment-rate * force_y)) (max-pycor) ))
let toofar false
; foreach neighbor_cells[
; if distancexy newx newy > max-distance [set toofar true]
; ]
if not toofar[
set xcor newx
set ycor newy
]
]
end
to Go
; call to cell-instructions to advance cell activity
if division[
GoCellInstructions ; from Cell-Instructions.nls
]
FormatCells
update-springs
;repeat 3 [ layout-spring cells links .1 2 1 ]
repeat M [apply-springs]
; call to Draw function to display cells
CellDirect
CheckForAnchors
tick
end
to CheckForAnchors
if count anchors < 2[
ask max-one-of cells [xcor] [
if xcor > 16 [
if count anchors = 0 or (count anchors = 1 and [xcor] of one-of anchors < -16) [
hatch-anchors 1 [
create-spring-with item 0 neighbor_cells
ask item 0 neighbor_cells [set neighbor_cells replace-item 1 neighbor_cells myself]
]
die
]
]
]
ask min-one-of cells [xcor] [
if xcor < -16 [
if count anchors = 0 or (count anchors = 1 and [xcor] of one-of anchors > 16) [
hatch-anchors 1 [
create-spring-with item 1 neighbor_cells
ask item 1 neighbor_cells [set neighbor_cells replace-item 0 neighbor_cells myself]
]
die
]
]
]
]
end
to CellDirect
if orientation-type = "upward-restricted" [
ask cells [
if count my-links != 0 [
let avg 0
ask my-links [
let hding link-heading
if end2 = myself [set hding hding - 180]
set avg avg + hding
]
set avg avg / count my-links
set heading avg - 90 * count my-links
if heading > 90 and heading < 270 [set heading heading + 180]
]
]
]
if orientation-type = "minimal-rotation" [
ask cells [
if count my-links != 0 [
let avg 0
ask my-links [
let hding link-heading
if end2 = myself [set hding hding - 180]
set avg avg + hding
]
set avg avg / count my-links
let goal avg - 90 * count my-links
ifelse subtract-headings goal heading < -90 or subtract-headings goal heading > 90
[set heading goal + 180]
[set heading goal]
]
]
]
end
;; ReDraw the cell structure
to Draw
if any? cells [
; call to position-cells which places all cells in appropriate position
position-2D-Cell-Positions
; call to format-cell function which defines superficial shapes and color
FormatCells
; if the true coordinates exceed the size of the world, then hide the turtle and move it to an inconsequential
; position otherwise update the displayed position to match the true position
ask cells [
ifelse (abs cxcor2D >= max-pxcor) or (abs cycor2D >= max-pycor) [
hide-turtle
setxy max-pxcor max-pycor
][
setxy cxcor2D cycor2D
]
]
]
end
;; Set desired shapes and colors based on cell state
to FormatCells
ask cells [
if cell_state = "immature" [ set color red set shape "hex-arrow"]
if cell_state = "mature" [ set color blue set shape "hex-arrow"]
if cell_state = "wholly-mature" [ set color green - 3 set shape "hex"]
if cell_state = "dead" [ hide-turtle ]
if is_stem? [
set color white
]
]
end
;; Set up a "small world" where there are fewer, larger patches
;; Use for close examination of individual cell activity
to SmallWorld
set-patch-size 13
resize-world (0 - 17) 17 (0 - 17) 17
Setup
end
;; Set up a "large world" where there are more, smaller patches
;; Use for macroscopic view of the cellular structure
to LargeWorld
set-patch-size 3
resize-world (0 - 75) 75 (0 - 75) 75
Setup
end
@#$#@#$#@
GRAPHICS-WINDOW
262
10
693
523
-1
-1
3.0
1
10
1
1
1
0
0
0
1
-70
70
-150
17
1
1
1
ticks
30.0
SLIDER
26
150
127
183
stem-mc
stem-mc
2
10
2.0
2
1
NIL
HORIZONTAL
BUTTON
35
43
96
76
NIL
setup\n
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
96
43
159
76
step
go
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
0
MONITOR
733
17
798
62
Live Cells
count cells with [cell_state != \"dead\"]
17
1
11
SLIDER
127
150
228
183
lifespan
lifespan
0
200
8.0
1
1
NIL
HORIZONTAL
BUTTON
35
10
128
43
small-world
SmallWorld
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
128
10
232
43
large-world
LargeWorld
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
SWITCH
7
113
153
146
immortal-stem-cell?
immortal-stem-cell?
0
1
-1000
MONITOR
798
17
886
62
Max Generation
[generation] of max-one-of cells [generation]
17
1
11
MONITOR
886
17
995
62
% Wholly Mature
count cells with [cell_state = \"wholly-mature\"] * 100 / count cells with [cell_state != \"dead\"]
5
1
11
PLOT
732
218
996
346
Cell type count vs Distance along crypt
NIL
NIL
0.0
10.0
0.0
3.0
true
false
"" ""
PENS
"Immature" 1.0 0 -2674135 true "set-plot-x-range 0 max-pxcor" "histogram [ round distance cell 0 ] of cells with [cell_state = \"immature\"]"
"Maturing" 1.0 0 -13345367 true "" "histogram [ round distance cell 0 ] of cells with [cell_state = \"mature\"]"
"Fully Mature" 1.0 0 -6459832 true "" "histogram [ round distance cell 0 ] of cells with [cell_state = \"wholly-mature\"]"
BUTTON
159
43
222
76
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
0
SLIDER
26
183
127
216
gen1-mc
gen1-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
26
216
127
249
gen2-mc
gen2-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
26
249
127
282
gen3-mc
gen3-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
26
282
127
315
gen4-mc
gen4-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
26
315
127
348
gen5-mc
gen5-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
127
183
228
216
gen1-wm
gen1-wm
0
12
7.0
1
1
NIL
HORIZONTAL
SLIDER
127
216
228
249
gen2-wm
gen2-wm
0
12
7.0
1
1
NIL
HORIZONTAL
SLIDER
127
249
228
282
gen3-wm
gen3-wm
0
12
8.0
1
1
NIL
HORIZONTAL
SLIDER
127
282
228
315
gen4-wm
gen4-wm
0
12
7.0
1
1
NIL
HORIZONTAL
SLIDER
127
315
228
348
gen5-wm
gen5-wm
0
12
6.0
1
1
NIL
HORIZONTAL
SWITCH
153
113
251
146
angle-shift
angle-shift
1
1
-1000
SWITCH
7
80
97
113
rabbit?
rabbit?
1
1
-1000
SWITCH
97
80
251
113
no-whole-maturation?
no-whole-maturation?
1
1
-1000
SLIDER
26
348
127
381
gen6-mc
gen6-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
26
381
127
414
gen7-mc
gen7-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
26
414
127
447
gen8-mc
gen8-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
26
447
127
480
gen9-mc
gen9-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
127
348
229
381
gen6-wm
gen6-wm
0
12
5.0
1
1
NIL
HORIZONTAL
SLIDER
127
381
229
414
gen7-wm
gen7-wm
0
12
4.0
1
1
NIL
HORIZONTAL
SLIDER
127
414
229
447
gen8-wm
gen8-wm
0
12
3.0
1
1
NIL
HORIZONTAL
SLIDER
127
447
229
480
gen9-wm
gen9-wm
0
12
2.0
1
1
NIL
HORIZONTAL
SLIDER
26
480
127
513
gen10-mc
gen10-mc
0
6
6.0
1
1
NIL
HORIZONTAL
SLIDER
127
480
229
513
gen10-wm
gen10-wm
0
12
1.0
1
1
NIL
HORIZONTAL
SLIDER
733
353
905
386
spring-strength
spring-strength
0
5
3.2
.1
1
NIL
HORIZONTAL
SLIDER
732
390
904
423
resting-distance
resting-distance
0
10
3.2
.2
1
NIL
HORIZONTAL
SLIDER
733
426
905
459
adjustment-rate
adjustment-rate
0
2
0.1
.01
1
NIL
HORIZONTAL
SLIDER
733
462
905
495
explode-force
explode-force
0
10
2.0
1
1
NIL
HORIZONTAL
SLIDER
911
352
944
502
M
M
0
300
213.0
1
1
NIL
VERTICAL
SLIDER
727
497
899
530
spring-radius
spring-radius
0
10
8.0
1
1
NIL
HORIZONTAL
SWITCH
906
107