Beispiel #1
0
def test_1rdm_response():
    mol, mf, impClusters = test_makemole1()
    #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()
    umat = np.zeros((mol.nao_nr(), mol.nao_nr()))

    #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)
    RDMderivs_rot = theDMET.helper.construct1RDM_response(False, umat, None)

    Norb = theDMET.helper.locints.Norbs
    Nterms = theDMET.helper.Nterms
    numPairs = theDMET.helper.numPairs

    inH1start = theDMET.helper.H1start
    inH1row = theDMET.helper.H1row
    inH1col = theDMET.helper.H1col
    inH0 = theDMET.helper.locints.loc_rhf_fock()  #+ umat
    RDMderivs_libdmet = libdmet.rhf_response(Norb, Nterms, numPairs, inH1start,
                                             inH1row, inH1col, inH0)
    inH0 = np.array(inH0.reshape((10 * 10)), dtype=ctypes.c_double)
    assert np.abs((RDMderivs_rot - RDMderivs_libdmet)).sum() < 1e-8
    return RDMderivs_rot, RDMderivs_libdmet
Beispiel #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	
Beispiel #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)
Beispiel #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)
Beispiel #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
Beispiel #6
0
one_bath_orb_per_bond = False  # Sun & Chan, JCTC 10, 3784 (2014) [ http://dx.doi.org/10.1021/ct500512f ]
casci_energy_formula = False  # CASCI or DMET energy formula

basis = '6-31g'

for distance in np.arange(1.8, 1.85, 0.1):  # Ni---H2O distance
    print('-----------------------------------------------')
    print('----  Me-N=N-Me at', distance, 'angstroms  --------')
    print('-----------------------------------------------')
    mol = Me2N2_struct.structure(distance, basis)
    mf = scf.RHF(mol)
    mf.verbose = 3
    mf.scf()

    if (True):
        myInts = localintegrals.localintegrals(mf, range(mol.nao_nr()),
                                               localization)
        myInts.molden('Me2N2.molden')

        unit_sizes = None
        if (basis == '6-31g'):
            unit_sizes = np.array([18, 15, 15])  # N2, CH3, CH3
        assert (np.sum(unit_sizes) == mol.nao_nr())

        impurityClusters = []
        if (casci_energy_formula):  # Do only 1 impurity at the edge
            num_orb_in_imp = np.sum(unit_sizes[0:1])
            impurity_orbitals = np.zeros([mol.nao_nr()], dtype=int)
            impurity_orbitals[0:num_orb_in_imp] = 1
            impurityClusters.append(impurity_orbitals)
        else:  # Partition
            jump = 0
Beispiel #7
0
    #elif ( bl < 3.35 ):
    else:
        #localization_type = 'meta_lowdin'
        #localization_type = 'boys'
        localization_type = 'iao'
        rotation = np.eye( mol.nao_nr(), dtype=float )
        for i in range(nat):
            theta  = i * (2*np.pi/nat)
            offset = 14 * i # 14 basisfunctions in cc-pVDZ
            # Order of AO: 3s 2p 1d
            rotation[ offset+3:offset+6,  offset+3:offset+6  ] = ringhelper.p_functions( theta )
            rotation[ offset+6:offset+9,  offset+6:offset+9  ] = ringhelper.p_functions( theta )
            rotation[ offset+9:offset+14, offset+9:offset+14 ] = ringhelper.d_functions( theta )
        assert( np.linalg.norm( np.dot( rotation, rotation.T ) - np.eye( rotation.shape[0] ) ) < 1e-6 )
        myInts = localintegrals.localintegrals( mf, range( mol.nao_nr() ), localization_type, rotation )
        if (( localization_type == 'meta_lowdin' ) or ( localization_type == 'iao' )):
            myInts.TI_OK = True
        myInts.molden( 'Be-loc.molden' )

        atoms_per_imp = 1 # Impurity size = 1/2/4 Be atoms
        assert ( nat % atoms_per_imp == 0 )
        orbs_per_imp = myInts.Norbs * atoms_per_imp / nat

        impurityClusters = []
        for cluster in range( nat / atoms_per_imp ):
            impurities = np.zeros( [ myInts.Norbs ], dtype=int )
            for orb in range( orbs_per_imp ):
                impurities[ orbs_per_imp*cluster + orb ] = 1
            impurityClusters.append( impurities )
        if (( localization_type == 'meta_lowdin' ) or ( localization_type == 'iao' )):
Beispiel #8
0
        ENUCL = mf.mol.energy_nuc()
        OEI = np.dot(
            np.dot(mf.mo_coeff.T,
                   mol.intor('cint1e_kin_sph') + mol.intor('cint1e_nuc_sph')),
            mf.mo_coeff)
        TEI = ao2mo.outcore.full_iofree(mol, mf.mo_coeff,
                                        compact=False).reshape(
                                            mol.nao_nr(), mol.nao_nr(),
                                            mol.nao_nr(), mol.nao_nr())
        import chemps2
        Energy, OneDM = chemps2.solve(ENUCL, OEI, OEI, TEI, mol.nao_nr(),
                                      mol.nelectron, mol.nao_nr(), 0.0, False)
        print "bl =", bondlength, " and energy =", Energy

    else:
        myInts = localintegrals.localintegrals(mf, range(mol.nao_nr()),
                                               'meta_lowdin')
        myInts.molden('hydrogen-loc.molden')
        myInts.TI_OK = True  # Only s functions

        atoms_per_imp = 2  # Impurity size = 1 atom
        assert (nat % atoms_per_imp == 0)
        orbs_per_imp = myInts.Norbs * atoms_per_imp / nat

        impurityClusters = []
        for cluster in range(nat / atoms_per_imp):
            impurities = np.zeros([myInts.Norbs], dtype=int)
            for orb in range(orbs_per_imp):
                impurities[orbs_per_imp * cluster + orb] = 1
            impurityClusters.append(impurities)
        isTranslationInvariant = True  # OK because only s-functions and meta-lowdin
        method = 'ED'
