Index: /experiments/frams/foraminifera/data/scripts/foraminifera.expdef
===================================================================
--- /experiments/frams/foraminifera/data/scripts/foraminifera.expdef	(revision 566)
+++ /experiments/frams/foraminifera/data/scripts/foraminifera.expdef	(revision 567)
@@ -23,5 +23,4 @@
 code:~
 
-global chambers;
 global colors;
 global retColors;
@@ -30,10 +29,13 @@
 global movePerStep;
 global nutrientenergywaiting;
-global o;
 global reprocounter;
 global changePeriod;
 global phase;
 global nutrientSqrCm;
-global species_genes; 
+global species_genes;
+global max_chambers_def;
+global foram_uid; //introduced because each replacement of a creature (while growing) would generate a new Creature.uid
+global chamber_vis_denominator;
+global curRadius;
 
 @include "foraminifera.inc"
@@ -96,21 +98,12 @@
 
 	//morphology
-	init_chambers();
-	curColor = retColors[0];
 	ExpProperties.zone1_range = micronsToFrams(1000);
 	ExpProperties.zone2_range = micronsToFrams(3000);
-	ExpProperties.chamber_proculus_haplo = micronsToFrams(50);
-	ExpProperties.chamber_difference_haplo = 0.0;
-	ExpProperties.chamber_proculus_diplo = micronsToFrams(20);
-	ExpProperties.chamber_difference_diplo = micronsToFrams(8);
-
-	max_chamber_volume = [Vector.new(), Vector.new()];
-	for (var j = 0; j < 2; j++)
-	{
-		for (var i = 0; i < chambers[0].size; i++)
-		{
-			max_chamber_volume[j].add(((volumeInMicrons(getProperty(j, "chamber_proculus")) + volumeInMicrons(getProperty(j, "chamber_proculus") + (i) * getProperty(j, "chamber_difference")))*(i+1))/2);	
-		}                                  
-	}
+	ExpProperties.chamber_proculus_haplo = micronsToFrams(20);
+	ExpProperties.chamber_proculus_diplo = micronsToFrams(10);
+	colors = ["1.0,1.0,0.0","1.0,0.5,0.0"];
+	retColors = ["1.0,1.0,1.0", "1.0,1.0,0.0"];
+	curColor = retColors[0];
+	curRadius = ExpProperties.zone1_range;
 
 	//nutrients
@@ -122,5 +115,7 @@
 	ExpState.totaltestedcr = 0;
 	ExpState.nutrient = "";
-	
+
+	max_chambers_def = 35;
+	chamber_vis_denominator = 6;
 	//addSpecies({"min_repro_energies" : [4,6]});
 	//addSpecies({"min_repro_energies" : [4,8]});
@@ -132,100 +127,32 @@
 @include "standard_placement.inc"
 
