6.1.1.4. pytfa.optim

6.1.1.4.1. Submodules

6.1.1.4.2. Package Contents

6.1.1.4.2.1. Classes

GenericConstraint

Class to represent a generic constraint. The purpose is that the interface

ModelConstraint

Class to represent a variable attached to the model

GeneConstraint

Class to represent a variable attached to a enzyme

ReactionConstraint

Class to represent a variable attached to a reaction

MetaboliteConstraint

Class to represent a variable attached to a enzyme

NegativeDeltaG

Class to represent thermodynamics constraints.

ForwardDeltaGCoupling

Class to represent thermodynamics coupling: DeltaG of reactions has to be

BackwardDeltaGCoupling

Class to represent thermodynamics coupling: DeltaG of reactions has to be

ForwardDirectionCoupling

Class to represent a forward directionality coupling with thermodynamics on

BackwardDirectionCoupling

Class to represent a backward directionality coupling with thermodynamics on

SimultaneousUse

Class to represent a simultaneous use constraint on reaction variables

DisplacementCoupling

Class to represent the coupling to the thermodynamic displacement

ForbiddenProfile

Class to represent a forbidden net flux directionality profile

LinearizationConstraint

Class to represent a variable attached to a reaction

GenericVariable

Class to represent a generic variable. The purpose is that the interface

ModelVariable

Class to represent a variable attached to the model

GeneVariable

Class to represent a gene variable

BinaryVariable

Class to represent a generic binary variable

ReactionVariable

Class to represent a variable attached to a reaction

MetaboliteVariable

Class to represent a variable attached to a enzyme

ForwardUseVariable

Class to represent a forward use variable, a type of binary variable used to

BackwardUseVariable

Class to represent a backward use variable, a type of binary variable used

ForwardBackwardUseVariable

Class to represent a type of binary variable used to tell whether the

LogConcentration

Class to represent a log concentration of a enzyme

DeltaGErr

Class to represent a DeltaGErr

DeltaG

Class to represent a DeltaG

DeltaGstd

Class to represent a DeltaG^o (naught) - standard conditions

ThermoDisplacement

Class to represent the thermodynamic displacement of a reaction

PosSlackVariable

Class to represent a positive slack variable for relaxation problems

NegSlackVariable

Class to represent a negative slack variable for relaxation problems

PosSlackLC

Class to represent a variable attached to a enzyme

NegSlackLC

Class to represent a variable attached to a enzyme

LinearizationVariable

Class to represent a product A*B when performing linearization of the

NegativeDeltaG

Class to represent thermodynamics constraints.

PosSlackVariable

Class to represent a positive slack variable for relaxation problems

NegSlackVariable

Class to represent a negative slack variable for relaxation problems

DeltaGstd

Class to represent a DeltaG^o (naught) - standard conditions

LogConcentration

Class to represent a log concentration of a enzyme

NegSlackLC

Class to represent a variable attached to a enzyme

PosSlackLC

Class to represent a variable attached to a enzyme

GenericConstraint

Class to represent a generic constraint. The purpose is that the interface

ForwardUseVariable

Class to represent a forward use variable, a type of binary variable used to

BackwardUseVariable

Class to represent a backward use variable, a type of binary variable used

GenericVariable

Class to represent a generic variable. The purpose is that the interface

6.1.1.4.2.2. Functions

camel2underscores(name)

camel2underscores(name)

get_binary_type()

FIX : We enforce type to be integer instead of binary, else optlang does

dg_relax_config(model)

param model

get_solution_value_for_variables(solution, these_vars, index_by_reaction=False)

chunk_sum(variables)

This functions handles the sum of many sympy variables by chunks, which

symbol_sum(variables)

``` python

relax_dgo_gurobi(model, relax_obj_type=0)

relax_dgo(tmodel, reactions_to_ignore=(), solver=None, in_place=False)

param t_tmodel

relax_lc(tmodel, metabolites_to_ignore=(), solver=None)

param metabolites_to_ignore

get_all_subclasses(cls)

Given a variable or constraint class, get all the subclassses

chunk_sum(variables)

This functions handles the sum of many sympy variables by chunks, which

symbol_sum(variables)

``` python

get_solution_value_for_variables(solution, these_vars, index_by_reaction=False)

compare_solutions(models)

returns the solution dictionnary for each cobra_model

evaluate_constraint_at_solution(constraint, solution)

param expression

get_active_use_variables(tmodel, solution)

