22
33import cbit .util .xml .VCLoggerException ;
44import cbit .vcell .biomodel .BioModel ;
5+ import cbit .vcell .field .FieldDataIdentifierSpec ;
6+ import cbit .vcell .field .FieldFunctionArguments ;
7+ import cbit .vcell .field .FieldUtilities ;
58import cbit .vcell .geometry .GeometrySpec ;
69import cbit .vcell .mapping .MappingException ;
710import cbit .vcell .mapping .SimulationContext ;
11+ import cbit .vcell .math .MathException ;
12+ import cbit .vcell .messaging .server .SimulationTask ;
813import cbit .vcell .mongodb .VCMongoMessage ;
914import cbit .vcell .parser .ExpressionException ;
10- import cbit .vcell .solver .Simulation ;
11- import cbit .vcell .solver .SolverException ;
12- import cbit .vcell .solver .TimeBounds ;
13- import cbit .vcell .solver .UniformOutputTimeSpec ;
15+ import cbit .vcell .solver .*;
1416import cbit .vcell .xml .XMLSource ;
1517import cbit .vcell .xml .XmlHelper ;
1618import cbit .vcell .xml .XmlParseException ;
1719import org .apache .logging .log4j .LogManager ;
1820import org .apache .logging .log4j .Logger ;
21+ import org .vcell .libvcell .solvers .LocalFVSolverStandalone ;
1922import org .vcell .sbml .FiniteVolumeRunUtil ;
2023import org .vcell .sbml .vcell .SBMLExporter ;
2124import org .vcell .sbml .vcell .SBMLImporter ;
25+ import org .vcell .util .document .ExternalDataIdentifier ;
26+ import org .vcell .util .document .KeyValue ;
27+ import org .vcell .util .document .User ;
2228
2329import java .beans .PropertyVetoException ;
2430import java .io .ByteArrayInputStream ;
2531import java .io .File ;
2632import java .io .InputStream ;
33+ import java .util .ArrayList ;
34+ import java .util .List ;
2735
2836
2937public class SolverUtils {
3038 private static final Logger logger = LogManager .getLogger (Entrypoints .class );
3139
32- public static void vcmlToFiniteVolumeInput (String vcml_content , String simulation_name , File outputDir ) throws XmlParseException , MappingException , SolverException , ExpressionException {
40+ public static void vcmlToFiniteVolumeInput (String vcml_content , String simulation_name , File parentDir , File outputDir ) throws XmlParseException , MappingException , SolverException , ExpressionException , MathException {
3341 GeometrySpec .avoidAWTImageCreation = true ;
3442 VCMongoMessage .enabled = false ;
3543 if (vcml_content .substring (0 , 300 ).contains ("<sbml xmlns=\" http://www.sbml.org/sbml" )) {
@@ -41,7 +49,50 @@ public static void vcmlToFiniteVolumeInput(String vcml_content, String simulatio
4149 if (sim == null ) {
4250 throw new IllegalArgumentException ("Simulation not found: " + simulation_name );
4351 }
44- FiniteVolumeRunUtil .writeInputFilesOnly (outputDir , sim );
52+ FieldDataIdentifierSpec [] fdiSpecs = getFieldDataIdentifierSpecs (sim , parentDir );
53+
54+ TempSimulation tempSimulation = new TempSimulation (sim , false );
55+ tempSimulation .setSimulationOwner (sim .getSimulationOwner ());
56+ SimulationJob tempSimulationJob = new SimulationJob (tempSimulation , 0 , fdiSpecs );
57+ SimulationTask simTask = new SimulationTask (tempSimulationJob , 0 );
58+ LocalFVSolverStandalone solver = new LocalFVSolverStandalone (simTask , outputDir );
59+ solver .initialize ();
60+ }
61+
62+ private static FieldDataIdentifierSpec [] getFieldDataIdentifierSpecs (Simulation sim , File parentDir ) throws MathException , ExpressionException {
63+ FieldDataIdentifierSpec [] fdiSpecs = null ;
64+ FieldFunctionArguments [] fieldFuncArgs = FieldUtilities .getFieldFunctionArguments (sim .getMathDescription ());
65+ if (fieldFuncArgs != null ) {
66+ List <FieldDataIdentifierSpec > fdiSpecList = new ArrayList <>();
67+ for (FieldFunctionArguments fieldFuncArg : fieldFuncArgs ) {
68+ if (fieldFuncArg != null ) {
69+ String name = fieldFuncArg .getFieldName ();
70+ File fieldDataDir = new File (parentDir , name );
71+ if (!fieldDataDir .exists ()) {
72+ throw new IllegalArgumentException ("Field data directory does not exist: " + fieldDataDir .getAbsolutePath ());
73+ }
74+ // search fieldDataDir for files with name pattern SimID_<key>_* and extract the key
75+ KeyValue key = null ;
76+ for (File f : fieldDataDir .listFiles ()) {
77+ String [] filename_parts = f .getName ().split ("_" );
78+ if (filename_parts .length < 3 ) {
79+ continue ;
80+ }
81+ if (filename_parts [0 ].equals ("SimID" )) {
82+ key = new KeyValue (filename_parts [1 ]);
83+ break ;
84+ }
85+ }
86+ if (key == null ) {
87+ throw new IllegalArgumentException ("Field data directory does not contain a file with key: " + name );
88+ }
89+ ExternalDataIdentifier extDataId = new ExternalDataIdentifier (key , User .tempUser , name );
90+ fdiSpecList .add (new FieldDataIdentifierSpec (fieldFuncArg , extDataId ));
91+ }
92+ }
93+ fdiSpecs = fdiSpecList .toArray (new FieldDataIdentifierSpec [fdiSpecList .size ()]);
94+ }
95+ return fdiSpecs ;
4596 }
4697
4798
0 commit comments