2323import cbit .vcell .xml .ExternalDocInfo ;
2424
2525import org .jlibsedml .components .SId ;
26- import org .jlibsedml .components .SedBase ;
2726import org .jlibsedml .components .SedML ;
2827import org .jlibsedml .components .task .AbstractTask ;
2928import org .jlibsedml .components .dataGenerator .DataGenerator ;
3938import org .jlibsedml .components .simulation .UniformTimeCourse ;
4039import org .jlibsedml .components .Variable ;
4140import org .jlibsedml .XPathTarget ;
42- import org .jlibsedml .XMLException ;
4341import org .jlibsedml .modelsupport .SBMLSupport ;
4442
4543import org .jmathml .ASTNode ;
5452import org .apache .commons .lang .NotImplementedException ;
5553import org .apache .logging .log4j .LogManager ;
5654import org .apache .logging .log4j .Logger ;
57- import org .vcell .util .Pair ;
5855
5956import java .beans .PropertyVetoException ;
6057import java .io .*;
@@ -102,18 +99,22 @@ private static void sanityCheck(BioModel bioModel) throws SEDMLImportException {
10299 }
103100 }
104101
105- public Pair < SedMLDataContainer , Map < BioModel , SBMLSymbolMapping >> initialize (ExternalDocInfo externalDocInfo , SedMLDataContainer providedSedmlContainer , boolean disallowModifiedImport )
102+ public Configuration initialize (ExternalDocInfo externalDocInfo , SedMLDataContainer initialSedmlContainer , boolean exactMatchOnly )
106103 throws ExpressionException , SEDMLImportException {
107104 cbit .util .xml .VCLogger sedmlImportLogger = new LocalLogger ();
108105
109106 //String outDirRoot = outputDirForSedml.toString().substring(0, outputDirForSedml.toString().lastIndexOf(System.getProperty("file.separator")));
110107 SedMLDataContainer actionableSedmlContainer ;
111108 Map <BioModel , SBMLSymbolMapping > bioModelMapping ;
112- SedMLImporter sedmlImporter = new SedMLImporter (sedmlImportLogger , disallowModifiedImport );
109+ SedMLImporter sedmlImporter = new SedMLImporter (sedmlImportLogger , new SedMLImporter .StrictnessPolicy (
110+ true ,
111+ SedMLImporter .StrictnessPolicy .MultipleSubTaskPolicy .CONDENSE_ELSE_REMOVE ,
112+ exactMatchOnly ? SedMLImporter .StrictnessPolicy .SolverMatchPolicy .STRICT_MATCH_OR_REJECT : SedMLImporter .StrictnessPolicy .SolverMatchPolicy .SUNDIALS_AS_LAST_RESORT
113+ ));
113114 this .modelReportingName = org .vcell .util .FileUtils .getBaseName (externalDocInfo .getFile ().getAbsolutePath ());
114115
115116 try {
116- actionableSedmlContainer = sedmlImporter .initialize (externalDocInfo .getFile (), providedSedmlContainer );
117+ actionableSedmlContainer = sedmlImporter .initialize (externalDocInfo .getFile (), initialSedmlContainer );
117118 } catch (Exception e ) {
118119 String errMessage = "Unable to prepare SED-ML for conversion into BioModel(s)" ;
119120 String formattedError = String .format ("%s, failed with error: %s" , errMessage , e .getMessage ());
@@ -131,7 +132,7 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
131132
132133 this .countBioModels = bioModelMapping .size ();
133134
134- SedML sedML = providedSedmlContainer .getSedML ();
135+ SedML sedML = initialSedmlContainer .getSedML ();
135136 Set <AbstractTask > topmostTasks = new LinkedHashSet <> ();
136137 for (BioModel bioModel : bioModelMapping .keySet ()) {
137138 Simulation [] sims = bioModel .getSimulations ();
@@ -141,8 +142,8 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
141142 }
142143 TempSimulation tempSimulation = new TempSimulation (sim ,false );
143144 String importedTaskId = tempSimulation .getImportedTaskID ();
144- SedBase foundElement = sedML . searchInTasksFor (new SId (importedTaskId ));
145- if (!( foundElement instanceof AbstractTask abstractTask ) ) throw new RuntimeException ("Imported task id " + importedTaskId + " is not an AbstractTask." );
145+ AbstractTask abstractTask = initialSedmlContainer . findAbstractTaskById (new SId (importedTaskId ));
146+ if (null == abstractTask ) throw new RuntimeException ("Imported task id " + importedTaskId + " is not an AbstractTask." );
146147 this .tempSimulationToTaskMap .put (tempSimulation , abstractTask );
147148 this .taskToTempSimulationMap .put (abstractTask , tempSimulation );
148149 this .origSimulationToTempSimulationMap .put (sim , tempSimulation );
@@ -156,8 +157,8 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
156157 for (AbstractTask at : sedML .getTasks ()) {
157158 if (!(at instanceof RepeatedTask rt )) continue ;
158159 for (SubTask entry : rt .getSubTasks ()) {
159- SedBase foundElement = sedML . searchInTasksFor (entry .getTask ());
160- if (!( foundElement instanceof AbstractTask subTaskTarget ) ) throw new RuntimeException ("Subtask (id=" + entry .getId ().string () + " ) does not reference an AbstractTask." );
160+ AbstractTask subTaskTarget = initialSedmlContainer . findAbstractTaskById (entry .getTask ());
161+ if (null == subTaskTarget ) throw new RuntimeException ("Subtask (id=" + entry .getId ().string () + " ) does not reference an AbstractTask." );
161162 subTasks .add (subTaskTarget );
162163 }
163164 }
@@ -177,8 +178,8 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
177178 List <AbstractTask > subTasksList = new ArrayList <> ();
178179 Task baseTask ;
179180 if (abstractTask instanceof RepeatedTask repeatedTask ) {
180- subTasksList .addAll (providedSedmlContainer .getActualSubTasks (repeatedTask .getId ()));
181- baseTask = providedSedmlContainer .getBaseTask (repeatedTask .getId ());
181+ subTasksList .addAll (initialSedmlContainer .getActualSubTasks (repeatedTask .getId ()));
182+ baseTask = initialSedmlContainer .getBaseTask (repeatedTask .getId ());
182183 if (baseTask == null ) throw new RuntimeException ("Unable to find base task of repeated task: " + repeatedTask .getId ().string () + "." );
183184 } else if (abstractTask instanceof Task task ) {
184185 baseTask = task ;
@@ -204,11 +205,11 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
204205 // variable id is constructed based on the task id
205206 List <DataSet > datasets = rep .getDataSets ();
206207 for (DataSet dataset : datasets ) {
207- SedBase foundDataGen = sedML . searchInDataGeneratorsFor (dataset .getDataReference ());
208- if (!( foundDataGen instanceof DataGenerator dataGen ) ) throw new IllegalArgumentException ("Unable to find data generator referenced in dataset: " + dataset .getDataReference ());
208+ DataGenerator dataGen = initialSedmlContainer . findDataGeneratorById (dataset .getDataReference ());
209+ if (null == dataGen ) throw new IllegalArgumentException ("Unable to find data generator referenced in dataset: " + dataset .getDataReference ());
209210 for (Variable var : dataGen .getVariables ()) {
210- SedBase foundAbstractTask = sedML . searchInTasksFor (var .getTaskReference ());
211- if (!( foundAbstractTask instanceof AbstractTask task ) ) throw new IllegalArgumentException ("Unable to find task referenced by variable: " + var .getTaskReference ());
211+ AbstractTask task = initialSedmlContainer . findAbstractTaskById (var .getTaskReference ());
212+ if (null == task ) throw new IllegalArgumentException ("Unable to find task referenced by variable: " + var .getTaskReference ());
212213 variableToTaskMap .put (var , task );
213214 }
214215 }
@@ -269,7 +270,7 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
269270 logger .info ("Initialization Statistics:\n \t > taskToSimulationMap: {}\n \t > taskToListOfSubTasksMap: {}\n \t > taskToVariableMap: {}\n \t > topTaskToBaseTask: {}\n " ,
270271 this .taskToTempSimulationMap .size (), this .taskToListOfSubTasksMap .size (), this .taskToVariableMap .size (), this .topTaskToBaseTask .size ());
271272 }
272- return new Pair <> (this .initializedSedMLContainer = actionableSedmlContainer , this .bioModelToSBMLMapping = bioModelMapping );
273+ return new Configuration (this .initializedSedMLContainer = actionableSedmlContainer , this .bioModelToSBMLMapping = bioModelMapping );
273274 }
274275
275276 private static class TempSimulationJob extends SimulationJob {
@@ -385,10 +386,9 @@ public Map<AbstractTask, BiosimulationLog.Status> simulateAllTasks(CLIRecordable
385386 // must interpolate data for uniform time course which is not supported natively by the Java solvers
386387 Task baseTask = this .initializedSedMLContainer .getBaseTask (task .getId ());
387388 if (baseTask == null ) throw new RuntimeException ("Unable to find base task" );
388- SedBase elementFound = this .initializedSedMLContainer .getSedML ().searchInSimulationsFor (baseTask .getSimulationReference ());
389- if (!(elementFound instanceof org .jlibsedml .components .simulation .Simulation sedmlSim ))
390- throw new RuntimeException ("Unable to find simulation for base task" );
391- if (sedmlSim instanceof UniformTimeCourse utcSedmlSim ) {
389+ org .jlibsedml .components .simulation .Simulation sedmlSim = this .initializedSedMLContainer .findSimulationById (baseTask .getSimulationReference ());
390+ if (null == sedmlSim ) throw new RuntimeException ("Unable to find simulation for base task" );
391+ if (sedmlSim instanceof UniformTimeCourse utcSedmlSim ) {
392392 odeSolverResultSet = RunUtils .interpolate (odeSolverResultSet , utcSedmlSim );
393393 logTaskMessage += "done. Interpolating... " ;
394394 }
@@ -737,5 +737,7 @@ public static void main(String[] args) throws Exception {
737737
738738*/
739739 }
740+
741+ public record Configuration (SedMLDataContainer postInitializedSedml , Map <BioModel , SBMLSymbolMapping > bioModelsToSymbolMappings ){}
740742}
741743
0 commit comments