Yield all the non exchange reactions in the model.
7219
def _adjustment_reactions(self):
        """"""
        for reaction_id in self._model.reactions:
            if not self._model.is_exchange(reaction_id):
                yield reaction_id
71372
def find_unconstrained_reactions(model):
    """"""
    lower_bound, upper_bound = helpers.find_bounds(model)
    return [rxn for rxn in model.reactions if
            rxn.lower_bound <= lower_bound and
            rxn.upper_bound >= upper_bound]
237779
def check_all(self) -> Generator[AAAError, None, None]:
        
        # Function def
        if function_is_noop(self.node):
            return
        self.mark_bl()
        self.mark_def()
        # ACT
        # Load act block and kick out when none is found
        self.act_node = self.load_act_node()
        self.act_block = Block.build_act(self.act_node.node, self.node)
        act_block_first_line_no, act_block_last_line_no = self.act_block.get_span(0)
        # ARRANGE
        self.arrange_block = Block.build_arrange(self.node.body, act_block_first_line_no)
        # ASSERT
        assert self.act_node
        self.assert_block = Block.build_assert(self.node.body, act_block_last_line_no)
        # SPACING
        for block in ['arrange', 'act', 'assert']:
            self_block = getattr(self, '{}_block'.format(block))
            try:
                span = self_block.get_span(self.first_line_no)
            except EmptyBlock:
                continue
            self.line_markers.update(span, self_block.line_type)
        yield from self.line_markers.check_arrange_act_spacing()
        yield from self.line_markers.check_act_assert_spacing()
        yield from self.line_markers.check_blank_lines()
821532
def run(self):
        """"""

        # Create dictonary of signatures
        database_signatures = {}
        for entry in self._model.reactions:
            signature = reaction_signature(
                entry.equation, direction=self._args.compare_direction,
                stoichiometry=self._args.compare_stoichiometry)
            database_signatures.setdefault(signature, set()).add(
                (entry.id, entry.equation, entry.filemark))

        for reaction_set in itervalues(database_signatures):
            if len(reaction_set) > 1:
                print('Found {} duplicate reactions:'.format(
                    len(reaction_set)))
                for reaction, equation, filemark in reaction_set:
                    result = ' - {}: {}'.format(reaction, equation)
                    if filemark is not None:
                        result += ' (found in {})'.format(filemark)
                    print(result)
11286
def find_zero_constrained_reactions(model):
    """"""
    return [rxn for rxn in model.reactions if
            rxn.lower_bound == 0 and
            rxn.upper_bound == 0]
409066
def _generator_other(self):
        """"""
        for path in self.paths:
            for root, dnames, fnames in self._walker(path):
                yield from self._generator_rebase(dnames, root)
                yield from self._generator_rebase(fnames, root)
81986
def columns(self, model=None):
        
        column = self.column(model=model)
        if column:
            yield column

        check = self.__value
        if not isinstance(check, (list, set, tuple)):
            check = (check,)

        for val in check:
            if isinstance(val, (Query, QueryCompound)):
                for col in val.columns(model):
                    yield col
139906
def add_all_exchange_reactions(model, compartment, allow_duplicates=False):
    

    all_reactions = {}
    if not allow_duplicates:
        # TODO: Avoid adding reactions that already exist in the database.
        # This should be integrated in the database.
        for rxnid in model.database.reactions:
            rx = model.database.get_reaction(rxnid)
            all_reactions[rx] = rxnid

    added = set()
    added_compounds = set()
    initial_compounds = set(model.compounds)
    reactions = set(model.database.reactions)
    for model_compound in initial_compounds:
        compound = model_compound.in_compartment(compartment)
        if compound in added_compounds:
            continue

        rxnid_ex = create_exchange_id(reactions, compound)

        reaction_ex = Reaction(Direction.Both, {compound: -1})
        if reaction_ex not in all_reactions:
            model.database.set_reaction(rxnid_ex, reaction_ex)
            reactions.add(rxnid_ex)
        else:
            rxnid_ex = all_reactions[reaction_ex]

        if not model.has_reaction(rxnid_ex):
            added.add(rxnid_ex)
        model.add_reaction(rxnid_ex)
        added_compounds.add(compound)

    return added
