Dateien nach "mod/butadien" hochladen

This commit is contained in:
2026-08-25 13:56:19 +02:00
parent 110c0c9ebe
commit baef275e24
+75 -16
View File
@@ -1,4 +1,4 @@
#config.ilp.solver="CPLEX"
config.ilp.solver="CPLEX"
#import mod
#from mod import *
import networkx as nx
@@ -6,6 +6,22 @@ import networkx as nx
# import Graph class from graph.py
from graph import GraphObj
#ethylen = Graph.fromGMLString(
"""graph [
node [ id 0 label "H" ]
node [ id 1 label "H" ]
node [ id 2 label "C" ]
node [ id 3 label "C" ]
node [ id 4 label "H" ]
node [ id 5 label "H" ]
edge [ source 0 target 2 label "-" ]
edge [ source 1 target 2 label "-" ]
edge [ source 2 target 3 label "=" ]
edge [ source 3 target 4 label "-" ]
edge [ source 3 target 5 label "-" ]
]"""
#, name="Ethylen")
butadien = Graph.fromGMLString(
"""graph [
node [ id 0 label "C" ]
@@ -30,6 +46,37 @@ butadien = Graph.fromGMLString(
]"""
, name="Butadien")
#benzene = Graph.fromSMILES('c1=cc=cc=c1')
#benzene = Graph.fromGMLString(
"""graph [
node [ id 0 label "C" ]
node [ id 1 label "H" ]
node [ id 2 label "C" ]
node [ id 3 label "H" ]
node [ id 4 label "C" ]
node [ id 5 label "H" ]
node [ id 6 label "C" ]
node [ id 7 label "H" ]
node [ id 8 label "C" ]
node [ id 9 label "H" ]
node [ id 10 label "C" ]
node [ id 11 label "H" ]
edge [ source 0 target 1 label "-" ]
edge [ source 0 target 2 label "=" ]
edge [ source 2 target 3 label "-" ]
edge [ source 2 target 4 label "-" ]
edge [ source 4 target 5 label "-" ]
edge [ source 4 target 6 label "=" ]
edge [ source 6 target 7 label "-" ]
edge [ source 6 target 8 label "-" ]
edge [ source 8 target 9 label "-" ]
edge [ source 8 target 10 label "=" ]
edge [ source 10 target 11 label "-" ]
edge [ source 10 target 0 label "-" ]
]"""
#, name="Benzene")
#pentadien = Graph.fromGMLString(
"""graph
@@ -113,10 +160,16 @@ dielsalder = Rule.fromGMLString(
def cyclesizes(g):
nxGraph = GraphObj(g).nx_graph
#Chein restrictions: (No steric reason)
paths = sorted(list(nx.all_simple_paths(nxGraph)))
if max(paths > 12):
return True
#Restriction to E/Z? Benzen can't be created or consumed by the reaction due to steric difficulties
#Chain restrictions: (No steric reason)
for nodestart in nxGraph.nodes:
for nodeend in nxGraph.nodes:
if nodeend != nodestart:
paths = sorted(list(nx.all_shortest_paths(nxGraph, nodestart, nodeend)))
for path in paths:
if len(path) > 10: #First node included in length
return True
#Cycle restrictions:
cycles = sorted(list(nx.chordless_cycles(nxGraph)))
@@ -137,7 +190,7 @@ def cyclesizes(g):
if cycle != cycleref and len(list(set(cycle) & set(cycleref))) >= 3:
return True
#Only cordless cycles of length 5,6 and 7 are acceptable
if min(cycle_lengths) >= 5 and max(cycle_lengths) <=7:
if min(cycle_lengths) >= 6 and max(cycle_lengths) <=6:
return False
return True
@@ -154,9 +207,6 @@ def doubledoublebond(g):
def restriction(dg):
#Only rings 5 to 7
#No neighbouring double bonds. Is this already in MOD? Can this even happen?
#No Carbon in 3 rings? Better 4?
for a in dg.right:
if a.vLabelCount("C") > 10:
return False
@@ -176,7 +226,8 @@ postSection("Loaded Rules")
for a in inputRules:
a.print()
ethylen = Graph.fromSMILES('C=C')
goal = Graph.fromSMILES('C1C=CC=CC=1')
dg = DG(graphDatabase=inputGraphs)
dg.build().execute(
addSubset(inputGraphs)
@@ -185,18 +236,26 @@ dg.build().execute(
](
repeat(revive(inputRules)) #Revive not necessary
)
)
print([str(a.graph.name) for a in dg.vertices])
print([str(a.graph.smiles) for a in dg.vertices])
dg.print()
postSection("Product Graphs")
for a in dg.vertices:
a.graph.print()
flow = Flow(dg)
flow.addSource(butadien)
#flow = Flow(dg)
#flow.addSource(butadien)
#flow.findSolutions()
#flow.solutions.list()
#flow.solutions.print(flowPrinter)
flow.addSink(ethylen)
flow.addSink(goal)
flow.addConstraint(inFlow[butadien] >= 2)
#flow.addConstraint(outFlow[ethylen] == 1)
flow.addConstraint(outFlow[goal] == 1)
flow.findSolutions(maxNumSolutions=3)
flow.solutions.list()
flow.solutions.print(flowPrinter)
sys.exit(0)