Esempio n. 1
0
def test_adc_parse():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "adc.out"))
    assert np.isclose(CAPH._W[0][0], -6.3724737e+01)
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "adc.out"),
                          onset="4000")
    assert np.isclose(CAPH._W[0][0], -4.9669293e+01)
    try:
        CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "adc.out"),
                              onset="1000")
    except:
        pass
Esempio n. 2
0
def get_corrected_energy(pc):
    CAPH = CAPHamiltonian(pc=pc)
    eta_list = np.linspace(0, 5000, 101)
    eta_list = np.around(eta_list * 1E-5, decimals=5)
    CAPH.run_trajectory(eta_list)
    traj = CAPH.track_state(1, tracking="energy")
    corr_energy, corr_eta_opt = traj.find_eta_opt(corrected=True,
                                                  start_idx=10,
                                                  end_idx=-1,
                                                  ref_energy=ref_energy,
                                                  units="eV")
    return corr_energy
Esempio n. 3
0
def test_biorthogonalization():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory([0.01])
    roots = CAPH._all_roots[0]
    ovlp = np.zeros((len(roots), len(roots)), dtype='complex_')
    for i in range(0, len(roots)):
        lr = roots[i].Leigvc
        for j in range(0, len(roots)):
            rr = roots[j].Reigvc
            ovlp[i][j] = np.dot(lr, rr)
    identity = np.identity(len(roots))
    diff = np.sum(ovlp - identity)
    assert np.isclose(diff, 0.0)
Esempio n. 4
0
def test_roots():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory(eta_list)
    traj = CAPH.track_state(1)
    E1, eta1, root1 = traj.find_eta_opt(corrected=True,
                                        units="au",
                                        return_root=True)
    E2, root2 = traj.get_energy(eta1,
                                corrected=True,
                                units="au",
                                return_root=True)
    assert root1 == root2
    assert np.isclose(E1, E2)
Esempio n. 5
0
def test_molcas():
    sys = pyopencap.System(sys_dict)
    pc = pyopencap.CAP(sys, cap_dict, 10)
    pc.read_data(es_dict)
    pc.compute_ao_cap(cap_dict)
    pc.compute_projected_cap()
    CAPH = CAPHamiltonian(pc=pc)
Esempio n. 6
0
def test_eomcc_parse():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "eomcc.out"))
    assert np.isclose(CAPH._H0[0][0], -1.09353e+02)
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "eomcc.out"),
                          irrep="B2g")
    assert np.isclose(CAPH._H0[0][0], -1.09313e+02)
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "eomcc_old.out"),
                          irrep="B2g")
    assert np.isclose(CAPH._H0[0][0], -1.09313e+02)
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "eomcc.out"),
                          irrep="all")
    assert len(CAPH._H0) == 10
    try:
        CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "eomcc.out"),
                              irrep="B1g")
    except:
        pass
Esempio n. 7
0
def test_qchem():
    sys = pyopencap.System(sys_dict)
    pc = pyopencap.CAP(sys, cap_dict, 5)
    pc.read_data(es_dict)
    pc.compute_ao_cap(cap_dict)
    pc.compute_projected_cap()
    W = pc.get_projected_cap()
    pc.compute_ao_cap(cap_dict2)
    pc.compute_projected_cap()
    W2 = pc.get_projected_cap()
    assert not W[0][0] == W2[0][0]
    CAPH = CAPHamiltonian(pc=pc)
Esempio n. 8
0
def test_eta_opt():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory(eta_list)
    traj = CAPH.track_state(1, tracking="overlap")
    uc_energy_au, uc_eta = traj.find_eta_opt(units="au")
    corr_energy_au, corr_eta = traj.find_eta_opt(corrected=True, units="au")
    uc_energy_ev, uc_eta = traj.find_eta_opt(ref_energy=ref_energy, units="eV")
    corr_energy_ev, corr_eta = traj.find_eta_opt(ref_energy=ref_energy,
                                                 corrected=True,
                                                 units="eV")
    assert np.isclose(np.real(uc_energy_au), -109.265006)
    assert np.isclose(np.real(corr_energy_au), -109.26652)
    assert np.isclose(np.real(uc_energy_ev), 2.6381)
    assert np.isclose(np.real(corr_energy_ev), 2.59686)
    traj = CAPH.track_state(1, tracking="energy")
    uc_energy_au = traj.get_energy(uc_eta)
    corr_energy_au = traj.get_energy(corr_eta, corrected=True)
    uc_energy_ev = traj.get_energy(uc_eta, ref_energy=ref_energy, units="eV")
    corr_energy_ev = traj.get_energy(corr_eta,
                                     ref_energy=ref_energy,
                                     corrected=True,
                                     units="eV")
    assert np.isclose(np.real(uc_energy_au), -109.265006)
    assert np.isclose(np.real(corr_energy_au), -109.26652)
    assert np.isclose(np.real(uc_energy_ev), 2.6381)
    assert np.isclose(np.real(corr_energy_ev), 2.59686)
Esempio n. 9
0
def test_energies_ev():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory(eta_list)
    assert np.isclose(np.real(CAPH.energies_ev(ref_energy=ref_energy)[0]),
                      1.3174781)
    traj = CAPH.track_state(1, tracking="overlap")
    assert np.isclose(np.real(traj.energies_ev(ref_energy=ref_energy)[0]),
                      2.55378)
Esempio n. 10
0
def test_correction():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory(eta_list)
    traj = CAPH.track_state(1, correction="density")
    E1, eta1 = traj.find_eta_opt(corrected=True, units="au")
    traj = CAPH.track_state(1, correction="derivative")
    E2, eta2 = traj.find_eta_opt(corrected=True, units="au")
    assert np.isclose(E1, E2)
    assert np.isclose(eta1, eta2)
Esempio n. 11
0
def test_tracking():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory(eta_list)
    traj = CAPH.track_state(1, tracking="overlap")
    E1, eta1 = traj.find_eta_opt(corrected=True, units="au")
    traj = CAPH.track_state(1, tracking="energy")
    E2, eta2 = traj.find_eta_opt(corrected=True, units="au")
    assert np.isclose(E1, E2)
    assert np.isclose(eta1, eta2)
Esempio n. 12
0
def test_energies_ev():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory(eta_list)
    traj = CAPH.track_state(1, tracking="overlap")
Esempio n. 13
0
# fill density matrices
h0 = np.zeros((nstates, nstates))
for i in range(0, len(e)):
    h0[i][i] = e[i]

# compute CAP
pc = pyopencap.CAP(s, cap_dict, nstates)
for i in range(0, len(fs.ci)):
    for j in range(0, len(fs.ci)):
        dm1 = fs.trans_rdm1(fs.ci[i], fs.ci[j], myhf.mo_coeff.shape[1],
                            mol.nelec)
        dm1_ao = np.einsum('pi,ij,qj->pq', myhf.mo_coeff, dm1,
                           myhf.mo_coeff.conj())
        pc.add_tdm(dm1_ao, i, j, "pyscf")

pc.compute_projected_cap()
W = pc.get_projected_cap()

from pyopencap.analysis import CAPHamiltonian as CAPH
my_CAPH = CAPH(H0=h0, W=W)

my_CAPH.export("H2_fci_opencap.out")

end = time.time()
print("Time:")
print(end - start)

import os
os.remove("molden_in.molden")
Esempio n. 14
0
h0 = np.zeros((nstates, nstates))
for i in range(0, len(h0)):
    h0[i][i] = E_0 + state.excitation_energy[i]

for i in range(0, nstates):
    state2state = State2States(state, initial=i)
    rdm = state.state_dm[i]
    rdm_alpha, rdm_beta = rdm.to_ao_basis()
    rdm_alpha = rdm_alpha.to_ndarray()
    rdm_beta = rdm_beta.to_ndarray()
    pc.add_tdms(rdm_alpha, rdm_beta, i, i, "psi4")
    for j, tdm in enumerate(state2state.transition_dm):
        tdm_alpha, tdm_beta = tdm.to_ao_basis()
        tdm_alpha = tdm_alpha.to_ndarray()
        tdm_beta = tdm_beta.to_ndarray()
        pc.add_tdms(tdm_alpha, tdm_beta, i, i + j + 1, "psi4")
        pc.add_tdms(tdm_alpha.conj().T,
                    tdm_beta.conj().T, i + j + 1, i, "psi4")

pc.compute_projected_cap()
W = pc.get_projected_cap()

from pyopencap.analysis import CAPHamiltonian as CAPH
my_CAPH = CAPH(H0=h0, W=W)

my_CAPH.export("n2_adc_opencap.out")

end = time.time()
print("Time:")
print(end - start)
Esempio n. 15
0
    '''
    
# Analyze OpenCAP output file, view eigenvalue trajectory

import pyopencap
from pyopencap.analysis import CAPHamiltonian
import numpy as np
import argparse
import matplotlib.pyplot as plt

parser = argparse.ArgumentParser(description='Process OpenCAP output file.')
parser.add_argument('output_file',help='OpenCAP output file')
args = parser.parse_args()


CAPH = CAPHamiltonian(output=args.output_file)
eta_list = np.linspace(0,5000,101)
eta_list = np.around(eta_list * 1E-5,decimals=5)
CAPH.run_trajectory(eta_list)
plt.plot(np.real(CAPH.total_energies),np.imag(CAPH.total_energies),'ro')
plt.show()

for i in range(0,CAPH.nstates):
	traj = CAPH.track_state(i,tracking="overlap")
	uc_energy, eta_opt = traj.find_eta_opt(start_idx=10)
	corr_energy, corr_eta_opt = traj.find_eta_opt(corrected=True,start_idx=10)
	plt.plot(np.real(traj.uncorrected_energies),np.imag(traj.uncorrected_energies),'-ro')
	plt.plot(np.real(traj.corrected_energies),np.imag(traj.corrected_energies),'-bo')
	plt.plot(np.real(corr_energy),np.imag(corr_energy),"g*",markersize=20)
	plt.plot(np.real(uc_energy),np.imag(uc_energy),"g*",markersize=20)
	plt.show()
Esempio n. 16
0
es_dict = {
    "package": "openmolcas",
    "method": "ms-caspt2",
    "molcas_output": OUTPUT_FILE,
    "rassi_h5": RASSI_FILE,
}

s = pyopencap.System(sys_dict)
pc = pyopencap.CAP(s, cap_dict, 10)
pc.read_data(es_dict)
pc.compute_projected_cap()
W = pc.get_projected_cap()
h0 = pc.get_H()

CAPH = CAPHamiltonian(H0=h0, W=W)
eta_list = np.linspace(0, 5000, 101)
eta_list = np.around(eta_list * 1E-5, decimals=5)
CAPH.run_trajectory(eta_list)
ref_energy = -109.36219955
traj = CAPH.track_state(2, tracking="overlap")
# Find optimal value of eta
uc_energy, eta_opt = traj.find_eta_opt(start_idx=10,
                                       ref_energy=ref_energy,
                                       units="eV")
# start_idx and end_idx for search use python slice notation (i.e. [start_idx:end_idx]).
corr_energy, corr_eta_opt = traj.find_eta_opt(corrected=True,
                                              start_idx=10,
                                              end_idx=-1,
                                              ref_energy=ref_energy,
                                              units="eV")
Esempio n. 17
0
def test_init_from_matrices():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "eomcc.out"))
    CAPH2 = CAPHamiltonian(H0=CAPH._H0, W=CAPH._W)
    assert CAPH._nstates == CAPH2._nstates
Esempio n. 18
0
def test_include_states():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.run_trajectory(eta_list, include_states=[0, 1, 2, 4])
    assert CAPH.H0.shape == CAPH.W.shape == (4, 4)
    assert np.isclose(CAPH.H0[3][3], -1.089933e+02)
    assert np.isclose(CAPH.W[3][3], -1.65280e+02)
Esempio n. 19
0
def test_opencap_parse():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    assert np.isclose(CAPH._W[0][0], -4.28708660e+01)
Esempio n. 20
0
def test_export():
    CAPH = CAPHamiltonian(output=os.path.join(dest_dir, "n2_opencap.out"))
    CAPH.export("test.out")
    CAPH2 = CAPHamiltonian(output="test.out")
    assert np.isclose(CAPH._H0[0][0], CAPH2._H0[0][0])
    os.remove("test.out")
Esempio n. 21
0
es_dict = {
    "package": "qchem",
    "method": "eom",
    "qchem_output": "../../analysis/N2/ref_outputs/qc_inp.out",
    "qchem_fchk": "../../analysis/N2/ref_outputs/qc_inp.fchk",
}

s = pyopencap.System(sys_dict)
pc = pyopencap.CAP(s, cap_dict, 5)
pc.read_data(es_dict)
pc.compute_projected_cap()
W = pc.get_projected_cap()
H0 = pc.get_H()

CAPH = CAPHamiltonian(pc=pc)
eta_list = np.linspace(0, 5000, 201)
eta_list = np.around(eta_list * 1E-5, decimals=5)
CAPH.run_trajectory(eta_list)
traj = CAPH.track_state(1, tracking="energy")
ref_energy = -109.36195558
# Find optimal value of eta
uc_energy, eta_opt = traj.find_eta_opt(start_idx=10,
                                       ref_energy=ref_energy,
                                       units="eV")
# start_idx and end_idx for search use python slice notation (i.e. [start_idx:end_idx]).
corr_energy, corr_eta_opt = traj.find_eta_opt(corrected=True,
                                              start_idx=10,
                                              end_idx=-1,
                                              ref_energy=ref_energy,
                                              units="eV")
Esempio n. 22
0
mytd = tdscf.TDA(mf).run(nstates=nstates)
print(mytd.e_tot)

H0 = np.zeros((nstates, nstates))
for i in range(0, len(mytd.e_tot)):
    H0[i][i] = mytd.e_tot[i]

for i in range(0, nstates):
    for j in range(i, nstates):
        dm1_alpha, dm1_beta = tda_density_matrix(mytd, i, j)
        pc.add_tdms(dm1_alpha, dm1_beta, i, j, "pyscf")
        if not i == j:
            pc.add_tdms(dm1_alpha.conj().T, dm1_beta.conj().T, j, i, "pyscf")

pc.compute_projected_cap()
W = pc.get_projected_cap()

from pyopencap.analysis import CAPHamiltonian as CAPH
my_CAPH = CAPH(H0=H0, W=W)

my_CAPH.export("n2_tddft_opencap.out")

import os
os.remove("molden_in.molden")
os.remove('n2.chk')

end = time.time()
print("Time:")
print(end - start)