}
Logs.log("\n\n", Simulator.class);
// Simulation
double t = 0;
JEXCSVWriter writer = new JEXCSVWriter(DirectoryManager.getHostDirectory() + File.separator + "Results.csv"); // Set up a file writer to write data as we go.
try
// set up a try loop so we can catch errors and close the writer if something bad happens
{
writer.write(new String[] { "Time", "Gen", "Pol", "AntiGen", "Rib", "Transcript" }); // List of strings with a comma between them (i.e. a row in the table, in this case, the header of the table)
DecimalFormat format = new DecimalFormat("0.00");
double lastRecordedTime = 0;
String[] itemsToRecord = new String[] { "Gen", "Pol", "AntiGen", "Rib", "Transcript" };
Vector<String> data = new Vector<String>();
while (t < sim.duration)
{
// Add matured items to the pool
pool.mature(t);
// records the amounts of items in the pool at given time in the results table
if(t - lastRecordedTime >= sim.dtRecorder) // If enough time has elapsed since our last recording, record the status of the pool at this time step
{
data.add("" + t); // Time
for (String itemName : itemsToRecord)
{
double amount = pool.amounts.getCount(itemName);
data.add(format.format(amount));
}
writer.write(data);
Logs.log(data.toString(), Simulator.class);
data.clear();
lastRecordedTime = t;
}
// increment time here
// This way, time 0 is recorded initially but time is incremented
// dt for integrating and finding the next solution.
t = t + sim.dt;
// calculate rates based on each reaction in the simulation
for (Reaction rxn : sim.rxns)
{
rxn.calculateBaseRate();
rxn.applyStoichAndRate();
}
// Use the new calculated base rates (dA/dt, dB/dt, etc) to calculate the amount to adjust each amount for the given time-step
pool.simpleLinearIntegrate(sim.dt, t, 1.0); // 1.0 is an attenuation factor (1.0 means no attenuation of all the reactions, 0.0 means all the reactions are stopped. Used to apply things like cell death)
}
}
finally
{
if(writer != null)
{
writer.close();
try
// try to open the folder with the results
{
Desktop.getDesktop().open(sim.outputFolder);
}