Beispiel #1
0
def uhf_fixed_occ(atoms,occa, occb,**opts):
    """\
    occa and occb represent the orbital occupation arrays for 
    the calculating spin orbitals with holes
    
    uhf(atoms,**opts) - Unrestriced Open Shell Hartree Fock
    atoms       A Molecule object containing the molecule

    Options:      Value   Description
    --------      -----   -----------
    ConvCriteria  1e-4    Convergence Criteria
    MaxIter       20      Maximum SCF iterations
    DoAveraging   True    Use DIIS averaging for convergence acceleration
    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
    orbs          None    If not None, the guess orbitals
    """

    from biorthogonal import biorthogonalize,pad_out

    ConvCriteria = opts.get('ConvCriteria',1e-5)
    MaxIter = opts.get('MaxIter',40)
    DoAveraging = opts.get('DoAveraging',True)
    averaging = opts.get('averaging',0.5)
    ETemp = opts.get('ETemp',False)
    
    bfs = opts.get('bfs',None)
    if not bfs:
        basis_data = opts.get('basis_data',None)
        bfs = getbasis(atoms,basis_data)

    integrals = opts.get('integrals', None)
    if integrals:
        S,h,Ints = integrals
    else:
        S,h,Ints = getints(bfs,atoms)

    nel = atoms.get_nel()

    nalpha,nbeta = atoms.get_alphabeta() #pass in opts for multiplicity
    S,h,Ints = getints(bfs,atoms)

    orbsa = opts.get('orbsa',None)
    orbsb = opts.get('orbsb',None)
    if (orbsa!=None and orbsb!=None):
        orbsa = orbsa
        orbsb = orbsb
    else:
        orbe,orbs = geigh(h,S)
        orbea = orbeb = orbe
        orbsa = orbsb = orbs
    
    #print "A Trial Orbital Energies:\n", orbea

    print "A Trial Orbitals:\n"
    pad_out(orbsa)

    #print "B Trial Orbital Energies:\n",orbeb

    print "B Trial Orbitals:\n"
    pad_out(orbsb)
    
    enuke = atoms.get_enuke()
    eold = 0.

    for i in xrange(MaxIter):
        print "SCF Iteration:",i,"Starting Energy:",eold
        #save the starting orbitals
        oldorbs_a=orbsa
        oldorbs_b=orbsb

        Da = mk_auger_dens(orbsa,occa)
        Db = mk_auger_dens(orbsb,occb)
        #Da_std = mkdens(orbsa,0,nalpha)
        #Db_std = mkdens(orbsb,0,nbeta)
        #pad_out(Da - Da_std ) #use to test mk_aug_dens with ground state occupations
        #pad_out(Db - Db_std )
        
        
        Ja = getJ(Ints,Da)
        Jb = getJ(Ints,Db)
        Ka = getK(Ints,Da)
        Kb = getK(Ints,Db)
        Fa = h+Ja+Jb-Ka
        Fb = h+Ja+Jb-Kb

        orbea,orbsa = geigh(Fa,S)
        orbeb,orbsb = geigh(Fb,S)
        
        #save the new orbitals
        neworbs_a=orbsa
        neworbs_b=orbsb
        
        #now we biorthogonalize the new orbitals to the old ones
        #to setup occupation arrays for the next scf cycle
        orbsa = biorthogonalize(neworbs_a,oldorbs_a,S,nalpha,occa)
        orbsb = biorthogonalize(neworbs_b,oldorbs_b,S,nbeta,occb)
        
        energya = get_energy(h,Fa,Da)
        energyb = get_energy(h,Fb,Db)
        energy = (energya+energyb)/2+enuke
        Dab = Da+Db
        Eone = trace2(Dab,h)
        Ej = 0.5*trace2(Dab,Ja+Jb)
        Ek = -0.5*(trace2(Da,Ka)+trace2(Db,Kb))
        
        #print "%d %f %f %f %f" % (i,energy,Eone,Ej,Ek)
        
        logging.debug("%d %f %f %f %f" % (i,energy,Eone,Ej,Ek))
        if abs(energy-eold) < ConvCriteria: break
        eold = energy
        if i==(MaxIter-1):
            print "Warning: Reached maximum number of SCF cycles may want to rerun calculation with more SCF cycles"
    logger.info("Final UHF energy for system %s is %f" % (atoms.name,energy))
    return energy,(orbea,orbeb),(orbsa,orbsb)
