How to use the cameo.config function in cameo

To help you get started, we’ve selected a few cameo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biosustain / cameo / cameo / strain_design / heuristic / evolutionary / objective_functions.py View on Github external
if self.carbon_yield:
            product = model.reaction.get_by_id(self.product)
            if product.boundary:
                product_flux = round(solution.fluxes[self.product], config.ndecimals) * n_carbon(product)
            else:
                product_flux = round(solution.fluxes[self.product], config.ndecimals) * n_carbon(product) / 2
            substrate_flux = 0
            for substrate_id in self.substrates:
                substrate = model.reactions.get_by_id(substrate_id)
                if substrate.boundary:
                    substrate_flux += abs(solution.fluxes[substrate_id]) * n_carbon(substrate)
                else:
                    substrate_flux += abs(solution.fluxes[substrate_id]) * n_carbon(substrate) / 2
            substrate_flux = round(substrate_flux, config.ndecimals)
        else:
            product_flux = round(solution.fluxes[self.product], config.ndecimals)
            substrate_flux = round(sum(abs(solution.fluxes[s]) for s in self.substrates), config.ndecimals)
        if substrate_flux > config.non_zero_flux_threshold:
            return (biomass_flux * product_flux) / substrate_flux
        else:
            return 0.
github biosustain / cameo / cameo / visualization / plotting.py View on Github external
def plot_production_envelope(envelope, objective, key, grid=None, width=None, height=None, title=None,
                             points=None, points_colors=None, axis_font_size=None):

    if width is None and height is None:
        width = 700
    if width is None or height is None:
        width, height = _golden_ratio(width, height)
    if util.in_ipnb():
        if config.use_bokeh:
            plot_production_envelope_ipython_bokeh(envelope, objective, key, grid=grid, width=width, height=height,
                                                   title=title, points=points, points_colors=points_colors,
                                                   axis_font_size=axis_font_size)
        elif config.use_matplotlib:
            plot_production_envelope_ipython_matplotlib(envelope, objective, key, grid=grid, width=width, height=height,
                                                        title=title, points=points, points_colors=points_colors,
                                                        axis_font_size=axis_font_size)
    else:
        plot_production_envelope_cli(envelope, objective, key, width=width, height=height, title=title, points=points,
                                     points_colors=points_colors, axis_font_size=axis_font_size)
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary / multiprocess / plotters.py View on Github external
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

__all__ = ['IPythonNotebookBokehMultiprocessPlotObserver']

from multiprocessing.queues import Full
from pandas import DataFrame
from cameo import config
from cameo.strain_design.heuristic.evolutionary.multiprocess.observers import AbstractParallelObserver, \
    AbstractParallelObserverClient

if config.use_bokeh:
    from bokeh.plotting import figure, show
    from bokeh.models import ColumnDataSource
    from bokeh.io import push_notebook


class IPythonNotebookBokehMultiprocessPlotObserver(AbstractParallelObserver):
    __name__ = "IPython Notebook Bokeh Multiprocess Plot Observer"

    def __init__(self, color_map={}, *args, **kwargs):
        super(IPythonNotebookBokehMultiprocessPlotObserver, self).__init__(*args, **kwargs)
        self.connections = {}
        self.color_map = color_map
        self.data_frame = DataFrame(columns=['iteration', 'island', 'color', 'fitness'])
        self.plotted = False
        self.handle = None
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary / plotters.py View on Github external
#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

import scipy
import numpy as np

from cameo import config

if config.use_bokeh:
    from bokeh.plotting import show, figure
    from bokeh.models import ColumnDataSource
    from bokeh.io import push_notebook


class IPythonBokehFitnessPlotter(object):
    __name__ = "IPython Bokeh Fitness Plot"

    def __init__(self, window_size=1000):
        self.iteration = 0
        self.window_size = window_size
        self.iterations = []
        self.fitness = []
        self.uuid = None
        self.plotted = False
github biosustain / cameo / cameo / strain_design / heuristics / single_objective.py View on Github external
    def run(self, view=config.default_view, **kwargs):
        return self.heuristic_method.evolve(
            generator=self._generate_individual,
            maximize=True,
            view=view,
            evaluator=self._evaluate_population,
            archive=self.archive,
            **kwargs)
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary / multiprocess / optimization.py View on Github external
def _set_observers(self, number_of_islands):
        observers = []

        plotting_observer = None
        if util.in_ipnb():
            color_map = util.generate_colors(number_of_islands)
            progress_observer = IPythonNotebookMultiprocessProgressObserver(number_of_islands=number_of_islands)
            if config.use_bokeh:
                plotting_observer = IPythonNotebookBokehMultiprocessPlotObserver(number_of_islands=number_of_islands,
                                                                                 color_map=color_map)
        else:
            progress_observer = CliMultiprocessProgressObserver(number_of_islands=number_of_islands)

        if progress_observer is not None:
            observers.append(progress_observer)
        if plotting_observer is not None:
            observers.append(plotting_observer)

        return observers
github biosustain / cameo / cameo / strain_design / heuristic / __init__.py View on Github external
def _set_observer(self):
        self.observer = []

        if in_ipnb():
            if config.use_bokeh:
                if self.is_mo():
                    self.observer.append(plotters.IPythonBokehParetoPlotter(self.objective_function))
                else:
                    self.observer.append(plotters.IPythonBokehFitnessPlotter())
            elif config.use_matplotlib:
                pass
            else:
                pass
            self.observer.append(observers.IPythonNotebookProgressObserver())

        else:
            if config.use_bokeh:
                pass
            else:
                pass
            self.observer.append(observers.CLIProgressObserver())
github biosustain / cameo / cameo / visualization / plotting.py View on Github external
def _plot_grid(self):
        if util.in_ipnb():
            if config.use_bokeh:
                self._plot_bokeh_grid()
            elif config.use_matplotlib:
                self._plot_matplotlib_grid()
        else:
            self._plot_cli_grid()