Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByDrescher committed Nov 7, 2024
1 parent 137224f commit 825a465
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
21 changes: 19 additions & 2 deletions biosimulators_copasi/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Union, get_type_hints

import COPASI
from biosimulators_utils.sedml.data_model import UniformTimeCourseSimulation, SteadyStateSimulation, Variable, Algorithm
from biosimulators_utils.sedml.data_model import UniformTimeCourseSimulation, SteadyStateSimulation, Variable

import basico
import pandas
Expand Down Expand Up @@ -91,6 +91,7 @@ def __eq__(self, other: CopasiAlgorithmParameter) -> bool:
def __ne__(self, other: RelativeToleranceParameter) -> bool:
return not self.__eq__(other)


class Resolution(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "resolution"
Expand All @@ -109,6 +110,7 @@ def set_value(self, new_value: float):
raise ValueError
self._value = new_value


class DerivationFactor(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "derivationfactor"
Expand All @@ -127,6 +129,7 @@ def set_value(self, new_value: float):
raise ValueError
self._value = new_value


class UseNewton(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "useNewton"
Expand All @@ -145,6 +148,7 @@ def set_value(self, new_value: bool):
raise ValueError
self._value = new_value


class UseIntegration(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "useIntegration"
Expand All @@ -163,6 +167,7 @@ def set_value(self, new_value: bool):
raise ValueError
self._value = new_value


class UseBackIntegration(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "useBackIntegration"
Expand All @@ -181,6 +186,7 @@ def set_value(self, new_value: bool):
raise ValueError
self._value = new_value


class AcceptNegativeConcentrations(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "acceptNegativeConcentrations"
Expand All @@ -199,6 +205,7 @@ def set_value(self, new_value: bool):
raise ValueError
self._value = new_value


class IterationLimit(CopasiAlgorithmParameter):
KISAO_ID: str = "KISAO_0000486"
ID: str = "iterationLimit"
Expand All @@ -217,6 +224,7 @@ def set_value(self, new_value: int):
raise ValueError
self._value = new_value


class MaxForwardIntegrationDuration(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "maxForwardIntegrationDuration"
Expand All @@ -235,6 +243,7 @@ def set_value(self, new_value: float):
raise ValueError
self._value = new_value


class MaxReverseIntegrationDuration(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "maxReverseIntegrationDuration"
Expand All @@ -253,6 +262,7 @@ def set_value(self, new_value: float):
raise ValueError
self._value = new_value


class TargetCriterion(CopasiAlgorithmParameter):
KISAO_ID: str = "" # To be created
ID: str = "targetCriterion"
Expand All @@ -279,6 +289,7 @@ def set_value(self, new_value: str):
raise ValueError
self._value = new_value


class RelativeToleranceParameter(CopasiAlgorithmParameter):
KISAO_ID: str = "KISAO_0000209"
ID: str = "r_tol"
Expand Down Expand Up @@ -638,6 +649,7 @@ def __eq__(self, other):
event_support_equality = self.CAN_SUPPORT_EVENTS == other.CAN_SUPPORT_EVENTS
return kisao_equality and id_equality and name_equality and event_support_equality


class SteadyStateAlgorithm(CopasiAlgorithm):
KISAO_ID: str = None
ID: str = None
Expand Down Expand Up @@ -684,6 +696,7 @@ def get_overrides(self) -> dict:
overrides.update(self.target_criterion.get_override_repr())
return overrides


class CopasiHybridAlternatingNewtonLSODASolver(SteadyStateAlgorithm):
KISAO_ID: str = "KISAO_0000411" # Placeholder until it gets its own solver
ID: str = "steadystatestandard"
Expand All @@ -703,6 +716,7 @@ def __init__(self, use_integration: bool = True, use_back_integration: bool = Fa
def get_copasi_id(self) -> str:
return CopasiHybridAlternatingNewtonLSODASolver.ID


class PureNewtonRootFindingAlgorithm(SteadyStateAlgorithm):
KISAO_ID: str = "KISAO_0000409"
ID: str = "steadystatenewton"
Expand All @@ -719,6 +733,7 @@ def __init__(self, resolution: float = 1e-09, derivation_factor: float = 0.001,
def get_copasi_id(self) -> str:
return PureNewtonRootFindingAlgorithm.ID


class PureIntegrationRootFindingAlgorithm(SteadyStateAlgorithm):
KISAO_ID: str = "" # No applicable term yet
ID: str = "steadystateintegration"
Expand All @@ -734,9 +749,11 @@ def __init__(self, use_integration: bool = True, use_back_integration: bool = Fa
super().__init__(True, use_integration, use_back_integration, resolution, derivation_factor,
accept_negative_concentrations, iteration_limit, max_forward_duration, max_back_duration,
target_criterion_distance, target_criterion_rate, units)

def get_copasi_id(self) -> str:
return PureIntegrationRootFindingAlgorithm.ID


class GibsonBruckAlgorithm(CopasiAlgorithm):
KISAO_ID: str = "KISAO_0000027"
ID: str = "stochastic"
Expand Down Expand Up @@ -1340,4 +1357,4 @@ def generate_data_handler(self, output_selection: list[str]):
@staticmethod
def _get_times(number_of_steps: int, output_start_time: float, output_end_time: float) -> "list[float]":
time_range: float = output_end_time - output_start_time
return [(i * time_range) / number_of_steps for i in range(number_of_steps)] + [output_start_time]
return [(i * time_range) / number_of_steps for i in range(number_of_steps)] + [output_start_time]
9 changes: 5 additions & 4 deletions biosimulators_copasi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def get_algorithm(kisao_id: str, events_were_requested: bool = False, config: Co
:obj:`CopasiAlgorithm`: The copasi algorithm deemed suitable
"""
algorithm_kisao_to_class_map: dict[str, CopasiAlgorithm] = \
{ CopasiAlgorithmType[alg_name].value.KISAO_ID: CopasiAlgorithmType[alg_name].value
for alg_name, _ in CopasiAlgorithmType.__members__.items() }
{CopasiAlgorithmType[alg_name].value.KISAO_ID: CopasiAlgorithmType[alg_name].value
for alg_name, _ in CopasiAlgorithmType.__members__.items()}

legal_alg_kisao_ids = \
[ kisao for kisao, obj in algorithm_kisao_to_class_map.items()
if not events_were_requested or obj.CAN_SUPPORT_EVENTS ]
[kisao for kisao, obj in algorithm_kisao_to_class_map.items()
if not events_were_requested or obj.CAN_SUPPORT_EVENTS]

if kisao_id in legal_alg_kisao_ids:
constructor = algorithm_kisao_to_class_map[kisao_id]
Expand All @@ -76,6 +76,7 @@ def get_algorithm(kisao_id: str, events_were_requested: bool = False, config: Co

raise ValueError(f"No suitable equivalent for '{kisao_id}' could be found with the provided substitution policy")


def set_algorithm_parameter_values(copasi_algorithm: CopasiAlgorithm, requested_changes: list) \
-> tuple[list[AlgorithmParameterChange], list[AlgorithmParameterChange]]:
""" Set a parameter of a COPASI simulation function
Expand Down

0 comments on commit 825a465

Please sign in to comment.