opencobra / cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
http://opencobra.github.io/cobrapy/
GNU General Public License v2.0
460 stars 216 forks source link

Cannot open valid SMBL models #1125

Closed fatima98crc closed 2 years ago

fatima98crc commented 2 years ago

I am trying to run two established models on COBRApy and I keep getting the following error: "_Model does not contain SBML fbc package information." However, I have checked both models and both are valid. I have not been able to attach them as they are XML files. By the are the well-curated and published Pseudomonas aeruginosa (iPau21) and Bacillus subtilis (Bsu1103) models. Any help would be appreciated.

NB: I validate the model with the SMBL validator and got the following warning: The with the id 'Extracellular' does not have a 'size' attribute, nor is its initial value set by an or

matthiaskoenig commented 2 years ago

You can put the models in a zip archive and upload them here. Without the models it is not possible to debug the issue.

cdiener commented 2 years ago

Hi, the message you are getting is a warning but it should still have read the model unless you got another error message. Can you post the entire output in a code block here as well?

raktim2801 commented 2 years ago

Hi, I am also facing a similar issue. I am getting the following error while trying to load.

GurobiError Traceback (most recent call last) C:\Python\Python37\lib\site-packages\cobra\io\sbml.py in read_sbml_model(filename, number, f_replace, kwargs) 254 f_replace=f_replace, --> 255 kwargs) 256 except IOError as e:

C:\Python\Python37\lib\site-packages\cobra\io\sbml.py in _sbml_to_model(doc, number, f_replace, set_missing_bounds, **kwargs) 359 LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id) --> 360 cobra_model = Model(model_id) 361 cobra_model.name = model.getName()

C:\Python\Python37\lib\site-packages\cobra\core\model.py in init(self, id_or_model, name) 116 interface = configuration.solver --> 117 self._solver = interface.Model() 118 self._solver.objective = interface.Objective(Zero)

C:\Python\Python37\lib\site-packages\optlang\interface.py in init(self, name, objective, variables, constraints, problem, *args, **kwargs) 1190 else: -> 1191 self._initialize_problem() 1192 if variables is not None:

C:\Python\Python37\lib\site-packages\optlang\gurobi_interface.py in _initialize_problem(self) 530 def _initialize_problem(self): --> 531 self.problem = gurobipy.Model() 532 self.problem.params.OutputFlag = 0

src\gurobipy\env.pxi in gurobipy.Env.init()

src\gurobipy\gurobi.pxi in gurobipy.gurobi._getdefaultenv()

src\gurobipy\env.pxi in gurobipy.Env.init()

GurobiError: License expired 2021-09-04

The above exception was the direct cause of the following exception:

CobraSBMLError Traceback (most recent call last)

in ----> 1 M=cobra.io.read_sbml_model("F:\Models\core_v7_2.xml") C:\Python\Python37\lib\site-packages\cobra\io\sbml.py in read_sbml_model(filename, number, f_replace, **kwargs) 266 "\nIf the model is valid and cannot be read please open an issue " 267 "at https://github.com/opencobra/cobrapy/issues .") --> 268 raise_from(cobra_error, original_error) 269 270 C:\Python\Python37\lib\site-packages\six.py in raise_from(value, from_value) CobraSBMLError: Something went wrong reading the SBML model. Most likely the SBML model is not valid. Please check that your model is valid using the `cobra.io.sbml.validate_sbml_model` function or via the online validator at http://sbml.org/validator . `(model, errors) = validate_sbml_model(filename)` If the model is valid and cannot be read please open an issue at https://github.com/opencobra/cobrapy/issues .

But, I have already validated using sbml validator,

This document is valid SBML. However, one or more warnings have been issued.

And the warning is as follows:

WarningAs a principle of best modeling practice, the should set an initial value (amount or concentration) rather than be left undefined. Doing so improves the portability of models between different simulation and analysis systems, and helps make it easier to detect potential errors in models. The with the id 'M_1_4_alpha_D_Glucan_day' does not have an 'initialConcentration' or 'initialAmount' attribute, nor is its initial value set by an or .

The model was created using cobra v0.16.1. Please help me solve the issue. Thanks

Midnighter commented 2 years ago