-function secToSimSteps(value_in_sec){
-	return value_in_sec/ExpProperties.secPerStep;
-}
-
-function volumeInMicrons(radiusInFrams)
-{
-	return 4.0/3.0*Math.pi*Math.pow(framsToMicrons(radiusInFrams),3);
-}
-
-function energyFromVolume(base, isRadiusInFrams)
-{
-	if (isRadiusInFrams == 1) //radius in frams
-	{
-		return ExpProperties.picoCarbonPerMikro*volumeInMicrons(base);
-	}
-	else //volume in microns
-	{
-		return ExpProperties.picoCarbonPerMikro * base;
-	}
-}
-
-function getMovePerStep()
-{
-	return micronsToFrams((ExpProperties.foramSpeedMmPerMin/60)*1000)*ExpProperties.secPerStep;
-}
-
-function micronsToFrams(micrometers)
-{
-	return micrometers*0.01;
-}
-
-function framsToMicrons(framsworldunits)
-{
-	return framsworldunits/0.01;
-}
-
-function getProperty(gen, prop_id)
-{
-	var ploid = "haplo";
-	if (gen == 1) ploid = "diplo";
-	return ExpProperties.[prop_id + "_" + ploid];
-}
-
-function getGene(cr, gen_id, gen_set)
-{
-	if (cr.data->lifeparams->gen == 0) 
-		return cr.data->genes[gen_id];
-	else 
-		return cr.data->genes[gen_set][gen_id];
-}
-
-function addForam(species, iter, chambernum, ploid)
-{
-	var geno = createForamMorphology(ploid, ploid, chambernum);
-	curColor = retColors[ploid];
-	var cr = Populations[0].add(geno);
-	cr.name = "Initial creature" + species + "_" + iter;
-	placeCreatureRandomly(cr, 0, 0);
-	cr.energy0 = energyFromVolume(max_chamber_volume[ploid][chambernum],0);
-	cr.energy = cr.energy0;
-	setGenotype({"opt" : "birth", "cr" : cr, "gen" : ploid, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]});
-	if (ploid == 1)
-	{
-		cr.data->genes = [cr.data->genes, cr.data->genes]; //TODO two different genes sets
-	}
-	moveReticulopodia(cr);
-}
-
-function addInitialForam(species, iter)
-{
-	var ploid = 0;
-	if (Math.rnd01 > 0.5)
-	{
-		ploid = 1;
-	}	
-	//add new foram with random energy bewtween starting energy and reproduction threshold
-	addForam(species, iter, int(Math.rndUni(0,species_genes[species]->min_repro_energies[ploid])),ploid);
-}
-
-//new species can be added as a dictionary with parameter values that are different than default values
-function addSpecies(new_genes)
-{
-	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});
-	for (var i = 0; i < new_genes.size; i++)
-	{
-		var key = new_genes.getKey(i);
-		species_genes[species_genes.size-1][key] = new_genes[key];
-	} 
-}
-
 function onExpInit()
 {
+	foram_uid = 0;
+
 	Populations[0].clear();
 	Populations[1].clear();
 	Populations[2].clear(); //reticulopodia and nutrients
 
+	if (ExpProperties.max_chamber_num_haplo == max_chambers_def && ExpProperties.max_chamber_num_diplo == max_chambers_def)
+	{
+		max_chamber_volume = [[30403.5869594578,52812.2546633948,79578.5148482541,113588.815134453,154620.677376218,205094.322220826,262572.712174265,326078.453295303,402342.518962956,498133.985678766,615066.864740109,759500.497626816,937064.025544282,1155915.25563075,1429139.14079748,1762487.92940157,2176286.62046069,2685795.63187845,3316190.12127043,4096436.04462706,5051343.25226193,6231980.1061213,7687880.79524734,9485307.02904958,11716968.9852569,14459866.4934433,17836388.9853663,22004935.7247348,27138607.2546045,33482425.1582986,41336775.1280297,50997910.7842793,62888631.7871037,77563060.9243464,95659468.591964]
+, [3430.07716920763,6159.93090353532,9322.94192815286,13462.9896597283,18399.8550832969,24558.9218126892,31468.8148639192,39189.4977865513,48404.4292075836,60185.8639086061,74490.6048472854,92117.8178412275,113852.779747083,140714.366929552,174450.937643841,215250.242147183,266323.295274072,328858.042352538,406552.379957238,503526.321155323,621060.781025019,767240.824049468,947210.683224091,1169506.19906112,1447211.61255879,1787155.29073739,2205627.64766244,2723413.2837305,3360233.53738709,4147771.02835393,5126445.06973928,6328060.3331703,7805693.278958,9631924.72156452,11884287.1596814]];
+	}
+
+	else
+	{
+		max_chamber_volume = [Vector.new(), Vector.new()];
+		var density = 100;
+		for (var ploid = 0; ploid < 2; ploid++) 
+		{
+			var rad = getPloidRadius(ploid);
+			for (var cham_num = 0; cham_num < getProperty(ploid,"max_chamber_num"); cham_num++)
+			{
+				max_chamber_volume[ploid].add(volumeFromGeno(ploid, rad, cham_num+1, density));
+			}                                  
+		}
+	}
+
 	if (species_genes.size == 0)
 	{
@@ -240,5 +167,4 @@
 		}
 	}
-	o = Populations[0][0].getMechPart(0).orient.clone();
 	ExpState.totaltestedcr = 0;
 
@@ -312,4 +238,133 @@
 // -------------------------------- experiment end --------------------------------
 
