Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "libvcell"
version = "0.0.6"
version = "0.0.7"
description = "This is a python package which wraps a subset of VCell Java code as a native python package."
authors = ["Jim Schaff <[email protected]>", "Ezequiel Valencia <[email protected]>"]
repository = "https://github.com/virtualcell/libvcell"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String toJson() {
documentation = """
Converts VCML file into Finite Volume Input files.
vcml_content: text of VCML XML document
output_dir_path: path to the output directory
output_dir_path: path to the output directory (expected to be subdirectory of the workspace)
Returns a JSON string with success status and message"""
)
public static CCharPointer entrypoint_vcmlToFiniteVolumeInput(
Expand All @@ -65,7 +65,9 @@ public static CCharPointer entrypoint_vcmlToFiniteVolumeInput(
String vcmlContentStr = CTypeConversion.toJavaString(vcml_content);
String simulationName = CTypeConversion.toJavaString(simulation_name);
String outputDirPathStr = CTypeConversion.toJavaString(output_dir_path);
vcmlToFiniteVolumeInput(vcmlContentStr, simulationName, new File(outputDirPathStr));
File outputDir = new File(outputDirPathStr);
File parentDir = outputDir.getParentFile();
vcmlToFiniteVolumeInput(vcmlContentStr, simulationName, parentDir, outputDir);
returnValue = new ReturnValue(true, "Success");
}catch (Throwable t) {
logger.error("Error processing spatial model", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static void main(String[] args) {
File vcml_file = new File(args[1]);
String vcml_sim_name = args[2];
File output_dir = new File(args[3]);
File parent_dir = output_dir.getParentFile();
logger.info("Logger logging");
PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, "none");
PropertyLoader.setProperty(PropertyLoader.mongodbDatabase, "none");
Expand All @@ -35,7 +36,7 @@ public static void main(String[] args) {
byte[] data = f_vcml.readAllBytes();
logger.info("Read " + data.length + " bytes from " + vcml_file.getAbsolutePath());
String vcml_str = new String(data);
vcmlToFiniteVolumeInput(vcml_str, vcml_sim_name, output_dir);
vcmlToFiniteVolumeInput(vcml_str, vcml_sim_name, parent_dir, output_dir);
}

// use reflection to load jsbml classes and call their default constructors
Expand Down
63 changes: 57 additions & 6 deletions vcell-native/src/main/java/org/vcell/libvcell/SolverUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,42 @@

import cbit.util.xml.VCLoggerException;
import cbit.vcell.biomodel.BioModel;
import cbit.vcell.field.FieldDataIdentifierSpec;
import cbit.vcell.field.FieldFunctionArguments;
import cbit.vcell.field.FieldUtilities;
import cbit.vcell.geometry.GeometrySpec;
import cbit.vcell.mapping.MappingException;
import cbit.vcell.mapping.SimulationContext;
import cbit.vcell.math.MathException;
import cbit.vcell.messaging.server.SimulationTask;
import cbit.vcell.mongodb.VCMongoMessage;
import cbit.vcell.parser.ExpressionException;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.SolverException;
import cbit.vcell.solver.TimeBounds;
import cbit.vcell.solver.UniformOutputTimeSpec;
import cbit.vcell.solver.*;
import cbit.vcell.xml.XMLSource;
import cbit.vcell.xml.XmlHelper;
import cbit.vcell.xml.XmlParseException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.vcell.libvcell.solvers.LocalFVSolverStandalone;
import org.vcell.sbml.FiniteVolumeRunUtil;
import org.vcell.sbml.vcell.SBMLExporter;
import org.vcell.sbml.vcell.SBMLImporter;
import org.vcell.util.document.ExternalDataIdentifier;
import org.vcell.util.document.KeyValue;
import org.vcell.util.document.User;

import java.beans.PropertyVetoException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;


public class SolverUtils {
private static final Logger logger = LogManager.getLogger(Entrypoints.class);

public static void vcmlToFiniteVolumeInput(String vcml_content, String simulation_name, File outputDir) throws XmlParseException, MappingException, SolverException, ExpressionException {
public static void vcmlToFiniteVolumeInput(String vcml_content, String simulation_name, File parentDir, File outputDir) throws XmlParseException, MappingException, SolverException, ExpressionException, MathException {
GeometrySpec.avoidAWTImageCreation = true;
VCMongoMessage.enabled = false;
if (vcml_content.substring(0, 300).contains("<sbml xmlns=\"http://www.sbml.org/sbml")) {
Expand All @@ -41,7 +49,50 @@ public static void vcmlToFiniteVolumeInput(String vcml_content, String simulatio
if (sim == null) {
throw new IllegalArgumentException("Simulation not found: " + simulation_name);
}
FiniteVolumeRunUtil.writeInputFilesOnly(outputDir, sim);
FieldDataIdentifierSpec[] fdiSpecs = getFieldDataIdentifierSpecs(sim, parentDir);

TempSimulation tempSimulation = new TempSimulation(sim, false);
tempSimulation.setSimulationOwner(sim.getSimulationOwner());
SimulationJob tempSimulationJob = new SimulationJob(tempSimulation, 0, fdiSpecs);
SimulationTask simTask = new SimulationTask(tempSimulationJob, 0);
LocalFVSolverStandalone solver = new LocalFVSolverStandalone(simTask, outputDir);
solver.initialize();
}

private static FieldDataIdentifierSpec[] getFieldDataIdentifierSpecs(Simulation sim, File parentDir) throws MathException, ExpressionException {
FieldDataIdentifierSpec[] fdiSpecs = null;
FieldFunctionArguments[] fieldFuncArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
if (fieldFuncArgs != null) {
List<FieldDataIdentifierSpec> fdiSpecList = new ArrayList<>();
for (FieldFunctionArguments fieldFuncArg : fieldFuncArgs) {
if (fieldFuncArg != null) {
String name = fieldFuncArg.getFieldName();
File fieldDataDir = new File(parentDir, name);
if (!fieldDataDir.exists()) {
throw new IllegalArgumentException("Field data directory does not exist: " + fieldDataDir.getAbsolutePath());
}
// search fieldDataDir for files with name pattern SimID_<key>_* and extract the key
KeyValue key = null;
for (File f: fieldDataDir.listFiles()) {
String[] filename_parts = f.getName().split("_");
if (filename_parts.length < 3) {
continue;
}
if (filename_parts[0].equals("SimID")) {
key = new KeyValue(filename_parts[1]);
break;
}
}
if (key == null) {
throw new IllegalArgumentException("Field data directory does not contain a file with key: " + name);
}
ExternalDataIdentifier extDataId = new ExternalDataIdentifier(key, User.tempUser, name);
fdiSpecList.add(new FieldDataIdentifierSpec(fieldFuncArg, extDataId));
}
}
fdiSpecs = fdiSpecList.toArray(new FieldDataIdentifierSpec[fdiSpecList.size()]);
}
return fdiSpecs;
}


Expand Down
Loading
Loading