Ejemplo n.º 1
0
def test_solvers():
    #mpDMET
    mol, mf, impClusters = test_makemole1()
    symmetry = 'Translation'  #or [0]*5, takes longer time

    time1 = time.time()
    solverlist = 'CASCI'  #['RHF', 'CASCI', 'CASCI', 'CASCI', 'CASCI']
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='F',
                        solver=solverlist)
    runDMET.one_shot()
    time2 = time.time()
    time_FCI_1 = time2 - time1
    E_FCI_1 = runDMET.Energy_total

    time1 = time.time()
    solverlist = 'DMRG-CASCI-B'  #['RHF', 'CASCI', 'CASCI', 'CASCI', 'CASCI']
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='F',
                        solver=solverlist)
    runDMET.one_shot()
    time2 = time.time()
    time_FCI_2 = time2 - time1
    E_FCI_2 = runDMET.Energy_total

    time1 = time.time()
    solverlist = 'DMRG-CASCI-C'  #['RHF', 'CASCI', 'CASCI', 'CASCI', 'CASCI']
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='F',
                        solver=solverlist)
    runDMET.one_shot()
    time2 = time.time()
    time_FCI_3 = time2 - time1
    E_FCI_3 = runDMET.Energy_total

    assert np.isclose(E_FCI_2, E_FCI_1)
    assert np.isclose(E_FCI_3, E_FCI_1)

    #Remove DMRG temp directories
    for i in range(10):
        os.system('rm -rf ' + str(i) + '*')
Ejemplo n.º 2
0
def test_self_consistent():
	#pmDMET
	mol, mf, mydft, impClusters  = test_makemole1()
	symmetry = None  #or [0]*5, takes longer time
	solverlist = 'CASCI' #['RHF', 'CASCI', 'CASCI', 'CASCI', 'CASCI']
	runDMET = dmet.DMET(mf, impClusters, symmetry, orthogonalize_method = 'overlap', schmidt_decomposition_method = 'OED', OEH_type = 'FOCK', SC_CFtype = 'F', solver = solverlist)
	#runDMET.CAS = [[4,4]]
	runDMET.SC_canonical = True
	time1 = time.time()
	runDMET.self_consistent()
	time2 = time.time()
	time_pmDMET = time2 - time1
	
	#QC-DMET	
	myInts = localintegrals.localintegrals( mf, range( mol.nao_nr() ), 'meta_lowdin' )
	myInts.TI_OK = False
	method = 'CASSCF'
	SCmethod = 'BFGS' #Don't do it self-consistently
	TI = False
	theDMET = qc_dmet.dmet( myInts, impClusters, TI, method, SCmethod )	
	theDMET.impCAS = (4,4)
	time1 = time.time()
	theDMET.doselfconsistent()
	time2 = time.time()
	time_QCDMET = time2 - time1	
	
	return runDMET.Energy_total, time_pmDMET, time_QCDMET	
Ejemplo n.º 3
0
def test_costfunction():
    #pmDMET
    mol, mf, impClusters = test_makemole1()
    symmetry = None  #or [0]*5, takes longer time
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='meta_lowdin',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='FB',
                        solver='RHF')
    runDMET.one_shot()

    #QC-DMET
    myInts = localintegrals.localintegrals(mf, range(mol.nao_nr()),
                                           'meta_lowdin')
    myInts.TI_OK = False
    method = 'RHF'
    SCmethod = 'NONE'  #Don't do it self-consistently
    TI = False
    theDMET = qc_dmet.dmet(myInts, impClusters, TI, method, SCmethod)
    theDMET.doselfconsistent()

    uvec_size = runDMET.uvec.size
    uvec = np.random.rand(uvec_size)
    umat = runDMET.uvec2umat(uvec)

    CF_pmDMET = runDMET.costfunction(uvec)
    CF_QCDMET = theDMET.costfunction(uvec)
    CF_deriv_pmDMET = runDMET.costfunction_gradient(uvec)
    CF_deriv_QCDMET = theDMET.costfunction_derivative(uvec)

    assert np.isclose((CF_QCDMET - CF_pmDMET).sum(), 0)
    assert np.isclose((CF_deriv_QCDMET - CF_deriv_pmDMET).sum(), 0)
Ejemplo n.º 4
0
def test_1RDM_response():
    #pmDMET
    mol, mf, impClusters = test_makemole1()
    symmetry = [0] * 5  #or 'Translation'
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='meta_lowdin',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='FB',
                        solver='RHF')

    #QC-DMET
    myInts = localintegrals.localintegrals(mf, range(mol.nao_nr()),
                                           'meta_lowdin')
    myInts.TI_OK = True
    method = 'ED'
    SCmethod = 'LSTSQ'  #Don't do it self-consistently
    TI = True
    theDMET = qc_dmet.dmet(myInts, impClusters, TI, method, SCmethod)

    uvec_size = runDMET.uvec.size
    uvec = np.zeros(uvec_size)
    umat = runDMET.uvec2umat(uvec)

    RDMderivs_QCDMET = theDMET.helper.construct1RDM_response(False, umat, None)
    RDMderivs_pDMET = runDMET.construct_1RDM_response(uvec)
    diff = np.abs((RDMderivs_QCDMET - RDMderivs_pDMET)).sum()
    assert np.isclose(RDMderivs_QCDMET.size, RDMderivs_pDMET.size)
    assert np.isclose(diff, 0)
