# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

# +
# Import libraries - REQUIRES pip version 9.0.3
import pandas
import os
from os.path import join
import sys

# Using Cobrapy 0.13.0
import cobra
import cobra.test
from cobra import Model
from cobra import Metabolite
from cobra import Reaction
from cobra.io import write_sbml_model

# Estabish handler for logger
import logging
logging.basicConfig()
logger = logging.getLogger('logger')

# Verbose exception printing
# %xmode
# -

# Initialize model
toy = Model('toy_model')

# +
# Define reactions and metabolites

cpdA_e = Metabolite(
    'cpdA_e',
    name='compound A',
    compartment='e')
cpdA_c = Metabolite(
    'cpdA_c',
    name='compound A',
    compartment='c')

rxn1 = Reaction('rxn1')
rxn1.name = 'Transport'
rxn1.gene_reaction_rule = 'gene1'
rxn1.lower_bound = 0. 
rxn1.upper_bound = 1000.  
rxn1.add_metabolites({
    cpdA_e: -1.0,
    cpdA_c: 1.0
})

cpdB_c = Metabolite(
    'cpdB_c',
    name='compound B',
    compartment='c')

rxn2 = Reaction('rxn2')
rxn2.name = 'Metabolite conversion 1'
rxn2.gene_reaction_rule = 'gene2'
rxn2.lower_bound = -1000. 
rxn2.upper_bound = 1000.  
rxn2.add_metabolites({
    cpdA_c: -1.0,
    cpdB_c: 1.0
})

cpdC_c = Metabolite(
    'cpdC_c',
    name='compound C',
    compartment='c')

rxn3 = Reaction('rxn3')
rxn3.name = 'Metabolite conversion 2'
rxn3.gene_reaction_rule = 'gene3'
rxn3.lower_bound = 0. 
rxn3.upper_bound = 1000.  
rxn3.add_metabolites({
    cpdB_c: -1.0,
    cpdC_c: 1.0
})

cpdD_c = Metabolite(
    'cpdD_c',
    name='compound D',
    compartment='c')

rxn4 = Reaction('rxn4')
rxn4.name = 'Metabolite conversion 3'
rxn4.gene_reaction_rule = 'gene4'
rxn4.lower_bound = 0. 
rxn4.upper_bound = 1000.  
rxn4.add_metabolites({
    cpdC_c: -1.0,
    cpdD_c: 1.0
})

cpdE_c = Metabolite(
    'cpdE_c',
    name='compound E',
    compartment='c')

rxn5 = Reaction('rxn5')
rxn5.name = 'Metabolite conversion 4'
rxn5.gene_reaction_rule = 'gene5'
rxn5.lower_bound = 0. 
rxn5.upper_bound = 1000.  
rxn5.add_metabolites({
    cpdC_c: -1.0,
    cpdE_c: 1.0
})

rxn6 = Reaction('rxn6')
rxn6.name = 'Metabolite conversion 5'
rxn6.lower_bound = 0. 
rxn6.upper_bound = 1000.  
rxn6.add_metabolites({
    cpdE_c: -1.0,
    cpdD_c: 1.0
})

biomass_cpd = Metabolite(
    'biomass_cpd',
    name='Biomass',
    compartment='c')

biomass_rxn = Reaction('biomass_rxn')
biomass_rxn.name = 'Biomass reaction'
biomass_rxn.lower_bound = 0. 
biomass_rxn.upper_bound = 1000.  
biomass_rxn.add_metabolites({
    cpdD_c: -1.0,
    biomass_cpd: 1.0
})

toy.add_reactions([rxn1,rxn2,rxn3,rxn4,rxn5,rxn6,biomass_rxn])

# -

# Add input and output exchanges
toy.add_boundary(cpdA_e, type='exchange', reaction_id='EX_cpdA_e', lb=-1000.0, ub=1000.0)
toy.add_boundary(biomass_cpd, type='demand', reaction_id='EX_biomass', lb=None, ub=1000.0)

# +
#toy.objective = 'biomass_rxn'
# -

toy

# Write to an SBML for later use
cobra.io.write_sbml_model(toy, 'data/toy_model.sbml')

StarcoderdataJupyterScriptsDedupFiltered