Skip to content

Commit

Permalink
Version 2.3.0. Mike Hasson's work on material dependent transport. Also
Browse files Browse the repository at this point in the history
.mat file support is here.
  • Loading branch information
dukovski committed Oct 24, 2016
1 parent 2dfd256 commit 6157bf3
Show file tree
Hide file tree
Showing 7 changed files with 1,170 additions and 31 deletions.
2 changes: 1 addition & 1 deletion comets_simplified/src/edu/bu/segrelab/comets/Comets.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class Comets implements CometsConstants,
* by each cell just runs through a diffusion routine.
*/
public static boolean DIFFUSION_TEST_MODE = false;
private String versionString = "2.2.3, 2 August 2016";
private String versionString = "2.3.0, 24 October 2016";

// The setup pane
private CometsSimRunner runner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ else if (c.getParameters().getNumLayers()>1)
c.fireSimulationStateChangeEvent(new SimulationStateChangeEvent(SimulationStateChangeEvent.State.PAUSE));
}
if (c.getParameters().showCycleTime())
// System.out.println("Cycle complete in " + (System.currentTimeMillis() - start)/1000.0 + "s");
System.out.println("Cycle complete in " + (System.currentTimeMillis() - start)/1000.0 + "s");
totalTime += System.currentTimeMillis() - start;
c.updateOnCycle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ public synchronized int run(FBAModel[] models)
media = world.getModelMediaAt(x, y, i);
else if (cParams.getNumLayers() > 1)
media = world3D.getModelMediaAt(x, y, z, i);

double[] lb = ((FBAModel)models[i]).getBaseExchLowerBounds();
double[] ub = ((FBAModel)models[i]).getBaseExchUpperBounds();
// String[] exchNames = ((FBAModel)models[i]).getExchangeReactionNames();
Expand Down Expand Up @@ -757,7 +756,7 @@ else if (cParams.getNumLayers() > 1)
if(deltaBiomass[i]<0.0)deltaBiomass[i]=0.0;
// deltaBiomass[i] = (double)(((FBAModel)models[i]).getObjectiveFluxSolution()) * cParams.getTimeStep();
// deltaBiomass[i] = (double)(((FBAModel)models[i]).getObjectiveFluxSolution());
//System.out.println("solution: " + ((FBAModel)models[i]).getObjectiveSolution());
// System.out.println("solution: " + ((FBAModel)models[i]).getObjectiveSolution());

if (cParams.showGraphics())
cellColor = calculateColor();
Expand Down
264 changes: 255 additions & 9 deletions comets_simplified/src/edu/bu/segrelab/comets/fba/FBACometsLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ private enum LoaderState
private boolean useGui;
private Comets c;
private int lineCount;

private boolean substrate = false;
private boolean modelDiffusion = false;
private boolean specific = false;
private boolean friction = false;
private double[][] substrateDiffConsts;
private double[][] modelDiffConsts;
private int[][] substrateLayout;
private double[][] specificMedia;
private double[][] substrateFrictionConsts;
private static final String MODEL_FILE = "model_file",
MODEL_WORLD = "model_world",
GRID_SIZE = "grid_size",
Expand All @@ -87,7 +95,12 @@ private enum LoaderState
BARRIER = "barrier",
MEDIA = "media",
PARAMETERS = "parameters",
DIFFUSION_CONST = "diffusion_constants";
DIFFUSION_CONST = "diffusion_constants",
SUBSTRATE_DIFFUSIVITY = "substrate_diffusivity",
SUBSTRATE_FRICTION = "substrate_friction",
MODEL_DIFFUSIVITY = "model_diffusivity",
SUBSTRATE_LAYOUT = "substrate_layout",
SPECIFIC_MEDIA = "specific_media";
/**
* Returns the recently loaded World2D.
*/
Expand Down Expand Up @@ -202,7 +215,7 @@ public int loadLayoutFile(String filename, Comets c, boolean useGui) throws IOEx
/*
* makes and stores internally: an FBAWorld, an array of FBAModels, an
* ArrayList of FBACells
*/
*/
try
{
BufferedReader reader = new BufferedReader(new FileReader(filename));
Expand Down Expand Up @@ -270,7 +283,6 @@ public int loadLayoutFile(String filename, Comets c, boolean useGui) throws IOEx
if (state == LoaderState.CANCELED)
throw new LayoutFileException("Layout file loading canceled", lineCount);
}