Ejemplo n.º 5
0
def test_make_H1():

    #pmDMET
    mol, mf, impClusters = test_makemole1()
    symmetry = [0] * 5  #or 'Translation'
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='FB',
                        solver='RHF')
    H1start, H1row, H1col = runDMET.make_H1()[1:]

    #QC-DMET
    myInts = localintegrals.localintegrals(mf, range(mol.nao_nr()),
                                           'meta_lowdin')
    myInts.TI_OK = True
    method = 'ED'
    SCmethod = 'LSTSQ'  #Don't do it self-consistently
    TI = True
    theDMET = qc_dmet.dmet(myInts, impClusters, TI, method, SCmethod)

    H1start = theDMET.helper.H1start - H1start
    H1row = theDMET.helper.H1row - H1row
    H1col = theDMET.helper.H1col - H1col
    assert H1start.sum() == 0
    assert H1row.sum() == 0
    assert H1col.sum() == 0
Ejemplo n.º 6
0
def test_kernel():
    mol, mf, impClusters = test_makemole2()
    symmetry = None
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='FB',
                        solver='RHF')
    Nelecs = runDMET.kernel()
    Etotal = runDMET.fragment_energies.sum()

    assert np.isclose(Nelecs, mol.nelectron)
    assert np.isclose(Etotal, mf.energy_elec()[0])
Ejemplo n.º 7
0
def test_one_shot_DMET():
    mol, mf, impClusters = test_makemole2()
    symmetry = [0, 1, 2, 3, 4]
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='FB',
                        solver='RHF')
    runDMET.embedding_symmetry = [0, 1, 2, 3, 4]
    E_total = runDMET.one_shot()
    Nelecs = runDMET.fragment_nelecs.sum()
    Etotal = runDMET.fragment_energies.sum()

    assert np.isclose(Nelecs, mol.nelectron)
    assert np.isclose(Etotal, mf.energy_elec()[0])
Ejemplo n.º 8
0
def test_rdm_diff():
    mol, mf, impClusters = test_makemole2()
    symmetry = [0, 1, 2, 1, 0]
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='FB',
                        solver='RHF')
    runDMET.one_shot()
    uvec_size = runDMET.uvec.size
    umat1 = np.zeros(uvec_size)
    umat2 = np.random.rand(uvec_size)
    CF1 = runDMET.costfunction(umat1)
    CF2 = runDMET.costfunction(umat2)
    assert (CF1 < 1e-8)
    assert (CF2 > 1e-5)
Ejemplo n.º 9
0
def test_single_embedding():
    mol, mf, impClusters = test_makemole2()
    impClusters = [impClusters[0]]
    symmetry = None
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='overlap',
                        OEH_type='FOCK',
                        SC_CFtype='FB',
                        solver='RHF')
    runDMET.single_embedding = True
    runDMET.one_shot()
    E_total = runDMET.Energy_total
    Nelecs = runDMET.fragment_nelecs.sum()

    assert np.isclose(Nelecs, mol.nelectron)
    assert np.isclose(E_total, mf.e_tot)
Ejemplo n.º 10
0
    for frag in range(4):
        impurity_orbitals = np.zeros([mol.nao_nr()], dtype=int)
        start = unit_sizes[:frag].sum()
        impurity_orbitals[start:(start + unit_sizes[frag])] = 1
        impClusters.append(impurity_orbitals)
    return mol, mf, impClusters


for bond in np.arange(0.8, 2.0, 0.2):
    mol, mf, impClusters = test_makemole(bond)
    symmetry = 'Translation'  #or [0]*5, takes longer time
    solverlist = 'CASCI'  #['RHF', 'CASCI', 'CASCI', 'CASCI', 'CASCI']
    runDMET = dmet.DMET(mf,
                        impClusters,
                        symmetry,
                        orthogonalize_method='overlap',
                        schmidt_decomposition_method='OED',
                        OEH_type='FOCK',
                        SC_CFtype='F',
                        solver=solverlist)
    #runDMET.CAS = [[4,4]]
    time1 = time.time()
    runDMET.self_consistent()
    time2 = time.time()
    time_mpDMET = time2 - time1
    print('Total energy + Time:', runDMET.Energy_total, time_mpDMET)
    '''#QC-DMET	
	myInts = localintegrals.localintegrals( mf, range( mol.nao_nr() ), 'meta_lowdin' )
	myInts.TI_OK = False
	method = 'CASSCF'
	SCmethod = 'BFGS' #Don't do it self-consistently
	TI = False