Ejemplo n.º 1
0
 def setup_grid(self,molecule,bfs,**opts):
     from PyQuante.MolecularGrid import MolecularGrid
     grid_nrad = opts.get('grid_nrad',32)
     grid_fineness = opts.get('grid_fineness',1)
     self.gr = MolecularGrid(molecule,grid_nrad,grid_fineness,**opts) 
     self.gr.set_bf_amps(bfs)
     self.bfgrid = self.gr.allbfs() # bfs over all grid points
     return
Ejemplo n.º 2
0
def new_grid_tester():
    from PyQuante.TestMolecules import he,h2
    from PyQuante.MolecularGrid import MolecularGrid
    from PyQuante.Ints import getbasis
    from PyQuante import SCF
    mol = h2
    gr = MolecularGrid(mol,do_grad_dens=True)
    gr2 = MG2(mol,do_grad_dens=True)
    print "test_length: ",test_length(gr,gr2)
    print "test_distance: ",test_distance(gr,gr2)

    bfs = getbasis(mol)
    gr.set_bf_amps(bfs)
    gr2.add_basis(bfs)
    print "test_bfgrid: ",test_bfgrid(gr,gr2)

    # This is a little weird, but now use the hf density matrix to
    #  test whether the densities are the same
    hf = SCF(mol)
    hf.iterate()
    gr.setdens(hf.dmat)
    gr2.set_density(hf.dmat)
    print "test_density: ",test_density(gr,gr2)
    print "test_gamma: ",test_gamma(gr,gr2)
Ejemplo n.º 3
0
def new_grid_tester():
    from PyQuante.TestMolecules import he,h2
    from PyQuante.MolecularGrid import MolecularGrid
    from PyQuante.Ints import getbasis
    from PyQuante import SCF
    mol = h2
    gr = MolecularGrid(mol,do_grad_dens=True)
    gr2 = MG2(mol,do_grad_dens=True)
    print "test_length: ",test_length(gr,gr2)
    print "test_distance: ",test_distance(gr,gr2)

    bfs = getbasis(mol)
    gr.set_bf_amps(bfs)
    gr2.add_basis(bfs)
    print "test_bfgrid: ",test_bfgrid(gr,gr2)

    # This is a little weird, but now use the hf density matrix to
    #  test whether the densities are the same
    hf = SCF(mol)
    hf.iterate()
    gr.setdens(hf.dmat)
    gr2.set_density(hf.dmat)
    print "test_density: ",test_density(gr,gr2)
    print "test_gamma: ",test_gamma(gr,gr2)
Ejemplo n.º 4
0
class DFTHamiltonian(AbstractHamiltonian):
    method='DFT'
    def __init__(self,molecule,**opts):
        from PyQuante.DFunctionals import need_gradients
        self.molecule = molecule
        logging.info("DFT calculation on system %s" % self.molecule.name)
        self.basis_set = BasisSet(molecule,**opts)
        self.integrals = Integrals(molecule,self.basis_set,**opts)
        self.iterator = SCFIterator()
        self.h = self.integrals.get_h()
        self.S = self.integrals.get_S()
        self.ERI = self.integrals.get_ERI()
        self.Enuke = molecule.get_enuke()
        self.nel = molecule.get_nel()
        self.F = self.h
        self.functional = opts.get('functional','SVWN')
        opts['do_grad_dens'] = need_gradients[self.functional]
        self.setup_grid(molecule,self.basis_set.get(),**opts)
        self.dmat = None
        self.entropy = None
        nel = molecule.get_nel()
        nclosed,nopen = molecule.get_closedopen()
        logging.info("Nclosed/open = %d, %d" % (nclosed,nopen))
        self.solver = SolverFactory(nel,nclosed,nopen,self.S,**opts)
        return
        
    def __repr__(self):
        lstr = ['Hamiltonian constructed for method %s' % self.method,
                repr(self.molecule),
                repr(self.basis_set),
                repr(self.iterator)]
        return '\n'.join(lstr)

    def get_energy(self): return self.energy
    def iterate(self,**opts): return self.iterator.iterate(self,**opts)

    def setup_grid(self,molecule,bfs,**opts):
        from PyQuante.MolecularGrid import MolecularGrid
        grid_nrad = opts.get('grid_nrad',32)
        grid_fineness = opts.get('grid_fineness',1)
        self.gr = MolecularGrid(molecule,grid_nrad,grid_fineness,**opts) 
        self.gr.set_bf_amps(bfs)
        self.bfgrid = self.gr.allbfs() # bfs over all grid points
        return

    def update(self,**opts):
        from PyQuante.LA2 import trace2
        from PyQuante.Ints import getJ
        from PyQuante.dft import getXC

        self.dmat,self.entropy = self.solver.solve(self.F,**opts)
        D = self.dmat
        
        self.gr.setdens(D)
        self.J = getJ(self.ERI,D)
        self.Ej = 2*trace2(D,self.J)

        self.Exc,self.XC = getXC(self.gr,self.nel,self.bfgrid,
                                 functional=self.functional)

        self.Eone = 2*trace2(D,self.h)

        self.F = self.h+2*self.J+self.XC
        self.energy = self.Eone + self.Ej + self.Exc + self.Enuke + self.entropy
        return