else if (parsed[0].equalsIgnoreCase(MODEL_WORLD))
{
Map<String, Point2D.Double> media = new HashMap<String, Point2D.Double>();
Expand Down Expand Up @@ -363,10 +375,10 @@ else if (worldParsed[0].equalsIgnoreCase(GRID_SIZE))
else if(worldParsed.length == 3)
c.getParameters().setNumLayers(Integer.valueOf(1));

if (Integer.valueOf(worldParsed[3])==1)
{
throw new IOException("In a 3D simulation the number of layers along the 3rd coordinate must be larger than 1.");
}
//if (Integer.valueOf(worldParsed[3])==1)
//{
// throw new IOException("In a 3D simulation the number of layers along the 3rd coordinate must be larger than 1.");
//}
}

/****************** BARRIER *************************/
Expand Down Expand Up @@ -396,6 +408,47 @@ else if (worldParsed[0].equalsIgnoreCase(DIFFUSION_CONST))
List<String> lines = collectLayoutFileBlock(reader);
state = parseMediaDiffusionConstantsBlock(lines, diffConsts);
}
/****************** DIFFUSION CONSTANTS BY SUBSTRATE ********************/

else if (worldParsed[0].equalsIgnoreCase(SUBSTRATE_DIFFUSIVITY))
{
substrate = true;
List<String> lines = collectLayoutFileBlock(reader);
state = parseSubstrateDiffusionConstantsBlock(lines,numMedia);
}
/****************** FRICTION CONSTANTS BY SUBSTRATE ********************/

else if (worldParsed[0].equalsIgnoreCase(SUBSTRATE_FRICTION))
{
friction = true;
List<String> lines = collectLayoutFileBlock(reader);
state = parseSubstrateFrictionConstantsBlock(lines);
}
/****************** DIFFUSION CONSTANTS BY MODEL ********************/

else if (worldParsed[0].equalsIgnoreCase(MODEL_DIFFUSIVITY))
{
modelDiffusion = true;
List<String> lines = collectLayoutFileBlock(reader);
state = parseModelDiffusionConstantsBlock(lines,numMedia);
}

/****************** SUBSTRATE LAYOUT ********************/

else if (worldParsed[0].equalsIgnoreCase(SUBSTRATE_LAYOUT))
{
List<String> lines = collectLayoutFileBlock(reader);
state = parseSubstrateLayoutBlock(lines,c.getParameters().getNumCols(),c.getParameters().getNumRows());
}

/****************** SPECIFIC MEDIA ********************/

else if (worldParsed[0].equalsIgnoreCase(SPECIFIC_MEDIA))
{
specific = true;
List<String> lines = collectLayoutFileBlock(reader);
state = parseSpecificMediaBlock(lines);
}

/****************** MEDIA ***********************/

Expand Down Expand Up @@ -634,7 +687,6 @@ else if (worldParsed[0].equalsIgnoreCase("prevent_media_in"))
}
}
}

/* Set diffusion constants */
double[] diffusionConsts = new double[numMedia];
double defaultDiffConst = pParams.getDefaultDiffusionConstant();
Expand All @@ -649,6 +701,22 @@ else if (worldParsed[0].equalsIgnoreCase("prevent_media_in"))
}
}
world.setDiffusionConstants(diffusionConsts);
if(substrate)
{
world.setSubstrateDiffusion(substrateDiffConsts);
world.setSubstrateLayout(substrateLayout);
}
if(modelDiffusion){
world.setModelDiffusivity(modelDiffConsts);
}
if(specific)
{
world.setSpecificMedia(specificMedia);
}
if(friction)
{
world.setSubstrateFriction(substrateFrictionConsts);
}
System.out.println("Done!");
}
else if(c.getParameters().getNumLayers()>1)
Expand Down Expand Up @@ -1109,6 +1177,184 @@ private LoaderState parseMediaDiffusionConstantsBlock(List<String> lines, Map<In

}

