-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
163 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Antimony -> SBML""" | ||
|
||
import antimony as ant | ||
from pathlib import Path | ||
|
||
__all__ = ["antimony_to_sbml_str"] | ||
|
||
|
||
def antimony_to_sbml_str(ant_model: str | Path) -> str: | ||
"""Convert Antimony string to SBML model. | ||
Arguments: | ||
ant_str: | ||
Antimony model as string (model, not filename), or Path to file. | ||
Returns: | ||
SBML model as string. | ||
""" | ||
|
||
# Unload everything / free memory | ||
ant.clearPreviousLoads() | ||
ant.freeAll() | ||
|
||
if isinstance(ant_model, Path): | ||
status = ant.loadAntimonyFile(str(ant_model)) | ||
else: | ||
status = ant.loadAntimonyString(ant_model) | ||
if status < 0: | ||
raise RuntimeError( | ||
f"Antimony model could not be loaded: {ant.getLastError()}" | ||
) | ||
|
||
if (main_module_name := ant.getMainModuleName()) is None: | ||
raise AssertionError("There is no Antimony module.") | ||
|
||
sbml_str = ant.getSBMLString(main_module_name) | ||
if not sbml_str: | ||
raise ValueError("Antimony model could not be converted to SBML.") | ||
|
||
return sbml_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.