Beispiel #1
0
    # Pickle filenames for part 2
    with open(path + "fit_points.p", 'wb') as f:
        pickle.dump([elem.filename for elem in calcs], f)

# PART 2 --- run when the Gaussian calculations have been completed
if False:
    with open(path + "fit_points.p", 'rb') as f:
        calcs = pickle.load(f)

    rms_list = []
    charges_dict = {}

    color_span = []
    error_color_span = []
    for calc in calcs:
        g = resp_helpers.G09_esp(path + calc + '.esp')
        charges.update_with_charges(charge_type, path + calc + '.log',
                                    g.molecule)
        with open(path + calc + "-charges.txt", "a") as fc:
            for atom in g.molecule:
                atom.print_with_charge(charge_type, fc)
                if atom.label in charges_dict:
                    charges_dict[atom.label].append(atom.charges[charge_type])
                else:
                    charges_dict[atom.label] = [atom.charges[charge_type]]

            min_rms, min_rrms, rep_esp_field = rms_and_rep(g.field, g.molecule,
                                                           charge_type)
            rms_list.append(min_rms)
            print("\n", min_rms, file=fc)
Beispiel #2
0
if args.output is not None and os.path.exists(args.output):
    raise FileExistsError("Output file exists: " + args.output)

if args.dimension == 2 and not args.slice_dist:
    raise ValueError("A 2D plot requires a slicing plane to be requested with "
                     "the '--slice_dist' option.")

filetype = args.points_file[-4:]
if filetype not in ['.cub', '.esp']:
    print("The fields must have the extension .cub or .esp")
    sys.exit(1)

if filetype == '.cub':
    g = cube_helpers.Cube(args.points_file)
elif filetype == '.esp':
    g = resp_helpers.G09_esp(args.points_file)

# TODO: The colour span is calculated based on all values, but if only a slice
# is plotted, the shown points may occupy only a narrow range.
if args.color_range:
    color_span = args.color_range
elif args.sym_color_range:
    color_limit = max(abs(np.nanmin(g.field.get_values())),
                      abs(np.nanmax(g.field.get_values())))
    color_span = [-color_limit, color_limit]
else:
    color_span = [min(g.field.get_values()), max(g.field.get_values())]

if args.slice_atoms:
    plane_eqn = graphs.plane_through_atoms(g.molecule, *args.slice_atoms)
else:
Beispiel #3
0
zero_net_charge = True
if "plus" in molecule_name or "minus" in molecule_name:
    zero_net_charge = False

print("\nThe molecule was found {0}to be neutral based on its name. You should"
      " check if this is correct.".format("" if zero_net_charge else "NOT "))

resp_output_path = output_path + 'resp_calcs/'
min_resp_output_path = output_path + 'min_resp_calcs/'
os.mkdir(resp_output_path)
os.mkdir(min_resp_output_path)

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:")
Beispiel #4
0
args = parser.parse_args()

filetype = args.template_file[-4:]
if filetype not in ['.cub', '.esp']:
    print("The template file must have the extension .cub or .esp")
    sys.exit(1)

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

if filetype == '.cub':
    template_cube = cube_helpers.Cube(args.template_file)
    molecule = template_cube.molecule
elif filetype == '.esp':
    esp_file = resp_helpers.G09_esp(args.template_file)
    molecule = esp_file.molecule

input_type = charges_parser.input_type(args.input_charge_type)
charges._get_charges(args.input_charge_type, args.input_charge_file,
                     input_type, molecule)

if filetype == '.cub':
    rep_field = calc_grid_field(molecule, template_cube.field.grid, 'rep_esp',
                                [args.input_charge_type])[0]

    rep_field.write_cube(args.output + '.cub', molecule,
                         args.input_charge_type)
elif filetype == '.esp':
    rep_field = calc_non_grid_field(molecule, esp_file.field.points, 'rep_esp',
                                    [args.input_charge_type])[0]
Beispiel #5
0
import resp_parser

import os
import shutil

