def main(): root = Tk() if (len(sys.argv) > 1): mol_filename = sys.argv[1] else: #print >> sys.stderr, "Syntax: %s <mol file> [<svg file>]" % sys.argv[0] mol_filename = askopenfilename(parent=root, title="Pick a MOL file to plot", filetypes=[("MOL files", "*.mol"), ("All Files", "*")]) if (mol_filename == ''): sys.exit(-1) if (len(sys.argv) > 2): svg_filename = sys.argv[2] else: svg_filename = None if (not os.path.isfile(mol_filename)): print >> sys.stderr, "File not found: " + mol_filename sys.exit(-2) #file = open(mol_filename) try: G = molfile2graph(mol_filename) except Exception, strerror: root.title("ERROR") Message(root, text=strerror, width=100).pack() Button(root, text="OK", command=root.destroy).pack() root.mainloop() sys.exit(-1)
def main(): root = Tk() if (len(sys.argv) > 1): mol_filename = sys.argv[1] else: #print >> sys.stderr, "Syntax: %s <mol file> [<svg file>]" % sys.argv[0] mol_filename = askopenfilename(parent=root, title="Pick a MOL file to plot", filetypes=[("MOL files", "*.mol"),("All Files", "*")]) if (mol_filename == ''): sys.exit(-1) if (len(sys.argv) > 2): svg_filename = sys.argv[2] else: svg_filename = None if (not os.path.isfile(mol_filename)): print >> sys.stderr, "File not found: " + mol_filename sys.exit(-2) #file = open(mol_filename) try: G = molfile2graph(mol_filename) except Exception, strerror: root.title("ERROR") Message(root, text=strerror, width=100).pack() Button(root, text="OK", command=root.destroy).pack() root.mainloop() sys.exit(-1)
def init(): global html_path html_path = "../results" global compound2smiles compound2smiles = util.parse_dat("../metacyc/compounds.dat", "UNIQUE-ID", "SMILES") global atom_types atom_types = ['C', 'N', 'O', 'P', 'S'] #global bond_types; bond_types = range(5) global bond_types bond_types = range(4) global motif_sizes motif_sizes = range(2, 7) global log_zero log_zero = -800.0 global compound2graph compound2graph = {} for compound in compound2smiles.keys(): try: compound2graph[compound] = chemconvert.molfile2graph("../mol/" + compound + ".mol") except Exception: pass return
def init(): global html_path; html_path = "../results" global compound2smiles; compound2smiles = util.parse_dat("../metacyc/compounds.dat", "UNIQUE-ID", "SMILES") global atom_types; atom_types = ['C', 'N', 'O', 'P', 'S'] #global bond_types; bond_types = range(5) global bond_types; bond_types = range(4) global motif_sizes; motif_sizes = range(2, 7) global log_zero; log_zero = -800.0 global compound2graph; compound2graph = {} for compound in compound2smiles.keys(): try: compound2graph[compound] = chemconvert.molfile2graph("../mol/" + compound + ".mol") except Exception: pass return
reaction_titles.append("*"*60 + " " + line[2:] + " " + "*"*60) reaction_compounds.append(None) elif (prev_line_bag == None): prev_line_bag = bag.Bag().from_string(line) else: curr_line_bag = bag.Bag().from_string(line) common_bag = curr_line_bag.intersection(prev_line_bag) side_bags = [prev_line_bag - common_bag, curr_line_bag - common_bag, common_bag] # left-side, right-side, common side_strings = ["", "", ""] side_graphs = (ChemGraph(), ChemGraph(), ChemGraph()) for side in range(3): side_strings[side] += str(side_bags[side]) for (compound, cnt) in sorted(side_bags[side].itercounts()): for i in range(cnt): side_graphs[side].add(molfile2graph(mol_path + "/" + compound + ".mol")) if (side_graphs[0].node_bag() != side_graphs[1].node_bag()): raise Exception("Unbalanced reaction at lines %d - %d\n%s = %s (common: %s)" %\ (line_number-1, line_number, side_strings[0], side_strings[1], side_strings[2])) reaction_titles.append("%s = %s (common: %s)" % tuple(side_strings)) reaction_compounds.append(side_graphs) prev_line_bag = curr_line_bag # now deduce the reactions from the ChemGraphs Gref = None # a full graph that is the reference for drawing the global reaction Gprev = None # a full graph that remembers the last right-hand graph (aligned with the reference graph) total_reaction_list = [] # a list of 3-tuples that indicate which bonds have changes and by how much