148047
def run(self):
        """"""

        # Load compound information
        def compound_name(id):
            if id not in self._model.compounds:
                return id
            return self._model.compounds[id].properties.get('name', id)

        epsilon = self._args.epsilon

        if self._args.unrestricted:
            # Allow all exchange reactions with no flux limits
            for reaction in self._mm.reactions:
                if self._mm.is_exchange(reaction):
                    del self._mm.limits[reaction].bounds

        loop_removal = self._get_loop_removal_option()
        enable_tfba = loop_removal == 'tfba'
        enable_fastcore = self._args.fastcore

        if enable_tfba and enable_fastcore:
            self.argument_error(
                'Using Fastcore with thermodynamic constraints'
                ' is not supported!')
        start_time = time.time()

        if enable_fastcore:
            solver = self._get_solver()
            try:
                inconsistent = set(fastcore.fastcc(
                    self._mm, epsilon, solver=solver))
            except fluxanalysis.FluxBalanceError as e:
                self.report_flux_balance_error(e)
        else:
            if enable_tfba:
                solver = self._get_solver(integer=True)
            else:
                solver = self._get_solver()

            if self._args.reduce_lp:
                logger.info('Running with reduced number of LP problems.')
                try:
                    inconsistent = set(
                        fluxanalysis.consistency_check(
                            self._mm, self._mm.reactions, epsilon,
                            tfba=enable_tfba, solver=solver))
                except fluxanalysis.FluxBalanceError as e:
                    self.report_flux_balance_error(e)
            else:
                logger.info('Using flux bounds to determine consistency.')
                try:
                    inconsistent = set(self._run_fva_fluxcheck(
                        self._mm, solver, enable_tfba, epsilon))
                except FluxCheckFVATaskError:
                    self.report_flux_balance_error()

        logger.info('Solving took {:.2f} seconds'.format(
            time.time() - start_time))

        # Count the number of reactions that are fixed at zero. While these
        # reactions are still inconsistent, they are inconsistent because they
        # have been explicitly disabled.
        disabled_exchange = 0
        disabled_internal = 0

        count_exchange = 0
        total_exchange = 0

        count_internal = 0
        total_internal = 0

        # Print result
        for reaction in sorted(self._mm.reactions):
            disabled = self._mm.limits[reaction].bounds == (0, 0)

            if self._mm.is_exchange(reaction):
                total_exchange += 1
                count_exchange += int(reaction in inconsistent)
                disabled_exchange += int(disabled)
            else:
                total_internal += 1
                count_internal += int(reaction in inconsistent)
                disabled_internal += int(disabled)

            if reaction in inconsistent:
                rx = self._mm.get_reaction(reaction)
                rxt = rx.translated_compounds(compound_name)
                print('{}\t{}'.format(reaction, rxt))

        logger.info('Model has {}/{} inconsistent internal reactions'
                    ' ({} disabled by user)'.format(
                        count_internal, total_internal, disabled_internal))
        logger.info('Model has {}/{} inconsistent exchange reactions'
                    ' ({} disabled by user)'.format(
                        count_exchange, total_exchange, disabled_exchange))
1038366
def batch(self):
        """"""
        _batch = []
        yield _batch
        if _batch:
            new_part = super(type(self), type(self)).empty()
            new_part._from_entities(_batch, _batch[0].__dimension__)
            self.concat(new_part, inplace=True)
101218
def generate_model(self, model_name=None):
        """"""

        for i, c in enumerate(self._components):
            c.generate_model(model_name=model_name)
680028
def copy(self):
        """"""

        model = self.__class__(self._database)
        model._limits_lower = dict(self._limits_lower)
        model._limits_upper = dict(self._limits_upper)
        model._reaction_set = set(self._reaction_set)
        model._compound_set = set(self._compound_set)
        return model
124162
def get_all(self):
        ''''''
        for name, values in self._map.items():
            for value in values:
                yield (name, value)
908523
def columns(self, model=None):
        
        for query in self.__queries:
            for column in query.columns(model=model):
                yield column
601721
def _yield_all(self, l):
        '''
        
        '''
        if l is not None:
            if type(l) in [list, tuple]:
                for f in l:
                    for x in self._yield(f): yield x
            else:
                for x in self._yield(l): yield x
1202242
def parse_reaction(s):
    """"""

    def parse_count(s):
        m = re.match(r'^\((.+)\)$', s)
        if m is not None:
            s = m.group(1)

        m = re.match(r'^\d+$', s)
        if m is not None:
            return int(m.group(0))

        return Expression(s)

    def parse_compound(s):
        m = re.match(r'(.+)\((.+)\)', s)
        if m is not None:
            return Compound(m.group(1), arguments=[Expression(m.group(2))])
        return Compound(s)

    def parse_compound_list(s):
        for cpd in s.split(' + '):
            if cpd == '':
                continue

            fields = cpd.strip().split(' ')
            if len(fields) > 2:
                raise ParseError(
                    'Malformed compound specification: {}'.format(cpd))
            if len(fields) == 1:
                count = 1
                compound = parse_compound(fields[0])
            else:
                count = parse_count(fields[0])
                compound = parse_compound(fields[1])

            yield compound, count

    cpd_left, cpd_right = s.split('<=>')
    left = parse_compound_list(cpd_left.strip())
    right = parse_compound_list(cpd_right.strip())

    return Reaction(Direction.Both, left, right)
47855
def charge_balance(model):
    

    compound_charge = {}
    for compound in model.compounds:
        if compound.charge is not None:
            compound_charge[compound.id] = compound.charge

    for reaction in model.reactions:
        charge = reaction_charge(reaction.equation, compound_charge)
        yield reaction, charge