def status(self): from os import path from time import time from aBuild.utility import grep import os ctime = time() with chdir(self.directory): outcar = self._check_file_exists('OUTCAR') incar = self._check_file_exists('INCAR') kpoints = self._check_file_exists('KPOINTS') potcar = self._check_file_exists('POTCAR') poscar = self._check_file_exists('POSCAR') if not (incar and kpoints and potcar and poscar): return 'not setup' if incar: relax = grep('INCAR', 'IBRION') if '-1' not in relax or relax is []: static = True else: static = False else: msg.warn("No INCAR found. That seems odd..") outcarfinishtags = self._check_tag_exists( 'OUTCAR', '------------------------ aborting loop because EDIFF is reached ----------------------------------------\n' ) or self._check_tag_exists('OUTCAR', ' writing wavefunctions') if outcar: time = path.getmtime('OUTCAR') sgrcon = grep('OUTCAR', 'SGRCON') if (ctime - time) < 60: folderstat = 'running' else: if static and self._check_tag_exists( 'OUTCAR', '------------------------ aborting loop because EDIFF is reached ----------------------------------------\n' ): print('Tripped 1') folderstat = 'done' elif self._check_tag_exists('OUTCAR', ' writing wavefunctions'): print('Tripped 2') folderstat = 'done' else: folderstat = 'running' else: folderstat = 'not started' # if outcar: #if 'OUTCAR' in files: print("Folder Stat {}".format(folderstat)) return folderstat
def _check_tag_exists(self,file,tag): from aBuild.utility import grep lines = grep(file,tag) if lines == []: return False else: return True
def setup_select(self): from os import path, remove from shutil import copy from glob import glob from aBuild.utility import sed, grep, tail, cat from aBuild.fitting.mtp import MTP from math import ceil # 1. Concatenate all of the candidate.cfg_# into one candidate.cfg # and remove all of the other ones. # 2. Concatenate all of the selection.log_* files into one file. # 3. Concatenate all of the relaxed.cfg_# into one file. This file should # get bigger and bigger with each iteration (Hopefully), but we don't ever # want to delete one of these files. # 4. Save the old new_training.cfg # 5. Build a submission script. # Find what iteration we are currently on. candIterationFiles = glob(path.join(self.root, "candidate_iteration_*")) relaxedIterationFiles = glob( path.join(self.root, "relaxed_iteration_*")) unrelaxedIterationFiles = glob( path.join(self.root, "unrelaxed_iteration_*")) if len(candIterationFiles) != len(relaxedIterationFiles) or len( candIterationFiles) != len(unrelaxedIterationFiles): msg.fatal( " I can't figure out what iteration we're on based on the files present. Have a look at all of the *_iteration_* files" ) if candIterationFiles != []: iteration = len(candIterationFiles) + 1 else: iteration = 1 # 1. Bring all of the candidate.cfg_* files together into one candFiles = glob(path.join(self.root, "candidate.cfg_*")) if candFiles != []: cat(candFiles, path.join(self.root, "candidate.temp"), remove=True) # Save a record copy( path.join(self.root, 'candidate.temp'), path.join(self.root, "candidate_iteration_" + str(iteration) + ".cfg")) # Prepare to select, which needs this file. copy(path.join(self.root, 'candidate.temp'), path.join(self.root, "candidate.cfg")) remove(path.join(self.root, 'candidate.temp')) else: msg.info("Can't find candidate.cfg_* files to concatenate") candidatesFile = path.join(self.root, 'candidate.cfg') grepResults = grep(candidatesFile, 'begin', '-in') nCandidates = len(grepResults) print(nCandidates, 'Found this many candidates') # Sometimes the candidate.cfg file is really big and it is best to split it up into 2 or 3 files and select in quasi-parallel fashion if nCandidates > 1e6: with open(candidatesFile, 'r') as f: for i, l in enumerate(f): pass nLines = i + 1 nFiles = ceil(nCandidates / 1e6) nConfigs = ceil(nCandidates / nFiles) msg.info("Found lots of candidates, splitting into multiple files") start = 1 for fileNo in range(1, nFiles + 1): print("Building candidate file no: {}".format(fileNo)) if fileNo < nFiles: end = int(grepResults[nConfigs * fileNo].split(':')[0]) - 1 sed( '-n', str(start) + ',' + str(end) + ' p', candidatesFile, "> " + path.join(self.root, 'candidate_part_' + str(fileNo) + '.cfg')) else: tail( candidatesFile, nLines - end + 1, "> " + path.join(self.root, 'candidate_part_' + str(fileNo) + '.cfg')) self.settings["execution"]["mem_per_cpu"] = '72' self.select_add( self.settings["execution"], exeCommand= 'mlp_release_version select-add pot.mtp train.cfg candidate_part_' + str(fileNo) + '.cfg new_training_' + str(fileNo) + '.cfg', jobfile='jobscript_select_' + str(fileNo) + '.sh') start = end + 1 # 2. selection.log_* logFiles = glob(path.join(self.root, "selection.log_*")) if logFiles != []: cat(logFiles, path.join(self.root, "selection.temp"), remove=True) copy( path.join(self.root, 'selection.temp'), path.join(self.root, "selection_iteration_" + str(iteration) + ".log")) remove(path.join(self.root, 'selection.temp')) else: msg.info("Can't find selection.log_* files to concatenate") # 3. relaxed.cfg_* relaxedFiles = glob(path.join(self.root, "relaxed.cfg_*")) if relaxedFiles != []: cat(relaxedFiles, path.join(self.root, "relaxed.temp"), remove=True) copy( path.join(self.root, 'relaxed.temp'), path.join(self.root, "relaxed_iteration_" + str(iteration) + ".cfg")) remove(path.join(self.root, 'relaxed.temp')) else: msg.info("Can't find relaxed.cfg_* files to concatenate") # 4. unrelaxed.cfg_* unrelaxedFiles = glob(path.join(self.root, "unrelaxed.cfg_*")) if unrelaxedFiles != []: cat(unrelaxedFiles, path.join(self.root, "unrelaxed.temp"), remove=True) # Save a record of this iteration. May consider copying this file to to-relax.cfg next time we relax copy( path.join(self.root, 'unrelaxed.temp'), path.join(self.root, "unrelaxed_iteration_" + str(iteration) + ".cfg")) remove(path.join(self.root, 'unrelaxed.temp')) else: msg.info("Can't find unrelaxed.cfg_* files to concatenate") # 5. relax_log.txt_* relaxLogFiles = glob(path.join(self.root, "relax_log.txt_*")) if relaxLogFiles != []: cat(relaxLogFiles, path.join(self.root, "relax_log.temp"), remove=True) copy( path.join(self.root, 'relax_log.temp'), path.join(self.root, "relax_log_iteration_" + str(iteration) + ".txt")) remove(path.join(self.root, 'relax_log.temp')) else: msg.info("Can't find relax_log.txt_* files to concatenate") #6. save the new_training.cfg if path.isfile(path.join(self.root, 'new_training.cfg')): copy( path.join(self.root, 'new_training.cfg'), path.join( self.root, "new_training_iteration_" + str(iteration - 1) + ".cfg")) remove(path.join(self.root, 'new_training.cfg')) # 7. Build job submission script. self.select_add(self.settings["execution"])
def status(self): from os import path from time import time from aBuild.utility import grep import os fTagStatic = '------------------------ aborting loop because EDIFF is reached ----------------------------------------\n' fTagRelax = ' writing wavefunctions' ctime = time() print('checking directory {}'.format(self.directory)) with chdir(self.directory): outcar = self._check_file_exists('OUTCAR') incar = self._check_file_exists('INCAR') kpoints = self._check_file_exists('KPOINTS') potcar = self._check_file_exists('POTCAR') poscar = self._check_file_exists('POSCAR') output = self._check_file_exists('vasp_output') oszicar = self._check_file_exists('OSZICAR') inputs = incar and kpoints and potcar and poscar ''' Check to see if the input files are present if they aren't, no need to proceed, just return 'not setup' ''' if not inputs: return 'not setup' ''' If the OUTCAR file is present, we know that we're either running, finished successfully, or finished with errors! ''' elif outcar: # OUTCAR present sgrcon = grep('vasp_output','SGRCON') tooclose = grep('vasp_output','HOPE') finalenergyline = grep('OUTCAR','free energy') generalerror = grep('vasp_output','ERROR') # Check to make sure I've converged electonically. if grep('OSZICAR','DAV:') != []: electronicIteration = int(grep('OSZICAR','DAV:')[-1].split()[1]) else: electronicIteration = 0 if grep('INCAR','nsw') != []: nsw = int(grep('INCAR','nsw')[0].split('=')[1]) if nsw == 0: nsw = 1 else: nsw = 1 if grep('OSZICAR','F=') != []: ionicIteration = int(grep('OSZICAR','F=')[-1].split()[0]) else: ionicIteration = 1 if grep('INCAR','nelm') != []: maxelectronic = grep('INCAR','nelm')[0].split('=')[1] else: maxelectronic = 60 if ionicIteration == nsw and int(electronicIteration) == int(maxelectronic): return 'unconverged' ''' Let's first check to see if this is a static calculation or a relaxation because the tag to check for is different.''' if incar: relax = grep('INCAR','IBRION') if '-1' not in relax or relax is []: static = True else: static = False else: return 'not setup' ''' Check finish tag for static calc''' if static and self._check_tag_exists('OUTCAR', fTagStatic): #finish tag found if finalenergyline != []: #Let's double check return 'done' else: # Apparently not, why? return 'idk' ''' Check finish tag for relax calc''' elif self._check_tag_exists('OUTCAR',fTagRelax): #Looks like it's done if finalenergyline != []: # Let's double check return 'done' else: # Apparently not, why? return 'idk' else: ''' Check how long since the last file write. If it was recent then we're probably running.''' time = path.getmtime('OUTCAR') if (ctime - time) < 3600: # If the OUTCAR was modified in the last hour # the calculation is probably still running. return 'running' elif sgrcon: return 'sgrcon' elif generalerror: return 'error' elif tooclose: return 'warning' else: return 'too long' else: return 'not started' if output: warning = grep('output','RRRRR') != [] or grep('output','AAAAAA') != [] if warning: return 'warning' return folderstat