def generate_data(): mol = Molecule.from_file("eth.cml") scf = SCF(mol, basis="sto3g") scf.iterate() shelf = open_shelf() shelf["scf"] = scf shelf.close()
def generate_data(): mol = Molecule.from_file("eth.cml") scf = SCF(mol, basis="sto3g") scf.iterate() shelf = open_shelf() shelf["scf"]=scf shelf.close()
def test_fci(): """ test FCI calculation""" from Molecule import Molecule from PyQuante import SCF nel = 2 mult = 1 m_s = 0 k=10 # h2 = Molecule('h2',[(1,(0,0,0)),(1,(1.4,0,0))], multiplicity = mult) h2 = Molecule('h2',[(1,(0,0,0)),(1,(1.4,0,0))]) Solver = SCF(h2,method = "HF") Solver.iterate() print "orbital energies ",Solver.solver.orbe print "HF energy = ",Solver.energy # FCIInst = FCISolver(Solver.h, Solver.ERI, Solver.solver.orbs, nel, mult, m_s, k=k, sigma_eigs=None) # eva, eve = FCIInst.iterate() FCIInst = FCIExactSolver(Solver.h, Solver.ERI, h2.get_enuke(), Solver.solver.orbs, nel, mult, m_s) eva,eve = FCIInst.diagonalize() print "eva = ", eva # print "eve = ",eve print "correlation energy = ", eva[0] - Solver.energy print "correlation energy should be (with 6-31g**) -0.03387 a.u."
def pyquante_hf(mol, x, eps, basis = "sto-3g"): atoms = [None]*mol.num_atoms for i in xrange(mol.num_atoms): atoms[i] = (mol.atoms[i].charge, (mol.atoms[i].rad[0],mol.atoms[i].rad[1],mol.atoms[i].rad[2])) mol_pq = Molecule(mol.name, atoms, units='Bohr') solver = SCF(mol_pq,method="HF",ConvCriteria=1e-7,MaxIter=40,basis=basis) print 'SCF iteration - done' solver.iterate() norb=int(solver.solver.nclosed) w=solver.basis_set.get() cf=solver.solver.orbs[:,0:norb] psi = [None]*norb for i in xrange(norb): psi[i] = gto2tuck(w,cf[:,i],x) print psi[i].r psi[i] = local(psi[i],1e-14) psi[i] = tuck.round(psi[i],eps) print psi[i].r E = solver.solver.orbe[:norb] return psi,E
def test_fci(): """ test FCI calculation""" from Molecule import Molecule from PyQuante import SCF nel = 2 mult = 1 m_s = 0 k = 10 # h2 = Molecule('h2',[(1,(0,0,0)),(1,(1.4,0,0))], multiplicity = mult) h2 = Molecule('h2', [(1, (0, 0, 0)), (1, (1.4, 0, 0))]) Solver = SCF(h2, method="HF") Solver.iterate() print "orbital energies ", Solver.solver.orbe print "HF energy = ", Solver.energy # FCIInst = FCISolver(Solver.h, Solver.ERI, Solver.solver.orbs, nel, mult, m_s, k=k, sigma_eigs=None) # eva, eve = FCIInst.iterate() FCIInst = FCIExactSolver(Solver.h, Solver.ERI, h2.get_enuke(), Solver.solver.orbs, nel, mult, m_s) eva, eve = FCIInst.diagonalize() print "eva = ", eva # print "eve = ",eve print "correlation energy = ", eva[0] - Solver.energy print "correlation energy should be (with 6-31g**) -0.03387 a.u."
def calculate(self, verbose=False): from PyQuante import SCF, Molecule if verbose: logging.basicConfig(level=logging.DEBUG) pyquante_atoms = [] for a in self._atoms: pyquante_atoms.append( (a.number, a.position) ) m = Molecule('molecule', pyquante_atoms) lda = SCF(m, method="DFT") lda.iterate() result = { "total_energy": lda.energy, "orbital_energies": lda.solver.orbe, } return result
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)
def Edot(method='ROHF'): O = Molecule('O', atomlist=[('O', (0, 0, 0))], multiplicity=3) job = SCF(O, method=method, basis='6-31G**') job.iterate() return job.energy
from PyQuante.Molecule import Molecule from PyQuante import SCF #Intializing the molecules H2 = Molecule('H2', [(1, (0, 0, 0)), (1, (1.4, 0, 0))]) OHmin = Molecule('OHmin', [(8, (0., 0., -0.08687037)), (1, (0., 0., 0.86464814))], units='Angstrom', charge=-1) #HF method example #Different basis can be used, sto-3g #H2solver = SCF(H2, method="HF") H2solver = SCF(H2, method="HF") H2solver.iterate() print "HF energy = ", H2solver.energy #DFT method example lda = SCF(H2, method="DFT") lda.iterate() blyp = SCF(H2, method="DFT", functional="BLYP") blyp.iterate() print "DFT results: LDA = ", lda.energy, " BLYP = ", blyp.energy #Open shell Hartree Fock # method='UHF' or method='ROHF'
from PyQuante import Molecule, SCF # Define the atom he = Molecule('he',atomlist=[(2,(0,0,0))],charge=0,multiplicity=1) # Run HF solver = SCF(he,method="HF",basis="dzvp") solver.iterate() # Show result print solver print "HF Energy = ",solver.energy print "---With fractional charge---" he = Molecule('he',atomlist=[(2.04,(0,0,0))],charge=0,multiplicity=1) # Run HF solver = SCF(he,method="HF",basis="dzvp") solver.iterate() # Show result print solver print "HF Energy = ",solver.energy
from numpy import * def const_init(vec, label): log = "const double %s[%d] = {" % (label, vec.size) for i, v in enumerate(vec[:-1]): log += "%15.8f," % v if not i % 5: log += "\n" log += "%15.8f};\n" % vec[-1] print log h2o = Molecule('H2O', [(8, (-3.08471, 1.12313, 0.00396)), (1, (-2.11791, 0.90877, 0.01763)), (1, (-3.12325, 2.07922, -0.24921))], units='Angstrom') solver = SCF(h2o, basis='sto3g', method="HF", etol=1e-15) solver.iterate() print "Energy: %14.12f" % solver.energy D = (solver.dmat * 2.0).ravel() S = solver.S.ravel() F = solver.F.ravel() H = solver.h.ravel() const_init(D, "ref_D") const_init(S, "ref_S") const_init(F, "ref_F") const_init(H, "ref_H")
from PyQuante.Molecule import Molecule from PyQuante import SCF #Intializing the molecules H2 = Molecule('H2', [ (1, (0,0,0)), (1,(1.4,0,0)) ] ) OHmin = Molecule( 'OHmin', [ (8, (0., 0., -0.08687037)) , (1, (0., 0., 0.86464814)) ], units='Angstrom', charge=-1 ) #HF method example #Different basis can be used, sto-3g #H2solver = SCF(H2, method="HF") H2solver = SCF(H2, method="HF") H2solver.iterate() print "HF energy = ", H2solver.energy #DFT method example lda = SCF(H2,method="DFT") lda.iterate() blyp = SCF(H2,method="DFT",functional="BLYP") blyp.iterate() print "DFT results: LDA = ", lda.energy, " BLYP = ", blyp.energy #Open shell Hartree Fock # method='UHF' or method='ROHF'
def Edot(method='ROHF'): O = Molecule('O',atomlist=[('O',(0,0,0))],multiplicity=3) job = SCF(O,method=method,basis='6-31G**') job.iterate() return job.energy
def testH(self): solv = SCF(h, method='DFT') solv.iterate() self.assertAlmostEqual(solv.energy, -7.431364, 4)
import logging from numpy import array from PyQuante import SCF, Molecule atoms = [(14, array([0, 0, 0])), (14, array([ 2.3419588, 0. , 0. ])), (14, array([ 3.21218834, 2.05887837, 0. ])), (14, array([ 1.23984519, 3.29297073, -0.42228815])), (14, array([-0.05485092, 1.72185148, -1.63972761])), (14, array([ 1.15882181, 0.99278059, -3.55206339])), (14, array([ 3.39816913, 0.26950033, -3.1977073 ])), (14, array([ 4.55928267, 1.90791736, -1.93502226])), (14, array([ 3.39316637, -1.42643782, -1.53138653])), (1, array([-0.6106289 , 0.43621736, 1.28608097])), (1, array([-0.5834327 , -1.31182802, -0.39633738])), (1, array([-1.43155677, 2.12871605, -2.08077878])), (1, array([ 1.53825752, 4.55183661, -1.16374012])), (1, array([ 0.53075288, 3.66105357, 0.83588437])), (1, array([ 5.94172312, 1.43875952, -1.62950356])), (1, array([ 4.67251821, 3.2307785 , -2.61584443])), (1, array([ 3.97839267, -0.14357093, -4.51963896])), (1, array([ 2.59722827, -2.64784197, -1.83682433])), (1, array([ 4.77261873, -1.8301562 , -1.14139106])), (1, array([ 0.40165221, -0.13112135, -4.18238283])), (1, array([ 1.17882996, 2.10638397, -4.5476595 ]))] logging.basicConfig(level=logging.DEBUG) m = Molecule('molecule', atoms) lda = SCF(m, method="DFT") lda.iterate()
from PyQuante import Molecule, SCF # Define the atom he = Molecule('he', atomlist=[(2, (0, 0, 0))], charge=0, multiplicity=1) # Run HF solver = SCF(he, method="HF", basis="dzvp") solver.iterate() # Show result print solver print "HF Energy = ", solver.energy print "---With fractional charge---" he = Molecule('he', atomlist=[(2.04, (0, 0, 0))], charge=0, multiplicity=1) # Run HF solver = SCF(he, method="HF", basis="dzvp") solver.iterate() # Show result print solver print "HF Energy = ", solver.energy
def energy(R=1.217, method='UHF'): O2 = Molecule('O2',atomlist=[('O',(0,0,0)),('O',(R,0,0))],\ units='Angstrom',multiplicity=3) O2abinitio = SCF(O2, method=method, basis='6-31G**') O2abinitio.iterate() return O2abinitio.energy
""" Calculates the H2 molecule using UHF. And plots the charge density along the x-axis. """ from PyQuante import SCF, Molecule from PyQuante.NumWrap import arange from pylab import plot, savefig # Do the lda calculation: h2 = Molecule('h2', [(1, (-0.7, 0, 0)), (1, (0.7, 0, 0))]) hf = SCF(h2, method="UHF", basis="6-31G**") hf.iterate() # print some info: print "UHF Results: energy =", hf.energy print "orbital energies:", hf.solvera.orbe # Get the items we'll need to compute the density with orbs = hf.solvera.orbs bfs = hf.basis_set.get() nclosed,nopen = h2.get_closedopen() nbf = len(bfs) x,y,z = 0, 0, 0 xs = arange(-1.0, 1.1, 0.1) ds = [] for x in xs: amp_xyz = 0 for i in range(nclosed):
def energy(R=1.217,method='UHF'): O2 = Molecule('O2',atomlist=[('O',(0,0,0)),('O',(R,0,0))],\ units='Angstrom',multiplicity=3) O2abinitio = SCF(O2,method=method,basis='6-31G**') O2abinitio.iterate() return O2abinitio.energy