atom.print_with_charge('resp') print("\nChecking differences between raw and equivalenced charges ...") print(compare_charges(esp_charge_type, 'resp', g.molecule, esp_equiv_molecule)) start_charges = [atom.charges[charge_type + '_equiv'] for atom in g.molecule] num = 50 ratio_limits = (0, 1.5) print("\nEvaluating HEAVY ratios. This may take a while.") heavy_args = (g.field, path, resp_output_path, esp_fn, False) heavy_result, indicator_charge, ratio_values = resp.eval_ratios( 'heavy', ratio_limits, start_charges, num, indicator_label, heavy_args, first_verbose=True) if zero_net_charge: # Scaling all charges is only possible with neutral molecules as # otherwise in this case there's no free hydrogens to compensate as in # the 'heavy_only' version print("\nEvaluating REGULAR ratios. This may take a while.") regular_args = (g.molecule, g.field) # Note that indicator charge and ratio values are re-used from the heavy # version. This is fine for ratio_values. For indicator_charge it's fine as # long as the indicator charge is on a heavy atom. TODO result = resp.eval_ratios('regular', ratio_limits,
print("RRMS: {0:.5f}".format(resp_charge_rrms)) for atom in esp_equiv_molecule: atom.print_with_charge('resp') print("\nChecking differences between raw and equivalenced charges ...") print(compare_charges(esp_charge_type, 'resp', g.molecule, esp_equiv_molecule)) start_charges = [atom.charges[charge_type + '_equiv'] for atom in g.molecule] num = 50 ratio_limits = (0, 1.5) print("\nEvaluating HEAVY ratios. This may take a while.") heavy_args = (g.field, path, resp_output_path, esp_fn, False) heavy_result, indicator_charge, ratio_values = resp.eval_ratios( 'heavy', ratio_limits, start_charges, num, indicator_label, heavy_args, first_verbose=True) if zero_net_charge: # Scaling all charges is only possible with neutral molecules as # otherwise in this case there's no free hydrogens to compensate as in # the 'heavy_only' version print("\nEvaluating REGULAR ratios. This may take a while.") regular_args = (g.molecule, g.field) # Note that indicator charge and ratio values are re-used from the heavy # version. This is fine for ratio_values. For indicator_charge it's fine as # long as the indicator charge is on a heavy atom. TODO result = resp.eval_ratios('regular', ratio_limits, start_charges, num, indicator_label, regular_args, first_verbose=True)[0]
# For now a patch: args.indicator = 1 input_type = charges_parser.input_type(args.input_charge_type) charges._get_charges(args.input_charge_type, args.input_charge_file, input_type, molecule) start_charges = [atom.charges[args.input_charge_type] for atom in molecule] print("\nEvaluating ratios...") if args.scale_all: regular_args = (molecule, esp_file.field) result, indicator_charge, ratio_values = eval_ratios('regular', args.limits, start_charges, args.sampling, args.indicator, regular_args, first_verbose=True) else: func_args = (esp_file.field, args.respin_location, save_resp_to, args.esp_filename, False) try: result, indicator_charge, ratio_values = eval_ratios( 'heavy', args.limits, start_charges, args.sampling, args.indicator, func_args, first_verbose=True)
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 heavy_min_ratio, heavy_min_ratio_rrms, compr_charges = resp.minimize_ratio( 'heavy', ratio_values, heavy_result, heavy_args) shutil.rmtree(opt_output_path) # Presentation: 3D if False: fig = plt.figure() ax = fig.gca(projection='3d')
# raise ValueError("Indicator label {0} requested but the molecule has " # "only {1} atoms.".format(args.indicator, len(molecule))) # For now a patch: args.indicator = 1 input_type = charges_parser.input_type(args.input_charge_type) charges._get_charges(args.input_charge_type, args.input_charge_file, input_type, molecule) start_charges = [atom.charges[args.input_charge_type] for atom in molecule] print("\nEvaluating ratios...") if args.scale_all: regular_args = (molecule, esp_file.field) result, indicator_charge, ratio_values = eval_ratios( 'regular', args.limits, start_charges, args.sampling, args.indicator, regular_args, first_verbose=True) else: func_args = (esp_file.field, args.respin_location, save_resp_to, args.esp_filename, False) try: result, indicator_charge, ratio_values = eval_ratios( 'heavy', args.limits, start_charges, args.sampling, args.indicator, func_args, first_verbose=True) 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)