-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for GPAW4QMCPACK converter
- Loading branch information
Juha Tiihonen
committed
Dec 20, 2021
1 parent
3295d77
commit a6e5c92
Showing
6 changed files
with
131 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
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
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,88 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
# unit test GPAW4QMCPACK | ||
|
||
# TODO: implement and test converter generated QMCPACK input | ||
|
||
def run_gpaw4qmcpack_test(test_name, g4q_exe, h5diff_exe): | ||
okay = True | ||
|
||
# Example invocation of converter | ||
#gpaw4qmcpack infile.gpw outfile.h5 --density | ||
|
||
infile = 'restart.gpw' | ||
outfile = 'test.orbs.h5' | ||
cmd = [g4q_exe,infile,outfile] | ||
|
||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | ||
stdout, stderr = p.communicate() | ||
|
||
file_out = open('stdout.txt', 'w') | ||
file_out.write(stdout) | ||
file_out.close() | ||
if len(stderr) > 0 : | ||
file_err = open('stderr.txt', 'w') | ||
file_err.write(stderr) | ||
file_err.close() | ||
|
||
ret = p.returncode | ||
|
||
if ret != 0: | ||
print("Return code nonzero: ", ret) | ||
okay = False | ||
|
||
if len(stderr.strip()) != 0: | ||
# some MPI output on stderr is okay | ||
# TODO - more general way of checking acceptable stderr strings | ||
if not stderr.startswith('Rank'): | ||
print("Stderr not empty") | ||
print(stderr) | ||
okay = False | ||
|
||
ret = os.system(h5diff_exe + ' -d 0.000001 gold.orbs.h5 test.orbs.h5') | ||
# if it's okay up to this point | ||
if ret==0 and okay: | ||
print(" pass") | ||
return True | ||
else: | ||
print("h5diff reported a difference") | ||
print(" FAIL") | ||
return False | ||
|
||
return okay | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description='Test gpaw4qmcpck') | ||
parser.add_argument('test_name', | ||
default='test_Si_diamond', | ||
help='Name of test to run (name of directory)') | ||
parser.add_argument('--exe', | ||
default='gpaw4qmcpack', | ||
help='Location of gpaw4qmcpack executable') | ||
parser.add_argument('--h5diff', | ||
default='h5diff', | ||
help='Location of h5diff executable') | ||
args = parser.parse_args() | ||
|
||
test_dir = args.test_name | ||
if not os.path.exists(test_dir): | ||
print("Test not found: ", test_dir) | ||
sys.exit(1) | ||
|
||
curr_dir = os.getcwd() | ||
os.chdir(test_dir) | ||
|
||
ret = run_gpaw4qmcpack_test(test_dir, args.exe, args.h5diff) | ||
|
||
os.chdir(curr_dir) | ||
|
||
if ret: | ||
sys.exit(0) | ||
sys.exit(1) | ||
|
Binary file not shown.
Binary file not shown.
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,23 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# This file provided just for reference, not executed in the test | ||
|
||
from ase.build import bulk | ||
from ase.units import Ry | ||
from gpaw import GPAW,PW,FermiDirac,setup_paths | ||
|
||
silicon = bulk('Si', 'diamond', a=5.459) | ||
|
||
econv = 1e-9*2*Ry | ||
ecut = 30*Ry | ||
silicon.calc = GPAW(xc='PBE', | ||
setups = {'default':'sg15'}, # Based on standard library of soft SG15 ecps | ||
mode = PW(ecut,force_complex_dtype=True), # give all modes explicitly | ||
txt = 'silicon.txt', | ||
kpts = (2,2,2), | ||
occupations = FermiDirac(0.1), | ||
convergence = {'energy':econv}, | ||
symmetry = 'off' | ||
) | ||
silicon.get_potential_energy() | ||
silicon.calc.write('Si.gpw',mode='all') # important to request mode='all' |