+function volumeFromGeno(morphotype, rad, chamber_num, density)
+{
+	var geno = create_genotype(rad, chamber_num, colors[morphotype], 1);
+	var m=Model.newFromString(geno);
+	var mg=ModelGeometry.forModel(m);
+	mg.geom_density=density; 
+	var volumeInFrams = mg.volume();
+
+	return volumeInFrams/Math.pow(ExpProperties.scalingFactor,3);
+}
+
+function secToSimSteps(value_in_sec){
+	return value_in_sec/ExpProperties.secPerStep;
+}
+
+function volumeInMicrons(radiusInFrams)
+{
+	return 4.0/3.0*Math.pi*Math.pow(framsToMicrons(radiusInFrams),3);
+}
+
+function energyFromVolume(base, isRadiusInFrams)
+{
+	if (isRadiusInFrams == 1) //radius in frams
+	{
+		return ExpProperties.picoCarbonPerMikro*volumeInMicrons(base);
+	}
+	else //volume in microns
+	{
+		return ExpProperties.picoCarbonPerMikro * base;
+	}
+}
+
+function getMovePerStep()
+{
+	return micronsToFrams((ExpProperties.foramSpeedMmPerMin/60)*1000)*ExpProperties.secPerStep;
+}
+
+function micronsToFrams(micrometers)
+{
+	return micrometers*ExpProperties.scalingFactor;
+}
+
+function framsToMicrons(framsworldunits)
+{
+	return framsworldunits/ExpProperties.scalingFactor;
+}
+
+function getProperty(gen, prop_id)
+{
+	var ploid = "haplo";
+	if (gen == 1) ploid = "diplo";
+	return ExpProperties.[prop_id + "_" + ploid];
+}
+
+function getGene(cr, gen_id, gen_set)
+{
+	if (cr.data->lifeparams->gen == 0) 
+		return cr.data->genes[gen_id];
+	else 
+		return cr.data->genes[gen_set][gen_id];
+}
+
+function getPloidRadius(ploid)
+{
+	var radius = ExpProperties.chamber_proculus_haplo;
+		if (ploid == 1)
+		{
+			radius = ExpProperties.chamber_proculus_diplo;
+		}
+	return radius;
+}
+
+function chamberNumFromEnergy(energy, ploid)
+{
+	var chamber_num = max_chamber_volume[ploid].size;
+	for (var i = 0; i < chamber_num; i++)
+	{
+		if (energy < energyFromVolume(max_chamber_volume[ploid][i],0))
+		{
+			chamber_num = i+1;
+			break;
+		}	
+	}                                  
+	
+	return chamber_num;
+}
+
+function addForam(species, iter, start_energy, ploid)
+{
+	var chambernum =  chamberNumFromEnergy(start_energy, ploid);
+	var radius = getPloidRadius(ploid);
+	var geno = create_genotype(radius, chambernum, colors[ploid], 1);
+	curColor = retColors[ploid];
+	var cr = Populations[0].add(geno);
+	cr.name = "Initial creature" + species + "_" + iter;
+	placeCreatureRandomly(cr, 0, 0);
+	cr.energy = start_energy;
+	setGenotype({"opt" : "birth", "cr" : cr, "gen" : ploid, "species" : species, "energy0" : cr.energy, "genes" : species_genes[species], "parentsuids" : ["c0"]});
+	if (ploid == 1)
+	{
+		cr.data->genes = [cr.data->genes, cr.data->genes]; //TODO two different genes sets
+	}
+	moveReticulopodia(cr);
+}
+
+function addInitialForam(species, iter)
+{
+	var ploid = 0;
+	if (Math.rnd01 > 0.5)
+	{
+		ploid = 1;
+	}	
+	//add new foram with random energy bewtween starting energy and reproduction threshold
+	var repro_thr = species_genes[species]->min_repro_energies[ploid];
+	var start_energy = Math.rndUni(energyFromVolume(getPloidRadius(ploid),1),repro_thr-0.25*repro_thr);
+	addForam(species, iter, start_energy,ploid);
+}
+
+//new species can be added as a dictionary with parameter values that are different than default values
+function addSpecies(new_genes)
+{
+	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});
+	for (var i = 0; i < new_genes.size; i++)
+	{
+		var key = new_genes.getKey(i);
+		species_genes[species_genes.size-1][key] = new_genes[key];
+	} 
+}
+
 // -------------------------------- foram begin -----------------------------------
 
@@ -322,5 +377,5 @@
 function lastChamberNum(cr)
 {
-	return cr.numparts-1;
+	return cr.numparts;
 }
 
@@ -328,4 +383,16 @@
 {
 	return ExpProperties.["zone"+zone_num+"_range"];
+}
+
+function addReticulopodia(cr, radius)
+{
+		if (reticulopodiaExists(cr))
+		{
+			Populations[2].delete(cr.data->reticulopodiacreature);
+		}
+		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="+radius+",sz="+radius+",ry=1.57079633,vr="+curColor+"\nj:0, 1, sh=1");
+		cr.data->reticulopodiacreature = ret;
+		ret.getMechPart(0).orient.set(cr.getMechPart(0).orient);
+		ret.moveAbs(cr.center_x-radius, cr.center_y-radius, cr.center_z-radius);
 }
 