Beispiel #2
0
def uhf_fixed_occ(atoms, occa, occb, **kwargs):
    """\
    occa and occb represent the orbital occupation arrays for 
    the calculating spin orbitals with holes
    
    uhf(atoms,**kwargs) - Unrestriced Open Shell Hartree Fock
    atoms       A Molecule object containing the molecule

    Options:      Value   Description
    --------      -----   -----------
    ConvCriteria  1e-4    Convergence Criteria
    MaxIter       20      Maximum SCF iterations
    DoAveraging   True    Use DIIS averaging for convergence acceleration
    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
    orbs          None    If not None, the guess orbitals
    """

    from biorthogonal import biorthogonalize, pad_out

    ConvCriteria = kwargs.get('ConvCriteria', settings.ConvergenceCriteria)
    MaxIter = kwargs.get('MaxIter', settings.MaxIters)
    DoAveraging = kwargs.get('DoAveraging', settings.Averaging)
    averaging = kwargs.get('averaging', settings.MixingFraction)
    ETemp = kwargs.get('ETemp', settings.ElectronTemperature)

    bfs = getbasis(atoms, **kwargs)

    S, h, Ints = getints(bfs, atoms, **kwargs)

    nel = atoms.get_nel()

    nalpha, nbeta = atoms.get_alphabeta()  #pass in kwargs for multiplicity

    orbsa = kwargs.get('orbsa')
    orbsb = kwargs.get('orbsb')
    if (orbsa == None or orbsb == None):
        orbe, orbs = geigh(h, S)
        orbea = orbeb = orbe
        orbsa = orbsb = orbs

    #print "A Trial Orbital Energies:\n", orbea

    print "A Trial Orbitals:\n"
    pad_out(orbsa)

    #print "B Trial Orbital Energies:\n",orbeb

    print "B Trial Orbitals:\n"
    pad_out(orbsb)

    enuke = atoms.get_enuke()
    eold = 0.

    for i in xrange(MaxIter):
        print "SCF Iteration:", i, "Starting Energy:", eold
        #save the starting orbitals
        oldorbs_a = orbsa
        oldorbs_b = orbsb

        Da = mk_auger_dens(orbsa, occa)
        Db = mk_auger_dens(orbsb, occb)
        #Da_std = mkdens(orbsa,0,nalpha)
        #Db_std = mkdens(orbsb,0,nbeta)
        #pad_out(Da - Da_std ) #use to test mk_aug_dens with ground state occupations
        #pad_out(Db - Db_std )

        Ja = getJ(Ints, Da)
        Jb = getJ(Ints, Db)
        Ka = getK(Ints, Da)
        Kb = getK(Ints, Db)
        Fa = h + Ja + Jb - Ka
        Fb = h + Ja + Jb - Kb

        orbea, orbsa = geigh(Fa, S)
        orbeb, orbsb = geigh(Fb, S)

        #save the new orbitals
        neworbs_a = orbsa
        neworbs_b = orbsb

        #now we biorthogonalize the new orbitals to the old ones
        #to setup occupation arrays for the next scf cycle
        orbsa = biorthogonalize(neworbs_a, oldorbs_a, S, nalpha, occa)
        orbsb = biorthogonalize(neworbs_b, oldorbs_b, S, nbeta, occb)

        energya = get_energy(h, Fa, Da)
        energyb = get_energy(h, Fb, Db)
        energy = (energya + energyb) / 2 + enuke
        Dab = Da + Db
        Eone = trace2(Dab, h)
        Ej = 0.5 * trace2(Dab, Ja + Jb)
        Ek = -0.5 * (trace2(Da, Ka) + trace2(Db, Kb))

        #print "%d %f %f %f %f" % (i,energy,Eone,Ej,Ek)

        logging.debug("%d %f %f %f %f" % (i, energy, Eone, Ej, Ek))
        if abs(energy - eold) < ConvCriteria: break
        eold = energy
        if i == (MaxIter - 1):
            print "Warning: Reached maximum number of SCF cycles may want to rerun calculation with more SCF cycles"
    logger.info("Final UHF energy for system %s is %f" % (atoms.name, energy))
    return energy, (orbea, orbeb), (orbsa, orbsb)