private LoaderState parseSubstrateDiffusionConstantsBlock(List<String> lines, int numMedia) throws LayoutFileException,
NumberFormatException
{
/* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
*
* diffusion_constants <default>
* <medium number> <diff_const>
* <medium number> <diff_const>
* //
*/
Integer i = 0;
substrateDiffConsts = new double[lines.size()][numMedia];
for (String line : lines)
{
lineCount++;
if (line.length() == 0)
continue;

String[] diffConstParsed = line.split("\\s+");
if (diffConstParsed.length != numMedia)
throw new LayoutFileException("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant.", lineCount);

else
{
for(int j = 0;j<numMedia;j++)
{
substrateDiffConsts[i][j] = Double.parseDouble(diffConstParsed[j]);
}
i++;
}
}
return LoaderState.OK;

}

private LoaderState parseSubstrateFrictionConstantsBlock(List<String> lines) throws LayoutFileException,
NumberFormatException
{
/* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
*
* diffusion_constants <default>
* <medium number> <diff_const>
* <medium number> <diff_const>
* //
*/
Integer i = 0;
substrateFrictionConsts = new double[lines.size()][models.length];
for (String line : lines)
{
lineCount++;
if (line.length() == 0)
continue;

String[] diffConstParsed = line.split("\\s+");
if (diffConstParsed.length != models.length)
throw new LayoutFileException("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant.", lineCount);

else
{
for(int j = 0;j<models.length;j++)
{
substrateFrictionConsts[i][j] = Double.parseDouble(diffConstParsed[j]);
}
i++;
}
}
return LoaderState.OK;

}
private LoaderState parseModelDiffusionConstantsBlock(List<String> lines, int numMedia) throws LayoutFileException,
NumberFormatException
{
/* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
*
* diffusion_constants <default>
* <medium number> <diff_const>
* <medium number> <diff_const>
* //
*/
Integer i = 0;
modelDiffConsts = new double[lines.size()][numMedia];
for (String line : lines)
{
lineCount++;
if (line.length() == 0)
continue;

String[] diffConstParsed = line.split("\\s+");
if (diffConstParsed.length != numMedia)
throw new LayoutFileException("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant.", lineCount);

else
{
for(int j = 0;j<numMedia;j++)
{
modelDiffConsts[i][j] = Double.parseDouble(diffConstParsed[j]);
}
i++;
}
}
return LoaderState.OK;

}

private LoaderState parseSubstrateLayoutBlock(List<String> lines,int cols,int rows) throws LayoutFileException,
NumberFormatException
{
/* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
*
* diffusion_constants <default>
* <medium number> <diff_const>
* <medium number> <diff_const>
* //
*/
if (lines.size() != rows)
throw new LayoutFileException("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant.", lineCount);
else
{
Integer i = 0;
substrateLayout = new int[cols][rows];
for (String line : lines)
{
lineCount++;
if (line.length() == 0)
continue;

String[] layoutParsed = line.split("\\s+");
if (layoutParsed.length != cols)
throw new LayoutFileException("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant.", lineCount);

else
{
for(int j = 0;j<cols;j++)
{
substrateLayout[j][i] = Integer.parseInt(layoutParsed[j]);
}
i++;
}
}
}
return LoaderState.OK;

}

private LoaderState parseSpecificMediaBlock(List<String> lines) throws LayoutFileException,
NumberFormatException
{
/* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
*
* diffusion_constants <default>
* <medium number> <diff_const>
* <medium number> <diff_const>
* //
*/
Integer i = 0;
specificMedia = new double[4][lines.size()];
for (String line : lines)
{
lineCount++;
if (line.length() == 0)
continue;

String[] sMediaParsed = line.split("\\s+");
if (sMediaParsed.length != 4)
throw new LayoutFileException("Each line of the 'specific_media' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant.", lineCount);

else
{
for(int j = 0;j<4;j++)
{
specificMedia[j][i] = Double.parseDouble(sMediaParsed[j]);
}
i++;
}
}
return LoaderState.OK;
}

private LoaderState parseInitialPopBlock(String[] header, List<String> lines) throws LayoutFileException,
NumberFormatException
{
Expand Down
Loading

0 comments on commit 6157bf3

Please sign in to comment.