Example #1
0
    def test_rhf_0d(self):
        from pyscf.df import mdf_jk
        from pyscf.scf import hf
        L = 4
        cell = pbcgto.Cell()
        cell.build(
            unit='B',
            a=numpy.eye(3) * L * 5,
            gs=[10] * 3,
            atom='''He 2 2 2; He 2 2 3''',
            dimension=0,
            verbose=0,
            basis={'He': [[0, (0.8, 1.0)], [0, (1.0, 1.0)], [0, (1.2, 1.0)]]})
        mol = cell.to_mol()
        mf = mdf_jk.density_fit(hf.RHF(mol))
        mf.with_df.gs = [10] * 3
        mf.with_df.auxbasis = {'He': [[0, (1e6, 1)]]}
        mf.with_df.charge_constraint = False
        mf.with_df.metric = 'S'
        eref = mf.kernel()

        mf = pbchf.RHF(cell)
        mf.with_df = pdf.PWDF(cell)
        mf.exxdiv = None
        mf.get_hcore = lambda *args: hf.get_hcore(mol)
        mf.energy_nuc = lambda *args: mol.energy_nuc()
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, eref, 8)
Example #2
0
def test_hf(pseudo=None):
    # The molecular calculation
    mol = gto.Mole()
    mol.unit = 'B'
    L = 60
    mol.atom.extend([
        ['He', (L / 2., L / 2., L / 2.)],
    ])
    # these are some exponents which are not hard to integrate
    mol.basis = {'He': [[0, (0.8, 1.0)], [0, (1.0, 1.0)], [0, (1.2, 1.0)]]}
    mol.build()

    m = hf.RHF(mol)
    print "Molecular HF energy"
    print(m.scf())  # -2.63502450321874

    # The periodic calculation
    cell = pbcgto.Cell()
    cell.unit = 'B'
    cell.h = np.diag([L, L, L])
    cell.gs = np.array([60, 60, 60])
    cell.nimgs = [0, 0, 0]

    cell.atom = mol.atom
    cell.basis = mol.basis
    cell.pseudo = pseudo
    # cell.verbose = 4
    cell.build(None, None)

    mf = pbchf.RHF(cell)

    print(mf.scf())  # -2.58766850182551: doesn't look good, but this is due
Example #3
0
def mf_initializer_diis(mol):
    """Will init pyscf hf engine. With damping of 0.3 and maximum of 100 
    iterations"""
    mf = hf.RHF(mol)
    mf.verbose = 1
    mf.max_cycle = 100
    
    return mf
Example #4
0
def measure_hf_energy(p_batch, molecules):

    energies = []
    for (p, mol) in zip(p_batch, molecules):
        mf = hf.RHF(mol.get_pyscf_molecule())
        h1e = mf.get_hcore()
        veff = mf.get_veff(dm=p.astype("float64"))
        energies.append(mf.energy_tot(p.astype("float64"), h1e, veff))
    return energies
def scf_runs(molecules):

    S, P = [], []
    for i, molecule in enumerate(molecules):
        
        msg.info(str(i + 1) + "/" + str(len(molecules)))
        
        mol = molecule.get_pyscf_molecule()
        mf = hf.RHF(mol)
        mf.verbose = 1
        mf.run()
        
        S.append(mf.get_ovlp().reshape((dim**2, )))
        P.append(mf.make_rdm1().reshape((dim**2, )))

    return S, P
Example #6
0
def RHF(mol, *args):
    '''This is a wrap function to decide which SCF class to use, RHF or ROHF
    '''
    if mol.nelectron == 1:
        if mol.symmetry:
            return rhf_symm.HF1e(mol)
        else:
            return rohf.HF1e(mol)
    elif not mol.symmetry or mol.groupname is 'C1':
        if mol.spin > 0:
            return rohf.ROHF(mol, *args)
        else:
            return rhf.RHF(mol, *args)
    else:
        if mol.spin > 0:
            return rhf_symm.ROHF(mol, *args)
        else:
            return rhf_symm.RHF(mol, *args)
Example #7
0
def scf_runs(molecules):

    S, P, F = [], [], []
    for i, molecule in enumerate(molecules):

        msg.info(str(i + 1) + "/" + str(len(molecules)))

        mol = molecule.get_pyscf_molecule()
        mf = hf.RHF(mol)
        mf.verbose = 1
        mf.run()

        h = mf.get_hcore(mol)
        s = mf.get_ovlp()
        p = mf.make_rdm1()
        f = mf.get_fock(h, s, mf.get_veff(mol, p), p)

        S.append(s.reshape((dim**2, )))
        P.append(p.reshape((dim**2, )))
        F.append(f.reshape((dim**2, )))

    return S, P, F
