def main (): client, db = mongo.connect() parser = argparse.ArgumentParser(description='UTILITIES') parser.add_argument('molecule', help='the name of the molecule/molecues', nargs='?') parser.set_defaults(which='main') subparser = parser.add_subparsers(help='TEST SET COMMANDS') plotter = subparser.add_parser('plot', help='PLOTTING OPERATIONS') plotter.add_argument('-d', '--dataset', required=True, help='Dataset to plot') plotter.add_argument('-s', '--savefig', help='Location to save the figure') plotter.set_defaults(which='plotting') converter = subparser.add_parser('convert', help='CONVERSION OPERATIONS') converter.add_argument('-s', '--save', help='Name the com file') converter.set_defaults(which='convert') spectra = subparser.add_parser('spectra', help='SPECTRA GRAB') spectra.add_argument('-s', '--savefig', help='Location to save the figure') spectra.add_argument('-d', '--dataset', help='dataset to examine, otherwise all', default=None) spectra.set_defaults(which='spectra') args = parser.parse_args() mol = molecule.Molecule(os.getcwd()).pull_record(db, {'g_safename':args.molecule}) if args.which == 'plotting': if args.savefig: loc = args.savefig else: loc = None main_title = mol.g_safename + ' ' + args.dataset shift_sets = tensor_analysis.molecule_tensor_analysis(mol, args.dataset) exp, calc, names = tensor_analysis.extract_data(shift_sets) fig = plotting.Figure(dimensions=(12,5), cols=1, main_title=main_title) plotting.plot_tensor_scatter(calc, exp, fig, loc, legend=False) fig.show_figure() # plotting.plot_tensors(tensors, title=args.dataset, loc=loc) elif args.which == 'convert': params = molecule.input_gaussian_params() molecule.convert_to_com(mol, **params) mol.cleanup() if args.save: if not args.save.endswith('.com'): args.save += '.com' old = os.path.join(os.getcwd(), mol.g_safename, mol.g_safename+'.com') new = os.path.join(os.path.dirname(old), args.save) os.rename(old, new) elif args.which == 'spectra': shift_list = [] for x in mol.get_spectra(nuclei='13C'): if hasattr(x, 'dataset'): name = "(C) " + x.dataset else: name = "(E) " + str(x.assignment_method) shifts = sorted(x.shifts, key=lambda y: y[0]) shifts.insert(0, name) shift_list.append(shifts) print '\n' for sl in sublist(shift_list, 5): for line in zip(*sl): # print shifts print ''.join(['{:<30}'.format(x) for x in line]) print '\n' exp_spectra = mol.get_spectra(computed=False, nuclei='13C') if args.dataset: comp_spectra = mol.get_spectra(computed=True, dataset=args.dataset, assignment_method='Computed') else: comp_spectra = mol.get_spectra(computed=True, assignment_method='Computed') if comp_spectra: print '{:<30}{:<25}{:<20}{:<20}{:<20}'.format('Experimental', 'Computed', 'slope', 'intercept', 'R') for exp_spec in exp_spectra: for comp_spec in comp_spectra: stats = tensor_analysis.regres_stats(comp_spec, exp_spec) print '{:<30}{:<25}{:<20}{:<20}{:<20}'.format(exp_spec.assignment_method, comp_spec.dataset, round(stats[0],4), round(stats[1],4), round(stats[2],4)) if args.savefig: print 'Saving figure to {0}'.format(saveto) t = tensor_analysis.molecule_tensor_analysis(mol, comp_spec.dataset) plotting.plot_tensors(t, title=mol.g_safename, loc=saveto)