def test_casci_grad(self): mf = scf.RHF(mol0).ddCOSMO().run() mc = solvent.ddCOSMO(mcscf.CASCI(mf, 2, 2)) e, de = mc.nuc_grad_method().as_scanner()(mol0) self.assertAlmostEqual(e, -1.1844606066401635, 7) self.assertAlmostEqual(lib.fp(de), -0.18558925270492277, 5) mf = scf.RHF(mol1).run() mc1 = solvent.ddCOSMO(mcscf.CASCI(mf, 2, 2)).run() e1 = mc1.e_tot mf = scf.RHF(mol2).run() mc2 = solvent.ddCOSMO(mcscf.CASCI(mf, 2, 2)).run() e2 = mc2.e_tot self.assertAlmostEqual((e2 - e1) / dx, de[0, 2], 3)
def test_ccsd_grad(self): mf = scf.RHF(mol0).ddCOSMO().run() mycc = cc.CCSD(mf).ddCOSMO() e, de = mycc.nuc_grad_method().as_scanner()(mol0) self.assertAlmostEqual(e, -1.206178782599439, 7) self.assertAlmostEqual(lib.fp(de), -0.17959270231901459, 5) mf = scf.RHF(mol1).run() mycc1 = solvent.ddCOSMO(cc.CCSD(mf)).run() e1 = mycc1.e_tot mf = scf.RHF(mol2).run() mycc2 = solvent.ddCOSMO(cc.CCSD(mf)).run() e2 = mycc2.e_tot self.assertAlmostEqual((e2 - e1) / dx, de[0, 2], 4)
def test_casscf_grad(self): mf = scf.RHF(mol0).ddCOSMO().run() mc = solvent.ddCOSMO(mcscf.CASSCF(mf, 2, 2)).set(conv_tol=1e-9) mc_g = mc.nuc_grad_method().as_scanner() e, de = mc_g(mol0) self.assertAlmostEqual(e, -1.1964048498155815, 7) self.assertAlmostEqual(lib.fp(de), -0.18331022006442843, 5) mf = scf.RHF(mol1).run() mc1 = solvent.ddCOSMO(mcscf.CASSCF(mf, 2, 2)).run() e1 = mc1.e_tot mf = scf.RHF(mol2).run() mc2 = solvent.ddCOSMO(mcscf.CASSCF(mf, 2, 2)).run() e2 = mc2.e_tot self.assertAlmostEqual((e2 - e1) / dx, de[0, 2], 3)
def pyscf_run_pcm_hf(xyz, basis, charge=0, multiplicity=1, conv_tol=1e-11, conv_tol_grad=1e-10, max_iter=150, pcm_options=None): from pyscf import scf, gto from pyscf.solvent import ddCOSMO mol = gto.M( atom=xyz, unit="Bohr", basis=basis, # spin in the pyscf world is 2S spin=multiplicity - 1, charge=charge, # Disable commandline argument parsing in pyscf parse_arg=False, dump_input=False, verbose=0, ) mf = ddCOSMO(scf.RHF(mol)) # default eps mf.with_solvent.eps = pcm_options.get("eps") mf.conv_tol = conv_tol mf.conv_tol_grad = conv_tol_grad mf.max_cycle = max_iter mf.kernel() # replace eps with eps_opt for the ADC calculation mf.with_solvent.eps = pcm_options.get("eps_opt") return adcc.backends.import_scf_results(mf)
def run_pyscf_tdscf(xyz, basis, charge=0, multiplicity=1, conv_tol=1e-12, conv_tol_grad=1e-11, max_iter=150, pcm_options=None): mol = gto.M( atom=xyz, basis=basis, unit="Bohr", charge=charge, # spin in the pyscf world is 2S spin=multiplicity - 1, verbose=0, # Disable commandline argument parsing in pyscf parse_arg=False, dump_input=False, ) if pcm_options: mf = ddCOSMO(scf.RHF(mol)) mf.with_solvent.eps = pcm_options.get("eps") else: mf = scf.RHF(mol) mf.conv_tol = conv_tol mf.conv_tol_grad = conv_tol_grad mf.max_cycle = max_iter mf.kernel() if pcm_options: mf.with_solvent.eps = pcm_options.get("eps_opt") # for n_eq solvation only PTE implemented mf.with_solvent.equilibrium_solvation = True cis = ddCOSMO(tdscf.TDA(mf)) else: cis = tdscf.TDA(mf) cis.nstates = 5 cis.conv_tol = 1e-7 cis.kernel() return mf, cis
def run_scf_solvent(mol, solvent_radii, solvent_lebedev_order): from pyscf import scf, solvent mf = scf.RHF(mol) mf = solvent.ddCOSMO(mf) mf.radii_table = solvent_radii mf.lebedev_order = solvent_lebedev_order mf.run() #print('DONE RHF/SOLVENT', mf.e_tot) return mf
def energy_calc(params, current_geom, mol): energy = 0.0 if (params.qm_program == 'pyscf'): pymol = gto.Mole() pymol.verbose = 0 geom_vec = [] for i in range(params.natoms): atom = [ params.symbols[i], ] atom_coords = [] for j in range(3): atom_coords.append(current_geom[i][j]) atom_coords = tuple(atom_coords) atom.append(atom_coords) geom_vec.append(atom) #print(geom_vec) pymol.atom = geom_vec pymol.unit = 'Bohr' pymol.basis = params.basis pymol.charge = params.charge pymol.spin = params.mult - 1 pymol.build() if (params.method == "scf"): scf_obj = scf.RHF(pymol) #if(params.method == "mp2"): #TODO Doesn't work yet. Few things left to figure out. # scf_obj = scf.RHF(pymol).run() # scf_obj = mp.MP2(scf_obj).run() #if(params.method == "dft"): # scf_obj = dft.RKS(mol) # scf_obj.xc = params.xc_functional if (params.do_solvent): solv_obj = solvent.ddCOSMO(scf_obj) solv_obj.with_solvent.eps = params.eps solv_obj.run() energy = solv_obj.kernel() print(energy) else: energy = scf_obj.scf() if (params.qm_program == 'psi4'): mol.set_geometry(psi4.core.Matrix.from_array(current_geom)) grad_method = "%s/%s" % (params.method, params.basis) psi4.core.set_output_file("psi4_out.dat", False) psi4.set_options(params.keywords) psi4.set_num_threads(params.nthreads) energy = psi4.energy(grad_method) return energy
def test_tda_grad(self): mol0 = gto.M(atom='H 0 0 0 ; H .5 .5 .1', unit='B', basis='321g') mol1 = gto.M(atom='H 0 0 -.001; H .5 .5 .1', unit='B', basis='321g') mol2 = gto.M(atom='H 0 0 0.001; H .5 .5 .1', unit='B', basis='321g') mf = scf.RHF(mol0).ddCOSMO().run() td = solvent.ddCOSMO(tdscf.TDA(mf)).run(equilibrium_solvation=True) ref = tda_grad(td, td.xy[0]) + mf.nuc_grad_method().kernel() e, de = td.nuc_grad_method().as_scanner(state=1)(mol0) de = td.nuc_grad_method().kernel() self.assertAlmostEqual(abs(ref - de).max(), 0, 12) td1 = mol1.RHF().ddCOSMO().run().TDA().ddCOSMO().run( equilibrium_solvation=True) td2 = mol2.RHF().ddCOSMO().run().TDA().ddCOSMO().run( equilibrium_solvation=True) e1 = td1.e_tot[0] e2 = td2.e_tot[0] self.assertAlmostEqual((e2 - e1) / 0.002, de[0, 2], 5)
# Author: Qiming Sun <*****@*****.**> # ''' A simple example of using solvent model in the mean-field calculations. ''' from pyscf import gto, scf, dft from pyscf import solvent mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', verbose=4) mf = scf.RHF(mol) solvent.ddCOSMO(mf).run() mf = dft.UKS(mol) mf.xc = 'b3lyp' solvent.ddPCM(mf).run() # Once solvent module is imported, PySCF-1.6.1 and newer supports the .ddCOSMO # and .ddPCM methods to create solvent model. from pyscf import solvent mf = mf.ddCOSMO() # Adjust solvent model by modifying the attribute .with_solvent mf.with_solvent.eps = 32.613 # methanol dielectric constant mf.run()
from pyscf import solvent mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', basis='ccpvdz') mf = scf.RHF(mol).run() # # 1. Allow solvent response to CASCI optimization # mc = mcscf.CASCI(mf, 4, 4) mc = solvent.ddCOSMO(mc) mc.run() # # Freeze solvent effects in the CASSCF optimization # # In this case, we need to decide which HF reference to use in the ddCOSMO-CASCI # calculation. The fully relaxed solvent at HF level is preferred. # mf = solvent.ddCOSMO(scf.RHF(mol)).run() mc = mcscf.CASCI(mf, 4, 4) # By passing density to solvent model, the solvent potential is frozen at the # HF level. mc = solvent.ddCOSMO(mc, dm=mf.make_rdm1()) mc.run()
from pyscf import solvent mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', basis='ccpvdz', verbose=3) mf = scf.RHF(mol).run() # # 1. Allow solvent response to CASSCF optimization # mycc = solvent.ddCOSMO(cc.CCSD(mf)) # Adjust solvent model by modifying the attribute .with_solvent mycc.with_solvent.eps = 32.613 # methanol dielectric constant mycc.run() # # Freeze solvent effects in the CASSCF optimization # # Solvent is fully relaxed in the HF calculation. # mf = solvent.ddCOSMO(scf.RHF(mol)).run() # By passing density to solvent model, the solvent potential is frozen at the # HF level. mycc = solvent.ddCOSMO(cc.CCSD(mf), dm=mf.make_rdm1()) mycc.run()
from pyscf import gto, qmmm, solvent # # Case 1. Cavity for dummy atoms with basis on the dummy atoms # mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 X-C 0.000000 0.000000 -1.5 X-O 0.000000 0.000000 1.6 ''', verbose=4) sol = solvent.ddCOSMO(mol) cavity_radii = sol.get_atomic_radii() cavity_radii[4] = 3.0 # Bohr, for X-C cavity_radii[5] = 2.5 # Bohr, for X-O # Overwrite the get_atom_radii method to feed the custom cavity into the solvent model sol.get_atomic_radii = lambda: cavity_radii mf = mol.RHF().ddCOSMO(sol) mf.run() # # Case 2. Cavity for dummy atoms (without basis) # mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500
# ''' A simple example of using solvent model in the mean-field calculations. ''' from pyscf import gto, scf, dft from pyscf import solvent mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', verbose = 4) mf = scf.RHF(mol) solvent.ddCOSMO(mf).run() mf = dft.UKS(mol) mf.xc = 'b3lyp' solvent.ddPCM(mf).run() # Once solvent module is imported, PySCF-1.6.1 and newer supports the .DDCOSMO # and .DDPCM methods to create solvent model. from pyscf import solvent mf = mf.DDCOSMO() # Adjust solvent model by modifying the attribute .with_solvent mf.with_solvent.eps = 32.613 # methanol dielectric constant mf.run()
''' from pyscf import gto, scf, mcscf from pyscf import solvent mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', basis='ccpvdz', verbose=4) # Initialize the reference HF calculation mf = solvent.ddCOSMO(scf.RHF(mol)).run() # Compute 5 states in CASCI. Slow solvent was assumed. Its effects are frozen # at HF level. mc = solvent.ddCOSMO(mcscf.CASCI(mf, 4, 4), dm=mf.make_rdm1()) mc.fcisolver.nstates = 5 mc.run() es_1 = mc.e_tot # Compute 5 states in CASCI, while the solvent only responses to the first # excited state. mc = solvent.ddCOSMO(mcscf.CASCI(mf, 4, 4)) mc.fcisolver.nstates = 5 mc.with_solvent.state_id = 1 mc.run() es_2 = mc.e_tot
mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', basis='ccpvdz', verbose=4) mf = scf.RHF(mol).run() # # 1. Allow solvent response to CASSCF optimization # mc = mcscf.CASSCF(mf, 8, 8) mc = solvent.ddCOSMO(mc) # Adjust solvent model by modifying the attribute .with_solvent mc.with_solvent.eps = 32.613 # methanol dielectric constant mc.run() # # Freeze solvent effects in the CASSCF optimization # # Solvent is fully relaxed in the HF calculation. # mf = solvent.ddCOSMO(scf.RHF(mol)).run() mc = mcscf.CASSCF(mf, 4, 4) # By passing density to solvent model, the solvent potential is frozen at the # HF level. mc = solvent.ddCOSMO(mc, dm=mf.make_rdm1()) mc.run()
def grad_calc(params, current_geom, mol): """ Uses Psi4 to calculate the energy gradient and returns the mass-weighted gradient and energy. Here any of the keywords the user provides in the .json input are used to set the options for the energy calculation. Parameters: ---------- params(self) -- contains initialized shared parameters. current_geom(np array) -- Matrix of size natoms x 3 containing the geometry. mol(psi4.Molecule) -- Psi4 molecule object containing the current molecule. Returns: ------- grad_mw(np array) -- Mass weighted gradient matrix of size natoms x 3. E(float) -- single-point energy from Psi4 calculation. """ if (params.qm_program == 'pyscf'): pymol = gto.Mole() pymol.verbose = 0 geom_vec = [] for i in range(params.natoms): atom = [ params.symbols[i], ] atom_coords = [] for j in range(3): atom_coords.append(current_geom[i][j]) atom_coords = tuple(atom_coords) atom.append(atom_coords) geom_vec.append(atom) #print(geom_vec) pymol.atom = geom_vec pymol.unit = 'Bohr' pymol.basis = params.basis pymol.charge = params.charge pymol.spin = params.mult - 1 pymol.build() if (params.method == "scf"): scf_obj = scf.RHF(pymol) #if(params.method == "mp2"): #TODO Doesn't work yet. Few things left to figure out. # mf = scf.RHF(pymol).run() # scf_obj = mp.MP2(mf).run() if (params.do_solvent): solv_obj = solvent.ddCOSMO(scf_obj) solv_obj.with_solvent.eps = params.eps solv_obj.run() E = solv_obj.kernel() grad = solv_obj.nuc_grad_method().kernel() else: E = scf_obj.kernel() grad = scf_obj.nuc_grad_method().kernel() #print(grad) grad_mw = mass_weight(params.natoms, grad, mol) if (params.qm_program == 'psi4'): mol.set_geometry(psi4.core.Matrix.from_array(current_geom)) mol.fix_orientation(True) mol.fix_com(True) mol.reset_point_group('c1') grad_method = "%s/%s" % (params.method, params.basis) psi4.core.set_output_file("psi4_out.dat", False) psi4.set_options(params.keywords) psi4.set_num_threads(params.nthreads) E, wfn = psi4.energy(grad_method, return_wfn=True) psi4.set_num_threads(params.nthreads) grad = np.asarray(psi4.gradient(grad_method, ref_wfn=wfn)) #print(grad) grad_mw = mass_weight(params.natoms, grad, mol) return grad_mw, E
#!/usr/bin/env python # # Author: Qiming Sun <*****@*****.**> # ''' Geometry optimization with solvent model ''' from pyscf import gto, scf, dft from pyscf import solvent from pyscf.geomopt import geometric_solver mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', verbose=4) mf = solvent.ddCOSMO(scf.RHF(mol)) new_mol = geometric_solver.optimize(mf)
import avas mol = gto.Mole() mol.basis = 'aug-cc-pvdz' mol.atom = ''' F 0.0000 0.0000 0.0000 Li 0.0000 0.0000 1.5639 ''' mol.verbose = 4 mol.spin = 0 mol.charge = 0 mol.symmetry = 1 mol.build() mf = scf.RHF(mol) mf = solvent.ddCOSMO(mf) mf.with_solvent.lebedev_order = 21 mf.with_solvent.lmax = 10 mf.with_solvent.max_cycle = 50 mf.with_solvent.conv_tol = 1e-6 mf.with_solvent.grids.radi_method = dft.mura_knowles mf.with_solvent.grids.becke_scheme = dft.stratmann mf.with_solvent.grids.level = 4 mf.with_solvent.grids.prune = None mf.kernel() ncore = 2 aolst1 = ['F 2s'] aolst2 = ['F 2p'] aolst3 = ['Li 2s'] aolst4 = ['Li 2p']
def atom_charges(self): return numpy.append(self.qm_mol.atom_charges(), self.mm_charges) # Make a giant system include both QM and MM particles qmmm_mol = QMMMMole(mol, coords, charges) # The solvent model is based on the giant system sol = solvent.DDCOSMO(qmmm_mol) # According to Lipparini's suggestion in issue #446 sol.radii_table = radii.VDW # # The order to apply solvent model and QM/MM charges does not affect results # # ddCOSMO-QMMM-SCF # mf = scf.RHF(mol) mf = qmmm.mm_charge(mf, coords, charges) mf = solvent.ddCOSMO(mf, sol) mf.run() # # QMMM-ddCOSMO-SCF # mf = scf.RHF(mol) mf = solvent.ddCOSMO(mf, sol) mf = qmmm.mm_charge(mf, coords, charges) mf.run()
mol = gto.M(atom=''' C 0.000000 0.000000 -0.542500 O 0.000000 0.000000 0.677500 H 0.000000 0.9353074360871938 -1.082500 H 0.000000 -0.9353074360871938 -1.082500 ''', verbose = 4) numpy.random.seed(1) coords = numpy.random.random((5,3)) * 10 charges = (numpy.arange(5) + 1.) * -.1 # # The order to apply solvent model and QM/MM charges does not affect results # # ddCOSMO-QMMM-SCF # mf = scf.RHF(mol) mf = qmmm.mm_charge(mf, coords, charges) mf = solvent.ddCOSMO(mf) mf.run() # # QMMM-ddCOSMO-SCF # mf = scf.RHF(mol) mf = solvent.ddCOSMO(mf) mf = qmmm.mm_charge(mf, coords, charges) mf.run()