Skip to content

Commit 5a2d0d5

Browse files
authored
Merge pull request #89 from EnzymeML/fix-basico-tl
Fix an issue where parameter estimation fails sometimes
2 parents acd6127 + d7c1226 commit 5a2d0d5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pyenzyme/thinlayers/basico.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ def _initialize_parameters(self):
277277
)
278278

279279
param_dict["name"] = 'Values[' + param.symbol + ']'
280-
parameters.append(param_dict)
280+
281+
# add only if lower and upper bound are not np.nan
282+
if "lower" in param_dict and "upper" in param_dict:
283+
if not (np.isnan(param_dict["lower"]) or np.isnan(param_dict["upper"])):
284+
parameters.append(param_dict)
281285

282286
return parameters
283287

@@ -296,6 +300,9 @@ def _get_experimental_data(self):
296300
# get all species
297301
species_df = basico.get_species(model=self.model).reset_index()
298302

303+
# construct sbml_id to name mapping dictionary
304+
sbml_id_to_name = {row['sbml_id']: row['name'] for _, row in species_df.iterrows()}
305+
299306
# loop over 'id' colum of self.df and create a new experiment for each id
300307
for id in self.df['id'].unique():
301308
# get the dataframe for the id
@@ -315,14 +322,22 @@ def _get_experimental_data(self):
315322
if col in species_df['name'].values:
316323
df = df.rename(columns={col: f"[{col}]"})
317324
continue
325+
if col in sbml_id_to_name.keys():
326+
# locate the name corresponding to the sbml_id
327+
species_name = sbml_id_to_name[col]
328+
df = df.rename(columns={col: f"[{species_name}]"})
329+
continue
318330
# otherwise raise error
319331
else:
320332
raise ValueError(f"Column {col} not found in species_df")
321333

322334
# finally add all the initial concentrations to the dataframe with the
323335
# initial value at Time == 0
324336
for species in inits.species.keys():
325-
df.loc[df.index[0], f"[{species}]_0"] = inits.species[species]
337+
if species in sbml_id_to_name.keys():
338+
df.loc[df.index[0], f"[{sbml_id_to_name[species]}]_0"] = inits.species[species]
339+
else:
340+
df.loc[df.index[0], f"[{species}]_0"] = inits.species[species]
326341

327342
# now add as experiment to basico
328343
basico.add_experiment(name=id, data=df, data_dir=self.model_dir)

0 commit comments

Comments
 (0)