Beispiel #9
0
    mf.scf()

    if ( False ):   
        ccsolver = ccsd.CCSD( mf )
        ccsolver.verbose = 5
        ECORR, t1, t2 = ccsolver.ccsd()
        ECCSD = mf.hf_energy + ECORR
        print "ECCSD for alpha ",alpha," =", ECCSD
        
    if ( False ):
        mp2solver = mp.MP2( mf )
        ECORR, t_mp2 = mp2solver.kernel()
        EMP2 = mf.hf_energy + ECORR
        print "EMP2 for alpha ",alpha," =", EMP2
    
    myInts = localintegrals.localintegrals( mf, range( mol.nao_nr() ), 'meta_lowdin' )
    myInts.molden( 'polyyne-loc.molden' )

    atoms_per_imp = 4 # Impurity size counted in number of atoms
    assert ( nat % atoms_per_imp == 0 )
    orbs_per_imp = myInts.Norbs * atoms_per_imp / nat

    impurityClusters = []
    for cluster in range( nat / atoms_per_imp ):
        impurities = np.zeros( [ myInts.Norbs ], dtype=int )
        for orb in range( orbs_per_imp ):
            impurities[ orbs_per_imp*cluster + orb ] = 1
        impurityClusters.append( impurities )
    isTranslationInvariant = False # Both in meta_lowdin (due to px, py) and Boys TI is not OK
    method = 'CC'
    SCmethod = 'NONE' #Don't do it self-consistently
Beispiel #10
0
    ccsolver1.verbose = 5
    ECORR1, t1, t2 = ccsolver1.ccsd()
    ECCSD1 = mf1.hf_energy + ECORR1
    print "ERHF  for structure", thestructure, "=", mf1.hf_energy + ERHF2
    print "ECCSD for structure", thestructure, "=", ECCSD1 + ECCSD2
    # ERHF  (reactants) = -925.856396874
    # ECCSD (reactants) = -927.858808954
    # ERHF  (products)  = -925.964797448
    # ECCSD (products)  = -927.949282439

############
#   DMET   #
############

if (True):
    myInts = localintegrals.localintegrals(mf2, range(mol2.nao_nr()), 'iao')
    myInts.molden('emft-loc.molden')

    unit_sizes = None
    if ((thebasis1 == 'cc-pvdz') and (thebasis2 == 'aug-cc-pvdz')):
        if (thestructure == 'reactants'):  # 1-chlorodecane
            unit_sizes = np.array([27, 24, 24, 24, 24, 24, 24, 24, 24, 24,
                                   29])  # Cl, 9xCH2, CH3 (272 orbs total)
        if (thestructure == 'products'):  # 1-decanol
            unit_sizes = np.array([28, 24, 24, 24, 24, 24, 24, 24, 24, 24,
                                   29])  # OH, 9xCH2, CH3 (273 orbs total)
    assert (np.sum(unit_sizes) == mol2.nao_nr())

    for carbons_in_cluster in range(0, 5):  # 0, 1, 2, 3, 4
        orbs_in_imp = np.sum(unit_sizes[0:carbons_in_cluster + 1])
        impurityClusters = []
Beispiel #11
0
    with open( 'sn2-mo.molden', 'w' ) as thefile:
        molden.header( mol, thefile )
        molden.orbital_coeff( mol, thefile, mf.mo_coeff )

if ( False ):
    ccsolver = ccsd.CCSD( mf )
    ccsolver.verbose = 5
    ECORR, t1, t2 = ccsolver.ccsd()
    ECCSD = mf.hf_energy + ECORR
    print "ERHF  for structure", thestructure, "=", mf.hf_energy
    print "ECCSD for structure", thestructure, "=", ECCSD
    
if ( True ):
    # myInts = localintegrals.localintegrals( mf, range( mol.nao_nr() ), 'boys', localization_threshold=1e-5 )
    # myInts = localintegrals.localintegrals( mf, range( mol.nao_nr() ), 'meta_lowdin' )
    myInts = localintegrals.localintegrals( mf, range( mol.nao_nr() ), 'iao' )
    myInts.molden( 'sn2-loc.molden' )
    
    unit_sizes = None
    if (( thebasis1 == 'cc-pvdz' ) and ( thebasis2 == 'aug-cc-pvdz' )):
        unit_sizes = np.array([ 87, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 29 ]) # ClBr, 11xCH2, CH3 (356 orbs total)
    assert( np.sum( unit_sizes ) == mol.nao_nr() )

    for carbons_in_cluster in cluster_sizes:
        impurityClusters = []
        if ( single_impurity == True ): # Do only 1 impurity at the edge
            num_orb_in_imp = np.sum( unit_sizes[ 0 : carbons_in_cluster ] )
            impurity_orbitals = np.zeros( [ mol.nao_nr() ], dtype=int )
            impurity_orbitals[ 0 : num_orb_in_imp ] = 1
            impurityClusters.append( impurity_orbitals )
        else: # Partition