Skip to content

Repository files navigation

Python tooling for the CellDL Editor

This package allows CellML to be generated for BG-RDF bond-graph models created by the CellDL Editor. It does so by bundling the bg2cellml Python package with the Pyodide distribution, allowing bg2cellml to be used in a Javascript envirinment.

It is intended to be used with the @celldl/editor Vue 3 component and the @celldl/editor-rdf BG-RDF framework.

Installation

bun add @celldl/editor-python-tools

Usage

  • vite.config.ts:

The use of these tools in a Vite production environment requires a plugin for Pyodide:

import*asvitefrom'vite'import{pyodidePlugin}from'@celldl/editor-python-tools/vite'exportdefaultvite.defineConfig({plugins: [pyodidePlugin()]})
  • Application.vue

Besides a loaded Pyodide environment, the package requres an initialised BG-RDF framework.

<script setup lang="ts">import*asvuefrom'vue'// BG-RDF environmentimport*as$rdffrom'@celldl/editor-rdf'// Python toolsimport { initialisePython, typePyodideAPI } from'@celldl/editor-python-tools'import { loadInBrowser } from'@celldl/editor-python-tools/web'// Initialise BG-RDF and Python before importing the CellDLEditor Vue componentconst CellDLEditor =vue.defineAsyncComponent(async () => {await$rdf.initialise()const rdfInterface:$rdf.RdfInterface= { getRdfStatements: $rdf.bgRdfStatements, oximockRdfModule: $rdf.oxiRdfModule }awaitloadInBrowser().then(async (pyodideApi:PyodideAPI) => {awaitinitialisePython(pyodideApi, rdfInterface, (msg:string) => {console.log(msg) }) })returnimport('@celldl/editor')})// CellML generationimport { celldl2cellml, typeCellMLOutput } from'@celldl/editor-python-tools'const celldl:string='<svg><!-- Valid CellDL --></svg>'const celldlUri:string=`https://celldl.org/cellml/${name}`// Some URI to identify the sourceconst cellmlObject:CellMLOutput=celldl2cellml(celldlUri, celldl)if (cellmlObject.cellml) {const cellml:string=cellmlObject.cellmlconsole.log(cellml) // The resulting CellML} elseif (cellmlObject.issues) {const issues:string[] =cellmlObject.issuesconsole.log(issues) // Issues from generating CellML} else {window.alert('Unexpected exception generating CellML...')}</setup>

About

Python tools for the CellDL Editor

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages