Ejemplo n.º 1
0
def test():
    from Ints import getbasis, getints
    from hartree_fock import rhf
    from Molecule import Molecule

    # Make a test molecule for the calculation
    h2 = Molecule('h2', [(1, (1., 0, 0)), (1, (-1., 0, 0))])

    # Get a basis set and compute the integrals.
    # normally the routine will do this automatically, but we
    # do it explicitly here so that we can pass the same set
    # of integrals into the CI code and thus not recompute them.
    bfs = getbasis(h2)
    S, h, Ints = getints(bfs, h2)

    # Compute the HF wave function for our molecule
    en, orbe, orbs = rhf(h2, integrals=(S, h, Ints))
    print "SCF completed, E = ", en
    print " orbital energies ", orbe

    # Compute the occupied and unoccupied orbitals, used in the
    # CIS program to generate the excitations
    nclosed, nopen = h2.get_closedopen()
    nbf = len(bfs)
    nocc = nclosed + nopen
    nvirt = nbf - nocc

    # Call the CI program:
    Ecis = CIS(Ints, orbs, orbe, nocc, nvirt, en)
    print "Ecis = ", Ecis
Ejemplo n.º 2
0
def test():
    from hartree_fock import rhf
    from Molecule import Molecule

    # Make a test molecule for the calculation
    h2 = Molecule('h2',[(1,(1.,0,0)),(1,(-1.,0,0))])

    # Get a basis set and compute the integrals.
    # normally the routine will do this automatically, but we
    # do it explicitly here so that we can pass the same set
    # of integrals into the CI code and thus not recompute them.
    bfs = getbasis(h2)
    S,h,Ints = getints(bfs,h2)

    # Compute the HF wave function for our molecule
    en,orbe,orbs = rhf(h2,
                       integrals=(S,h,Ints)
                       )
    print "SCF completed, E = ",en
    print " orbital energies ",orbe

    # Compute the occupied and unoccupied orbitals, used in the
    # CIS program to generate the excitations
    nclosed,nopen = h2.get_closedopen()
    nbf = len(bfs)
    nocc = nclosed+nopen
    nvirt = nbf-nocc

    # Call the CI program:
    Ecis = CIS(Ints,orbs,orbe,nocc,nvirt,en)
    print "Ecis = ",Ecis
Ejemplo n.º 3
0
def rhf_dyn(atoms, **kwargs):
    """\
    Uses RHF derived forces to compute dynamics.  
    
    Options:      Value   Description
    --------      -----   -----------
    job           pydyn   Descriptive job name
    nsteps        100     number of dynamics steps to take
    dt            0.1     time step size in picoseconds
                          units matter! we assume atom positions are 
                          stored in bohrs, velocities are in bohr/ps,
                          acceleration is in bohr/ps^2
                          and forces are in hartree/bohr
    
    
    Hartree-Fock options copied from hartree_fock.py -> rhf
    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
    """
    #dynamics options
    job = kwargs.get('job', settings.DynJob)
    nsteps = kwargs.get('nsteps', settings.DynSteps)
    dt = kwargs.get('dt', settings.DynTStep)

    #save any given RHF options
    cc = kwargs.get('ConvCriteria', settings.ConvergenceCriteria)
    maxit = kwargs.get('MaxIter', settings.MaxIters)
    doavg = kwargs.get('DoAveraging', settings.Averaging)
    temp = kwargs.get('ETemp', settings.ElectronTemperature)
    bfcns = kwargs.get('bfs')
    if not bfcns:
        bdat = kwargs.get('basis_data')
    ints = kwargs.get('integrals')
    init_orbs = kwargs.get('orbs')

    #open data file to store energy info
    edat = open(job + '.edat', 'w')
    edat.write("#Step       Time    PE  KE  TE\n")

    #open trajectory file to store xyz info
    xyz = open(job + '.xyz', 'w')
    #xyz.write("#RHF molecular dynamics done by PyQuante\n")
    #xyz.write("#job: %s  nsteps: %d  dt:%f\n"%(job,nsteps,dt))
    xyz.write(xyz_str(atoms))
    t = 0.
    for n in xrange(nsteps):
        t += n * dt
        pe,orben,coefs = rhf(atoms,ConvCriteria=cc,MaxIter=maxit,\
                           DoAveraging=doavg,ETemp=temp,bfs=bfcns,\
                           basis_data=bdat,integrals=ints,orbs=init_orbs)

        ncl, nop = atoms.get_closedopen()

        wf = Wavefunction(orbs=coefs,
                          orbe=orben,
                          restricted=True,
                          nclosed=ncl,
                          nopen=nop)
        hf_force(atoms, wf, bdat)

        ke = leapfrog(atoms, t, dt)
        te = ke + pe
        bl = atoms[0].dist(atoms[1])
        edat.write('%d      %f	%f      %f      %f  %f\n' %
                   (n, t, bl, pe, ke, te))
        xyz.write(xyz_str(atoms))

    edat.close()
    xyz.close()

    return
