def gui_smiles_text_callback(smiles): """ Take form input and attempt a SMILES dictionary lookup. Otherwise considered actual SMILES input. """ informalName = None ex = get_example(smiles) if ex: informalName = ex[1] smiles = ex[2] print ">>> Using %s per input.\n" % informalName parse_smiles_text(smiles, informalName)
def main(): parser = argparse.ArgumentParser() parser.add_argument('model', help='name of the model to attack') parser.add_argument('--image', type=int, default=0) parser.add_argument('--accuracy', action='store_true', help='first determines the accuracy of the model') parser.add_argument('--save', type=str, default=None, help='filename to save result to') # hyperparameters parser.add_argument('--regions', type=int, default=400) parser.add_argument('--iterations', type=int, default=500) parser.add_argument('--gamma', type=int, default=6, help='hyperparam of region selection') parser.add_argument('--misc-factor', type=float, default=75.) # advanced control over certain aspects (only if you know what you are doing) parser.add_argument('--nth-likely-class-starting-point', type=int, default=None) parser.add_argument('--no-line-search', action='store_true') parser.add_argument('--max-other-classes', type=int, default=None) parser.add_argument('--no-normalization', action='store_true') args = parser.parse_args() logging.getLogger().setLevel(logging.INFO) if args.save is not None: if os.path.exists(args.save): logging.warning( f'not runnning because results already exist: {args.save}') return result = run(*get_example(args.model), args=args) if args.save is not None: directory = os.path.dirname(args.save) if len(directory) > 0 and not os.path.exists(directory): os.makedirs(directory) with open(args.save, 'wb') as f: pickle.dump(result, f)
def main(): """Main function""" # Extract arguments or get random SMILES smiles = None informalName = None ex = get_example(None if len(sys.argv) < 2 else sys.argv[1]) if not ex: smiles = sys.argv[1] print "\n>>> Using input `%s` as SMILES.\n" % smiles else: informalName = ex[1] smiles = ex[2] print "\n>>> Using %s per argument.\n" % informalName # Init GUI. win = Window('Chemical Structure Diagram Generation (WIP)') # Set globals. Globals.drawable = win.drawable Globals.debugText = win.debugText Globals.window = win Globals.ringGroups = None Globals.molecule = None # Set callbacks. win.drawCallback = gui_draw_callback win.smilesCallback = gui_smiles_text_callback # Process initial data. parse_smiles_text(smiles, informalName) try: # Run GUI. win.run() except KeyboardInterrupt: print ""
def example_detail(example_id): return render_template('examples.html', examples=get_example(example_id), detail=True)
group = parser.add_mutually_exclusive_group() group.add_argument("file", help="module file to load puzzle from", type=str, nargs="?") group.add_argument("-c", "--choice", choices=("a", "b", "c", "d", "f", "m", "s", "t"), help="Choose one of the default example puzzles and do not load from module file", type=str, required=False) parser.add_argument("-d", "--detail", type=int, help="Detail of log output (higher means more intermediate steps are shown)", required=False) parser.add_argument("-v", "--verbose", action="store_true", help="Print very detailed log output (every step)") args = parser.parse_args() detail = 0 if args.detail: detail = args.detail if args.verbose: detail = -1 start_time = time.process_time() if args.file: print(f"Importing grid puzzle from {args.file}") x = importlib.import_module(args.file) solver.solve(x.g, detail) elif args.choice: g = examples.get_example(args) solver.solve(g, detail) else: raise RuntimeError("Must define input puzzle either via module file or example choice. Run -h to see details.") elapsed_time = time.process_time() - start_time print(f"Took {elapsed_time:.4f}s to execute.")