3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-22 04:13:47 +01:00

Fixed problems with SC script

* Fixed obvious bugs:
  -- forgotten 'import re'
  -- import user script by name from string
  -- 'import converter' instead of 'import plovasp...'

* Number of iterations provided by the bash-script now has
an affect.

* Added a possibility to specify an alternative cfg-file
This commit is contained in:
Oleg E. Peil 2016-05-10 11:43:29 +02:00
parent 8b6ec2df6c
commit 6d1891a99a
2 changed files with 38 additions and 12 deletions

View File

@ -24,13 +24,14 @@
# #
################################################################################ ################################################################################
import os
import errno import errno
import os
import re
import time
import signal import signal
import sys import sys
import time
import pytriqs.utility.mpi as mpi import pytriqs.utility.mpi as mpi
import converters.plovasp.main as plovasp import converter
debug = True debug = True
# #
@ -87,7 +88,7 @@ class bcolors:
# #
# Main self-consistent cycle # Main self-consistent cycle
# #
def run_all(vasp_pid): def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter):
""" """
""" """
mpi.report(" Waiting for VASP lock to appear...") mpi.report(" Waiting for VASP lock to appear...")
@ -96,6 +97,7 @@ def run_all(vasp_pid):
vasp_running = True vasp_running = True
iter = 0
while vasp_running: while vasp_running:
if debug: print bcolors.RED + "rank %s"%(mpi.rank) + bcolors.ENDC if debug: print bcolors.RED + "rank %s"%(mpi.rank) + bcolors.ENDC
mpi.report(" Waiting for VASP lock to disappear...") mpi.report(" Waiting for VASP lock to disappear...")
@ -107,6 +109,15 @@ def run_all(vasp_pid):
mpi.report(" VASP stopped") mpi.report(" VASP stopped")
vasp_running = False vasp_running = False
break break
# Tell VASP to stop if the maximum number of iterations is reached
iter += 1
if iter = n_iter:
if mpi.is_master_node():
print "\n Maximum number of iterations reached."
print " Aborting VASP iterations...\n"
f_stop = open('STOPCAR', 'wt')
f_stop.write("LABORT = .TRUE.\n")
f_stop.close()
if debug: print bcolors.MAGENTA + "rank %s"%(mpi.rank) + bcolors.ENDC if debug: print bcolors.MAGENTA + "rank %s"%(mpi.rank) + bcolors.ENDC
err = 0 err = 0
@ -114,7 +125,7 @@ def run_all(vasp_pid):
try: try:
if debug: print bcolors.BLUE + "plovasp: rank %s"%(mpi.rank) + bcolors.ENDC if debug: print bcolors.BLUE + "plovasp: rank %s"%(mpi.rank) + bcolors.ENDC
if mpi.is_master_node(): if mpi.is_master_node():
plovasp.generate_and_output_as_text('plo.cfg', vasp_dir='./') converter.generate_and_output_as_text(cfg_file, vasp_dir='./')
# Read energy from OSZICAR # Read energy from OSZICAR
dft_energy = get_dft_energy() dft_energy = get_dft_energy()
except Exception, exc: except Exception, exc:
@ -167,19 +178,34 @@ def run_all(vasp_pid):
mpi.report("***Done") mpi.report("***Done")
def main(): def main():
import importlib
try: try:
vasp_pid = int(sys.argv[1]) vasp_pid = int(sys.argv[1])
except (ValueError, KeyError): except (ValueError, KeyError):
if mpi.is_master_node(): if mpi.is_master_node():
print "VASP process pid must be provided as the first argument" print "ERROR: VASP process pid must be provided as the first argument"
raise raise
try: try:
dmft_script = re.sub("\.py$", "", sys.argv[2]) n_iter = int(sys.argv[2])
except (ValueError, KeyError):
if mpi.is_master_node():
print "ERROR: Number of iterations must be provided as the second argument"
raise
try:
dmft_script = re.sub("\.py$", "", sys.argv[3])
except: except:
if mpi.is_master_node(): if mpi.is_master_node():
print "User-defined DMFT script must be provided as the second argument" print "ERROR: User-defined DMFT script must be provided as the third argument"
raise raise
# Optional parameter: config-file name
try:
cfg_file = sys.argv[4]
except KeyError:
cfg_file = 'plo.cfg'
# if len(sys.argv) > 1: # if len(sys.argv) > 1:
# vasp_path = sys.argv[1] # vasp_path = sys.argv[1]
# else: # else:
@ -191,9 +217,9 @@ def main():
# raise # raise
signal.signal(signal.SIGINT, sigint_handler) signal.signal(signal.SIGINT, sigint_handler)
from dmft_script import dmft_cycle dmft_mod = importlib.import_module(dmft_script)
run_all(vasp_pid) run_all(vasp_pid, dmft_mod.dmft_cycle, cfg_file, n_iter)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -83,5 +83,5 @@ stdbuf -o 0 $MPIRUN_CMD -np $NPROC "$VASP_DIR/vasp" &
PYTRIQS=@CMAKE_INSTALL_PREFIX@/bin/pytriqs PYTRIQS=@CMAKE_INSTALL_PREFIX@/bin/pytriqs
$MPIRUN_CMD -np $NPROC $PYTRIQS -m pytriqs.applications.dft.converters.plovasp.sc_dmft $(jobs -p) $DMFT_SCRIPT || kill %1 $MPIRUN_CMD -np $NPROC $PYTRIQS -m pytriqs.applications.dft.converters.plovasp.sc_dmft $(jobs -p) $NITER $DMFT_SCRIPT 'plo.cfg' || kill %1