116 lines
3.4 KiB
C#
116 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BaseCellSimulation
|
|
{
|
|
public struct cellInfo
|
|
{
|
|
public double time;
|
|
public CellState state;
|
|
public Dictionary<string, double> resources;
|
|
public CellCaState caState;
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new();
|
|
sb.AppendLine($"Time: {time}, State: {state}");
|
|
foreach (var kvp in resources)
|
|
{
|
|
sb.AppendLine($"{kvp.Key}: {kvp.Value}");
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
|
|
public class Cell
|
|
{
|
|
private List<Organell> organelles = new();
|
|
private CellRessources resources;
|
|
private CellState state = CellState.Resting;
|
|
private double time = 0.0;
|
|
private Random rng = new();
|
|
private CellCaState caState = new();
|
|
|
|
public EnviromentState EnviromentState { get { return resources.Env; } set { resources.Env = value; } }
|
|
|
|
public Cell()
|
|
{
|
|
organelles.Add(new Cytosol());
|
|
organelles.Add(new Mitochondrion());
|
|
organelles.Add(new Nucleus());
|
|
organelles.Add(new Membrane());
|
|
organelles.Add(new Lysosome());
|
|
|
|
resources = CellRessources.InitDefaults();
|
|
|
|
|
|
// calcium baseline
|
|
caState.CytosolicCa = 0.0001; // 100 nM
|
|
caState.ER_Ca = 0.5; // 0.5 mM
|
|
}
|
|
|
|
public void Step(double dt)
|
|
{
|
|
foreach (Organell organell in organelles)
|
|
{
|
|
organell.calculateRate(resources);
|
|
}
|
|
|
|
foreach (Organell organell in organelles)
|
|
{
|
|
organell.applyChanges(resources, dt);
|
|
}
|
|
|
|
CheckForDeath(dt);
|
|
|
|
time += dt;
|
|
|
|
}
|
|
|
|
private void CheckForDeath(double dt)
|
|
{
|
|
// Energie- und Calciumkritische Schwellen
|
|
const double ATP_MIN = 0.05; // mM
|
|
const double CA_TOXIC = 0.002; // 2 µM
|
|
const double WASTE_MAX = 5.0; // mM
|
|
|
|
if (resources.Res.Energy.ATP < ATP_MIN || caState.CytosolicCa > CA_TOXIC || resources.Res.Protein.Waste > WASTE_MAX)
|
|
{
|
|
// langsamer Zelltod
|
|
if (rng.NextDouble() < 0.1 * dt)
|
|
state = CellState.Apoptosis;
|
|
}
|
|
|
|
if (state == CellState.Apoptosis)
|
|
{
|
|
// Zelle verliert Ressourcen über Zeit
|
|
resources.Res.Energy.ATP *= (1.0 - 0.05 * dt);
|
|
resources.Res.Carbon.Glucose *= (1.0 - 0.03 * dt);
|
|
resources.Res.Protein.AminoAcids *= (1.0 - 0.02 * dt);
|
|
}
|
|
}
|
|
|
|
public cellInfo GetCellInfo()
|
|
{
|
|
return new cellInfo
|
|
{
|
|
time = this.time,
|
|
state = this.state,
|
|
resources = new Dictionary<string, double>
|
|
{
|
|
{ "Glucose", resources.Res.Carbon.Glucose },
|
|
{ "Oxygen", resources.Res.Oxygen },
|
|
{ "ATP", resources.Res.Energy.ATP },
|
|
{ "NAD", resources.Res.Energy.NAD },
|
|
{ "NADH", resources.Res.Energy.NADH },
|
|
{ "AminoAcids", resources.Res.Protein.AminoAcids }
|
|
},
|
|
caState = this.caState
|
|
};
|
|
}
|
|
|
|
}
|
|
}
|