def _energy_gradss(self,argnum,max_scf=301,max_d=300,printguess=None,name='Output.molden',output=False,order='first'): """This function returns the gradient of args""" ## For the moment it retuns a value at a time ## This is used only by testing functions. eigen = True rguess = False args=[np.log(self.sys.alpha),self.sys.coef,self.sys.xyz,self.sys.l,self.sys.charges,self.sys.atom,self.sys.natoms,self.sys.nbasis, self.sys.list_contr,self.sys.ne, max_scf,max_d,log,eigen,None,None, name,output,self.sys.alpha] # Last term is only used for Algopy if self.verbose: self.tape.write(' \n Grad point ...\n') self.tape.write(' ---Start--- \n') self.tape.write(' Initial parameters \n') self.tape.write(' Maximum number of SCF: %d\n'%max_scf) self.tape.write(' Default SCF tolerance: %f\n'%1e-8) self.tape.write(' Initial density matrix: %s\n'%str(rguess)) self.sys.printcurrentgeombasis(self.tape) grad_fun =[] for i in argnum: var = UTPM.init_jacobian(args[i]) diff_args = list(args) # We are making a copy of args diff_args[i] = var diff_args[-1]= var t0 = time.clock() grad = UTPM.extract_jacobian(rhfenergy(*(diff_args))) timer = time.clock() - t0 self.sys.grad = grad self.tape.write(' ---End--- \n') self.tape.write(' Time %3.7f :\n'%timer) return grad
def algo_jaco(*args, **kwargs): var = UTPM.init_hessian(args[narg]) diff_args = list(args) # We are making a copy of args diff_args[narg] = var diff_args[-1]= var diff_args = tuple(diff_args) return UTPM.extract_hessian(rhfenergy(*(diff_args)))
def _singlepoint(self,max_scf=300,max_d=300,printcoef=False,name='Output.molden',output=False): """ This function calculates a single point energy max_scf -> Maximum number of SCF cycles max_d -> Maximum cycles of iterations if cannonical purification """ log = True # We are not using logarithms of alphas eigen = True # We are using diagonalizations readguess = False #By now, we are stating the densisty matrix from scratch rguess = None if printcoef: pguess = name+'.npy' else: pguess = None args=[np.log(self.sys.alpha),self.sys.coef,self.sys.xyz,self.sys.l,self.sys.charges,self.sys.atom,self.sys.natoms,self.sys.nbasis, self.sys.list_contr,self.sys.ne, max_scf,max_d,log,eigen,pguess,rguess, name,output,self.sys.alpha] # Last term is only used for Algopy if self.verbose: self.tape.write(' \n Single point ...\n') self.tape.write(' ---Start--- \n') self.tape.write(' Initial parameters \n') self.tape.write(' Maximum number of SCF: %d\n'%max_scf) self.tape.write(' Default SCF tolerance: %f\n'%1e-8) self.tape.write(' Initial density matrix: %s\n'%str(rguess)) self.sys.printcurrentgeombasis(self.tape) # Function t0 = time.clock() ene = rhfenergy(*(args)) timer = time.clock() - t0 self.energy = ene if self.verbose: self.tape.write(' ---End--- \n') self.tape.write(' Time %3.7f :\n'%timer) if (ene == 99999): if self.verbose: self.tape.write(' SCF did not converged :( !!\n') print(' SCF did not converged :( !! %s\n') self.status = False else: if self.verbose: self.tape.write(' SCF converged!!\n') self.tape.write(' Energy: %3.7f \n'%ene) if pguess != None: self.tape.write(' Coefficients in file: %s\n'%pguess) print(' SCF converged!!') print(' Energy: %3.7f'%ene) if output: if self.verbose: self.tape.write(' Result in file: %s\n'%name) else: print(' Result in file: %s\n'%name) return ene
def _singlepoint(self, max_scf=300, max_d=300, printcoef=False, name='Output.molden', output=False): """ This function calculates a single point energy max_scf -> Maximum number of SCF cycles max_d -> Maximum cycles of iterations if cannonical purification """ log = True # We are not using logarithms of alphas eigen = True # We are using diagonalizations rguess = None if printcoef: pguess = name + '.npy' else: pguess = None if self.verbose: self._print_head_energy(max_scf, rguess) t0 = time.clock() args = self._energy_args(max_scf=max_scf, max_d=max_d, log=True, printguess=pguess, readguess=rguess, name=name, write=output) # Function ene = rhfenergy(*(args)) if (ene == 99999): self.status = False print(' SCF did not converged :( !! %s\n') else: print(' SCF converged!!') print(' Energy: %3.7f' % ene) print(' Result in file: %s\n' % name) self.energy = ene if self.verbose: timer = time.clock() - t0 self._print_tail_energy(timer, ene, pguess, output=output, name=name) return ene