Skip to content
Snippets Groups Projects
Commit 53ca9853 authored by Peter Schubert's avatar Peter Schubert
Browse files

gba_stoic_problem solved via ipopt using jax autograd and jit

parent 3ed33387
Branches main
No related tags found
No related merge requests found
......@@ -8,5 +8,8 @@ class FbcGeneProduct:
def __init__(self, s_fbc_gene_product):
self.id = s_fbc_gene_product.name
self.name = s_fbc_gene_product.get('name', '')
if ('name' in s_fbc_gene_product) and (type(s_fbc_gene_product['name']) == str):
self.name = s_fbc_gene_product['name']
else:
self.name = self.id
self.label = s_fbc_gene_product['label']
......@@ -10,10 +10,13 @@ class FbcObjective:
def __init__(self, s_fbc_objective):
self.id = s_fbc_objective.name
self.name = s_fbc_objective.get('name', '')
if ('name' in s_fbc_objective) and (type(s_fbc_objective['name']) == str):
self.name = s_fbc_objective['name']
else:
self.name = self.id
self.direction = s_fbc_objective['type']
self.active = s_fbc_objective['active']
self.coefficiants = {}
self.coefficients = {}
for reac_ref in sbmlxdf.record_generator(s_fbc_objective['fluxObjectives']):
params = sbmlxdf.extract_params(reac_ref)
self.coefficiants[params['reac']] = float(params['coef'])
self.coefficients[params['reac']] = float(params['coef'])
......@@ -13,6 +13,10 @@ class XbaCompartment:
def __init__(self, s_compartment):
self.id = s_compartment.name
if ('name' in s_compartment) and (type(s_compartment['name']) == str):
self.name = s_compartment['name']
else:
self.name = self.id
self.name = s_compartment.get('name', self.id)
if 'size' in s_compartment:
self.size = s_compartment['size']
......
......@@ -11,6 +11,10 @@ class XbaFunction:
def __init__(self, s_function):
self.id = s_function.name
if ('name' in s_function) and (type(s_function['name']) == str):
self.name = s_function['name']
else:
self.name = self.id
self.name = s_function.get('name', self.id)
self.math = s_function['math']
......
......@@ -33,18 +33,18 @@ class XbaModel:
print(f'{sbml_file} seems not to be a valid SBML model')
return
model_dict = sbml_model.to_df()
self.id = model_dict['modelAttrs'].id
self.name = model_dict['modelAttrs'].get('name', self.id)
self.unit_defs = {udid: XbaUnitDef(row)
for udid, row in model_dict['unitDefs'].iterrows()}
self.compartments = {cid: XbaCompartment(row)
for cid, row in model_dict['compartments'].iterrows()}
self.parameters = {pid: XbaParameter(row)
for pid, row in model_dict['parameters'].iterrows()}
self.functions = {}
if 'funcDefs' in model_dict:
self.functions = {fid: XbaFunction(row)
for fid, row in model_dict['funcDefs'].iterrows()}
else:
self.functions = {}
self.species = {sid: XbaSpecies(row)
for sid, row in model_dict['species'].iterrows()}
self.reactions = {rid: XbaReaction(row, self.species, self.functions, self.compartments)
......
......@@ -9,7 +9,10 @@ class XbaParameter:
def __init__(self, s_parameter):
self.id = s_parameter.name
self.name = s_parameter.get('name', self.id)
if ('name' in s_parameter) and (type(s_parameter['name']) == str):
self.name = s_parameter['name']
else:
self.name = self.id
self.value = s_parameter['value']
self.constant = s_parameter['constant']
self.units = s_parameter['units']
......
......@@ -14,7 +14,10 @@ class XbaReaction:
def __init__(self, s_reaction, species, functions, compartments):
self.id = s_reaction.name
self.name = s_reaction.get('name', self.id)
if ('name' in s_reaction) and (type(s_reaction['name']) == str):
self.name = s_reaction['name']
else:
self.name = self.id
if ('sboterm' in s_reaction) and (type(s_reaction['sboterm']) is str):
self.sboterm = SboTerm(s_reaction['sboterm'])
self.reaction_string = s_reaction['reactionString']
......
......@@ -12,7 +12,10 @@ class XbaSpecies:
def __init__(self, s_species):
self.id = s_species.name
self.name = s_species.get('name', self.id)
if ('name' in s_species) and (type(s_species['name']) == str):
self.name = s_species['name']
else:
self.name = self.id
# set sboterm to 000247 to support Flux Balance Analysis
self.sboterm = SboTerm(s_species.get('sboterm', 'SBO:0000247'))
self.compartment = s_species['compartment']
......@@ -20,8 +23,12 @@ class XbaSpecies:
self.boundary = s_species['boundaryCondition']
if 'initialConcentration' in s_species:
self.initial_conc = s_species['initialConcentration']
if 'units' in s_species:
if 'substanceUnits' in s_species:
self.units = s_species['substanceUnits']
if 'fbcCharge' in s_species:
self.charge = s_species['fbcCharge']
if 'fbcChemicalFormula' in s_species:
self.formula = s_species['fbcChemicalFormula']
if 'xmlAnnotation' in s_species:
attrs = sbmlxdf.extract_xml_attrs(s_species['xmlAnnotation'], ns=xml_gba_ns, token='molecule')
if 'weight_Da' in attrs:
......
......@@ -11,7 +11,10 @@ class XbaUnitDef:
def __init__(self, s_unit_def):
self.id = s_unit_def.name
self.name = s_unit_def.get('name', self.id)
if ('name' in s_unit_def) and (type(s_unit_def['name']) == str):
self.name = s_unit_def['name']
else:
self.name = self.id
self.units = [XbaUnit(sbmlxdf.extract_params(u))
for u in sbmlxdf.record_generator(s_unit_def['units'])]
......
"""Implementation of FbaProblem Class.
Peter Schubert, HHU Duesseldorf, September 2022
"""
import numpy as np
import math
from scipy import sparse
......@@ -70,7 +74,7 @@ class FbaProblem:
if fbc_obj.active is True:
# self.obj_id = fbc_obj.id
self.obj_dir = fbc_obj.direction
self.objective = fbc_obj.coefficiants
self.objective = fbc_obj.coefficients
break
# lp problem will only be created once required.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment