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
7 changes: 6 additions & 1 deletion .github/workflows/on-release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ jobs:
mkdir -p dist
cp wheelhouse/*.whl dist/

- name: Publish to PyPI
- name: Publish to PyPI (dry run)
run: |
poetry config pypi-token.pypi "${{ secrets.PYPI_TOKEN }}"
poetry publish --dry-run

- name: Publish to PyPI (release-only - push to PyPI)
run: |
poetry config pypi-token.pypi "${{ secrets.PYPI_TOKEN }}"
poetry publish --skip-existing
if: github.event_name == 'release'

- name: Setup tmate
if: failure()
Expand Down
4 changes: 3 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def main() -> None:
run_command(
"java -agentlib:native-image-agent=config-output-dir=target/recording "
"-jar target/vcell-native-1.0-SNAPSHOT.jar "
"src/test/resources/TinySpacialProject_Application0.xml "
"src/test/resources/TinySpatialProject_Application0.xml "
"src/test/resources/TinySpatialProject_Application0.vcml "
"Simulation0 "
"target/sbml-input",
cwd=vcell_native_dir,
)
Expand Down
20 changes: 18 additions & 2 deletions docs/modules.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Modules

## libvcell.libvcell
## libvcell

::: libvcell.libvcell
::: libvcell

# Modules

## libvcell

::: libvcell

### Functions

#### sbml_to_finite_volume_input

::: libvcell.solver_utils.sbml_to_finite_volume_input

#### vcml_to_finite_volume_input

::: libvcell.solver_utils.vcml_to_finite_volume_input
3 changes: 3 additions & 0 deletions libvcell/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from libvcell.solver_utils import sbml_to_finite_volume_input, vcml_to_finite_volume_input

__all__ = ["vcml_to_finite_volume_input", "sbml_to_finite_volume_input"]
19 changes: 0 additions & 19 deletions libvcell/libvcell.py

This file was deleted.

36 changes: 36 additions & 0 deletions libvcell/solver_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path

from libvcell._internal.native_calls import ReturnValue, VCellNativeCalls


def vcml_to_finite_volume_input(vcml_content: str, simulation_name: str, output_dir_path: Path) -> tuple[bool, str]:
"""
Convert VCML content to finite volume input files

Args:
vcml_content (str): VCML content
simulation_name (str): simulation name
output_dir_path (Path): output directory path

Returns:
tuple[bool, str]: A tuple containing the success status and a message
"""
native = VCellNativeCalls()
return_value: ReturnValue = native.vcml_to_finite_volume_input(vcml_content, simulation_name, output_dir_path)
return return_value.success, return_value.message


def sbml_to_finite_volume_input(sbml_content: str, output_dir_path: Path) -> tuple[bool, str]:
"""
Convert SBML content to finite volume input files

Args:
sbml_content (str): SBML content
output_dir_path (Path): output directory path

Returns:
tuple[bool, str]: A tuple containing the success status and a message
"""
native = VCellNativeCalls()
return_value: ReturnValue = native.sbml_to_finite_volume_input(sbml_content, output_dir_path)
return return_value.success, return_value.message
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.4"
version = "0.0.5"
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
4 changes: 3 additions & 1 deletion scripts/build_native.sh → scripts/local_build_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ mvn clean install
# run with native-image-agent to record configuration for native-image
java -agentlib:native-image-agent=config-output-dir=target/recording \
-jar target/vcell-native-1.0-SNAPSHOT.jar \
"$ROOT_DIR/vcell-native/src/test/resources/TinySpacialProject_Application0.xml" \
"$ROOT_DIR/vcell-native/src/test/resources/TinySpatialProject_Application0.xml" \
"$ROOT_DIR/vcell-native/src/test/resources/TinySpatialProject_Application0.vcml" \
"Simulation0" \
"$ROOT_DIR/vcell-native/target/sbml-input"

# build vcell-native as native shared object library
Expand Down
10 changes: 7 additions & 3 deletions tests/test_libvcell.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from pathlib import Path

from libvcell.libvcell import libvcell
from libvcell import sbml_to_finite_volume_input, vcml_to_finite_volume_input


def test_vcml_to_finite_volume_input(temp_output_dir: Path, vcml_file_path: Path, vcml_sim_name: str) -> None:
vcml_content = vcml_file_path.read_text()
libvcell.vcml_to_finite_volume_input(
success, msg = vcml_to_finite_volume_input(
vcml_content=vcml_content, simulation_name=vcml_sim_name, output_dir_path=temp_output_dir
)
assert len(list(temp_output_dir.iterdir())) > 0
assert success is True
assert msg == "Success"


def test_sbml_to_finite_volume_input(temp_output_dir: Path, sbml_file_path: Path, vcml_sim_name: str) -> None:
sbml_content = sbml_file_path.read_text()
libvcell.sbml_to_finite_volume_input(sbml_content=sbml_content, output_dir_path=temp_output_dir)
success, msg = sbml_to_finite_volume_input(sbml_content=sbml_content, output_dir_path=temp_output_dir)
assert len(list(temp_output_dir.iterdir())) > 0
assert success is True
assert msg == "Success"
2 changes: 1 addition & 1 deletion vcell-native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
<imageName>libvcell</imageName>
<mainClass>org.vcell.libvcell.Entrypoints</mainClass>
<mainClass>org.vcell.libvcell.MainRecorder</mainClass>
</properties>

<dependencies>
Expand Down
90 changes: 7 additions & 83 deletions vcell-native/src/main/java/org/vcell/libvcell/Entrypoints.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
package org.vcell.libvcell;

import cbit.util.xml.VCLoggerException;
import cbit.vcell.biomodel.BioModel;
import cbit.vcell.geometry.GeometrySpec;
import cbit.vcell.mapping.MappingException;
import cbit.vcell.mapping.SimulationContext;
import cbit.vcell.mongodb.VCMongoMessage;
import cbit.vcell.parser.ExpressionException;
import cbit.vcell.resource.PropertyLoader;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.SolverException;
import cbit.vcell.solver.TimeBounds;
import cbit.vcell.solver.UniformOutputTimeSpec;
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.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.json.simple.JSONValue;
import org.vcell.sbml.FiniteVolumeRunUtil;
import org.vcell.sbml.vcell.SBMLExporter;
import org.vcell.sbml.vcell.SBMLImporter;

import java.beans.PropertyVetoException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.concurrent.ConcurrentHashMap;

import static org.vcell.libvcell.SolverUtils.sbmlToFiniteVolumeInput;
import static org.vcell.libvcell.SolverUtils.vcmlToFiniteVolumeInput;


public class Entrypoints {
private static final Logger logger = LogManager.getLogger(Entrypoints.class);
Expand All @@ -50,7 +31,7 @@ private static CCharPointer createString(String str) {

@CEntryPoint(name = "freeString", documentation = "Release memory allocated for a string")
public static void freeString(
IsolateThread thread,
IsolateThread ignoredThread,
CCharPointer ptr) {
if (ptr.isNonNull()) {
allocatedMemory.remove(ptr.rawValue());
Expand All @@ -75,7 +56,7 @@ public String toJson() {
Returns a JSON string with success status and message"""
)
public static CCharPointer entrypoint_vcmlToFiniteVolumeInput(
IsolateThread thread,
IsolateThread ignoredThread,
CCharPointer vcml_content,
CCharPointer simulation_name,
CCharPointer output_dir_path) {
Expand Down Expand Up @@ -105,7 +86,7 @@ public static CCharPointer entrypoint_vcmlToFiniteVolumeInput(
Returns a JSON string with success status and message"""
)
public static CCharPointer entrypoint_sbmlToFiniteVolumeInput(
IsolateThread thread,
IsolateThread ignoredThread,
CCharPointer sbml_content,
CCharPointer output_dir_path) {
ReturnValue returnValue;
Expand All @@ -123,61 +104,4 @@ public static CCharPointer entrypoint_sbmlToFiniteVolumeInput(
logger.info("Returning from sbmlToFiniteVolumeInput: " + json);
return createString(json);
}


public static void vcmlToFiniteVolumeInput(String vcml_content, String simulation_name, File outputDir) throws XmlParseException, MappingException, SolverException, ExpressionException {
GeometrySpec.avoidAWTImageCreation = true;
VCMongoMessage.enabled = false;
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(vcml_content));
bioModel.updateAll(false);
Simulation sim = bioModel.getSimulation(simulation_name);
FiniteVolumeRunUtil.writeInputFilesOnly(outputDir, sim);
}


public static void sbmlToFiniteVolumeInput(String sbml_content, File outputDir) throws MappingException, PropertyVetoException, SolverException, ExpressionException, VCLoggerException {
GeometrySpec.avoidAWTImageCreation = true;
VCMongoMessage.enabled = false;
SBMLExporter.MemoryVCLogger vcl = new SBMLExporter.MemoryVCLogger();
boolean bValidateSBML = true;
// input stream from sbml_content String
InputStream is = new ByteArrayInputStream(sbml_content.getBytes());
SBMLImporter importer = new SBMLImporter(is, vcl, bValidateSBML);
BioModel bioModel = importer.getBioModel();
bioModel.updateAll(false);

final double duration = 5.0; // endpoint arg
final double time_step = 0.1; // endpoint arg
//final ISize meshSize = new ISize(10, 10, 10); // future endpoint arg
SimulationContext simContext = bioModel.getSimulationContext(0);
Simulation sim = new Simulation(simContext.getMathDescription(), simContext);
sim.getSolverTaskDescription().setTimeBounds(new TimeBounds(0.0, duration));
sim.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec(time_step));

FiniteVolumeRunUtil.writeInputFilesOnly(outputDir, sim);
}



// Input Goes as Follows: SBML Input, Output dir
// "/Users/evalencia/Documents/VCell_Repositories/vcell/vcell-rest/src/test/resources/TinySpacialProject_Application0.xml"
// "/Users/evalencia/Documents/VCell_Repositories/vcell/vcell-nativelib/target/sbml-input"
public static void main(String[] args) {
try {
logger.info("Logger logging");
PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, "none");
PropertyLoader.setProperty(PropertyLoader.mongodbDatabase, "none");
File sbml_file = new File(args[0]);
// read sbml_file and create a string object
try (FileInputStream fis = new FileInputStream(sbml_file)) {
byte[] data = fis.readAllBytes();
logger.info("Read " + data.length + " bytes from " + sbml_file);
String sbml_str = new String(data);
sbmlToFiniteVolumeInput(sbml_str, new File(args[1]));
}
} catch (Exception e) {
System.out.println(e.getMessage());
logger.error("Error processing spatial model", e);
}
}
}
}
47 changes: 47 additions & 0 deletions vcell-native/src/main/java/org/vcell/libvcell/MainRecorder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.vcell.libvcell;

import cbit.vcell.resource.PropertyLoader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.FileInputStream;

import static org.vcell.libvcell.SolverUtils.sbmlToFiniteVolumeInput;
import static org.vcell.libvcell.SolverUtils.vcmlToFiniteVolumeInput;


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

public static void main(String[] args) {
try {
File sbml_file = new File(args[0]);
File vcml_file = new File(args[1]);
String vcml_sim_name = args[2];
File output_dir = new File(args[3]);
logger.info("Logger logging");
PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, "none");
PropertyLoader.setProperty(PropertyLoader.mongodbDatabase, "none");


try (FileInputStream f_sbml = new FileInputStream(sbml_file)) {
byte[] data = f_sbml.readAllBytes();
logger.info("Read " + data.length + " bytes from " + sbml_file.getAbsolutePath());
String sbml_str = new String(data);
sbmlToFiniteVolumeInput(sbml_str, output_dir);
//vcmlToFiniteVolumeInput(vcml_str, sim_name, new File(args[1]));
}
// read sbml_file and create a string object
try (FileInputStream f_vcml = new FileInputStream(vcml_file)) {
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);
}
} catch (Exception e) {
System.out.println(e.getMessage());
logger.error("Error processing spatial model", e);
}
}
}
Loading
Loading