Пример #1
0
def test():
    from Ints import getbasis, getints, get2JmK
    from hartree_fock import get_nel, get_enuke, get_energy
    from LA2 import geigh, mkdens
    from IO import mtx2file
    from Molecule import Molecule

    ConvCriteria = 0.00001
    MaxIt = 30
    h2o = Molecule("h2o", [(8, (0, 0, 0)), (1, (1.0, 0, 0)), (1, (0, 1.0, 0))], units="Angstrom")
    bfs = getbasis(h2o)
    S, h, Ints = getints(bfs, h2o)
    orbe, orbs = geigh(h, S)
    nel = get_nel(h2o)
    nocc = int(nel / 2)
    enuke = get_enuke(h2o)
    eold = 0.0
    avg = DIIS2(S)
    for i in range(30):
        D = mkdens(orbs, 0, nocc)
        mtx2file(D)
        G = get2JmK(Ints, D)
        F = h + G
        F = avg.getF(F, D)  # do the DIIS extrapolation
        orbe, orbs = geigh(F, S)
        energy = get_energy(h, F, D, enuke)
        print i + 1, energy
        if abs(energy - eold) < ConvCriteria:
            break
        eold = energy

    return
Пример #2
0
def test():
    from Ints import getbasis, getints, get2JmK
    from hartree_fock import get_nel, get_enuke, get_energy
    from LA2 import geigh, mkdens
    from IO import mtx2file
    from Molecule import Molecule

    ConvCriteria = 0.00001
    MaxIt = 30
    h2o = Molecule('h2o', [(8, (0, 0, 0)), (1, (1., 0, 0)), (1, (0, 1., 0))],
                   units='Angstrom')
    bfs = getbasis(h2o)
    S, h, Ints = getints(bfs, h2o)
    orbe, orbs = geigh(h, S)
    nel = get_nel(h2o)
    nocc = int(nel / 2)
    enuke = get_enuke(h2o)
    eold = 0.
    avg = DIIS2(S)
    for i in xrange(30):
        D = mkdens(orbs, 0, nocc)
        mtx2file(D)
        G = get2JmK(Ints, D)
        F = h + G
        F = avg.getF(F, D)  # do the DIIS extrapolation
        orbe, orbs = geigh(F, S)
        energy = get_energy(h, F, D, enuke)
        print i + 1, energy
        if abs(energy - eold) < ConvCriteria: break
        eold = energy

    return
Пример #3
0
def rhf(atoms,**opts):
    """\
    rhf(atoms,**opts) - Closed-shell HF driving routine
    
    atoms       A Molecule object containing the molecule

    Options:      Value   Description
    --------      -----   -----------
    ConvCriteria  1e-4    Convergence Criteria
    MaxIter       20      Maximum SCF iterations
    DoAveraging   True    Use DIIS for accelerated convergence (default)
                  False   No convergence acceleration
    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
    orbs          None    If not none, the guess orbitals
    """
    ConvCriteria = opts.get('ConvCriteria',1e-10)
    MaxIter = opts.get('MaxIter',20)
    DoAveraging = opts.get('DoAveraging',False)
    ETemp = opts.get('ETemp',False)
    
    logger.info("RHF calculation on %s" % atoms.name)

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

    nclosed,nopen = atoms.get_closedopen()
    nocc = nclosed
    assert(nopen == 0), "SCF currently only works for closed-shell systems"
    
    logger.info("Nbf = %d" % len(bfs))
    logger.info("Nclosed = %d" % nclosed)

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

    nel = atoms.get_nel()

    orbs = opts.get('orbs',None)
    if orbs is None: orbe,orbs = geigh(h,S)

    enuke = atoms.get_enuke()
    eold = 0.

    
    if DoAveraging:
        logger.info("Using DIIS averaging")
        avg = DIIS(S)
    logging.debug("Optimization of HF orbitals")
    for i in xrange(MaxIter):
        if ETemp:
            efermi = get_efermi(nel,orbe,ETemp)
            occs = get_fermi_occs(efermi,orbe,ETemp)
            D = mkdens_occs(orbs,occs)
            entropy = get_entropy(occs,ETemp)
        else:
            D = mkdens(orbs,0,nocc)
        G = get2JmK(Ints,D)
        F = h+G
        if DoAveraging: F = avg.getF(F,D)
        orbe,orbs = geigh(F,S)
        energy = get_energy(h,F,D,enuke)
        if ETemp:
            energy += entropy
        logging.debug("%d %f" % (i,energy))
        if abs(energy-eold) < ConvCriteria: break
        logger.info("Iteration: %d    Energy: %f    EnergyVar: %f"%(i,energy,abs(energy-eold)))
        eold = energy
    if i < MaxIter:
        logger.info("PyQuante converged in %d iterations" % i)
    else:
        logger.warning("PyQuante failed to converge after %d iterations"
                            % MaxIter)
    logger.info("Final HF energy for system %s is %f" % (atoms.name,energy))
    return energy,orbe,orbs
Пример #4
0
def get_fock(D,Ints,h):
    "Return the HF Fock matrix"
    return h + get2JmK(Ints,D)
Пример #5
0
def rhf(atoms, **kwargs):
    """\
    rhf(atoms,**kwargs) - Closed-shell HF driving routine
    
    atoms       A Molecule object containing the molecule

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

    logger.info("RHF calculation on %s" % atoms.name)

    bfs = getbasis(atoms, **kwargs)

    nclosed, nopen = atoms.get_closedopen()
    nocc = nclosed
    assert (nopen == 0), "SCF currently only works for closed-shell systems"

    logger.info("Nbf = %d" % len(bfs))
    logger.info("Nclosed = %d" % nclosed)

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

    orbs = kwargs.get('orbs')
    if orbs is None: orbe, orbs = geigh(h, S)

    enuke = atoms.get_enuke()
    eold = 0.

    if DoAveraging:
        logger.info("Using DIIS averaging")
        avg = DIIS(S)
    logging.debug("Optimization of HF orbitals")
    for i in xrange(MaxIter):
        if ETemp:
            efermi = get_efermi(nel, orbe, ETemp)
            occs = get_fermi_occs(efermi, orbe, ETemp)
            D = mkdens_occs(orbs, occs)
            entropy = get_entropy(occs, ETemp)
        else:
            D = mkdens(orbs, 0, nocc)
        G = get2JmK(Ints, D)
        F = h + G
        if DoAveraging: F = avg.getF(F, D)
        orbe, orbs = geigh(F, S)
        energy = get_energy(h, F, D, enuke)
        if ETemp:
            energy += entropy
        logging.debug("%d %f" % (i, energy))
        if abs(energy - eold) < ConvCriteria: break
        logger.info("Iteration: %d    Energy: %f    EnergyVar: %f" %
                    (i, energy, abs(energy - eold)))
        eold = energy
    if i < MaxIter:
        logger.info("PyQuante converged in %d iterations" % i)
    else:
        logger.warning("PyQuante failed to converge after %d iterations" %
                       MaxIter)
    logger.info("Final HF energy for system %s is %f" % (atoms.name, energy))
    return energy, orbe, orbs
Пример #6
0
def get_fock(D, Ints, h):
    "Return the HF Fock matrix"
    return h + get2JmK(Ints, D)