| Crates.io | libsbml |
| lib.rs | libsbml |
| version | 0.1.1 |
| created_at | 2025-05-03 16:45:39.293572+00 |
| updated_at | 2025-07-18 23:30:56.067031+00 |
| description | Rust bindings for libSBML |
| homepage | |
| repository | https://github.com/EnzymeML/libsbml-rs |
| max_upload_size | |
| id | 1658984 |
| size | 553,681 |
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.
serdecargo-vcpkgCurrently available through Git:
cargo add libsbml
Since this crate wraps the libsbml C++ library, you have two options for installation:
libsbml via your OS package manager.libsbml via cargo-vcpkgIn the latter case, the C++ dependency libsbml is automatically installed using cargo-vcpkg. You dont need to link the library manually, but note that the build.rs script will install cargo-vcpkg if it is not found in your environment. We generally recommend installing libsbml via your OS package manager, because the build time is significantly reduced.
[!NOTE] The detection of libsbml is done via
pkg-config, which is not available on all platforms. If you are using a platform that does not supportpkg-config, the build will fall back to usingcargo-vcpkg, which is supported on all platforms, but the build time is significantly increased.
✅ Tested and supported:
The crate follows SBML's hierarchical structure, with all operations flowing through the root SBMLDocument. We offer two API styles:
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 LGPL 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 | ⚠️ Partially |
| Compartment | ✅ Implemented |
| Species | ✅ Implemented |
| Parameter | ✅ Implemented |
| Reaction | ✅ Implemented |
| Rule | ✅ Implemented |
| AssignmentRule | ✅ Implemented |
| RateRule | ✅ Implemented |
| UnitDefinition | ✅ Implemented |
| Unit | ✅ Implemented |
| KineticLaw | ✅ 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 | ✅ 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 |
| SBML Object | Status |
|---|---|
| FluxObjective | ✅ Implemented |
| FluxBound | ✅ Implemented |
| Objective | ✅ Implemented |
Future development priorities: