diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3d8cf85..44058c1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ "3.7", "3.8", "3.9", "3.10"] + python-version: [ "3.8", "3.9", "3.10", "3.11"] runs-on: [ubuntu-latest, macos-latest, windows-latest] steps: @@ -34,6 +34,7 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install package run: | python -m pip install --upgrade pip @@ -47,7 +48,7 @@ jobs: run: | pip list - - name: Run some examples + - name: Run simple examples run: | cd examples python document.py @@ -55,16 +56,25 @@ jobs: cd test python test.py - ## Test NeuroML example + - name: Test NeuroML examples + if: ${{ matrix.python-version != '3.7'}} + run: | - cd ../neuroml2 + cd examples/neuroml2 python neuroml2_spec.py # Note: NeuroML files will be validated with OMV below + - name: Test SBML examples + if: ${{ matrix.python-version != '3.7'}} + run: | + + cd examples/sbml + ./regenerateAndTest.sh + - name: Run pytest run: | - pytest tests + pytest tests -v - name: Install & test NeuroMLlite run: | diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index e146eb91..5720078f 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -33,7 +33,7 @@ jobs: uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.9 diff --git a/.gitignore b/.gitignore index 3ce81332..e7c235dc 100644 --- a/.gitignore +++ b/.gitignore @@ -163,3 +163,4 @@ cython_debug/ .idea/ /examples/document.specification.bson /examples/neuroml2/hello_world.v.dat +/examples/sbml/example_sbml_test.xml diff --git a/README.md b/README.md index 12721e5a..91de3fd5 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ # Modelspec - [![Continuous builds](https://github.com/ModECI/modelspec/actions/workflows/ci.yml/badge.svg)](https://github.com/ModECI/modelspec/actions/workflows/ci.yml) [![PyPI](https://img.shields.io/pypi/v/modelspec)](https://pypi.org/project/modelspec/) - -Functionality for specifying the structure of models & enabling automatic serialization to them (e.g. in JSON and YAML format). +Functionality for specifying the allowed structure of models, facilitating the creation of APIs in Python for handling the models & enabling automatic serialization of instances of them (e.g. in JSON and YAML format). This package is being used by [NeuroMLlite](https://github.com/NeuroML/NeuroMLlite) & [MDF](https://github.com/ModECI/MDF). diff --git a/docs/sphinx/source/api/Contributors.md b/docs/sphinx/source/api/Contributors.md index e64cc00e..a43d6881 100644 --- a/docs/sphinx/source/api/Contributors.md +++ b/docs/sphinx/source/api/Contributors.md @@ -3,7 +3,7 @@ # Modelspec contributors This page list names and Github profiles of contributors to Modelspec, listed in no particular order. -This page is generated periodically, most recently on 2023-09-12. +This page is generated periodically, most recently on 2023-12-13. - Padraig Gleeson ([@pgleeson](https://github.com/pgleeson)) - Manifest Chakalov ([@mqnifestkelvin](https://github.com/mqnifestkelvin)) diff --git a/docs/sphinx/source/api/Introduction.md b/docs/sphinx/source/api/Introduction.md index 12721e5a..91de3fd5 100644 --- a/docs/sphinx/source/api/Introduction.md +++ b/docs/sphinx/source/api/Introduction.md @@ -1,10 +1,8 @@ # Modelspec - [![Continuous builds](https://github.com/ModECI/modelspec/actions/workflows/ci.yml/badge.svg)](https://github.com/ModECI/modelspec/actions/workflows/ci.yml) [![PyPI](https://img.shields.io/pypi/v/modelspec)](https://pypi.org/project/modelspec/) - -Functionality for specifying the structure of models & enabling automatic serialization to them (e.g. in JSON and YAML format). +Functionality for specifying the allowed structure of models, facilitating the creation of APIs in Python for handling the models & enabling automatic serialization of instances of them (e.g. in JSON and YAML format). This package is being used by [NeuroMLlite](https://github.com/NeuroML/NeuroMLlite) & [MDF](https://github.com/ModECI/MDF). diff --git a/docs/sphinx/source/api/Quickstart.md b/docs/sphinx/source/api/Quickstart.md index 832b149a..b6adbf02 100644 --- a/docs/sphinx/source/api/Quickstart.md +++ b/docs/sphinx/source/api/Quickstart.md @@ -15,18 +15,19 @@ More details, and importantly, how to set up a [virtual environment](https://vir ### Simple example -A basic example which illustrates how to create the specification for a document(model) and create serialized instances can be found [here](examples/README). +A basic example which illustrates how to create the specification for a document (i.e. the model definition for a document) and create serialized instances can be found [here](examples/README). ### Serialization formats -Python scripts can be used to generate the specification of a type of model(e.g. [this](https://github.com/ModECI/modelspec/blob/main/examples/document.py)), but the models are saved in standardized format in either text based [JSON](https://github.com/ModECI/modelspec/blob/main/examples/document.json) or [YAML](https://github.com/ModECI/modelspec/blob/main/examples/document.yaml) formats or in binary [BSON](https://github.com/ModECI/modelspec/blob/main/examples/document.bson) format. Support for XML serialization is under development. +Python scripts can be used to generate the specification of a type of model (e.g. [this](https://github.com/ModECI/modelspec/blob/main/examples/document.py)), but the models are saved in standardized format in either text based ([JSON](https://github.com/ModECI/modelspec/blob/main/examples/document.json) or [YAML](https://github.com/ModECI/modelspec/blob/main/examples/document.yaml)) formats or in binary ([BSON](https://github.com/ModECI/modelspec/blob/main/examples/document.bson)) format. Support for [XML](https://github.com/ModECI/modelspec/blob/main/examples/document.xml) serialization has recently been added. ### Current formats using modelspec -#### MDF +#### MDF (Model Description Format) -MDF uses modelspec to create the structure of its models and convert the models into serialized formats such as JSON, YAML, and BSON. +[ModECI's MDF](https://modeci.org/quickstart) uses modelspec to create the structure of its models and convert the models into serialized formats such as JSON, YAML, and BSON. #### NeuroML -NeuroMLlite uses modelspec to create the structure of its models and convert the models into serialize formats such as JSON, YAML, and BSON. +[NeuroMLlite](https://github.com/NeuroML/NeuroMLlite) uses modelspec to create the structure of its models and convert the models into serialize formats such as JSON, YAML, and BSON. +The XML serialisation of modelspec will be useful for integrating NeuroML 2 files into the framework, see [here](https://github.com/ModECI/modelspec/tree/main/examples/neuroml2). diff --git a/docs/sphinx/source/api/examples/document.bson b/docs/sphinx/source/api/examples/document.bson index 61eb48f7..577bfeed 100644 Binary files a/docs/sphinx/source/api/examples/document.bson and b/docs/sphinx/source/api/examples/document.bson differ diff --git a/docs/sphinx/source/api/examples/document.json b/docs/sphinx/source/api/examples/document.json index 5e61879e..f94e651c 100644 --- a/docs/sphinx/source/api/examples/document.json +++ b/docs/sphinx/source/api/examples/document.json @@ -1,6 +1,7 @@ { "MyBook": { "title": "My life in Python", + "ISBN": 123, "sections": { "Abstract": { "paragraphs": [ diff --git a/docs/sphinx/source/api/examples/document.py b/docs/sphinx/source/api/examples/document.py index c57be063..578099c7 100644 --- a/docs/sphinx/source/api/examples/document.py +++ b/docs/sphinx/source/api/examples/document.py @@ -52,7 +52,7 @@ class Document(Base): sections: List[Section] = field(factory=list) -doc = Document(id="MyBook") +doc = Document(id="MyBook", ISBN=123) doc.title = "My life in Python" a = Section(id="Abstract") diff --git a/docs/sphinx/source/api/examples/document.xml b/docs/sphinx/source/api/examples/document.xml index 4641d46e..a7f9fedc 100644 --- a/docs/sphinx/source/api/examples/document.xml +++ b/docs/sphinx/source/api/examples/document.xml @@ -1,5 +1,5 @@ - - + +
diff --git a/docs/sphinx/source/api/examples/document.yaml b/docs/sphinx/source/api/examples/document.yaml index 54e03ea7..a5a8df3f 100644 --- a/docs/sphinx/source/api/examples/document.yaml +++ b/docs/sphinx/source/api/examples/document.yaml @@ -1,5 +1,6 @@ MyBook: title: My life in Python + ISBN: 123 sections: Abstract: paragraphs: diff --git a/examples/COMBINE.md b/examples/COMBINE.md new file mode 100644 index 00000000..3aee77c5 --- /dev/null +++ b/examples/COMBINE.md @@ -0,0 +1,29 @@ +# COMBINE standards in modelspec + +![combine](images/combine.png) + +To illustrate the utility of modelspec, and to create a uniform, compatible set of APIs across a diverse range of model specification formats, we are investigating the [COMBINE set of standards in computational biology](https://co.mbine.org/standards/), and attempting to express these formats in modelspec. + +## NeuroML + +![neuroml](images/neuroml.png) + +A preliminary version of an API for [NeuroML2](https://docs.neuroml.org/Userdocs/NeuroMLv2.html) can be found [here](neuroml2). This allows generation of NeuroML2 models using the modelspec based API, saving as valid XML, as well as JSON, YAML and BSON equivalents. See [neuroml2_spec.py](neuroml2/neuroml2_spec.py). + +[NeuroMLlite](https://github.com/NeuroML/NeuroMLlite) already uses modelspec as its primary specification format. See [here](https://github.com/NeuroML/NeuroMLlite/blob/master/neuromllite/__init__.py). + +## SBML + +![combine](images/sbml.png) + +Work towards an API for [SBML](https://www.sbml.org/) can be found [here](sbml). + +An example of an SBML file generated from this is [here](sbml/test_minimal_example.xml). + +## CellML + +TODO... + +## SED-ML + +TODO... diff --git a/examples/document.bson b/examples/document.bson index 61eb48f7..577bfeed 100644 Binary files a/examples/document.bson and b/examples/document.bson differ diff --git a/examples/document.json b/examples/document.json index 5e61879e..f94e651c 100644 --- a/examples/document.json +++ b/examples/document.json @@ -1,6 +1,7 @@ { "MyBook": { "title": "My life in Python", + "ISBN": 123, "sections": { "Abstract": { "paragraphs": [ diff --git a/examples/document.py b/examples/document.py index c57be063..578099c7 100644 --- a/examples/document.py +++ b/examples/document.py @@ -52,7 +52,7 @@ class Document(Base): sections: List[Section] = field(factory=list) -doc = Document(id="MyBook") +doc = Document(id="MyBook", ISBN=123) doc.title = "My life in Python" a = Section(id="Abstract") diff --git a/examples/document.xml b/examples/document.xml index 4641d46e..a7f9fedc 100644 --- a/examples/document.xml +++ b/examples/document.xml @@ -1,5 +1,5 @@ - - + +
diff --git a/examples/document.yaml b/examples/document.yaml index 54e03ea7..a5a8df3f 100644 --- a/examples/document.yaml +++ b/examples/document.yaml @@ -1,5 +1,6 @@ MyBook: title: My life in Python + ISBN: 123 sections: Abstract: paragraphs: diff --git a/examples/images/combine.png b/examples/images/combine.png new file mode 100644 index 00000000..3ba0e32d Binary files /dev/null and b/examples/images/combine.png differ diff --git a/examples/images/neuroml.png b/examples/images/neuroml.png new file mode 100644 index 00000000..297ee4e7 Binary files /dev/null and b/examples/images/neuroml.png differ diff --git a/examples/images/sbml.png b/examples/images/sbml.png new file mode 100644 index 00000000..1fed3ed0 Binary files /dev/null and b/examples/images/sbml.png differ diff --git a/examples/neuroml2/TestNeuroML.xml b/examples/neuroml2/TestNeuroML.xml index 70586cf6..6319bb51 100644 --- a/examples/neuroml2/TestNeuroML.xml +++ b/examples/neuroml2/TestNeuroML.xml @@ -1,4 +1,4 @@ - + diff --git a/examples/neuroml2/neuroml2_spec.py b/examples/neuroml2/neuroml2_spec.py index 6b07fda5..36422ab5 100644 --- a/examples/neuroml2/neuroml2_spec.py +++ b/examples/neuroml2/neuroml2_spec.py @@ -197,7 +197,7 @@ class neuroml(Base): with open("NeuroML2.specification.yaml", "w") as d: yy = yaml.dump(doc_dict, indent=4, sort_keys=False) - print(yy) + # print(yy) d.write(yy) from modelspec.utils import load_xml diff --git a/examples/sbml/SBML.md b/examples/sbml/SBML.md new file mode 100644 index 00000000..664e42e0 --- /dev/null +++ b/examples/sbml/SBML.md @@ -0,0 +1,2265 @@ +## sbml +The top-level SBML container implementing SBML 3.2. See sbml.level-3.version-2.core.release-2.pdf section 4. +http://www.sbml.org/sbml/level3/version2/ + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
idstr
xmlnsstr string, fixed to "http://www.sbml.org/sbml/level3/version2/core"
levelstr SBML level, fixed to 3
versionstrSBML version, fixed to 2
modelModel Optional model
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Model +The model + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
substanceUnitsstr UnitSIdRef optional
timeUnitsstr UnitSIdRef optional
volumeUnitsstr UnitSIdRef optional
areaUnitsstr UnitSIdRef optional
lengthUnitsstr UnitSIdRef optional
extentUnitsstr UnitSIdRef optional
conversionFactorstrSIdRef optional
listOfUnitDefinitionsListOfUnitDefinitions
+ +### Allowed children + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
listOfFunctionDefinitionsFunctionDefinition
listOfCompartmentsCompartment
listOfSpeciesSpecies
listOfParametersParameter
listOfInitialAssignmentsInitialAssignment
listOfRulesRule
listOfConstraintsConstraint
listOfReactionsReaction
listOfEventsEvent
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## ListOfUnitDefinitions +A listOfUnitDefinitions + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
+ +### Allowed children + + + + + + + + +
listOfUnitDefinitionsunitDefinitionthe actual list Of Unit Definitions
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## unitDefinition +A unit definition + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
idstr
listOfUnitsListOfUnitsList of units used to compose the definition
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## ListOfUnits +A listOfUnits + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
+ +### Allowed children + + + + + + + + +
listOfUnitsunitthe actual list Of Units
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## unit +A unit used to compose a unit definition. unit = (multiplier x 10^scale x kind)^exponent + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
kindstrbase unit (base or derived SI units only, see Table 2 of the SBML spec)
exponentstrdouble
scalestrinteger
multiplierstrdouble
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## FunctionDefinition +A function definition using MathML + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
sidstr SId optional
mathMathMathML function definition optional
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Math +Subset of MathML 2.0 used to define all formulae in SBML + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstr
contentstr
+ +## Compartment +A compartment + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
constantboolwhether size is fixed
spatialDimensionsfloateg 3 for three dimensional space etc
sizefloatinitial size of compartment
unitsstrunits being used to define the compartment's size
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Species +A species: entities of the same kind participating in reactions within a specific compartment + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
compartmentstrSIdRef
hasOnlySubstanceUnitsboolboolean
boundaryConditionboolboolean
constantboolboolean
initialAmountfloatdouble optional
initialConcentrationfloatdouble optional
substanceUnitsstrUnitSIdRef optional
conversionFactorstrSIdRef optional
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Parameter +A parameter + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
constantboolboolean
valuefloatdouble optional
unitsstrUnitSIdRef optional
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## InitialAssignment +An initial assignment + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
symbolstrSIdRef required
mathstrMathML optional
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Rule +A rule, either algebraic, assignment or rate + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
mathstrMathML optional
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Constraint +A model constraint + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
mathstr MathML optional
messagestrXHTML 1.0 optional
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Reaction +A model reaction + +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
reversibleboolboolean
compartmentstrSIdRef optional
kineticLawKineticLaw
+ +### Allowed children + + + + + + + + + + + + + + + + + + + + + + +
listOfReactantsSpeciesReference
listOfProductsSpeciesReference
listOfModifiersModifierSpeciesReference
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## KineticLaw +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
mathstr
+ +### Allowed children + + + + + + + + +
listOfLocalParametersLocalParameter
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## LocalParameter +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
valuefloat
unitsstrUnitSIdRef optional
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## SpeciesReference +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
speciesstrSIdRef
stoichiometryfloatdouble optional
constantboolboolean
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## SpeciesReference +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
speciesstrSIdRef
stoichiometryfloatdouble optional
constantboolboolean
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## ModifierSpeciesReference +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
speciesstrSIdRef
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Event +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
useValuesFromTriggerTimebool
triggerTrigger
priorityPriority
delayDelay
+ +### Allowed children + + + + + + + + +
listOfEventAssignmentsEventAssignment
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Trigger +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
initialValuebool
persistentbool
mathstr
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Priority +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
mathstr
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## Delay +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
mathstr
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
+ +## EventAssignment +### Allowed parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sidstr SId optional
namestr string optional
metaidstr XML ID optional
sboTermstrSBOTerm optional
notesNotes XHTML 1.0 optional
annotationstrXML content optional
mathstr
variablestrSIdRef
+ +## Notes +XHTML field of SBase + +### Allowed parameters + + + + + + + + + + + + + + + +
xmlnsstrstr fixed "http://www.w3.org/1999/xhtml"
contentstrstr valid XHTML
diff --git a/examples/sbml/SBML.rst b/examples/sbml/SBML.rst new file mode 100644 index 00000000..083cfc0f --- /dev/null +++ b/examples/sbml/SBML.rst @@ -0,0 +1,884 @@ +==== +sbml +==== +The top-level SBML container implementing SBML 3.2. See sbml.level-3.version-2.core.release-2.pdf section 4. +http://www.sbml.org/sbml/level3/version2/ + +**Allowed parameters** + +=============== ======================================= ================================================================ +Allowed field Data Type Description +=============== ======================================= ================================================================ +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**id** str +**xmlns** str string, fixed to "http://www.sbml.org/sbml/level3/version2/core" +**level** str SBML level, fixed to 3 +**version** str SBML version, fixed to 2 +**model** ` <#model>`__ Optional model +=============== ======================================= ================================================================ + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +===== +Model +===== +The model + +**Allowed parameters** + +========================= ======================================================================= ==================== +Allowed field Data Type Description +========================= ======================================================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**substanceUnits** str UnitSIdRef optional +**timeUnits** str UnitSIdRef optional +**volumeUnits** str UnitSIdRef optional +**areaUnits** str UnitSIdRef optional +**lengthUnits** str UnitSIdRef optional +**extentUnits** str UnitSIdRef optional +**conversionFactor** str SIdRef optional +**listOfUnitDefinitions** ` <#listofunitdefinitions>`__ +========================= ======================================================================= ==================== + +**Allowed children** + +============================= ============================================ ============= +Allowed child Data Type Description +============================= ============================================ ============= +**listOfFunctionDefinitions** `FunctionDefinition <#functiondefinition>`__ +**listOfCompartments** `Compartment <#compartment>`__ +**listOfSpecies** `Species <#species>`__ +**listOfParameters** `Parameter <#parameter>`__ +**listOfInitialAssignments** `InitialAssignment <#initialassignment>`__ +**listOfRules** `Rule <#rule>`__ +**listOfConstraints** `Constraint <#constraint>`__ +**listOfReactions** `Reaction <#reaction>`__ +**listOfEvents** `Event <#event>`__ +============================= ============================================ ============= + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +===================== +ListOfUnitDefinitions +===================== +A listOfUnitDefinitions + +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +=============== ======================================= ==================== + +**Allowed children** + +========================= ==================================== =================================== +Allowed child Data Type Description +========================= ==================================== =================================== +**listOfUnitDefinitions** `unitDefinition <#unitdefinition>`__ the actual list Of Unit Definitions +========================= ==================================== =================================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +============== +unitDefinition +============== +A unit definition + +**Allowed parameters** + +=============== =================================================== ============================================ +Allowed field Data Type Description +=============== =================================================== ============================================ +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**id** str +**listOfUnits** ` <#listofunits>`__ List of units used to compose the definition +=============== =================================================== ============================================ + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +=========== +ListOfUnits +=========== +A listOfUnits + +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +=============== ======================================= ==================== + +**Allowed children** + +=============== ================ ======================== +Allowed child Data Type Description +=============== ================ ======================== +**listOfUnits** `unit <#unit>`__ the actual list Of Units +=============== ================ ======================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +==== +unit +==== +A unit used to compose a unit definition. unit = (multiplier x 10^scale x kind)^exponent + +**Allowed parameters** + +=============== ======================================= ======================================================================= +Allowed field Data Type Description +=============== ======================================= ======================================================================= +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**kind** str base unit (base or derived SI units only, see Table 2 of the SBML spec) +**exponent** str double +**scale** str integer +**multiplier** str double +=============== ======================================= ======================================================================= + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +================== +FunctionDefinition +================== +A function definition using MathML + +**Allowed parameters** + +=============== ======================================= =================================== +Allowed field Data Type Description +=============== ======================================= =================================== +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**sid** str SId optional +**math** ` <#math>`__ MathML function definition optional +=============== ======================================= =================================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +==== +Math +==== +Subset of MathML 2.0 used to define all formulae in SBML + +**Allowed parameters** + +=============== =========== ============= +Allowed field Data Type Description +=============== =========== ============= +**xmlns** str +**content** str +=============== =========== ============= + +=========== +Compartment +=========== +A compartment + +**Allowed parameters** + +===================== ======================================= ================================================= +Allowed field Data Type Description +===================== ======================================= ================================================= +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**constant** bool whether size is fixed +**spatialDimensions** float eg 3 for three dimensional space etc +**size** float initial size of compartment +**units** str units being used to define the compartment's size +===================== ======================================= ================================================= + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +======= +Species +======= +A species: entities of the same kind participating in reactions within a specific compartment + +**Allowed parameters** + +========================= ======================================= ==================== +Allowed field Data Type Description +========================= ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**compartment** str SIdRef +**hasOnlySubstanceUnits** bool boolean +**boundaryCondition** bool boolean +**constant** bool boolean +**initialAmount** float double optional +**initialConcentration** float double optional +**substanceUnits** str UnitSIdRef optional +**conversionFactor** str SIdRef optional +========================= ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +========= +Parameter +========= +A parameter + +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**constant** bool boolean +**value** float double optional +**units** str UnitSIdRef optional +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +================= +InitialAssignment +================= +An initial assignment + +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**symbol** str SIdRef required +**math** str MathML optional +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +==== +Rule +==== +A rule, either algebraic, assignment or rate + +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**math** str MathML optional +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +========== +Constraint +========== +A model constraint + +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**math** str MathML optional +**message** str XHTML 1.0 optional +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +======== +Reaction +======== +A model reaction + +**Allowed parameters** + +=============== ================================================= ==================== +Allowed field Data Type Description +=============== ================================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**reversible** bool boolean +**compartment** str SIdRef optional +**kineticLaw** ` <#kineticlaw>`__ +=============== ================================================= ==================== + +**Allowed children** + +=================== ======================================================== ============= +Allowed child Data Type Description +=================== ======================================================== ============= +**listOfReactants** `SpeciesReference <#speciesreference>`__ +**listOfProducts** `SpeciesReference <#speciesreference>`__ +**listOfModifiers** `ModifierSpeciesReference <#modifierspeciesreference>`__ +=================== ======================================================== ============= + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +========== +KineticLaw +========== +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**math** str +=============== ======================================= ==================== + +**Allowed children** + +========================= ==================================== ============= +Allowed child Data Type Description +========================= ==================================== ============= +**listOfLocalParameters** `LocalParameter <#localparameter>`__ +========================= ==================================== ============= + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +============== +LocalParameter +============== +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**value** float +**units** str UnitSIdRef optional +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +================ +SpeciesReference +================ +**Allowed parameters** + +================= ======================================= ==================== +Allowed field Data Type Description +================= ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**species** str SIdRef +**stoichiometry** float double optional +**constant** bool boolean +================= ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +================ +SpeciesReference +================ +**Allowed parameters** + +================= ======================================= ==================== +Allowed field Data Type Description +================= ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**species** str SIdRef +**stoichiometry** float double optional +**constant** bool boolean +================= ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +======================== +ModifierSpeciesReference +======================== +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**species** str SIdRef +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +===== +Event +===== +**Allowed parameters** + +============================ ============================================= ==================== +Allowed field Data Type Description +============================ ============================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**useValuesFromTriggerTime** bool +**trigger** ` <#trigger>`__ +**priority** ` <#priority>`__ +**delay** ` <#delay>`__ +============================ ============================================= ==================== + +**Allowed children** + +========================== ====================================== ============= +Allowed child Data Type Description +========================== ====================================== ============= +**listOfEventAssignments** `EventAssignment <#eventassignment>`__ +========================== ====================================== ============= + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +======= +Trigger +======= +**Allowed parameters** + +================ ======================================= ==================== +Allowed field Data Type Description +================ ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**initialValue** bool +**persistent** bool +**math** str +================ ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +======== +Priority +======== +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**math** str +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +===== +Delay +===== +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**math** str +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== + +=============== +EventAssignment +=============== +**Allowed parameters** + +=============== ======================================= ==================== +Allowed field Data Type Description +=============== ======================================= ==================== +**sid** str SId optional +**name** str string optional +**metaid** str XML ID optional +**sboTerm** str SBOTerm optional +**notes** ` <#notes>`__ XHTML 1.0 optional +**annotation** str XML content optional +**math** str +**variable** str SIdRef +=============== ======================================= ==================== + +===== +Notes +===== +XHTML field of SBase + +**Allowed parameters** + +=============== =========== ======================================== +Allowed field Data Type Description +=============== =========== ======================================== +**xmlns** str str fixed "http://www.w3.org/1999/xhtml" +**content** str str valid XHTML +=============== =========== ======================================== diff --git a/examples/sbml/SBML.specification.json b/examples/sbml/SBML.specification.json new file mode 100644 index 00000000..4380131c --- /dev/null +++ b/examples/sbml/SBML.specification.json @@ -0,0 +1,1006 @@ +{ + "sbml": { + "definition": "The top-level SBML container implementing SBML 3.2. See sbml.level-3.version-2.core.release-2.pdf section 4.\nhttp://www.sbml.org/sbml/level3/version2/", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "id": { + "type": "str", + "description": "" + }, + "xmlns": { + "type": "str", + "description": " string, fixed to \"http://www.sbml.org/sbml/level3/version2/core\"" + }, + "level": { + "type": "str", + "description": " SBML level, fixed to 3" + }, + "version": { + "type": "str", + "description": "SBML version, fixed to 2" + }, + "model": { + "type": "Model", + "description": " Optional model" + } + } + }, + "Notes": { + "definition": "XHTML field of SBase", + "allowed_parameters": { + "xmlns": { + "type": "str", + "description": "str fixed \"http://www.w3.org/1999/xhtml\"" + }, + "content": { + "type": "str", + "description": "str valid XHTML" + } + } + }, + "Model": { + "definition": "The model", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "substanceUnits": { + "type": "str", + "description": " UnitSIdRef optional" + }, + "timeUnits": { + "type": "str", + "description": " UnitSIdRef optional" + }, + "volumeUnits": { + "type": "str", + "description": " UnitSIdRef optional" + }, + "areaUnits": { + "type": "str", + "description": " UnitSIdRef optional" + }, + "lengthUnits": { + "type": "str", + "description": " UnitSIdRef optional" + }, + "extentUnits": { + "type": "str", + "description": " UnitSIdRef optional" + }, + "conversionFactor": { + "type": "str", + "description": "SIdRef optional" + }, + "listOfUnitDefinitions": { + "type": "ListOfUnitDefinitions", + "description": "" + } + }, + "allowed_children": { + "listOfFunctionDefinitions": { + "type": "FunctionDefinition", + "description": "" + }, + "listOfCompartments": { + "type": "Compartment", + "description": "" + }, + "listOfSpecies": { + "type": "Species", + "description": "" + }, + "listOfParameters": { + "type": "Parameter", + "description": "" + }, + "listOfInitialAssignments": { + "type": "InitialAssignment", + "description": "" + }, + "listOfRules": { + "type": "Rule", + "description": "" + }, + "listOfConstraints": { + "type": "Constraint", + "description": "" + }, + "listOfReactions": { + "type": "Reaction", + "description": "" + }, + "listOfEvents": { + "type": "Event", + "description": "" + } + } + }, + "ListOfUnitDefinitions": { + "definition": "A listOfUnitDefinitions", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + } + }, + "allowed_children": { + "listOfUnitDefinitions": { + "type": "unitDefinition", + "description": "the actual list Of Unit Definitions" + } + } + }, + "unitDefinition": { + "definition": "A unit definition", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "id": { + "type": "str", + "description": "" + }, + "listOfUnits": { + "type": "ListOfUnits", + "description": "List of units used to compose the definition" + } + } + }, + "ListOfUnits": { + "definition": "A listOfUnits", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + } + }, + "allowed_children": { + "listOfUnits": { + "type": "unit", + "description": "the actual list Of Units" + } + } + }, + "unit": { + "definition": "A unit used to compose a unit definition. unit = (multiplier x 10^scale x kind)^exponent", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "kind": { + "type": "str", + "description": "base unit (base or derived SI units only, see Table 2 of the SBML spec)" + }, + "exponent": { + "type": "str", + "description": "double" + }, + "scale": { + "type": "str", + "description": "integer" + }, + "multiplier": { + "type": "str", + "description": "double" + } + } + }, + "FunctionDefinition": { + "definition": "A function definition using MathML", + "allowed_parameters": { + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "sid": { + "type": "str", + "description": " SId optional" + }, + "math": { + "type": "Math", + "description": "MathML function definition optional" + } + } + }, + "Math": { + "definition": "Subset of MathML 2.0 used to define all formulae in SBML", + "allowed_parameters": { + "xmlns": { + "type": "str", + "description": "" + }, + "content": { + "type": "str", + "description": "" + } + } + }, + "Compartment": { + "definition": "A compartment", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "constant": { + "type": "bool", + "description": "whether size is fixed" + }, + "spatialDimensions": { + "type": "float", + "description": "eg 3 for three dimensional space etc" + }, + "size": { + "type": "float", + "description": "initial size of compartment" + }, + "units": { + "type": "str", + "description": "units being used to define the compartment's size" + } + } + }, + "Species": { + "definition": "A species: entities of the same kind participating in reactions within a specific compartment", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "compartment": { + "type": "str", + "description": "SIdRef" + }, + "hasOnlySubstanceUnits": { + "type": "bool", + "description": "boolean" + }, + "boundaryCondition": { + "type": "bool", + "description": "boolean" + }, + "constant": { + "type": "bool", + "description": "boolean" + }, + "initialAmount": { + "type": "float", + "description": "double optional" + }, + "initialConcentration": { + "type": "float", + "description": "double optional" + }, + "substanceUnits": { + "type": "str", + "description": "UnitSIdRef optional" + }, + "conversionFactor": { + "type": "str", + "description": "SIdRef optional" + } + } + }, + "Parameter": { + "definition": "A parameter", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "constant": { + "type": "bool", + "description": "boolean" + }, + "value": { + "type": "float", + "description": "double optional" + }, + "units": { + "type": "str", + "description": "UnitSIdRef optional" + } + } + }, + "InitialAssignment": { + "definition": "An initial assignment", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "symbol": { + "type": "str", + "description": "SIdRef required" + }, + "math": { + "type": "str", + "description": "MathML optional" + } + } + }, + "Rule": { + "definition": "A rule, either algebraic, assignment or rate", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "math": { + "type": "str", + "description": "MathML optional" + } + } + }, + "Constraint": { + "definition": "A model constraint", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "math": { + "type": "str", + "description": " MathML optional" + }, + "message": { + "type": "str", + "description": "XHTML 1.0 optional" + } + } + }, + "Reaction": { + "definition": "A model reaction", + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "reversible": { + "type": "bool", + "description": "boolean" + }, + "compartment": { + "type": "str", + "description": "SIdRef optional" + }, + "kineticLaw": { + "type": "KineticLaw", + "description": "" + } + }, + "allowed_children": { + "listOfReactants": { + "type": "SpeciesReference", + "description": "" + }, + "listOfProducts": { + "type": "SpeciesReference", + "description": "" + }, + "listOfModifiers": { + "type": "ModifierSpeciesReference", + "description": "" + } + } + }, + "KineticLaw": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "math": { + "type": "str", + "description": "" + } + }, + "allowed_children": { + "listOfLocalParameters": { + "type": "LocalParameter", + "description": "" + } + } + }, + "LocalParameter": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "value": { + "type": "float", + "description": "" + }, + "units": { + "type": "str", + "description": "UnitSIdRef optional" + } + } + }, + "SpeciesReference": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "species": { + "type": "str", + "description": "SIdRef" + }, + "stoichiometry": { + "type": "float", + "description": "double optional" + }, + "constant": { + "type": "bool", + "description": "boolean" + } + } + }, + "ModifierSpeciesReference": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "species": { + "type": "str", + "description": "SIdRef" + } + } + }, + "Event": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "useValuesFromTriggerTime": { + "type": "bool", + "description": "" + }, + "trigger": { + "type": "Trigger", + "description": "" + }, + "priority": { + "type": "Priority", + "description": "" + }, + "delay": { + "type": "Delay", + "description": "" + } + }, + "allowed_children": { + "listOfEventAssignments": { + "type": "EventAssignment", + "description": "" + } + } + }, + "Trigger": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "initialValue": { + "type": "bool", + "description": "" + }, + "persistent": { + "type": "bool", + "description": "" + }, + "math": { + "type": "str", + "description": "" + } + } + }, + "Priority": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "math": { + "type": "str", + "description": "" + } + } + }, + "Delay": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "math": { + "type": "str", + "description": "" + } + } + }, + "EventAssignment": { + "allowed_parameters": { + "sid": { + "type": "str", + "description": " SId optional" + }, + "name": { + "type": "str", + "description": " string optional" + }, + "metaid": { + "type": "str", + "description": " XML ID optional" + }, + "sboTerm": { + "type": "str", + "description": "SBOTerm optional" + }, + "notes": { + "type": "Notes", + "description": " XHTML 1.0 optional" + }, + "annotation": { + "type": "str", + "description": "XML content optional" + }, + "math": { + "type": "str", + "description": "" + }, + "variable": { + "type": "str", + "description": "SIdRef" + } + } + } +} diff --git a/examples/sbml/SBML.specification.yaml b/examples/sbml/SBML.specification.yaml new file mode 100644 index 00000000..0a420b31 --- /dev/null +++ b/examples/sbml/SBML.specification.yaml @@ -0,0 +1,735 @@ +sbml: + definition: 'The top-level SBML container implementing SBML 3.2. See sbml.level-3.version-2.core.release-2.pdf + section 4. + + http://www.sbml.org/sbml/level3/version2/' + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + id: + type: str + description: '' + xmlns: + type: str + description: ' string, fixed to "http://www.sbml.org/sbml/level3/version2/core"' + level: + type: str + description: ' SBML level, fixed to 3' + version: + type: str + description: SBML version, fixed to 2 + model: + type: Model + description: ' Optional model' +Notes: + definition: XHTML field of SBase + allowed_parameters: + xmlns: + type: str + description: str fixed "http://www.w3.org/1999/xhtml" + content: + type: str + description: str valid XHTML +Model: + definition: The model + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + substanceUnits: + type: str + description: ' UnitSIdRef optional' + timeUnits: + type: str + description: ' UnitSIdRef optional' + volumeUnits: + type: str + description: ' UnitSIdRef optional' + areaUnits: + type: str + description: ' UnitSIdRef optional' + lengthUnits: + type: str + description: ' UnitSIdRef optional' + extentUnits: + type: str + description: ' UnitSIdRef optional' + conversionFactor: + type: str + description: SIdRef optional + listOfUnitDefinitions: + type: ListOfUnitDefinitions + description: '' + allowed_children: + listOfFunctionDefinitions: + type: FunctionDefinition + description: '' + listOfCompartments: + type: Compartment + description: '' + listOfSpecies: + type: Species + description: '' + listOfParameters: + type: Parameter + description: '' + listOfInitialAssignments: + type: InitialAssignment + description: '' + listOfRules: + type: Rule + description: '' + listOfConstraints: + type: Constraint + description: '' + listOfReactions: + type: Reaction + description: '' + listOfEvents: + type: Event + description: '' +ListOfUnitDefinitions: + definition: A listOfUnitDefinitions + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + allowed_children: + listOfUnitDefinitions: + type: unitDefinition + description: the actual list Of Unit Definitions +unitDefinition: + definition: A unit definition + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + id: + type: str + description: '' + listOfUnits: + type: ListOfUnits + description: List of units used to compose the definition +ListOfUnits: + definition: A listOfUnits + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + allowed_children: + listOfUnits: + type: unit + description: the actual list Of Units +unit: + definition: A unit used to compose a unit definition. unit = (multiplier x 10^scale + x kind)^exponent + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + kind: + type: str + description: base unit (base or derived SI units only, see Table 2 of + the SBML spec) + exponent: + type: str + description: double + scale: + type: str + description: integer + multiplier: + type: str + description: double +FunctionDefinition: + definition: A function definition using MathML + allowed_parameters: + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + sid: + type: str + description: ' SId optional' + math: + type: Math + description: MathML function definition optional +Math: + definition: Subset of MathML 2.0 used to define all formulae in SBML + allowed_parameters: + xmlns: + type: str + description: '' + content: + type: str + description: '' +Compartment: + definition: A compartment + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + constant: + type: bool + description: whether size is fixed + spatialDimensions: + type: float + description: eg 3 for three dimensional space etc + size: + type: float + description: initial size of compartment + units: + type: str + description: units being used to define the compartment's size +Species: + definition: 'A species: entities of the same kind participating in reactions within + a specific compartment' + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + compartment: + type: str + description: SIdRef + hasOnlySubstanceUnits: + type: bool + description: boolean + boundaryCondition: + type: bool + description: boolean + constant: + type: bool + description: boolean + initialAmount: + type: float + description: double optional + initialConcentration: + type: float + description: double optional + substanceUnits: + type: str + description: UnitSIdRef optional + conversionFactor: + type: str + description: SIdRef optional +Parameter: + definition: A parameter + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + constant: + type: bool + description: boolean + value: + type: float + description: double optional + units: + type: str + description: UnitSIdRef optional +InitialAssignment: + definition: An initial assignment + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + symbol: + type: str + description: SIdRef required + math: + type: str + description: MathML optional +Rule: + definition: A rule, either algebraic, assignment or rate + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + math: + type: str + description: MathML optional +Constraint: + definition: A model constraint + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + math: + type: str + description: ' MathML optional' + message: + type: str + description: XHTML 1.0 optional +Reaction: + definition: A model reaction + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + reversible: + type: bool + description: boolean + compartment: + type: str + description: SIdRef optional + kineticLaw: + type: KineticLaw + description: '' + allowed_children: + listOfReactants: + type: SpeciesReference + description: '' + listOfProducts: + type: SpeciesReference + description: '' + listOfModifiers: + type: ModifierSpeciesReference + description: '' +KineticLaw: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + math: + type: str + description: '' + allowed_children: + listOfLocalParameters: + type: LocalParameter + description: '' +LocalParameter: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + value: + type: float + description: '' + units: + type: str + description: UnitSIdRef optional +SpeciesReference: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + species: + type: str + description: SIdRef + stoichiometry: + type: float + description: double optional + constant: + type: bool + description: boolean +ModifierSpeciesReference: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + species: + type: str + description: SIdRef +Event: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + useValuesFromTriggerTime: + type: bool + description: '' + trigger: + type: Trigger + description: '' + priority: + type: Priority + description: '' + delay: + type: Delay + description: '' + allowed_children: + listOfEventAssignments: + type: EventAssignment + description: '' +Trigger: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + initialValue: + type: bool + description: '' + persistent: + type: bool + description: '' + math: + type: str + description: '' +Priority: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + math: + type: str + description: '' +Delay: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + math: + type: str + description: '' +EventAssignment: + allowed_parameters: + sid: + type: str + description: ' SId optional' + name: + type: str + description: ' string optional' + metaid: + type: str + description: ' XML ID optional' + sboTerm: + type: str + description: SBOTerm optional + notes: + type: Notes + description: ' XHTML 1.0 optional' + annotation: + type: str + description: XML content optional + math: + type: str + description: '' + variable: + type: str + description: SIdRef diff --git a/examples/sbml/example_sbml_minimal.xml b/examples/sbml/example_sbml_minimal.xml new file mode 100644 index 00000000..c3315f41 --- /dev/null +++ b/examples/sbml/example_sbml_minimal.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/examples/sbml/regenerateAndTest.sh b/examples/sbml/regenerateAndTest.sh new file mode 100755 index 00000000..198da2b6 --- /dev/null +++ b/examples/sbml/regenerateAndTest.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -ex + +python test_sbml3.py + +python sbml_validators.py example_sbml_minimal.xml +python sbml_validators.py test_minimal_example.xml diff --git a/examples/sbml/sbml32spec.py b/examples/sbml/sbml32spec.py new file mode 100644 index 00000000..c6372a91 --- /dev/null +++ b/examples/sbml/sbml32spec.py @@ -0,0 +1,484 @@ +#!/usr/bin/env python3 + +""" +initial attempt at creating an SBML API using modelspec +https://github.com/combine-org/compbiolibs/issues/28 + +based on sbml.level-3.version-2.core.release-2.pdf +""" + +import modelspec +from modelspec import field, instance_of, optional +from modelspec.base_types import Base +from typing import List + +from sbml_validators import * + + +@modelspec.define +class Notes(Base): + """ + XHTML field of SBase + + Args: + xmlns: str fixed "http://www.w3.org/1999/xhtml" + content: str valid XHTML + """ + + xmlns: str = field( + default="http://www.w3.org/1999/xhtml", + validator=[instance_of(str), xmlns_notes], + ) + content: str = field( + default=None, validator=optional([instance_of(str), valid_xhtml]) + ) + + +@modelspec.define +class Math(Base): + """ + Subset of MathML 2.0 used to define all formulae in SBML + """ + + xmlns: str = field( + default="http://www.w3.org/1998/Math/MathML", + validator=[instance_of(str), xmlns_math], + ) + content: str = field( + default=None, validator=optional([instance_of(str), valid_mathml]) + ) + + +@modelspec.define +class SBase(Base): + """ + Abstract base class for all SBML objects + + Args: + sid: SId optional + name: string optional + metaid: XML ID optional + sboTerm: SBOTerm optional + + notes: XHTML 1.0 optional + annotation: XML content optional + """ + + sid: str = field(default=None, validator=optional([instance_of(str), valid_sid])) + name: str = field(default=None, validator=optional(instance_of(str))) + + metaid: str = field( + default=None, validator=optional([instance_of(str), valid_xml_id]) + ) + sboTerm: str = field( + default=None, validator=optional([instance_of(str), valid_sbo]) + ) + + notes: Notes = field(default=None, validator=optional(instance_of(Notes))) + annotation: str = field( + default=None, validator=optional([instance_of(str), valid_xml_content]) + ) + + +@modelspec.define +class SBaseWithId(SBase): + + id: str = field(default=None, validator=optional([instance_of(str), valid_sid])) + + +@modelspec.define +class Trigger(SBase): + initialValue: bool = field(default=None, validator=instance_of(bool)) + persistent: bool = field(default=None, validator=instance_of(bool)) + math: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class Priority(SBase): + math: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class Delay(SBase): + math: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class EventAssignment(SBase): + """ + Args: + variable: SIdRef + """ + + math: str = field(default=None, validator=optional(instance_of(str))) + variable: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class Event(SBase): + useValuesFromTriggerTime: bool = field(default=None, validator=instance_of(bool)) + trigger: Trigger = field(default=None, validator=optional(instance_of(Trigger))) + priority: Priority = field(default=None, validator=optional(instance_of(Priority))) + delay: Delay = field(default=None, validator=optional(instance_of(Delay))) + listOfEventAssignments: List[EventAssignment] = field(factory=list) + + +@modelspec.define +class SimpleSpeciesReference(SBase): + """ + Base class used by SpeciesReference and ModifierSpeciesReference + + Args: + species: SIdRef + """ + + species: str = field(default=None, validator=instance_of(str)) + + +@modelspec.define +class ModifierSpeciesReference(SimpleSpeciesReference): + """""" + + +@modelspec.define +class SpeciesReference(SimpleSpeciesReference): + """ + Args: + stoichiometry: double optional + constant: boolean + """ + + stoichiometry: float = field(default=None, validator=optional(instance_of(float))) + constant: bool = field(default=None, validator=instance_of(bool)) + + +@modelspec.define +class LocalParameter(SBase): + """ + Args: + units: UnitSIdRef optional + """ + + value: float = field(default=None, validator=optional(instance_of(float))) + units: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class KineticLaw(SBase): + """ """ + + math: str = field(default=None, validator=optional(instance_of(str))) + + listOfLocalParameters: List[LocalParameter] = field(factory=list) + + +@modelspec.define +class Reaction(SBase): + """ + A model reaction + + Args: + reversible: boolean + compartment: SIdRef optional + """ + + reversible: bool = field(default=None, validator=instance_of(bool)) + compartment: str = field(default=None, validator=optional(instance_of(str))) + + listOfReactants: List[SpeciesReference] = field(factory=list) + listOfProducts: List[SpeciesReference] = field(factory=list) + listOfModifiers: List[ModifierSpeciesReference] = field(factory=list) + + kineticLaw: KineticLaw = field( + default=None, validator=optional(instance_of(KineticLaw)) + ) + + +@modelspec.define +class Constraint(SBase): + """ + A model constraint + + Args: + math: MathML optional + message: XHTML 1.0 optional + """ + + math: str = field(default=None, validator=optional(instance_of(str))) + message: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class Rule(SBase): + """ + A rule, either algebraic, assignment or rate + + Args: + math: MathML optional + """ + + math: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class AlgebraicRule(Rule): + """ + An algebraic rule + """ + + +@modelspec.define +class AssignmentRule(Rule): + """ + An assignment rule + + Args: + variable: SIdRef required + """ + + variable: str = field(default=None, validator=instance_of(str)) + + +@modelspec.define +class RateRule(Rule): + """ + A rate rule + + Args: + variable: SIdRef required + """ + + variable: str = field(default=None, validator=instance_of(str)) + + +@modelspec.define +class InitialAssignment(SBase): + """ + An initial assignment + + Args: + symbol: SIdRef required + math: MathML optional + """ + + symbol: str = field(default=None, validator=instance_of(str)) + math: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class Parameter(SBase): + """ + A parameter + + Args: + value: double optional + units: UnitSIdRef optional + constant: boolean + """ + + constant: bool = field(default=None, validator=instance_of(bool)) + + value: float = field(default=None, validator=optional(instance_of(float))) + units: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class Species(SBase): + """ + A species: entities of the same kind participating in reactions within a specific compartment + + Args: + compartment: SIdRef + initialAmount: double optional + initialConcentration: double optional + substanceUnits: UnitSIdRef optional + hasOnlySubstanceUnits: boolean + boundaryCondition: boolean + constant: boolean + conversionFactor: SIdRef optional + """ + + compartment: str = field(default=None, validator=instance_of(str)) + hasOnlySubstanceUnits: bool = field(default=None, validator=instance_of(bool)) + boundaryCondition: bool = field(default=None, validator=instance_of(bool)) + constant: bool = field(default=None, validator=instance_of(bool)) + + initialAmount: float = field(default=None, validator=optional(instance_of(float))) + initialConcentration: float = field( + default=None, validator=optional(instance_of(float)) + ) + substanceUnits: str = field(default=None, validator=optional(instance_of(str))) + conversionFactor: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class Compartment(SBase): + """ + A compartment + + Args: + spatialDimensions: eg 3 for three dimensional space etc + size: initial size of compartment + units: units being used to define the compartment's size + constant: whether size is fixed + """ + + constant: bool = field(default=None, validator=instance_of(bool)) + + spatialDimensions: float = field( + default=None, validator=optional(instance_of(float)) + ) + size: float = field(default=None, validator=optional(instance_of(float))) + units: str = field(default=None, validator=optional(instance_of(str))) + + +@modelspec.define +class unit(SBase): + """ + A unit used to compose a unit definition. + unit = (multiplier x 10^scale x kind)^exponent + + Args: + kind: base unit (base or derived SI units only, see Table 2 of the SBML spec) + exponent: double + scale: integer + multiplier: double + """ + + kind: str = field(default=None, validator=[instance_of(str), valid_kind]) + exponent: str = field(default=1.0, validator=instance_of(float)) + scale: str = field(default=0, validator=instance_of(int)) + multiplier: str = field(default=1.0, validator=instance_of(float)) + + +@modelspec.define +class ListOfUnits(SBase): + """ + A listOfUnits + + Args: + listOfUnits: the actual list Of Units + """ + + listOfUnits: List[unit] = field(factory=list) + + +@modelspec.define +class unitDefinition(SBaseWithId): + """ + A unit definition + + Args: + listOfUnits: List of units used to compose the definition + """ + + listOfUnits: ListOfUnits = field( + default=None, validator=optional(instance_of(ListOfUnits)) + ) + + +@modelspec.define +class ListOfUnitDefinitions(SBase): + """ + A listOfUnitDefinitions + + Args: + listOfUnitDefinitions: the actual list Of Unit Definitions + """ + + listOfUnitDefinitions: List[unitDefinition] = field(factory=list) + + +@modelspec.define +class FunctionDefinition(SBase): + """ + A function definition using MathML + + Args: + sid: SId required + + math: MathML function definition optional + """ + + sid: str = field(default=None, validator=[instance_of(str), valid_sid]) + + math: Math = field(default=None, validator=optional(instance_of(Math))) + + +@modelspec.define +class Model(SBase): + """ + The model + + Args: + substanceUnits: UnitSIdRef optional + timeUnits: UnitSIdRef optional + volumeUnits: UnitSIdRef optional + areaUnits: UnitSIdRef optional + lengthUnits: UnitSIdRef optional + extentUnits: UnitSIdRef optional + conversionFactor: SIdRef optional + """ + + substanceUnits: str = field( + default=None, validator=optional([instance_of(str), valid_unitsid]) + ) + timeUnits: str = field( + default=None, validator=optional([instance_of(str), valid_unitsid]) + ) + volumeUnits: str = field( + default=None, validator=optional([instance_of(str), valid_unitsid]) + ) + areaUnits: str = field( + default=None, validator=optional([instance_of(str), valid_unitsid]) + ) + lengthUnits: str = field( + default=None, validator=optional([instance_of(str), valid_unitsid]) + ) + extentUnits: str = field( + default=None, validator=optional([instance_of(str), valid_unitsid]) + ) + conversionFactor: str = field( + default=None, validator=optional([instance_of(str), valid_unitsid]) + ) + + listOfFunctionDefinitions: List[FunctionDefinition] = field(factory=list) + + listOfUnitDefinitions: ListOfUnitDefinitions = field( + default=None, validator=optional(instance_of(ListOfUnitDefinitions)) + ) + + listOfCompartments: List[Compartment] = field(factory=list) + listOfSpecies: List[Species] = field(factory=list) + listOfParameters: List[Parameter] = field(factory=list) + listOfInitialAssignments: List[InitialAssignment] = field(factory=list) + listOfRules: List[Rule] = field(factory=list) + listOfConstraints: List[Constraint] = field(factory=list) + listOfReactions: List[Reaction] = field(factory=list) + listOfEvents: List[Event] = field(factory=list) + + +@modelspec.define +class sbml(SBaseWithId): + """ + The top-level SBML container implementing SBML 3.2. + See sbml.level-3.version-2.core.release-2.pdf section 4. + http://www.sbml.org/sbml/level3/version2/ + + Args: + xmlns: string, fixed to "http://www.sbml.org/sbml/level3/version2/core" + level: SBML level, fixed to 3 + version: SBML version, fixed to 2 + + model: Optional model + """ + + xmlns: str = field( + default="http://www.sbml.org/sbml/level3/version%s/core" % SBML_VERSION, + validator=[instance_of(str), xmlns_sbml], + ) + level: str = field(default=None, validator=[instance_of(str), fixed_level]) + version: str = field(default=None, validator=[instance_of(str), fixed_version]) + + model: Model = field(default=None, validator=optional(instance_of(Model))) + # models: List[Model] = field(factory=list) diff --git a/examples/sbml/sbml_validators.py b/examples/sbml/sbml_validators.py new file mode 100644 index 00000000..5ab66a5b --- /dev/null +++ b/examples/sbml/sbml_validators.py @@ -0,0 +1,182 @@ +""" +functions used to validate the user assigned values of items +these functions will generally be called by passing to the validator option of attrs.field +""" + +import re +from lxml import etree +from io import StringIO +import sys + +# sbml.level-3.version-2.core.release-2.pdf Table 2 +sbml_si_units = """ +ampere coulomb gray joule litre mole radian steradian weber avogadro dimensionless henry katal lumen newton +second tesla becquerel farad hertz kelvin lux ohm siemens volt candela gram item kilogram metre pascal sievert watt +""".split() + +SBML_VERSION = "2" +SBML_LEVEL = "3" + + +def valid_kind(instance, attribute, value): + if not value in sbml_si_units: + raise ValueError( + f"kind {value} must be one of the standard SI units: {sbml_si_units}" + ) + + +def valid_mathml(instance, attribute, value): + "http://www.w3.org/1998/Math/MathML" + + +def xmlns_sbml(instance, attribute, value): + if value != "http://www.sbml.org/sbml/level3/version2/core": + raise ValueError( + "xmlns must be 'http://www.sbml.org/sbml/level3/version2/core'" + ) + + +def xmlns_notes(instance, attribute, value): + if value != "http://www.w3.org/1999/xhtml": + raise ValueError("xmlns must be 'http://www.w3.org/1999/xhtml'") + + +def xmlns_math(instance, attribute, value): + if value != "http://www.w3.org/1998/Math/MathML": + raise ValueError("xmlns must be 'http://www.w3.org/1998/Math/MathML'") + + +def fixed_level(instance, attribute, value): + if value != SBML_LEVEL: + raise ValueError("this implementation only supports level %s" % SBML_LEVEL) + + +def fixed_version(instance, attribute, value): + if value != SBML_VERSION: + raise ValueError("this implementation only supports version %s" % SBML_VERSION) + + +def valid_sid(instance, attribute, value): + if value is not None: + if not re.fullmatch("[_A-Za-z][_A-Za-z0-9]*", value): + raise ValueError( + "an SId must match the regular expression: [_A-Za-z][_A-Za-z0-9]*" + ) + + +def valid_unitsid(instance, attribute, value): + "same as sid except has a separate namespace" + if not re.fullmatch("[_A-Za-z][_A-Za-z0-9]*", value): + raise ValueError( + "a UnitSId must match the regular expression: [_A-Za-z][_A-Za-z0-9]*" + ) + + +def valid_unitsid(instance, attribute, value): + if not re.fullmatch("[_A-Za-z][_A-Za-z0-9]*", value): + raise ValueError( + "a UnitSId must match the regular expression: [_A-Za-z][_A-Za-z0-9]*" + ) + + +def valid_sbo(instance, attribute, value): + if not re.fullmatch("SBO:[0-9]{7}", value): + raise ValueError("an SBOTerm must match the regular expression: SBO:[0-9]{7}") + + +def valid_xml_id(instance, attribute, value): + "a valid XML 1.0 ID" + # not implemented yet: CombiningChar , Extender + # NameChar ::= letter | digit | '.' | '-' | '_' | ':' | CombiningChar | Extender + # ID ::= ( letter | '_' | ':' ) NameChar* + + if not re.fullmatch("[A-Za-z_:][A-Za-z0-9._:-]*", value): + raise ValueError("an SBOTerm must match the regular expression: SBO:[0-9]{7}") + + +def valid_xhtml(instance, attribute, value): + "use etree to validate XHTML, throw exception on error" + etree.parse(StringIO(value), etree.HTMLParser(recover=False)) + + +def valid_xml_content(instance, attribute, value): + "stub" + + if not re.search("<.*>", value): + raise ValueError( + f"{value} doesn't look like XML (this validator is only a stub)" + ) + + +def valid_mathml(instance, attribute, value): + """ + stubvalidator for MathML + note: see pdf section 4.3.2 for special rules for FunctionDefinition MathML + versus all other MathML uses in SBML + """ + + if not re.search("", value): + raise ValueError( + f"{value} doesn't look like MathML (this validator is only a stub)" + ) + + +# from: https://github.com/combine-org/combine-notebooks + + +def validate_sbml(doc, units_consistency: bool = False) -> None: + """Validate sbml.""" + import libsbml + + # set the unit checking, similar for the other settings + doc.setConsistencyChecks(libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, units_consistency) + doc.checkConsistency() + # get errors/warnings + n_errors: int = doc.getNumErrors() + errors: List[libsbml.SBMLError] = list() + warnings: List[libsbml.SBMLError] = list() + for k in range(n_errors): + error: libsbml.SBMLError = doc.getError(k) + severity = error.getSeverity() + if (severity == libsbml.LIBSBML_SEV_ERROR) or ( + severity == libsbml.LIBSBML_SEV_FATAL + ): + errors.append(error) + else: + warnings.append(error) + # print results + print("-" * 80) + print(f"{'validation error(s)':<25}: {len(errors)}") + print(f"{'validation warning(s)':<25}: {len(warnings)}") + if len(errors) > 0: + print("--- errors ---") + for kerr in enumerate(errors): + print(f"E{kerr}: {error.getCategoryAsString()} L{error.getLine()}") + print( + f"[{error.getSeverityAsString()}] {error.getShortMessage()} | {error.getMessage()}" + ) + if len(warnings) > 0: + print("--- warnings ---") + for kwarn in enumerate(warnings): + print(f"E{kwarn}: {error.getCategoryAsString()} L{error.getLine()}") + print( + f"[{error.getSeverityAsString()}] {error.getShortMessage()} | {error.getMessage()}" + ) + print("-" * 80) + + return len(warnings) + len(errors) + + +if __name__ == "__main__": + + import libsbml + + sbml_file = sys.argv[1] + + print("Going to validate SBML file: %s" % sbml_file) + reader = libsbml.SBMLReader() + document = reader.readSBML(sbml_file) + + issues = validate_sbml(document, units_consistency=False) + + exit(issues) diff --git a/examples/sbml/test_minimal_example.json b/examples/sbml/test_minimal_example.json new file mode 100644 index 00000000..e83375b6 --- /dev/null +++ b/examples/sbml/test_minimal_example.json @@ -0,0 +1,25 @@ +{ + "test_minimal_example": { + "level": "3", + "version": "2", + "model": { + "substanceUnits": "mole", + "timeUnits": "second", + "extentUnits": "mole", + "listOfUnitDefinitions": { + "listOfUnitDefinitions": { + "per_second": { + "listOfUnits": { + "listOfUnits": [ + { + "kind": "second", + "exponent": -1.0 + } + ] + } + } + } + } + } + } +} diff --git a/examples/sbml/test_minimal_example.xml b/examples/sbml/test_minimal_example.xml new file mode 100644 index 00000000..29bf4ff4 --- /dev/null +++ b/examples/sbml/test_minimal_example.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/examples/sbml/test_minimal_example.yaml b/examples/sbml/test_minimal_example.yaml new file mode 100644 index 00000000..e0916973 --- /dev/null +++ b/examples/sbml/test_minimal_example.yaml @@ -0,0 +1,14 @@ +test_minimal_example: + level: '3' + version: '2' + model: + substanceUnits: mole + timeUnits: second + extentUnits: mole + listOfUnitDefinitions: + listOfUnitDefinitions: + per_second: + listOfUnits: + listOfUnits: + - kind: second + exponent: -1.0 diff --git a/examples/sbml/test_sbml3.py b/examples/sbml/test_sbml3.py new file mode 100755 index 00000000..6b1c717b --- /dev/null +++ b/examples/sbml/test_sbml3.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +""" +derived from https://github.com/combine-org/draft-modelspec-sbml-api/blob/main/test_sbml32.py +a minimalish sbml to xml example +""" + +import json +import yaml +import os + +from sbml32spec import * + + +def test_example_sbml_minimal(): + "aiming to match the xml file example_sbml_minimal.xml" + + name = "test_minimal_example" + + sbml_doc = sbml(id=name, version="2", level="3") + # open(f"{path}.docs.json", "w").write(json.dumps(sbml_doc.generate_documentation(format="dict"), indent=4)) + + model = Model(substanceUnits="mole", timeUnits="second", extentUnits="mole") + sbml_doc.model = model + + unit_def = unitDefinition(id="per_second") + + model.listOfUnitDefinitions = ListOfUnitDefinitions() + + model.listOfUnitDefinitions.listOfUnitDefinitions.append(unit_def) + + unit_s = unit(kind="second", exponent=-1.0) + unit_def.listOfUnits = ListOfUnits() + unit_def.listOfUnits.listOfUnits.append(unit_s) + + print("------------------------------------------------") + print(sbml_doc) + print("------------------------------------------------") + + sbml_doc.to_json_file(f"{name}.json") + sbml_doc.to_yaml_file(f"{name}.yaml") + sbml_doc.to_xml_file(f"{name}.xml") + + print("Generating documentation...") + + doc_md = sbml_doc.generate_documentation(format="markdown") + + with open("SBML.md", "w") as d: + d.write(doc_md) + + doc_rst = sbml_doc.generate_documentation(format="rst") + + with open("SBML.rst", "w") as d: + d.write(doc_rst) + + print("\n >> Generating specification in dict form...") + doc_dict = sbml_doc.generate_documentation(format="dict") + + with open("SBML.specification.json", "w") as d: + d.write(json.dumps(doc_dict, indent=4)) + + print(" >> Generating specification in YAML...\n") + + with open("SBML.specification.yaml", "w") as d: + yy = yaml.dump(doc_dict, indent=4, sort_keys=False) + # print(yy) + d.write(yy) + + +if __name__ == "__main__": + test_example_sbml_minimal() diff --git a/examples/test/test.md b/examples/test/test.md index 366f1b45..ccfd2fe6 100644 --- a/examples/test/test.md +++ b/examples/test/test.md @@ -12,16 +12,51 @@ A model.... float_like_req - int + float name says it all... float_like_optional + float + name also says it all... + + + + + int_like_optional int name also says it all... + + mid + MidClassNoId + + + + + + +## MidClassNoId +A model.... + +### Allowed parameters + + + + + + + + + + + + + + +
int_valintname says it all...
str_valstrname says it all...
diff --git a/examples/test/test.py b/examples/test/test.py index f14d8165..ce820a7f 100644 --- a/examples/test/test.py +++ b/examples/test/test.py @@ -1,15 +1,17 @@ import modelspec from modelspec import field, instance_of, optional from modelspec.base_types import Base +from modelspec.utils import load_json from typing import List +from typing import Any +import sys -# Example testing multiple options... -from typing import Any +# Example testing multiple options... def convert2float(x: Any) -> float: - print("Converting {} ({})".format(x, type(x))) + print("convert2float {} ({})".format(x, type(x))) """Convert to float if not None""" if x is not None: return float(x) @@ -17,6 +19,29 @@ def convert2float(x: Any) -> float: return None +def convert2int(x: Any) -> int: + print("convert2int {} ({})".format(x, type(x))) + """Convert to int if not None""" + if x is not None: + return int(x) + else: + return None + + +@modelspec.define +class MidClassNoId(Base): + """ + A model.... + + Args: + int_val: name says it all... + str_val: name says it all... + """ + + int_val: int = field(default=None, validator=instance_of(int)) + str_val: str = field(default=None, validator=optional(instance_of(str))) + + @modelspec.define class TopClass(Base): """ @@ -26,28 +51,49 @@ class TopClass(Base): id: The unique id of the thing float_like_req: name says it all... float_like_optional: name also says it all... + int_like_optional: name also says it all... """ id: str = field(validator=instance_of(str)) - float_like_req: int = field( + float_like_req: float = field( default=None, validator=instance_of(float), converter=convert2float ) - float_like_optional: int = field( + float_like_optional: float = field( default=None, validator=optional(instance_of(float)), converter=convert2float ) + int_like_optional: int = field( + default=None, validator=optional(instance_of(int)), converter=convert2int + ) + + mid: MidClassNoId = field( + default=None, validator=optional(instance_of(MidClassNoId)) + ) tc = TopClass( - id="MyTest", float_like_req="03" + id="MyTest", float_like_req="04" ) # a string which can be converted to a float... # tc.float_like_req = 2.01 -tc.float_like_optional = 43 +tc.float_like_optional = 44 +# tc.float_like_optional2 = 66 +tc.mid = MidClassNoId(int_val=4, str_val="three") print(tc) tc.to_yaml_file("test_instance.yaml") +tc.to_json_file("test_instance.json") + +if sys.version_info >= (3, 8): + tc.to_xml_file("test_instance.xml") + +str_b4 = str(tc) + +str_json_after = TopClass.from_json_file("test_instance.json") +print(str_json_after) +str_yaml_after = TopClass.from_yaml_file("test_instance.yaml") +print(str_yaml_after) doc_md = tc.generate_documentation(format="markdown") diff --git a/examples/test/test.specification.yaml b/examples/test/test.specification.yaml index ca4fe7b2..4ffaa7aa 100644 --- a/examples/test/test.specification.yaml +++ b/examples/test/test.specification.yaml @@ -5,8 +5,23 @@ TopClass: type: str description: The unique id of the thing float_like_req: - type: int + type: float description: name says it all... float_like_optional: + type: float + description: name also says it all... + int_like_optional: type: int description: name also says it all... + mid: + type: MidClassNoId + description: '' +MidClassNoId: + definition: A model.... + allowed_parameters: + int_val: + type: int + description: name says it all... + str_val: + type: str + description: name says it all... diff --git a/examples/test/test_instance.json b/examples/test/test_instance.json new file mode 100644 index 00000000..7b8b0878 --- /dev/null +++ b/examples/test/test_instance.json @@ -0,0 +1,10 @@ +{ + "MyTest": { + "float_like_req": 4.0, + "float_like_optional": 44.0, + "mid": { + "int_val": 4, + "str_val": "three" + } + } +} diff --git a/examples/test/test_instance.xml b/examples/test/test_instance.xml new file mode 100644 index 00000000..4895ba5e --- /dev/null +++ b/examples/test/test_instance.xml @@ -0,0 +1,4 @@ + + + + diff --git a/examples/test/test_instance.yaml b/examples/test/test_instance.yaml index 51f8b261..1a3bcd49 100644 --- a/examples/test/test_instance.yaml +++ b/examples/test/test_instance.yaml @@ -1,3 +1,6 @@ MyTest: - float_like_req: 3.0 - float_like_optional: 43.0 + float_like_req: 4.0 + float_like_optional: 44.0 + mid: + int_val: 4 + str_val: three diff --git a/setup.cfg b/setup.cfg index 8d8f84cf..cd33b37f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,10 +22,10 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 Topic :: Scientific/Engineering Topic :: Software Development Typing :: Typed @@ -38,7 +38,7 @@ install_requires = numpy tabulate attrs - cattrs + cattrs>=23.2.3 # Issue with JSON serialisation in some versions, see https://github.com/ModECI/modelspec/issues/66 docstring-parser typing_extensions;python_version<'3.8' typing_compat;python_version<'3.8' @@ -68,6 +68,7 @@ test = typing_extensions; python_version<'3.8' docs = + pandas requests Sphinx recommonmark>=0.5.0 @@ -84,6 +85,7 @@ dev = flake8 pyneuroml>=0.7.2 NeuroMLlite>=0.5.3 + python-libsbml modelspec[test] all = diff --git a/src/modelspec/__init__.py b/src/modelspec/__init__.py index 8f33cf5a..b8bd118b 100644 --- a/src/modelspec/__init__.py +++ b/src/modelspec/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.3.2" +__version__ = "0.3.3" from .base_types import Base, define, has, field, fields, optional, instance_of, in_ diff --git a/src/modelspec/base_types.py b/src/modelspec/base_types.py index f4a81a9d..5dbe8f48 100644 --- a/src/modelspec/base_types.py +++ b/src/modelspec/base_types.py @@ -57,11 +57,13 @@ def print_(text: str, print_it: bool = False): """ Print a message preceded by modelspec, only if print_it=True """ + if not print_it: + return + prefix = "modelspec >>> " if not isinstance(text, str): text = ("%s" % text).decode("ascii") - if print_it: - print("{}{}".format(prefix, text.replace("\n", "\n" + prefix))) + print("{}{}".format(prefix, text.replace("\n", "\n" + prefix))) def print_v(text: str): @@ -128,11 +130,14 @@ def to_xml(self) -> str: root = build_xml_element(self) xml_string = ET.tostring( - root, encoding="utf-8", xml_declaration=False, method="xml" + root, encoding="UTF-8", xml_declaration=True, method="xml" ).decode("utf-8") parsed_xml = xml.dom.minidom.parseString(xml_string) pretty_xml = parsed_xml.toprettyxml(indent=" " * 4) + pretty_xml = pretty_xml.replace( + '?xml version="1.0" ?', '?xml version="1.0" encoding="UTF-8"?' + ) return pretty_xml @classmethod @@ -156,11 +161,26 @@ def from_dict(cls, d: Dict[str, Any]) -> "Base": else: return converter.structure(d, cls) + @classmethod + def from_yaml(cls, yaml_str: str) -> "Base": + """Instantiate an modelspec object from a YAML string""" + return cls.from_dict(yaml.load(yaml_str, Loader=yaml.SafeLoader)) + + @classmethod + def from_yaml_file(cls, yaml_file: str) -> "Base": + """Instantiate an modelspec object from a file containing YAML""" + return cls.from_dict(yaml.load(yaml_str, Loader=yaml.SafeLoader)) + @classmethod def from_json(cls, json_str: str) -> "Base": """Instantiate an modelspec object from a JSON string""" return cls.from_dict(json.loads(json_str)) + @classmethod + def from_json_file(cls, json_file: str) -> "Base": + """Instantiate an modelspec object from a file containing JSON""" + return cls.from_dict(json.load(json_file)) + @classmethod def from_bson(cls, bson_str: str) -> "Base": """Instantiate an modelspec object from a BSON string""" @@ -303,14 +323,7 @@ def to_xml_file( if filename is None: filename = f"{self.id}.xml" - root = build_xml_element(self) - - # Generate the XML string - xml_str = ET.tostring(root, encoding="utf-8", method="xml").decode("utf-8") - - # Create a pretty-formatted XML string using minidom - parsed_xml = xml.dom.minidom.parseString(xml_str) - pretty_xml_str = parsed_xml.toprettyxml(indent=" " * 4) + pretty_xml_str = self.to_xml() # Write the XML data to the file with open(filename, "w", encoding="utf-8") as file: diff --git a/src/modelspec/utils.py b/src/modelspec/utils.py index 16844cb1..29f9275a 100644 --- a/src/modelspec/utils.py +++ b/src/modelspec/utils.py @@ -14,7 +14,7 @@ from modelspec.base_types import EvaluableExpression from random import Random -from typing import Union +from typing import Union, Dict verbose = False @@ -247,8 +247,12 @@ def build_xml_element(data, parent=None): if parent is None: parent = ET.Element(data.__class__.__name__) + print_(" == Converting to XML: %s" % data, verbose) + attrs = attr.fields(data.__class__) for aattr in attrs: + + print_(" == Looking at: {} ({})".format(aattr, type(aattr)), verbose) if isinstance(aattr.default, attr.Factory): children = data.__getattribute__(aattr.name) if not isinstance(children, (list, tuple)): @@ -258,11 +262,32 @@ def build_xml_element(data, parent=None): child_element = build_xml_element(child) parent.append(child_element) - # Filters name space and schemaLoacation attributes, only allows non name space attributes to be added as attributes + # Filters name space and schemaLocation attributes, only allows non name space attributes to be added as attributes elif not isinstance(aattr.default, str): attribute_name = aattr.name attribute_value = data.__getattribute__(aattr.name) - parent.set(attribute_name, str(attribute_value)) + print_( + f" -- {attribute_name} = {attribute_value} (is type: {type(attribute_value)}, should be type:{aattr.type}))", + verbose, + ) + if attribute_value is not None: + if ( + type(attribute_value) == int + or type(attribute_value) == float + or type(attribute_value) == str + or type(attribute_value) == bool + or type(attribute_value) == list + ): + parent.set(attribute_name, str(attribute_value)) + elif type(attribute_value) == dict: + + """for k, v in attribute_value.items(): + child_element = build_xml_element(v)""" + else: + child_element = build_xml_element(attribute_value) + child_element.tag = attribute_name + # + parent.append(child_element) # This defines the various namespaces and schemaLocation of the generated xml if hasattr(data, "xmlns"): @@ -285,13 +310,12 @@ def ascii_encode_dict(data): def _parse_element(dict_format, to_build): - if verbose: - print("Parse for element: [%s]" % dict_format) + print_("Parse for element: [%s]" % dict_format, verbose) for k in dict_format.keys(): - if verbose: - print( - " Setting id: {} in {} ({})".format(k, type.__name__, type(to_build)) - ) + print_( + " Setting id: {} in {} ({})".format(k, type.__name__, type(to_build)), + verbose, + ) to_build.id = k to_build = _parse_attributes(dict_format[k], to_build) @@ -303,10 +327,10 @@ def _parse_attributes(dict_format, to_build): for key in dict_format: value = dict_format[key] new_format = True - if verbose: - print( - " Setting {}={} ({}) in {}".format(key, value, type(value), to_build) - ) + print_( + " Setting {}={} ({}) in {}".format(key, value, type(value), to_build), + verbose, + ) if new_format: if type(to_build) == dict: @@ -316,8 +340,7 @@ def _parse_attributes(dict_format, to_build): type_to_use = to_build.allowed_children[key][1] for v in value: ff = type_to_use() - if verbose: - print(f" Type for {key}: {type_to_use} ({ff})") + print_(f" Type for {key}: {type_to_use} ({ff})", verbose) ff = _parse_element({v: value[v]}, ff) exec("to_build.%s.append(ff)" % key) else: @@ -332,13 +355,11 @@ def _parse_attributes(dict_format, to_build): to_build.__setattr__(key, value) else: type_to_use = to_build.allowed_fields[key][1] - if verbose: - print( - "type_to_use: {} ({})".format( - type_to_use, type(type_to_use) - ) - ) - print(f"- {key} = {value}") + print_( + "type_to_use: {} ({})".format(type_to_use, type(type_to_use)), + verbose, + ) + print_(f"- {key} = {value}", verbose) if type_to_use == EvaluableExpression: vv = {} @@ -449,19 +470,17 @@ def evaluate( if array_format == FORMAT_TENSORFLOW: import tensorflow as tf - if verbose: - print_( - " > Evaluating: [%s] which is a: %s, vs parameters: %s (using %s arrays)..." - % (expr, type(expr).__name__, _params_info(parameters), array_format), - verbose, - ) + print_( + " > Evaluating: [%s] which is a: %s, vs parameters: %s (using %s arrays)..." + % (expr, type(expr).__name__, _params_info(parameters), array_format), + verbose, + ) try: if type(expr) == str and expr in parameters: expr = parameters[ expr ] # replace with the value in parameters & check whether it's float/int... - if verbose: - print_(" Using for that param: %s" % _val_info(expr), verbose) + print_(" Using for that param: %s" % _val_info(expr), verbose) if type(expr) == str: try: @@ -480,41 +499,34 @@ def evaluate( pass if type(expr) == list: - if verbose: - print_(" Returning a list in format: %s" % array_format, verbose) + print_(" Returning a list in format: %s" % array_format, verbose) if array_format == FORMAT_TENSORFLOW: return tf.constant(expr, dtype=tf.float64) else: return np.array(expr) if type(expr) == np.ndarray: - if verbose: - print_( - " Returning a numpy array in format: %s" % array_format, verbose - ) + print_(" Returning a numpy array in format: %s" % array_format, verbose) if array_format == FORMAT_TENSORFLOW: return tf.convert_to_tensor(expr, dtype=tf.float64) else: return np.array(expr) if "Tensor" in type(expr).__name__: - if verbose: - print_( - " Returning a tensorflow Tensor in format: %s" % array_format, - verbose, - ) + print_( + " Returning a tensorflow Tensor in format: %s" % array_format, + verbose, + ) if array_format == FORMAT_NUMPY: return expr.numpy() else: return expr if int(expr) == expr and cast_to_int: - if verbose: - print_(" Returning int: %s" % int(expr), verbose) + print_(" Returning int: %s" % int(expr), verbose) return int(expr) else: # will have failed if not number - if verbose: - print_(" Returning {}: {}".format(type(expr), expr), verbose) + print_(" Returning {}: {}".format(type(expr), expr), verbose) return expr except: try: @@ -531,25 +543,22 @@ def evaluate( if type(expr) == str and "numpy." in expr: parameters["numpy"] = np - if verbose: - print_( - " Trying to eval [%s] with Python using %s..." - % (expr, parameters.keys()), - verbose, - ) + print_( + " Trying to eval [%s] with Python using %s..." + % (expr, parameters.keys()), + verbose, + ) v = eval(expr, parameters) - if verbose: - print_( - " Evaluated with Python: {} = {}".format(expr, _val_info(v)), - verbose, - ) + print_( + " Evaluated with Python: {} = {}".format(expr, _val_info(v)), + verbose, + ) if (type(v) == float or type(v) == str) and int(v) == v: - if verbose: - print_(" Returning int: %s" % int(v), verbose) + print_(" Returning int: %s" % int(v), verbose) if array_format == FORMAT_TENSORFLOW: return tf.constant(int(v)) @@ -557,8 +566,7 @@ def evaluate( return int(v) return v except Exception as e: - if verbose: - print_(f" Returning without altering: {expr} (error: {e})", verbose) + print_(f" Returning without altering: {expr} (error: {e})", verbose) return expr diff --git a/test_all.sh b/test_all.sh index 0a91b46b..f646a3e4 100755 --- a/test_all.sh +++ b/test_all.sh @@ -24,6 +24,11 @@ python neuroml2_spec.py pynml -validate hello_world_neuroml.net.nml pynml -validate TestNeuroML.xml +## Test SBML example + +cd ../sbml +./regenerateAndTest.sh + cd ../.. @@ -33,6 +38,7 @@ pytest tests -v ## Run OMV tests +# See https://github.com/OpenSourceBrain/osb-model-validation omv all -V diff --git a/tests/test_base.py b/tests/test_base.py index 54a5bbb4..3cd6fddb 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -162,8 +162,9 @@ def test_save_load_json(tmp_path): # net.id = net.id+'_yaml' net.to_yaml_file(filenamey) - # filenamex = str(Path(tmp_path) / f"{net.id}.xml") - # net.to_xml_file(filenamex) + if sys.version_info >= (3, 8): + filenamex = str(Path(tmp_path) / f"{net.id}.xml") + net.to_xml_file(filenamex) from modelspec.utils import load_json, load_yaml, load_xml @@ -173,12 +174,24 @@ def test_save_load_json(tmp_path): str_netj = str(netj) + netj2 = NewNetwork.from_json(net.to_json()) + str_netj2 = str(netj2) + + netj3 = NewNetwork.from_json_file(filenamej) + str_netj3 = str(netj3) + datay = load_yaml(filenamey) print_v("Loaded network specification from %s" % filenamey) nety = NewNetwork.from_dict(datay) str_nety = str(nety) + nety2 = NewNetwork.from_yaml(net.to_yaml() + " ") + str_nety2 = str(nety2) + + nety3 = NewNetwork.from_yaml_file(filenamey) + str_nety3 = str(nety3) + # datax = load_xml(filenamex) # print_v("Loaded network specification from %s" % filenamex) @@ -201,6 +214,8 @@ def test_save_load_json(tmp_path): ) # Order not preserved in py2, just test len else: assert str_orig == str_netj + assert str_orig == str_netj2 + assert str_orig == str_netj3 print("Test YAML..") if sys.version_info[0] == 2: @@ -209,6 +224,8 @@ def test_save_load_json(tmp_path): ) # Order not preserved in py2, just test len else: assert str_orig == str_nety + assert str_orig == str_nety2 + assert str_orig == str_nety3 # print("Test XML..") # if sys.version_info[0] == 2: