Skip to content

biomodels.models

Access to the BioModels database: search, model info, download, selection.

The curated model set is queried and downloaded through the BioModels REST API (https://www.biomodels.org, www.ebi.ac.uk/biomodels rejects the quoted search query used here). Model info and the downloaded SBML are cached on disk under biomodels_cache() so a rerun of the check never re-fetches a model it already has.

BioModelsError

Bases: RuntimeError

A BioModels request failed or returned an unexpected response.

ModelInfo dataclass

ModelInfo(
    id, name, publication_id, format_version, main_file
)

Metadata of one BioModels model, from /{id}?format=json.

Selection dataclass

Selection(date, query, models)

A snapshot of the curated model ids, e.g. biomodels/models.json.

biomodels_cache

biomodels_cache(cache=None)

Cache directory of the BioModels info and downloads.

Parameters:

Name Type Description Default
cache Path | None

cache root, sbml2cellml.testsuite.cases.cache_dir() by default.

None

Returns:

Type Description
Path

<cache>/biomodels.

query_curated_ids

query_curated_ids()

Ids of every manually curated SBML model, paged through the search.

Returns:

Type Description
list[str]

The model ids, sorted and without duplicates.

Raises:

Type Description
BioModelsError

if a search page cannot be fetched.

model_info

model_info(model_id, cache=None)

Metadata of a model, cached as <cache>/biomodels/<id>/info.json.

Parameters:

Name Type Description Default
model_id str

BioModels id, e.g. BIOMD0000000001.

required
cache Path | None

cache root, sbml2cellml.testsuite.cases.cache_dir() by default.

None

Returns:

Type Description
ModelInfo

The model metadata.

Raises:

Type Description
BioModelsError

if the request fails or the response has no main SBML file.

download_model

download_model(model_id, cache=None)

Download the main SBML file of a model, cached on disk.

Parameters:

Name Type Description Default
model_id str

BioModels id, e.g. BIOMD0000000001.

required
cache Path | None

cache root, sbml2cellml.testsuite.cases.cache_dir() by default.

None

Returns:

Type Description
Path

Path of the cached SBML file.

Raises:

Type Description
BioModelsError

if the info or download request fails.

load_selection

load_selection(path)

Read a selection file (e.g. biomodels/models.json).

Parameters:

Name Type Description Default
path Path

the selection file.

required

Returns:

Type Description
Selection

The selection.

write_selection

write_selection(path, ids)

Write a selection file with today's date and the given ids.

Parameters:

Name Type Description Default
path Path

file to write.

required
ids list[str]

model ids, written sorted and without duplicates.

required

Returns:

Type Description
Selection

The selection written.

packages

packages(sbml_path)

SBML packages an SBML file uses, not merely declares.

A package declared through the root element's xmlns counts only when an element with its prefix actually occurs in the file, e.g. <comp:... for a comp declaration. comp is the exception: its port elements do not change the math, so it counts only when a <comp:submodel, <comp:modelDefinition or <comp:externalModelDefinition element occurs.

Parameters:

Name Type Description Default
sbml_path Path

SBML file to inspect.

required

Returns:

Type Description
tuple[str, ...]

The package names, sorted and without duplicates.