Exemplo n.º 1
0
parser.add_argument("-o",
                    "--output",
                    help="output file name",
                    default='resp_charges.txt')

args = parser.parse_args()

if args.save_resp_to is None:
    save_resp_to = "resp_temp_dir-dont_remove/"
else:
    save_resp_to = args.save_resp_to + "/"

if os.path.exists(args.output):
    raise FileExistsError("Output file exists: " + args.output)
if os.path.exists(save_resp_to):
    raise FileExistsError("Output directory exists: " + save_resp_to)

molecule = run_resp(args.respin_location,
                    save_resp_to,
                    resp_type='two_stage',
                    esp_fn=args.esp_filename)

if args.save_resp_to is None:
    shutil.rmtree(save_resp_to)

print("\nThe molecule with RESP charges is:")
for atom in molecule:
    atom.print_with_charge('resp')

charges.dump_charges_to_qout(molecule, "resp", args.output)
Exemplo n.º 2
0
# 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(
    charge_type.upper()))
print("RRMS: {0:.5f}".format(equiv_charge_rrms))
Exemplo n.º 3
0
                                    respin2_fn="")
# Note: the molecule is taken from one of the respin files...
molecule = _read_respin(respin1)[-1]
# ... but this will throw an error if the molecule in log is not the same one
charges._get_charges(args.input_charge_type, args.input_charge_file,
                     input_type, molecule)

if args.dump_raw:
    charges.dump_charges_to_qout(molecule, args.input_charge_type, args.dump_raw)
    import sys
    sys.exit(0)

if args.esp_file is not None:
    try:
        averaged_molecule = run_resp(
            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)
Exemplo n.º 4
0
    charge_type, ext)

esp_cube = cube_helpers.Cube(path + molecule_name + '_esp.cub')
ed_cube = cube_helpers.Cube(path + molecule_name + '_den.cub')
molecule = esp_cube.molecule

isoval = 0.01
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]
Exemplo n.º 5
0
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(
      charge_type.upper()))
print("RRMS: {0:.5f}".format(equiv_charge_rrms))
for atom in g.molecule:
Exemplo n.º 6
0
    @staticmethod
    def get_meshgrid(xlim1, xlim2, sampling_num):
        charges1 = linspace(xlim1[0], xlim1[1], num=sampling_num)
        charges2 = linspace(xlim2[0], xlim2[1], num=sampling_num)
        return meshgrid(charges1, charges2)


# CALCULATIONS COMMON TO 1 AND 2D VARIATIONS
if True:
    os.mkdir(output_path)
    os.mkdir(resp_output_path)
    levels = [1, 5, 10, 20, 30, 50, 100]

    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)
    # Equivalence alternative charge as well (i.e. unrest RESP on its own grid)
    alt_esp_equiv_molecule = resp.run_resp(path,
                                           resp_output_path + 'alt_unrest',
                                           resp_type='unrest',
                                           esp_fn=alt_esp_fn,
                                           check_ivary=False)

    charges.update_with_charges(esp_charge_type, log_fn, g.molecule)
    # This should actually be called esp_charge_rms
    charge_rms, charge_rrms = rms_and_rep(g.field, g.molecule,
                                          esp_charge_type)[:2]
    resp_rms, resp_rrms = rms_and_rep(g.field, esp_equiv_molecule, 'resp')[:2]
    # Note that, crucially, the equivalenced alternative charges are evaluated
    # on the same grid as the original charges, i.e. `g.field`
Exemplo n.º 7
0
                    "if all charges are to be scaled.",
                    metavar="SAVE_RESP_TO")

parser.add_argument("-o", "--output",
                    help="output file name",
                    default='resp_charges.txt')

args = parser.parse_args()

if args.save_resp_to is None:
    save_resp_to = "resp_temp_dir-dont_remove/"
else:
    save_resp_to = args.save_resp_to + "/"

if os.path.exists(args.output):
    raise FileExistsError("Output file exists: " + args.output)
if os.path.exists(save_resp_to):
    raise FileExistsError("Output directory exists: " + save_resp_to)

molecule = run_resp(args.respin_location, save_resp_to, resp_type='two_stage',
                    esp_fn=args.esp_filename)

if args.save_resp_to is None:
    shutil.rmtree(save_resp_to)

print("\nThe molecule with RESP charges is:")
for atom in molecule:
    atom.print_with_charge('resp')

charges.dump_charges_to_qout(molecule, "resp", args.output)
Exemplo n.º 8
0
molecule = _read_respin(respin1)[-1]
# ... but this will throw an error if the molecule in log is not the same one
charges._get_charges(args.input_charge_type, args.input_charge_file,
                     input_type, molecule)

if args.dump_raw:
    charges.dump_charges_to_qout(molecule, args.input_charge_type,
                                 args.dump_raw)
    import sys
    sys.exit(0)

if args.esp_file is not None:
    try:
        averaged_molecule = run_resp(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)