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
 9
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
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: Optional[int] = Field(None, description="BioModel ID of the model")
    sbml_file_path: Optional[str] = Field(None, description="Path to an SBML file")
    name: Optional[str] = Field(..., description="Name of the model")
    description: Optional[str] = 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, Union[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, Union[float, int]]) -> None:
        """
        Abstract method to update model parameters.

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

    @abstractmethod
    def simulate(self, duration: Union[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
20
21
22
23
24
25
26
27
@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, Union[str, int]]

Dictionary with model metadata

Source code in aiagents4pharma/talk2biomodels/models/sys_bio_model.py
29
30
31
32
33
34
35
36
37
@abstractmethod
def get_model_metadata(self) -> Dict[str, Union[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 Union[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
47
48
49
50
51
52
53
54
55
56
57
@abstractmethod
def simulate(self, duration: Union[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, Union[float, int]]

Dictionary of parameter values.

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

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