def run_dalton_label_to_operator(dalton_label, operator_label, slice_idx, is_imaginary, is_spin_dependent): operator = utils.dalton_label_to_operator(dalton_label) assert operator.label == operator_label assert operator.slice_idx == slice_idx assert operator.is_imaginary == is_imaginary assert operator.is_spin_dependent == is_spin_dependent return operator
def calculate_disk_uhf(testcasedir, hamiltonian, spin, frequency, label_1, label_2): occupations = utils.read_file_occupations(testcasedir / "occupations") nocc_alph, nvirt_alph, nocc_beta, nvirt_beta = occupations norb = nocc_alph + nvirt_alph C = utils.read_file_3(testcasedir / "C") assert C.shape[0] == 2 assert C.shape[2] == norb nbasis = C.shape[1] moene = utils.read_file_2(testcasedir / "moene") assert moene.shape == (norb, 2) moints_iajb_aaaa = utils.read_file_4(testcasedir / "moints_iajb_aaaa") moints_iajb_aabb = utils.read_file_4(testcasedir / "moints_iajb_aabb") moints_iajb_bbaa = utils.read_file_4(testcasedir / "moints_iajb_bbaa") moints_iajb_bbbb = utils.read_file_4(testcasedir / "moints_iajb_bbbb") moints_ijab_aaaa = utils.read_file_4(testcasedir / "moints_ijab_aaaa") moints_ijab_bbbb = utils.read_file_4(testcasedir / "moints_ijab_bbbb") assert moints_iajb_aaaa.shape == (nocc_alph, nvirt_alph, nocc_alph, nvirt_alph) assert moints_iajb_aabb.shape == (nocc_alph, nvirt_alph, nocc_beta, nvirt_beta) assert moints_iajb_bbaa.shape == (nocc_beta, nvirt_beta, nocc_alph, nvirt_alph) assert moints_iajb_bbbb.shape == (nocc_beta, nvirt_beta, nocc_beta, nvirt_beta) assert moints_ijab_aaaa.shape == (nocc_alph, nocc_alph, nvirt_alph, nvirt_alph) assert moints_ijab_bbbb.shape == (nocc_beta, nocc_beta, nvirt_beta, nvirt_beta) operator_1 = utils.dalton_label_to_operator(label_1) operator_2 = utils.dalton_label_to_operator(label_2) operator_1_integrals_mn = utils.read_file_3( testcasedir / f"operator_mn_{operator_1.label}") operator_2_integrals_mn = utils.read_file_3( testcasedir / f"operator_mn_{operator_2.label}") # The first dimension can"t be checked since there may be multiple # components. assert operator_1_integrals_mn.shape[1:] == (nbasis, nbasis) assert operator_2_integrals_mn.shape[1:] == (nbasis, nbasis) # Only take the component/slice from the integral as determined # from the DALTON operator label. operator_1_integrals_mn = operator_1_integrals_mn[operator_1.slice_idx] operator_2_integrals_mn = operator_2_integrals_mn[operator_2.slice_idx] # However, this eliminates an axis, which needs to be added back. operator_1_integrals_mn = operator_1_integrals_mn[np.newaxis, ...] operator_2_integrals_mn = operator_2_integrals_mn[np.newaxis, ...] operator_1.ao_integrals = operator_1_integrals_mn operator_2.ao_integrals = operator_2_integrals_mn moene_alph = np.diag(moene[:, 0]) moene_beta = np.diag(moene[:, 1]) moene = np.stack((moene_alph, moene_beta), axis=0) assert moene.shape == (2, norb, norb) solver = iterators.ExactInv(C, moene, occupations) solver.tei_mo = ( moints_iajb_aaaa, moints_iajb_aabb, moints_iajb_bbaa, moints_iajb_bbbb, moints_ijab_aaaa, moints_ijab_bbbb, ) solver.tei_mo_type = "partial" driver = cphf.CPHF(solver) driver.add_operator(operator_1) driver.add_operator(operator_2) driver.set_frequencies([float(frequency)]) driver.run(solver_type="exact", hamiltonian=hamiltonian, spin=spin) assert len(driver.frequencies) == len(driver.results) == 1 res = driver.results[0] assert res.shape == (2, 2) bl = res[1, 0] tr = res[0, 1] diff = abs(abs(bl) - abs(tr)) # Results should be symmetric w.r.t. interchange between operators # in the LR equations. thresh = 1.0e-14 assert diff < thresh return bl
# pq += 1 F_grad = dict() B = dict() for atom in range(natoms): for p in range(3): key = str(atom) + cart[p] contr1 = np.einsum("pqmm->pq", deriv1["TEI" + key][:, :, o, o]) contr2 = np.einsum("pmmq->pq", deriv1["TEI" + key][:, o, o, :]) F_grad[key] = deriv1["T" + key] + deriv1["V" + key] + ( 2 * contr1) - contr2 for atom in range(natoms): for p in range(3): key = str(atom) + cart[p] contr1 = np.einsum("ia,ii->ia", deriv1["S" + key][o, v], F[o, o]) contr2 = np.einsum("iamn,mn->ia", MO[o, v, o, o], deriv1["S" + key][o, o]) contr3 = np.einsum("inma,mn->ia", MO[o, o, o, v], deriv1["S" + key][o, o]) B[key] = contr1 - F_grad[key][o, v] + (2 * contr2) - contr3 return B if __name__ == "__main__": dalton_integrals = parse_aoproper( "r_lih_hf_sto-3g/dalton_response_rpa_singlet/AOPROPER") from pyresponse.utils import dalton_label_to_operator labels = dalton_integrals.keys() for label in labels: print(dalton_label_to_operator(label))