def iterate(self,**opts): self.iter = 0 self.etemp = opts.get("etemp",False) logging.debug("iter Energy <b|b>") logging.debug("---- ------ -----") self.b = fminBFGS(self.get_energy,self.b,self.get_gradient,logger=logging) return
def iterate(self,**kwargs): self.iter = 0 self.etemp = kwargs.get("etemp",settings.DFTElectronTemperature) logging.debug("iter Energy <b|b>") logging.debug("---- ------ -----") self.b = fminBFGS(self.get_energy,self.b,self.get_gradient,logger=logging) return
def iterate(self, **opts): self.iter = 0 self.etemp = opts.get("etemp", False) logging.debug("iter Energy <b|b>") logging.debug("---- ------ -----") self.b = fminBFGS(self.get_energy, self.b, self.get_gradient, logger=logging) return
def iterate(self, **kwargs): self.iter = 0 self.etemp = kwargs.get("etemp", settings.DFTElectronTemperature) logging.debug("iter Energy <b|b>") logging.debug("---- ------ -----") self.b = fminBFGS(self.get_energy, self.b, self.get_gradient, logger=logging) return
def opt(atoms,**kwargs): from PyQuante.optimize import fminBFGS c0,Efunc,Ffunc = energy_forces_factories(atoms,**kwargs) print "C0 = ",c0 # Currently optimization works when I use Energies and numerical # forces, but not using the analytical forces. Obviously something # is wrong somewhere here, but I don't have time to fix this now. # Hopefully the final fix won't be too hard. copt = fminBFGS(Efunc,c0,Ffunc,avegtol=1e-4) #copt = fminBFGS(Efunc,c0,None,avegtol=1e-4) Efinal = Efunc(copt) return Efinal,copt
def oep(atoms,orbs,energy_func,grad_func=None,**opts): """oep - Form the optimized effective potential for a given energy expression oep(atoms,orbs,energy_func,grad_func=None,**opts) atoms A Molecule object containing a list of the atoms orbs A matrix of guess orbitals energy_func The function that returns the energy for the given method grad_func The function that returns the force for the given method Options ------- verbose False Output terse information to stdout (default) True Print out additional information ETemp False Use ETemp value for finite temperature DFT (default) float Use (float) for the electron temperature bfs None The basis functions to use. List of CGBF's basis_data None The basis data to use to construct bfs integrals None The one- and two-electron integrals to use If not None, S,h,Ints """ verbose = opts.get('verbose',False) ETemp = opts.get('ETemp',False) opt_method = opts.get('opt_method','BFGS') bfs = opts.get('bfs',None) if not bfs: basis = opts.get('basis',None) bfs = getbasis(atoms,basis) # The basis set for the potential can be set different from # that used for the wave function pbfs = opts.get('pbfs',None) if not pbfs: pbfs = bfs npbf = len(pbfs) integrals = opts.get('integrals',None) if integrals: S,h,Ints = integrals else: S,h,Ints = getints(bfs,atoms) nel = atoms.get_nel() nocc,nopen = atoms.get_closedopen() Enuke = atoms.get_enuke() # Form the OEP using Yang/Wu, PRL 89 143002 (2002) nbf = len(bfs) norb = nbf bp = zeros(nbf,'d') bvec = opts.get('bvec',None) if bvec: assert len(bvec) == npbf b = array(bvec) else: b = zeros(npbf,'d') # Form and store all of the three-center integrals # we're going to need. # These are <ibf|gbf|jbf> (where 'bf' indicates basis func, # as opposed to MO) # N^3 storage -- obviously you don't want to do this for # very large systems Gij = [] for g in range(npbf): gmat = zeros((nbf,nbf),'d') Gij.append(gmat) gbf = pbfs[g] for i in range(nbf): ibf = bfs[i] for j in range(i+1): jbf = bfs[j] gij = three_center(ibf,gbf,jbf) gmat[i,j] = gij gmat[j,i] = gij # Compute the Fermi-Amaldi potential based on the LDA density. # We're going to form this matrix from the Coulombic matrix that # arises from the input orbitals. D0 and J0 refer to the density # matrix and corresponding Coulomb matrix D0 = mkdens(orbs,0,nocc) J0 = getJ(Ints,D0) Vfa = (2*(nel-1.)/nel)*J0 H0 = h + Vfa b = fminBFGS(energy_func,b,grad_func, (nbf,nel,nocc,ETemp,Enuke,S,h,Ints,H0,Gij), logger=logging) energy,orbe,orbs = energy_func(b,nbf,nel,nocc,ETemp,Enuke, S,h,Ints,H0,Gij,return_flag=1) return energy,orbe,orbs
def oep(atoms, orbs, energy_func, grad_func=None, **opts): """oep - Form the optimized effective potential for a given energy expression oep(atoms,orbs,energy_func,grad_func=None,**opts) atoms A Molecule object containing a list of the atoms orbs A matrix of guess orbitals energy_func The function that returns the energy for the given method grad_func The function that returns the force for the given method Options ------- verbose False Output terse information to stdout (default) True Print out additional information ETemp False Use ETemp value for finite temperature DFT (default) float Use (float) for the electron temperature bfs None The basis functions to use. List of CGBF's basis_data None The basis data to use to construct bfs integrals None The one- and two-electron integrals to use If not None, S,h,Ints """ verbose = opts.get('verbose', False) ETemp = opts.get('ETemp', False) opt_method = opts.get('opt_method', 'BFGS') bfs = opts.get('bfs', None) if not bfs: basis = opts.get('basis', None) bfs = getbasis(atoms, basis) # The basis set for the potential can be set different from # that used for the wave function pbfs = opts.get('pbfs', None) if not pbfs: pbfs = bfs npbf = len(pbfs) integrals = opts.get('integrals', None) if integrals: S, h, Ints = integrals else: S, h, Ints = getints(bfs, atoms) nel = atoms.get_nel() nocc, nopen = atoms.get_closedopen() Enuke = atoms.get_enuke() # Form the OEP using Yang/Wu, PRL 89 143002 (2002) nbf = len(bfs) norb = nbf bp = zeros(nbf, 'd') bvec = opts.get('bvec', None) if bvec: assert len(bvec) == npbf b = array(bvec) else: b = zeros(npbf, 'd') # Form and store all of the three-center integrals # we're going to need. # These are <ibf|gbf|jbf> (where 'bf' indicates basis func, # as opposed to MO) # N^3 storage -- obviously you don't want to do this for # very large systems Gij = [] for g in xrange(npbf): gmat = zeros((nbf, nbf), 'd') Gij.append(gmat) gbf = pbfs[g] for i in xrange(nbf): ibf = bfs[i] for j in xrange(i + 1): jbf = bfs[j] gij = three_center(ibf, gbf, jbf) gmat[i, j] = gij gmat[j, i] = gij # Compute the Fermi-Amaldi potential based on the LDA density. # We're going to form this matrix from the Coulombic matrix that # arises from the input orbitals. D0 and J0 refer to the density # matrix and corresponding Coulomb matrix D0 = mkdens(orbs, 0, nocc) J0 = getJ(Ints, D0) Vfa = (2 * (nel - 1.) / nel) * J0 H0 = h + Vfa b = fminBFGS(energy_func, b, grad_func, (nbf, nel, nocc, ETemp, Enuke, S, h, Ints, H0, Gij), logger=logging) energy, orbe, orbs = energy_func(b, nbf, nel, nocc, ETemp, Enuke, S, h, Ints, H0, Gij, return_flag=1) return energy, orbe, orbs