|
1 | 1 | package org.vcell.libvcell; |
2 | 2 |
|
3 | | -import cbit.util.xml.VCLoggerException; |
4 | | -import cbit.vcell.biomodel.BioModel; |
5 | | -import cbit.vcell.geometry.GeometrySpec; |
6 | | -import cbit.vcell.mapping.MappingException; |
7 | | -import cbit.vcell.mapping.SimulationContext; |
8 | | -import cbit.vcell.mongodb.VCMongoMessage; |
9 | | -import cbit.vcell.parser.ExpressionException; |
10 | | -import cbit.vcell.resource.PropertyLoader; |
11 | | -import cbit.vcell.solver.Simulation; |
12 | | -import cbit.vcell.solver.SolverException; |
13 | | -import cbit.vcell.solver.TimeBounds; |
14 | | -import cbit.vcell.solver.UniformOutputTimeSpec; |
15 | | -import cbit.vcell.xml.XMLSource; |
16 | | -import cbit.vcell.xml.XmlHelper; |
17 | | -import cbit.vcell.xml.XmlParseException; |
18 | 3 | import org.apache.logging.log4j.LogManager; |
19 | 4 | import org.apache.logging.log4j.Logger; |
20 | 5 | import org.graalvm.nativeimage.IsolateThread; |
21 | 6 | import org.graalvm.nativeimage.c.function.CEntryPoint; |
22 | 7 | import org.graalvm.nativeimage.c.type.CCharPointer; |
23 | 8 | import org.graalvm.nativeimage.c.type.CTypeConversion; |
24 | 9 | import org.json.simple.JSONValue; |
25 | | -import org.vcell.sbml.FiniteVolumeRunUtil; |
26 | | -import org.vcell.sbml.vcell.SBMLExporter; |
27 | | -import org.vcell.sbml.vcell.SBMLImporter; |
28 | 10 |
|
29 | | -import java.beans.PropertyVetoException; |
30 | | -import java.io.ByteArrayInputStream; |
31 | 11 | import java.io.File; |
32 | | -import java.io.FileInputStream; |
33 | | -import java.io.InputStream; |
34 | 12 | import java.util.concurrent.ConcurrentHashMap; |
35 | 13 |
|
| 14 | +import static org.vcell.libvcell.SolverUtils.sbmlToFiniteVolumeInput; |
| 15 | +import static org.vcell.libvcell.SolverUtils.vcmlToFiniteVolumeInput; |
| 16 | + |
36 | 17 |
|
37 | 18 | public class Entrypoints { |
38 | 19 | private static final Logger logger = LogManager.getLogger(Entrypoints.class); |
@@ -123,70 +104,4 @@ public static CCharPointer entrypoint_sbmlToFiniteVolumeInput( |
123 | 104 | logger.info("Returning from sbmlToFiniteVolumeInput: " + json); |
124 | 105 | return createString(json); |
125 | 106 | } |
126 | | - |
127 | | - |
128 | | - public static void vcmlToFiniteVolumeInput(String vcml_content, String simulation_name, File outputDir) throws XmlParseException, MappingException, SolverException, ExpressionException { |
129 | | - GeometrySpec.avoidAWTImageCreation = true; |
130 | | - VCMongoMessage.enabled = false; |
131 | | - if (vcml_content.substring(0, 300).contains("<sbml xmlns=\"http://www.sbml.org/sbml")) { |
132 | | - throw new IllegalArgumentException("expecting VCML content, not SBML"); |
133 | | - } |
134 | | - BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(vcml_content)); |
135 | | - bioModel.updateAll(false); |
136 | | - Simulation sim = bioModel.getSimulation(simulation_name); |
137 | | - if (sim == null) { |
138 | | - throw new IllegalArgumentException("Simulation not found: " + simulation_name); |
139 | | - } |
140 | | - FiniteVolumeRunUtil.writeInputFilesOnly(outputDir, sim); |
141 | | - } |
142 | | - |
143 | | - |
144 | | - public static void sbmlToFiniteVolumeInput(String sbml_content, File outputDir) throws MappingException, PropertyVetoException, SolverException, ExpressionException, VCLoggerException { |
145 | | - GeometrySpec.avoidAWTImageCreation = true; |
146 | | - VCMongoMessage.enabled = false; |
147 | | - SBMLExporter.MemoryVCLogger vcl = new SBMLExporter.MemoryVCLogger(); |
148 | | - boolean bValidateSBML = true; |
149 | | - // input stream from sbml_content String |
150 | | - if (sbml_content.substring(0, 300).contains("<vcml xmlns=\"http://sourceforge.net/projects/vcell")) { |
151 | | - throw new IllegalArgumentException("expecting SBML content, not VCML"); |
152 | | - } |
153 | | - InputStream is = new ByteArrayInputStream(sbml_content.getBytes()); |
154 | | - SBMLImporter importer = new SBMLImporter(is, vcl, bValidateSBML); |
155 | | - BioModel bioModel = importer.getBioModel(); |
156 | | - bioModel.updateAll(false); |
157 | | - |
158 | | - final double duration = 5.0; // endpoint arg |
159 | | - final double time_step = 0.1; // endpoint arg |
160 | | - //final ISize meshSize = new ISize(10, 10, 10); // future endpoint arg |
161 | | - SimulationContext simContext = bioModel.getSimulationContext(0); |
162 | | - Simulation sim = new Simulation(simContext.getMathDescription(), simContext); |
163 | | - sim.getSolverTaskDescription().setTimeBounds(new TimeBounds(0.0, duration)); |
164 | | - sim.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec(time_step)); |
165 | | - |
166 | | - FiniteVolumeRunUtil.writeInputFilesOnly(outputDir, sim); |
167 | | - } |
168 | | - |
169 | | - |
170 | | - |
171 | | - // Input Goes as Follows: SBML Input, Output dir |
172 | | - // "/Users/evalencia/Documents/VCell_Repositories/vcell/vcell-rest/src/test/resources/TinySpacialProject_Application0.xml" |
173 | | - // "/Users/evalencia/Documents/VCell_Repositories/vcell/vcell-nativelib/target/sbml-input" |
174 | | - public static void main(String[] args) { |
175 | | - try { |
176 | | - logger.info("Logger logging"); |
177 | | - PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, "none"); |
178 | | - PropertyLoader.setProperty(PropertyLoader.mongodbDatabase, "none"); |
179 | | - File sbml_file = new File(args[0]); |
180 | | - // read sbml_file and create a string object |
181 | | - try (FileInputStream fis = new FileInputStream(sbml_file)) { |
182 | | - byte[] data = fis.readAllBytes(); |
183 | | - logger.info("Read " + data.length + " bytes from " + sbml_file); |
184 | | - String sbml_str = new String(data); |
185 | | - sbmlToFiniteVolumeInput(sbml_str, new File(args[1])); |
186 | | - } |
187 | | - } catch (Exception e) { |
188 | | - System.out.println(e.getMessage()); |
189 | | - logger.error("Error processing spatial model", e); |
190 | | - } |
191 | | - } |
192 | | -} |
| 107 | + } |
0 commit comments