3232public class SpatialSBMLSimResults {
3333
3434 //private ODESolverResultSet resultSet;
35- private final OutputContext DEFAULT_OUTPUT_CONTEXT = new OutputContext (new AnnotatedFunction [] {});
3635 private final DataSetControllerImpl dataSetController ;
3736 private final VCSimulationIdentifier simId ;
3837 private final int jobIndex ;
@@ -87,7 +86,9 @@ public SBMLDataRecord getDataForSBMLVar(String sbmlId, UniformTimeCourse utcSim)
8786 VCDataIdentifier vcDId = new VCSimulationDataIdentifier (this .simId , this .jobIndex );
8887 double [] times = this .getDesiredTimes (vcDId , utcSim );
8988
90- DataOperation dataOperation = new DataOperation .DataProcessingOutputInfoOP (vcDId ,true , this .DEFAULT_OUTPUT_CONTEXT );
89+ AnnotatedFunction [] annotatedFunctions = this .sbmlMapping .getAllRuntimeStes ().stream ().filter (AnnotatedFunction .class ::isInstance ).map (AnnotatedFunction .class ::cast ).toArray (AnnotatedFunction []::new );
90+ OutputContext outputContext = new OutputContext (annotatedFunctions );
91+ DataOperation dataOperation = new DataOperation .DataProcessingOutputInfoOP (vcDId ,true , outputContext );
9192 DataOperationResults .DataProcessingOutputInfo results = (DataOperationResults .DataProcessingOutputInfo ) this .dataSetController .doDataOperation (dataOperation );
9293 Set <String > varNamesSet = new HashSet <>(Arrays .asList (results .getVariableNames ()));
9394
@@ -101,22 +102,27 @@ public SBMLDataRecord getDataForSBMLVar(String sbmlId, UniformTimeCourse utcSim)
101102 if (ste instanceof Structure .StructureSize ) ste = this .getStructureSizeSymbolTableEntry (ste , sbmlId );
102103
103104 cbit .vcell .math .Variable mathVar = this .mathMapping .getVariable (ste );
104- if (mathVar != null ) return this .processSpatialData (mathVar , vcDId , mesh , varNamesSet , times );
105+ if (mathVar == null && ste instanceof AnnotatedFunction annotatedFunction && annotatedFunction .isOutputFunction ()){
106+ mathVar = annotatedFunction ;
107+ }
108+ if (mathVar != null ) return this .processSpatialData (mathVar , vcDId , mesh , varNamesSet , times , outputContext );
105109 if (ste instanceof Kinetics .KineticsParameter lumpedRate && Kinetics .ROLE_LumpedReactionRate == lumpedRate .getRole ())
106- return this .processLumpedRate (sbmlId , vcDId , lumpedRate , times , mesh , varNamesSet );
107- throw new RuntimeException ("Math mapping couldn't find mathVar with ste: " + ste .getName ());
110+ return this .processLumpedRate (sbmlId , vcDId , lumpedRate , times , mesh , varNamesSet , outputContext );
111+
112+ String errorFormat = "Math mapping couldn't find correct mathVar or properly process ste: %s (%s)" ;
113+ throw new RuntimeException (String .format (errorFormat , ste , ste .getClass ().getSimpleName ()));
108114 }
109115
110- private SBMLDataRecord processSpatialData (cbit .vcell .math .Variable mathVar , VCDataIdentifier vcDId , CartesianMesh mesh , Set <String > varNamesSet , double [] times ) throws IOException , DataAccessException , ExpressionException {
111- DataIdentifier [] dataIdentifiers = this .dataSetController .getDataIdentifiers (this . DEFAULT_OUTPUT_CONTEXT , vcDId );
116+ private SBMLDataRecord processSpatialData (cbit .vcell .math .Variable mathVar , VCDataIdentifier vcDId , CartesianMesh mesh , Set <String > varNamesSet , double [] times , OutputContext outputContext ) throws IOException , DataAccessException , ExpressionException {
117+ DataIdentifier [] dataIdentifiers = this .dataSetController .getDataIdentifiers (outputContext , vcDId );
112118 Set <String > identifierSet = Arrays .stream (dataIdentifiers ).map (DataIdentifier ::getName ).collect (Collectors .toSet ());
113119 identifierSet .addAll (varNamesSet );
114120 int meshStep = mesh .getSizeZ () * mesh .getSizeY () * mesh .getSizeX ();
115121 double [] data ;
116122 if (identifierSet .contains (mathVar .getName ())) {
117123 data = new double [meshStep * times .length ];
118124 for (int i = 0 ; i < times .length ; i ++) {
119- SimDataBlock sdb = this .dataSetController .getSimDataBlock (this . DEFAULT_OUTPUT_CONTEXT , vcDId , mathVar .getName (), times [i ]);
125+ SimDataBlock sdb = this .dataSetController .getSimDataBlock (outputContext , vcDId , mathVar .getName (), times [i ]);
120126 double [] subData = sdb .getData ();
121127 System .arraycopy (subData , 0 , data , i * meshStep , subData .length );
122128 }
@@ -131,7 +137,7 @@ private SBMLDataRecord processSpatialData(cbit.vcell.math.Variable mathVar, VCDa
131137 return new SBMLDataRecord (data , List .of (times .length , mesh .getSizeZ (), mesh .getSizeY (), mesh .getSizeX ()), times );
132138 }
133139
134- private SBMLDataRecord processLumpedRate (String sbmlId , VCDataIdentifier vcDId , Kinetics .KineticsParameter lumpedRate , double [] times , CartesianMesh mesh , Set <String > varNamesSet ) throws ExpressionException , DataAccessException {
140+ private SBMLDataRecord processLumpedRate (String sbmlId , VCDataIdentifier vcDId , Kinetics .KineticsParameter lumpedRate , double [] times , CartesianMesh mesh , Set <String > varNamesSet , OutputContext outputContext ) throws ExpressionException , DataAccessException {
135141 // if reaction has been transformed to distributed, then retrieve distributed rate and multiply by compartment size.
136142 // find distributed rate by looking in MathSymbolMapping for a variable which is mapped to the same reaction and has ROLE_ReactionRate
137143 Stream <Kinetics .KineticsParameter > kineticsParameterStream = this .mathMapping .getMappedBiologicalSymbols ().stream ()
@@ -163,7 +169,7 @@ private SBMLDataRecord processLumpedRate(String sbmlId, VCDataIdentifier vcDId,
163169 if (varNamesSet .contains (distributedRateMathVar .getName ())) {
164170 data = new double [meshStep * times .length ];
165171 for (int i = 0 ; i < times .length ; i ++) {
166- SimDataBlock sdb = this .dataSetController .getSimDataBlock (this . DEFAULT_OUTPUT_CONTEXT , vcDId , distributedRateMathVar .getName (), times [i ]);
172+ SimDataBlock sdb = this .dataSetController .getSimDataBlock (outputContext , vcDId , distributedRateMathVar .getName (), times [i ]);
167173 double [] subData = sdb .getData ();
168174 for (int j = 0 ; j < subData .length ; j ++) {
169175 data [i * meshStep + j ] = subData [j ] * compartmentSize ;
0 commit comments