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] rep_field.write_to_file(args.output + '.esp', molecule)
else: filename = path + charge_types[charge_type] update_with_charges(charge_type, filename, molecule) print("\n{0} charges:".format(charge_type.upper())) for atom in molecule: atom.print_with_charge(charge_type) # The same but to file (would be better with my Tee class from featsel) with open(charge_dir + '/charges.txt', 'w') as f: for atom in esp_cube.molecule: atom.print_with_charge(charge_type, f=f) # This is costly but was designed to be easy for many charge types, so # should be moved outside of the loop rep = calc_grid_field(esp_cube.molecule, esp_cube.field.grid, 'rep_esp', [charge_type])[0] # Change details of calculating difference here (absolute, relative) diff = difference(esp_cube.field, rep) # Write cube diff.write_cube(charge_dir + '/diff.cub', molecule, charge_type) # and with elements within the ED isosurface excluded diff_filtered = copy.deepcopy(diff) diff_filtered.check_nans = False _dist, diff_filtered.values = filter_by_dist(exclusion_dist, dist, diff) diff_filtered.write_cube(charge_dir + '/diff_filtered-iso_' + str(isoval) + '.cub', molecule, charge_type) rep_filtered = copy.deepcopy(rep) rep_filtered.check_nans = False _dist, rep_filtered.values = filter_by_dist(exclusion_dist, dist, rep)
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' ] for charge_type in all_charges: print('\n', charge_type.upper()) for atom in molecule: atom.print_with_charge(charge_type) sys.stdout.flush() rep = calc_grid_field(molecule, esp_cube.field.grid, 'rep_esp', [charge_type])[0] # Change details of calculating difference here (absolute, relative) diff = difference(esp_cube.field, rep) # Write cube diff.write_cube(output_path + charge_type + '_diff.cub', molecule, charge_type) # and with elements within the ED isosurface excluded diff_filtered = copy.deepcopy(diff) diff_filtered.check_nans = False _dist, diff_filtered.values = filter_by_dist(exclusion_dist, dist, diff) diff_filtered.write_cube( output_path + charge_type + '_diff_filtered-iso_' + str(isoval) + '.cub', molecule, charge_type)
atom = cube.molecule[0] grid = cube.field.grid # Write the field as a new cube out_cube_path = "tests/temp_test.cub" while True: try: cube.field.write_cube(out_cube_path, cube.molecule, 'cube') break except FileExistsError: os.remove(out_cube_path) # This is getting complicated so these initialization lines should be a # separate test. That likely requires a custom test suite so that they're only # executed once and before the others. dist_field = calc_grid_field(cube.molecule, grid, 'dist') repESP_field = calc_grid_field(cube.molecule, grid, 'rep_esp', ['cube'])[0] # Values calculated with an independent ad-hoc script dist_result = [ 0.1, 0.3, 0.7, 0.316227766, 0.424264068, 0.761577310, 0.608276253, 0.670820393, 0.921954445, 0.223606797, 0.360555127, 0.728010988, 0.374165738, 0.469041575, 0.787400787, 0.640312423, 0.7, 0.943398113, 0.412310562, 0.5, 0.806225774, 0.509901951, 0.583095189, 0.860232526, 0.728010988, 0.781024967, 1.004987562 ] # Values above in Bohr, convert to Angstrom dist_result = [angstrom_per_bohr * elem for elem in dist_result] # Isovalue selected so that only two points fall above it ed_isoval = 7.01e-07 edt_field = cube.field.distance_transform(ed_isoval)
atom = cube.molecule[0] grid = cube.field.grid # Write the field as a new cube out_cube_path = "tests/temp_test.cub" while True: try: cube.field.write_cube(out_cube_path, cube.molecule, 'cube') break except FileExistsError: os.remove(out_cube_path) # This is getting complicated so these initialization lines should be a # separate test. That likely requires a custom test suite so that they're only # executed once and before the others. dist_field = calc_grid_field(cube.molecule, grid, 'dist') repESP_field = calc_grid_field(cube.molecule, grid, 'rep_esp', ['cube'])[0] # Values calculated with an independent ad-hoc script dist_result = [0.1, 0.3, 0.7, 0.316227766, 0.424264068, 0.761577310, 0.608276253, 0.670820393, 0.921954445, 0.223606797, 0.360555127, 0.728010988, 0.374165738, 0.469041575, 0.787400787, 0.640312423, 0.7, 0.943398113, 0.412310562, 0.5, 0.806225774, 0.509901951, 0.583095189, 0.860232526, 0.728010988, 0.781024967, 1.004987562] # Values above in Bohr, convert to Angstrom dist_result = [angstrom_per_bohr*elem for elem in dist_result] # Isovalue selected so that only two points fall above it ed_isoval = 7.01e-07 edt_field = cube.field.distance_transform(ed_isoval) # This was calculated with the aforementioned script as the smaller elements of # the distance matrices from those two points.