-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil_CoreExt.py
157 lines (117 loc) · 4.14 KB
/
Util_CoreExt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Util_Orb
import pyscf
import pickle
# basically the procedure consists of first HF, then reoder, then perform ICIPT2
APP = "/home/nzhangcaltech/iCI_CXX/bin/iCIPT2_D2h_CSF_CoreExt.exe"
def _perform_hf_then_localize_orb(mol, CoreOrb: list, debug=False):
# perform HF
mf = pyscf.scf.RHF(mol)
mf.kernel()
if debug:
print("HF finished")
print("HF energy: ", mf.e_tot)
print(mf.mo_energy)
# split-localization of orbitals
mo = mf.mo_coeff
for core_orbs_info in CoreOrb:
loc = core_orbs_info["loc"]
mo = Util_Orb.split_loc_given_range(mol, mo, loc[0], loc[1])
mf.mo_coeff = mo
if debug:
for core_orbs_info in CoreOrb:
loc = core_orbs_info["loc"]
print(mo[:, loc[0]:loc[1]])
return mf
def _dump_CoreExt_FCIDUMP(mol, hf, CoreOrb: list, prefix, dump = True, debug=False, Rela4C=False, with_breit=False):
# dump the CoreExt FCIDUMP
# CoreOrb: [{"loc": [0, 2], "cas": [4, 4], "type": "C1s"}, ...]
# prefix: prefix of the FCIDUMP file
# return useful info for run the test!
FACTOR = 1
if Rela4C == True:
nao_2c = mol.nao * 2
assert hf.mo_coeff.shape[0] == nao_2c * 2
mo = hf.mo_coeff[:, nao_2c:]
if with_breit != True:
with_breit = False
FACTOR = 2
else:
Rela4C = False
with_breit = False
mo = hf.mo_coeff
nocc = mol.nelectron // 2
Res = []
for core_orbs_info in CoreOrb:
loc = core_orbs_info["loc"]
cas = core_orbs_info["cas"]
assert (loc[1] + cas[0] <= nocc)
if loc[1] + cas[0] == nocc and loc[0] == 0:
orb_order = list(range(FACTOR * mol.nao))
else:
orb_order = list(range(FACTOR * loc[0])) # the core that not involved
# the nor-core that not involved
orb_order.extend(range(FACTOR * loc[1], FACTOR * (nocc - cas[0])))
# the core that involved
orb_order.extend(list(range(FACTOR * loc[0], FACTOR * loc[1])))
# the nor-core that involved
orb_order.extend(list(range(FACTOR * (nocc - cas[0]), FACTOR * mol.nao)))
# add nsegment
# print("loc: ", loc)
# print("cas: ", cas)
nsegment = "0 %d %d %d %d 0 %d 0" % (
loc[0] + nocc - cas[0] - loc[1],
loc[1] - loc[0],
cas[0], cas[1],
mol.nao - nocc - cas[1]
)
if debug:
print("orb_order: ", orb_order)
import copy
mo = copy.deepcopy(hf.mo_coeff)
mo = mo[:, orb_order]
if FACTOR == 1:
orbsym = pyscf.symm.label_orb_symm(
mol, mol.irrep_id, mol.symm_orb, mo)
else:
# orbsym = [0] * len(orb_order)//FACTOR
orbsym = None
### dump the FCIDUMP ###
if dump:
if Rela4C is False:
pyscf.tools.fcidump.from_mo(
mol, prefix + core_orbs_info["type"], mo, orbsym)
else:
from Util_Rela4C import FCIDUMP_Rela4C
FCIDUMP_Rela4C(mol, hf, with_breit=with_breit, filename=prefix + core_orbs_info["type"], mode="outcore", orbsym_ID=orbsym)
Res.append({"loc": loc, "cas": cas, "type": core_orbs_info["type"],
"orb_order": orb_order, "orbsym": orbsym, "mo": mo,
"nsegment": nsegment})
return Res
if __name__ == "__main__":
### test C2H2 ###
CoreOrb_C2H4 = [
{"loc": [0, 2],
"cas": [4, 4],
"type": "C1s"},
]
mol = pyscf.gto.M(
verbose=4,
atom='''
C 0.0000000 -0.6654000 0.0000000
H 0.9220909 -1.2282467 0.0000000
H -0.9220909 -1.2282467 0.0000000
C 0.0000000 0.6654000 0.0000000
H -0.9220909 1.2282467 0.0000000
H 0.9220909 1.2282467 0.0000000
''',
basis='cc-pvdz',
spin=0,
charge=0,
symmetry='D2h',
)
mol.build()
hf = _perform_hf_then_localize_orb(mol, CoreOrb_C2H4, debug=True)
_dump_CoreExt_FCIDUMP(mol, hf, CoreOrb_C2H4, "FCIDUMP_C2H4_", debug=True)
task = "0 0 2 1 1 2 0 2 1 1"
# generate the input file
# run the test