@@ -335,9 +402,7 @@
 	if (ExpProperties.visualize == 1)
 	{
-		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");
-		cr.data->reticulopodiacreature = ret;
-		ret.getMechPart(0).orient.set(cr.getMechPart(0).orient);
-		ret.moveAbs(cr.center_x-getZoneRange(cr,1), cr.center_y-getZoneRange(cr,1), cr.center_z-getZoneRange(cr,1));
-	}
+		addReticulopodia(cr, curRadius);
+	}
+	moveReticulopodia(cr);
 }
 
@@ -355,25 +420,31 @@
 }
 
+function reticulopodiaExists(cr)
+{
+	var has_ret = 0;
+
+	if (cr.data->reticulopodiacreature != null)
+	{
+		if (Populations[2].findUID(cr.data->reticulopodiacreature.uid) != null)
+		{
+			has_ret = 1;
+		}
+	}
+
+	return has_ret;
+}
+
 function visualization(cr)
 {
-	var has_ret = 0;
-
-	if (cr.data->reticulopodiacreature != null)
-	{
-		if (Populations[2].findUID(cr.data->reticulopodiacreature.uid) != null)
-		{
-			has_ret = 1;
-		}
-	}
-
-	return has_ret;
-}
-
-function foramGrow(cr, chamber_num)
-{
-	if ((chamber_num+1) < chambers[cr.data->lifeparams->species].size)
+	return reticulopodiaExists(cr);
+}
+
+function foramGrow(cr, chamber_num, lastchambergrowth)
+{
+	if ((chamber_num+1) <= max_chamber_volume[cr.data->lifeparams->gen].size)
 	{
 		curColor = retColors[cr.data->lifeparams->gen];
-		var geno = createForamMorphology(cr.data->lifeparams->gen, cr.data->lifeparams->gen, chamber_num+1);
+		var ploid = cr.data->lifeparams->gen;
+		var geno = create_genotype(getPloidRadius(ploid), chamber_num+1, colors[ploid], lastchambergrowth);
 		var cr2 = Populations[0].add(geno);
 
@@ -382,13 +453,15 @@
 
 		setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : "growth", "energy0" : cr.energy0});
-		cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
+		cr2.moveAbs(cr.pos_x, cr.pos_y,cr.pos_z);
 		setForamMeta(cr2);
 
-		if (visualization(cr))
+		if (reticulopodiaExists(cr))
 		{
 			Populations[2].delete(cr.data->reticulopodiacreature);
 		}
 		Populations[0].delete(cr);
-	}
+		return cr2;
+	}
+	return cr;
 }
 
@@ -551,21 +624,4 @@
 }
 
