forked from oimeitei/quemb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditioned DMRG unittests (oimeitei#44)
* Added unittest for BE-DMRG (Insensitive to imports) * Remove redundant imports. --------- Co-authored-by: Shaun Weatherly <[email protected]>
- Loading branch information
1 parent
a44df05
commit 846a143
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
This script tests the QuEmb to block2 interface for performing ground state BE-DMRG. | ||
Author(s): Shaun Weatherly | ||
""" | ||
|
||
import os | ||
import unittest | ||
import tempfile | ||
from pyscf import gto, scf | ||
from molbe import fragpart, BE | ||
|
||
class TestBE_DMRG(unittest.TestCase): | ||
try: | ||
from pyscf import dmrgscf | ||
except ImportError: | ||
dmrgscf=None | ||
|
||
@unittest.skipIf(dmrgscf is None, "Module `pyscf.dmrgscf` not imported correctly.") | ||
def test_h8_sto3g_pipek(self): | ||
mol = gto.M() | ||
mol.atom = [['H', (0.,0.,i*1.2)] for i in range(8)] | ||
mol.basis = 'sto-3g' | ||
mol.charge = 0 | ||
mol.spin = 0 | ||
mol.build() | ||
self.molecular_DMRG_test(mol, 'be1', 100, 'H8 (BE1)', 'hchain_simple', -4.20236532) | ||
|
||
def molecular_DMRG_test(self, mol, be_type, maxM, test_name, frag_type, target, delta = 1e-4): | ||
with tempfile.TemporaryDirectory() as tmp: | ||
mf = scf.RHF(mol); mf.kernel() | ||
fobj = fragpart(frag_type=frag_type, be_type=be_type, mol=mol) | ||
mybe = BE(mf, fobj, lo_method='pipek', pop_method='lowdin') | ||
mybe.oneshot(solver='block2', | ||
scratch_dir=str(tmp), | ||
maxM=int(maxM), | ||
maxIter=30, | ||
force_cleanup=True) | ||
self.assertAlmostEqual(mybe.ebe_tot, target, | ||
msg = "BE Correlation Energy (Chem. Pot. Optimization) for " + test_name | ||
+ " does not match the expected correlation energy!", delta = delta) | ||
tmpfiles = [] | ||
for path, dir_n, file_n in os.walk(tmp, topdown=True): | ||
for n in file_n: | ||
if n.startswith('F.') or n.startswith('FCIDUMP') or n.startswith('node'): | ||
tmpfiles.append(n) | ||
try: | ||
assert len(tmpfiles) == 0 | ||
except Exception as inst: | ||
print(f"DMRG tempfiles not cleared correctly in {test_name}:\n", inst, tmpfiles) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |