Skip to content

Commit f6e94f3

Browse files
authored
Merge pull request #1633 from virtualcell/dan-ss-results6
Dan ss results6
2 parents b3183a8 + 6171172 commit f6e94f3

8 files changed

Lines changed: 219 additions & 11 deletions

File tree

vcell-core/src/main/java/cbit/vcell/simdata/DataSetControllerImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,15 @@ public ODEDataBlock getODEDataBlock(VCDataIdentifier vcdID) throws DataAccessExc
24022402
public LangevinBatchResultSet getLangevinBatchResultSet(VCDataIdentifier vcdID) throws DataAccessException {
24032403
if (lg.isTraceEnabled()) lg.trace("DataSetControllerImpl.getLangevinBatchResultSet()");
24042404
try {
2405-
VCData simData = getVCData(vcdID);
2405+
VCData vcData = getVCData(vcdID);
2406+
if(!(vcData instanceof SimulationData)) {
2407+
return null;
2408+
}
2409+
SimulationData simData = (SimulationData)vcData;
2410+
if(!(simData.getIsIDAData())) {
2411+
return null;
2412+
}
2413+
24062414
ODEDataInfo odeDataInfo = new ODEDataInfo(vcdID.getOwner(), vcdID.getID(),
24072415
simData.getDataBlockTimeStamp(ODE_DATA, 0));
24082416
int keepAtMost = 10000;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package cbit.vcell.simdata;
2+
3+
import cbit.vcell.solver.ode.ODESimData;
4+
5+
import java.io.*;
6+
7+
public class LangevinSolverResultSet implements Serializable {
8+
9+
private final LangevinBatchResultSet raw;
10+
11+
public LangevinSolverResultSet(LangevinBatchResultSet raw) {
12+
this.raw = raw;
13+
}
14+
15+
// // safe getter that returns a deep copy, but I don't think we need it
16+
// public LangevinBatchResultSet getLangevinBatchResultSetSafe() {
17+
// return deepCopy(raw);
18+
// }
19+
20+
// convenience getters
21+
public ODESimData getAvg() {
22+
return raw == null ? null : raw.getOdeSimDataAvg();
23+
}
24+
public ODESimData getMin() {
25+
return raw == null ? null : raw.getOdeSimDataMin();
26+
}
27+
public ODESimData getMax() {
28+
return raw == null ? null : raw.getOdeSimDataMax();
29+
}
30+
public ODESimData getStd() {
31+
return raw == null ? null : raw.getOdeSimDataStd();
32+
}
33+
public ODESimData getClusterCounts() {
34+
return raw == null ? null : raw.getOdeSimDataClusterCounts();
35+
}
36+
public ODESimData getClusterMean() {
37+
return raw == null ? null : raw.getOdeSimDataClusterMean();
38+
}
39+
public ODESimData getClusterOverall() {
40+
return raw == null ? null : raw.getOdeSimDataClusterOverall();
41+
}
42+
43+
// helper functions
44+
public boolean isAverageDataAvailable() {
45+
return getAvg() != null &&
46+
getMin() != null &&
47+
getMax() != null &&
48+
getStd() != null;
49+
}
50+
public boolean isClusterDataAvailable() {
51+
return getClusterCounts() != null &&
52+
getClusterMean() != null &&
53+
getClusterOverall() != null;
54+
}
55+
56+
private static LangevinBatchResultSet deepCopy(LangevinBatchResultSet original) {
57+
if (original == null) {
58+
return null;
59+
}
60+
try {
61+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
62+
ObjectOutputStream out = new ObjectOutputStream(bos);
63+
out.writeObject(original);
64+
out.flush();
65+
66+
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
67+
return (LangevinBatchResultSet) in.readObject();
68+
69+
} catch (ClassNotFoundException | IOException e) {
70+
throw new RuntimeException("Deep copy failed", e);
71+
}
72+
}
73+
74+
}

vcell-core/src/main/java/cbit/vcell/simdata/ODEDataManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ODEDataManager implements DataManager {
3535
private VCDataIdentifier vcDataIdentifier = null;
3636
private ODESolverResultSet odeSolverResultSet = null;
3737
private NFSimMolecularConfigurations nFSimMolecularConfigurations = null;
38-
private LangevinBatchResultSet langevinBatchResultSet = null;
38+
private LangevinSolverResultSet langevinSolverResultSet = null;
3939
private OutputContext outputContext = null;
4040

4141
public OutputContext getOutputContext() {
@@ -180,7 +180,11 @@ private void connect() throws DataAccessException {
180180
// clone, so we can operate safely on it (adding/removing user-defined functions) - real remote data is being cached...
181181
odeSolverResultSet = new ODESimData(getVCDataIdentifier(),getVCDataManager().getODEData(getVCDataIdentifier()));
182182
nFSimMolecularConfigurations = getVCDataManager().getNFSimMolecularConfigurations(getVCDataIdentifier());
183-
// langevinBatchResultSet = getVCDataManager().getLangevinBatchResultSet(getVCDataIdentifier());
183+
LangevinBatchResultSet raw = getVCDataManager().getLangevinBatchResultSet(getVCDataIdentifier());
184+
langevinSolverResultSet = new LangevinSolverResultSet(raw); // may be null
185+
if( langevinSolverResultSet.isAverageDataAvailable()) {
186+
odeSolverResultSet = langevinSolverResultSet.getAvg();
187+
}
184188
}
185189

186190
private void addOutputFunction(AnnotatedFunction function, ODESolverResultSet odeRS) {

vcell-core/src/main/java/cbit/vcell/simdata/SimulationData.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,17 @@ public synchronized File getJobFunctionsFile() throws FileNotFoundException {
639639

640640

641641

642-
public synchronized boolean getIsODEData() throws DataAccessException {
643-
refreshLogFile();
644-
return isODEData;
645-
}
646-
642+
public synchronized boolean getIsODEData() throws DataAccessException {
643+
refreshLogFile();
644+
return isODEData;
645+
}
646+
public synchronized boolean getIsIDAData() throws DataAccessException {
647+
refreshLogFile();
648+
return odeIdentifier.equals(IDA_DATA_IDENTIFIER);
649+
}
650+
public String getDataIdentifierSafe() {
651+
return new String(odeIdentifier);
652+
}
647653

648654
private long getLastModified(File pdeFile, File zipFile) throws IOException {
649655
if (zipFile == null) {

vcell-core/src/test/java/cbit/vcell/simdata/LangevinResultsReadTest.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class LangevinResultsReadTest {
4646
private static File langevin_input_file;
4747
private static File messaging_config_file;
4848

49+
private static File euler_log_file;
50+
private static File euler_ode_file;
51+
4952
// results for first task in the batch, named to match single run file (ending in "_") ex: SimID_303404574_0_
5053
private static File ida_0_file;
5154
// log produced by the solver for first task in the batch, named using the normal convention ex: SimID_303404574_0_0.log
@@ -56,6 +59,8 @@ public class LangevinResultsReadTest {
5659
// SimID_303404574_0_.ida
5760
private static File log_data_file;
5861

62+
// resource location of files for various test cases
63+
private static String resourceBase = null;
5964

6065
@BeforeAll
6166
public static void setUp() throws IOException {
@@ -71,6 +76,7 @@ public static void setUp() throws IOException {
7176
throw new IOException("Failed to create subdirectory: " + localSimDir.getAbsolutePath());
7277
}
7378

79+
resourceBase = "cbit/vcell/simdata/langevin/batch/";
7480
functions_file = copyToPrimaryDir("SimID_303404574_0_.functions");
7581
ida_0_file = copyToPrimaryDir("SimID_303404574_0_.ida"); // results for batch run0 (or for single run)
7682
log_0_file = copyToPrimaryDir("SimID_303404574_0_0.log"); // langevin-made log for run 0
@@ -87,6 +93,11 @@ public static void setUp() throws IOException {
8793
ida_min_file = copyToPrimaryDir("SimID_303404574_0__Min.ida");
8894
ida_std_file = copyToPrimaryDir("SimID_303404574_0__Std.ida");
8995

96+
resourceBase = "cbit/vcell/simdata/langevin/euler/";
97+
euler_log_file = copyToPrimaryDir("SimID_303690651_0_.log");
98+
euler_ode_file = copyToPrimaryDir("SimID_303690651_0_.ode");
99+
100+
90101
// ida_1_File = File.createTempFile("SimID_284673710_0_", ".ida");
91102
// Resources.asByteSource(Resources.getResource("cbit/vcell/simdata/SimID_284673710_0_.ida"))
92103
// .copyTo(com.google.common.io.Files.asByteSink(ida_1_File));
@@ -102,7 +113,7 @@ public static void tearDown() {
102113

103114

104115
@Test
105-
public void testReadData() throws IOException, DataAccessException, CacheException {
116+
public void testReadDataLangevinBatch() throws IOException, DataAccessException, CacheException {
106117

107118
String simID = "303404574";
108119
KeyValue key = new KeyValue(simID);
@@ -111,10 +122,13 @@ public void testReadData() throws IOException, DataAccessException, CacheExcepti
111122

112123
VCDataIdentifier vCDataIdentifier = new VCSimulationDataIdentifier(vcSimID, 0);
113124
VCData vcData = new SimulationData(vCDataIdentifier, primaryDir, localSimDir, null);
125+
SimulationData simData = (SimulationData)vcData;
126+
String identifier = simData.getDataIdentifierSafe();
127+
assertTrue(identifier.equals(SimDataConstants.IDA_DATA_IDENTIFIER), "Langevin simulation should be IDA data");
128+
assertFalse(identifier.equals(SimDataConstants.ODE_DATA_IDENTIFIER), "Langevin simulation should not be ODE data");
114129

115130
Cachetable aCacheTable = new Cachetable(10 * Cachetable.minute, 100000);
116131
aCacheTable.put(vCDataIdentifier, vcData);
117-
118132
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(aCacheTable, primaryDir, localSimDir);
119133

120134
LangevinBatchResultSet lbrs = dataSetControllerImpl.getLangevinBatchResultSet(vCDataIdentifier);
@@ -143,6 +157,31 @@ public void testReadData() throws IOException, DataAccessException, CacheExcepti
143157

144158
}
145159

160+
// we should not try to read euler results using LangevinBatchResultSet
161+
@Test
162+
public void testReadDataEulerBatch() throws IOException, DataAccessException, CacheException {
163+
164+
String simID = "303690651";
165+
KeyValue key = new KeyValue(simID);
166+
User usr = new User("temp",key);
167+
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(key, usr);
168+
169+
VCDataIdentifier vCDataIdentifier = new VCSimulationDataIdentifier(vcSimID, 0);
170+
VCData vcData = new SimulationData(vCDataIdentifier, primaryDir, localSimDir, null);
171+
SimulationData simData = (SimulationData)vcData;
172+
String identifier = simData.getDataIdentifierSafe();
173+
assertFalse(identifier.equals(SimDataConstants.IDA_DATA_IDENTIFIER), "Langevin simulation should not be IDA data");
174+
assertTrue(identifier.equals(SimDataConstants.ODE_DATA_IDENTIFIER), "Langevin simulation should be ODE data");
175+
176+
Cachetable aCacheTable = new Cachetable(10 * Cachetable.minute, 100000);
177+
aCacheTable.put(vCDataIdentifier, vcData);
178+
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(aCacheTable, primaryDir, localSimDir);
179+
180+
LangevinBatchResultSet lbrs = dataSetControllerImpl.getLangevinBatchResultSet(vCDataIdentifier);
181+
assertNull(lbrs, "Result set should be null for Euler data when read as LangevinBatchResultSet");
182+
183+
}
184+
146185
// @Test
147186
// public void testRead() throws IOException {
148187
//
@@ -167,7 +206,7 @@ private static void deleteRecursively(File file) {
167206

168207
private static File copyToPrimaryDir(String resourceName) throws IOException {
169208
File out = new File(primaryDir, resourceName);
170-
Resources.asByteSource(Resources.getResource("cbit/vcell/simdata/langevin/batch/" + resourceName))
209+
Resources.asByteSource(Resources.getResource(resourceBase + resourceName))
171210
.copyTo(com.google.common.io.Files.asByteSink(out));
172211
return out;
173212
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ODEData logfile
2+
CompactODEData binary format version 1
3+
SimID_303690651_0_.ode
Binary file not shown.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<SimulationTask xmlns="http://sourceforge.net/projects/vcell/vcml" TaskId="0" JobIndex="0" isPowerUser="false">
2+
<MathDescription Name="unnamed_generated">
3+
<Constant Name="_F_">96485.3321</Constant>
4+
<Constant Name="_F_nmol_">9.64853321E-5</Constant>
5+
<Constant Name="_K_GHK_">1.0E-9</Constant>
6+
<Constant Name="_N_pmol_">6.02214179E11</Constant>
7+
<Constant Name="_PI_">3.141592653589793</Constant>
8+
<Constant Name="_R_">8314.46261815</Constant>
9+
<Constant Name="_T_">300.0</Constant>
10+
<Constant Name="EmptySet_init_mole_litre_1">1.0</Constant>
11+
<Constant Name="k4">180.0</Constant>
12+
<Constant Name="k4prime">0.018</Constant>
13+
<Constant Name="k6">1.0</Constant>
14+
<Constant Name="K_millivolts_per_volt">1000.0</Constant>
15+
<Constant Name="kappa">0.015</Constant>
16+
<Constant Name="KMOLE">0.001660538783162726</Constant>
17+
<Constant Name="Size_cell">1.0</Constant>
18+
<Constant Name="u_init_mole_litre_1">0.0</Constant>
19+
<Constant Name="v_init_mole_litre_1">0.0</Constant>
20+
<VolumeVariable Name="u" Domain="Compartment" />
21+
<VolumeVariable Name="v" Domain="Compartment" />
22+
<Function Name="alpha">(k4prime / k4)</Function>
23+
<Function Name="EmptySet" Domain="Compartment">(K_EmptySet_total / Size_cell)</Function>
24+
<Function Name="K_EmptySet_total" Domain="Compartment">(Size_cell * EmptySet_init_mole_litre_1)</Function>
25+
<Function Name="K_s_z_total" Domain="Compartment">(Size_cell * s_z_init_mole_litre_1)</Function>
26+
<Function Name="LumpedJ_r0" Domain="Compartment">((k4 * (v - u) * (alpha + pow(u,2.0))) - (k6 * u))</Function>
27+
<Function Name="LumpedJ_r1" Domain="Compartment">(kappa - (k6 * u))</Function>
28+
<Function Name="s_z" Domain="Compartment">(K_s_z_total / Size_cell)</Function>
29+
<Function Name="s_z_init_mole_litre_1" Domain="Compartment">(v_init_mole_litre_1 - u_init_mole_litre_1)</Function>
30+
<CompartmentSubDomain Name="Compartment">
31+
<BoundaryType Boundary="Xm" Type="Value" />
32+
<BoundaryType Boundary="Xp" Type="Value" />
33+
<BoundaryType Boundary="Ym" Type="Value" />
34+
<BoundaryType Boundary="Yp" Type="Value" />
35+
<BoundaryType Boundary="Zm" Type="Value" />
36+
<BoundaryType Boundary="Zp" Type="Value" />
37+
<OdeEquation Name="u" SolutionType="Unknown">
38+
<Rate>(LumpedJ_r0 / Size_cell)</Rate>
39+
<Initial>u_init_mole_litre_1</Initial>
40+
</OdeEquation>
41+
<OdeEquation Name="v" SolutionType="Unknown">
42+
<Rate>(LumpedJ_r1 / Size_cell)</Rate>
43+
<Initial>v_init_mole_litre_1</Initial>
44+
</OdeEquation>
45+
</CompartmentSubDomain>
46+
<Version Name="unnamed_generated" KeyValue="164204547" BranchId="164138400" Archived="0" Date="15-Aug-2019 17:46:00" FromVersionable="false">
47+
<Owner Name="danv" Identifier="26766043" />
48+
<GroupAccess Type="1" />
49+
</Version>
50+
</MathDescription>
51+
<Simulation Name="Copy of Copy of Simulation0">
52+
<SolverTaskDescription TaskType="Unsteady" UseSymbolicJacobian="false" Solver="Forward Euler (First Order, Fixed Time Step)">
53+
<TimeBound StartTime="0.0" EndTime="100.0" />
54+
<TimeStep DefaultTime="0.1" MinTime="1.0E-8" MaxTime="1.0" />
55+
<ErrorTolerance Absolut="1.0E-9" Relative="1.0E-9" />
56+
<OutputOptions KeepEvery="1" KeepAtMost="1000" />
57+
<NumberProcessors>1</NumberProcessors>
58+
</SolverTaskDescription>
59+
<MathOverrides />
60+
<Version Name="Copy of Copy of Simulation0" KeyValue="303690651" BranchId="303690652" Archived="0" Date="03-Feb-2026 21:49:49" FromVersionable="false">
61+
<Owner Name="danv" Identifier="26766043" />
62+
<GroupAccess Type="1" />
63+
</Version>
64+
</Simulation>
65+
<Geometry Name="Compartmental1134096228" Dimension="0">
66+
<Extent X="10.0" Y="10.0" Z="10.0" />
67+
<Origin X="0.0" Y="0.0" Z="0.0" />
68+
<SubVolume Name="Compartment" Handle="0" Type="Compartmental" KeyValue="164138398" />
69+
<Version Name="Compartmental1134096228" KeyValue="164138394" BranchId="164138395" Archived="0" Date="14-Aug-2019 23:06:24" FromVersionable="false">
70+
<Owner Name="danv" Identifier="26766043" />
71+
<GroupAccess Type="1" />
72+
</Version>
73+
</Geometry>
74+
</SimulationTask>

0 commit comments

Comments
 (0)