-function createLogVector(cr, value)
-{
-	var vec = Vector.new();
-	for (var i = 0; i < species_genes.size; i++)
-	{
-		for (var j = 0; j < 2; j++)
-		{
-			vec.add(0);
-		}
-		if (cr.data->lifeparams->species == i)
-		{
-			vec[i*2+cr.data->lifeparams->gen] = value;		
-		}
-	}
-	return vec;
-}
-
 function onForamsStep(cr)
 {
@@ -583,14 +639,46 @@
 	else if (cr.data->lifeparams->chamber_growth > 0)
 	{
-		cr.data->lifeparams->chamber_growth = Math.max(cr.data->lifeparams->chamber_growth-1,0);
-		//Simulator.print("chamber growing, time left = " + cr.data->lifeparams->chamber_growth*ExpProperties.secPerStep);
+		var chamber_time = Math.max(cr.data->lifeparams->chamber_growth-1,0);
+		cr.data->lifeparams->chamber_growth = chamber_time;
 		cr.energy -= ExpProperties.chamberCostPerSec * cr.energy * ExpProperties.secPerStep;
 
-	 	//Simulator.print("energy " + cr2.energy + " subtracting " + growth_cost);
+		if (visualization(cr))
+		{
+			var total_time = secToSimSteps(ExpProperties.chamberGrowthSec);
+			var ret_unit = total_time/chamber_vis_denominator;
+			var chamber_unit = total_time-ret_unit;
+
+			if (chamber_time < ret_unit || chamber_time >= chamber_unit)
+			{
+				var new_rad = Math.min(Math.max((chamber_time%ret_unit)/ret_unit*getZoneRange(cr,1),0.01),getZoneRange(cr,1));
+
+				if(chamber_time < ret_unit)
+					new_rad = getZoneRange(cr,1)-new_rad;
+
+				addReticulopodia(cr,new_rad);
+			}
+			else
+			{
+				var new_rad = 1 - Math.min(Math.max((chamber_time-ret_unit)/chamber_unit,0.01),1);
+				curRadius = cr.data->reticulopodiacreature.getPart(1).sy;
+				
+				if (chamber_time == ret_unit){
+					new_rad == 1;
+				}
+	
+				var new_cr = foramGrow(cr, chamberNumFromEnergy(cr.data->lifeparams->max_energy_level, cr.data->lifeparams->gen)-1, new_rad);
+				curRadius = getZoneRange(new_cr,1);
+
+				if (chamber_time == 0)//checking for end of chamber growth process
+				{
+					new_cr.data->lifeparams->chamber_growth = -1;	
+				}
+			} 
+		}
 	}
 	//checking for end of chamber growth process
-	else if (cr.data->lifeparams->chamber_growth == 0)
-	{
-		foramGrow(cr, lastChamberNum(cr)); 
+	else if (cr.data->lifeparams->chamber_growth == 0 && visualization(cr)==0)
+	{	
+		foramGrow(cr, lastChamberNum(cr), 1); 
 		cr.data->lifeparams->chamber_growth = -1;
 		//Simulator.print("chamber "+ (lastChamberNum(cr) + 1) +" complete");
@@ -603,6 +691,4 @@
 			setForamMeta(cr);
 		}
-
-		cr.getMechPart(0).orient.set(o);
 
 		if (deathConditions(cr) == 1)
@@ -631,7 +717,7 @@
 
 		//cheking conditions of chamber growth process start
-		if  (lastChamberNum(cr) != chambers[0].size-1)
-		{
-			if ((cr.data->lifeparams->max_energy_level >= energyFromVolume(max_chamber_volume[cr.data->lifeparams->gen][lastChamberNum(cr)],0))) 	
+		if  (lastChamberNum(cr) < max_chamber_volume[cr.data->lifeparams->gen].size)
+		{
+			if ((cr.data->lifeparams->max_energy_level >= energyFromVolume(max_chamber_volume[cr.data->lifeparams->gen][lastChamberNum(cr)-1],0))) 	
 			{
 				cr.data->lifeparams->chamber_growth = int(secToSimSteps(ExpProperties.chamberGrowthSec));
@@ -765,6 +851,9 @@
 	{
 		reprocounter = 0;
-		reproduce_parents(0);
-		reproduce_parents(1);
+		for (var s = 0; s < species_genes.size; s++)
+		{
+			reproduce_parents(s);
+		}
+		
 	}
 
@@ -849,4 +938,22 @@
 }
 
+function createLogVector(cr, value)
+{
+	var vec = Vector.new();
+	for (var i = 0; i < species_genes.size; i++)
+	{
+		for (var j = 0; j < 2; j++)
+		{
+			vec.add(0);
+		}
+		if (cr.data->lifeparams->species == i)
+		{
+			vec[i*2+cr.data->lifeparams->gen] = value;		
+		}
+	}
+	return vec;
+}
+
+
 // -------------------------------- step end --------------------------------
 //TODO default params values in frams instead of microns/seconds
@@ -866,4 +973,10 @@
 name:Maximum number of steps
 type:d 0 10000000 0
+group:
+
+property:
+id:scalingFactor
+name:Scaling factor for micrometers
+type:f 0 -1 0.01
 group:
 
@@ -926,12 +1039,12 @@
 property:
 id:min_repro_energ_haplo
-name:Min reproduction energy of haploid
-type:f 0 -1 4
+name:Min reproduction energy of haploid in pg
+type:f 0 -1 350000
 group:Energy
 
 property:
 id:min_repro_energ_diplo
-name:Min reproduction energy of diploid
-type:f 0 -1 6
+name:Min reproduction energy of diploid in pg
+type:f 0 -1 600000
 group:Energy
 
@@ -955,4 +1068,17 @@
 
 property:
+id:max_chamber_num_haplo
+name:Maximum number of haploid chambers
+type:f 1 50 35
+group:Energy
+
+property:
+id:max_chamber_num_diplo
+name:Maximum number of diploid chambers
+type:f 1 50 35
+group:Energy
+
+
+property:
 id:crossprob
 name:Crossover probability
@@ -975,5 +1101,5 @@
 id:chamberGrowthSec
 name:Time of the chamber growth in seconds
-type:f 360 1440 720
+type:f 720 43200 43200
 group:Foraminifera
 
@@ -988,16 +1114,4 @@
 name:Size of proculus
 type:f
-group:Foraminifera
-
-property:
-id:chamber_difference_haplo
-name:Difference in size between subsequent chambers
-type:f 0 -1 0
-group:Foraminifera
-
-property:
-id:chamber_difference_diplo
-name:Difference in size between subsequent chambers
-type:f 0 -1 0.08
 group:Foraminifera
 
Index: /experiments/frams/foraminifera/data/scripts/foraminifera.inc
===================================================================
--- /experiments/frams/foraminifera/data/scripts/foraminifera.inc	(revision 566)
+++ /experiments/frams/foraminifera/data/scripts/foraminifera.inc	(revision 567)
@@ -17,55 +17,10 @@
 			size=size*(1.35-0.35*lastchambergrowth); //last iteration: 'size' is only used for shifting (dx). The last chamber emerges at the surface of the previous one
 		}
-		str+="p:sh=1,sx=%g,sy=%g,sz=%g,vr=%s\n" % effectivesize % effectivesize % effectivesize % rgbstring;
+		str += "p:sh=1,sx=%g,sy=%g,sz=%g,rz=3.14159265358979,vr=%s\n" % effectivesize % effectivesize % effectivesize % rgbstring;
 		if (i>0)
-			str+="j:%d,%d,sh=1,dx=%g,ry=%g\n" % (i-1) % i % (size*shift) % (angle_delta+i*angle_delta_delta);
+			str+="j:%d,%d,sh=1,dx=%g,rz=%g\n" % (i-1) % i % (size*shift) % (angle_delta+i*angle_delta_delta);
 		size*=growing;
 	}
 	return str;
-}
-
-function init_chambers()
-{
-	colors = ["1.0,1.0,0.0","1.0,0.5,0.0"];
-	retColors = ["1.0,1.0,1.0", "1.0,1.0,0.0"];
-	chambers = [ ["p:sh=1, sx=0.2, sy=0.2, sz=0.2, rz=3.14159265358979,",
-"p:0.18421219587326, 0.13, sh=1, sx=0.21, sy=0.21, sz=0.21,",
-"p:0.323935478925705, 0.195192575454712, -0.0246672090142965, sh=1, sx=0.2205, sy=0.2205, sz=0.2205,",
-"p:0.467822402715683, 0.258204102516174, -0.0246672090142965, sh=1, sx=0.231525, sy=0.231525, sz=0.231525,",
-"p:0.664101362228394, 0.309014827013016, -0.0246672090142965, sh=1, sx=0.24310125, sy=0.24310125, sz=0.24310125,",
-"p:0.860512733459473, 0.274790525436401, -0.0246672090142965, sh=1, sx=0.2552563125, sy=0.2552563125, sz=0.2552563125,",
-"p:1.0273220539093, 0.1655353307724, -0.0246672090142965, sh=1, sx=0.268019128125, sy=0.268019128125, sz=0.268019128125,",
-"p:1.13825333118439, -0.000509921927005053, -0.0246672090142965, sh=1, sx=0.28142008453125, sy=0.28142008453125, sz=0.28142008453125,",
-"p:1.17569863796234, -0.196833491325378, -0.0246672090142965, sh=1, sx=0.295491088757813, sy=0.295491088757813, sz=0.295491088757813,",
-"p:1.13369226455688, -0.392314255237579, -0.0246672090142965, sh=1, sx=0.310265643195703, sy=0.310265643195703, sz=0.310265643195703,"],
-        ["p:sh=1, sx=0.1, sy=0.1, sz=0.1, rz=3.14159265358979,",
-"p:0.110527315735817, -0.0167302016913891, sh=1, sx=0.105, sy=0.105, sz=0.105, rx=3.63519277003091e-33,",
-"p:0.207026958465576, -0.080698736011982, 1.17627548103266e-17, sh=1, sx=0.11025, sy=0.11025, sz=0.11025,",
-"p:0.271191358566284, -0.169948443770409, 1.17627548103266e-17, sh=1, sx=0.1157625, sy=0.1157625, sz=0.1157625,",
-"p:0.291628688573837, -0.286643952131271, 1.17627548103266e-17, sh=1, sx=0.121550625, sy=0.121550625, sz=0.121550625,",
-"p:0.264833927154541, -0.403534322977066, 1.17627548103266e-17, sh=1, sx=0.12762815625, sy=0.12762815625, sz=0.12762815625,",
-"p:0.194418027997017, -0.500668346881866, 1.17627548103266e-17, sh=1, sx=0.1340095640625, sy=0.1340095640625, sz=0.1340095640625,",
-"p:0.091719962656498, -0.562735974788666, 1.17627548103266e-17, sh=1, sx=0.140710042265625, sy=0.140710042265625, sz=0.140710042265625,",
-"p:-0.0270438715815544, -0.57991486787796, 1.17627548103266e-17, sh=1, sx=0.147745544378906, sy=0.147745544378906, sz=0.147745544378906,",
-"p:-0.143122747540474, -0.549489378929138, 1.17627548103266e-17, sh=1, sx=0.155132821597852, sy=0.155132821597852, sz=0.155132821597852,"]];
-}
-
-function createForamMorphology(morphotype, gen, chamber_num)
-{
-	var geno = "//0\nm:Vstyle=foram\n" + chambers[morphotype][0] + "vr=" + colors[gen];
-
-	chamber_num = Math.min(chamber_num, chambers[morphotype].size - 1);
-
-	for (var i = 0; i < chamber_num; i++)
-	{
-		geno += "\n" + chambers[morphotype][i+1]  + "vr=" +  colors[gen];
-	}
-
-	for (var i = 0; i < chamber_num; i++)
-	{
-		geno += "\n" +  "j:"+ i +", "+ (i+1) +", sh=1";
-	}
-
-	return geno;
 }
 
@@ -80,8 +35,23 @@
 	else if (mode->opt == "birth")
 	{
+		foram_uid += 1;
+		var new_id = "c"+string(foram_uid);
 		mode->cr.data->genes = String.deserialize(String.serialize(mode->genes));
-		mode->cr.data->lifeparams = {"max_energy_level" : mode->energy0, "gen" : mode->gen,  "hibernated" : 0, "species" : mode->species, "reproduce" : 0, "dir" : randomDir(), "dir_counter" : Math.random(int(secToSimSteps(ExpProperties.dir_change_sec))), "chamber_growth" : -1, "division_time" : -1};			
-
-	}
+		mode->cr.data->lifeparams = {"max_energy_level" : mode->energy0, "gen" : mode->gen,  "hibernated" : 0, "species" : mode->species, "reproduce" : 0, "dir" : randomDir(), "dir_counter" : Math.random(int(secToSimSteps(ExpProperties.dir_change_sec))), "chamber_growth" : -1, "division_time" : -1, "uid" : new_id};	
+
+		var oper = "cloning";
+		if (mode->parentsuids.size > 1)
+		{	
+			oper = "cross-over";
+		}
+		
+		var dict={"Time":Simulator.stepNumber,"FromIDs":mode->parentsuids,"ID":new_id, "Inherited":[1.0], "Operation": oper, "Kind" : mode->gen};
+		Simulator.print("[OFFSPRING] " + String.serialize(dict));		
+	}
+}
+
+function getEnergy0(radius)
+{
+	return energyFromVolume(micronsToFrams(radius),1);
 }
 
