A Rust crate providing a robust interface for reading and writing SBML (Systems Biology Markup Language) files.
Built as an ergonomic wrapper around the libsbml
C++ library with type-safe Rust abstractions.
- Type-safe builder pattern API for SBML model creation
- Seamless serialization/deserialization of annotations using
serde
- Bundled
libsbml
library - no external installation required - Cross-platform support (macOS and Windows)
- Comprehensive error handling and type safety
Currently available through Git:
cargo add --git https://github.com/EnzymeML/sbml-rs
- CMake: Required for building the bundled
libsbml
library - Rust: 1.70 or higher (recommended)
✅ Tested and supported:
- macOS (arm64, x86_64)
- Windows (x86_64)
- Linux (x86_64)
Please note, due to ongoing development to support platforms, the crate is currently only available as a static library for Windows and Linux. MacOS is available as a dynamic library. We will update this section as we add more support.
The crate follows SBML's hierarchical structure, with all operations flowing through the root SBMLDocument
. We offer two API styles:
- Builder pattern (recommended)
- Traditional setter methods
use sbml::prelude::*;
let doc = SBMLDocument::new(3, 2);
// Create a model
let model = doc.create_model("Model");
// Create a compartment
let compartment = model.build_compartment("cytosol")
.name("Cytosol")
.build();
// Create the glucose species with annotation
let glucose = model
.build_species("glucose")
.name("Glucose")
.compartment(&compartment.id())
.initial_amount(10.0)
.boundary_condition(true)
.annotation_serde(&glucose_annotation)?
.build();
// Export to SBML XML
let sbml_string = doc.to_xml_string();
Leverage Rust's type system for SBML annotations:
use sbml::prelude::*;
#[derive(Serialize, Deserialize, Debug)]
struct MyAnnotation {
#[serde(rename = "@xmlns")]
xmlns: String,
key: String,
value: i32,
}
// Create and attach annotation
let annotation = MyAnnotation {
xmlns: "http://my.namespace.com".to_string(),
key: "test".to_string(),
value: 1,
};
let species = model.build_species("glucose")
.name("Glucose")
.compartment(&compartment.id())
.initial_amount(10.0)
.boundary_condition(true)
.annotation_serde(&annotation)?
.build();
// Read annotation
let retrieved: MyAnnotation = species.get_annotation_serde()?;
# Format code
cargo fmt
# Run linter
cargo clippy --all-targets --all-features
# Run tests
cargo test
Contributions are welcome! Please feel free to submit a Pull Request.
This crate is a Rust port of the libsbml library. Special thanks to the SBML team for their excellent work.
This project is licensed under the MIT License - see the LICENSE file for details.
The following table shows the current implementation status of SBML objects in this crate:
SBML Object | Status |
---|---|
Model | |
Compartment | ✅ Implemented |
Species | ✅ Implemented |
Parameter | ✅ Implemented |
Reaction | ✅ Implemented |
Rule | ✅ Implemented |
AssignmentRule | ✅ Implemented |
RateRule | ✅ Implemented |
UnitDefinition | ✅ Implemented |
Unit | ✅ Implemented |
KineticLaw | ❌ Not yet implemented |
SpeciesReference | ✅ Implemented |
ModifierSpeciesReference | ✅ Implemented |
InitialAssignment | ❌ Not yet implemented |
Event | ❌ Not yet implemented |
EventAssignment | ❌ Not yet implemented |
Trigger | ❌ Not yet implemented |
Delay | ❌ Not yet implemented |
Priority | ❌ Not yet implemented |
FunctionDefinition | ❌ Not yet implemented |
Constraint | ❌ Not yet implemented |
LocalParameter | ❌ Not yet implemented |
StoichiometryMath | ❌ Not yet implemented |
CompartmentType | ❌ Not yet implemented |
SpeciesType | ❌ Not yet implemented |
SBase | ✅ Implemented |
ListOf | ✅ Implemented |
ASTNode | ❌ Not yet implemented |
CVTerm | ❌ Not yet implemented |
Date | ❌ Not yet implemented |
ModelHistory | ❌ Not yet implemented |
ModelCreator | ❌ Not yet implemented |
Future development priorities:
- Complete implementation of remaining SBML core objects
- Improve error handling and validation
- Add more examples and documentation
- Performance optimizations