def main(): parser = optparse.OptionParser(description="Produces `.dot` output from `.chem` input.") parser.add_option("-i", "--infile", dest="infile", help="read from INFILE in .chem format (if ommited, use stdin)", metavar="INFILE") parser.add_option("-o", "--outfile", dest="outfile", help="write to OUTFILE in .dot format (if ommited, use stdout)", metavar="OUTFILE") parser.add_option("-n", "--names", dest="names", help="style of molecular species naming. One of 'full', 'id', 'blank'", metavar="NAMES", default=None) parser.add_option("-l", "--layout", dest="layout", help="layout to assign to the dot file") (options, args) = parser.parse_args() rn = None if options.infile is None: #read from standard in rn = ReactionNetwork.from_string(sys.stdin.read()) else: #read from provided filename rn = ReactionNetwork.from_filename(options.infile) dot = net_to_dot(rn, names=options.names) if options.layout is not None: dot["graph"]["layout"] = options.layout dotstr = str(dot) if options.outfile is None: #print to standard out sys.stdout.write(dotstr) else: #write to provided filename outfile = open(options.outfile, "w") outfile.write(dotstr) outfile.close()
def test_to_dot_str(self): """ Test for dot conversion by string representation Assumes that the dot representation itself is valid """ target = 'digraph G {\n\tnode [margin="0.02,0.02", fontsize=10.0, width=0.3, height=0.0];\n\tedge [len=0.25, dir="both"];\n\tgraph [K=0.25, overlap="false"];\n\tM0 [label="A"];\n\tM1 [label="B"];\n\tM2 [label="C"];\n\tR0 [style="filled", label=2.0, width="0.2", shape="box", fillcolor="black", fontcolor="white", height="0.2", margin="0.01,0.01"];\n\tM0 -> R0 [arrowhead="none", arrowtail="invempty"];\n\tM1 -> R0 [color="grey", arrowhead="none", arrowtail="none"];\n\tR0 -> M2 [arrowhead="normal", arrowtail="none"];\n}' str(net_to_dot(self.net))