@@ -93,13 +63,8 @@
 	{
 		result = (result-ExpProperties.divisionCost)/2;
-		number *= 2; 
+		number *= 2;
 	}
 	//Simulator.print("parent: " + parent_energy + " result: " + result + " number " + number);
 	return {"energy" : result, "number" : number};
-}
-
-function getEnergy0(radius)
-{
-	return energyFromVolume(micronsToFrams(radius),1);
 }
 
@@ -135,9 +100,9 @@
 	}
 
-	Simulator.print("haploid number of offspring: " + number + " energ0: " + energy0);
+	//Simulator.print("haploid number of offspring: " + number + " energ0: " + energy0);
 
 	for (var j = 0; j < number; j++)
 	{
-		createOffspring(createForamMorphology(gen, gen, 0), energy0, new_genes, parent.data->lifeparams); 
+		createOffspring(create_genotype(ExpProperties.chamber_proculus_diplo, 1, colors[1], 1), energy0, new_genes, parent.data->lifeparams, [parent.data->lifeparams->uid, parent2.data->lifeparams->uid]);
 	}
 }
@@ -156,5 +121,5 @@
 		}	
 
-	Simulator.print("diploid number of offspring: " + number+ " energ0: " + energy0);
+	//Simulator.print("diploid number of offspring: " + number+ " energ0: " + energy0);
 
 	for (var j = 0; j < number / 2; j++)
