Skip to content

Commit 7a1bdab

Browse files
Ohhminseokseunghoonlee89jiseong0626
authored
Pull Request for Multireference Methods Using Nonorthogonal Orbitals: GBCI, GB-PDFT, and XMS-GB-PDFT. (#200)
* sfnoci * sfnoci * sfnoci * Update * sfnoci * sfnoci * sfnoci * Update * Update * sfnoci * sfnoci * Merge remote-tracking branch 'upstream/master' * Bug Fix * Bug fix * Add trans_rdm1 * Rename sfnoci module to gbci * Add GBCI tests * Add GBCI examples * rename of functions * Clean up comments and references * rev comments and minor parts * Fix GBCI lint issues * Fix GBCI lint issues and reuse mcpdft _grid_ao2mo * Move GBCI examples * Address GBCI review comments * Add GBCI tests --------- Co-authored-by: Seunghoon Lee <seunghoonlee89@gmail.com> Co-authored-by: jiseong_QClab <fark4308@snu.ac.kr>
1 parent 7e3acd5 commit 7a1bdab

26 files changed

Lines changed: 6960 additions & 2182 deletions

‎examples/gbci/00-gbci.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
#
3+
# NH3-F2 GBCI example.
4+
5+
import numpy as np
6+
7+
from pyscf import gto, scf, gbci
8+
from pyscf.mcscf import addons
9+
10+
11+
ATOM = """
12+
H 2.490675 0.939499 -0.000156
13+
N 2.085280 0.000000 0.000003
14+
H 2.490739 -0.469633 0.813668
15+
H 2.490627 -0.469860 -0.813586
16+
F -0.222963 0.000000 0.000001
17+
F -1.710402 0.000000 0.000000
18+
"""
19+
20+
BASIS = "ccpvdz"
21+
NCAS = 3
22+
NELECAS = (2, 2)
23+
CAS_LIST = [9, 14, 15]
24+
GROUP_A = {"atom": [[0, 1, 2, 3], [4, 5]]}
25+
NROOTS = 4
26+
TARGET_S2 = 0.0
27+
28+
29+
mol = gto.M(
30+
atom=ATOM,
31+
basis=BASIS,
32+
charge=0,
33+
spin=0,
34+
verbose=5,
35+
)
36+
mf = scf.ROHF(mol).run()
37+
38+
mc = gbci.gbci(mf, NCAS, NELECAS, group_a=GROUP_A)
39+
mc.fcisolver.nroots = NROOTS
40+
mc.fcisolver.spin = 0
41+
mc.fix_spin_(ss=TARGET_S2)
42+
43+
mo = addons.sort_mo(mc, mf.mo_coeff, CAS_LIST, 1)
44+
e_tot, e_cas, ci = mc.kernel(mo)
45+
46+
print("GBCI energies:")
47+
print(np.asarray(e_tot))

‎examples/gbci/01-gbpdft.py‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
#
3+
# NH3-F2 GBPDFT example.
4+
5+
import numpy as np
6+
7+
from pyscf import gto, scf
8+
from pyscf.gbci import gbpdft
9+
from pyscf.mcscf import addons
10+
11+
12+
ATOM = """
13+
H 2.490675 0.939499 -0.000156
14+
N 2.085280 0.000000 0.000003
15+
H 2.490739 -0.469633 0.813668
16+
H 2.490627 -0.469860 -0.813586
17+
F -0.222963 0.000000 0.000001
18+
F -1.710402 0.000000 0.000000
19+
"""
20+
21+
BASIS = "ccpvdz"
22+
NCAS = 3
23+
NELECAS = (2, 2)
24+
CAS_LIST = [9, 14, 15]
25+
GROUP_A = {"atom": [[0, 1, 2, 3], [4, 5]]}
26+
OTXC = "tPBE"
27+
NROOTS = 4
28+
TARGET_S2 = 0.0
29+
30+
31+
mol = gto.M(
32+
atom=ATOM,
33+
basis=BASIS,
34+
charge=0,
35+
spin=0,
36+
verbose=5,
37+
)
38+
mf = scf.ROHF(mol).run()
39+
40+
mc = gbpdft.GBCI(mf, OTXC, NCAS, NELECAS, group_a=GROUP_A)
41+
mc.fcisolver.nroots = NROOTS
42+
mc.fcisolver.spin = 0
43+
mc.fix_spin_(ss=TARGET_S2)
44+
45+
mo = addons.sort_mo(mc, mf.mo_coeff, CAS_LIST, 1)
46+
e_tot, e_ot, e_gbci, e_cas, ci, mo_coeff, mo_energy = mc.kernel(mo)
47+
48+
print("GBPDFT total energies:")
49+
print(np.asarray(e_tot))
50+
print("GBPDFT on-top energies:")
51+
print(np.asarray(e_ot))
52+
print("GBCI reference energies:")
53+
print(np.asarray(e_gbci))

‎examples/gbci/02-xmsgbpdft.py‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
#
3+
# NH3-F2 XMS-GBPDFT example.
4+
5+
import numpy as np
6+
7+
from pyscf import gto, scf
8+
from pyscf.gbci import gbpdft
9+
from pyscf.mcscf import addons
10+
11+
12+
ATOM = """
13+
H 2.490675 0.939499 -0.000156
14+
N 2.085280 0.000000 0.000003
15+
H 2.490739 -0.469633 0.813668
16+
H 2.490627 -0.469860 -0.813586
17+
F -0.222963 0.000000 0.000001
18+
F -1.710402 0.000000 0.000000
19+
"""
20+
21+
BASIS = "ccpvdz"
22+
NCAS = 3
23+
NELECAS = (2, 2)
24+
CAS_LIST = [9, 14, 15]
25+
GROUP_A = {"atom": [[0, 1, 2, 3], [4, 5]]}
26+
OTXC = "tPBE"
27+
NROOTS = 4
28+
TARGET_S2 = 0.0
29+
30+
31+
mol = gto.M(
32+
atom=ATOM,
33+
basis=BASIS,
34+
charge=0,
35+
spin=0,
36+
verbose=5,
37+
)
38+
mf = scf.ROHF(mol).run()
39+
40+
mc = gbpdft.GBCI(mf, OTXC, NCAS, NELECAS, group_a=GROUP_A)
41+
mc.fcisolver.nroots = NROOTS
42+
mc.fcisolver.spin = 0
43+
mc.fix_spin_(ss=TARGET_S2)
44+
45+
mo = addons.sort_mo(mc, mf.mo_coeff, CAS_LIST, 1)
46+
weights = np.ones(NROOTS) / NROOTS
47+
xms = mc.multi_state(weights, "xms")
48+
e_tot, e_ot, e_gbci, e_cas, ci, mo_coeff, mo_energy = xms.kernel(
49+
mo_coeff=mo)
50+
51+
print("XMS-GBPDFT average energy:")
52+
print(e_tot)
53+
print("XMS-GBPDFT state energies:")
54+
print(np.asarray(xms.e_states))
55+
print("XMS-GBPDFT GBCI reference energies:")
56+
print(np.asarray(e_gbci))
57+
print("XMS-GBPDFT effective Hamiltonian:")
58+
print(np.asarray(xms.get_heff_pdft()))

‎pyscf/gbci/README.md‎

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# GBCI, GBPDFT, and XMS-GBPDFT
2+
3+
This directory contains GBCI, GBPDFT, and multi-state (XMS) GBPDFT tools.
4+
5+
GBCI is the renamed and reorganized form of the previous SFNOCI module. The
6+
new name reflects that the implementation is no longer limited to the old
7+
spin-flip NOCI interface and now serves as the grouped-bath CI reference used by
8+
GBPDFT and XMS-GBPDFT.
9+
10+
## Dependencies
11+
12+
GBPDFT uses the compiled GBCI helper library for fast on-top pair-density
13+
contractions. Build the PySCF-forge C extensions before running GBPDFT.
14+
15+
## Modules
16+
17+
Main GBCI modules:
18+
19+
- `pyscf.gbci.gbci`
20+
- `pyscf.gbci.direct_gbci`
21+
- `pyscf.gbci.rdm`
22+
- `pyscf.gbci.fasscf`
23+
24+
GBPDFT modules:
25+
26+
- `pyscf.gbci.gbpdft`
27+
- `pyscf.gbci.otpd`
28+
- `pyscf.gbci.msgbpdft`
29+
- `pyscf.gbci.xmsgbpdft`
30+
31+
## Import Changes
32+
33+
Use GBCI and GBPDFT through `pyscf.gbci`:
34+
35+
```python
36+
from pyscf import gbci
37+
from pyscf.gbci import gbpdft
38+
from pyscf.gbci import otpd
39+
```
40+
41+
Do not use the old SFNOCI or separate-package imports:
42+
43+
```python
44+
from pyscf import sfnoci
45+
from pyscf.sfnoci import sfnoci
46+
```
47+
48+
## GBCI Usage
49+
50+
```python
51+
from pyscf import gto, scf, gbci
52+
53+
mol = gto.M(
54+
atom="Li 0 0 0; H 0 0 1.6",
55+
basis="sto-3g",
56+
spin=0,
57+
verbose=0,
58+
)
59+
60+
mf = scf.ROHF(mol).run()
61+
62+
mc = gbci.gbci(mf, ncas=2, nelecas=(1, 1))
63+
mc.fcisolver.nroots = 1
64+
65+
e_gbci, e_cas, ci = mc.kernel()
66+
67+
print("GBCI energy:", e_gbci)
68+
```
69+
70+
`group_a` can be used to build grouped baths by active MO index, atom index, or
71+
occupation-pattern index:
72+
73+
```python
74+
gbci.gbci(mf, 2, (1, 1), group_a={"mo": [[0], [1]]})
75+
gbci.gbci(mf, 2, (1, 1), group_a={"atom": [[0], [1]]})
76+
gbci.gbci(mf, 2, (1, 1), group_a={"occ": [[0], [1], [2]]})
77+
```
78+
79+
## GBPDFT Usage
80+
81+
Import the GBPDFT module from `pyscf.gbci`:
82+
83+
```python
84+
from pyscf.gbci import gbpdft
85+
```
86+
87+
### Build GBPDFT directly from an SCF object
88+
89+
```python
90+
from pyscf import gto, scf
91+
from pyscf.gbci import gbpdft
92+
93+
mol = gto.M(
94+
atom="Li 0 0 0; H 0 0 1.6",
95+
basis="sto-3g",
96+
spin=0,
97+
verbose=0,
98+
)
99+
100+
mf = scf.ROHF(mol).run()
101+
102+
pdft = gbpdft.GBCI(
103+
mf,
104+
"tPBE",
105+
ncas=2,
106+
nelecas=(1, 1),
107+
)
108+
109+
pdft.fcisolver.nroots = 1
110+
111+
e_tot, e_ot, e_gbci, e_cas, ci, mo_coeff, mo_energy = pdft.kernel()
112+
113+
print("GBPDFT total energy:", e_tot)
114+
print("on-top energy:", e_ot)
115+
print("GBCI energy:", e_gbci)
116+
```
117+
118+
### Build GBPDFT from an existing GBCI object
119+
120+
```python
121+
from pyscf import gto, scf, gbci
122+
from pyscf.gbci import gbpdft
123+
124+
mol = gto.M(
125+
atom="Li 0 0 0; H 0 0 1.6",
126+
basis="sto-3g",
127+
spin=0,
128+
verbose=0,
129+
)
130+
131+
mf = scf.ROHF(mol).run()
132+
133+
mc = gbci.gbci(mf, ncas=2, nelecas=(1, 1))
134+
mc.fcisolver.nroots = 1
135+
136+
pdft = gbpdft.gbci(mc, "tPBE")
137+
138+
e_tot, e_ot, e_gbci, e_cas, ci, mo_coeff, mo_energy = pdft.kernel()
139+
140+
print("GBPDFT total energy:", e_tot)
141+
```
142+
143+
## XMS-GBPDFT Usage
144+
145+
XMS-GBPDFT is built from a GBPDFT object with `multi_state`:
146+
147+
```python
148+
import numpy as np
149+
from pyscf import gto, scf
150+
from pyscf.gbci import gbpdft
151+
152+
mol = gto.M(
153+
atom="Li 0 0 0; H 0 0 1.6",
154+
basis="sto-3g",
155+
spin=0,
156+
verbose=0,
157+
)
158+
159+
mf = scf.ROHF(mol).run()
160+
161+
pdft = gbpdft.GBCI(
162+
mf,
163+
"tPBE",
164+
ncas=2,
165+
nelecas=(1, 1),
166+
group_a={"mo": [[0], [1]]},
167+
)
168+
pdft.fcisolver.nroots = 2
169+
170+
xms = pdft.multi_state(np.ones(2) / 2, "xms")
171+
e_tot, e_ot, e_gbci, e_cas, ci, mo_coeff, mo_energy = xms.kernel()
172+
173+
print("XMS-GBPDFT average energy:", e_tot)
174+
print("XMS-GBPDFT state energies:", xms.e_states)
175+
print("XMS-GBPDFT GBCI reference energies:", e_gbci)
176+
print("XMS-GBPDFT effective Hamiltonian:", xms.get_heff_pdft())
177+
```
178+
179+
## Examples
180+
181+
Example input files are available in:
182+
183+
```text
184+
examples/gbci/
185+
```
186+
187+
For example:
188+
189+
```bash
190+
python examples/gbci/00-gbci.py
191+
python examples/gbci/01-gbpdft.py
192+
python examples/gbci/02-xmsgbpdft.py
193+
```

‎pyscf/gbci/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from pyscf.gbci.gbci import GBCI
2+
3+
def gbci(mf, ncas, nelecas, ncore=None, group_a=None):
4+
return GBCI(mf, ncas, nelecas, ncore=ncore, group_a=group_a)

0 commit comments

Comments
 (0)