source: experiments/frams/foraminifera/data/scripts/foraminifera.expdef @ 557

Last change on this file since 557 was 557, checked in by Maciej Komosinski, 8 years ago
  • Fixed extra space after property ID
  • A function to generate simple planispiral forams
File size: 26.9 KB
RevLine 
[380]1expdef:
[406]2name:Reproduction of benthic foraminifera
[380]3info:~
[434]4Basic information about this simulation:
5www.framsticks.com/foraminifera
6
7Technical information:
[476]8Genes and parameter values which control reproduction are stored in data->genes and data->lifeparams fields.
[380]9
[476]10genes:
[402]11genes which are not encoded in Ff genotype:
[422]12min_repro_energy - Minimum energy necessary for reproduction
13hibernation - Defines foram behavior in the case of no nutrients
[380]14
[476]15lifeparams:
[380]16Physiological parameters of foraminifera:
[422]17max_energy_level - maximum energy level reached so far
[380]18gen - generation: 0 haploid, 1 diploid
[432]19species - species: 0 not hibernating 1 hibernating
20hibernated - 0/1 foram is/isn't hibernated
[422]21reproduce - 0/1 foram isn't/is ready for reproduction
[380]22~
23code:~
24
[479]25global chambers;
[422]26global colors;
[493]27global retColors;
28global curColor;
[479]29global max_chamber_volume;
[474]30global movePerStep;
[479]31global nutrientenergywaiting;
32global o;
33global reprocounter;
[481]34global changePeriod;
35global phase;
[493]36global nutrientSqrCm;
[487]37global species_genes;
[380]38
[406]39@include "foraminifera.inc"
[401]40
[380]41// -------------------------------- experiment begin --------------------------------
42
43function onExpDefLoad()
44{
45        // define genotype and creature groups
46        GenePools.clear();
47        Populations.clear();
48        GenePools[0].name = "Unused";
49
50        var pop = Populations[0];
[421]51        pop.name = "Forams";
[380]52        pop.en_assim = 0;
[404]53        pop.nnsim = 0;
[380]54        pop.enableperf = 1;
55        pop.death = 1;
56        pop.energy = 1;
[487]57        pop.selfmask = 0;
58        pop.othermask = 0;
[401]59        //pop.selfmask = 0x20002; pop.othermask = 0x10002;
[422]60        pop.perfperiod = 25;
[487]61        pop.bodysim = 0;
[380]62
[421]63        pop = Populations.addGroup("Nutrients");
[380]64        pop.nnsim = 0;
65        pop.enableperf = 0;
66        pop.death = 1;
67        pop.energy = 1;
[487]68        pop.selfmask = 0;
69        pop.othermask = 0;
[422]70        //pop.othermask = 0x10002;
[487]71        pop.bodysim = 0;
[380]72
[444]73        pop = Populations.addGroup("ReticulopodiaNutrients");
[430]74        pop.nnsim = 0;
75        pop.enableperf = 0;
76        pop.death = 0;
77        pop.energy = 0;
[487]78        pop.selfmask = 0;
79        pop.othermask = 0;
80        pop.bodysim = 0;
[444]81
[422]82        //world
83        SignalView.mode = 1;
[496]84        World.wrldwat = 200;
[493]85        World.wrldsiz = micronsToFrams(100000);
[422]86        World.wrldbnd = 1;
87
[474]88        movePerStep = getMovePerStep();
89
[486]90        //ExpProperties.visualize = 1; //uncomment to visualize reticulopodia and indicate nutrients positions
[444]91
[487]92        //ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files   
[493]93        ExpProperties.logPref = "";
[401]94
[487]95        species_genes = [];
96
[554]97        //morphology
[479]98        init_chambers();
[493]99        curColor = retColors[0];
[486]100        ExpProperties.zone1_range = micronsToFrams(1000);
101        ExpProperties.zone2_range = micronsToFrams(3000);
102        ExpProperties.chamber_proculus_haplo = micronsToFrams(50);
103        ExpProperties.chamber_difference_haplo = 0.0;
104        ExpProperties.chamber_proculus_diplo = micronsToFrams(20);
105        ExpProperties.chamber_difference_diplo = micronsToFrams(8);
[479]106
107        max_chamber_volume = [Vector.new(), Vector.new()];
[422]108        for (var j = 0; j < 2; j++)
109        {
110                for (var i = 0; i < chambers[0].size; i++)
111                {
[479]112                        max_chamber_volume[j].add(((volumeInMicrons(getProperty(j, "chamber_proculus")) + volumeInMicrons(getProperty(j, "chamber_proculus") + (i) * getProperty(j, "chamber_difference")))*(i+1))/2); 
[422]113                }                                 
114        }
115
116        //nutrients
[486]117        ExpProperties.nutrientradius = micronsToFrams(10);
[552]118        ExpProperties.energy_nut = 200 * energyFromVolume(ExpProperties.nutrientradius,1);
[554]119        nutrientSqrCm = 10;
[493]120        ExpProperties.nutrient_pop = Math.pow(framsToMicrons(World.wrldsiz)*0.0001,2)/nutrientSqrCm;
[554]121
[380]122        ExpState.totaltestedcr = 0;
[421]123        ExpState.nutrient = "";
[488]124       
[493]125        //addSpecies({"min_repro_energies" : [4,6]});
126        //addSpecies({"min_repro_energies" : [4,8]});
[557]127       
128        //Simulator.print(create_genotype(0.1, 30)); //sample call
129        //Simulator.print(create_genotype(0.2, 30)); //sample call
[380]130}
131
132@include "standard_placement.inc"
133
[554]134function secToSimSteps(value_in_sec){
135        return value_in_sec/ExpProperties.secPerStep;
136}
137
[479]138function volumeInMicrons(radiusInFrams)
[475]139{
[479]140        return 4.0/3.0*Math.pi*Math.pow(framsToMicrons(radiusInFrams),3);
[475]141}
142
[479]143function energyFromVolume(base, isRadiusInFrams)
144{
145        if (isRadiusInFrams == 1) //radius in frams
146        {
[486]147                return ExpProperties.picoCarbonPerMikro*volumeInMicrons(base);
[479]148        }
149        else //volume in microns
150        {
[486]151                return ExpProperties.picoCarbonPerMikro * base;
[479]152        }
153}
154
[474]155function getMovePerStep()
156{
[486]157        return micronsToFrams((ExpProperties.foramSpeedMmPerMin/60)*1000)*ExpProperties.secPerStep;
[474]158}
159
[447]160function micronsToFrams(micrometers)
[422]161{
[493]162        return micrometers*0.01;
[422]163}
164
[447]165function framsToMicrons(framsworldunits)
[445]166{
[493]167        return framsworldunits/0.01;
[445]168}
169
[422]170function getProperty(gen, prop_id)
171{
172        var ploid = "haplo";
173        if (gen == 1) ploid = "diplo";
[486]174        return ExpProperties.[prop_id + "_" + ploid];
[422]175}
176
[487]177function getGene(cr, gen_id, gen_set)
178{
179        if (cr.data->lifeparams->gen == 0)
180                return cr.data->genes[gen_id];
181        else
182                return cr.data->genes[gen_set][gen_id];
183}
184
[479]185function addForam(species, iter, chambernum, ploid)
[422]186{
[496]187        var geno = createForamMorphology(ploid, ploid, chambernum);
[493]188        curColor = retColors[ploid];
[422]189        var cr = Populations[0].add(geno);
[479]190        cr.name = "Initial creature" + species + "_" + iter;
[422]191        placeCreatureRandomly(cr, 0, 0);
[479]192        cr.energy0 = energyFromVolume(max_chamber_volume[ploid][chambernum],0);
[422]193        cr.energy = cr.energy0;
[554]194        setGenotype({"opt" : "birth", "cr" : cr, "gen" : ploid, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]});
[479]195        if (ploid == 1)
196        {
197                cr.data->genes = [cr.data->genes, cr.data->genes]; //TODO two different genes sets
198        }
[525]199        moveReticulopodia(cr);
[422]200}
201
[479]202function addInitialForam(species, iter)
203{
204        var ploid = 0;
205        if (Math.rnd01 > 0.5)
206        {
207                ploid = 1;
208        }       
[493]209        //add new foram with random energy bewtween starting energy and reproduction threshold
[488]210        addForam(species, iter, int(Math.rndUni(0,species_genes[species]->min_repro_energies[ploid])),ploid);
[479]211}
212
[487]213//new species can be added as a dictionary with parameter values that are different than default values
214function addSpecies(new_genes)
215{
[493]216        species_genes.add({"min_repro_energies" : [ExpProperties.min_repro_energ_haplo,ExpProperties.min_repro_energ_diplo], "energies0" : [ExpProperties.energies0_haplo, ExpProperties.energies0_diplo], "hibernation" : 0, "morphotype" : 0});
[487]217        for (var i = 0; i < new_genes.size; i++)
218        {
219                var key = new_genes.getKey(i);
220                species_genes[species_genes.size-1][key] = new_genes[key];
221        }
222}
223
[380]224function onExpInit()
225{
226        Populations[0].clear();
227        Populations[1].clear();
[444]228        Populations[2].clear(); //reticulopodia and nutrients
[380]229
[487]230        if (species_genes.size == 0)
[380]231        {
[487]232                addSpecies({}); //default
[380]233        }
[487]234
235        for (var spec = 0; spec < species_genes.size; spec++)
236        {
237                for (var i = 0; i < ExpProperties.foramPop; i++)
238                {
239                        addInitialForam(spec, i);       
240                }
241        }
[422]242        o = Populations[0][0].getMechPart(0).orient.clone();
[380]243        ExpState.totaltestedcr = 0;
[554]244
245        reprocounter = 0;
246        nutrientenergywaiting = 0;
247        changePeriod = 0;
248        phase = "low";
[380]249}
250
251function onExpLoad()
252{
253        for (var pop in Populations)
254                pop.clear();
255
256        Loader.addClass(sim_params.*);
257        Loader.setBreakLabel(Loader.BeforeUnknown, "onExpLoad_Unknown");
258        Loader.run();
259
[421]260        Simulator.print("Loaded " + Populations[0].size + " Forams and " + Populations[1].size + " nutrient objects");
[380]261}
262
263function onExpLoad_Unknown()
264{
265        if (Loader.objectName == "org") // saved by the old expdef
266        {
267                var g = Genotype.newFromString("");
268                Loader.currentObject = g;
269                Interface.makeFrom(g).setAllDefault();
270                Loader.loadObject();
271                var cr = Populations[0].add(g);
272                if (cr != null)
273                {
[401]274                        //cr.rotate(0,0,Math.rnd01*Math.twopi);
[476]275                        if ((typeof(g.data->genes) == "Vector") && (g.data->genes.size >= 3))
[401]276                        {
277                                // [x,y,energy]
[476]278                                cr.move(g.data->genes[0] - cr.center_x, g.data->genes[1] - cr.center_y, 0);
279                                cr.energy = g.data->genes[2];
[380]280                        }
281                        else
282                        {
[401]283                                cr.move(Math.rnd01 * World.wrldsiz - cr.center_x, Math.rnd01 * World.wrldsiz - cr.center_y, 0);
[380]284                        }
285                }
286        }
287        else if (Loader.objectName == "Creature")
288        {
289                Loader.currentObject = CreatureSnapshot.new();
290                Loader.loadObject();
291                Populations[0].add(Loader.currentObject);
292        }
293}
294
295function onExpSave()
296{
297        File.writeComment("saved by '%s.expdef'" % Simulator.expdef);
298
[401]299        var tmpvec = [], i;
[380]300
[401]301        for(var cr in Populations[1])
[380]302                tmpvec.add([cr.center_x, cr.center_y, cr.energy]);
303
[421]304        ExpState.nutrient = tmpvec;
[380]305        File.writeObject(sim_params.*);
[432]306        ExpState.nutrient = null; //vectors are only created for saving and then discarded
[380]307
308        for (var cr in Populations[0])
309                File.writeObject(cr);
310}
311
312// -------------------------------- experiment end --------------------------------
313
[421]314// -------------------------------- foram begin -----------------------------------
[380]315
[479]316function setForamMeta(cr)
[430]317{
[479]318        //percent of current energy
[486]319        cr.idleen = (ExpProperties.e_meta * cr.energy)*ExpProperties.secPerStep;
[430]320}
321
322function lastChamberNum(cr)
323{
324        return cr.numparts-1;
325}
326
[479]327function getZoneRange(cr, zone_num)
328{
[486]329        return ExpProperties.["zone"+zone_num+"_range"];
[479]330}
331
[421]332function onForamsBorn(cr)
333{
[479]334        setForamMeta(cr);
[486]335        if (ExpProperties.visualize == 1)
[430]336        {
[506]337                var ret = Populations[2].add("//0\nm:Vstyle=reticulopodia\np:sh=1,sx=0.001,sy=0.001,sz=0.001\np:sh=3,sx=0.01,sy="+getZoneRange(cr,1)+",sz="+getZoneRange(cr,1)+",ry=1.57079633,vr="+curColor+"\nj:0, 1, sh=1");
[476]338                cr.data->reticulopodiacreature = ret;
[506]339                ret.getMechPart(0).orient.set(cr.getMechPart(0).orient);
[496]340                ret.moveAbs(cr.center_x-getZoneRange(cr,1), cr.center_y-getZoneRange(cr,1), cr.center_z-getZoneRange(cr,1));
[430]341        }
[380]342}
343
[401]344function placeRandomlyNotColliding(cr)
345{
346        var retry = 100; //try 100 times
347        while (retry--)
348        {
349                placeCreatureRandomly(cr, 0, 0);
350                if (!cr.boundingBoxCollisions(0))
351                        return cr;
352        }
353
354        Populations[0].delete(cr);
355}
356
[444]357function visualization(cr)
358{
359        var has_ret = 0;
360
[476]361        if (cr.data->reticulopodiacreature != null)
[444]362        {
[476]363                if (Populations[2].findUID(cr.data->reticulopodiacreature.uid) != null)
[444]364                {
365                        has_ret = 1;
366                }
367        }
368
369        return has_ret;
370}
371
[422]372function foramGrow(cr, chamber_num)
[380]373{
[476]374        if ((chamber_num+1) < chambers[cr.data->lifeparams->species].size)
[474]375        {
[493]376                curColor = retColors[cr.data->lifeparams->gen];
[496]377                var geno = createForamMorphology(cr.data->lifeparams->gen, cr.data->lifeparams->gen, chamber_num+1);
[474]378                var cr2 = Populations[0].add(geno);
[422]379
[474]380                cr2.energy0 = cr.energy;
381                cr2.energy = cr2.energy0;
[422]382
[554]383                setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : "growth", "energy0" : cr.energy0});
[474]384                cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
[479]385                setForamMeta(cr2);
[422]386
[474]387                if (visualization(cr))
388                {
[476]389                        Populations[2].delete(cr.data->reticulopodiacreature);
[474]390                }
391                Populations[0].delete(cr);
[430]392        }
[380]393}
394
[435]395function stepToNearest(cr)
[380]396{
397        var p = cr.getMechPart(0);
[479]398        var n = cr.signals.receiveSet("nutrient", getZoneRange(cr,2));
[380]399
[401]400        //if signals are received find the source of the nearest
[380]401        if (n.size > 0)
402        {
403                var i;
404                var mp;
405                var distvec = XYZ.new(0, 0, 0);
406                var dist;
[470]407                var mindist = 100000000000.0;
[380]408                var mindistvec = null;
[430]409                var eating = 0;
[380]410
[401]411                for (i = 0; i < n.size; i++)
[380]412                {
[430]413                        mp = n[i].value.getMechPart(0);
[401]414                        distvec.set(mp.pos);
415                        distvec.sub(p.pos);
416                        dist = distvec.length;
[479]417                        if (dist < getZoneRange(cr,1))
[380]418                        {
[430]419                                if (n[i].value != null)
420                                {
421                                        energyTransfer(cr, n[i].value);
422                                        eating = 1;
423                                }
424                        }
[476]425                        else if (eating == 0 && cr.data->lifeparams->hibernated == 0 && dist < mindist)
[430]426                        {
[401]427                                mindist = dist;
428                                mindistvec = distvec.clone();
[380]429                        }
430                }
431
[476]432                if (!eating && cr.data->lifeparams->hibernated == 0)
[430]433                {
434                        mindistvec.normalize();
[474]435                        mindistvec.scale(-1*movePerStep);
[430]436                        cr.localDrive = mindistvec;
437                        moveEnergyDec(cr);
438                }
439
[422]440                return 1;
[380]441        }
[422]442       
443        else
[474]444        {
[422]445                return 0;
[474]446        }
[422]447}
[401]448
[422]449function moveEnergyDec(cr)
450{
[476]451        if (cr.data->lifeparams->hibernated == 0)
[422]452        {
[479]453                //percent of maximal energy
[504]454                cr.energy -= (ExpProperties.energy_move * cr.data->lifeparams->max_energy_level)*ExpProperties.secPerStep;
[422]455        }
[421]456}
[380]457
[493]458function fence(pos, zone)
[487]459{
[496]460        return Math.min(Math.max(0,pos),World.wrldsiz);
[487]461}
462
[422]463function foramMove(cr)
[421]464{
[422]465        //TODO moving inside sediment?
[421]466
[422]467        //adjustment in z axis
[554]468        var change_direction = 0;
469        var new_x = fence(cr.pos_x, getZoneRange(cr, 1));
470        var new_y = fence(cr.pos_y,getZoneRange(cr, 1));
[421]471
[554]472        if ((new_x != cr.pos_x) || (new_y != cr.pos_y) || (cr.data->lifeparams->dir_counter >= int(secToSimSteps(ExpProperties.dir_change_sec))))
473        {
474                change_direction = 1;
475        }
476
477        cr.moveAbs(new_x, new_y, 0);
478
[430]479        //are there any nutrients in zone 1 or 2?
[401]480        {
[435]481                var moved = stepToNearest(cr); //TODO weighted sum of distance and energy
[422]482                if (moved==1)
[430]483                {
[502]484                        moveReticulopodia(cr);
[422]485                        return;
486                }
[401]487        }
488
[422]489        //no nutrients in zone 2
[487]490        if (getGene(cr, "hibernation",0) == 1)
[401]491        {
[430]492                reverseHib(cr);
[422]493                cr.localDrive = XYZ.new(0,0,0);
[380]494        }
[422]495        //random move
[554]496        else if (change_direction == 1)
[380]497        {
[476]498                cr.data->lifeparams->dir = randomDir();
[552]499                cr.data->lifeparams->dir_counter = 0;
[476]500                cr.localDrive = cr.data->lifeparams->dir;
[422]501                moveEnergyDec(cr);
502        }
[474]503        else
504        {
[476]505                cr.localDrive = cr.data->lifeparams->dir;
[474]506        }
[502]507        moveReticulopodia(cr);
[422]508}
[401]509
[502]510function moveReticulopodia(cr)
511{
512        if (visualization(cr))
513        {
514                cr.data->reticulopodiacreature.moveAbs(cr.center_x-getZoneRange(cr,1), cr.center_y-getZoneRange(cr,1), cr.center_z-getZoneRange(cr,1));
515                cr.data->reticulopodiacreature.localDrive = cr.localDrive;
516        }
517}
518
[474]519function randomDir()
520{
[486]521        var dir = (Math.rndUni(-ExpProperties.zone2_range, ExpProperties.zone2_range), Math.rndUni(-ExpProperties.zone2_range, ExpProperties.zone2_range), 0); 
[474]522        dir.normalize();
523        dir.scale(-1*movePerStep);
524        return dir;
525}
526
[430]527function energyTransfer(cr1, cr2)
[422]528{
[430]529        cr1.localDrive = XYZ.new(0,0,0);
[510]530        var e =  ExpProperties.feedtrans*cr1.energy*ExpProperties.secPerStep; //TODO efficiency dependent on age
[502]531        //Simulator.print("transferring "+e +"("+e*ExpProperties.ingestion+")"+" to "+cr1.name +" ("+ cr1.energy+") " +" from "+cr2.uid+" ("+cr2.energy+") "+ e/ExpProperties.secPerStep+ " per sec");
[510]532        var transferred = cr2.transferEnergyTo(cr1, e);
533        cr1.energy -= transferred*(1-ExpProperties.ingestion);
[476]534        if (cr1.data->lifeparams->hibernated == 1)
[422]535        {
[430]536                reverseHib(cr1);
[422]537        }
538}
[401]539
[430]540function reverseHib(cr)
541{
[476]542        if (cr.data->lifeparams->hibernated == 1)
[430]543        {
[479]544                setForamMeta(cr); //unhibernate
[430]545        }
546        else
547        {
[486]548                cr.idleen = (ExpProperties.energy_hib * cr.energy)*ExpProperties.secPerStep; //hibernate
[430]549        }
[476]550        cr.data->lifeparams->hibernated = 1 - cr.data->lifeparams->hibernated;
[430]551}
552
[493]553function createLogVector(cr, value)
554{
555        var vec = Vector.new();
556        for (var i = 0; i < species_genes.size; i++)
557        {
558                for (var j = 0; j < 2; j++)
559                {
560                        vec.add(0);
561                }
562                if (cr.data->lifeparams->species == i)
563                {
564                        vec[i*2+cr.data->lifeparams->gen] = value;             
565                }
566        }
567        return vec;
568}
[479]569
[422]570function onForamsStep(cr)
571{
[479]572        //checking for gametogenesis process
573        if (cr.data->lifeparams->division_time > 0)
[444]574        {
[479]575                cr.data->lifeparams->division_time = Math.max(cr.data->lifeparams->division_time-1,0);
[444]576        }
[479]577        //checking for end of gametogenesis
578        else if (cr.data->lifeparams->division_time == 0)
[422]579        {
[479]580                //waiting for gamets fusion
[422]581        }
[479]582        //checking for chamber growth process
583        else if (cr.data->lifeparams->chamber_growth > 0)
584        {
585                cr.data->lifeparams->chamber_growth = Math.max(cr.data->lifeparams->chamber_growth-1,0);
[486]586                //Simulator.print("chamber growing, time left = " + cr.data->lifeparams->chamber_growth*ExpProperties.secPerStep);
[504]587                cr.energy -= ExpProperties.chamberCostPerSec * cr.energy * ExpProperties.secPerStep;
[422]588
[479]589                //Simulator.print("energy " + cr2.energy + " subtracting " + growth_cost);
590        }
591        //checking for end of chamber growth process
592        else if (cr.data->lifeparams->chamber_growth == 0)
[430]593        {
[479]594                foramGrow(cr, lastChamberNum(cr));
595                cr.data->lifeparams->chamber_growth = -1;
596                //Simulator.print("chamber "+ (lastChamberNum(cr) + 1) +" complete");
[430]597        }
[479]598        else
[422]599        {
[479]600                //update of metabolism rate
601                if (cr.data->lifeparams->hibernated == 0)
[401]602                {
[479]603                        setForamMeta(cr);
604                }
605
606                cr.getMechPart(0).orient.set(o);
607
608                if (deathConditions(cr) == 1)
609                {
[493]610                        if (ExpProperties.logging == 1)
611                        {
612                                log(createLogVector(cr, cr.data->lifeparams->max_energy_level),ExpProperties.logPref+"fossil_log.txt");
[552]613                                log(createLogVector(cr, cr.lifespan),ExpProperties.logPref+"lifespan_log.txt");
[493]614                        }                       
[479]615                        Populations[0].kill(cr);
616                        return;
617                }
618
[552]619                //update direction change counter
620                cr.data->lifeparams->dir_counter += 1;
621
[479]622                foramMove(cr);
623
624                var repro = foramReproduce(cr);
625                if (repro == 1)
626                {
627                        return;
628                }
629
630                cr.data->lifeparams->max_energy_level = Math.max(cr.energy, cr.data->lifeparams->max_energy_level);
631
632                //cheking conditions of chamber growth process start
633                if  (lastChamberNum(cr) != chambers[0].size-1)
634                {
635                        if ((cr.data->lifeparams->max_energy_level >= energyFromVolume(max_chamber_volume[cr.data->lifeparams->gen][lastChamberNum(cr)],0)))   
636                        {
[554]637                                cr.data->lifeparams->chamber_growth = int(secToSimSteps(ExpProperties.chamberGrowthSec));
[479]638                        }       
639                }
[430]640        }       
[380]641}
642
[422]643function deathConditions(cr)
644{
[486]645        if ((cr.energy <= getProperty(cr.data->lifeparams->gen,"e_death_level")*cr.data->lifeparams->max_energy_level) || (Math.rnd01 < ExpProperties.hunted_prob))
[479]646        {
[422]647                return 1;
[479]648        }
[422]649        else
650                return 0;
651}
652
[421]653function onForamsDied(cr)
[380]654{
[444]655        if (visualization(cr))
[430]656        {
[476]657                Populations[2].delete(cr.data->reticulopodiacreature);
[430]658        }
[380]659        //fossilization
660        var geno = GenePools[0].add(cr.genotype);
[476]661        geno.data->genes = cr.data->genes;
662        geno.data->lifeparams = cr.data->lifeparams;
[486]663        if (ExpProperties.logging == 1) Simulator.print("\"" + cr.name + "\" died...");
[380]664        ExpState.totaltestedcr++;
665}
666
[421]667// --------------------------------foram end -------------------------------------
[380]668
[421]669// -------------------------------- nutrient begin --------------------------------
[380]670
[479]671function createNutrientGenotype(nutrientradius)
[422]672{
[524]673        return "//0\nm:Vstyle=nutrient\np:sh=3,sx="+nutrientradius+",sy="+nutrientradius+",sz="+nutrientradius+",ry=1.57,vr=0.0,1.0,0.0";
[422]674}
675
[421]676function onNutrientsStep(cr)
[380]677{
[444]678        cr.moveAbs(cr.pos_x % World.wrldsiz, cr.pos_y % World.wrldsiz, 0.5);
[380]679}
680
[421]681function addNutrient()
[380]682{
[486]683        var cr = Populations[1].add(createNutrientGenotype(ExpProperties.nutrientradius));
[380]684
[421]685        cr.name = "Nutrients";
[380]686        cr.idleen = 0;
[486]687        cr.energy0 = ExpProperties.energy_nut;
[416]688        cr.energy = cr.energy0;
[421]689        cr.signals.add("nutrient");
[380]690
[430]691        cr.signals[0].value = cr;
[380]692
[422]693        placeCreatureRandomly(cr, 0, 0);
[486]694        if (ExpProperties.visualize == 1)
[444]695        {
[486]696                var nutsize = ExpProperties.nutrientradius*10;
[555]697                var nut = Populations[2].add("//0\nm:Vstyle=nutrient_visual\np:sh=2,sx="+nutsize+",sy="+nutsize+",sz="+nutsize+",ry=1.5,vr=0.0,1.0,0.0");
[476]698                cr.data->reticulopodiacreature = nut;
[444]699                nut.moveAbs(cr.pos_x-1.5*nutsize, cr.pos_y-1.5*nutsize, 0.5);
700        }
[380]701}
702
[444]703function onNutrientsDied(cr)
704{
705        if (visualization(cr))
706        {
[476]707                Populations[2].delete(cr.data->reticulopodiacreature);
[444]708        }
709}
710
[422]711function nutrientGrowth()
[380]712{
[486]713        if (ExpProperties.foodPeriodChange > 0)
[481]714        {
715                        changePeriod += 1;
[554]716                        if (phase=="low" && changePeriod >= secToSimSteps(23328000)) //9 months
[481]717                        {
[486]718                                ExpProperties.foodperiod = ExpProperties.foodperiod/ExpProperties.foodPeriodChange;
[481]719                                phase = "high";
720                                changePeriod = 0;
721                        }
722               
[554]723                        else if (phase == "high" && changePeriod >= secToSimSteps(7776000)) //3 months
[481]724                        {
[486]725                                ExpProperties.foodperiod = ExpProperties.foodperiod*ExpProperties.foodPeriodChange;
[481]726                                phase = "low";
727                                changePeriod = 0;
728                        }
729        }
[474]730        nutrientenergywaiting = nutrientenergywaiting + 1;
[554]731        if (nutrientenergywaiting >= secToSimSteps(ExpProperties.foodperiod))
[380]732        {
[493]733                for (var i = 0; i < ExpProperties.nutrient_pop; i++)
[432]734                {   
[422]735                        addNutrient();
736                }
737
738                nutrientenergywaiting = 0.0;
739                Simulator.checkpoint();
[493]740
741                if (ExpProperties.logging == 1)
742                {
743                        log([ExpProperties.nutrient_pop],ExpProperties.logPref+"nutrients_log.txt");
744                }
[380]745        }
[493]746
[380]747}
748
[421]749// -------------------------------- nutrient end --------------------------------
[380]750
[422]751// -------------------------------- step begin --------------------------------
[380]752
[422]753function onStep()
754{
[432]755
756        nutrientGrowth();
[486]757        if (ExpProperties.logging == 1)
[422]758        {
759                createStatistics();
760        }
761
762        //reproduction --------------------------------------------
763        reprocounter += 1;
[554]764        if (reprocounter > secToSimSteps(ExpProperties.reproTimeSec))
[422]765        {
766                reprocounter = 0;
767                reproduce_parents(0);
768                reproduce_parents(1);
769        }
770
771        //check for extinction -----------------------------------------------
772        if (Populations[0].size == 0)
773        {
[486]774                if (ExpProperties.autorestart)
[422]775                {
776                        Simulator.print("no more creatures, restarting...");
777                        onExpInit();
778                }
779                else
780                {
781                        Simulator.print("no more creatures, stopped.");
782                        Simulator.stop();
783                }
784        }
[486]785        if (ExpProperties.maxSteps > 0)
[432]786        {
[486]787                if (Simulator.stepNumber >= ExpProperties.maxSteps)
[432]788                        Simulator.stop();
789        }
[422]790}
791
792function createStatistics()
793{       
[487]794        var number = [];
795        var e_inc = [];
[422]796        var e_nut = 0.0;
797
[487]798        for (var s = 0; s < species_genes.size; s++)
799        {
800                number.add([0,0]);// [haplo][diplo]
801                e_inc.add([0,0]);
802        }
803
[422]804        for (var i = 0; i < Populations[0].size; i++)
805        {
806                var cr = Populations[0].get(i);
[476]807                var gen = cr.data->lifeparams->gen;
808                var species = cr.data->lifeparams->species;
[430]809
810                number[species][gen] = number[species][gen] + 1;
811                e_inc[species][gen] = e_inc[species][gen] + cr.energy;
[422]812        }
813
814        for (var i = 0; i < Populations[1].size; i++)
815        {
816                var cr = Populations[1].get(i);
817                e_nut += cr.energy;
818        }
819
[487]820        var log_numbers = [];
821        var log_energies = [];
[422]822
[487]823        for (var s = 0; s < species_genes.size; s++)
824        {
825                for (var p = 0; p < 2; p++)
826                {
827                        log_numbers.add(number[s][p]);
828                        log_energies.add(e_inc[s][p]);
829                }
830        }
831       
832        log_numbers.add(Populations[1].size);
833        log_energies.add(e_nut);
834
[493]835        log(log_numbers, ExpProperties.logPref+"forams_log.txt");
836    log(log_energies,  ExpProperties.logPref+"energies_log.txt");
[422]837}
838
[380]839function log(tolog, fname)
840{
[430]841        var f = File.appendDirect(fname, "forams data");
[380]842        f.writeString("" + Simulator.stepNumber);
[401]843        for (var  i = 0; i < tolog.size; i++)
[380]844        {
845                f.writeString(";" + tolog[i]);
846        }
847        f.writeString("\n");
848        f.close();
849}
850
[422]851// -------------------------------- step end --------------------------------
[479]852//TODO default params values in frams instead of microns/seconds
[380]853
[401]854@include "standard_events.inc"
[380]855
[401]856~
[380]857
[486]858property:
[444]859id:visualize
860name:Show reticulopodia and nutrients
[430]861type:d 0 1 0
[554]862group:
[430]863
[486]864property:
[434]865id:maxSteps
[554]866name:Maximum number of steps
[552]867type:d 0 10000000 0
[554]868group:
[432]869
[486]870property:
[554]871id:logging
872name:Log statistics to file
873type:d 0 1 0
874group:
875
876property:
[493]877id:logPref
878name:Log prefix
879type:s
880
881property:
[554]882id:secPerStep
883name:Seconds per simulation step
884help:Number of seconds of foraminifera time per simulation step
885type:f 1 480 300
886flags: 16
887group:
888
889property:
[474]890id:foramSpeedMmPerMin
891name:Speed of foraminfera in mm/min
[554]892type:f 0.01 0.1 0.05
[474]893flags: 16
894group:Foraminifera
895
[486]896property:
[554]897id:dir_change_sec
898name:Number of seconds before direction change
899type:d 300 300000 6000
[479]900group:Foraminifera
901
[486]902property:
[554]903id:foramPop
904name:Initial forams population size
905type:d 1 1000 20
[552]906group:Foraminifera
907
908property:
[554]909id:gametoPeriodSec
[479]910name:Time of gametogenesis
[554]911type:f 300 300000 21600
912group:Reproduction
[479]913
[486]914property:
[554]915id:gametSuccessRate
916name:Ratio of successful gamets
917type:f 0.0001 0.01 0.001
918group:Reproduction
[479]919
[486]920property:
[554]921id:divisionCost
922name:Cost of division in pG
923type:f 15 25 20
924group:Reproduction
[474]925
[486]926property:
[554]927id:min_repro_energ_haplo
928name:Min reproduction energy of haploid
929type:f 0 -1 4
930group:Energy
[380]931
[486]932property:
[554]933id:min_repro_energ_diplo
934name:Min reproduction energy of diploid
935type:f 0 -1 6
936group:Energy
[479]937
[486]938property:
[554]939id:repro_prob
940name:Probability of reproduction
941type:f 0 1 0.8
942group:Reproduction
[380]943
[486]944property:
[554]945id:energies0_haplo
946name:Energy of offspring from diploid forams
947type:f 0 -1 20
948group:Energy
[479]949
[486]950property:
[554]951id:energies0_diplo
952name:Energy of offspring from diploid forams
953type:f 0 -1 1.25
954group:Energy
955
956property:
957id:crossprob
958name:Crossover probability
959type:f 0 1 0
960group:Reproduction
961
962property:
963id:mutationprob
964name:Mutation probability
965type:f 0 1 0
966group:Reproduction
967
968property:
969id:reproTimeSec
970name:Time before reproduction
971type:d 0 10000 720
972group:Reproduction
973
974property:
975id:chamberGrowthSec
976name:Time of the chamber growth in seconds
977type:f 360 1440 720
[479]978group:Foraminifera
979
[486]980property:
[422]981id:chamber_proculus_haplo
[423]982name:Size of proculus
[422]983type:f
[421]984group:Foraminifera
[380]985
[486]986property:
[422]987id:chamber_proculus_diplo
[423]988name:Size of proculus
[422]989type:f
[380]990group:Foraminifera
991
[486]992property:
[422]993id:chamber_difference_haplo
[423]994name:Difference in size between subsequent chambers
[554]995type:f 0 -1 0
[380]996group:Foraminifera
997
[486]998property:
[422]999id:chamber_difference_diplo
[423]1000name:Difference in size between subsequent chambers
[554]1001type:f 0 -1 0.08
[380]1002group:Foraminifera
1003
[486]1004property:
[422]1005id:hunted_prob
1006name:Probability of being hunted
1007type:f 0 1 0
[554]1008group:Foraminifera
[380]1009
[486]1010property:
[557]1011id:zone1_range
[556]1012name:Zone 1 range in frams units
[554]1013type:f 0 200 10
[422]1014group:Foraminifera
[380]1015
[486]1016property:
[422]1017id:zone2_range
[556]1018name:Zone 2 range in frams units
[554]1019type:f 0 3000 30
[421]1020group:Foraminifera
[380]1021
[486]1022property:
[554]1023id:chamberCostPerSec
1024name:Cost of growning chamber per second
1025type:f 0 1 0.000001
1026group:Energy
[380]1027
[486]1028property:
[475]1029id:e_death_level_haplo
1030name:Minimal level of energy to sustain life of haploid
[554]1031type:f 0 1 0.5
1032group:Energy
[475]1033
[486]1034property:
[475]1035id:e_death_level_diplo
1036name:Minimal level of energy to sustain life of diploid
[554]1037type:f 0 1 0.5
1038group:Energy
[475]1039
[486]1040property:
[422]1041id:energy_hib
1042name:Energy used for hibernation during one step
[554]1043type:f 0 1 0.0000001
1044group:Energy
[422]1045
[486]1046property:
[422]1047id:energy_move
1048name:Energy used for movement during one step
[554]1049type:f 0 1 0.0000005
1050group:Energy
[422]1051
[486]1052property:
[380]1053id:e_meta
1054name:Idle metabolism
[554]1055type:f 0 1 0.0000005
[380]1056group:Energy
[556]1057help:Foraminifera consumes this proportion of its energy in one time step
[380]1058
[486]1059property:
[554]1060id:ingestion
1061name:Ingestion rate
1062type:f 0 -1 0.25
1063group:Energy
1064
1065property:
[493]1066id:nutrient_pop
[554]1067name:Nutrient population
[474]1068type:f 0 1000000
[380]1069group:Energy
1070help:How fast energy is created in the world
1071
[486]1072property:
[554]1073id:energy_nut
1074name:Nutrient energy
1075type:f 0 10000000
[481]1076group:Energy
1077
[486]1078property:
[554]1079id:nutrientradius
1080name:Nutrient size
1081type:f 0.001 0.9 0.1
[479]1082group:Energy
1083
[486]1084property:
[554]1085id:picoCarbonPerMikro
[556]1086name:Picograms of carbon in cubic micrometer
[554]1087type:f 0 -1 0.13
[380]1088group:Energy
1089
[486]1090property:
[380]1091id:feedtrans
[479]1092name:Energy transfer per second
[554]1093type:f 0 1 0.001
[380]1094group:Energy
[422]1095
[486]1096property:
[479]1097id:foodperiod
1098name:Time between food occurrences
[554]1099type:f 0 1000000 14400
[422]1100group:Energy
1101
[486]1102property:
[554]1103id:foodPeriodChange
1104name:Set variable feed rate
1105type:f 0 -1 0
[421]1106group:Energy
1107
[486]1108property:
[422]1109id:stress
1110name:Environmental stress
1111type:d 0 1 1
[554]1112group:
[422]1113
[486]1114property:
[422]1115id:repro_trigger
1116name:Reproduction trigger
1117type:d 0 1 1
[554]1118group:Reproduction
[422]1119
[486]1120property:
[422]1121id:creath
1122name:Creation height
[554]1123type:f -1 50 -0.99
[422]1124help:~
1125Vertical position (above the surface) where new Forams are revived.
1126Negative values are only used in the water area:
1127  0   = at the surface
1128-0.5 = half depth
1129-1   = just above the bottom~
1130
[554]1131property:
1132id:autorestart
1133name:Restart after extinction
1134help:Restart automatically this experiment after the last creature has died?
1135type:d 0 1 0
1136
[421]1137state:
1138id:nutrient
[428]1139name:Nutrient locations
[421]1140help:vector of vectors [x,y,energy]
1141type:x
1142flags:32
1143
[380]1144state:
1145id:notes
1146name:Notes
1147type:s 1
1148help:~
1149You can write anything here
1150(it will be saved to the experiment file)~
1151
1152state:
1153id:totaltestedcr
[421]1154name:Evaluated Forams
1155help:Total number of the Forams evaluated in the experiment
[380]1156type:d
1157flags:16
Note: See TracBrowser for help on using the repository browser.