[3af7d7]: / aiagents4pharma / talk2biomodels / tools / load_arguments.py

Download this file

115 lines (103 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
"""
A utility module for defining the dataclasses
for the arguments to set up initial settings
before the experiment is run.
"""
import logging
from dataclasses import dataclass
from typing import Union, List, Optional, Annotated
from pydantic import Field
import basico
# Initialize logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@dataclass
class TimeData:
"""
Dataclass for storing the time data.
"""
duration: Union[int, float] = Field(
description="Duration of the simulation",
default=100)
interval: Union[int, float] = Field(
description="The interval is the time step or"
" the step size of the simulation. It is unrelated"
" to the step size of species concentration and parameter values.",
default=100)
@dataclass
class SpeciesInitialData:
"""
Dataclass for storing the species initial data.
"""
species_name: List[str] = Field(
description="List of species whose initial concentration is to be set."
" This does not include species that reoccur or the species whose"
" concentration is to be determined/observed at the end of the experiment."
" Do not hallucinate the species name.",
default=[])
species_concentration: List[Union[int, float]] = Field(
description="List of initial concentrations of species."
" This does not include species that reoccur or the species whose"
" concentration is to be determined/observed at the end of the experiment."
" Do not hallucinate the species concentration.",
default=[])
@dataclass
class TimeSpeciesNameConcentration:
"""
Dataclass for storing the time,
species name, and concentration data.
"""
time: Union[int, float] = Field(description="time point where the event occurs")
species_name: str = Field(description="species name")
species_concentration: Union[int, float] = Field(
description="species concentration at the time point")
@dataclass
class ReocurringData:
"""
Dataclass for species that reoccur. In other words,
the concentration of the species resets to a certain
value after a certain time interval.
"""
data: List[TimeSpeciesNameConcentration] = Field(
description="List of time, name, and concentration data"
" of species or parameters that reoccur",
default=[])
@dataclass
class ArgumentData:
"""
Dataclass for storing the argument data.
"""
experiment_name: Annotated[str, "An AI assigned _ separated name of"
" the experiment based on human query"
" and the context of the experiment."
" This must be set before the experiment is run."]
time_data: Optional[TimeData] = Field(
description="time data",
default=None)
species_to_be_analyzed_before_experiment: Optional[SpeciesInitialData] = Field(
description="Data of species whose initial concentration"
" is to be set before the experiment. This does not include"
" species that reoccur or the species whose concentration"
" is to be determined at the end of the experiment.",
default=None)
reocurring_data: Optional[ReocurringData] = Field(
description="List of concentration and time data of species that"
" reoccur. For example, a species whose concentration resets"
" to a certain value after a certain time interval.",
default=None)
def add_rec_events(model_object, reocurring_data):
"""
Add reocurring events to the model.
Args:
model_object: The model object.
reocurring_data: The reocurring data.
Returns:
None
"""
for row in reocurring_data.data:
tp, sn, sc = row.time, row.species_name, row.species_concentration
basico.add_event(f'{sn}_{tp}',
f'Time > {tp}',
[[sn, str(sc)]],
model=model_object.copasi_model)