def get_fock(mf, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): h1e_kpts, s_kpts, vhf_kpts, dm_kpts = h1e, s1e, vhf, dm if h1e_kpts is None: h1e_kpts = mf.get_hcore() if vhf_kpts is None: vhf_kpts = mf.get_veff(mf.cell, dm_kpts) f_kpts = h1e_kpts + vhf_kpts if cycle < 0 and diis is None: # Not inside the SCF iteration return f_kpts if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if s_kpts is None: s_kpts = mf.get_ovlp() if dm_kpts is None: dm_kpts = mf.make_rdm1() if isinstance(level_shift_factor, (tuple, list, np.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor if diis and cycle >= diis_start_cycle: f_kpts = diis.update(s_kpts, dm_kpts, f_kpts, mf, h1e_kpts, vhf_kpts) if abs(level_shift_factor) > 1e-4: f_kpts =([mol_hf.level_shift(s, dm_kpts[0,k], f_kpts[0,k], shifta) for k, s in enumerate(s_kpts)], [mol_hf.level_shift(s, dm_kpts[1,k], f_kpts[1,k], shiftb) for k, s in enumerate(s_kpts)]) return lib.asarray(f_kpts)
def get_fock( mf, h1e_kpts, s_kpts, vhf_kpts, dm_kpts, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None, ): if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if isinstance(level_shift_factor, (tuple, list, np.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor f_kpts = h1e_kpts + vhf_kpts if adiis and cycle >= diis_start_cycle: f_kpts = adiis.update(s_kpts, dm_kpts, f_kpts) if abs(level_shift_factor) > 1e-4: f_kpts = [hf.level_shift(s, dm_kpts[0, k], f_kpts[0, k], shifta) for k, s in enumerate(s_kpts)] + [ hf.level_shift(s, dm_kpts[1, k], f_kpts[1, k], shiftb) for k, s in enumerate(s_kpts) ] return lib.asarray(f_kpts)
def get_fock(mf, h1e_kpts, s_kpts, vhf_kpts, dm_kpts, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if isinstance(level_shift_factor, (tuple, list, np.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor f_kpts = h1e_kpts + vhf_kpts if adiis and cycle >= diis_start_cycle: f_kpts = adiis.update(s_kpts, dm_kpts, f_kpts) if abs(level_shift_factor) > 1e-4: f_kpts = ([ hf.level_shift(s, dm_kpts[0, k], f_kpts[0, k], shifta) for k, s in enumerate(s_kpts) ], [ hf.level_shift(s, dm_kpts[1, k], f_kpts[1, k], shiftb) for k, s in enumerate(s_kpts) ]) return lib.asarray(f_kpts)
def get_fock(mf, h1e, s1e, vhf, dm, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if isinstance(level_shift_factor, (tuple, list, numpy.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor if isinstance(damp_factor, (tuple, list, numpy.ndarray)): dampa, dampb = damp_factor else: dampa = dampb = damp_factor f = h1e + vhf if f.ndim == 2: f = (f, f) if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = [dm*.5] * 2 if 0 <= cycle < diis_start_cycle-1 and abs(dampa)+abs(dampb) > 1e-4: f = (hf.damping(s1e, dm[0], f[0], dampa), hf.damping(s1e, dm[1], f[1], dampb)) if diis and cycle >= diis_start_cycle: f = diis.update(s1e, dm, f, mf, h1e, vhf) if abs(shifta)+abs(shiftb) > 1e-4: f = (hf.level_shift(s1e, dm[0], f[0], shifta), hf.level_shift(s1e, dm[1], f[1], shiftb)) return numpy.array(f)
def get_fock(mf, h1e, s1e, vhf, dm, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if isinstance(level_shift_factor, (tuple, list, numpy.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor if isinstance(damp_factor, (tuple, list, numpy.ndarray)): dampa, dampb = damp_factor else: dampa = dampb = damp_factor f = h1e + vhf if f.ndim == 2: f = (f, f) if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = [dm*.5] * 2 if 0 <= cycle < diis_start_cycle-1 and abs(dampa)+abs(dampb) > 1e-4: f = (hf.damping(s1e, dm[0], f[0], dampa), hf.damping(s1e, dm[1], f[1], dampb)) if adiis and cycle >= diis_start_cycle: f = adiis.update(s1e, dm, f) if abs(shifta)+abs(shiftb) > 1e-4: f = (hf.level_shift(s1e, dm[0], f[0], shifta), hf.level_shift(s1e, dm[1], f[1], shiftb)) return numpy.array(f)
def uhf_get_fock(mf, emb_pot=None, proj_pot=None, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if emb_pot is None: emb_pot = [0.0, 0.0] if proj_pot is None: proj_pot = [0.0, 0.0] if h1e is None: h1e = mf.get_hcore() #if vhf is None: vhf = mf.get_veff(dm=dm) #For some reason the vhf being passed is wrong I believe. vhf = mf.get_veff(dm=dm) f = h1e + vhf if f.ndim == 2: f = (f, f) f[0] = f[0] + emb_pot[0] + proj_pot[0] #Add embedding potential f[1] = f[1] + emb_pot[1] + proj_pot[1] #Add embedding potential if cycle < 0 and diis is None: # Not inside the SCF iteration return f if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if s1e is None: s1e = mf.get_ovlp() if dm is None: dm = self.make_rdm1() if isinstance(level_shift_factor, (tuple, list, np.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor if isinstance(damp_factor, (tuple, list, np.ndarray)): dampa, dampb = damp_factor else: dampa = dampb = damp_factor if isinstance(dm, np.ndarray) and dm.ndim == 2: dm = [dm * .5] * 2 if 0 <= cycle < diis_start_cycle - 1 and abs(dampa) + abs(dampb) > 1e-4: f = (hf.damping(s1e, dm[0], f[0], dampa), hf.damping(s1e, dm[1], f[1], dampb)) if diis and cycle >= diis_start_cycle: f = diis.update(s1e, dm, f, mf, h1e, vhf) if abs(shifta) + abs(shiftb) > 1e-4: f = (hf.level_shift(s1e, dm[0], f[0], shifta), hf.level_shift(s1e, dm[1], f[1], shiftb)) return np.array(f)
def get_fock_(mf, h1e, s1e, vhf, dm, cycle=-1, adiis=None, diis_start_cycle=0, level_shift_factor=0, damp_factor=0): f = h1e + vhf if f.ndim == 2: f = (f, f) if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = [dm * 0.5] * 2 if 0 <= cycle < diis_start_cycle - 1: f = (hf.damping(s1e, dm[0], f[0], damp_factor), hf.damping(s1e, dm[1], f[1], damp_factor)) if adiis and cycle >= diis_start_cycle: f = adiis.update(s1e, dm, numpy.array(f)) f = (hf.level_shift(s1e, dm[0], f[0], level_shift_factor), hf.level_shift(s1e, dm[1], f[1], level_shift_factor)) return numpy.array(f)
def get_fock(mf, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): h1e_kpts, s_kpts, vhf_kpts, dm_kpts = h1e, s1e, vhf, dm if h1e_kpts is None: h1e_kpts = mf.get_hcore() if vhf_kpts is None: vhf_kpts = mf.get_veff(mf.cell, dm_kpts) f_kpts = h1e_kpts + vhf_kpts if cycle < 0 and diis is None: # Not inside the SCF iteration return f_kpts if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if s_kpts is None: s_kpts = mf.get_ovlp() if dm_kpts is None: dm_kpts = mf.make_rdm1() if 0 <= cycle < diis_start_cycle-1 and abs(damp_factor) > 1e-4: f_kpts = [mol_hf.damping(s1e, dm_kpts[k] * 0.5, f_kpts[k], damp_factor) for k, s1e in enumerate(s_kpts)] if diis and cycle >= diis_start_cycle: f_kpts = diis.update(s_kpts, dm_kpts, f_kpts, mf, h1e_kpts, vhf_kpts) if abs(level_shift_factor) > 1e-4: f_kpts = [mol_hf.level_shift(s, dm_kpts[k], f_kpts[k], level_shift_factor) for k, s in enumerate(s_kpts)] return lib.asarray(f_kpts)
def get_fock(mf, h1e, s1e, vhf, dm, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): '''Build fock matrix based on Roothaan's effective fock. See also :func:`get_roothaan_fock` ''' if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = numpy.array((dm*.5, dm*.5)) # To Get orbital energy in get_occ, we saved alpha and beta fock, because # Roothaan effective Fock cannot provide correct orbital energy with `eig` # TODO, check other treatment J. Chem. Phys. 133, 141102 mf._focka_ao = h1e + vhf[0] mf._fockb_ao = h1e + vhf[1] f = get_roothaan_fock((mf._focka_ao,mf._fockb_ao), dm, s1e) if 0 <= cycle < diis_start_cycle-1: f = hf.damping(s1e, dm[0], f, damp_factor) if adiis and cycle >= diis_start_cycle: #f = adiis.update(s1e, dmsf*.5, f) f = adiis.update(s1e, dm[0], f) #f = level_shift(s1e, dmsf*.5, f, level_shift_factor) f = hf.level_shift(s1e, dm[0], f, level_shift_factor) return f
def get_fock(mf, h1e_kpts, s_kpts, vhf_kpts, dm_kpts, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp f_kpts = h1e_kpts + vhf_kpts if adiis and cycle >= diis_start_cycle: f_kpts = adiis.update(s_kpts, dm_kpts, f_kpts) if abs(level_shift_factor) > 1e-4: f_kpts = [ hf.level_shift(s, dm_kpts[k], f_kpts[k], level_shift_factor) for k, s in enumerate(s_kpts) ] return lib.asarray(f_kpts)
def get_fock(mf, h1e, s1e, vhf, dm, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): '''Build fock matrix based on Roothaan's effective fock. See also :func:`get_roothaan_fock` ''' if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = numpy.array((dm*.5, dm*.5)) # To Get orbital energy in get_occ, we saved alpha and beta fock, because # Roothaan effective Fock cannot provide correct orbital energy with `eig` # TODO, check other treatment J. Chem. Phys. 133, 141102 mf._focka_ao = h1e + vhf[0] mf._fockb_ao = h1e + vhf[1] f = get_roothaan_fock((mf._focka_ao,mf._fockb_ao), dm, s1e) if 0 <= cycle < diis_start_cycle-1: f = hf.damping(s1e, dm[0], f, damp_factor) if diis and cycle >= diis_start_cycle: #f = diis.update(s1e, dmsf*.5, f, mf, h1e, vhf) f = diis.update(s1e, dm[0], f, mf, h1e, vhf) #f = level_shift(s1e, dmsf*.5, f, level_shift_factor) f = hf.level_shift(s1e, dm[0], f, level_shift_factor) return f
def get_fock(mf, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if h1e is None: h1e = mf.get_hcore() if vhf is None: vhf = mf.get_veff(mf.mol, dm) f = h1e + vhf if f.ndim == 2: f = (f, f) if cycle < 0 and diis is None: # Not inside the SCF iteration return f if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if s1e is None: s1e = mf.get_ovlp() if dm is None: dm = self.make_rdm1() if isinstance(level_shift_factor, (tuple, list, numpy.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor if isinstance(damp_factor, (tuple, list, numpy.ndarray)): dampa, dampb = damp_factor else: dampa = dampb = damp_factor if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = [dm * .5] * 2 if 0 <= cycle < diis_start_cycle - 1 and abs(dampa) + abs(dampb) > 1e-4: f = (hf.damping(s1e, dm[0], f[0], dampa), hf.damping(s1e, dm[1], f[1], dampb)) if diis and cycle >= diis_start_cycle: f = diis.update(s1e, dm, f, mf, h1e, vhf) if abs(shifta) + abs(shiftb) > 1e-4: f = (hf.level_shift(s1e, dm[0], f[0], shifta), hf.level_shift(s1e, dm[1], f[1], shiftb)) return numpy.array(f)
def get_fock_(mf, h1e, s1e, vhf, dm, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): '''Roothaan's effective fock. Ref. http://www-theor.ch.cam.ac.uk/people/ross/thesis/node15.html ======== ======== ====== ========= space closed open virtual ======== ======== ====== ========= closed Fc Fb Fc open Fb Fc Fa virtual Fc Fa Fc ======== ======== ====== ========= where Fc stands for the Fa + Fb Returns: (fock_eff, fock_alpha, fock_beta) Roothaan effective Fock matrix, with UHF alpha and beta Fock matrices. Attach alpha and beta fock, because Roothaan effective Fock cannot provide correct orbital energies. ''' if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift_factor if damp_factor is None: damp_factor = mf.damp_factor if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = numpy.array((dm*.5, dm*.5)) # Fc = (Fa+Fb)/2 mf._focka_ao = h1e + vhf[0] fockb_ao = h1e + vhf[1] fc = (mf._focka_ao + fockb_ao) * .5 # Projector for core, open-shell, and virtual nao = s1e.shape[0] pc = numpy.dot(dm[1], s1e) po = numpy.dot(dm[0]-dm[1], s1e) pv = numpy.eye(nao) - numpy.dot(dm[0], s1e) f = reduce(numpy.dot, (pc.T, fc, pc)) * .5 f += reduce(numpy.dot, (po.T, fc, po)) * .5 f += reduce(numpy.dot, (pv.T, fc, pv)) * .5 f += reduce(numpy.dot, (po.T, fockb_ao, pc)) f += reduce(numpy.dot, (po.T, mf._focka_ao, pv)) f += reduce(numpy.dot, (pv.T, fc, pc)) f = f + f.T if 0 <= cycle < diis_start_cycle-1: f = hf.damping(s1e, dm[0], f, damp_factor) if adiis and cycle >= diis_start_cycle: #f = adiis.update(s1e, dmsf*.5, f) f = adiis.update(s1e, dm[0], f) #f = level_shift(s1e, dmsf*.5, f, level_shift_factor) f = hf.level_shift(s1e, dm[0], f, level_shift_factor) # attach alpha and beta fock, because Roothaan effective Fock cannot provide # correct orbital energy. To define orbital energy in mf.eig, we use alpha # fock and beta fock. # TODO, check other treatment J. Chem. Phys. 133, 141102 return f
def get_fock(mf, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if h1e is None: h1e = mf.get_hcore() if vhf is None: vhf = mf.get_veff(mf.mol, dm) f = h1e + vhf if f.ndim == 2: f = (f, f) if cycle < 0 and diis is None: # Not inside the SCF iteration return f if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if s1e is None: s1e = mf.get_ovlp() if dm is None: dm = self.make_rdm1() if isinstance(level_shift_factor, (tuple, list, numpy.ndarray)): shifta, shiftb = level_shift_factor else: shifta = shiftb = level_shift_factor if isinstance(damp_factor, (tuple, list, numpy.ndarray)): dampa, dampb = damp_factor else: dampa = dampb = damp_factor if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = [dm*.5] * 2 if 0 <= cycle < diis_start_cycle-1 and abs(dampa)+abs(dampb) > 1e-4: f = (hf.damping(s1e, dm[0], f[0], dampa), hf.damping(s1e, dm[1], f[1], dampb)) if diis and cycle >= diis_start_cycle: f = diis.update(s1e, dm, f, mf, h1e, vhf) if abs(shifta)+abs(shiftb) > 1e-4: f = (hf.level_shift(s1e, dm[0], f[0], shifta), hf.level_shift(s1e, dm[1], f[1], shiftb)) return numpy.array(f)
def get_fock(self, h1e, s1e, vhf, dm, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): # Roothaan's effective fock # http://www-theor.ch.cam.ac.uk/people/ross/thesis/node15.html # | closed open virtual # ---------------------------------------- # closed | Fc Fb Fc # open | Fb Fc Fa # virtual | Fc Fa Fc # Fc = (Fa+Fb)/2 if diis_start_cycle is None: diis_start_cycle = self.diis_start_cycle if level_shift_factor is None: level_shift_factor = self.level_shift if damp_factor is None: damp_factor = self.damp if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = numpy.array((dm * .5, dm * .5)) self._focka_ao = h1e + vhf[0] self._fockb_ao = h1e + vhf[1] ncore = (self.mol.nelectron - self.mol.spin) // 2 nopen = self.mol.spin nocc = ncore + nopen dmsf = dm[0] + dm[1] mo_space = scipy.linalg.eigh(-dmsf, s1e, type=2)[1] fa = reduce(numpy.dot, (mo_space.T, self._focka_ao, mo_space)) fb = reduce(numpy.dot, (mo_space.T, self._fockb_ao, mo_space)) feff = (fa + fb) * .5 feff[:ncore, ncore:nocc] = fb[:ncore, ncore:nocc] feff[ncore:nocc, :ncore] = fb[ncore:nocc, :ncore] feff[nocc:, ncore:nocc] = fa[nocc:, ncore:nocc] feff[ncore:nocc, nocc:] = fa[ncore:nocc, nocc:] cinv = numpy.dot(mo_space.T, s1e) f = reduce(numpy.dot, (cinv.T, feff, cinv)) if 0 <= cycle < diis_start_cycle - 1: f = hf.damping(s1e, dm[0], f, damp_factor) if adiis and cycle >= diis_start_cycle: f = adiis.update(s1e, dm[0], f) f = hf.level_shift(s1e, dm[0], f, level_shift_factor) return f
def rohf_get_fock(mf, emb_pot=None, proj_pot=None, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): '''Build fock matrix based on Roothaan's effective fock. See also :func:`get_roothaan_fock` ''' if emb_pot is None: emb_pot = [0.0, 0.0] if h1e is None: h1e = mf.get_hcore() if s1e is None: s1e = mf.get_ovlp() if vhf is None: vhf = mf.get_veff(dm=dm) if dm is None: dm = mf.make_rdm1() if isinstance(dm, np.ndarray) and dm.ndim == 2: dm = np.array((dm * .5, dm * .5)) # To Get orbital energy in get_occ, we saved alpha and beta fock, because # Roothaan effective Fock cannot provide correct orbital energy with `eig` # TODO, check other treatment J. Chem. Phys. 133, 141102 focka = h1e + vhf[0] + emb_pot[0] + proj_pot[0] #Add embedding potential fockb = h1e + vhf[1] + emb_pot[1] + proj_pot[1] #Add embedding potential f = rohf.get_roothaan_fock((focka, fockb), dm, s1e) if cycle < 0 and diis is None: # Not inside the SCF iteration return f if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp dm_tot = dm[0] + dm[1] if 0 <= cycle < diis_start_cycle - 1 and abs(damp_factor) > 1e-4: raise NotImplementedError('ROHF Fock-damping') if diis and cycle >= diis_start_cycle: f = diis.update(s1e, dm_tot, f, mf, h1e, vhf) if abs(level_shift_factor) > 1e-4: f = hf.level_shift(s1e, dm_tot * .5, f, level_shift_factor) f = lib.tag_array(f, focka=focka, fockb=fockb) return f
def get_fock(mf, h1e_kpts, s_kpts, vhf_kpts, dm_kpts, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp f_kpts = h1e_kpts + vhf_kpts if adiis and cycle >= diis_start_cycle: f_kpts = adiis.update(s_kpts, dm_kpts, f_kpts) if abs(level_shift_factor) > 1e-4: f_kpts = [hf.level_shift(s, dm_kpts[k], f_kpts[k], level_shift_factor) for k, s in enumerate(s_kpts)] return lib.asarray(f_kpts)
def get_fock(self, h1e, s1e, vhf, dm, cycle=-1, adiis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): # Roothaan's effective fock # http://www-theor.ch.cam.ac.uk/people/ross/thesis/node15.html # | closed open virtual # ---------------------------------------- # closed | Fc Fb Fc # open | Fb Fc Fa # virtual | Fc Fa Fc # Fc = (Fa+Fb)/2 if diis_start_cycle is None: diis_start_cycle = self.diis_start_cycle if level_shift_factor is None: level_shift_factor = self.level_shift if damp_factor is None: damp_factor = self.damp if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = numpy.array((dm*.5, dm*.5)) self._focka_ao = h1e + vhf[0] self._fockb_ao = h1e + vhf[1] ncore = (self.mol.nelectron-self.mol.spin) // 2 nopen = self.mol.spin nocc = ncore + nopen dmsf = dm[0]+dm[1] mo_space = scipy.linalg.eigh(-dmsf, s1e, type=2)[1] fa = reduce(numpy.dot, (mo_space.T, self._focka_ao, mo_space)) fb = reduce(numpy.dot, (mo_space.T, self._fockb_ao, mo_space)) feff = (fa + fb) * .5 feff[:ncore,ncore:nocc] = fb[:ncore,ncore:nocc] feff[ncore:nocc,:ncore] = fb[ncore:nocc,:ncore] feff[nocc:,ncore:nocc] = fa[nocc:,ncore:nocc] feff[ncore:nocc,nocc:] = fa[ncore:nocc,nocc:] cinv = numpy.dot(mo_space.T, s1e) f = reduce(numpy.dot, (cinv.T, feff, cinv)) if 0 <= cycle < diis_start_cycle-1: f = hf.damping(s1e, dm[0], f, damp_factor) if adiis and cycle >= diis_start_cycle: f = adiis.update(s1e, dm[0], f) f = hf.level_shift(s1e, dm[0], f, level_shift_factor) return f
def get_fock(mf, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): h1e_kpts, s_kpts, vhf_kpts, dm_kpts = h1e, s1e, vhf, dm if h1e_kpts is None: h1e_kpts = mf.get_hcore() if vhf_kpts is None: vhf_kpts = mf.get_veff(mf.cell, dm_kpts) focka = h1e_kpts + vhf_kpts[0] fockb = h1e_kpts + vhf_kpts[1] f_kpts = get_roothaan_fock((focka, fockb), dm, s1e) if cycle < 0 and diis is None: # Not inside the SCF iteration return f_kpts if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp if s_kpts is None: s_kpts = mf.get_ovlp() if dm_kpts is None: dm_kpts = mf.make_rdm1() dm_sf = dm_kpts[0] + dm_kpts[1] if 0 <= cycle < diis_start_cycle - 1 and abs(damp_factor) > 1e-4: raise NotImplementedError('ROHF Fock-damping') if diis and cycle >= diis_start_cycle: f_kpts = diis.update(s_kpts, dm_sf, f_kpts, mf, h1e_kpts, vhf_kpts) if abs(level_shift_factor) > 1e-4: f_kpts = [ mol_hf.level_shift(s, dm_sf[k] * .5, f_kpts[k], level_shift_factor) for k, s in enumerate(s_kpts) ] f_kpts = lib.tag_array(lib.asarray(f_kpts), focka=focka, fockb=fockb) return f_kpts
def get_fock(mf, h1e=None, s1e=None, vhf=None, dm=None, cycle=-1, diis=None, diis_start_cycle=None, level_shift_factor=None, damp_factor=None): '''Build fock matrix based on Roothaan's effective fock. See also :func:`get_roothaan_fock` ''' if h1e is None: h1e = mf.get_hcore() if s1e is None: s1e = mf.get_ovlp() if vhf is None: vhf = mf.get_veff(mf.mol, dm) if dm is None: dm = mf.make_rdm1() if isinstance(dm, numpy.ndarray) and dm.ndim == 2: dm = numpy.array((dm*.5, dm*.5)) # To Get orbital energy in get_occ, we saved alpha and beta fock, because # Roothaan effective Fock cannot provide correct orbital energy with `eig` # TODO, check other treatment J. Chem. Phys. 133, 141102 focka = h1e + vhf[0] fockb = h1e + vhf[1] f = get_roothaan_fock((focka,fockb), dm, s1e) if cycle < 0 and diis is None: # Not inside the SCF iteration return f if diis_start_cycle is None: diis_start_cycle = mf.diis_start_cycle if level_shift_factor is None: level_shift_factor = mf.level_shift if damp_factor is None: damp_factor = mf.damp dm_tot = dm[0] + dm[1] if 0 <= cycle < diis_start_cycle-1 and abs(damp_factor) > 1e-4: raise NotImplementedError('ROHF Fock-damping') if diis and cycle >= diis_start_cycle: f = diis.update(s1e, dm_tot, f, mf, h1e, vhf) if abs(level_shift_factor) > 1e-4: f = hf.level_shift(s1e, dm_tot*.5, f, level_shift_factor) f = lib.tag_array(f, focka=focka, fockb=fockb) return f