help_description = """Evaluate the fit quality of the given charges on the
    provided mesh of fitting points."""

parser = argparse.ArgumentParser(
    parents=[charges_parser.parser],
    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    description=help_description)

parser.add_argument("esp_filename",
                    help=resp_parser.esp_file_help,
                    metavar="ESP_FILE_NAME")

args = parser.parse_args()

esp_file = resp_helpers.G09_esp(args.esp_filename)
molecule = esp_file.molecule

input_type = charges_parser.input_type(args.input_charge_type)
charges._get_charges(args.input_charge_type, args.input_charge_file,
                     input_type, molecule)

rms, rrms = rms_and_rep(esp_file.field, molecule, args.input_charge_type)[:2]
print(" RMS: {0:.5f}".format(rms))
print("RRMS: {0:.5f}".format(rrms))
print("RMSV: {0:.5f}".format(rms / rrms))
Beispiel #6
0
opt_output_path = output_path + 'opt/'

common_fn = path + molecule_name + "_" + esp_charge_type
log_fn = common_fn + ".log"
input_esp = common_fn + ".esp"
esp_fn = molecule_name + "_" + esp_charge_type + ".esp"
alt_esp_fn = molecule_name + "_" + alt_esp_charge_type + ".esp"
output_esp = common_fn + ".esp"

print("esp_fit.py script")
print("\nMolecule:             ", molecule_name)
print("Charge type:          ", esp_charge_type.upper())
print("Non-ESP charge type:  ", charge_type.upper())
print("Alt. ESP charge type: ", alt_esp_charge_type.upper(), '\n')

g = resp_helpers.G09_esp(input_esp)

# Write the .esp file in the correct format expected by the `resp` program
if False:
    g.field.write_to_file(output_esp, g.molecule)

# Division into Voronoi basins:
# parent_atom, dist = rep_esp.calc_non_grid_field(g.molecule, g.field.points,
#                                                 'dist')

import copy
from itertools import chain
molecule = copy.deepcopy(g.molecule)


def polygon_area(vertices):
Beispiel #7
0
if args.save_resp_to is None:
    save_resp_to = "compromise_temp_dir-dont_remove/"
else:
    save_resp_to = args.save_resp_to + "/"
    if args.scale_all:
        raise ValueError("The option '--save_resp_to' should only be specified"
                         " when the '--scale_all' option is not set.")

if os.path.exists(args.output):
    raise FileExistsError("Output file exists: " + args.output)
if not args.scale_all:
    min_resp_calc_dir = save_resp_to + "/min_resp_calcs/"
    os.mkdir(save_resp_to)
    os.mkdir(min_resp_calc_dir)

esp_file = resp_helpers.G09_esp(args.respin_location + '/' + args.esp_filename)
molecule = esp_file.molecule

# This will be used when plotting is available:
# if args.indicator > len(molecule):
#     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...")
Beispiel #8
0
if filetype == '.cub':
    field1 = Cube(args.field1)
    molecule = field1.molecule
    field1 = field1.field
    field2 = Cube(args.field2).field

    # Exclusion: run checks before the (possibly costly) difference is
    # calculated
    if args.exclude:
        ed_cube, isoval, excl_dist = args.exclude
        ed_cube = Cube(ed_cube)
        isoval = float(isoval)
        excl_dist = float(excl_dist)
elif filetype == '.esp':
    esp_file1 = resp_helpers.G09_esp(args.field1)
    esp_file2 = resp_helpers.G09_esp(args.field2)
    # TODO: Molecules not cross-checked. They should be because .esp files in
    # Antechamber format produced by repESP will have no identitity info. This
    # is fine for now for the difference (actual - reproduced), because actual
    # will be Gaussian .esp but not the other way round.
    molecule = esp_file1.molecule
    field1 = esp_file1.field
    field2 = esp_file2.field

diff = difference(field1, field2, relative=args.relative,
                  absolute=args.absolute)

if filetype == '.cub':
    if args.exclude:
        diff.check_nans = False