Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
NVIDIA
GitHub Repository: NVIDIA/cuda-q-academic
Path: blob/main/chemistry-simulations/aux_files/qmmm/qchem/PEoperator.py
1165 views
1
import numpy as np
2
from aux_files.qmmm.qchem.hamiltonian import jordan_wigner_pe
3
from functools import reduce
4
from aux_files.qmmm.qchem.cppe_lib import PolEmbed
5
6
7
def generate_pe_spin_ham_restricted(v_pe):
8
9
# Total number of qubits equals the number of spin molecular orbitals
10
nqubits = 2 * v_pe.shape[0]
11
12
# Initialization
13
spin_pe_op = np.zeros((nqubits, nqubits))
14
15
for p in range(nqubits // 2):
16
for q in range(nqubits // 2):
17
18
# p & q have the same spin <a|a>= <b|b>=1
19
# <a|b>=<b|a>=0 (orthogonal)
20
spin_pe_op[2 * p, 2 * q] = v_pe[p, q]
21
spin_pe_op[2 * p + 1, 2 * q + 1] = v_pe[p, q]
22
23
return spin_pe_op
24
25
26
def pe_operator(dm, mol, mo_coeff, potential, elec_only=False, tolerance=1e-12):
27
28
# `dm` are in atomic orbitals
29
mype = PolEmbed(mol, potential)
30
E_pe, V_pe, V_es, V_ind = mype.get_pe_contribution(dm, elec_only)
31
32
#convert from `ao` to `mo`
33
V_pe_mo = reduce(np.dot, (mo_coeff.T, V_pe, mo_coeff))
34
35
obi_pe = generate_pe_spin_ham_restricted(V_pe_mo)
36
spin_pe_ham = jordan_wigner_pe(obi_pe, tolerance)
37
38
return spin_pe_ham, E_pe, V_pe_mo
39
40
41
def pe_operator_as(dm,
42
mol,
43
mo_coeff,
44
potential,
45
mc,
46
elec_only=False,
47
tolerance=1e-12):
48
49
# `dm` is in atomic orbitals
50
mype = PolEmbed(mol, potential)
51
E_pe, V_pe, V_es, V_ind = mype.get_pe_contribution(dm, elec_only)
52
#convert from `ao` to `mo`
53
V_pe_mo = reduce(np.dot, (mo_coeff.T, V_pe, mo_coeff))
54
V_pe_cas = V_pe_mo[mc.ncore:mc.ncore + mc.ncas, mc.ncore:mc.ncore + mc.ncas]
55
56
obi_pe = generate_pe_spin_ham_restricted(V_pe_cas)
57
spin_pe_ham = jordan_wigner_pe(obi_pe, tolerance)
58
59
return spin_pe_ham, E_pe, V_pe, V_pe_cas
60
61