Returns the active use variables in a solution. Use Variables are binary

get_direction_use_variables(tmodel, solution)

Returns the active use variables in a solution. Use Variables are binary

get_primal(tmodel, vartype, index_by_reactions=False)

Returns the primal value of the cobra_model for variables of a given type

strip_from_integer_variables(tmodel)

Removes all integer and binary variables of a cobra_model, to make it sample-able

copy_solver_configuration(source, target)

Copies the solver configuration from a source model to a target model

6.1.1.4.2.3. Attributes

ABCRequirePrefixMeta

ABCRequirePrefixMeta

op_replace_dict

BIGM

BIGM_THERMO

BIGM_DG

BIGM_P

EPSILON

SYMPY_ADD_CHUNKSIZE

INTEGER_VARIABLE_TYPES

pytfa.optim.camel2underscores(name)
pytfa.optim.ABCRequirePrefixMeta
class pytfa.optim.GenericConstraint(expr, id_='', model=None, hook=None, queue=False, **kwargs)[source]
Class to represent a generic constraint. The purpose is that the interface

is instantiated on initialization, to follow the type of interface used by the problem, and avoid incompatibilities in optlang

Attributes:

id

Used for DictList comprehension. Usually points back at a

enzyme or reaction id for ease of linking. Should be unique given a constraint type. :name: Should be a concatenation of the id and a prefix that is specific to the variable type. will be used to address the constraint at the solver level, and hence should be unique in the whole cobra_model :expr: the expression of the constraint (sympy.Expression subtype) :cobra_model: the cobra_model hook. :constraint: links directly to the cobra_model representation of tbe constraint

prefix
property __attrname__(self)

Name the attribute the instances will have Example: GenericConstraint -> generic_constraint :return:

get_interface(self, expr, queue)

Called upon completion of __init__, initializes the value of self.var, which is returned upon call, and stores the actual interfaced variable.

Returns

instance of Variable from the problem

make_name(self)
Needs to be overridden by the subclass, concats the id with a

prefix

Returns

None

