def load_rho(coordinates, numbers, fn_cube, ref_ugrid, stride, chop): '''Load densities from a file, reduce by stride, chop and check ugrid **Arguments:** coordinates An array with shape (N, 3) containing atomic coordinates. numbers A vector with shape (N,) containing atomic numbers. fn_cube The cube file with the electron density. ref_ugrid A reference ugrid that must match the one from the density cube file (after reduction). stride The reduction factor. chop The number of slices to chop of the grid in each direction. ''' if fn_cube is None: # Load the built-in database of proatoms natom = len(numbers) numbers = np.unique(numbers) proatomdb = ProAtomDB.from_refatoms(numbers, max_kation=0, max_anion=0, agspec='fine') # Construct the pro-density rho = np.zeros(ref_ugrid.shape) for i in xrange(natom): spline = proatomdb.get_spline(numbers[i]) ref_ugrid.eval_spline(spline, coordinates[i], rho) else: # Load cube mol_rho = IOData.from_file(fn_cube) rho = mol_rho.cube_data ugrid = mol_rho.grid # Reduce grid size if stride > 1: rho, ugrid = reduce_data(rho, ugrid, stride, chop) # Compare with ref_ugrid (only shape) if (ugrid.shape != ref_ugrid.shape).any(): raise ValueError( 'The densities file does not contain the same amount if information as the potential file.' ) return rho
def test_plot_atoms(): padb = ProAtomDB.from_refatoms(numbers=[8, 1], max_cation=1, max_anion=1) with tmpdir('horton.scripts.test.test_atomdb.test_plot_atoms') as dn: plot_atoms(padb, dn) fns = [ 'dens_001__h.png', 'rdens_001__h.png', 'fukui_001__h.png', 'rfukui_001__h.png', 'dens_008__o.png', 'rdens_008__o.png', 'fukui_008__o.png', 'rfukui_008__o.png', ] check_files(dn, fns)
def test_plot_atoms(): padb = ProAtomDB.from_refatoms(numbers=[8, 1], max_cation=1, max_anion=1) with tmpdir("horton.scripts.test.test_atomdb.test_plot_atoms") as dn: plot_atoms(padb, dn) fns = [ "dens_001__h.png", "rdens_001__h.png", "fukui_001__h.png", "rfukui_001__h.png", "dens_008__o.png", "rdens_008__o.png", "fukui_008__o.png", "rfukui_008__o.png", ] check_files(dn, fns)
def load_rho(system, fn_cube, ref_ugrid, stride, chop): '''Load densities from a file, reduce by stride, chop and check ugrid **Arguments:** system A Horton system object for the current system. This is only used to construct the pro-density. fn_cube The cube file with the electron density. ref_ugrid A reference ugrid that must match the one from the density cube file (after reduction). stride The reduction factor. chop The number of slices to chop of the grid in each direction. ''' if fn_cube is None: # Load the built-in database of proatoms numbers = np.unique(system.numbers) proatomdb = ProAtomDB.from_refatoms(numbers, max_kation=0, max_anion=0, agspec='fine') # Construct the pro-density rho = np.zeros(ref_ugrid.shape) for i in xrange(system.natom): spline = proatomdb.get_spline(system.numbers[i]) ref_ugrid.eval_spline(spline, system.coordinates[i], rho) else: # Load cube sys = System.from_file(fn_cube) rho = sys.extra['cube_data'] ugrid = sys.grid # Reduce grid size if stride > 1: rho, ugrid = reduce_data(rho, ugrid, stride, chop) # Compare with ref_ugrid (only shape) if (ugrid.shape != ref_ugrid.shape).any(): raise ValueError( 'The densities file does not contain the same amount if information as the potential file.' ) return rho
def load_rho(coordinates, numbers, fn_cube, ref_ugrid, stride, chop): '''Load densities from a file, reduce by stride, chop and check ugrid **Arguments:** coordinates An array with shape (N, 3) containing atomic coordinates. numbers A vector with shape (N,) containing atomic numbers. fn_cube The cube file with the electron density. ref_ugrid A reference ugrid that must match the one from the density cube file (after reduction). stride The reduction factor. chop The number of slices to chop of the grid in each direction. ''' if fn_cube is None: # Load the built-in database of proatoms natom = len(numbers) numbers = np.unique(numbers) proatomdb = ProAtomDB.from_refatoms(numbers, max_cation=0, max_anion=0, agspec='fine') # Construct the pro-density rho = np.zeros(ref_ugrid.shape) for i in xrange(natom): spline = proatomdb.get_spline(numbers[i]) ref_ugrid.eval_spline(spline, coordinates[i], rho) else: # Load cube mol_rho = IOData.from_file(fn_cube) rho = mol_rho.cube_data ugrid = mol_rho.grid # Reduce grid size if stride > 1: rho, ugrid = reduce_data(rho, ugrid, stride, chop) # Compare with ref_ugrid (only shape) if (ugrid.shape != ref_ugrid.shape).any(): raise ValueError('The densities file does not contain the same amount if information as the potential file.') return rho
def load_rho(system, fn_cube, ref_ugrid, stride, chop): '''Load densities from a file, reduce by stride, chop and check ugrid **Arguments:** system A Horton system object for the current system. This is only used to construct the pro-density. fn_cube The cube file with the electron density. ref_ugrid A reference ugrid that must match the one from the density cube file (after reduction). stride The reduction factor. chop The number of slices to chop of the grid in each direction. ''' if fn_cube is None: # Load the built-in database of proatoms numbers = np.unique(system.numbers) proatomdb = ProAtomDB.from_refatoms(numbers, max_kation=0, max_anion=0, agspec='fine') # Construct the pro-density rho = np.zeros(ref_ugrid.shape) for i in xrange(system.natom): spline = proatomdb.get_spline(system.numbers[i]) ref_ugrid.eval_spline(spline, system.coordinates[i], rho) else: # Load cube sys = System.from_file(fn_cube) rho = sys.extra['cube_data'] ugrid = sys.grid # Reduce grid size if stride > 1: rho, ugrid = reduce_data(rho, ugrid, stride, chop) # Compare with ref_ugrid (only shape) if (ugrid.shape != ref_ugrid.shape).any(): raise ValueError('The densities file does not contain the same amount if information as the potential file.') return rho