def __init__(self, **kwargs): MASTObj.__init__(self, ALLOWED_KEYS, **kwargs) self.section_end = '$end' self.delimiter = ' ' # how we're breaking up each line self.section_parsers = {\ 'mast' : self.parse_mast_section, 'structure' : self.parse_structure_section, 'scaling' : self.parse_scaling_section, 'ingredients' : self.parse_ingredients_section, 'defects' : self.parse_defects_section, 'recipe' : self.parse_recipe_section, 'neb' : self.parse_neb_section, 'chemical_potentials' : self.parse_chemical_potentials_section, 'summary' : self.parse_summary_section, 'personal_recipe' : self.parse_personal_recipe_section } scratchpath = dirutil.get_mast_scratch_path() inputlocation = os.path.dirname(self.keywords['inputfile']) if (inputlocation == ""): self.logger = loggerutils.get_mast_logger("mast input parser") elif scratchpath not in inputlocation: self.logger = loggerutils.get_mast_logger("mast input parser") else: self.logger = loggerutils.get_mast_logger("mast input parser %s" % inputlocation)
def get_job_error_file(ingpath): """ Return the job error file full path Args: ingpath <str>: ingredient path """ logger = loggerutils.get_mast_logger("mast queue commands") jobid = get_last_jobid(ingpath) tryfile = my_queue_commands.get_approx_job_error_file(jobid) #logger.info("Try this search string: %s" % tryfile) if not os.path.isdir(ingpath): return None dircontents = os.listdir(ingpath) tryitems = list() for diritem in dircontents: if tryfile in diritem: tryitems.append(os.path.join(ingpath, diritem)) if len(tryitems) == 0: logger.warning("No job error file found for %s" % ingpath) return None if len(tryitems) > 1: logger.warning( "More than one job error file found for %s. Using first file %s" % (ingpath, tryitems[0])) return tryitems[0]
def __init__(self, inputtxt="", plot_threshold=0.01): """Initialize defect formation energy ingredient Args: inputtxt <str>: Input text file, containing: dfe_label1=perfect_label defected_label dfe_label2=perfect_label defected_label dfe_label3=perfect_label defected_label etc. bandgap_lda_or_gga=<float> bandgap_hse_or_expt=<float> plot_threshold <float>: Plotting threshold value """ self.logger = loggerutils.get_mast_logger("DFE ingredient") self.ingdir = os.getcwd() #Should be run in current directory self.recdir = os.path.dirname(self.ingdir) self.plot_threshold = plot_threshold ipdir = os.path.join(self.recdir, 'input.inp') os.chdir(self.recdir) #change to recipe directory ipparser = InputParser(inputfile=ipdir) self.input_options = ipparser.parse() os.chdir(self.ingdir) #change back to ingredient directory self.dirs = dict() self.bandgap_lda_or_gga = 0.0 self.bandgap_hse_or_expt = 0.0 self.read_input_file(inputtxt) self.e_defects = dict()
def __init__(self, inputtxt="", plot_threshold=0.01): """Initialize defect formation energy ingredient Args: inputtxt <str>: Input text file, containing: dfe_label1=perfect_label defected_label dfe_label2=perfect_label defected_label dfe_label3=perfect_label defected_label etc. bandgap_lda_or_gga=<float> bandgap_hse_or_expt=<float> plot_threshold <float>: Plotting threshold value """ self.logger = loggerutils.get_mast_logger("DFE ingredient") self.ingdir = os.getcwd() #Should be run in current directory self.recdir = os.path.dirname(self.ingdir) self.plot_threshold = plot_threshold ipdir = os.path.join(self.recdir,'input.inp') os.chdir(self.recdir) #change to recipe directory ipparser = InputParser(inputfile=ipdir) self.input_options = ipparser.parse() os.chdir(self.ingdir) #change back to ingredient directory self.dirs = dict() self.bandgap_lda_or_gga = 0.0 self.bandgap_hse_or_expt = 0.0 self.read_input_file(inputtxt) self.e_defects = dict()
def __init__(self, **kwargs): MASTObj.__init__(self, ALLOWED_KEYS, **kwargs) self.recipe_file = self.keywords['recipeFile'] self.input_options = self.keywords['inputOptions'] self.structure = self.keywords['structure'] self.work_dir = self.keywords['workingDirectory'] self.logger = loggerutils.get_mast_logger("recipe setup %s" % self.work_dir) self.metafile = Metadata(metafile='%s/metadata.txt' % self.work_dir) self.logger.debug('Setting up the recipe based on the personal recipe contents passed in self.recipe_file')
def __init__(self): self.scratch = dirutil.get_mast_scratch_path() self._ARCHIVE = dirutil.get_mast_archive_path() self.make_directories() self.logger = loggerutils.get_mast_logger('mast_monitor') self.logger.info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") self.logger.info("\nMAST monitor started at %s.\n" % time.asctime()) self.logger.info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") self.run(1)
def __init__(self, allowed_keys, **kwargs): allowed_keys_base = dict() allowed_keys_base.update(allowed_keys) MASTObj.__init__(self, allowed_keys_base, **kwargs) work_dir = '/'.join(self.keywords['name'].split('/')[:-1]) topmeta = Metadata(metafile='%s/metadata.txt' % work_dir) data = topmeta.read_data(self.keywords['name'].split('/')[-1]) self.meta_dict = dict() if data: for datum in data.split(';'): self.meta_dict[datum.split(':')[0]] = datum.split(':')[1].strip() self.metafile = Metadata(metafile='%s/metadata.txt' % self.keywords['name']) self.program = self.keywords['program_keys']['mast_program'].lower() self.logger = loggerutils.get_mast_logger(self.keywords['name']) sdir=os.path.join(os.path.dirname(self.keywords['name']),"structure_index_files") if os.path.exists(sdir): self.atomindex = AtomIndex(structure_index_directory=sdir) else: self.atomindex = None if self.program == 'vasp': self.checker = VaspChecker(name=self.keywords['name'], program_keys = self.keywords['program_keys'], structure = self.keywords['structure']) self.errhandler = VaspError(name=self.keywords['name'], program_keys = self.keywords['program_keys'], structure = self.keywords['structure']) elif self.program == 'vasp_neb': self.checker = VaspNEBChecker(name=self.keywords['name'], program_keys = self.keywords['program_keys'], structure = self.keywords['structure']) self.errhandler = VaspNEBError(name=self.keywords['name'], program_keys = self.keywords['program_keys'], structure = self.keywords['structure']) elif self.program == 'phon': self.checker = PhonChecker(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure']) self.errhandler = PhonError(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure']) elif self.program == 'lammps': self.checker = LammpsChecker(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure']) self.errhandler = GenericError(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure']) elif self.program =='structopt': self.checker = StructoptChecker(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure']) self.errhandler = GenericError(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure']) else: allowed_keys={'name','program_keys','structure'} self.checker = GenericChecker(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure']) self.errhandler = GenericError(name=self.keywords['name'],program_keys=self.keywords['program_keys'],structure=self.keywords['structure'])
def __init__(self, **kwargs): MASTObj.__init__(self, ALLOWED_KEYS, **kwargs) self.recipe_file = self.keywords['recipeFile'] self.input_options = self.keywords['inputOptions'] self.structure = self.keywords['structure'] self.work_dir = self.keywords['workingDirectory'] self.logger = loggerutils.get_mast_logger("recipe setup %s" % self.work_dir) self.metafile = Metadata(metafile='%s/metadata.txt' % self.work_dir) self.logger.debug( 'Setting up the recipe based on the personal recipe contents passed in self.recipe_file' )
def __init__(self, ingpath, keywords, archivelist=list()): """ Args: ingpath <str>: ingredient path keywords <dict>: keyword dictionary archivelist <list of str>: list of file names to be archived e.g. OUTCAR (optional) Returns: modifies submission script to add more nodes """ self.ingpath = ingpath self.archivelist = archivelist self.logger = loggerutils.get_mast_logger(self.ingpath) self.keywords = keywords
def __init__(self, working_directory): #self.name = name self.ingredients = dict() #name: status self.update_methods = dict() self.parents_to_check= dict() self.run_methods = dict() self.write_methods = dict() self.ready_methods = dict() self.complete_methods = dict() self.ingred_input_options = dict() self.summary_options = "" self.status="I" self.working_directory = working_directory self.logger = loggerutils.get_mast_logger(self.working_directory)
def __init__(self, working_directory): #self.name = name self.ingredients = dict() #name: status self.update_methods = dict() self.parents_to_check= dict() self.run_methods = dict() self.write_methods = dict() self.ready_methods = dict() self.complete_methods = dict() self.ingred_input_options = dict() self.summary_options = "" self.status="I" self.working_directory = working_directory self.logger = loggerutils.get_mast_logger(self.working_directory) self.ingred_to_check = ""
def __init__(self, ingpath, archivelist=list(), copyfromlist=list(), copytolist=list()): """ Args: (archivelist is different from the custodian version) ingpath <str>: ingredient path archivelist <list of str>: list of file names to archive copyfromlist <list of str>: list of file names to copy from copytolist <list of str>: list of file names to copy to; one-to -one correspondence with copyfromlist (e.g. copy from CONTCAR to POSCAR for VASP) Returns: Archives files to error.#.tar.gz """ self.ingpath = ingpath self.archivelist = list(archivelist) self.copyfromlist = list(copyfromlist) self.copytolist = list(copytolist) self.logger = loggerutils.get_mast_logger(self.ingpath)
def __init__(self, **kwargs): allowed_keys = { 'input_options': (InputOptions, None, 'Input options'), 'structure_index_directory': (str, "structure_index_files", "Structure index directory") } MASTObj.__init__(self, allowed_keys, **kwargs) self.logger = loggerutils.get_mast_logger("atom_indexing") self.sdir = self.keywords['structure_index_directory'] self.input_options = self.keywords['input_options'] if self.input_options == None: return self.scaling = self.input_options.get_item('scaling') self.logger.info("Scaling: %s" % self.scaling) if self.scaling == None: self.scaling = dict() self.startstr = self.input_options.get_item('structure','structure') self.atomcount=1 return
def __init__(self, **kwargs): allowed_keys = { "struc_work1": ( Structure, None, "First working Pymatgen Structure object (e.g. create a defect, or use work1 and work2 to interpolate positions)", ), "struc_work2": (Structure, None, "Second working Pymatgen Structure object"), "struc_init": (Structure, None, "Initial structure at the beginning of the MAST recipe"), "scaling_size": (str, None, "Scaling size"), "name": (str, get_mast_control_path(), "Name of ingredient"), } MASTObj.__init__(self, allowed_keys, **kwargs) rname = os.path.dirname(self.keywords["name"]) self.logger = loggerutils.get_mast_logger(rname) self.metafile = Metadata(metafile="%s/metadata.txt" % self.keywords["name"]) self.scaleinput = "" self.transform_scaling_size() return
def __init__(self, **kwargs): allowed_keys = { 'input_options': (InputOptions, None, 'Input options'), 'structure_index_directory': (str, "structure_index_files", "Structure index directory") } MASTObj.__init__(self, allowed_keys, **kwargs) self.logger = loggerutils.get_mast_logger("atom_indexing") self.sdir = self.keywords['structure_index_directory'] self.input_options = self.keywords['input_options'] if self.input_options == None: return self.scaling = self.input_options.get_item('scaling') self.logger.info("Scaling: %s" % self.scaling) if self.scaling == None: self.scaling = dict() self.startstr = self.input_options.get_item('structure', 'structure') self.atomcount = 1 return
def __init__(self, **kwargs): allowed_keys = { 'struc_work1': (Structure, None, 'First working Pymatgen Structure object (e.g. create a defect, or use work1 and work2 to interpolate positions)' ), 'struc_work2': (Structure, None, 'Second working Pymatgen Structure object'), 'struc_init': (Structure, None, 'Initial structure at the beginning of the MAST recipe'), 'scaling_size': (str, None, 'Scaling size'), 'name': (str, get_mast_control_path(), 'Name of ingredient') } MASTObj.__init__(self, allowed_keys, **kwargs) rname = os.path.dirname(self.keywords['name']) self.logger = loggerutils.get_mast_logger(rname) self.metafile = Metadata(metafile='%s/metadata.txt' % self.keywords['name']) self.scaleinput = "" self.transform_scaling_size() return
def get_job_error_file(ingpath): """ Return the job error file full path Args: ingpath <str>: ingredient path """ logger = loggerutils.get_mast_logger("mast queue commands") jobid = get_last_jobid(ingpath) tryfile = my_queue_commands.get_approx_job_error_file(jobid) #logger.info("Try this search string: %s" % tryfile) if not os.path.isdir(ingpath): return None dircontents = os.listdir(ingpath) tryitems = list() for diritem in dircontents: if tryfile in diritem: tryitems.append(os.path.join(ingpath, diritem)) if len(tryitems) == 0: logger.warning("No job error file found for %s" % ingpath) return None if len(tryitems) > 1: logger.warning("More than one job error file found for %s. Using first file %s" % (ingpath, tryitems[0])) return tryitems[0]
def __init__(self, allowed_keys, **kwargs): allowed_keys_base = dict() allowed_keys_base.update(allowed_keys) MASTObj.__init__(self, allowed_keys_base, **kwargs) self.logger = loggerutils.get_mast_logger(self.keywords['name'])
def __init__(self, allowed_keys, **kwargs): allowed_keys_base = dict() allowed_keys_base.update(allowed_keys) MASTObj.__init__(self, allowed_keys_base, **kwargs) work_dir = '/'.join(self.keywords['name'].split('/')[:-1]) topmeta = Metadata(metafile='%s/metadata.txt' % work_dir) data = topmeta.read_data(self.keywords['name'].split('/')[-1]) self.meta_dict = dict() if data: for datum in data.split(';'): self.meta_dict[datum.split(':')[0]] = datum.split( ':')[1].strip() self.metafile = Metadata(metafile='%s/metadata.txt' % self.keywords['name']) self.program = self.keywords['program_keys']['mast_program'].lower() self.logger = loggerutils.get_mast_logger(self.keywords['name']) sdir = os.path.join(os.path.dirname(self.keywords['name']), "structure_index_files") if os.path.exists(sdir): self.atomindex = AtomIndex(structure_index_directory=sdir) else: self.atomindex = None if self.program == 'vasp': self.checker = VaspChecker( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) self.errhandler = VaspError( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) elif self.program == 'vasp_neb': self.checker = VaspNEBChecker( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) self.errhandler = VaspNEBError( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) elif self.program == 'phon': self.checker = PhonChecker( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) self.errhandler = PhonError( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) elif self.program == 'lammps': self.checker = LammpsChecker( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) self.errhandler = GenericError( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) elif self.program == 'structopt': self.checker = StructoptChecker( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) self.errhandler = GenericError( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) else: allowed_keys = {'name', 'program_keys', 'structure'} self.checker = GenericChecker( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure']) self.errhandler = GenericError( name=self.keywords['name'], program_keys=self.keywords['program_keys'], structure=self.keywords['structure'])
def read_recipe(rawrlist, verbose=0): """Read the indented recipe. "Recipe" is a protected keyword signaling the recipe name. Args: rawrlist <list of str>: List of recipe lines from $recipe section of input file Returns: totpdict <dict>: Dictionary of [parentname][child]=[parent method group] totcdict <dict>: Dictionary of [childname]['parents']=[parent,parent,...] [childname]['method']=[method group] rname <str>: Recipe name """ logger = loggerutils.get_mast_logger("read_recipe") rfile = list(rawrlist) #MASTFile(filename) rdata = list() #preprocess by removing blank lines and any "recipe" line for line in rfile: duplicate = line if ((len(duplicate) - len(duplicate.lstrip(' '))) % 4 != 0): raise MASTError( "recipe/recipeutility", "Recipe at %s contains incorrect number of whitespace chars at the beginning of the line! Please convert all indentations to the appropriate number of groups of four spaces." % filename) if '\t' in line: raise MASTError( "recipe/recipeutility", "Recipe at %s contains tabs! Please convert all indentations to the appropriate number of groups of four spaces." % filename) myline = line.rstrip() #right-hand strip of carriage return only if len(myline) == 0: #blank line pass #elif (len(myline) > 6) and (myline[0:6].lower() == "recipe"): #rname = myline.split()[1] elif myline.strip()[0] == "#": #comment line, hash starting wherever pass else: rdata.append(myline) subrdict = split_into_subrecipes(rdata) howtorun = dict() parentstocheck = dict() howtoupdate = dict() for subkey in subrdict.keys(): idict = make_indentation_dictionary(subrdict[subkey]) if verbose == 1: ikeys = idict.keys() ikeys.sort() for indentkey in ikeys: logger.info("Indent: %s" % indentkey) for myitem in idict[indentkey]: logger.info(myitem) [onehtu, oneptc, onehtr] = parse_indentation_dict(idict) for pkey in onehtu.keys(): if not (pkey in howtoupdate.keys()): howtoupdate[pkey] = dict() for pmkey in onehtu[pkey].keys(): howtoupdate[pkey][pmkey] = onehtu[pkey][pmkey] for ckey in oneptc.keys(): if not (ckey in parentstocheck.keys()): parentstocheck[ckey] = list() parentstocheck[ckey].extend(oneptc[ckey]) howtorun[ckey] = onehtr[ckey] if verbose == 1: logger.info("How-to-update-children tree: ") keylist = howtoupdate.keys() keylist.sort() for htukey in keylist: logger.info("%s: %s" % (htukey, howtoupdate[htukey])) clist = parentstocheck.keys() clist.sort() logger.info("Parents-to-check tree: ") for ckey in clist: logger.info("%s: %s" % (ckey, parentstocheck[ckey])) logger.info("How-to-run tree: ") for ckey in clist: logger.info("%s: %s" % (ckey, howtorun[ckey])) return [howtoupdate, parentstocheck, howtorun]
def read_recipe(rawrlist, verbose=0): """Read the indented recipe. "Recipe" is a protected keyword signaling the recipe name. Args: rawrlist <list of str>: List of recipe lines from $recipe section of input file Returns: totpdict <dict>: Dictionary of [parentname][child]=[parent method group] totcdict <dict>: Dictionary of [childname]['parents']=[parent,parent,...] [childname]['method']=[method group] rname <str>: Recipe name """ logger=loggerutils.get_mast_logger("read_recipe") rfile = list(rawrlist) #MASTFile(filename) rdata = list() #preprocess by removing blank lines and any "recipe" line for line in rfile: duplicate = line if ((len(duplicate) - len(duplicate.lstrip(' '))) % 4 != 0): raise MASTError("recipe/recipeutility", "Recipe at %s contains incorrect number of whitespace chars at the beginning of the line! Please convert all indentations to the appropriate number of groups of four spaces." % filename) if '\t' in line: raise MASTError("recipe/recipeutility", "Recipe at %s contains tabs! Please convert all indentations to the appropriate number of groups of four spaces." % filename) myline = line.rstrip() #right-hand strip of carriage return only if len(myline) == 0: #blank line pass #elif (len(myline) > 6) and (myline[0:6].lower() == "recipe"): #rname = myline.split()[1] elif myline.strip()[0] == "#": #comment line, hash starting wherever pass else: rdata.append(myline) subrdict = split_into_subrecipes(rdata) howtorun=dict() parentstocheck=dict() howtoupdate=dict() for subkey in subrdict.keys(): idict = make_indentation_dictionary(subrdict[subkey]) if verbose == 1: ikeys = idict.keys() ikeys.sort() for indentkey in ikeys: logger.info("Indent: %s" % indentkey) for myitem in idict[indentkey]: logger.info(myitem) [onehtu, oneptc, onehtr]=parse_indentation_dict(idict) for pkey in onehtu.keys(): if not (pkey in howtoupdate.keys()): howtoupdate[pkey]=dict() for pmkey in onehtu[pkey].keys(): howtoupdate[pkey][pmkey]=onehtu[pkey][pmkey] for ckey in oneptc.keys(): if not (ckey in parentstocheck.keys()): parentstocheck[ckey]=list() parentstocheck[ckey].extend(oneptc[ckey]) howtorun[ckey]=onehtr[ckey] if verbose==1: logger.info("How-to-update-children tree: ") keylist = howtoupdate.keys() keylist.sort() for htukey in keylist: logger.info("%s: %s" % (htukey, howtoupdate[htukey])) clist = parentstocheck.keys() clist.sort() logger.info("Parents-to-check tree: ") for ckey in clist: logger.info("%s: %s" % (ckey, parentstocheck[ckey])) logger.info("How-to-run tree: ") for ckey in clist: logger.info("%s: %s" % (ckey, howtorun[ckey])) return [howtoupdate, parentstocheck, howtorun]