Skip to content

Commit

Permalink
Flake8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByDrescher committed Aug 24, 2023
1 parent 0b4451f commit 3953895
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
26 changes: 11 additions & 15 deletions biosimulators_copasi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
import biosimulators_copasi.utils as utils

from biosimulators_utils.config import get_config, Config # noqa: F401
from biosimulators_utils.log.data_model import CombineArchiveLog, TaskLog, \
StandardOutputErrorCapturerLevel, SedDocumentLog # noqa: F401
from biosimulators_utils.log.data_model import TaskLog, StandardOutputErrorCapturerLevel, SedDocumentLog # noqa: F401
from biosimulators_utils.viz.data_model import VizFormat # noqa: F401
from biosimulators_utils.report.data_model import ReportFormat, VariableResults, SedDocumentResults # noqa: F401
from biosimulators_utils.sedml.data_model import (Algorithm, AlgorithmParameterChange, Task, Model, Simulation,
ModelLanguage, ModelChange, ModelAttributeChange,
UniformTimeCourseSimulation, Variable, Symbol, SedDocument) # noqa: F401
from biosimulators_utils.sedml.data_model import \
Algorithm, Task, Model, Simulation, ModelLanguage, ModelChange, ModelAttributeChange, \
UniformTimeCourseSimulation, Variable, SedDocument # noqa: F401
from biosimulators_utils.sedml import validation
from biosimulators_utils.utils.core import raise_errors_warnings
from biosimulators_utils.warnings import warn, BioSimulatorsWarning
Expand All @@ -35,7 +34,6 @@
import basico
import COPASI
import lxml
import math
import numpy
import os
import tempfile
Expand All @@ -45,6 +43,7 @@

proper_args: dict = {}


def get_simulator_version():
""" Get the version of COPASI
Expand All @@ -53,6 +52,7 @@ def get_simulator_version():
"""
return basico.__version__


def exec_sedml_docs_in_combine_archive(archive_filename: str, out_dir: str, config: Config = None,
should_fix_copasi_generated_combine_archive: bool = None) -> tuple:
""" Execute the SED tasks defined in a COMBINE/OMEX archive and save the outputs
Expand Down Expand Up @@ -234,7 +234,8 @@ def get_copasi_error_message(sim: Simulation, details=None):
return error_msg


def preprocess_sed_task(task: Task, variables: list[Variable], config: Config = None) -> data_model.BasicoInitialization:
def preprocess_sed_task(task: Task, variables: list[Variable],
config: Config = None) -> data_model.BasicoInitialization:
""" Preprocess a SED task, including its possible model changes and variables. This is useful for avoiding
repeatedly initializing tasks on repeated calls of :obj:`exec_sed_task`.
Expand Down Expand Up @@ -282,7 +283,7 @@ def preprocess_sed_task(task: Task, variables: list[Variable], config: Config =

# process solution algorithm
has_events: bool = basico_data_model.getModel().getNumEvents() >= 1
copasi_algorithm = utils.get_algorithm(sim.algorithm.kisao_id, has_events, config=config)
copasi_algorithm = utils.get_algorithm(utc_sim.algorithm.kisao_id, has_events, config=config)

# Create and return preprocessed simulation settings
preprocessed_info = data_model.BasicoInitialization(copasi_algorithm, variables, has_events)
Expand Down Expand Up @@ -332,9 +333,6 @@ def _apply_model_changes(sedml_model: Model, copasi_algorithm: utils.CopasiAlgor
legal_changes: list[ModelAttributeChange] = []
illegal_changes: list[ModelChange] = []

specs = basico.get_species()
comps = basico.get_compartments()

# If there's no changes, get out of here
if not sedml_model.changes:
return legal_changes, illegal_changes
Expand Down Expand Up @@ -368,8 +366,8 @@ def _apply_model_changes(sedml_model: Model, copasi_algorithm: utils.CopasiAlgor
basico.set_compartment(compart_map["name"], initial_size=model_change.new_value)
continue

#reaction = basico.get_reactions(sbml_id=sbml_id)
#if reaction is not None:
# reaction = basico.get_reactions(sbml_id=sbml_id)
# if reaction is not None:
# basico.set_reaction(sbml_id=sbml_id, ???)
# continue

Expand All @@ -382,7 +380,6 @@ def _apply_model_changes(sedml_model: Model, copasi_algorithm: utils.CopasiAlgor

def _load_algorithm_parameters(sim: Simulation, copasi_algorithm: utils.CopasiAlgorithm, config: Config = None):
# Load the algorithm parameter changes specified by `simulation.algorithm_parameter_changes`
method_parameters = {}
algorithm_substitution_policy: AlgSubPolicy = bsu_sim_utils.get_algorithm_substitution_policy(config=config)
requested_algorithm: Algorithm = sim.algorithm
if copasi_algorithm.KISAO_ID != requested_algorithm.kisao_id:
Expand Down Expand Up @@ -411,4 +408,3 @@ def _load_algorithm_parameters(sim: Simulation, copasi_algorithm: utils.CopasiAl
warn(warning_message.format(change.new_value, change.kisao_id), BioSimulatorsWarning)

return

60 changes: 36 additions & 24 deletions biosimulators_copasi/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

import basico
import pandas
from biosimulators_utils.data_model import ValueType
import collections
import enum
import math

__all__ = [
'Units',
Expand Down Expand Up @@ -107,7 +104,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -125,7 +123,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -143,7 +142,8 @@ def get_value(self) -> bool:
return self._value

def set_value(self, new_value: bool):
if new_value is not None and not (type(new_value) == bool): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == bool): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -161,7 +161,8 @@ def get_value(self) -> int:
return self._value

def set_value(self, new_value: int):
if new_value is not None and not (type(new_value) == int): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == int): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -179,7 +180,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -197,7 +199,8 @@ def get_value(self) -> int:
return self._value

def set_value(self, new_value: int):
if new_value is not None and not (type(new_value) == int): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == int): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -224,7 +227,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -242,7 +246,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -260,7 +265,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -278,7 +284,8 @@ def get_value(self) -> int:
return self._value

def set_value(self, new_value: int):
if new_value is not None and not (type(new_value) == int): # can't use isinstance because PEP 285:
# can't use isinstance because PEP 285:
if new_value is not None and not (type(new_value) == int): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -296,7 +303,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285:
# can't use isinstance because PEP 285:
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand Down Expand Up @@ -325,7 +333,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -342,7 +351,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -360,7 +370,8 @@ def get_value(self) -> float:
return self._value

def set_value(self, new_value: float):
if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285
# can't use isinstance because PEP 285
if new_value is not None and not (type(new_value) == float): # noqa: E721
raise ValueError
self._value = new_value

Expand All @@ -378,7 +389,8 @@ def get_value(self) -> bool:
return self._value

def set_value(self, new_value: bool):
if new_value is not None and not (type(new_value) == bool): # can't use isinstance because PEP 285:
# can't use isinstance because PEP 285:
if new_value is not None and not (type(new_value) == bool): # noqa: E721
raise ValueError
self._value = new_value

Expand Down Expand Up @@ -432,12 +444,11 @@ def get_method_settings(self) -> dict[str, str]:
def __eq__(self, other):
if not isinstance(other, type(self)):
return False
return (True if (
self.KISAO_ID == other.KISAO_ID,
self.ID == other.ID,
self.NAME == other.NAME,
equality = self.KISAO_ID == other.KISAO_ID and \
self.ID == other.ID and \
self.NAME == other.NAME and \
self.CAN_SUPPORT_EVENTS == other.CAN_SUPPORT_EVENTS
) else False)
return True if equality else False


class GibsonBruckAlgorithm(CopasiAlgorithm):
Expand Down Expand Up @@ -757,6 +768,7 @@ class CopasiAlgorithmType(enum.Enum):
HYBRID_RK45 = HybridRK45Algorithm
SDE_SOLVE_RI5 = SDESolveRI5Algorithm


class CopasiMappings:
@staticmethod
def format_to_copasi_reaction_name(sbml_name: str):
Expand Down Expand Up @@ -821,7 +833,7 @@ def _map_sbml_id_to_copasi_name(for_output: bool) -> dict[str, str]:
compartment_mapping = {compartments.at[row, "sbml_id"]: str(row) for row in compartments.index}
metabolites_mapping = {metabolites.at[row, "sbml_id"]: str(row) for row in metabolites.index}
reactions_mapping = {reactions.at[row, "sbml_id"]: str(row) for row in reactions.index}
parameters_mapping = {parameters.at[row, "sbml_id"] : str(row) for row in parameters.index}
parameters_mapping = {parameters.at[row, "sbml_id"]: str(row) for row in parameters.index}

# Combine mappings
sbml_id_to_sbml_name_map = {"Time": "Time"}
Expand Down
8 changes: 1 addition & 7 deletions biosimulators_copasi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
from biosimulators_utils.combine.io import CombineArchiveReader, CombineArchiveWriter
from biosimulators_utils.config import get_config, Config # noqa: F401
from biosimulators_utils.simulator.utils import get_algorithm_substitution_policy
from biosimulators_utils.sedml.data_model import Variable, UniformTimeCourseSimulation, AlgorithmParameterChange
from biosimulators_utils.sedml.data_model import AlgorithmParameterChange
from kisao.data_model import AlgorithmSubstitutionPolicy, ALGORITHM_SUBSTITUTION_POLICY_LEVELS
from kisao.utils import get_preferred_substitute_algorithm_by_ids
import libsedml
import lxml
import os
import shutil
import tempfile
import pandas

__all__ = [
'get_algorithm',
Expand Down Expand Up @@ -178,8 +177,3 @@ def fix_copasi_generated_combine_archive(in_filename, out_filename, config=None)
CombineArchiveWriter().run(archive, archive_directory_name, out_filename)
finally:
shutil.rmtree(archive_directory_name)





0 comments on commit 3953895

Please sign in to comment.