@@ -170,5 +135,5 @@
 		for (var k = 0; k < 2; k++)
 		{
-			createOffspring(createForamMorphology(1 - parent.data->lifeparams->gen, 1 - parent.data->lifeparams->gen, 0), energy0, parent.data->genes[0], parent.data->lifeparams); 
+			createOffspring(create_genotype(ExpProperties.chamber_proculus_haplo, 1, colors[0], 1), energy0, parent.data->genes[0], parent.data->lifeparams, [parent.data->lifeparams->uid]); 
 		}
 
@@ -220,6 +185,6 @@
 					{
 						reproduce_haploid(parent1, parent2, 0);
-						print_repro_info(parent1);
-						print_repro_info(parent2);
+						//print_repro_info(parent1);
+						//print_repro_info(parent2);
 						pop.kill(parent1);
 						pop.kill(parent2);
@@ -235,6 +200,5 @@
 {
 	var reproduced = 1;
-	
-	
+
 	if (cr.data->lifeparams->gen == 1)
 	{
@@ -260,5 +224,5 @@
 	if (reproduced == 1)
 	{
-		print_repro_info(cr);
+		//print_repro_info(cr);
 		Populations[0].kill(cr);
 	}
@@ -267,12 +231,7 @@
 }
 
-function print_repro_info(cr)
-{
-	Simulator.print("Reproduced " + cr.data->lifeparams->gen + " of species " + cr.data->lifeparams->species + " energy: " + cr.energy);
-}
-
 function foramReproduce(cr)
 {
-	var properEnergy = cr.energy >= energyFromVolume(max_chamber_volume[cr.data->lifeparams->gen][getGene(cr, "min_repro_energies",0)[cr.data->lifeparams->gen]],0);
+	var properEnergy = cr.energy >= getGene(cr, "min_repro_energies",0)[cr.data->lifeparams->gen];
 	var reproduced = 0;	
 
@@ -309,5 +268,5 @@
 }
 
-function createOffspring(geno, energy, parent_genes, parent_lifeparams)
+function createOffspring(geno, energy, parent_genes, parent_lifeparams, parentsuids)
 {
 	curColor = retColors[1-parent_lifeparams->gen];
@@ -315,5 +274,10 @@
 	cr.energy0 = energy;
 	cr.energy = cr.energy0;
-	setGenotype({"opt" : "birth", "cr" : cr, "gen" : 1 - parent_lifeparams->gen, "species" : parent_lifeparams->species, "energy0" : cr.energy0, "genes" : parent_genes});
+	setGenotype({"opt" : "birth", "cr" : cr, "gen" : 1 - parent_lifeparams->gen, "species" : parent_lifeparams->species, "energy0" : cr.energy0, "genes" : parent_genes, "parentsuids" : parentsuids});
 	placeRandomlyNotColliding(cr);
 }
+
+function print_repro_info(cr)
+{
+	Simulator.print("Reproduced " + cr.data->lifeparams->gen + " of species " + cr.data->lifeparams->species + " energy: " + cr.energy);
+}
Index: /experiments/frams/foraminifera/data/scripts/foraminifera.show
===================================================================
--- /experiments/frams/foraminifera/data/scripts/foraminifera.show	(revision 566)
+++ /experiments/frams/foraminifera/data/scripts/foraminifera.show	(revision 567)
@@ -18,4 +18,6 @@
 function onLoad()
 {
+	Params = { "foodperiod" : [43200,25920,10800], "feedtrans" : [0.0005,0.001,0.002],"energy_nut" :[144.54,544.54,944.54], "stress" : [0,1], "visualize" : [0,1]};
+	ShowProperties.visualize=1;
 	Simulator.init();
 	last_simspeed=0;
@@ -23,6 +25,4 @@
 	GLDisplay.minfps = 10;
 	TrackingCam.cam_h = 15; //more side view
-	Params = { "foodperiod" : [43200,25920,10800], "feedtrans" : [0.0005,0.001,0.002],"energy_nut" :[144.54,544.54,944.54], "stress" : [0,1], "visualize" : [0,1]};
-	ShowProperties.visualize=1;
 	
 	//useful for screenshots:
