import cobra.test
from cobra.flux_analysis import production_envelope

model = cobra.test.create_test_model("textbook")

"""
Explanation: Production envelopes
Production envelopes (aka phenotype phase planes) will show distinct phases of optimal growth with different use of two different substrates. For more information, see Edwards et al.
Cobrapy supports calculating these production envelopes and they can easily be plotted using your favorite plotting package. Here, we will make one for the "textbook" E. coli core model and demonstrate plotting using matplotlib.
End of explanation
"""


prod_env = production_envelope(model, ["EX_glc__D_e", "EX_o2_e"])

prod_env.head()

"""
Explanation: We want to make a phenotype phase plane to evaluate uptakes of Glucose and Oxygen.
End of explanation
"""


prod_env = production_envelope(
    model, ["EX_o2_e"], objective="EX_ac_e", c_source="EX_glc__D_e")

prod_env.head()

%matplotlib inline

prod_env[prod_env.direction == 'maximum'].plot(
    kind='line', x='EX_o2_e', y='carbon_yield')

"""
Explanation: If we specify the carbon source, we can also get the carbon and mass yield. For example, temporarily setting the objective to produce acetate instead we could get production envelope as follows and pandas to quickly plot the results.
End of explanation
"""


