def _init_members_from_string(self, definition): if os.path.isfile(definition): self._load(definition) return filename = context.get_fn('grids/%s.txt' % definition) if os.path.isfile(filename): self._load(filename) return name = self._simple_names.get(definition) if name is not None: filename = context.get_fn('grids/%s.txt' % name) self._load(filename) return if definition.count(':') == 4: words = self.name.split(':') RTransformClass = self._simple_rtfs.get(words[0]) if RTransformClass is None: raise ValueError('Unknown radial grid type: %s' % words[0]) rmin = float(words[1]) * angstrom rmax = float(words[2]) * angstrom nrad = int(words[3]) rgrid = RadialGrid(RTransformClass(rmin, rmax, nrad)) nll = int(words[4]) self._init_members_from_tuple((rgrid, nll)) else: raise ValueError( 'Could not interpret atomic grid specification string: "%s"' % definition)
def _init_members_from_string(self, definition): if os.path.isfile(definition): self._load(definition) return filename = context.get_fn('grids/%s.txt' % definition) if os.path.isfile(filename): self._load(filename) return name = self._simple_names.get(definition) if name is not None: filename = context.get_fn('grids/%s.txt' % name) self._load(filename) return if definition.count(':') == 4: words = self.name.split(':') RTransformClass = self._simple_rtfs.get(words[0]) if RTransformClass is None: raise ValueError('Unknown radial grid type: %s' % words[0]) rmin = float(words[1])*angstrom rmax = float(words[2])*angstrom nrad = int(words[3]) rgrid = RadialGrid(RTransformClass(rmin, rmax, nrad)) nll = int(words[4]) self._init_members_from_tuple((rgrid, nll)) else: raise ValueError('Could not interpret atomic grid specification string: "%s"' % definition)
def load_periodic(): import csv convertor_types = { 'int': (lambda s: int(s)), 'float': (lambda s: float(s)), 'str': (lambda s: s.strip()), 'angstrom': (lambda s: float(s) * angstrom), '2angstrom': (lambda s: float(s) * angstrom / 2), } with open(context.get_fn('elements.csv'), 'r') as f: r = csv.reader(f) # go to the actual data for row in r: if len(row[1]) > 0: break # parse the first two header rows names = row convertors = [convertor_types[key] for key in r.next()] elements = [] for row in r: if len(row) == 0: break kwargs = {} for i in xrange(len(row)): cell = row[i] if len(cell) > 0: kwargs[names[i]] = convertors[i](cell) elements.append(Element(**kwargs)) return Periodic(elements)
def _load(self, filename): fn = context.get_fn(filename) members = [] with open(fn) as f: state = 0 for line in f: line = line[:line.find('#')].strip() if len(line) > 0: if state == 0: # read element number words = line.split() number = int(words[0]) if len(words) > 1: pseudo_number = int(words[1]) else: pseudo_number = number state = 1 elif state == 1: # read rtf string rtf = RTransform.from_string(line) state = 2 elif state == 2: nlls = np.array([int(w) for w in line.split()]) state = 0 members.append((number, pseudo_number, RadialGrid(rtf), nlls)) self._init_members_from_list(members)
def load_periodic(): import csv convertor_types = { 'int': (lambda s: int(s)), 'float': (lambda s : float(s)), 'str': (lambda s: s.strip()), 'angstrom': (lambda s: float(s)*angstrom), '2angstrom': (lambda s: float(s)*angstrom/2), } with open(context.get_fn('elements.csv'),'r') as f: r = csv.reader(f) # go to the actual data for row in r: if len(row[1]) > 0: break # parse the first two header rows names = row convertors = [convertor_types[key] for key in next(r)] elements = [] for row in r: if len(row) == 0: break kwargs = {} for i in xrange(len(row)): cell = row[i] if len(cell) > 0: kwargs[names[i]] = convertors[i](cell) elements.append(Element(**kwargs)) return Periodic(elements)
def check_hf_cs_hf(scf_solver): fn_fchk = context.get_fn('test/hf_sto3g.fchk') mol = IOData.from_file(fn_fchk) olp = mol.obasis.compute_overlap() kin = mol.obasis.compute_kinetic() na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers) er = mol.obasis.compute_electron_repulsion() external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RExchangeTerm(er, 'x_hf'), RTwoIndexTerm(na, 'ne'), ] ham = REffHam(terms, external) occ_model = AufbauOccModel(5) check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha) # test orbital energies expected_energies = np.array([ -2.59083334E+01, -1.44689996E+00, -5.57467136E-01, -4.62288194E-01, -4.62288194E-01, 5.39578910E-01, ]) assert abs(mol.orb_alpha.energies - expected_energies).max() < 1e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy'] - -9.856961609951867E+01) < 1e-8 assert abs(ham.cache['energy_kin'] - 9.766140786239E+01) < 2e-7 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] - 4.561984106482E+01) < 1e-6 assert abs(ham.cache['energy_ne'] - -2.465756615329E+02) < 1e-6 assert abs(ham.cache['energy_nn'] - 4.7247965053) < 1e-8
def copy_atom_output(fn, number, charge, mult, dn, fn_out): pop = number - charge symbol = periodic[number].symbol.lower().rjust(2, "_") destination = os.path.join(dn, "%03i_%s_%03i_q%+03i" % (number, symbol, pop, charge), "mult%02i" % mult) os.makedirs(destination) destination = os.path.join(destination, fn_out) shutil.copy(context.get_fn(os.path.join("test", fn)), destination)
def _load(self, filename): fn = context.get_fn(filename) members = [] with open(fn) as f: state = 0 for line in f: line = line[:line.find('#')].strip() if len(line) > 0: if state == 0: # read element number words = line.split() number = int(words[0]) if len(words) > 1: pseudo_number = int(words[1]) else: pseudo_number = number state = 1 elif state == 1: # read rtf string rtf = RTransform.from_string(line) state = 2 elif state == 2: nlls = np.array([int(w) for w in line.split()]) state = 0 members.append( (number, pseudo_number, RadialGrid(rtf), nlls)) self._init_members_from_list(members)
def check_hf_cs_hf(scf_solver): fn_fchk = context.get_fn('test/hf_sto3g.fchk') mol = IOData.from_file(fn_fchk) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RExchangeTerm(er, 'x_hf'), RTwoIndexTerm(na, 'ne'), ] ham = REffHam(terms, external) occ_model = AufbauOccModel(5) check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha) # test orbital energies expected_energies = np.array([ -2.59083334E+01, -1.44689996E+00, -5.57467136E-01, -4.62288194E-01, -4.62288194E-01, 5.39578910E-01, ]) assert abs(mol.exp_alpha.energies - expected_energies).max() < 1e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy'] - -9.856961609951867E+01) < 1e-8 assert abs(ham.cache['energy_kin'] - 9.766140786239E+01) < 2e-7 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] - 4.561984106482E+01) < 1e-6 assert abs(ham.cache['energy_ne'] - -2.465756615329E+02) < 1e-6 assert abs(ham.cache['energy_nn'] - 4.7247965053) < 1e-8
def check_methyl_os_tpss(scf_solver): """Try to converge the SCF for the methyl radical molecule with the TPSS functional. Parameters ---------- scf_solver : one of the SCFSolver types in HORTON A configured SCF solver that must be tested. """ fn_fchk = context.get_fn('test/methyl_tpss_321g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine', random_rotate=False) olp = mol.obasis.compute_overlap() kin = mol.obasis.compute_kinetic() na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers) er = mol.obasis.compute_electron_repulsion() external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UGridGroup(mol.obasis, grid, [ ULibXCMGGA('x_tpss'), ULibXCMGGA('c_tpss'), ]), UTwoIndexTerm(na, 'ne'), ] ham = UEffHam(terms, external) # compute the energy before converging dm_alpha = mol.orb_alpha.to_dm() dm_beta = mol.orb_beta.to_dm() ham.reset(dm_alpha, dm_beta) ham.compute_energy() assert abs(ham.cache['energy'] - -39.6216986265) < 1e-3 # The convergence should be reasonable, not perfect because of limited # precision in the molden file: assert convergence_error_eigen(ham, olp, mol.orb_alpha, mol.orb_beta) < 1e-3 # keep a copy of the orbital energies expected_alpha_energies = mol.orb_alpha.energies.copy() expected_beta_energies = mol.orb_beta.energies.copy() # Converge from scratch occ_model = AufbauOccModel(5, 4) check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha, mol.orb_beta) # test orbital energies assert abs(mol.orb_alpha.energies - expected_alpha_energies).max() < 2e-3 assert abs(mol.orb_beta.energies - expected_beta_energies).max() < 2e-3 ham.compute_energy() # compare with assert abs(ham.cache['energy_kin'] - 38.98408965928) < 1e-2 assert abs(ham.cache['energy_ne'] - -109.2368837076) < 1e-2 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_mgga_x_tpss'] + ham.cache['energy_libxc_mgga_c_tpss'] - 21.55131145126) < 1e-2 assert abs(ham.cache['energy'] - -39.6216986265) < 1e-3 assert abs(ham.cache['energy_nn'] - 9.0797839705) < 1e-5
def check_lih_os_hf(scf_solver): fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk') mol = IOData.from_file(fn_fchk) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UExchangeTerm(er, 'x_hf'), UTwoIndexTerm(na, 'ne'), ] ham = UEffHam(terms, external) occ_model = AufbauOccModel(2, 1) check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha, mol.exp_beta) expected_alpha_energies = np.array([ -2.76116635E+00, -7.24564188E-01, -1.79148636E-01, -1.28235698E-01, -1.28235698E-01, -7.59817520E-02, -1.13855167E-02, 6.52484445E-03, 6.52484445E-03, 7.52201895E-03, 9.70893294E-01, ]) expected_beta_energies = np.array([ -2.76031162E+00, -2.08814026E-01, -1.53071066E-01, -1.25264964E-01, -1.25264964E-01, -1.24605870E-02, 5.12761388E-03, 7.70499854E-03, 7.70499854E-03, 2.85176080E-02, 1.13197479E+00, ]) assert abs(mol.exp_alpha.energies - expected_alpha_energies).max() < 1e-5 assert abs(mol.exp_beta.energies - expected_beta_energies).max() < 1e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy'] - -7.687331212191962E+00) < 1e-8 assert abs(ham.cache['energy_kin'] - 7.640603924034E+00) < 2e-7 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] - 2.114420907894E+00) < 1e-7 assert abs(ham.cache['energy_ne'] - -1.811548789281E+01) < 2e-7 assert abs(ham.cache['energy_nn'] - 0.6731318487) < 1e-8
def copy_atom_output(fn, number, charge, mult, dn, fn_out): pop = number - charge symbol = periodic[number].symbol.lower().rjust(2, '_') destination = os.path.join( dn, '%03i_%s_%03i_q%+03i' % (number, symbol, pop, charge), 'mult%02i' % mult) os.makedirs(destination) destination = os.path.join(destination, fn_out) shutil.copy(context.get_fn(os.path.join('test', fn)), destination)
def check_h3_os_pbe(scf_solver): fn_fchk = context.get_fn("test/h3_pbe_321g.fchk") mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, "veryfine", random_rotate=False) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {"nn": compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ UTwoIndexTerm(kin, "kin"), UDirectTerm(er, "hartree"), UGridGroup(mol.obasis, grid, [ULibXCGGA("x_pbe"), ULibXCGGA("c_pbe")]), UTwoIndexTerm(na, "ne"), ] ham = UEffHam(terms, external) # compute the energy before converging dm_alpha = mol.exp_alpha.to_dm() dm_beta = mol.exp_beta.to_dm() ham.reset(dm_alpha, dm_beta) ham.compute_energy() assert abs(ham.cache["energy"] - -1.593208400939354e00) < 1e-5 # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file: assert convergence_error_eigen(ham, mol.lf, olp, mol.exp_alpha, mol.exp_beta) < 2e-6 # Converge from scratch occ_model = AufbauOccModel(2, 1) check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha, mol.exp_beta) # test orbital energies expected_energies = np.array( [-5.41141676e-01, -1.56826691e-01, 2.13089637e-01, 7.13565167e-01, 7.86810564e-01, 1.40663544e00] ) assert abs(mol.exp_alpha.energies - expected_energies).max() < 2e-5 expected_energies = np.array( [-4.96730336e-01, -5.81411249e-02, 2.73586652e-01, 7.41987185e-01, 8.76161160e-01, 1.47488421e00] ) assert abs(mol.exp_beta.energies - expected_energies).max() < 2e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache["energy_ne"] - -6.934705182067e00) < 1e-5 assert abs(ham.cache["energy_kin"] - 1.948808793424e00) < 1e-5 assert ( abs( ham.cache["energy_hartree"] + ham.cache["energy_libxc_gga_x_pbe"] + ham.cache["energy_libxc_gga_c_pbe"] - 1.502769385597e00 ) < 1e-5 ) assert abs(ham.cache["energy"] - -1.593208400939354e00) < 1e-5 assert abs(ham.cache["energy_nn"] - 1.8899186021) < 1e-8
def check_water_cs_m05(scf_solver): """Try to converge the SCF for the water molecule with the M05 functional. Parameters ---------- scf_solver : one of the SCFSolver types in HORTON A configured SCF solver that must be tested. """ fn_fchk = context.get_fn('test/water_m05_321g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine', random_rotate=False) olp = mol.obasis.compute_overlap() kin = mol.obasis.compute_kinetic() na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers) er = mol.obasis.compute_electron_repulsion() external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} libxc_term = RLibXCHybridMGGA('xc_m05') terms = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RGridGroup(mol.obasis, grid, [libxc_term]), RExchangeTerm(er, 'x_hf', libxc_term.get_exx_fraction()), RTwoIndexTerm(na, 'ne'), ] ham = REffHam(terms, external) # compute the energy before converging dm_alpha = mol.orb_alpha.to_dm() ham.reset(dm_alpha) ham.compute_energy() assert abs(ham.cache['energy'] - -75.9532086800) < 1e-3 # The convergence should be reasonable, not perfect because of limited # precision in the molden file: assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 1e-3 # keep a copy of the orbital energies expected_alpha_energies = mol.orb_alpha.energies.copy() # Converge from scratch occ_model = AufbauOccModel(5) check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha) # test orbital energies assert abs(mol.orb_alpha.energies - expected_alpha_energies).max() < 2e-3 ham.compute_energy() # compare with assert abs(ham.cache['energy_kin'] - 75.54463056278) < 1e-2 assert abs(ham.cache['energy_ne'] - -198.3003887880) < 1e-2 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] + ham.cache['energy_libxc_hyb_mgga_xc_m05'] - 3.764537450376E+01) < 1e-2 assert abs(ham.cache['energy'] - -75.9532086800) < 1e-3 assert abs(ham.cache['energy_nn'] - 9.1571750414) < 1e-5
def check_water_cs_hfs(scf_solver): fn_fchk = context.get_fn('test/water_hfs_321g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False) olp = mol.obasis.compute_overlap() kin = mol.obasis.compute_kinetic() na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers) er = mol.obasis.compute_electron_repulsion() external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RGridGroup(mol.obasis, grid, [ RDiracExchange(), ]), RTwoIndexTerm(na, 'ne'), ] ham = REffHam(terms, external) # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file and different integration grids: assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 3e-5 # Recompute the orbitals and orbital energies. This should be reasonably OK. dm_alpha = mol.orb_alpha.to_dm() ham.reset(dm_alpha) ham.compute_energy() fock_alpha = np.zeros(dm_alpha.shape) ham.compute_fock(fock_alpha) mol.orb_alpha.from_fock(fock_alpha, olp) expected_energies = np.array([ -1.83691041E+01, -8.29412411E-01, -4.04495188E-01, -1.91740814E-01, -1.32190590E-01, 1.16030419E-01, 2.08119657E-01, 9.69825207E-01, 9.99248500E-01, 1.41697384E+00, 1.47918828E+00, 1.61926596E+00, 2.71995350E+00 ]) assert abs(mol.orb_alpha.energies - expected_energies).max() < 2e-4 assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-7 assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-9 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4 assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4 assert abs(ham.cache['energy_nn'] - 9.1571750414) < 2e-8 # Converge from scratch and check energies occ_model = AufbauOccModel(5) check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha) ham.compute_energy() assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-4 assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-4 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4 assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
def check_lih_os_hf(scf_solver): fn_fchk = context.get_fn("test/li_h_3-21G_hf_g09.fchk") mol = IOData.from_file(fn_fchk) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {"nn": compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [UTwoIndexTerm(kin, "kin"), UDirectTerm(er, "hartree"), UExchangeTerm(er, "x_hf"), UTwoIndexTerm(na, "ne")] ham = UEffHam(terms, external) occ_model = AufbauOccModel(2, 1) check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha, mol.exp_beta) expected_alpha_energies = np.array( [ -2.76116635e00, -7.24564188e-01, -1.79148636e-01, -1.28235698e-01, -1.28235698e-01, -7.59817520e-02, -1.13855167e-02, 6.52484445e-03, 6.52484445e-03, 7.52201895e-03, 9.70893294e-01, ] ) expected_beta_energies = np.array( [ -2.76031162e00, -2.08814026e-01, -1.53071066e-01, -1.25264964e-01, -1.25264964e-01, -1.24605870e-02, 5.12761388e-03, 7.70499854e-03, 7.70499854e-03, 2.85176080e-02, 1.13197479e00, ] ) assert abs(mol.exp_alpha.energies - expected_alpha_energies).max() < 1e-5 assert abs(mol.exp_beta.energies - expected_beta_energies).max() < 1e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache["energy"] - -7.687331212191962e00) < 1e-8 assert abs(ham.cache["energy_kin"] - 7.640603924034e00) < 2e-7 assert abs(ham.cache["energy_hartree"] + ham.cache["energy_x_hf"] - 2.114420907894e00) < 1e-7 assert abs(ham.cache["energy_ne"] - -1.811548789281e01) < 2e-7 assert abs(ham.cache["energy_nn"] - 0.6731318487) < 1e-8
def check_water_cs_hfs(scf_solver): fn_fchk = context.get_fn('test/water_hfs_321g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RGridGroup(mol.obasis, grid, [ RDiracExchange(), ]), RTwoIndexTerm(na, 'ne'), ] ham = REffHam(terms, external) # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file and different integration grids: assert convergence_error_eigen(ham, mol.lf, olp, mol.exp_alpha) < 3e-5 # Recompute the orbitals and orbital energies. This should be reasonably OK. dm_alpha = mol.exp_alpha.to_dm() ham.reset(dm_alpha) ham.compute_energy() fock_alpha = mol.lf.create_two_index() ham.compute_fock(fock_alpha) mol.exp_alpha.from_fock(fock_alpha, olp) expected_energies = np.array([ -1.83691041E+01, -8.29412411E-01, -4.04495188E-01, -1.91740814E-01, -1.32190590E-01, 1.16030419E-01, 2.08119657E-01, 9.69825207E-01, 9.99248500E-01, 1.41697384E+00, 1.47918828E+00, 1.61926596E+00, 2.71995350E+00 ]) assert abs(mol.exp_alpha.energies - expected_energies).max() < 2e-4 assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-7 assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-9 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4 assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4 assert abs(ham.cache['energy_nn'] - 9.1571750414) < 2e-8 # Converge from scratch and check energies occ_model = AufbauOccModel(5) check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha) ham.compute_energy() assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-4 assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-4 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4 assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
def check_co_cs_pbe(scf_solver): fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine', random_rotate=False) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RGridGroup(mol.obasis, grid, [ RLibXCGGA('x_pbe'), RLibXCGGA('c_pbe'), ]), RTwoIndexTerm(na, 'ne'), ] ham = REffHam(terms, external) # Test energy before scf energy, focks = helper_compute(ham, mol.lf, mol.exp_alpha) assert abs(energy - -1.116465967841901E+02) < 1e-4 # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file: assert convergence_error_eigen(ham, mol.lf, olp, mol.exp_alpha) < 1e-5 # Converge from scratch occ_model = AufbauOccModel(7) check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha) # test orbital energies expected_energies = np.array([ -1.86831122E+01, -9.73586915E+00, -1.03946082E+00, -4.09331776E-01, -3.48686522E-01, -3.48686522E-01, -2.06049056E-01, 5.23730418E-02, 5.23730418E-02, 6.61093726E-01 ]) assert abs(mol.exp_alpha.energies - expected_energies).max() < 1e-2 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy_ne'] - -3.072370116827E+02) < 1e-2 assert abs(ham.cache['energy_kin'] - 1.103410779827E+02) < 1e-2 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_gga_x_pbe'] + ham.cache['energy_libxc_gga_c_pbe'] - 6.273115782683E+01) < 1e-2 assert abs(ham.cache['energy'] - -1.116465967841901E+02) < 1e-4 assert abs(ham.cache['energy_nn'] - 22.5181790889) < 1e-7
def check_h3_os_pbe(scf_solver): fn_fchk = context.get_fn('test/h3_pbe_321g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'veryfine', random_rotate=False) olp = mol.obasis.compute_overlap() kin = mol.obasis.compute_kinetic() na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers) er = mol.obasis.compute_electron_repulsion() external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UGridGroup(mol.obasis, grid, [ ULibXCGGA('x_pbe'), ULibXCGGA('c_pbe'), ]), UTwoIndexTerm(na, 'ne'), ] ham = UEffHam(terms, external) # compute the energy before converging dm_alpha = mol.orb_alpha.to_dm() dm_beta = mol.orb_beta.to_dm() ham.reset(dm_alpha, dm_beta) ham.compute_energy() assert abs(ham.cache['energy'] - -1.593208400939354E+00) < 1e-5 # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file: assert convergence_error_eigen(ham, olp, mol.orb_alpha, mol.orb_beta) < 2e-6 # Converge from scratch occ_model = AufbauOccModel(2, 1) check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha, mol.orb_beta) # test orbital energies expected_energies = np.array([ -5.41141676E-01, -1.56826691E-01, 2.13089637E-01, 7.13565167E-01, 7.86810564E-01, 1.40663544E+00 ]) assert abs(mol.orb_alpha.energies - expected_energies).max() < 2e-5 expected_energies = np.array([ -4.96730336E-01, -5.81411249E-02, 2.73586652E-01, 7.41987185E-01, 8.76161160E-01, 1.47488421E+00 ]) assert abs(mol.orb_beta.energies - expected_energies).max() < 2e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy_ne'] - -6.934705182067E+00) < 1e-5 assert abs(ham.cache['energy_kin'] - 1.948808793424E+00) < 1e-5 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_gga_x_pbe'] + ham.cache['energy_libxc_gga_c_pbe'] - 1.502769385597E+00) < 1e-5 assert abs(ham.cache['energy'] - -1.593208400939354E+00) < 1e-5 assert abs(ham.cache['energy_nn'] - 1.8899186021) < 1e-8
def cite(self, key, reason): """Cite a reference from `data/references.bib` for given reason. Parameters ---------- key : str The bibtex key in `data/references.bib`. reason: str The reason why this reference is cited, e.g. something in the form of `"for using method bluh"`. You may want to cite the same reference for different reasons from different parts of the code. At the end of the program, a list of "relevant" references will be printed that one should cite when using results obtained with a HORTON calculation. """ if self._biblio is None: filename = context.get_fn('references.bib') self._biblio = Biblio(filename) self._biblio.cite(key, reason)
def check_lih_os_hf(scf_solver): fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk') mol = IOData.from_file(fn_fchk) olp = mol.obasis.compute_overlap() kin = mol.obasis.compute_kinetic() na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers) er = mol.obasis.compute_electron_repulsion() external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} terms = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UExchangeTerm(er, 'x_hf'), UTwoIndexTerm(na, 'ne'), ] ham = UEffHam(terms, external) occ_model = AufbauOccModel(2, 1) check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha, mol.orb_beta) expected_alpha_energies = np.array([ -2.76116635E+00, -7.24564188E-01, -1.79148636E-01, -1.28235698E-01, -1.28235698E-01, -7.59817520E-02, -1.13855167E-02, 6.52484445E-03, 6.52484445E-03, 7.52201895E-03, 9.70893294E-01, ]) expected_beta_energies = np.array([ -2.76031162E+00, -2.08814026E-01, -1.53071066E-01, -1.25264964E-01, -1.25264964E-01, -1.24605870E-02, 5.12761388E-03, 7.70499854E-03, 7.70499854E-03, 2.85176080E-02, 1.13197479E+00, ]) assert abs(mol.orb_alpha.energies - expected_alpha_energies).max() < 1e-5 assert abs(mol.orb_beta.energies - expected_beta_energies).max() < 1e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy'] - -7.687331212191962E+00) < 1e-8 assert abs(ham.cache['energy_kin'] - 7.640603924034E+00) < 2e-7 assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] - 2.114420907894E+00) < 1e-7 assert abs(ham.cache['energy_ne'] - -1.811548789281E+01) < 2e-7 assert abs(ham.cache['energy_nn'] - 0.6731318487) < 1e-8
def _to_segmented(self): '''Convert all contractions from generalized to segmented''' new_basis_atom_map = {} for n, ba in self.basis_atom_map.iteritems(): new_bcs = [] for bc in ba.bcs: new_bcs.extend(bc.get_segmented_bcs()) new_ba = GOBasisAtom(new_bcs) new_basis_atom_map[n] = new_ba self.basis_atom_map = new_basis_atom_map go_basis_families_list = [ GOBasisFamily('STO-3G', filename=context.get_fn('basis/sto-3g.nwchem')), GOBasisFamily('STO-6G', filename=context.get_fn('basis/sto-6g.nwchem')), GOBasisFamily('3-21G', filename=context.get_fn('basis/3-21g.nwchem')), GOBasisFamily('3-21G*', filename=context.get_fn('basis/3-21g*.nwchem')), GOBasisFamily('3-21++G*', filename=context.get_fn('basis/3-21++g*.nwchem')), GOBasisFamily('4-31G', filename=context.get_fn('basis/4-31g.nwchem')), GOBasisFamily('6-31G', filename=context.get_fn('basis/6-31g.nwchem')), GOBasisFamily('6-31G*', filename=context.get_fn('basis/6-31g*.nwchem')), GOBasisFamily('6-31G**', filename=context.get_fn('basis/6-31g**.nwchem')), GOBasisFamily('6-31+G', filename=context.get_fn('basis/6-31+g.nwchem')), GOBasisFamily('6-31+G*', filename=context.get_fn('basis/6-31+g*.nwchem')), GOBasisFamily('6-31++G**', filename=context.get_fn('basis/6-31++g**.nwchem')), GOBasisFamily('6-311++G2d2p', filename=context.get_fn('basis/6-311++g2d2p.nwchem')), GOBasisFamily('cc-pVDZ', filename=context.get_fn('basis/cc-pvdz.nwchem')), GOBasisFamily('cc-pVTZ', filename=context.get_fn('basis/cc-pvtz.nwchem')), GOBasisFamily('cc-pVQZ', filename=context.get_fn('basis/cc-pvqz.nwchem')),
def __init__(self, atoms, coords, method='', basis='', route='', charge=0, spinmult=1, title='', filename='', template='default', nosave=False): '''initializes input object using default settings atoms array of chemical symbols for atoms in proper capitalization coords array of coordinates (array of dim 3) NOTE: Defaults were arbitrary and depended only on the template I used to create it ''' if filename!='': self.filename=filename else: self.filename='gaussian.com' self.basename=self.filename[:-4] #NOTE: assume specified filename has three character extension #Link0 self.chk=self.basename+'.chk' self.mem='1500MB' self.nosave=nosave #Route section if method!='': self.method=method else: self.method='uwb97xd' if basis!='': self.basis = basis else: self.basis = 'aug-cc-pvtz' self.basisinfo = None for ext in ['gbs','nwchem','davidh5']: if os.path.isfile(context.get_fn('basis/{0}.{1}'.format(self.basis,ext))): path = context.get_fn('basis/{0}.{1}'.format(self.basis,ext)) self.basis = 'gen' self.basisinfo = db.DataBasis(path, fileformat=os.path.splitext(path)[1][1:]) break # this needs to be better if template == 'default': route = 'scf=(tight,xqc,fermi) integral=grid=ultrafine nosymmetry ' + route elif template == 'opt': route = 'scf=(tight,xqc,fermi) integral=grid=ultrafine nosymmetry opt=tight ' + route elif template == 'stable': route = 'scf=(tight,xqc,fermi) integral=grid=ultrafine nosymmetry stable=opt ' + route elif template == 'freq': route = 'scf=(tight,xqc,fermi) integral=grid=ultrafine nosymmetry freq ' + route elif template == 'pop': route = 'scf=(tight,xqc,fermi) integral=grid=ultrafine nosymmetry density=current pop=(chelpg,npa) IOp(6/80=1) ' + route route = route.split() self.keywords = {} self.routerest = [] for i in route: if 'opt' == i.lower()[:3]: self.keywords['opt'] = i[4:] elif 'scf' == i.lower()[:3]: self.keywords['scf'] = i[4:] elif 'integral' == i.lower()[:8]: self.keywords['integral'] = i[9:] elif 'density' == i.lower()[:7]: self.keywords['density'] = i[8:] elif 'pop' == i.lower()[:3]: self.keywords['pop'] = i[4:] elif 'freq' == i.lower()[:4]: self.keywords['freq'] = i[5:] elif 'stable' == i.lower()[:6]: self.keywords['stable'] = i[7:] elif 'nosymmetry' == i.lower(): self.keywords['nosymmetry'] = '' else: self.routerest.append(i) #title section chemformula = ''.join(atoms) self.title=title+' '+chemformula+' '+self.method+'/'+self.basis #molecule specification (default: 0 1) self.charge=charge #difference in charge from neutral self.spinmultiplicity=spinmult #1 for singlet, 2 for doublet, ... #atoms self.atoms=atoms self.coords=coords
new_bcs = [] for bc in ba.bcs: new_bcs.extend(bc.get_segmented_bcs()) new_ba = GOBasisAtom(new_bcs) new_basis_atom_map[n] = new_ba self.basis_atom_map = new_basis_atom_map def _normalize_contractions(self): """Renormalize all contractions.""" for ba in self.basis_atom_map.itervalues(): for bc in ba.bcs: bc.normalize() go_basis_families_list = [ GOBasisFamily('STO-3G', filename=context.get_fn('basis/sto-3g.nwchem')), GOBasisFamily('STO-6G', filename=context.get_fn('basis/sto-6g.nwchem')), GOBasisFamily('3-21G', filename=context.get_fn('basis/3-21g.nwchem')), GOBasisFamily('3-21G(d)', filename=context.get_fn('basis/3-21g(d).nwchem')), GOBasisFamily('3-21++G(d)', filename=context.get_fn('basis/3-21++g(d).nwchem')), GOBasisFamily('4-31G', filename=context.get_fn('basis/4-31g.nwchem')), GOBasisFamily('6-31G', filename=context.get_fn('basis/6-31g.nwchem')), GOBasisFamily('6-31G(d)', filename=context.get_fn('basis/6-31g(d).nwchem')), GOBasisFamily('6-31G(d,p)', filename=context.get_fn('basis/6-31g(d,p).nwchem')), GOBasisFamily('6-31+G', filename=context.get_fn('basis/6-31+g.nwchem')), GOBasisFamily('6-31+G(d)', filename=context.get_fn('basis/6-31+g(d).nwchem')),
def check_h3_os_hfs(scf_solver): fn_fchk = context.get_fn('test/h3_hfs_321g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'veryfine', random_rotate=False) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} libxc_term = ULibXCLDA('x') terms1 = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UGridGroup(mol.obasis, grid, [libxc_term]), UTwoIndexTerm(na, 'ne'), ] ham1 = UEffHam(terms1, external) builtin_term = UDiracExchange() terms2 = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UGridGroup(mol.obasis, grid, [builtin_term]), UTwoIndexTerm(na, 'ne'), ] ham2 = UEffHam(terms2, external) # Compare the potential computed by libxc with the builtin implementation energy1, focks1 = helper_compute(ham1, mol.lf, mol.exp_alpha, mol.exp_beta) energy2, focks2 = helper_compute(ham2, mol.lf, mol.exp_alpha, mol.exp_beta) libxc_pot = ham1.cache.load('pot_libxc_lda_x_both')[:, 0] builtin_pot = ham2.cache.load('pot_x_dirac_alpha') # Libxc apparently approximates values of the potential below 1e-4 with zero. assert abs(libxc_pot - builtin_pot).max() < 1e-4 # Check of the libxc energy matches our implementation assert abs(energy1 - energy2) < 1e-10 ex1 = ham1.cache['energy_libxc_lda_x'] ex2 = ham2.cache['energy_x_dirac'] assert abs(ex1 - ex2) < 1e-10 # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file: assert convergence_error_eigen(ham1, mol.lf, olp, mol.exp_alpha, mol.exp_beta) < 1e-5 assert convergence_error_eigen(ham2, mol.lf, olp, mol.exp_alpha, mol.exp_beta) < 1e-5 occ_model = AufbauOccModel(2, 1) for ham in ham1, ham2: # Converge from scratch check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha, mol.exp_beta) # test orbital energies expected_energies = np.array([ -4.93959157E-01, -1.13961330E-01, 2.38730924E-01, 7.44216538E-01, 8.30143356E-01, 1.46613581E+00 ]) assert abs(mol.exp_alpha.energies - expected_energies).max() < 1e-5 expected_energies = np.array([ -4.34824166E-01, 1.84114514E-04, 3.24300545E-01, 7.87622756E-01, 9.42415831E-01, 1.55175481E+00 ]) assert abs(mol.exp_beta.energies - expected_energies).max() < 1e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy_ne'] - -6.832069993374E+00) < 1e-5 assert abs(ham.cache['energy_kin'] - 1.870784279014E+00) < 1e-5 assert abs(ham.cache['energy'] - -1.412556114057104E+00) < 1e-5 assert abs(ham.cache['energy_nn'] - 1.8899186021) < 1e-8 assert abs(ham1.cache['energy_hartree'] + ham1.cache['energy_libxc_lda_x'] - 1.658810998195E+00) < 1e-6 assert abs(ham2.cache['energy_hartree'] + ham2.cache['energy_x_dirac'] - 1.658810998195E+00) < 1e-6
def check_n2_cs_hfs(scf_solver): fn_fchk = context.get_fn('test/n2_hfs_sto3g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'veryfine', random_rotate=False) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} libxc_term = RLibXCLDA('x') terms1 = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RGridGroup(mol.obasis, grid, [libxc_term]), RTwoIndexTerm(na, 'ne'), ] ham1 = REffHam(terms1, external) builtin_term = RDiracExchange() terms2 = [ RTwoIndexTerm(kin, 'kin'), RDirectTerm(er, 'hartree'), RGridGroup(mol.obasis, grid, [builtin_term]), RTwoIndexTerm(na, 'ne'), ] ham2 = REffHam(terms2, external) # Compare the potential computed by libxc with the builtin implementation energy1, focks1 = helper_compute(ham1, mol.lf, mol.exp_alpha) energy2, focks2 = helper_compute(ham2, mol.lf, mol.exp_alpha) libxc_pot = ham1.cache.load('pot_libxc_lda_x_alpha') builtin_pot = ham2.cache.load('pot_x_dirac_alpha') # Libxc apparently approximates values of the potential below 1e-4 with zero. assert abs(libxc_pot - builtin_pot).max() < 1e-4 # Check of the libxc energy matches our implementation assert abs(energy1 - energy2) < 1e-10 ex1 = ham1.cache['energy_libxc_lda_x'] ex2 = ham2.cache['energy_x_dirac'] assert abs(ex1 - ex2) < 1e-10 # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file: assert convergence_error_eigen(ham1, mol.lf, olp, mol.exp_alpha) < 1e-5 assert convergence_error_eigen(ham2, mol.lf, olp, mol.exp_alpha) < 1e-5 occ_model = AufbauOccModel(7) for ham in ham1, ham2: # Converge from scratch check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha) # test orbital energies expected_energies = np.array([ -1.37107053E+01, -1.37098006E+01, -9.60673085E-01, -3.57928483E-01, -3.16017655E-01, -3.16017655E-01, -2.12998316E-01, 6.84030479E-02, 6.84030479E-02, 7.50192517E-01, ]) assert abs(mol.exp_alpha.energies - expected_energies).max() < 3e-5 ham.compute_energy() assert abs(ham.cache['energy_ne'] - -2.981579553570E+02) < 1e-5 assert abs(ham.cache['energy_kin'] - 1.061620887711E+02) < 1e-5 assert abs(ham.cache['energy'] - -106.205213597) < 1e-4 assert abs(ham.cache['energy_nn'] - 23.3180604505) < 1e-8 assert abs(ham1.cache['energy_hartree'] + ham1.cache['energy_libxc_lda_x'] - 6.247259253877E+01) < 1e-4 assert abs(ham2.cache['energy_hartree'] + ham2.cache['energy_x_dirac'] - 6.247259253877E+01) < 1e-4
new_bcs = [] for bc in ba.bcs: new_bcs.extend(bc.get_segmented_bcs()) new_ba = GOBasisAtom(new_bcs) new_basis_atom_map[n] = new_ba self.basis_atom_map = new_basis_atom_map def _normalize_contractions(self): """Renormalize all contractions.""" for ba in self.basis_atom_map.itervalues(): for bc in ba.bcs: bc.normalize() go_basis_families_list = [ GOBasisFamily('STO-3G', filename=context.get_fn('basis/sto-3g.nwchem')), GOBasisFamily('STO-6G', filename=context.get_fn('basis/sto-6g.nwchem')), GOBasisFamily('3-21G', filename=context.get_fn('basis/3-21g.nwchem')), GOBasisFamily('3-21G(d)', filename=context.get_fn('basis/3-21g(d).nwchem')), GOBasisFamily('3-21++G(d)', filename=context.get_fn('basis/3-21++g(d).nwchem')), GOBasisFamily('4-31G', filename=context.get_fn('basis/4-31g.nwchem')), GOBasisFamily('6-31G', filename=context.get_fn('basis/6-31g.nwchem')), GOBasisFamily('6-31G(d)', filename=context.get_fn('basis/6-31g(d).nwchem')), GOBasisFamily('6-31G(d,p)', filename=context.get_fn('basis/6-31g(d,p).nwchem')), GOBasisFamily('6-31+G', filename=context.get_fn('basis/6-31+g.nwchem')), GOBasisFamily('6-31+G(d)', filename=context.get_fn('basis/6-31+g(d).nwchem')), GOBasisFamily('6-31++G(d,p)', filename=context.get_fn('basis/6-31++g(d,p).nwchem')), GOBasisFamily('cc-pVDZ', filename=context.get_fn('basis/cc-pvdz.nwchem')), GOBasisFamily('cc-pVTZ', filename=context.get_fn('basis/cc-pvtz.nwchem')), GOBasisFamily('cc-pVQZ', filename=context.get_fn('basis/cc-pvqz.nwchem')), GOBasisFamily('cc-pCVDZ', filename=context.get_fn('basis/cc-pcvdz.nwchem')),
bc.to_arrays() def _to_segmented(self): '''Convert all contractions from generalized to segmented''' new_basis_atom_map = {} for n, ba in self.basis_atom_map.iteritems(): new_bcs = [] for bc in ba.bcs: new_bcs.extend(bc.get_segmented_bcs()) new_ba = GOBasisAtom(new_bcs) new_basis_atom_map[n] = new_ba self.basis_atom_map = new_basis_atom_map go_basis_families = [ GOBasisFamily('STO-3G', filename=context.get_fn('basis/sto-3g.nwchem')), GOBasisFamily('3-21G', filename=context.get_fn('basis/3-21g.nwchem')), GOBasisFamily('3-21++G*', filename=context.get_fn('basis/3-21++g*.nwchem')), GOBasisFamily('6-31++G**', filename=context.get_fn('basis/6-31++g**.nwchem')), GOBasisFamily('6-31G**', filename=context.get_fn('basis/6-31g**.nwchem')), GOBasisFamily('6-31+G*', filename=context.get_fn('basis/6-31+g*.nwchem')), GOBasisFamily('ANO', filename=context.get_fn('basis/ano-rcc.nwchem')), GOBasisFamily('aug-cc-pVDZ', filename=context.get_fn('basis/aug-cc-pvdz.nwchem')), GOBasisFamily('aug-cc-pVTZ', filename=context.get_fn('basis/aug-cc-pvtz.nwchem')), GOBasisFamily('aug-cc-pVQZ', filename=context.get_fn('basis/aug-cc-pvqz.nwchem')), GOBasisFamily('cc-pVDZ', filename=context.get_fn('basis/cc-pvdz.nwchem')),
def check_h3_os_hfs(scf_solver): fn_fchk = context.get_fn('test/h3_hfs_321g.fchk') mol = IOData.from_file(fn_fchk) grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'veryfine', random_rotate=False) olp = mol.obasis.compute_overlap(mol.lf) kin = mol.obasis.compute_kinetic(mol.lf) na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf) er = mol.obasis.compute_electron_repulsion(mol.lf) external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)} libxc_term = ULibXCLDA('x') terms1 = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UGridGroup(mol.obasis, grid, [libxc_term]), UTwoIndexTerm(na, 'ne'), ] ham1 = UEffHam(terms1, external) builtin_term = UDiracExchange() terms2 = [ UTwoIndexTerm(kin, 'kin'), UDirectTerm(er, 'hartree'), UGridGroup(mol.obasis, grid, [builtin_term]), UTwoIndexTerm(na, 'ne'), ] ham2 = UEffHam(terms2, external) # Compare the potential computed by libxc with the builtin implementation energy1, focks1 = helper_compute(ham1, mol.lf, mol.exp_alpha, mol.exp_beta) energy2, focks2 = helper_compute(ham2, mol.lf, mol.exp_alpha, mol.exp_beta) libxc_pot = ham1.cache.load('pot_libxc_lda_x_both')[:,0] builtin_pot = ham2.cache.load('pot_x_dirac_alpha') # Libxc apparently approximates values of the potential below 1e-4 with zero. assert abs(libxc_pot - builtin_pot).max() < 1e-4 # Check of the libxc energy matches our implementation assert abs(energy1 - energy2) < 1e-10 ex1 = ham1.cache['energy_libxc_lda_x'] ex2 = ham2.cache['energy_x_dirac'] assert abs(ex1 - ex2) < 1e-10 # The convergence should be reasonable, not perfect because of limited # precision in Gaussian fchk file: assert convergence_error_eigen(ham1, mol.lf, olp, mol.exp_alpha, mol.exp_beta) < 1e-5 assert convergence_error_eigen(ham2, mol.lf, olp, mol.exp_alpha, mol.exp_beta) < 1e-5 occ_model = AufbauOccModel(2, 1) for ham in ham1, ham2: # Converge from scratch check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha, mol.exp_beta) # test orbital energies expected_energies = np.array([ -4.93959157E-01, -1.13961330E-01, 2.38730924E-01, 7.44216538E-01, 8.30143356E-01, 1.46613581E+00 ]) assert abs(mol.exp_alpha.energies - expected_energies).max() < 1e-5 expected_energies = np.array([ -4.34824166E-01, 1.84114514E-04, 3.24300545E-01, 7.87622756E-01, 9.42415831E-01, 1.55175481E+00 ]) assert abs(mol.exp_beta.energies - expected_energies).max() < 1e-5 ham.compute_energy() # compare with g09 assert abs(ham.cache['energy_ne'] - -6.832069993374E+00) < 1e-5 assert abs(ham.cache['energy_kin'] - 1.870784279014E+00) < 1e-5 assert abs(ham.cache['energy'] - -1.412556114057104E+00) < 1e-5 assert abs(ham.cache['energy_nn'] - 1.8899186021) < 1e-8 assert abs(ham1.cache['energy_hartree'] + ham1.cache['energy_libxc_lda_x'] - 1.658810998195E+00) < 1e-6 assert abs(ham2.cache['energy_hartree'] + ham2.cache['energy_x_dirac'] - 1.658810998195E+00) < 1e-6
(2), Taewon D. Kim (2), Steven Vandenbrande (1), Derrick Yang (2), Cristina E. González-Espinoza (2), Stijn Fias (3), Peter A. Limacher (2), Diego Berrocal (2), Ali Malek (2) and Paul W. Ayers (2) (1) Center for Molecular Modeling (CMM), Ghent University, Ghent, Belgium. (2) The Ayers Group, McMaster University, Hamilton, Ontario, Canada. (3) General Chemistry (ALGC), Free University of Brussels, Brussels, Belgium. More information about HORTON can be found on this website: http://theochem.github.com/horton/ The purpose of this log file is to track the progress and quality of a computation. Useful numerical output may be written to a checkpoint file and is accessible through the Python scripting interface. ================================================================================""" % (horton.__version__) foot_banner = """ ================================================================================ _ _ / )--( \ End of the HORTON program. \| \ |/ |_||_| Thank you for using HORTON %s! See you soon! ================================================================================""" % (horton.__version__) timer = TimerGroup() biblio = Biblio(context.get_fn('references.bib')) log = ScreenLog('HORTON', horton.__version__, head_banner, foot_banner, timer, biblio) atexit.register(log.print_footer)
# # You should have received a copy of the GNU General Public License # along with this program; if not, see <http://www.gnu.org/licenses/> # # -- from cStringIO import StringIO from horton.log import Biblio from horton.context import context from common import write_if_changed biblio = Biblio(context.get_fn('references.bib')) def key(item): return int(item[1].tags['year']), item[0] f = StringIO() print >> f, 'Literature' print >> f, '##########' items = biblio._records.items() items.sort(key=key) for key, reference in items: print >> f print >> f, '.. [%s] %s' % (key, reference.format_rst()) s = f.getvalue() write_if_changed('tech_ref_literature.rst', s)
def cite(self, key, reason): if self._biblio is None: filename = context.get_fn("references.bib") self._biblio = Biblio(filename) self._biblio.cite(key, reason)
def _to_segmented(self): '''Convert all contractions from generalized to segmented''' new_basis_atom_map = {} for n, ba in self.basis_atom_map.iteritems(): new_bcs = [] for bc in ba.bcs: new_bcs.extend(bc.get_segmented_bcs()) new_ba = GOBasisAtom(new_bcs) new_basis_atom_map[n] = new_ba self.basis_atom_map = new_basis_atom_map go_basis_families = [ GOBasisFamily('STO-3G', filename=context.get_fn('basis/sto-3g.nwchem')), GOBasisFamily('3-21G', filename=context.get_fn('basis/3-21g.nwchem')), GOBasisFamily('3-21++G*', filename=context.get_fn('basis/3-21++g*.nwchem')), GOBasisFamily('6-31++G**', filename=context.get_fn('basis/6-31++g**.nwchem')), GOBasisFamily('6-31G**', filename=context.get_fn('basis/6-31g**.nwchem')), GOBasisFamily('6-31+G*', filename=context.get_fn('basis/6-31+g*.nwchem')), GOBasisFamily('ANO', filename=context.get_fn('basis/ano-rcc.nwchem')), GOBasisFamily('aug-cc-pVDZ', filename=context.get_fn('basis/aug-cc-pvdz.nwchem')), GOBasisFamily('aug-cc-pVTZ', filename=context.get_fn('basis/aug-cc-pvtz.nwchem')), GOBasisFamily('aug-cc-pVQZ', filename=context.get_fn('basis/aug-cc-pvqz.nwchem')), GOBasisFamily('cc-pVDZ', filename=context.get_fn('basis/cc-pvdz.nwchem')), GOBasisFamily('cc-pVTZ', filename=context.get_fn('basis/cc-pvtz.nwchem')), GOBasisFamily('cc-pVQZ', filename=context.get_fn('basis/cc-pvqz.nwchem')), ] go_basis_families = dict((bf.name.lower(), bf) for bf in go_basis_families)