Ejemplo n.º 1
0
def main():
    parser = optparse.OptionParser(
        description="Pretty-printer and syntax checker for .chem files.")
    parser.add_option("-i",
                      "--infile",
                      dest="infile",
                      help="read from INFILE (if ommited, use stdin)",
                      metavar="INFILE")
    parser.add_option(
        "-o",
        "--outfile",
        dest="outfile",
        help="write to OUTFILE in .chem format (if ommited, use stdout)",
        metavar="OUTFILE")
    (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)

    chemstr = str(rn)

    if options.outfile is None:
        #print to standard out
        sys.stdout.write(chemstr)
    else:
        #write to provided filename
        outfile = open(options.outfile, "w")
        outfile.write(chemstr)
        outfile.close()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
def main():
    parser = optparse.OptionParser(description="Pretty-printer and syntax checker for .chem files.")
    parser.add_option(
        "-i", "--infile", dest="infile", help="read from INFILE (if ommited, use stdin)", metavar="INFILE"
    )
    parser.add_option(
        "-o",
        "--outfile",
        dest="outfile",
        help="write to OUTFILE in .chem format (if ommited, use stdout)",
        metavar="OUTFILE",
    )
    (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)

    chemstr = str(rn)

    if options.outfile is None:
        # print to standard out
        sys.stdout.write(chemstr)
    else:
        # write to provided filename
        outfile = open(options.outfile, "w")
        outfile.write(chemstr)
        outfile.close()