def setUpClass(cls): cls.mol = gto.Mole() cls.mol.verbose = 4 cls.mol.atom = "O 0 0 0; H 0.790689766 0 0.612217330; H -0.790689766 0 0.612217330" cls.mol.basis = '3-21g' cls.mol.build() cls.mol.max_memory = 16e3 cls.mol.incore_anyway = True cls.mol.unit = "angstrom" cls.mf = scf.RHF(cls.mol) cls.mf.kernel() cls.ccsd = cc.RCCSD(cls.mf, frozen=1) cls.ccsd.kernel() cls.ccsd.solve_lambda() cls.eip, _ = cls.ccsd.ipccsd(nroots=8) cls.eea, _ = cls.ccsd.eaccsd(nroots=4) cls.energies = numpy.linspace(-1.9, 1, 50) cls.eta = 0.04 cls.title = 'H2O ({})'.format(cls.mol.basis) cls.options = dict( iter=dict(), chebushev=dict(order=400, range=10), td=dict(factor=1), )
def test_ipccsd(self): mycc = cc.RCCSD(mf) ecc, t1, t2 = mycc.kernel() e, v = mycc.ipccsd(nroots=3) self.assertAlmostEqual(e[0], 0.4335604332073799, 6) self.assertAlmostEqual(e[1], 0.5187659896045407, 6) self.assertAlmostEqual(e[2], 0.6782876002229172, 6)
def test_eaccsd(self): mycc = cc.RCCSD(mf) ecc, t1, t2 = mycc.kernel() e, v = mycc.eaccsd(nroots=3) self.assertAlmostEqual(e[0], 0.16737886338859731, 6) self.assertAlmostEqual(e[1], 0.24027613852009164, 6) self.assertAlmostEqual(e[2], 0.51006797826488071, 6)
def _run_ccsd(self, hf=None, **kwargs): from pyscf import cc if hf is None: hf = self._get_hf() ccsd = cc.RCCSD(hf) ccsd.kernel() return ccsd
def setUpClass(cls): cls.mol = gto.Mole() cls.mol.verbose = 6 cls.mol.atom = "H 0 0 0; H 0.74 0 0" cls.mol.basis = 'ccpvdz' cls.mol.build() cls.mol.max_memory = 16e3 cls.mf = scf.RHF(cls.mol) cls.mf.kernel() cls.ccsd = cc.RCCSD(cls.mf) cls.ccsd.kernel() cls.ccsd.solve_lambda() cls.eip, _ = cls.ccsd.ipccsd(nroots=4) cls.eea, _ = cls.ccsd.eaccsd(nroots=6) cls.energies = numpy.linspace(-1.9, 1, 200) cls.eta = 0.01 cls.title = "H2" cls.options = dict( iter=dict(), chebushev=dict(order=400, range=10), td=dict(factor=1), )
def test_eeccsd(self): mycc = cc.RCCSD(mf) ecc, t1, t2 = mycc.kernel() e, v = mycc.eeccsd(nroots=4) self.assertAlmostEqual(e[0], 0.2757159395886167, 6) self.assertAlmostEqual(e[1], 0.2757159395886167, 6) self.assertAlmostEqual(e[2], 0.2757159395886167, 6) self.assertAlmostEqual(e[3], 0.3005716731825082, 6)
def test_amplitudes_from_rccsd(self): e, t1, t2 = cc.RCCSD(rhf).set(conv_tol=1e-10).kernel() t1, t2 = myucc.amplitudes_from_rccsd(t1, t2) self.assertAlmostEqual(abs(t1[0] - myucc.t1[0]).max(), 0, 6) self.assertAlmostEqual(abs(t1[1] - myucc.t1[1]).max(), 0, 6) self.assertAlmostEqual(abs(t2[0] - myucc.t2[0]).max(), 0, 6) self.assertAlmostEqual(abs(t2[1] - myucc.t2[1]).max(), 0, 6) self.assertAlmostEqual(abs(t2[2] - myucc.t2[2]).max(), 0, 6)
def run_pyscf_ccsd(mol=None, hf=None, **kwargs): from pyscf import cc if mol is None and hf is None: raise Exception("provide mol or hf") if hf is None: hf = run_pyscf_hf(mol, **kwargs) ccsd = cc.RCCSD(hf) ccsd.kernel() return ccsd
def main(): # Here we check for the correct number of arguments. In the paper, this allowed rapid generation and organization of different methods args = sys.argv[1:] if len(args) != 4: print 'usage: formula basis ccsd/mbpt2/lin/cc2 none/full/mp/brutal' sys.exit(1) # Save the user input formula = args[0] basis = args[1] cctype = args[2] approx = cctype.lower() # Use the approximation as desired by user if approx == 'ccsd': approx = None partition = args[3] # Use the partitioning scheme as desired by user (usually none or mp) if partition.lower() == 'none': partition = None # Please see gw100 file for further information # Here we simply load the molecule information from the gw100 object from gw100 import GW100 gw100_set = GW100() mol = gw100_set.molecules[formula].mol # Here we change the default basis to the basis of interest mol.basis = basis # And rebuild the molecule object mol.build() # This instantiates the SCF object as RHF mf = scf.RHF(mol) # Verbosity can be important, but can also be minimized mf.verbose = 3 # This line runs the actual SCF calculation ehf = mf.scf() # Load the frozen orbital count (taken from Krause paper) frozen = gw100_set.molecules[formula].frozen # Identify the correct number of roots to find nocc = mol.nelectron // 2 nvir = mol.nao_nr() - nocc nip = min(nocc - len(frozen), 4) nea = min(nvir, 12) # Instantiate the cc object as RCCSD mcc = cc.RCCSD(mf, frozen=frozen) # mcc = cc.RCCSD(mf, approx=approx, frozen=frozen) # If you'd like to include run an # approximate calculation - use this variant # Again, verbosity can be changed as needed mcc.verbose = 4 # Run the actual cc calculation (this is for the GROUND state) mcc.ccsd() # This runs the IP calculation, asking for koopman-like roots, with nip IP values, and partitioning of choice e, c = mcc.ipccsd(nip, koopmans=True, partition=partition) # This runs the EA calculation, asking for koopman-like roots, with nea EA values, and partitioning of choice e, c = mcc.eaccsd(nea, koopmans=True, partition=partition)
def test_h2o_star(self): mol_h2o = gto.Mole() mol_h2o.atom = [ [8, [0.000000000000000, -0.000000000000000, -0.124143731294022]], [1, [0.000000000000000, -1.430522735894536, 0.985125550040314]], [1, [0.000000000000000, 1.430522735894536, 0.985125550040314]] ] mol_h2o.unit = 'B' mol_h2o.basis = { 'H': [[0, [5.4471780, 0.156285], [0.8245472, 0.904691]], [0, [0.1831916, 1.0]]], 'O': '3-21G' } mol_h2o.verbose = 7 mol_h2o.output = '/dev/null' mol_h2o.build() mol.conv_tol = 1e-12 mf_h2o = scf.RHF(mol_h2o) mf_h2o.conv_tol_grad = 1e-12 mf_h2o.kernel() mycc_h2o = cc.RCCSD(mf_h2o).run() mycc_h2o.conv_tol_normt = 1e-12 mycc_h2o.conv_tol = 1e-12 mycc_h2o.kernel() myeom = eom_rccsd.EOMIP(mycc_h2o) e = myeom.ipccsd_star(nroots=3) self.assertAlmostEqual(e[0], 0.410661965883, 6) myeom = eom_rccsd.EOMIP_Ta(mycc_h2o) e = myeom.ipccsd_star(nroots=3) self.assertAlmostEqual(e[0], 0.411695647736, 6) myeom = eom_rccsd.EOMEA(mycc_h2o) e = myeom.eaccsd_star(nroots=3) self.assertAlmostEqual(e[0], 0.250589854185, 6) myeom = eom_rccsd.EOMEA_Ta(mycc_h2o) e = myeom.eaccsd_star(nroots=3) self.assertAlmostEqual(e[0], 0.250720295150, 6)
To use DF-RCCSD object, density fitting should be enabled at SCF level. DFCCSD uses the same auxiliary basis as the DF-SCF method. It does not support a separated auxiliary basis. ''' from pyscf import gto, scf, cc mol = gto.Mole() mol.atom = [['O', (0., 0., 0.)], ['H', (0., -0.757, 0.587)], ['H', (0., 0.757, 0.587)]] mol.basis = 'cc-pvdz' mol.build() mf = scf.RHF(mol).density_fit().run() mycc = cc.RCCSD(mf).run() print(mycc.e_corr - -0.21337100025961622) print("IP energies... (right eigenvector)") part = None e, v = mycc.ipccsd(nroots=3, partition=part) print(e) print(e[0] - 0.43364287418576897) print(e[1] - 0.5188001071775572) print(e[2] - 0.67851590275796392) print("IP energies... (left eigenvector)") e, lv = mycc.ipccsd(nroots=3, left=True, partition=part) print(e) print(e[0] - 0.43364286531878882) print(e[1] - 0.51879999865136994)
if results.aux_basis_set != 'undefined' else None) pseudo_potential = (results.pseudo_potential if results.pseudo_potential != 'undefined' else None) functional = results.functional charge = int(results.charge) if results.charge is not None else 0 multiplicity = int( results.multiplicity) if results.multiplicity is not None else 1 spin = (multiplicity - 1) / 2 num_frozen_cores = int( results.frozen_cores) if results.frozen_cores is not None else 0 sys.argv = [sys.argv[0]] # ----------------------- # PYSCF # ----------------------- mol = gto.M( atom=atomic_coords, basis=basis_set, spin=spin, charge=charge, verbose=5) mf = scf.RHF(mol) if density_fit: mf = mf.density_fit() mf.with_df.auxbasis = aux_basis_set mf.run() my_cc = cc.RCCSD(mf) my_cc.kernel() e_ea, c_ea = my_cc.eaccsd(nroots=1)
from pyscf import gto, scf, cc mol = gto.M(atom='H 0 0 0; H 0 0 1') mf = scf.RHF(mol).run() cc.CCSD(mf).run() from pyscf import gto, scf, cc mol = gto.M(atom='H 0 0 0; H 0 0 1') mf = scf.RHF(mol).run() cc.RCCSD(mf).run()
def test_roccsd(self): mf = scf.ROHF(mol).run() mycc = cc.RCCSD(mf).run() self.assertAlmostEqual(mycc.e_tot, -76.119346385357446, 7)
mf1 = copy.copy(mf) no = mol.nelectron // 2 n = mol.nao_nr() nv = n - no mf1.mo_occ = numpy.zeros(mol.nao_nr()) mf1.mo_occ[:no] = 2 numpy.random.seed(12) mf1.mo_coeff = numpy.random.random((n, n)) dm = mf1.make_rdm1(mf1.mo_coeff, mf1.mo_occ) fockao = mf1.get_hcore() + mf1.get_veff(mol, dm) mf1.mo_energy = numpy.einsum('pi,pq,qi->i', mf1.mo_coeff, fockao, mf1.mo_coeff) idx = numpy.hstack( [mf1.mo_energy[:no].argsort(), no + mf1.mo_energy[no:].argsort()]) mf1.mo_coeff = mf1.mo_coeff[:, idx] mycc1 = cc.RCCSD(mf1) mycc1.eris = eris = mycc1.ao2mo() numpy.random.seed(12) r1 = numpy.random.random((no, nv)) - .9 r2 = numpy.random.random((no, no, nv, nv)) - .9 r2 = r2 + r2.transpose(1, 0, 3, 2) mycc1.t1 = r1 * 1e-5 mycc1.t2 = r2 * 1e-5 class KnowValues(unittest.TestCase): def test_ipccsd(self): mycc = cc.RCCSD(mf) ecc, t1, t2 = mycc.kernel() e, v = mycc.ipccsd(nroots=3) self.assertAlmostEqual(e[0], 0.4335604332073799, 6)
A simple example to compare ctf RCCSD with serial RCCSD on PYSCF Usage: mpirun -np 4 python 01-mole_rccsd_comparison.py ''' from pyscf import scf, gto, cc from cc_sym import rccsd, settings rank = settings.rank comm = settings.comm mol = gto.Mole(atom='H 0 0 0; F 0 0 1.1', basis='ccpvdz', verbose=4) mf = scf.RHF(mol) if rank == 0: mf.kernel() refcc = cc.RCCSD(mf) refcc.kernel() comm.barrier() mf.mo_coeff = comm.bcast(mf.mo_coeff, root=0) mf.mo_occ = comm.bcast(mf.mo_occ, root=0) mycc = rccsd.RCCSD(mf) mycc.kernel() if rank == 0: refcc.ipccsd(nroots=2) comm.barrier() mycc.ipccsd(nroots=2)
def ecw_energy(self, method, dim): mf_energy, Vemb, Vxc = self.imp_mf_energy(dim) Ne_frag = self.Ne_frag ops = self.ops subOEI = ops["subKin"] + ops["subVnuc1"] + Vemb subTEI = ops["subTEI"] mf = qcwrap.qc_scf(Ne_frag, dim, 'hf', mol=self.mol_frag, oei=subOEI, tei=subTEI, dm0=self.P_imp) mf.runscf() e_hf = mf.elec_energy # - np.trace(np.dot(mf.rdm1,Vemb)) if (self.plot_mo): self.ints.submo_molden(mf.mo_coeff, mf.mo_occ, self.loc2sub, "mo_frag.molden", self.mol_frag) exc = 0.0 if (Vxc is not None): # exc = np.einsum('ij,ji', Vxc, mf.rdm1-self.P_imp) exc = np.einsum('ij,ji', Vxc, self.P_imp) print('exc = ', exc) if (method == 'hf'): energy = e_hf elif (method == 'mp2'): mp2 = mp.MP2(mf) mp2.kernel() energy = e_hf + mp2.e_corr elif (method == 'ccsd' or method == 'ccsd(t)'): mycc = cc.CCSD(mf) mycc.max_cycle = 200 #mycc.conv_tol = 1e-6 #mycc.conv_tol_normt = 1e-4 mycc.kernel() et = 0.0 if (method == 'ccsd(t)'): print('CCSD(T) correction') et = mycc.ccsd_t() energy = e_hf + mycc.e_corr + et elif (method == 'eomccsd'): mf.verbose = 5 mycc = cc.RCCSD(mf) mycc.kernel() es, vs = mycc.eomee_ccsd_singlet(nroots=self.ex_nroots) if (self.ex_nroots == 1): r1, r2 = mycc.vector_to_amplitudes(vs) print('debug: ', r1.shape) else: for vn in vs: r1, r2 = mycc.vector_to_amplitudes(vn) energy = e_hf + mycc.e_corr elif (method == 'eomsfccsd'): self.mol_frag.spin = 2 mf = qcwrap.pyscf_rks.rohf_pyscf(Ne_frag, dim, mol=self.mol_frag, oei=subOEI, tei=subTEI, dm0=np.array((.5 * self.P_imp, .5 * self.P_imp))) mf.kernel(dm0=mf.dm_guess) mf1 = qcwrap.pyscf_rks.uhf_pyscf(Ne_frag, dim, mol=self.mol_frag, oei=subOEI, tei=subTEI, dm0=None) mf1.convert_from_rhf(mf) mycc = cc.UCCSD(mf1) mycc.verbose = 5 mycc.kernel() es, vs = mycc.eomsf_ccsd(nroots=self.ex_nroots) if (self.ex_nroots == 1): r1, r2 = cc.eom_uccsd.vector_to_amplitudes_eomsf( vs, mycc.nmo, mycc.nocc) tools.print_eomcc_t1(r1[0]) tools.print_eomcc_t1(r1[1]) else: for vn in vs: r1, r2 = cc.eom_uccsd.vector_to_amplitudes_eomsf( vn, mycc.nmo, mycc.nocc) tools.print_eomcc_t1(r1[0]) tools.print_eomcc_t1(r1[1]) energy = mf1.e_tot + mycc.e_corr else: raise Exception("ecw_method not supported!") energy -= mf_energy energy -= exc return energy
n = 6 mol.nelectron = n # Setting incore_anyway=True to ensure the customized Hamiltonian (the _eri # attribute) to be used in the post-HF calculations. Without this parameter, # some post-HF method (particularly in the MO integral transformation) may # ignore the customized Hamiltonian if memory is not enough. mol.incore_anyway = True h1 = numpy.zeros((n, n)) for i in range(n - 1): h1[i, i + 1] = h1[i + 1, i] = -1.0 h1[n - 1, 0] = h1[0, n - 1] = -1.0 eri = numpy.zeros((n, n, n, n)) for i in range(n): eri[i, i, i, i] = 2.0 mf = scf.RHF(mol) mf.get_hcore = lambda *args: h1 mf.get_ovlp = lambda *args: numpy.eye(n) mf._eri = ao2mo.restore(8, eri, n) mf.kernel() # In PySCF, the customized Hamiltonian needs to be created once in mf object. # The Hamiltonian will be used everywhere whenever possible. Here, the model # Hamiltonian is passed to CCSD object via the mf object. mycc = cc.RCCSD(mf) mycc.kernel() e, v = mycc.ipccsd(nroots=3) print(e)
from pyscf import gto from pyscf import scf from mpi4pyscf import cc as mpicc from pyscf import cc as serial_cc mol = gto.Mole() mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)], [1, (0., 0.757, 0.587)]] mol.basis = '6-31g' mol.verbose = 4 mol.build() mf = scf.RHF(mol) mf.chkfile = 'h2o.chk' mf.run() mycc = mpicc.RCCSD(mf) mycc.diis_file = 'mpi_ccdiis.h5' mycc.kernel() mycc.restore_from_diis_('mpi_ccdiis.h5') mycc.kernel() s_cc = serial_cc.RCCSD(mf) s_cc.diis_file = 'serial_ccdiis.h5' s_cc.kernel() p_cc = mpicc.RCCSD(mf) p_cc.restore_from_diis_('serial_ccdiis.h5') p_cc.kernel()