Example #8
0
def not_used():
    msg.info("Netowrk Analysis!", 2)

    #--- fetching the molecules ---
    msg.info("Fetching the molecules", 2)

    def grep_molecule(input_file):
        import re

        with open(input_file) as f:

            molecule = re.search(r"\$molecule.*\$end", f.read(), re.DOTALL)
            if molecule is None:
                raise ValueError("No molecule found in " + f.name)
            else:
                molecule = molecule.group(0)

                # cut out geometries
                geometries = molecule.splitlines()[2:-1]

        # from geometries take the species and positions
        species, positions = [], []
        for line in geometries:
            splits = line.split()
            species.append(splits[0])
            positions.append(splits[1:])

        return species, positions

    def fetch_molecules(folder):

        files = [file for file in listdir(folder) if ".inp" in file]

        for i, file in enumerate(files):

            msg.info("Fetching: " + str(i + 1) + "/" + str(len(files)))

            mol = Molecule(*grep_molecule(join(folder, file)))

            mol.basis = "sto-3g"

            yield mol

    molecules = list(fetch_molecules("butadien/data"))
    #---

    #--- do scf ---
    msg.info("Running the SCF calculations", 2)
    iterations = []
    for i, molecule in enumerate(molecules):

        mol = molecule.get_pyscf_molecule()

        msg.info("Calculating: " + str(i + 1) + "/200.")

        # assemble pyscf initial guesses
        P_1e = hf.init_guess_by_1e(mol)
        P_atom = hf.init_guess_by_atom(mol)
        P_minao = hf.init_guess_by_minao(mol)

        # nn guess
        S = hf.get_ovlp(mol).reshape(1, dim**2)
        P_NN = network.run(sess, S).reshape(dim, dim)

        iterations_molecule = []
        for guess in [P_1e, P_atom, P_minao, P_NN]:  #, P_NN]:

            mf = hf.RHF(mol)
            mf.verbose = 1
            mf.kernel(dm0=guess)
            iterations_molecule.append(mf.iterations)

        iterations.append(iterations_molecule)

    iterations = np.array(iterations)
    #---

    #--- statistics ---
    fig, axes = plt.subplots(2, 2)

    bins = 1  # todo hier kann man auch ein array angeben

    for i, name in enumerate(['1e', 'atom', 'P_minao']):

        hist, bins = np.histogram(iterations[:, i])
        center = (bins[:-1] + bins[1:]) / 2
        axes[i].bar(center, hist, label=name)

    plt.legend()
    plt.show()
Example #9
0
File: x2c.py Project: zzy2014/pyscf
# A tag to label the derived SCF class
class _X2C_SCF:
    pass


if __name__ == '__main__':
    mol = mole.Mole()
    mol.build(
        verbose=0,
        atom=[["O", (0., 0., 0.)], [1, (0., -0.757, 0.587)],
              [1, (0., 0.757, 0.587)]],
        basis='ccpvdz-dk',
    )

    method = hf.RHF(mol)
    enr = method.kernel()
    print('E(NR) = %.12g' % enr)

    method = UHF(mol)
    ex2c = method.kernel()
    print('E(X2C1E) = %.12g' % ex2c)
    method.with_x2c.basis = {'O': 'unc-ccpvqz', 'H': 'unc-ccpvdz'}
    print('E(X2C1E) = %.12g' % method.kernel())
    method.with_x2c.approx = 'atom1e'
    print('E(X2C1E) = %.12g' % method.kernel())

    method = UKS(mol)
    ex2c = method.kernel()
    print('E(X2C1E) = %.12g' % ex2c)
Example #10
0
    dm_ll = reduce(numpy.dot, (proj, dm_nr*.5, proj.T.conj()))
    dm_ll = (dm_ll + dhf.time_reversal_matrix(mol, dm_ll)) * .5
    return dm_ll


if __name__ == '__main__':
    mol = mole.Mole()
    mol.build(
        verbose = 0,
        atom = [["O" , (0. , 0.     , 0.)],
                [1   , (0. , -0.757 , 0.587)],
                [1   , (0. , 0.757  , 0.587)] ],
        basis = 'ccpvdz-dk',
    )

    method = hf.RHF(mol)
    enr = method.kernel()
    print('E(NR) = %.12g' % enr)

    method = sfx2c1e(hf.RHF(mol))
    esfx2c = method.kernel()
    print('E(SFX2C1E) = %.12g' % esfx2c)
    method.with_x2c.basis = 'unc-ccpvqz-dk'
    print('E(SFX2C1E) = %.12g' % method.kernel())
    method.with_x2c.approx = 'atom1e'
    print('E(SFX2C1E) = %.12g' % method.kernel())

    method = UHF(mol)
    ex2c = method.kernel()
    print('E(X2C1E) = %.12g' % ex2c)
    method.with_x2c.basis = {'O': 'unc-ccpvqz', 'H':'unc-ccpvdz'}
Example #11
0
    def mf_initializer(mol):
        mf = hf.RHF(mol)
        mf.diis = None
        mf.verbose = 1

        return mf
    P_atom = hf.init_guess_by_atom(mol)
    P_minao = hf.init_guess_by_minao(mol)
    
    print("die normalen sind fertig")

    # nn guess
    S = hf.get_ovlp(mol).reshape(1, dim**2)
    P_NN = network.run(sess, S).reshape(dim, dim).astype('float64')


    print("P_NN fertig")
    
    iterations_molecule = []
    for guess in [P_1e, P_atom, P_minao, P_NN]:#, P_NN]:
        print("SCF")
        mf = hf.RHF(mol)
        mf.verbose = 1
        mf.kernel(dm0=guess)
        iterations_molecule.append(mf.iterations)
    

    print("SCFs done")
    iterations.append(iterations_molecule)

    print("Next step")

iterations = np.array(iterations)
#---


#--- statistics ---