Ejemplo n.º 4
0
def RHFEnergyFunction(atomlist,**kwargs):
    from hartree_fock import rhf
    return rhf(atomlist,**kwargs)[0]
Ejemplo n.º 5
0
def rhf_dyn(atoms,**kwargs):
    """\
    Uses RHF derived forces to compute dynamics.  
    
    Options:      Value   Description
    --------      -----   -----------
    job           pydyn   Descriptive job name
    nsteps        100     number of dynamics steps to take
    dt            0.1     time step size in picoseconds
                          units matter! we assume atom positions are 
                          stored in bohrs, velocities are in bohr/ps,
                          acceleration is in bohr/ps^2
                          and forces are in hartree/bohr
    
    
    Hartree-Fock options copied from hartree_fock.py -> rhf
    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
    """
    #dynamics options
    job = kwargs.get('job',settings.DynJob)
    nsteps = kwargs.get('nsteps',settings.DynSteps)
    dt = kwargs.get('dt',settings.DynTStep)
    
    #save any given RHF options
    cc = kwargs.get('ConvCriteria',settings.ConvergenceCriteria)
    maxit = kwargs.get('MaxIter',settings.MaxIters)
    doavg = kwargs.get('DoAveraging',settings.Averaging)
    temp = kwargs.get('ETemp',settings.ElectronTemperature)
    bfcns = kwargs.get('bfs')
    if not bfcns:
        bdat = kwargs.get('basis_data')
    ints = kwargs.get('integrals')
    init_orbs = kwargs.get('orbs')
    
    #open data file to store energy info 
    edat = open(job+'.edat', 'w')
    edat.write("#Step       Time    PE  KE  TE\n")
    
    #open trajectory file to store xyz info
    xyz = open(job+'.xyz', 'w')
    #xyz.write("#RHF molecular dynamics done by PyQuante\n")
    #xyz.write("#job: %s  nsteps: %d  dt:%f\n"%(job,nsteps,dt))
    xyz.write(xyz_str(atoms))
    t=0.
    for n in xrange(nsteps):
        t+=n*dt
        pe,orben,coefs = rhf(atoms,ConvCriteria=cc,MaxIter=maxit,\
                           DoAveraging=doavg,ETemp=temp,bfs=bfcns,\
                           basis_data=bdat,integrals=ints,orbs=init_orbs)

        ncl,nop = atoms.get_closedopen()

        wf = Wavefunction(orbs=coefs,orbe=orben,restricted=True,nclosed=ncl,nopen=nop)
        hf_force(atoms,wf,bdat)
        
        ke = leapfrog(atoms,t,dt)
        te = ke+pe
        bl = atoms[0].dist(atoms[1])
        edat.write('%d      %f	%f      %f      %f  %f\n' %(n,t,bl,pe,ke,te))
        xyz.write(xyz_str(atoms))

    edat.close()
    xyz.close()

    return 
Ejemplo n.º 6
0
import numpy as np
import psi4
import sys
sys.path.insert(0, '../../3/misiewicz')
import hartree_fock
sys.path.insert(0, '../../6/misiewicz')
import utility

def mp2(C, evals, int_tensor, nocc):
    dim = C.shape[0]
    nvir = dim - nocc
    C_occ = C[:,:nocc].conjugate() # Grab the columns for occupied orbitals.
    C_vir = C[:,nocc:] # Grab the columns for virtual orbitals.
    aint = utility.tensor_basis_transform(int_tensor, C_occ, C_vir)
    e = 0
    for i, j, a, b in itertools.product(range(nocc), range(nocc), range(nvir), range(nvir)):
        e += aint[i,j,a,b] * (
        	np.conjugate(2 * aint[i,j,a,b] - aint[i,j,b,a])) / (
        	evals[i] + evals[j] - evals[nocc+a] - evals[nocc+b])
    
    return e

if __name__ == "__main__":
    psi4.set_memory('500 MB')
    h2o = psi4.geometry("""
O
H 1 0.96
H 1 0.96 2 104.5
""")
    hf_data = hartree_fock.rhf(h2o)[2:] # Throw away first two data points...
    print(mp2(*hf_data))