Template:Team:Paris Saclay/simbox

From 2013.igem.org

(Difference between revisions)
Line 28: Line 28:
  this.outputs= new Array();
  this.outputs= new Array();
  this.probability= 0.0;
  this.probability= 0.0;
 +
this.precomp_probfactor= 0.0;
 +
this.precomp_molusage= new Array();
}
}
Line 124: Line 126:
   if(reaction_tags[i].hasAttribute('probability'))
   if(reaction_tags[i].hasAttribute('probability'))
   simulations[id].reactions[i].probability= parseFloat(reaction_tags[i].getAttribute('probability'));
   simulations[id].reactions[i].probability= parseFloat(reaction_tags[i].getAttribute('probability'));
 +
 +
  //precomputing
 +
  simulations[id].reactions[i].precomp_probfactor= simulations[id].reactions[i].probability;
    
    
   var input_tags= reaction_tags[i].getElementsByTagName("in");
   var input_tags= reaction_tags[i].getElementsByTagName("in");
Line 135: Line 140:
     }
     }
     simulations[id].reactions[i].inputs[j]= tmpid;
     simulations[id].reactions[i].inputs[j]= tmpid;
 +
 +
    //precomputing
 +
    simulations[id].reactions[i].precomp_probfactor *= simulations[id].reactions[i].probability/simulations[id].volume;
 +
    if(!simulations[id].molecules[tmpid].const)
 +
    {
 +
    if(simulations[id].reactions[i].precomp_molusage[tmpid] == undefined)
 +
      simulations[id].reactions[i].precomp_molusage[tmpid] = 1;
 +
    else
 +
      simulations[id].reactions[i].precomp_molusage[tmpid] ++;
 +
    }
 +
   
   }
   }
Line 147: Line 163:
     }
     }
     simulations[id].reactions[i].outputs[j]= tmpid;
     simulations[id].reactions[i].outputs[j]= tmpid;
 +
 +
  //precomputing
 +
    if(simulations[id].reactions[i].precomp_molusage[tmpid] != undefined)
 +
    {
 +
    simulations[id].reactions[i].precomp_molusage[tmpid] --;
 +
    if(simulations[id].reactions[i].precomp_molusage[tmpid] <= 0) //not consuming
 +
      simulations[id].reactions[i].precomp_molusage.splice(tmpid, 1);
 +
    }
   }
   }
    
    
Line 309: Line 333:
   var reac= sim.reactions[sim.reac_order[i]];
   var reac= sim.reactions[sim.reac_order[i]];
-
   var proba= reac.probability * sim.timestep;
+
 
 +
   var proba= reac.precomp_probfactor;
   for(var j= 0 ; j < reac.inputs.length ; ++j)
   for(var j= 0 ; j < reac.inputs.length ; ++j)
-
  {
+
   proba *= sim.molecules[reac.inputs[j]].quantity;
-
  var inid= reac.inputs[j];
+
-
  if(!sim.molecules[inid].const)
+
-
  {
+
-
    if(usedmols[inid] == undefined)
+
-
    usedmols[inid]= 1;
+
-
    else
+
-
    usedmols[inid] ++;
+
-
  }
+
-
   proba *= sim.molecules[inid].quantity;
+
-
  }
+
-
  for(var j= 0 ; j < reac.outputs.length ; ++j)
+
-
  {
+
-
  var outid= reac.outputs[j];
+
-
  if(usedmols[outid] != undefined)
+
-
    usedmols[outid]--;
+
-
  }
+
-
  proba *= Math.pow(sim.cfactor/sim.volume, reac.inputs.length);
+
-
 
+
-
  //alert('BEFORE : reac '+i+ ' proba=' + proba);
+
   var entier= Math.floor(proba);
   var entier= Math.floor(proba);
Line 336: Line 342:
   for(var elt in usedmols)
   for(var elt in usedmols)
   {
   {
-
   if( entier * usedmols[elt] >= sim.molecules[elt].quantity )
+
   if( entier * reac.precomp_molusage[elt] >= sim.molecules[elt].quantity )
   {
   {
-
     var tmpe= Math.floor(sim.molecules[elt].quantity / usedmols[elt]);
+
     var tmpe= Math.floor(sim.molecules[elt].quantity / reac.precomp_molusage[elt]);
     if(tmpe < entier)
     if(tmpe < entier)
     entier= tmpe;
     entier= tmpe;
Line 344: Line 350:
   }
   }
   }
   }
-
 
-
  //alert('AFTER : reac '+i+ ' proba=' + (entier+frac));
 
   for(var j= 0 ; j < reac.inputs.length ; ++j)
   for(var j= 0 ; j < reac.inputs.length ; ++j)
Line 377: Line 381:
  for(var i= 0 ; i < sim.molecules.length ; ++i)
  for(var i= 0 ; i < sim.molecules.length ; ++i)
-
   sim.molecules[i].history.push(sim.molecules[i].quantity);
+
{
 +
   if(sim.molecules[i].curve_show)
 +
  sim.molecules[i].history.push(sim.molecules[i].quantity);
 +
}
  sim.curtime += sim.timestep;
  sim.curtime += sim.timestep;

Revision as of 11:06, 3 August 2013