@matthiaskoenig we need to change something. The solver errors get wrapped in the CobraSBMLError.

@raktim2801 your issue is:

GurobiError: License expired 2021-09-04
raktim2801 commented 2 years ago

@Midnighter Thanks for pointing that. I have uninstalled Gurobipy, which solved the issue for me. But, is it possible to define default / alternate solver (e.g. Optlang) while loading models? Thanks.

matthiaskoenig commented 2 years ago

@midnighter I agree. I wanted to do another round of cleanup better support for sbo and annotations and add type annotations to the sbml module. I would handle the error propagation as part of this. Currently finishing up the FROG project. This is next on my list.

On Sat, Oct 23, 2021, 15:56 Raktim Maiti @.***> wrote:

@Midnighter https://github.com/Midnighter Thanks for pointing that. I have uninstalled Gurobipy, which solved the issue for me. But, is it possible to define default / alternate solver (e.g. Optlang) while loading models? Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/opencobra/cobrapy/issues/1125#issuecomment-950156639, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG33OUCJ4B5EBD5OKN5CTTUIK5IVANCNFSM5GQNROFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

cdiener commented 2 years ago

@raktim2801 you can use the configuration for that: https://cobrapy.readthedocs.io/en/latest/configuration.html#Global-Configuration

fatima98crc commented 2 years ago

GurobiError Traceback (most recent call last) ~/opt/anaconda3/lib/python3.8/site-packages/cobra/io/sbml.py in read_sbml_model(filename, number, f_replace, kwargs) 250 doc = _get_doc_from_filename(filename) --> 251 return _sbml_to_model(doc, number=number, f_replace=f_replace, kwargs) 252 except IOError as e:

~/opt/anaconda3/lib/python3.8/site-packages/cobra/io/sbml.py in _sbml_to_model(doc, number, f_replace, set_missing_bounds, **kwargs) 372 LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id) --> 373 cobra_model = Model(model_id) 374 cobra_model.name = model.getName()

~/opt/anaconda3/lib/python3.8/site-packages/cobra/core/model.py in init(self, id_or_model, name) 119 interface = configuration.solver --> 120 self._solver = interface.Model() 121 self._solver.objective = interface.Objective(Zero)

~/opt/anaconda3/lib/python3.8/site-packages/optlang/gurobi_interface.py in init(self, problem, *args, **kwargs) 514 if problem is None: --> 515 self.problem = gurobipy.Model() 516 self.problem.params.OutputFlag = 0

src/gurobipy/env.pxi in gurobipy.Env.init()

src/gurobipy/gurobi.pxi in gurobipy.gurobi._getdefaultenv()

src/gurobipy/env.pxi in gurobipy.Env.init()

GurobiError: License expired 2021-10-03

The above exception was the direct cause of the following exception:

CobraSBMLError Traceback (most recent call last)

in ----> 1 model=cobra.io.read_sbml_model('Bsu1103.xml') 2 model.solver = 'gurobi' ~/opt/anaconda3/lib/python3.8/site-packages/cobra/io/sbml.py in read_sbml_model(filename, number, f_replace, **kwargs) 263 "at https://github.com/opencobra/cobrapy/issues ." 264 ) --> 265 raise_from(cobra_error, original_error) 266 267 ~/opt/anaconda3/lib/python3.8/site-packages/six.py in raise_from(value, from_value) CobraSBMLError: Something went wrong reading the SBML model. Most likely the SBML model is not valid. Please check that your model is valid using the `cobra.io.sbml.validate_sbml_model` function or via the online validator at http://sbml.org/validator . `(model, errors) = validate_sbml_model(filename)` If the model is valid and cannot be read please open an issue at https://github.com/opencobra/cobrapy/issues However, I have double-checked my Gurobi license and this is active. I tried opening the model on MATLAB and the same issue arises (my license is valid until 2022)
Midnighter commented 2 years ago

Are you sure that the license that is valid until 2022 is the active license? It clearly says

GurobiError: License expired 2021-10-03

which comes directly from Gurobi.

fatima98crc commented 2 years ago

Hi, I did just realize that I had not activated it on my laptop. So sorry about this and thank you so much for your time.

cdiener commented 2 years ago

Cool, sounds like you could fix it :)