Skip to content

Commit

Permalink
WIP, ssld import geometry, simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
danv61 committed Aug 30, 2024
1 parent 7e57365 commit 6175d89
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3351,6 +3351,8 @@ public void run(Hashtable<String, Object> hashTable) throws Exception {
// inside fromSsld() we will set to using count by default
BioModel bioModel = ssldUtils.fromSsld(ssldModel);



// we also add an empty rule-based application, just for testing
// it's going to be incomplete because we did not import the initial condition from the ssld model
SimulationContext ruleBasedSimContext = bioModel.addNewSimulationContext("NFSim app",
Expand Down
3 changes: 3 additions & 0 deletions vcell-core/src/main/java/cbit/vcell/math/VCML.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ public class VCML {
public final static String LangevinSimulationOptions_runIndex = "RunIndex";
public final static String LangevinSimulationOptions_intervalSpring = "IntervalSpring";
public final static String LangevinSimulationOptions_intervalImage = "IntervalImage";
public final static String LangevinSimulationOptions_Partition_Nx = "Partition Nx";
public final static String LangevinSimulationOptions_Partition_Ny = "Partition Ny";
public final static String LangevinSimulationOptions_Partition_Nz = "Partition Nz";

public final static String NFSimSimulationOptions = "NFSimSimulationOptions";
public final static String NFSimSimulationOptions_observableComputationOff = "ObservableComputationOff";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@

public class LangevinSimulationOptions implements Serializable, Matchable, VetoableChangeListener {

// TODO: add the partition definitions in the LangevinOptionsPanel

public final static String Partition_Nx = "Partition Nx: ";
public final static String Partition_Ny = "Partition Ny: ";
public final static String Partition_Nz = "Partition Nz: ";

protected int numOfTrials = 1;
protected int runIndex = 0; // run index, will result in Run0 (followed by Run1, 2,...)
protected double intervalSpring = 1.00E-9; // default: dt_spring: 1.00E-9 - from advanced
protected double intervalImage = 1.00E-4; // default: dt_image: 1.00E-4 - from advanced
protected int[] npart = { 10, 10, 10 }; // default number of partitions on each axis

protected transient PropertyChangeSupport propertyChange;
protected transient VetoableChangeSupport vetoChange;
Expand Down Expand Up @@ -87,6 +93,10 @@ public double getIntervalSpring() {
public double getIntervalImage() {
return intervalImage;
}
public int getNPart(int index) {
return npart[index];
}

public final void setRunIndex(int newValue) {
this.runIndex = newValue;
}
Expand All @@ -99,6 +109,11 @@ public final void setIntervalSpring(double newValue) {
public final void setIntervalImage(double newValue) {
this.intervalImage = newValue;
}
public final void setNPart(int[] npart) {
this.npart[0] = npart[0];
this.npart[1] = npart[1];
this.npart[2] = npart[2];
}

public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
getPropertyChange().addPropertyChangeListener(listener);
Expand Down Expand Up @@ -135,8 +150,11 @@ public String getVCML() {
buffer.append("\t" + VCML.LangevinSimulationOptions + " " + VCML.BeginBlock + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_numOfTrials + " " + numOfTrials + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_runIndex + " " + runIndex + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalSpring + " " + intervalSpring + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalImage + " " + intervalImage + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalSpring + " " + intervalSpring + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalImage + " " + intervalImage + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_Partition_Nx + " " + npart[0] + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_Partition_Ny + " " + npart[1] + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_Partition_Nz + " " + npart[2] + "\n");
buffer.append("\t" + VCML.EndBlock + "\n");
return buffer.toString();
}
Expand All @@ -163,6 +181,15 @@ public void readVCML(CommentStringTokenizer tokens) throws DataAccessException {
} else if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_intervalImage)) {
token = tokens.nextToken();
intervalImage = Double.parseDouble(token);
} else if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_Partition_Nx)) {
token = tokens.nextToken();
npart[0] = Integer.parseInt(token);
} else if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_Partition_Ny)) {
token = tokens.nextToken();
npart[1] = Integer.parseInt(token);
} else if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_Partition_Nz)) {
token = tokens.nextToken();
npart[2] = Integer.parseInt(token);
} else if (token.equalsIgnoreCase(VCML.LangevinSimulationOptions_numOfTrials)) {
token = tokens.nextToken();
int val2 = Integer.parseInt(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ private void setDpart(int i) {
System.out.println("Invalid input in BoxGeometry.setDpart(i). Got i = " + i);
}
}
public int [] getNpart() {
return npart;
}

public int getNpart(int i) {
return npart[i];
}


}
65 changes: 60 additions & 5 deletions vcell-core/src/main/java/org/vcell/model/ssld/SsldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import cbit.vcell.biomodel.BioModel;
import cbit.vcell.geometry.Geometry;
import cbit.vcell.geometry.GeometrySpec;
import cbit.vcell.mapping.*;
import cbit.vcell.model.*;
import cbit.vcell.parser.Expression;
import cbit.vcell.solver.LangevinSimulationOptions;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.SimulationOwner;
import cbit.vcell.solver.SolverTaskDescription;
import org.vcell.model.rbm.*;
import org.vcell.solver.langevin.LangevinLngvWriter;
import org.vcell.util.Coordinate;
Expand Down Expand Up @@ -321,12 +326,10 @@ MolecularType getSource(Structure structure) {
MolecularType getSink(Structure structure) {
return structureToSinkMap.get(structure);
}

}