change_expr(self, new_expr, sloppy=False)
property expr(self)
property name(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property constraint(self)
property model(self)
__repr__(self)

Return repr(self).

class pytfa.optim.ModelConstraint(model, expr, id_, **kwargs)[source]

Bases: GenericConstraint

Class to represent a variable attached to the model

prefix = MODC_
class pytfa.optim.GeneConstraint(gene, expr, **kwargs)[source]

Bases: GenericConstraint

Class to represent a variable attached to a enzyme

prefix = GC_
property gene(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property model(self)
class pytfa.optim.ReactionConstraint(reaction, expr, **kwargs)[source]

Bases: GenericConstraint

Class to represent a variable attached to a reaction

prefix = RC_
property reaction(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property model(self)
class pytfa.optim.MetaboliteConstraint(metabolite, expr, **kwargs)[source]

Bases: GenericConstraint

Class to represent a variable attached to a enzyme

prefix = MC_
property metabolite(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property model(self)
class pytfa.optim.NegativeDeltaG(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent thermodynamics constraints.

G: - DGR_rxn + DGoRerr_Rxn + RT * StoichCoefProd1 * LC_prod1
  • RT * StoichCoefProd2 * LC_prod2

  • RT * StoichCoefSub1 * LC_subs1

  • RT * StoichCoefSub2 * LC_subs2

= 0

prefix = G_
class pytfa.optim.ForwardDeltaGCoupling(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent thermodynamics coupling: DeltaG of reactions has to be DGR < 0 for the reaction to proceed forwards Looks like: FU_rxn: 1000 FU_rxn + DGR_rxn < 1000

prefix = FU_
class pytfa.optim.BackwardDeltaGCoupling(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent thermodynamics coupling: DeltaG of reactions has to be DGR > 0 for the reaction to proceed backwards Looks like: BU_rxn: 1000 BU_rxn - DGR_rxn < 1000

prefix = BU_
class pytfa.optim.ForwardDirectionCoupling(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent a forward directionality coupling with thermodynamics on reaction variables Looks like : UF_rxn: F_rxn - M FU_rxn < 0

prefix = UF_
class pytfa.optim.BackwardDirectionCoupling(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent a backward directionality coupling with thermodynamics on reaction variables Looks like : UR_rxn: R_rxn - M RU_rxn < 0

prefix = UR_
class pytfa.optim.SimultaneousUse(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent a simultaneous use constraint on reaction variables Looks like: SU_rxn: FU_rxn + BU_rxn <= 1

prefix = SU_
class pytfa.optim.DisplacementCoupling(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent the coupling to the thermodynamic displacement Looks like: Ln(Gamma) - (1/RT)*DGR_rxn = 0

prefix = DC_
class pytfa.optim.ForbiddenProfile(model, expr, id_, **kwargs)[source]

Bases: GenericConstraint

Class to represent a forbidden net flux directionality profile Looks like: FU_rxn_1 + BU_rxn_2 + … + FU_rxn_n <= n-1

prefix = FP_
class pytfa.optim.LinearizationConstraint(model, expr, id_, **kwargs)[source]

Bases: ModelConstraint

Class to represent a variable attached to a reaction

prefix = LC_
static from_constraints(cons, model)
pytfa.optim.camel2underscores(name)
pytfa.optim.ABCRequirePrefixMeta
pytfa.optim.op_replace_dict[source]
class pytfa.optim.GenericVariable(id_='', model=None, hook=None, queue=False, scaling_factor=1, **kwargs)[source]

Class to represent a generic variable. The purpose is that the interface is instantiated on initialization, to follow the type of interface used by the problem, and avoid incompatibilities in optlang

Attributes:

id

Used for DictList comprehension. Usually points back at a

enzyme or reaction id for ease of linking. Should be unique given a variable type. :name: Should be a concatenation of the id and a prefix that is specific to the variable type. will be used to address the variable at the solver level, and hence should be unique in the whole cobra_model :cobra_model: the cobra_model hook. :variable: links directly to the cobra_model representation of tbe variable

prefix
property __attrname__(self)

Name the attribute the instances will have Example: GenericVariable -> generic_variable :return:

get_interface(self, queue)

Called upon completion of __init__, initializes the value of self.var, which is returned upon call, and stores the actual interfaced variable.

Returns

instance of Variable from the problem

make_name(self)
Needs to be overridden by the subclass, concats the id with a

prefix

Returns

None

property name(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property variable(self)
property scaling_factor(self)
property unscaled(self)

If the scaling factor of quantity X is a, it is represented by the variable X_hat = X/a. This returns X = a.X_hat Useful for nondimensionalisation of variables and constraints

Returns

The variable divided by its scaling factor

property value(self)
property unscaled_value(self)
property model(self)
property type(self)
test_consistency(self, other)

Tests whether a candidate to an operation is of the right type and is from the same problem

Parameters

other – an object

Returns

None

get_operand(self, other)

For operations, choose if the operand is a GenericVariable, in which we return its optlang variable, or something else (presumably a numeric) and we let optlang decide what to do

Parameters

other

Returns

__add__(self, other)

Adding either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__radd__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

__sub__(self, other)

Substracting either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__rsub__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

__mul__(self, other)

Multiplying either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__rmul__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

__truediv__(self, other)

Dividing either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__rtruediv__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

make_result(self, new_variable)

Returns a Sympy expression :param new_variable: :return:

__repr__(self)

Return repr(self).

pytfa.optim.get_binary_type()[source]

FIX : We enforce type to be integer instead of binary, else optlang does not allow to set the binary variable bounds to anything other than (0,1) You might want to set it at (0,0) to enforce directionality for example

class pytfa.optim.ModelVariable(model, id_, **kwargs)[source]

Bases: GenericVariable

Class to represent a variable attached to the model

prefix = MODV_
class pytfa.optim.GeneVariable(gene, **kwargs)[source]

Bases: GenericVariable

Class to represent a gene variable

prefix = GV_
property gene(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property model(self)
class pytfa.optim.BinaryVariable(id_, model, **kwargs)[source]

Bases: GenericVariable

Class to represent a generic binary variable

prefix = B_
class pytfa.optim.ReactionVariable(reaction, **kwargs)[source]

Bases: GenericVariable

Class to represent a variable attached to a reaction

prefix = RV_
property reaction(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property model(self)
class pytfa.optim.MetaboliteVariable(metabolite, **kwargs)[source]

Bases: GenericVariable

Class to represent a variable attached to a enzyme

prefix = MV_
property metabolite(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property model(self)
class pytfa.optim.ForwardUseVariable(reaction, **kwargs)[source]

Bases: ReactionVariable, BinaryVariable

Class to represent a forward use variable, a type of binary variable used to enforce forward directionality in reaction net fluxes

prefix = FU_
class pytfa.optim.BackwardUseVariable(reaction, **kwargs)[source]

Bases: ReactionVariable, BinaryVariable

Class to represent a backward use variable, a type of binary variable used to enforce backward directionality in reaction net fluxes

prefix = BU_
class pytfa.optim.ForwardBackwardUseVariable(reaction, **kwargs)[source]

Bases: ReactionVariable, BinaryVariable

Class to represent a type of binary variable used to tell whether the reaction is active or not such that:

FU + BU + BFUSE = 1

prefix = BFUSE_
class pytfa.optim.LogConcentration(metabolite, **kwargs)[source]

Bases: MetaboliteVariable

Class to represent a log concentration of a enzyme

prefix = LC_
class pytfa.optim.DeltaGErr(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a DeltaGErr

prefix = DGE_
class pytfa.optim.DeltaG(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a DeltaG

prefix = DG_
class pytfa.optim.DeltaGstd(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a DeltaG^o (naught) - standard conditions

prefix = DGo_
class pytfa.optim.ThermoDisplacement(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent the thermodynamic displacement of a reaction Gamma = -DeltaG/RT

prefix = LnGamma_
class pytfa.optim.PosSlackVariable(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a positive slack variable for relaxation problems

prefix = PosSlack_
class pytfa.optim.NegSlackVariable(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a negative slack variable for relaxation problems

prefix = NegSlack_
class pytfa.optim.PosSlackLC(metabolite, **kwargs)[source]

Bases: MetaboliteVariable

Class to represent a variable attached to a enzyme

prefix = PosSlackLC_
class pytfa.optim.NegSlackLC(metabolite, **kwargs)[source]

Bases: MetaboliteVariable

Class to represent a variable attached to a enzyme

prefix = NegSlackLC_
class pytfa.optim.LinearizationVariable(model, id_, **kwargs)[source]

Bases: ModelVariable

Class to represent a product A*B when performing linearization of the model

prefix = LZ_
class pytfa.optim.NegativeDeltaG(reaction, expr, **kwargs)[source]

Bases: ReactionConstraint

Class to represent thermodynamics constraints.

G: - DGR_rxn + DGoRerr_Rxn + RT * StoichCoefProd1 * LC_prod1
  • RT * StoichCoefProd2 * LC_prod2

  • RT * StoichCoefSub1 * LC_subs1

  • RT * StoichCoefSub2 * LC_subs2

= 0

prefix = G_
pytfa.optim.dg_relax_config(model)
Parameters

model

Returns

pytfa.optim.get_solution_value_for_variables(solution, these_vars, index_by_reaction=False)
pytfa.optim.chunk_sum(variables)

This functions handles the sum of many sympy variables by chunks, which somehow increases the speed of the computation

You can test it in IPython: ```python a = sympy.symbols(‘a0:100’) %timeit (sum(a)) # >>> 198 µs ± 11.4 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

b = sympy.symbols(‘b0:1000’) %timeit (sum(b)) # >>> 1.85 ms ± 356 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

c = sympy.symbols(‘c0:3000’) %timeit (sum(c)) # >>> 5min 7s ± 2.57 s per loop (mean ± std. dev. of 7 runs, 1 loop each) ```

See the github thread

Parameters

variables

Returns

pytfa.optim.symbol_sum(variables)

``` python a = symbols(‘a0:100’)

%timeit Add(*a) # >>> 10000 loops, best of 3: 34.1 µs per loop

b = symbols(‘b0:1000’)

%timeit Add(*b) # >>> 1000 loops, best of 3: 343 µs per loop

c = symbols(‘c0:3000’)

%timeit Add(*c) # >>> 1 loops, best of 3: 1.03 ms per loop ```

See the github thread :param variables: :return:

class pytfa.optim.PosSlackVariable(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a positive slack variable for relaxation problems

prefix = PosSlack_
class pytfa.optim.NegSlackVariable(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a negative slack variable for relaxation problems

prefix = NegSlack_
class pytfa.optim.DeltaGstd(reaction, **kwargs)[source]

Bases: ReactionVariable

Class to represent a DeltaG^o (naught) - standard conditions

prefix = DGo_
class pytfa.optim.LogConcentration(metabolite, **kwargs)[source]

Bases: MetaboliteVariable

Class to represent a log concentration of a enzyme

prefix = LC_
class pytfa.optim.NegSlackLC(metabolite, **kwargs)[source]

Bases: MetaboliteVariable

Class to represent a variable attached to a enzyme

prefix = NegSlackLC_
class pytfa.optim.PosSlackLC(metabolite, **kwargs)[source]

Bases: MetaboliteVariable

Class to represent a variable attached to a enzyme

prefix = PosSlackLC_
pytfa.optim.BIGM[source]
pytfa.optim.BIGM_THERMO[source]
pytfa.optim.BIGM_DG[source]
pytfa.optim.BIGM_P[source]
pytfa.optim.EPSILON[source]
pytfa.optim.relax_dgo_gurobi(model, relax_obj_type=0)[source]
pytfa.optim.relax_dgo(tmodel, reactions_to_ignore=(), solver=None, in_place=False)[source]
Parameters
  • t_tmodel (pytfa.thermo.ThermoModel:) –

  • reactions_to_ignore – Iterable of reactions that should not be relaxed

  • solver – solver to use (e.g. ‘optlang-glpk’, ‘optlang-cplex’, ‘optlang-gurobi’

Returns

a cobra_model with relaxed bounds on standard Gibbs free energy

pytfa.optim.relax_lc(tmodel, metabolites_to_ignore=(), solver=None)[source]
Parameters
  • metabolites_to_ignore

  • in_tmodel (pytfa.thermo.ThermoModel:) –

  • min_objective_value

Returns

class pytfa.optim.GenericConstraint(expr, id_='', model=None, hook=None, queue=False, **kwargs)[source]
Class to represent a generic constraint. The purpose is that the interface

is instantiated on initialization, to follow the type of interface used by the problem, and avoid incompatibilities in optlang

Attributes:

id

Used for DictList comprehension. Usually points back at a

enzyme or reaction id for ease of linking. Should be unique given a constraint type. :name: Should be a concatenation of the id and a prefix that is specific to the variable type. will be used to address the constraint at the solver level, and hence should be unique in the whole cobra_model :expr: the expression of the constraint (sympy.Expression subtype) :cobra_model: the cobra_model hook. :constraint: links directly to the cobra_model representation of tbe constraint

prefix
property __attrname__(self)

Name the attribute the instances will have Example: GenericConstraint -> generic_constraint :return:

get_interface(self, expr, queue)

Called upon completion of __init__, initializes the value of self.var, which is returned upon call, and stores the actual interfaced variable.

Returns

instance of Variable from the problem

make_name(self)
Needs to be overridden by the subclass, concats the id with a

prefix

Returns

None

change_expr(self, new_expr, sloppy=False)
property expr(self)
property name(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property constraint(self)
property model(self)
__repr__(self)

Return repr(self).

class pytfa.optim.ForwardUseVariable(reaction, **kwargs)[source]

Bases: ReactionVariable, BinaryVariable

Class to represent a forward use variable, a type of binary variable used to enforce forward directionality in reaction net fluxes

prefix = FU_
class pytfa.optim.BackwardUseVariable(reaction, **kwargs)[source]

Bases: ReactionVariable, BinaryVariable

Class to represent a backward use variable, a type of binary variable used to enforce backward directionality in reaction net fluxes

prefix = BU_
class pytfa.optim.GenericVariable(id_='', model=None, hook=None, queue=False, scaling_factor=1, **kwargs)[source]

Class to represent a generic variable. The purpose is that the interface is instantiated on initialization, to follow the type of interface used by the problem, and avoid incompatibilities in optlang

Attributes:

id

Used for DictList comprehension. Usually points back at a

enzyme or reaction id for ease of linking. Should be unique given a variable type. :name: Should be a concatenation of the id and a prefix that is specific to the variable type. will be used to address the variable at the solver level, and hence should be unique in the whole cobra_model :cobra_model: the cobra_model hook. :variable: links directly to the cobra_model representation of tbe variable

prefix
property __attrname__(self)

Name the attribute the instances will have Example: GenericVariable -> generic_variable :return:

get_interface(self, queue)

Called upon completion of __init__, initializes the value of self.var, which is returned upon call, and stores the actual interfaced variable.

Returns

instance of Variable from the problem

make_name(self)
Needs to be overridden by the subclass, concats the id with a

prefix

Returns

None

property name(self)
property id(self)

for cobra.thermo.DictList compatibility :return:

property variable(self)
property scaling_factor(self)
property unscaled(self)

If the scaling factor of quantity X is a, it is represented by the variable X_hat = X/a. This returns X = a.X_hat Useful for nondimensionalisation of variables and constraints

Returns

The variable divided by its scaling factor

property value(self)
property unscaled_value(self)
property model(self)
property type(self)
test_consistency(self, other)

Tests whether a candidate to an operation is of the right type and is from the same problem

Parameters

other – an object

Returns

None

get_operand(self, other)

For operations, choose if the operand is a GenericVariable, in which we return its optlang variable, or something else (presumably a numeric) and we let optlang decide what to do

Parameters

other

Returns

__add__(self, other)

Adding either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__radd__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

__sub__(self, other)

Substracting either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__rsub__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

__mul__(self, other)

Multiplying either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__rmul__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

__truediv__(self, other)

Dividing either two variables together or a variable and a numeric results in a new variable :param other: :return: a new Generic Variable

__rtruediv__(self, other)

Take priority on symmetric arithmetic operation :param other: :return:

make_result(self, new_variable)

Returns a Sympy expression :param new_variable: :return:

__repr__(self)

Return repr(self).

pytfa.optim.SYMPY_ADD_CHUNKSIZE = 100[source]
pytfa.optim.INTEGER_VARIABLE_TYPES = ['binary', 'integer'][source]
pytfa.optim.get_all_subclasses(cls)[source]

Given a variable or constraint class, get all the subclassses that inherit from it

Parameters

cls

Returns

pytfa.optim.chunk_sum(variables)

This functions handles the sum of many sympy variables by chunks, which somehow increases the speed of the computation

You can test it in IPython: ```python a = sympy.symbols(‘a0:100’) %timeit (sum(a)) # >>> 198 µs ± 11.4 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

b = sympy.symbols(‘b0:1000’) %timeit (sum(b)) # >>> 1.85 ms ± 356 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

c = sympy.symbols(‘c0:3000’) %timeit (sum(c)) # >>> 5min 7s ± 2.57 s per loop (mean ± std. dev. of 7 runs, 1 loop each) ```

See the github thread

Parameters

variables

Returns

pytfa.optim.symbol_sum(variables)

``` python a = symbols(‘a0:100’)

%timeit Add(*a) # >>> 10000 loops, best of 3: 34.1 µs per loop

b = symbols(‘b0:1000’)

%timeit Add(*b) # >>> 1000 loops, best of 3: 343 µs per loop

c = symbols(‘c0:3000’)

%timeit Add(*c) # >>> 1 loops, best of 3: 1.03 ms per loop ```

See the github thread :param variables: :return:

pytfa.optim.get_solution_value_for_variables(solution, these_vars, index_by_reaction=False)
pytfa.optim.compare_solutions(models)[source]

returns the solution dictionnary for each cobra_model :param (iterable (pytfa.thermo.ThermoModel)) models: :return:

pytfa.optim.evaluate_constraint_at_solution(constraint, solution)[source]
Parameters
  • expression

  • solution – pandas.DataFrame, with index as variable names

Returns

pytfa.optim.get_active_use_variables(tmodel, solution)[source]

Returns the active use variables in a solution. Use Variables are binary variables that control the directionality of the reaction

ex: FU_ACALDt BU_PFK

Parameters
  • tmodel (pytfa.core.ThermoModel) –

  • solution

Returns

pytfa.optim.get_direction_use_variables(tmodel, solution)[source]

Returns the active use variables in a solution. Use Variables are binary variables that control the directionality of the reaction The difference with get_active_use_variables is that variables with both UseVariables at 0 will return as going forwards. This is to ensure that the output size of the function is equal to the number of FDPs

ex: FU_ACALDt BU_PFK

Parameters
  • tmodel (pytfa.core.ThermoModel) –

  • solution

Returns

pytfa.optim.get_primal(tmodel, vartype, index_by_reactions=False)[source]

Returns the primal value of the cobra_model for variables of a given type :param tmodel: :param vartype: Class of variable. Ex: pytfa.optim.variables.ThermoDisplacement :param index_by_reactions: Set to true to get reaction names as index instead of

variables. Useful for Escher export

Returns

pytfa.optim.strip_from_integer_variables(tmodel)[source]

Removes all integer and binary variables of a cobra_model, to make it sample-able :param tmodel: :return:

pytfa.optim.copy_solver_configuration(source, target)[source]

Copies the solver configuration from a source model to a target model :param source: :param target: :return: