{"action":"created","issue":{"url":"https://api.github.com/repos/opencobra/cobrapy/issues/591","repository_url":"https://api.github.com/repos/opencobra/cobrapy","labels_url":"https://api.github.com/repos/opencobra/cobrapy/issues/591/labels{/name}","comments_url":"https://api.github.com/repos/opencobra/cobrapy/issues/591/comments","events_url":"https://api.github.com/repos/opencobra/cobrapy/issues/591/events","html_url":"https://github.com/opencobra/cobrapy/issues/591","id":257398597,"number":591,"title":"write_sbml_model() stores metabolite charges as floats instead of ints","user":{"login":"mmundy42","id":2896238,"avatar_url":"https://avatars0.githubusercontent.com/u/2896238?v=4","gravatar_id":"","url":"https://api.github.com/users/mmundy42","html_url":"https://github.com/mmundy42","followers_url":"https://api.github.com/users/mmundy42/followers","following_url":"https://api.github.com/users/mmundy42/following{/other_user}","gists_url":"https://api.github.com/users/mmundy42/gists{/gist_id}","starred_url":"https://api.github.com/users/mmundy42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmundy42/subscriptions","organizations_url":"https://api.github.com/users/mmundy42/orgs","repos_url":"https://api.github.com/users/mmundy42/repos","events_url":"https://api.github.com/users/mmundy42/events{/privacy}","received_events_url":"https://api.github.com/users/mmundy42/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-13T14:19:41Z","updated_at":"2017-09-13T16:32:23Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"#### Problem description\r\n\r\nPlease explain:\r\n* **what** I wrote a model to a SBML format file and then read the SBML file back (round trip). When the metabolites in the model have charges that are floats, the SBML file has the charge as a float and an exception is raised when reading the SBML file. Note that cobra.core.Metabolite defines the charge attribute as a float.\r\n* **why** I expected cobra.io.write_sbml_model() to generate a SBML file that can be read by cobra.io.read_sbml_model().\r\n\r\nOne possible fix is to change line 486 of cobra.io.sbml3 to:\r\n\r\n```python\r\nset_attrib(species, \"fbc:charge\", int(met.charge))\r\n```\r\n\r\nbut I'm not sure how that would impact the changes discussed in #534.\r\n\r\n#### Code Sample\r\n\r\n```python\r\nimport cobra\r\nfrom cobra.test import create_test_model\r\nmodel1 = create_test_model('textbook')\r\nmodel1.metabolites[0].charge = -4.0\r\ncobra.io.write_sbml_model(model1, 'textbook.sbml')\r\nmodel2 = cobra.io.read_sbml_model('textbook.sbml')\r\nTraceback (most recent call last):\r\n  File \"<input>\", line 1, in <module>\r\n  File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cobra/io/sbml3.py\", line 586, in read_sbml_model\r\n    \"Something went wrong reading the model. You can get a detailed \"\r\nCobraSBMLError: Something went wrong reading the model. You can get a detailed report using the `cobra.io.sbml3.validate_sbml_model` function or using the online validator at http://sbml.org/validator\r\ncobra.io.sbml3.validate_sbml_model('textbook.sbml')\r\n(None, {'validator': [], 'other': [\"invalid literal for int() with base 10: '-4.0'\"], 'SBML errors': [], 'warnings': []})\r\n```\r\n\r\n#### Actual Output\r\n\r\nread_sbml_model() raises a CobraSBMLError exception.\r\n\r\n#### Expected Output\r\n\r\nread_sbml_model() returns success when reading a SBML file created by write_sbml_model().\r\n\r\n#### Output of `cobra.show_versions()`\r\n\r\n<details>\r\nSystem Information\r\n==================\r\nOS              Darwin\r\nOS-release      16.7.0\r\nPython          2.7.13\r\nPackage Versions\r\n================\r\npip              9.0.1\r\nsetuptools      36.2.6\r\ncobra            0.8.2\r\nfuture          0.16.0\r\nswiglpk          1.4.4\r\noptlang          1.2.2\r\nruamel.yaml    0.14.12\r\npandas          0.20.3\r\nnumpy           1.13.1\r\ntabulate         0.7.7\r\npython-libsbml  5.13.0\r\nlxml             3.8.0\r\nscipy           0.19.1\r\nmatplotlib       2.0.2\r\n</details>\r\n"},"comment":{"url":"https://api.github.com/repos/opencobra/cobrapy/issues/comments/329224056","html_url":"https://github.com/opencobra/cobrapy/issues/591#issuecomment-329224056","issue_url":"https://api.github.com/repos/opencobra/cobrapy/issues/591","id":329224056,"user":{"login":"cdiener","id":7153935,"avatar_url":"https://avatars3.githubusercontent.com/u/7153935?v=4","gravatar_id":"","url":"https://api.github.com/users/cdiener","html_url":"https://github.com/cdiener","followers_url":"https://api.github.com/users/cdiener/followers","following_url":"https://api.github.com/users/cdiener/following{/other_user}","gists_url":"https://api.github.com/users/cdiener/gists{/gist_id}","starred_url":"https://api.github.com/users/cdiener/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdiener/subscriptions","organizations_url":"https://api.github.com/users/cdiener/orgs","repos_url":"https://api.github.com/users/cdiener/repos","events_url":"https://api.github.com/users/cdiener/events{/privacy}","received_events_url":"https://api.github.com/users/cdiener/received_events","type":"User","site_admin":false},"created_at":"2017-09-13T16:32:23Z","updated_at":"2017-09-13T16:32:23Z","author_association":"MEMBER","body":"Since SBML with FBC only allows int charges the suggested fix makes sense to me. Should also create an entry in the logger."}}
{"actor":{"display_login":"cdiener"}}