Skip to content

Commit

Permalink
GPAW4QMCPACK: update copyright, use argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
Juha Tiihonen committed Dec 10, 2021
1 parent 31a2155 commit 3295d77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 56 deletions.
6 changes: 2 additions & 4 deletions src/QMCTools/Eshdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
## This file is distributed under the University of Illinois/NCSA Open Source License.
## See LICENSE file in top directory for details.
##
## Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
## Copyright (c) 2021 Juha Tiihonen and QMCPACK developers.
##
## File developed by: Juha Tiihonen, tiihonen@iki.fi, University of Jyvaskyla
##
## File created by: Juha Tiihonen, tiihonen@iki.fi, University of Jyvaskyla
#######################################################################################

#from numpy import array,pi,dot,real,imag,concatenate,unique,zeros
from numpy import array

# This file defines python classes to load/write data needed by the ESHDF file format.
Expand Down Expand Up @@ -121,8 +120,7 @@ def check_integrity(self):
# default: write to HDF5
def write(self, outfile = None):
if not self.loaded:
print('Must load data first')
return
raise(DataNotLoaded('Must load data first'))
#end if
if outfile is None:
outfile = self.outfile
Expand Down
4 changes: 2 additions & 2 deletions src/QMCTools/Eshdf_gpaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## This file is distributed under the University of Illinois/NCSA Open Source License.
## See LICENSE file in top directory for details.
##
## Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
## Copyright (c) 2021 Juha Tiihonen and QMCPACK developers.
##
## File developed by: Juha Tiihonen, tiihonen@iki.fi, University of Jyvaskyla
##
Expand Down Expand Up @@ -90,7 +90,7 @@ def load_gpaw_restart(
except:
print('ERROR: No wavefunctions found in the GPAW restart file {}'.format(filename))
print("Make sure to write the GPAW file with mode='all'!")
return
raise NoWavefunctionFound
#end try
if self.density:
# run SCF to re-populate density
Expand Down
60 changes: 10 additions & 50 deletions src/QMCTools/gpaw4qmcpack
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,25 @@
## This file is distributed under the University of Illinois/NCSA Open Source License.
## See LICENSE file in top directory for details.
##
## Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
## Copyright (c) 2021 Juha Tiihonen and QMCPACK developers.
##
## File developed by: Juha Tiihonen, tiihonen@iki.fi, University of Jyvaskyla
##
## File created by: Juha Tiihonen, tiihonen@iki.fi, University of Jyvaskyla
#######################################################################################

from Eshdf_gpaw import EshdfFilePwGpaw

def print_help_and_exit():
print('''
Usage: gpaw4qmcpack [options] INFILE [OUTFILE]
INFILE is a .gpw restart file
OUTFILE is an .h5 orbital file for QMCPACK [default=eshdf.h5]
options and <arguments> where needed:
import argparse

-d Convert charge density data. Default: no.
TROUBLESHOOTING:
The GPAW restart file (INFILE) must be created with mode='all' to include
the wave function information.
''')
exit()
#end def
from Eshdf_gpaw import EshdfFilePwGpaw

# parse command lines arguments
def parse_args(args):
if len(args)==1:
print_help_and_exit()
#end if
# parse arguments
infile_set = False
options = {}
outfile = 'eshdf.h5'
i = 1
while i<len(args):
arg = args[i]
if arg=='-d': # density
options['density'] = True
elif not infile_set:
infile = arg
# check if exists
infile_set = True
else:
outfile = arg
#end if
i += 1
#end while
return infile,outfile,options
#end def
parser = argparse.ArgumentParser(description='GPAW4QMCPACK')
parser.add_argument('infile',help='input .gpw restart file')
parser.add_argument('outfile',default='eshdf.h5',help='output .h5 orbital file')
parser.add_argument('-d','--density',action='store_true',help='whether or not to convert density')

if __name__=='__main__':
from sys import argv
infile,outfile,options = parse_args(argv)
eshdf = EshdfFilePwGpaw(infile=infile,outfile=outfile,**options)
eshdf.write(outfile)
args = vars(parser.parse_args())
eshdf = EshdfFilePwGpaw(**args)
eshdf.write()
print('Converted GPAW orbitals for QMCPACK!')
#end if

0 comments on commit 3295d77

Please sign in to comment.