Skip to content

Commit 377116a

Browse files
committed
preview of libDMET
1 parent 01829a6 commit 377116a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+32410
-0
lines changed

.gitignore

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
__pytest_cache__/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
60+
# Flask stuff:
61+
instance/
62+
.webassets-cache
63+
64+
# Scrapy stuff:
65+
.scrapy
66+
67+
# Sphinx documentation
68+
docs/_build/
69+
70+
# PyBuilder
71+
target/
72+
73+
# Jupyter Notebook
74+
.ipynb_checkpoints
75+
76+
# pyenv
77+
.python-version
78+
79+
# celery beat schedule file
80+
celerybeat-schedule
81+
82+
# SageMath parsed files
83+
*.sage.py
84+
85+
# Environments
86+
.env
87+
.venv
88+
env/
89+
venv/
90+
ENV/
91+
env.bak/
92+
venv.bak/
93+
94+
# Spyder project settings
95+
.spyderproject
96+
.spyproject
97+
98+
# Rope project settings
99+
.ropeproject
100+
101+
# mkdocs documentation
102+
/site
103+
104+
# mypy
105+
.mypy_cache/
106+
107+
# tmp
108+
tmp*
109+
*.tmp
110+
111+
# old
112+
old
113+
old/*
114+
115+
# wannier90 files
116+
*.win
117+
*.wout
118+
*.werr
119+
*.xsf
120+
*.chk
121+
*.mmn
122+
*.amn
123+
*.eig
124+
UNK*
125+
*.cube
126+
*.molden
127+
128+
frecord
129+
*.dat
130+
*.txt
131+
*.npy
132+
*.tga
133+
*.vmd
134+
*.png
135+
*.eps
136+
137+
*.h5
138+
*.lprof
139+
*.prof
140+
141+
# structure file
142+
POSCAR
143+
*.vasp
144+
145+
# FCIDUMP
146+
FCIDUMP
147+
148+
# pdos
149+
pdos*.pdf
150+
test.pdf
151+
152+
# gaopt
153+
GAOpt*
154+
155+
# xyz
156+
*.xyz

NOTICE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Copyright 2017-2021 The libDMET Developers.
2+
libDMET was developed by:
3+
4+
Zhi-Hao Cui <zhcui0408@gmail.com>
5+
Tianyu Zhu <tyzhu@caltech.edu>
6+
Bo-Xiao Zheng <boxiao.zheng@gmail.com>
7+
Chong Sun <csun2@caltech.edu>
8+
Linqing Peng <lppeng@caltech.edu>
9+
Xing Zhang <xzhang8@caltech.edu>
10+
Garnet Chan <gkc1000@gmail.com>

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
libDMET for realistic solids
2+
===============================================
3+
![Build Status](https://github.com/zhcui/libdmet_solid/workflows/CI/badge.svg)
4+
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
5+
6+
A library of density matrix embedding theory (DMET) for lattice models and realistic solids.
7+
8+
Installation
9+
------------
10+
11+
* Prerequisites
12+
- [PySCF](https://github.com/pyscf/pyscf/tree/dev) 1.7 or higher.
13+
14+
* Add libdmet top-level directory to your `PYTHONPATH` and you are all set!
15+
e.g. if libdmet_preview is installed in `/opt`, your `PYTHONPATH` should be
16+
17+
export PYTHONPATH=/opt/libdmet_preview:$PYTHONPATH
18+
19+
* Extensions
20+
- [Wannier90](https://github.com/wannier-developers/wannier90): optional, for wannier functions as local orbitals.
21+
- [Block2](https://github.com/block-hczhai/block2-preview.git): optional, for DMRG solver.
22+
- [Stackblock](https://github.com/sanshar/StackBlock): optional, for DMRG solver.
23+
- [Arrow](https://github.com/QMC-Cornell/shci/tree/master): optional, for SHCI solver.
24+
25+
Reference
26+
------------
27+
28+
The following papers should be cited in publications utilizing the libDMET program package:
29+
30+
Zhi-Hao Cui, Tianyu Zhu, Garnet Kin-Lic Chan, Efficient Implementation of Ab Initio Quantum Embedding in Periodic Systems:
31+
Density Matrix Embedding Theory, [J. Chem. Theory Comput. 2020, 16, 1, 119-129.](https://pubs.acs.org/doi/10.1021/acs.jctc.9b00933)
32+
33+
Tianyu Zhu, Zhi-Hao Cui, Garnet Kin-Lic Chan, Efficient Formulation of Ab Initio Quantum Embedding in Periodic Systems:
34+
Dynamical Mean-Field Theory, [J. Chem. Theory Comput. 2020, 16, 1, 141-153.](https://pubs.acs.org/doi/abs/10.1021/acs.jctc.9b00934)
35+
36+
Original [libDMET](https://bitbucket.org/zhengbx/libdmet) by Bo-Xiao Zheng.
37+
38+
Bug reports and feature requests
39+
--------------------------------
40+
Please submit tickets on the issues page.
41+
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#! /usr/bin/env python
2+
3+
import numpy as np
4+
import scipy.linalg as la
5+
6+
def test_hub1d_nib():
7+
from pyscf import lib
8+
from libdmet.utils import logger as log
9+
import libdmet.dmet.Hubbard as dmet
10+
log.verbose = "RESULT"
11+
12+
U = 4.0
13+
LatSize = 18
14+
ImpSize = 2
15+
Filling = 1.0 / 2
16+
int_bath = False
17+
restricted = True
18+
use_hcore_as_emb_ham = True
19+
MaxIter = 20
20+
21+
Mu = U * Filling
22+
last_dmu = 0.0
23+
24+
DiisStart = 4
25+
TraceStart = 3
26+
DiisDim = 4
27+
dc = dmet.FDiisContext(DiisDim)
28+
adiis = lib.diis.DIIS()
29+
adiis.space = DiisDim
30+
31+
ntotal = Filling * np.product(LatSize)
32+
if ntotal - np.round(ntotal) > 1e-5:
33+
log.warning("rounded total number of electrons to integer %d", np.round(ntotal))
34+
Filling=float(np.round(ntotal)) / np.product(LatSize)
35+
36+
Lat = dmet.ChainLattice(LatSize, ImpSize)
37+
nscsites = Lat.supercell.nsites
38+
Ham = dmet.Ham(Lat, U)
39+
Lat.setHam(Ham, use_hcore_as_emb_ham=use_hcore_as_emb_ham)
40+
vcor = dmet.PMInitGuess(ImpSize, U, Filling)
41+
42+
FCI = dmet.impurity_solver.FCI(restricted=restricted, tol=1e-11)
43+
solver = FCI
44+
45+
E_old = 0.0
46+
conv = False
47+
history = dmet.IterHistory()
48+
dVcor_per_ele = None
49+
50+
for iter in range(MaxIter):
51+
log.section("\nDMET Iteration %d\n", iter)
52+
53+
log.section("\nsolving mean-field problem\n")
54+
log.result("Vcor =\n%s", vcor.get())
55+
log.result("Mu (guess) = %20.12f", Mu)
56+
57+
rho, Mu, res = dmet.RHartreeFock(Lat, vcor, Filling, Mu, ires=True)
58+
E_mf = res["E"] / nscsites
59+
log.result("Mean-field energy (per site): %s", E_mf)
60+
61+
log.section("\nconstructing impurity problem\n")
62+
ImpHam, H1e, basis = dmet.ConstructImpHam(Lat, rho, vcor, int_bath=int_bath)
63+
ImpHam = dmet.apply_dmu(Lat, ImpHam, basis, last_dmu)
64+
basis_k = Lat.R2k_basis(basis)
65+
66+
log.section("\nsolving impurity problem\n")
67+
solver_args = {"nelec": (Lat.ncore+Lat.nval)*2, \
68+
"dm0": dmet.foldRho_k(res["rho_k"], basis_k)*2.0}
69+
70+
rhoEmb, EnergyEmb, ImpHam, dmu = \
71+
dmet.SolveImpHam_with_fitting(Lat, Filling, ImpHam, basis, solver, \
72+
solver_args)
73+
dmet.SolveImpHam_with_fitting.save("./frecord")
74+
75+
last_dmu += dmu
76+
rhoImp, EnergyImp, nelecImp = \
77+
dmet.transformResults(rhoEmb, EnergyEmb, basis, ImpHam, H1e, \
78+
lattice=Lat, last_dmu=last_dmu, int_bath=int_bath, \
79+
solver=solver, solver_args=solver_args)
80+
log.result("E (DMET) : %s", EnergyImp)
81+
82+
log.section("\nfitting correlation potential\n")
83+
vcor_new, err = dmet.FitVcor(rhoEmb, Lat, basis, \
84+
vcor, np.inf, Filling, MaxIter2 = 0)
85+
86+
# Fix trace
87+
if iter >= TraceStart:
88+
# to avoid spiral increase of vcor and mu
89+
log.result("Keep trace of vcor unchanged")
90+
ddiagV = np.average(np.diagonal(\
91+
(vcor_new.get()-vcor.get())[:2], 0, 1, 2))
92+
vcor_new = dmet.addDiag(vcor_new, -ddiagV)
93+
94+
# DIIS
95+
if iter >= DiisStart:
96+
pvcor = adiis.update(np.hstack((vcor_new.param)))
97+
dc.nDim = adiis.get_num_vec()
98+
else:
99+
pvcor = np.hstack((vcor_new.param))
100+
101+
dVcor_per_ele = la.norm(pvcor - vcor.param) / (len(vcor.param))
102+
vcor.update(pvcor)
103+
104+
dE = EnergyImp - E_old
105+
E_old = EnergyImp
106+
log.info("trace of vcor: %s", np.sum(np.diagonal((vcor.get())[:2], 0, 1, 2)))
107+
108+
history.update(EnergyImp, err, nelecImp, dVcor_per_ele, dc)
109+
history.write_table()
110+
dump_res_iter = np.array([Mu, last_dmu, vcor.param, rhoEmb, basis, rhoImp], dtype = object)
111+
np.save('./dmet_iter_%s.npy'%(iter), dump_res_iter)
112+
113+
if dVcor_per_ele < 1.0e-5 and abs(dE) < 1.0e-5 and iter > 3 :
114+
conv = True
115+
break
116+
117+
assert abs(EnergyImp - -0.552733945102) < 1e-4
118+
119+
if conv:
120+
log.result("DMET converged")
121+
else:
122+
log.result("DMET cannot converge")
123+
124+
if __name__ == "__main__":
125+
test_hub1d_nib()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/bin/env bash
2+
3+
rm -f ./*.lprof
4+
rm -f ./slurm*
5+
rm -rf ./tmp/
6+
rm -rf ./shdir/
7+
rm -rf ./__pycache__
8+
rm -f tmp*
9+
rm -f *.tmp
10+
rm -f *.chk
11+
rm -f *.h5
12+
rm -f frecord
13+
rm -f *.npy
14+
rm -f *.dat
15+
rm -f *.txt
16+
17+
rm -f *.win
18+
rm -f *.wout
19+
rm -f *.xsf
20+
rm -f *.mmn
21+
rm -f *.amn
22+
rm -f *.eig
23+
rm -f UNK*
24+
rm -f *.cube

0 commit comments

Comments
 (0)