Skip to content

System Bio Model

An abstract base class for BioModels in the BioModels repository.

SysBioModel

Bases: ABC, BaseModel

Abstract base class for BioModels in the BioModels repository. This class serves as a general structure for models, allowing different mathematical approaches to be implemented in subclasses.

Source code in aiagents4pharma/talk2biomodels/models/sys_bio_model.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class SysBioModel(ABC, BaseModel):
    """
    Abstract base class for BioModels in the BioModels repository.
    This class serves as a general structure for models, allowing
    different mathematical approaches to be implemented in subclasses.
    """

    biomodel_id: int | None = Field(None, description="BioModel ID of the model")
    sbml_file_path: str | None = Field(None, description="Path to an SBML file")
    name: str | None = Field(..., description="Name of the model")
    description: str | None = Field("", description="Description of the model")

    @model_validator(mode="after")
    def check_biomodel_id_or_sbml_file_path(self):
        """
        Validate that either biomodel_id or sbml_file_path is provided.
        """
        if not self.biomodel_id and not self.sbml_file_path:
            raise ValueError("Either biomodel_id or sbml_file_path must be provided.")
        return self

    @abstractmethod
    def get_model_metadata(self) -> dict[str, str | int]:
        """
        Abstract method to retrieve metadata of the model.
        This method should return a dictionary containing model metadata.

        Returns:
            dict: Dictionary with model metadata
        """

    @abstractmethod
    def update_parameters(self, parameters: dict[str, float | int]) -> None:
        """
        Abstract method to update model parameters.

        Args:
            parameters: Dictionary of parameter values.
        """

    @abstractmethod
    def simulate(self, duration: int | float) -> list[float]:
        """
        Abstract method to run a simulation of the model.

        Args:
            duration: Duration of the simulation.

        Returns:
            list: List of simulation results.
        """

check_biomodel_id_or_sbml_file_path()

Validate that either biomodel_id or sbml_file_path is provided.

Source code in aiagents4pharma/talk2biomodels/models/sys_bio_model.py
22
23
24
25
26
27
28
29
@model_validator(mode="after")
def check_biomodel_id_or_sbml_file_path(self):
    """
    Validate that either biomodel_id or sbml_file_path is provided.
    """
    if not self.biomodel_id and not self.sbml_file_path:
        raise ValueError("Either biomodel_id or sbml_file_path must be provided.")
    return self

get_model_metadata() abstractmethod

Abstract method to retrieve metadata of the model. This method should return a dictionary containing model metadata.

Returns:

Name Type Description
dict dict[str, str | int]

Dictionary with model metadata

Source code in aiagents4pharma/talk2biomodels/models/sys_bio_model.py
31
32
33
34
35
36
37
38
39
@abstractmethod
def get_model_metadata(self) -> dict[str, str | int]:
    """
    Abstract method to retrieve metadata of the model.
    This method should return a dictionary containing model metadata.

    Returns:
        dict: Dictionary with model metadata
    """

simulate(duration) abstractmethod

Abstract method to run a simulation of the model.

Parameters:

Name Type Description Default
duration int | float

Duration of the simulation.

required

Returns:

Name Type Description
list list[float]

List of simulation results.

Source code in aiagents4pharma/talk2biomodels/models/sys_bio_model.py
50
51
52
53
54
55
56
57
58
59
60
@abstractmethod
def simulate(self, duration: int | float) -> list[float]:
    """
    Abstract method to run a simulation of the model.

    Args:
        duration: Duration of the simulation.

    Returns:
        list: List of simulation results.
    """

update_parameters(parameters) abstractmethod

Abstract method to update model parameters.

Parameters:

Name Type Description Default
parameters dict[str, float | int]

Dictionary of parameter values.

required
Source code in aiagents4pharma/talk2biomodels/models/sys_bio_model.py
41
42
43
44
45
46
47
48
@abstractmethod
def update_parameters(self, parameters: dict[str, float | int]) -> None:
    """
    Abstract method to update model parameters.

    Args:
        parameters: Dictionary of parameter values.
    """