diff --git a/biosimulators/Dockerfile b/biosimulators/Dockerfile new file mode 100644 index 00000000..4ce6145f --- /dev/null +++ b/biosimulators/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.9-slim-bullseye + +# Install OpenJDK 11 +RUN apt-get update && \ + apt-get install -y --no-install-recommends openjdk-11-jre-headless && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy and install Python dependencies +COPY biosimulators/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the dependencies folder and the compiled Java engine +COPY target/dependency /app/lib +COPY target/sbscl-2.1.1.jar /app/sbscl.jar + +# Copy the Python CLI and Entrypoint script +COPY biosimulators/main.py . +COPY biosimulators/entrypoint.sh . + +# Make the entrypoint script executable +RUN chmod +x /app/entrypoint.sh + +ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file diff --git a/biosimulators/entrypoint.sh b/biosimulators/entrypoint.sh new file mode 100644 index 00000000..4c3e8702 --- /dev/null +++ b/biosimulators/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Start the Java Gateway Server in the background. +# We include the main jar AND all dependency jars in the classpath. +java -cp "/app/sbscl.jar:/app/lib/*" org.simulator.biosimulators.BioSimulatorsGateway & + +# Give the Java server 2 seconds to initialize +sleep 2 + +# Execute the Python CLI, passing along any arguments provided to Docker +python /app/main.py "$@" \ No newline at end of file diff --git a/biosimulators/main.py b/biosimulators/main.py new file mode 100644 index 00000000..3da843af --- /dev/null +++ b/biosimulators/main.py @@ -0,0 +1,27 @@ +import argparse +from py4j.java_gateway import JavaGateway +from biosimulators_utils.combine.exec import exec_sedml_docs_in_archive + +def exec_sed_doc(doc, working_dir, base_out_path, rel_out_path=None, apply_xml_model_changes=False, log=None, indent=0, out_dir=None, config=None): + pass + +def exec_sed_task(task, variables, preprocessed_task=None, log=None, config=None): + gateway = JavaGateway() + sbscl_engine = gateway.entry_point + return {}, log + +def main(): + parser = argparse.ArgumentParser(description="SBSCL BioSimulators interface") + parser.add_argument("-i", "--archive", required=True, type=str) + parser.add_argument("-o", "--out-dir", required=True, type=str) + args = parser.parse_args() + + exec_sedml_docs_in_archive( + exec_sed_doc, + args.archive, + args.out_dir, + apply_xml_model_changes=True, + ) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/biosimulators/requirements.txt b/biosimulators/requirements.txt new file mode 100644 index 00000000..4a9fe4ad --- /dev/null +++ b/biosimulators/requirements.txt @@ -0,0 +1,3 @@ +biosimulators-utils +py4j +numpy \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7fe847cc..f5934fc2 100644 --- a/pom.xml +++ b/pom.xml @@ -518,6 +518,11 @@ + + net.sf.py4j + py4j + 0.10.9.7 + diff --git a/src/main/java/org/simulator/biosimulators/BioSimulatorsGateway.java b/src/main/java/org/simulator/biosimulators/BioSimulatorsGateway.java new file mode 100644 index 00000000..4715a82c --- /dev/null +++ b/src/main/java/org/simulator/biosimulators/BioSimulatorsGateway.java @@ -0,0 +1,17 @@ +package org.simulator.biosimulators; + +import py4j.GatewayServer; + +public class BioSimulatorsGateway { + + public BioSimulatorsGateway() { + } + + public static void main(String[] args) { + BioSimulatorsGateway app = new BioSimulatorsGateway(); + // Starts the server on the default port (25333) + GatewayServer server = new GatewayServer(app); + server.start(); + System.out.println("SBSCL Gateway Server Started"); + } +}