public BioModel fromSsld(SsldModel ssldModel) throws Exception {


Mapping m = importPhysiologyFromSsld(ssldModel);
BioModel bioModel = m.getBioModel();
// String newApplicationName = bioModel.getFreeSimulationContextName();
Expand All @@ -335,7 +338,10 @@ public BioModel fromSsld(SsldModel ssldModel) throws Exception {
// we always import count, so we start with default count
springSaLaDSimContext.setUsingConcentration(false, true);
m.set(springSaLaDSimContext);

importApplicationFromSsld(m);
importGeometryFromSsld(m);
importSimulationFromSsld(m);

return bioModel;
}
Expand All @@ -345,9 +351,6 @@ public void importApplicationFromSsld(Mapping m) throws Exception {
final SsldModel ssldModel = m.getSsldModel();
SimulationContext simContext = m.getSimulationContext(); // default ssld application

GeometryContext geometryContext = simContext.getGeometryContext();
Geometry geometry = simContext.getGeometry();

ReactionRuleSpec[] rrSpecs = simContext.getReactionContext().getReactionRuleSpecs();
SpeciesContextSpec[] scSpecs = simContext.getReactionContext().getSpeciesContextSpecs();

Expand All @@ -357,11 +360,63 @@ public void importApplicationFromSsld(Mapping m) throws Exception {
for(ReactionRuleSpec rrs : rrSpecs) {
importReactionRuleSpecForSsld(rrs, m);
}
}

private void importSimulationFromSsld(Mapping m) throws Exception {

final SsldModel ssldModel = m.getSsldModel();
BoxGeometry ssldBoxGeometry = ssldModel.boxGeometry;
/* --- SystemTimes
private double totalTime;
private double dt;
private double dtspring;
private double dtdata;
private double dtimage;
*/
SystemTimes ssldSystemTimes = ssldModel.systemTimes;

final BioModel bioModel = m.getBioModel();
SimulationContext simContext = m.getSimulationContext();

SimulationContext.MathMappingCallback callback = new MathMappingCallbackTaskAdapter(null);
SimulationContext.NetworkGenerationRequirements networkGenerationRequirements = null; // network generation should not be executed
simContext.refreshMathDescription(callback,networkGenerationRequirements);
Simulation sim = simContext.addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX, callback, networkGenerationRequirements);

SolverTaskDescription lstd = sim.getSolverTaskDescription();
LangevinSimulationOptions lso = lstd.getLangevinSimulationOptions();
lso.setNPart(ssldBoxGeometry.getNpart());

// TODO: system times

}

private void importGeometryFromSsld(Mapping m) throws Exception {
/*
L_x: 0.1
L_y: 0.1
L_z_out: 0.010000000000000009
L_z_in: 0.09
Partition Nx: 10 // partitions imported in importSimulationFromSsld(), see above
Partition Ny: 10
Partition Nz: 10
double x, y, zin, zout, int[3] npart
*/
final SsldModel ssldModel = m.getSsldModel();
BoxGeometry ssldBoxGeometry = ssldModel.boxGeometry;

final BioModel bioModel = m.getBioModel();
SimulationContext simContext = m.getSimulationContext();
GeometryContext geometryContext = simContext.getGeometryContext();
Geometry geometry = simContext.getGeometry();
GeometrySpec geometrySpec = geometry.getGeometrySpec();

// TODO: see LangevinLngvWriter #938 for intracellularSubVolume expression, it's complicated

}


private void importReactionRuleSpecForSsld(ReactionRuleSpec rrs, Mapping m) throws Exception {
ReactionRule rr = rrs.getReactionRule();
Reaction ssldReaction = m.get(rr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cbit.vcell.geometry.AnalyticSubVolume;
import cbit.vcell.geometry.SubVolume;
import cbit.vcell.model.Structure;
import cbit.vcell.solver.*;
import org.vcell.util.Pair;

import cbit.vcell.geometry.Geometry;
Expand Down Expand Up @@ -43,11 +44,6 @@
import cbit.vcell.parser.DivideByZeroException;
import cbit.vcell.parser.Expression;
import cbit.vcell.parser.ExpressionException;
import cbit.vcell.solver.LangevinSimulationOptions;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.SimulationOwner;
import cbit.vcell.solver.SimulationSymbolTable;
import cbit.vcell.solver.SolverException;
//import org.jdom.output.Format;

public class LangevinLngvWriter {
Expand Down Expand Up @@ -145,7 +141,7 @@ public static String writeLangevinLngv(Simulation simulation, long randomSeed) t
/* ********* WRITE THE SPATIAL INFORMATION **********/
sb.append("*** " + SPATIAL_INFORMATION + " ***");
sb.append("\n");
writeSpatialInformation(geometrySpec, sb);
writeSpatialInformation(geometrySpec, simulation, sb);
sb.append("\n");

/* ******* WRITE THE SPECIES INFORMATION ***********/
Expand Down Expand Up @@ -922,7 +918,7 @@ private static void writeSpeciesInfo(StringBuilder sb) {
return;
}

public static void writeSpatialInformation(GeometrySpec geometrySpec, StringBuilder sb) { // SpringSaLaD exporting the time information
public static void writeSpatialInformation(GeometrySpec geometrySpec, Simulation simulation, StringBuilder sb) { // SpringSaLaD exporting the time information
if (geometrySpec.getDimension() != 3) {
throw new RuntimeException("SpringSaLaD requires 3D geometry");
}
Expand Down Expand Up @@ -985,12 +981,15 @@ public static void writeSpatialInformation(GeometrySpec geometrySpec, StringBuil
sb.append("\n");
sb.append("L_z_in: " + Lz_intra); // 0.09
sb.append("\n");
sb.append("Partition Nx: 10"); // TODO: make number of partitions on each axes part of Langevin Simulations Options
sb.append("\n");
sb.append("Partition Ny: 10");
sb.append("\n");
sb.append("Partition Nz: 10");
sb.append("\n");

SolverTaskDescription lstd = simulation.getSolverTaskDescription();
LangevinSimulationOptions lso = lstd.getLangevinSimulationOptions();
sb.append(LangevinSimulationOptions.Partition_Nx + lso.getNPart(0));
sb.append("\n");
sb.append(LangevinSimulationOptions.Partition_Ny + lso.getNPart(1));
sb.append("\n");
sb.append(LangevinSimulationOptions.Partition_Nz + lso.getNPart(2));
sb.append("\n");
}

public static void writeMoleculeCounters(StringBuilder sb) {
Expand Down

0 comments on commit 6175d89

Please sign in to comment.