12.5. Integer Hyperflows and Pathways

12.5.1. A Specific Pathway

A Pathway is an integer hyper-flow: each reaction is assigned a non-negative interger, specifying the number of times the reaction is used. Virtual input and output reactions are added to each molecule.

Explore in the playground.

 1 include("0212_dgPredicate.py")
 2 # Use the derivation graph 'dg' already created:
 3 flow = Flow(dg)
 4 # Specify which molecules can be fed into the network:
 5 flow.addSource(formaldehyde)
 6 flow.addSource(glycolaldehyde)
 7 # Specify which molecules that can remain in the network:
 8 flow.addSink(glycolaldehyde)
 9 # Specify restrictions on the amount of input/output molecules:
10 flow.addConstraint(inFlow[formaldehyde] == 2)
11 flow.addConstraint(inFlow[glycolaldehyde] == 1)
12 flow.addConstraint(outFlow[glycolaldehyde] == 2)
13 # Specify the minimization criteria:
14 #  number of unique reactions used
15 flow.objectiveFunction = isEdgeUsed
16 # Find a solution:
17 flow.findSolutions()
18 # Show solution information in the terminal:
19 flow.solutions.list()
20 # Print solutions:
21 flow.solutions.print()

12.5.2. Extra Constraints

We can add many kinds of constraints. They do not need to be related to input/ouput.

Explore in the playground.

 1 include("0212_dgPredicate.py")
 2 # Use the derivation graph 'dg' already created:
 3 flow = Flow(dg)
 4 # Specify which molecules can be fed into the network:
 5 flow.addSource(formaldehyde)
 6 flow.addSource(glycolaldehyde)
 7 # Specify which molecules that can remain in the network:
 8 flow.addSink(glycolaldehyde)
 9 # Specify restrictions on the amount of input/output molecules:
10 flow.addConstraint(inFlow[formaldehyde] == 2)
11 flow.addConstraint(inFlow[glycolaldehyde] == 1)
12 flow.addConstraint(outFlow[glycolaldehyde] == 2)
13 # Disable too large molecules:
14 for v in dg.vertices:
15    if v.graph.vLabelCount("C") > 4:
16       flow.addConstraint(vertex[v] == 0)
17 # Disable "strange" misleading input/output flows:
18 flow.allowIOReversal = False
19 # Specify the minimization criteria:
20 #  number of unique reactions used
21 flow.objectiveFunction = isEdgeUsed
22 # Find a solution:
23 flow.findSolutions()
24 # Show solution information in the terminal:
25 flow.solutions.list()
26 # Print solutions:
27 flow.solutions.print()

12.5.3. Multiple Solutions

It is often interesting to look for alternate solutions, possibly with a sub-optimal objective value.

Explore in the playground.

 1 include("0212_dgPredicate.py")
 2 # Use the derivation graph 'dg' already created:
 3 flow = Flow(dg)
 4 # Specify which molecules can be fed into the network:
 5 flow.addSource(formaldehyde)
 6 flow.addSource(glycolaldehyde)
 7 # Specify which molecules that can remain in the network:
 8 flow.addSink(glycolaldehyde)
 9 # Specify restrictions on the amount of input/output molecules:
10 flow.addConstraint(inFlow[formaldehyde] == 2)
11 flow.addConstraint(inFlow[glycolaldehyde] == 1)
12 flow.addConstraint(outFlow[glycolaldehyde] == 2)
13 # Disable "strange" misleading input/output flows:
14 flow.allowIOReversal = False
15 # Specify the minimization criteria:
16 #  number of reactions
17 flow.objectiveFunction = edge
18 # Find solutions:
19 #  at most 10 solutions, any quality
20 flow.findSolutions(maxNumSolutions=10)
21 # Show solution information in the terminal:
22 flow.solutions.list()
23 # Print solutions:
24 flow.solutions.print()

12.5.4. Finding Autocatalytic Cycles

Some pathways have a specific higher-order structure, e.g., autocatalysis.

Explore in the playground.

 1 include("0212_dgPredicate.py")
 2 # Use the derivation graph 'dg' already created:
 3 flow = Flow(dg)
 4 # Specify which molecules can be fed into the network:
 5 flow.addSource(formaldehyde)
 6 flow.addSource(glycolaldehyde)
 7 # Specify which molecules that can remain in the network:
 8 flow.addSink(glycolaldehyde)
 9 # Enable constraints for autocatalysis:
10 flow.overallAutocatalysis.enable()
11 # Specify the minimization criteria:
12 #  number of unique reactions used
13 flow.objectiveFunction = isEdgeUsed
14 # Find a solution:
15 flow.findSolutions()
16 # Show solution information in the terminal:
17 flow.solutions.list()
18 # Print solutions:
19 flow.solutions.print()