|
6 | 6 |
|
7 | 7 | from __future__ import annotations |
8 | 8 |
|
| 9 | +import contextlib |
| 10 | +import io |
| 11 | +import os |
9 | 12 | from dataclasses import dataclass |
10 | 13 | from pathlib import Path |
11 | | -from joblib import Parallel, delayed |
| 14 | +from typing import Dict, List, Optional, Tuple |
| 15 | + |
12 | 16 | import dill |
13 | 17 | import numpy as np |
14 | 18 | import pandas as pd |
15 | | -import os |
16 | | -import contextlib |
17 | | -import io |
18 | | - |
19 | | -from typing import Dict, List, Optional, Tuple |
| 19 | +from joblib import Parallel, delayed |
20 | 20 |
|
21 | | -from pyenzyme.thinlayers.base import BaseThinLayer, SimResult, Time, InitCondDict |
| 21 | +from pyenzyme.thinlayers.base import BaseThinLayer, InitCondDict, SimResult, Time |
22 | 22 | from pyenzyme.versions import v2 |
23 | 23 |
|
24 | 24 | try: |
@@ -242,7 +242,6 @@ def optimize(self, method="leastsq"): |
242 | 242 |
|
243 | 243 | return result |
244 | 244 |
|
245 | | - |
246 | 245 | def write(self) -> v2.EnzymeMLDocument: |
247 | 246 | """ |
248 | 247 | Creates a new EnzymeML document with optimized parameter values. |
@@ -297,9 +296,9 @@ def _initialize_parameters(self): |
297 | 296 | for param in self.enzmldoc.parameters: |
298 | 297 | # Build kwargs dictionary with conditional assignments |
299 | 298 | kwargs = { |
300 | | - **({'min': param.lower_bound} if param.lower_bound is not None else {}), |
301 | | - **({'max': param.upper_bound} if param.upper_bound is not None else {}), |
302 | | - **({'vary': param.fit}), |
| 299 | + **({"min": param.lower_bound} if param.lower_bound is not None else {}), |
| 300 | + **({"max": param.upper_bound} if param.upper_bound is not None else {}), |
| 301 | + **({"vary": param.fit}), |
303 | 302 | } |
304 | 303 |
|
305 | 304 | # Determine parameter value |
@@ -542,10 +541,13 @@ def to_pysces_model(self, model: pysces.model): |
542 | 541 | """ |
543 | 542 | model = dill.loads(dill.dumps(model)) |
544 | 543 | model.sim_time = np.array(self.time) |
545 | | - model.__dict__.update( |
546 | | - { |
547 | | - f"{species_id}_init": value if value != 0 else 1.0e-9 |
548 | | - for species_id, value in self.species.items() |
549 | | - } |
550 | | - ) |
| 544 | + |
| 545 | + for species, value in self.species.items(): |
| 546 | + if hasattr(model, f"{species}_init"): |
| 547 | + setattr(model, f"{species}_init", value) |
| 548 | + elif hasattr(model, species): |
| 549 | + setattr(model, species, value) |
| 550 | + else: |
| 551 | + raise ValueError(f"Species {species} not found in model") |
| 552 | + |
551 | 553 | return model |
0 commit comments