args.respin_location, save_resp_to, resp_type='unrest', check_ivary=True, esp_fn=args.esp_file) except Exception as e: shutil.rmtree(save_resp_to) raise e if args.save_resp_to is None: shutil.rmtree(save_resp_to) else: averaged_charges, ivary_list = equivalence( molecule, args.input_charge_type, args.respin_location, respin1_fn="", respin2_fn="") # Check equivalence information from respin: _check_ivary(True, molecule, ivary_list) # The new molecule and name 'resp' is for consistency with the # equivalencing code above averaged_molecule = copy.deepcopy(molecule) charges._update_molecule_with_charges(averaged_molecule, averaged_charges, "resp") message = charges.compare_charges(args.input_charge_type, "resp", molecule, averaged_molecule, thresh=args.thresh) thresh_message = " vary by more than the threshold of " + str(args.thresh) if message: print("\nThe following charges" + thresh_message) print(message) else: print("\nNo charges" + thresh_message) charges.dump_charges_to_qout(averaged_molecule, "resp", args.output)
dist = ed_cube.field.distance_transform(isoval) exclusion_dist = 0 check_ivary = True for charge_type in ['mk', 'chelpg']: esp_equiv_molecule = resp.run_resp(path, output_path + 'unrest_' + charge_type, resp_type='unrest', esp_fn=molecule_name + '_' + charge_type + '.esp', check_ivary=check_ivary) check_ivary = False charges = [atom.charges['resp'] for atom in esp_equiv_molecule] _update_molecule_with_charges(molecule, charges, charge_type + '_equiv') pickled_fn = path + "compromise_nbo_and_{0}/molecule.p".format(charge_type) with open(pickled_fn, "rb") as f: pickled_mol = pickle.load(f) charges = [atom.charges[charge_type] for atom in pickled_mol] _update_molecule_with_charges(molecule, charges, 'compr_' + charge_type) charges = [atom.charges['nbo_equiv'] for atom in pickled_mol] _update_molecule_with_charges(molecule, charges, 'nbo_equiv') all_charges = [ 'chelpg_equiv', 'mk_equiv', 'nbo_equiv', 'compr_chelpg', 'compr_mk' ]
log_fn = path + molecule_name + "_" + charge_type + ".log" esp_log_fn = path + molecule_name + "_" + esp_charge_type + ".log" g = resp_helpers.G09_esp(path + esp_fn) # Both the Gaussian ESP fitting methods and other charge assignment methods may # not yield equivalent charges. As equivalent charges make more sense for force # field development, they will be used. The ESP charges are equivalenced by # performing unrestrained RESP, which will be used as a reference for the fit # minimum. Charges from the other method will be equivalenced manually by my # averaging function `resp.equivalence`. They will be scaled to obtain # different ratio charges. All the charges are calculated and printed at the # start for reference. update_with_charges(esp_charge_type, esp_log_fn, g.molecule) update_with_charges(charge_type, log_fn, g.molecule) equiv_charges = resp.equivalence(g.molecule, charge_type, path)[0] _update_molecule_with_charges(g.molecule, equiv_charges, charge_type + '_equiv') print("\nRunning unrestrained RESP to fit ESP with equivalence:") esp_equiv_molecule = resp.run_resp(path, resp_output_path + 'unrest', resp_type='unrest', esp_fn=esp_fn) charge_rrms = rms_and_rep(g.field, g.molecule, charge_type)[1] equiv_charge_rrms = rms_and_rep(g.field, g.molecule, charge_type + '_equiv')[1] esp_charge_rrms = rms_and_rep(g.field, g.molecule, esp_charge_type)[1] resp_charge_rrms = rms_and_rep(g.field, esp_equiv_molecule, 'resp')[1] print("\nThe molecule with {0} charges:".format(charge_type.upper())) print("RRMS: {0:.5f}".format(charge_rrms)) for atom in g.molecule: atom.print_with_charge(charge_type)
log_fn = path + molecule_name + "_" + charge_type + ".log" esp_log_fn = path + molecule_name + "_" + esp_charge_type + ".log" g = resp_helpers.G09_esp(path + esp_fn) # Both the Gaussian ESP fitting methods and other charge assignment methods may # not yield equivalent charges. As equivalent charges make more sense for force # field development, they will be used. The ESP charges are equivalenced by # performing unrestrained RESP, which will be used as a reference for the fit # minimum. Charges from the other method will be equivalenced manually by my # averaging function `resp.equivalence`. They will be scaled to obtain # different ratio charges. All the charges are calculated and printed at the # start for reference. update_with_charges(esp_charge_type, esp_log_fn, g.molecule) update_with_charges(charge_type, log_fn, g.molecule) equiv_charges = resp.equivalence(g.molecule, charge_type, path)[0] _update_molecule_with_charges(g.molecule, equiv_charges, charge_type+'_equiv') print("\nRunning unrestrained RESP to fit ESP with equivalence:") esp_equiv_molecule = resp.run_resp( path, resp_output_path + 'unrest', resp_type='unrest', esp_fn=esp_fn) charge_rrms = rms_and_rep(g.field, g.molecule, charge_type)[1] equiv_charge_rrms = rms_and_rep(g.field, g.molecule, charge_type + '_equiv')[1] esp_charge_rrms = rms_and_rep(g.field, g.molecule, esp_charge_type)[1] resp_charge_rrms = rms_and_rep(g.field, esp_equiv_molecule, 'resp')[1] print("\nThe molecule with {0} charges:".format(charge_type.upper())) print("RRMS: {0:.5f}".format(charge_rrms)) for atom in g.molecule: atom.print_with_charge(charge_type) print("\nThe molecule with equivalenced {0} charges:".format(
if True: with open(output_path + "result.p", "rb") as f: read_result = pickle.load(f) rel_rrms = [ 100 * (elem - read_result.resp_rrms) / read_result.resp_rrms for elem in read_result.rrms ] rel_rrms = np.array(rel_rrms) rel_rrms.resize([read_result.sampling_num, read_result.sampling_num]) # Non-ESP charge and its minimized ratio charges.update_with_charges(charge_type, charge_log_fn, molecule) equiv_start_charges = resp.equivalence(molecule, charge_type, path)[0] charge_type += '_equiv' charges._update_molecule_with_charges(molecule, equiv_start_charges, charge_type) os.mkdir(opt_output_path) # Scan roughly various ratios to find bracket for minimization print("\nScanning roughly various ratios. This shouldn't take long.") heavy_args = (g.field, path, opt_output_path, esp_fn, False) heavy_result, indicator_charge, ratio_values = resp.eval_ratios( 'heavy', (0, 2), equiv_start_charges, 10, vary_label1, heavy_args, first_verbose=True) # Minimization print("\nStarting minimization of charge ratio.") heavy_args = (equiv_start_charges, g.field, path, opt_output_path, esp_fn, True) # True for optimization
except Exception as e: shutil.rmtree(save_resp_to) raise e print("\nOptimizing fit quality...") if args.scale_all: regular_args = (start_charges, molecule, esp_file.field) reg_min_ratio, reg_min_ratio_rrms, compr_charges = minimize_ratio( 'regular', ratio_values, result, regular_args) else: func_args = (start_charges, esp_file.field, args.respin_location, min_resp_calc_dir, args.esp_filename, True) try: min_ratio, min_ratio_rrms, compr_charges = minimize_ratio( 'heavy', ratio_values, result, func_args) except Exception as e: shutil.rmtree(save_resp_to) raise e shutil.rmtree(min_resp_calc_dir) if not args.scale_all and args.save_resp_to is None: shutil.rmtree(save_resp_to) # TODO: plotting requires information about other charges. This would make this # script much bigger or require input from other scripts. charges._update_molecule_with_charges(molecule, compr_charges, "compr") for atom in molecule: atom.print_with_charge("compr") charges.dump_charges_to_qout(molecule, "compr", args.output)
shutil.rmtree(save_resp_to) raise e if args.save_resp_to is None: shutil.rmtree(save_resp_to) else: averaged_charges, ivary_list = equivalence(molecule, args.input_charge_type, args.respin_location, respin1_fn="", respin2_fn="") # Check equivalence information from respin: _check_ivary(True, molecule, ivary_list) # The new molecule and name 'resp' is for consistency with the # equivalencing code above averaged_molecule = copy.deepcopy(molecule) charges._update_molecule_with_charges(averaged_molecule, averaged_charges, "resp") message = charges.compare_charges(args.input_charge_type, "resp", molecule, averaged_molecule, thresh=args.thresh) thresh_message = " vary by more than the threshold of " + str(args.thresh) if message: print("\nThe following charges" + thresh_message) print(message) else: print("\nNo charges" + thresh_message) charges.dump_charges_to_qout(averaged_molecule, "resp", args.output)