Beispiel #3
0
def uhf(atoms,**opts):
    """\
    uhf(atoms,**opts) - Unrestriced Open Shell Hartree Fock
    atoms       A Molecule object containing the molecule

    Options:      Value   Description
    --------      -----   -----------
    ConvCriteria  1e-4    Convergence Criteria
    MaxIter       20      Maximum SCF iterations
    DoAveraging   True    Use DIIS averaging for convergence acceleration
    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
    orbs          None    If not None, the guess orbitals
    """
    ConvCriteria = opts.get('ConvCriteria',1e-5)
    MaxIter = opts.get('MaxIter',40)
    DoAveraging = opts.get('DoAveraging',True)
    averaging = opts.get('averaging',0.5)
    ETemp = opts.get('ETemp',False)
    verbose = opts.get('verbose',False)

    bfs = opts.get('bfs',None)
    if not bfs:
        basis_data = opts.get('basis_data',None)
        bfs = getbasis(atoms,basis_data)

    integrals = opts.get('integrals', None)
    if integrals:
        S,h,Ints = integrals
    else:
        S,h,Ints = getints(bfs,atoms)

    nel = atoms.get_nel()

    nalpha,nbeta = atoms.get_alphabeta() #pass in opts for multiplicity
    S,h,Ints = getints(bfs,atoms)

    orbs = opts.get('orbs',None)
    if orbs!=None:
        #orbsa = orbsb = orbs
        orbsa = orbs[0]
        orbsb = orbs[1]
    else:
        orbe,orbs = geigh(h,S)
        orbea = orbeb = orbe
        orbsa = orbsb = orbs

    enuke = atoms.get_enuke()
    eold = 0.

    logger.info("UHF calculation on %s" % atoms.name)
    logger.info("Nbf = %d" % len(bfs))
    logger.info("Nalpha = %d" % nalpha)
    logger.info("Nbeta = %d" % nbeta)
    logger.info("Averaging = %s" % DoAveraging)
    logging.debug("Optimization of HF orbitals")
    for i in xrange(MaxIter):
        if verbose: print "SCF Iteration:",i,"Starting Energy:",eold
        if ETemp:
            # We have to multiply nalpha and nbeta by 2
            #  to get the Fermi energies to come out correct:
            efermia = get_efermi(2.0*nalpha,orbea,ETemp)
            occsa = get_fermi_occs(efermia,orbea,ETemp)
            #print "occsa = ",occsa
            Da = mkdens_occs(orbsa,occsa)
            efermib = get_efermi(2.0*nbeta,orbeb,ETemp)
            occsb = get_fermi_occs(efermib,orbeb,ETemp)
            #print "occsb = ",occsb
            Db = mkdens_occs(orbsb,occsb)
            entropy = 0.5*(get_entropy(occsa,ETemp)+get_entropy(occsb,ETemp))
        else:
            Da = mkdens(orbsa,0,nalpha)
            Db = mkdens(orbsb,0,nbeta)
        if DoAveraging:
            if i: 
                Da = averaging*Da + (1-averaging)*Da0
                Db = averaging*Db + (1-averaging)*Db0
            Da0 = Da
            Db0 = Db

        Ja = getJ(Ints,Da)
        Jb = getJ(Ints,Db)
        Ka = getK(Ints,Da)
        Kb = getK(Ints,Db)
        Fa = h+Ja+Jb-Ka
        Fb = h+Ja+Jb-Kb
        orbea,orbsa = geigh(Fa,S)
        orbeb,orbsb = geigh(Fb,S)
        energya = get_energy(h,Fa,Da)
        energyb = get_energy(h,Fb,Db)
        energy = (energya+energyb)/2+enuke
        Dab = Da+Db
        Eone = trace2(Dab,h)
        Ej = 0.5*trace2(Dab,Ja+Jb)
        Ek = -0.5*(trace2(Da,Ka)+trace2(Db,Kb))
        if ETemp: energy += entropy
        logger.debug("%d %f %f %f %f" % (i,energy,Eone,Ej,Ek))
        if abs(energy-eold) < ConvCriteria: break
        eold = energy
    logger.info("Final UHF energy for system %s is %f" % (atoms.name,energy))
    return energy,(orbea,orbeb),(orbsa,orbsb)
Beispiel #4
0
def uhf(atoms, **kwargs):
    """\
    uhf(atoms,**kwargs) - Unrestriced Open Shell Hartree Fock
    atoms       A Molecule object containing the molecule

    Options:      Value   Description
    --------      -----   -----------
    ConvCriteria  1e-4    Convergence Criteria
    MaxIter       20      Maximum SCF iterations
    DoAveraging   True    Use DIIS averaging for convergence acceleration
    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
    orbs          None    If not None, the guess orbitals
    """
    ConvCriteria = kwargs.get('ConvCriteria', settings.ConvergenceCriteria)
    MaxIter = kwargs.get('MaxIter', settings.MaxIters)
    DoAveraging = kwargs.get('DoAveraging', settings.Averaging)
    averaging = kwargs.get('averaging', settings.MixingFraction)
    ETemp = kwargs.get('ETemp', settings.ElectronTemperature)
    verbose = kwargs.get('verbose')

    bfs = getbasis(atoms, **kwargs)

    S, h, Ints = getints(bfs, atoms, **kwargs)

    nel = atoms.get_nel()

    nalpha, nbeta = atoms.get_alphabeta()  #pass in kwargs for multiplicity

    orbs = kwargs.get('orbs')
    if orbs != None:
        #orbsa = orbsb = orbs
        orbsa = orbs[0]
        orbsb = orbs[1]
    else:
        orbe, orbs = geigh(h, S)
        orbea = orbeb = orbe
        orbsa = orbsb = orbs

    enuke = atoms.get_enuke()
    eold = 0.

    logger.info("UHF calculation on %s" % atoms.name)
    logger.info("Nbf = %d" % len(bfs))
    logger.info("Nalpha = %d" % nalpha)
    logger.info("Nbeta = %d" % nbeta)
    logger.info("Averaging = %s" % DoAveraging)
    logging.debug("Optimization of HF orbitals")
    for i in xrange(MaxIter):
        if verbose: print "SCF Iteration:", i, "Starting Energy:", eold
        if ETemp:
            # We have to multiply nalpha and nbeta by 2
            #  to get the Fermi energies to come out correct:
            efermia = get_efermi(2.0 * nalpha, orbea, ETemp)
            occsa = get_fermi_occs(efermia, orbea, ETemp)
            #print "occsa = ",occsa
            Da = mkdens_occs(orbsa, occsa)
            efermib = get_efermi(2.0 * nbeta, orbeb, ETemp)
            occsb = get_fermi_occs(efermib, orbeb, ETemp)
            #print "occsb = ",occsb
            Db = mkdens_occs(orbsb, occsb)
            entropy = 0.5 * (get_entropy(occsa, ETemp) +
                             get_entropy(occsb, ETemp))
        else:
            Da = mkdens(orbsa, 0, nalpha)
            Db = mkdens(orbsb, 0, nbeta)
        if DoAveraging:
            if i:
                Da = averaging * Da + (1 - averaging) * Da0
                Db = averaging * Db + (1 - averaging) * Db0
            Da0 = Da
            Db0 = Db

        Ja = getJ(Ints, Da)
        Jb = getJ(Ints, Db)
        Ka = getK(Ints, Da)
        Kb = getK(Ints, Db)
        Fa = h + Ja + Jb - Ka
        Fb = h + Ja + Jb - Kb
        orbea, orbsa = geigh(Fa, S)
        orbeb, orbsb = geigh(Fb, S)
        energya = get_energy(h, Fa, Da)
        energyb = get_energy(h, Fb, Db)
        energy = (energya + energyb) / 2 + enuke
        Dab = Da + Db
        Eone = trace2(Dab, h)
        Ej = 0.5 * trace2(Dab, Ja + Jb)
        Ek = -0.5 * (trace2(Da, Ka) + trace2(Db, Kb))
        if ETemp: energy += entropy
        logger.debug("%d %f %f %f %f" % (i, energy, Eone, Ej, Ek))
        if abs(energy - eold) < ConvCriteria: break
        eold = energy
    logger.info("Final UHF energy for system %s is %f" % (atoms.name, energy))
    return energy, (orbea, orbeb), (orbsa, orbsb)