Exemple #1
0
def create_workflow_test_script(inputfile):
    myvars = get_variables()
    # set up testing directory tree
    wtdir = myvars['workflow_test_directory']
    mast_test_dir = os.path.join(wtdir, "no_directory_yet")
    while not (os.path.isdir(mast_test_dir)):
        timestamp = time.strftime("%Y%m%dT%H%M%S")
        mast_test_dir = os.path.join(wtdir, "output_test_%s" % timestamp)
        if not (os.path.isdir(mast_test_dir)):
            shutil.copytree("%s/mini_mast_tree" % wtdir, mast_test_dir)
    # set up output file and submission script
    shortname = inputfile.split(".")[0]
    output = "%s/output_%s" % (wtdir, shortname)
    submitscript = "%s/submit_%s.sh" % (wtdir, shortname)
    generic_script = "%s/generic_mast_workflow.sh" % wtdir
    bashcommand = "bash %s %s %s %s %s %s >> %s" % (
        generic_script, mast_test_dir, myvars["workflow_examples_located"],
        inputfile, myvars["workflow_activate_command"],
        myvars["workflow_testing_environment"], output)

    submitfile = MASTFile()
    submitfile.data.append(bashcommand + "\n")
    submitfile.to_file(submitscript)

    return [mast_test_dir, submitscript, output]
Exemple #2
0
    def create_archive_files(self):
        """Save off archive files.
            Returns:
                creates archive_input_options.txt
                creates archive_recipe_plan.txt
        """
        inputsave = MASTFile()
        inputsave.data = repr(self.input_options)
        inputsave.to_file(
            os.path.join(self.working_directory, 'archive_input_options.txt'))

        recipesave = MASTFile()
        recipesave.data = repr(self.recipe_plan)
        recipesave.to_file(
            os.path.join(self.working_directory, 'archive_recipe_plan.txt'))

        #pickle_plan = os.path.join(self.working_directory, 'archive_recipe_plan.pickle')
        #pm = PickleManager(pickle_plan)
        #pm.save_variable(self.recipe_plan)

        #pickle_options = os.path.join(self.working_directory, 'archive_input_options.pickle')
        #pm = PickleManager(pickle_options)
        #pm.save_variable(self.input_options)

        #create the *.py input script
        #ipc_obj = InputPythonCreator(input_options=self.input_options)
        #ipc_filename = ipc_obj.write_script(self.working_directory, 'archive_input_options.py')
        return
Exemple #3
0
 def test_update_children(self):
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("recipedir/metadata.txt")
     #metad = MASTFile("files/metadata_single")
     #metad.to_file("%s/metadata.txt" % ingdir)
     rp = RecipePlan("%s/recipedir" % testdir)
     rp.ingredients['ing1'] = "I"
     kdict = dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_xc'] = 'pw91'
     kdict['mast_kpoints'] = [1, 2, 3, "G"]
     rp.ingred_input_options['ing1'] = dict()
     rp.ingred_input_options['ing1'][
         'name'] = "%s/ing1" % rp.working_directory
     rp.ingred_input_options['ing1']['program_keys'] = kdict
     rp.ingred_input_options['ing1'][
         'structure'] = pymatgen.io.vaspio.Poscar.from_file(
             "files/perfect_structure").structure
     rp.update_methods['ing1'] = dict()
     rp.update_methods['ing1']['ing2a'] = [['give_structure']]
     rp.update_methods['ing1']['ing2b'] = [[
         'give_structure_and_restart_files'
     ]]
     rp.update_children('ing1')
     self.assertTrue(os.path.isfile("recipedir/ing2a/POSCAR"))
     self.assertTrue(os.path.isfile("recipedir/ing2b/POSCAR"))
     #CHGCAR softlink only sent to second child
     self.assertFalse(os.path.exists("recipedir/ing2a/CHGCAR"))
     self.assertTrue(os.path.exists("recipedir/ing2b/CHGCAR"))
Exemple #4
0
 def status_change_recommended(self, iname):
     """Check if a status change is recommended for the ingredient,
         as listed in the ingredient folder/change_status.txt.
         Args:
             iname <str>: ingredient name
         Returns:
             True if a status change was recommended, and 
                 changes the status of the ingredient in self.ingredients.
             False otherwise
     """
     statuspath = os.path.join(self.working_directory, iname, "change_status.txt")
     if not os.path.isfile(statuspath):
         return False
     statusfile = MASTFile(statuspath)
     newdata=list()
     changed=False
     for sline in statusfile.data: #status:recommend:timestamp
         if not "status_changed" in sline:
             newstatus = sline.split(":")[0]
             self.ingredients[iname]=newstatus
             newline = sline + ":status_changed:" + time.asctime() + "\n"
             self.logger.info("Status of %s changed to %s" % (iname, newstatus))
             changed=True
             newdata.append(newline)
         else:
             newdata.append(sline)
     statusfile.data=list(newdata)
     statusfile.to_file(statuspath)
     return changed
Exemple #5
0
 def test_update_children(self):
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("recipedir/metadata.txt")
     #metad = MASTFile("files/metadata_single")
     #metad.to_file("%s/metadata.txt" % ingdir)
     rp = RecipePlan("%s/recipedir" % testdir)
     rp.ingredients['ing1'] = "I"
     kdict=dict()
     kdict['mast_program']='vasp'
     kdict['mast_xc']='pw91'
     kdict['mast_kpoints']=[1,2,3,"G"]
     rp.ingred_input_options['ing1']=dict()
     rp.ingred_input_options['ing1']['name']="%s/ing1" % rp.working_directory
     rp.ingred_input_options['ing1']['program_keys']=kdict
     rp.ingred_input_options['ing1']['structure']=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     rp.update_methods['ing1']=dict()
     rp.update_methods['ing1']['ing2a']=[['give_structure']]
     rp.update_methods['ing1']['ing2b']=[['give_structure_and_restart_files']]
     rp.update_children('ing1')
     self.assertTrue(os.path.isfile("recipedir/ing2a/POSCAR"))
     self.assertTrue(os.path.isfile("recipedir/ing2b/POSCAR"))
     #CHGCAR softlink only sent to second child
     self.assertFalse(os.path.exists("recipedir/ing2a/CHGCAR"))
     self.assertTrue(os.path.exists("recipedir/ing2b/CHGCAR"))
Exemple #6
0
 def change_my_status(self, newstatus):
     """Change an ingredient status by writing the new status to 
         change_status.txt in the ingredient folder, to get picked
         up by the recipe plan.
         Args:
             newstatus <str>: New status to which to change the ingredient.
     """
     ingdir = self.keywords['name']
     oneup = os.path.dirname(ingdir)
     tryrecipe = os.path.basename(oneup)
     statuspath = ""
     if dirutil.dir_is_in_scratch(tryrecipe):
         statuspath = "%s/change_status.txt" % ingdir
     else:
         twoup = os.path.dirname(oneup)
         tryrecipe = os.path.basename(twoup)
         if dirutil.dir_is_in_scratch(tryrecipe):
             statuspath = "%s/change_status.txt" % oneup
         else:
             raise MASTError(self.__class__.__name__, "Cannot change status of ingredient %s as recipe %s or %s is not found in $MAST_SCRATCH." % (self.keywords['name'],oneup, twoup))
     if os.path.isfile(statuspath):
         statusfile = MASTFile(statuspath)
     else:
         statusfile=MASTFile()
     statusfile.data.append("%s:recommend:%s" % (newstatus, time.asctime()))
     statusfile.to_file(statuspath)
     self.logger.info("Recommending status change to %s" % newstatus)
Exemple #7
0
def create_workflow_test_script(inputfile):
    myvars = get_variables()
    # set up testing directory tree
    wtdir=myvars['workflow_test_directory']
    mast_test_dir=os.path.join(wtdir,"no_directory_yet")
    while not (os.path.isdir(mast_test_dir)):
        timestamp=time.strftime("%Y%m%dT%H%M%S")
        mast_test_dir = os.path.join(wtdir,"output_test_%s" % timestamp)
        if not (os.path.isdir(mast_test_dir)):
            shutil.copytree("%s/mini_mast_tree" % wtdir, mast_test_dir)
    # set up output file and submission script
    shortname = inputfile.split(".")[0]
    output="%s/output_%s" % (wtdir, shortname)
    submitscript="%s/submit_%s.sh" % (wtdir, shortname)
    generic_script="%s/generic_mast_workflow.sh" % wtdir
    bashcommand="bash %s %s %s %s %s %s >> %s" % (generic_script,
            mast_test_dir,
            myvars["workflow_examples_located"],
            inputfile,
            myvars["workflow_activate_command"],
            myvars["workflow_testing_environment"],
            output)

    submitfile=MASTFile()
    submitfile.data.append(bashcommand + "\n")
    submitfile.to_file(submitscript)
    
    return [mast_test_dir, submitscript, output]
Exemple #8
0
 def test_write_ingredient(self):
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("recipedir/metadata.txt")
     #metad = MASTFile("files/metadata_single")
     #metad.to_file("%s/metadata.txt" % ingdir)
     rp = RecipePlan("recipedir")
     rp.ingredients['ing2b'] = "I"
     kdict = dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_xc'] = 'pw91'
     kdict['mast_kpoints'] = [1, 2, 3, "G"]
     rp.ingred_input_options['ing2b'] = dict()
     rp.ingred_input_options['ing2b']['name'] = "recipedir/ing2b"
     rp.ingred_input_options['ing2b']['program_keys'] = kdict
     rp.ingred_input_options['ing2b'][
         'structure'] = pymatgen.io.vaspio.Poscar.from_file(
             "files/perfect_structure").structure
     rp.write_methods['ing2b'] = [['write_singlerun']]
     rp.write_ingredient('ing2b')
     self.assertTrue(os.path.isfile('recipedir/ing2b/INCAR'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/POSCAR'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/POTCAR'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/KPOINTS'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/submit.sh'))
Exemple #9
0
 def test_write_phonon_single(self):
     ingdir = "writedir/single_phonon_label1"
     topmetad = MASTFile("files/top_metadata_single_phonon")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single_phonon")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict = dict()
     kdict['mast_kpoints'] = [3, 3, 3, "G"]
     kdict['mast_xc'] = 'pbe'
     kdict['mast_program'] = 'vasp'
     kdict['mast_phonon_settings'] = dict()
     kdict['mast_phonon_settings']['phonon_center_site'] = "0.33 0.25 0.0"
     kdict['mast_phonon_settings']['phonon_center_radius'] = "1"
     kdict['mast_phonon_settings']['threshold'] = "0.075"
     my_structure = pymatgen.io.vaspio.Poscar.from_file(
         "files/perfect_structure").structure
     mywi = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     mywi.write_phonon_single()
     self.assertTrue(mywi.checker.is_ready_to_run())
     compare_phon_single = MASTFile("files/phon_single_POSCAR")
     phon_singlepos = MASTFile("%s/POSCAR" % ingdir)
     self.assertEqual(phon_singlepos.data, compare_phon_single.data)
    def evaluate_ga_vasp_and_update(self, childname=""):
        """Evaluate the Genetic Algorithm VASP ingredient.
        """
        raise NotImplementedError
        childpath = os.path.join(os.path.dirname(self.keywords['name']), childname)
        from mastlib.amy_ga_code import fitness_evaluation
        from MAST.ingredients.checker import VaspChecker
        from MAST.utility import MASTFile
        dircontents = os.listdir(self.keywords['name'])
        subfolders = list()
        for diritem in dircontents:
            fulldir = os.path.join(self.keywords['name'],diritem)
            if os.path.isdir(fulldir) and diritem.isdigit():
                subfolders.append(fulldir)
        
        energylist = list()
        structurelist = list()
        for subfolder in subfolders:
            mychecker = VaspChecker(subfolder, self.keywords['program_keys'], self.keywords['structure'])
            mystructure = mychecker.get_final_structure_from_directory()
            structurelist.append(mystructure)
            myenergy = mychecker.get_energy_from_energy_file()
            energylist.append(myenergy)

        [fitoutput, fitstructure] = fitness_evaluation.evaluate(structurelist, energylist)
        #If output is a structure or xyz file, could just write it directly.
        fitfile = MASTFile()
        fitfile.data = fitoutput
        import time
        timestamp = time.strftime("%Y%m%d_%H%M%S")
        outputname = "my_output_%s" % timestamp
        outputstrname = "my_structure_%s" % timestamp
        fitfile.to_file(os.path.join(childpath, outputname)) 
        fitstructure.write_file(os.path.join(childpath, outputstrname))
        return " %s and %s written in %s" % (outputname, outputstrname, childpath)
 def test_give_neb_structures_to_neb(self):
     ingdir = "%s/writedir/neb_labelinit-labelfin" % testdir
     recipedir = "%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_neb")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_neb")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict = dict()
     kdict['mast_program'] = 'vasp_neb'
     kdict['mast_neb_settings'] = dict()
     kdict['mast_neb_settings']['images'] = 3
     my_structure = pymatgen.io.vaspio.Poscar.from_file(
         "files/perfect_structure").structure
     myrelaxed = dict()
     for subdir in ['00', '01', '02', '03', '04']:
         os.mkdir("writedir/neb_labelinit-labelfin/%s" % subdir)
         myrelaxed[subdir] = MASTFile("files/POSCAR_%s" % subdir)
         myrelaxed[subdir].to_file(
             "writedir/neb_labelinit-labelfin/%s/CONTCAR" % subdir)
     myuci = ChopIngredient(name=ingdir,
                            program_keys=kdict,
                            structure=my_structure)
     myuci.give_neb_structures_to_neb("next_ingred")
     for subdir in ['01', '02', '03']:
         givenstr = MASTFile(
             "%s/writedir/next_ingred/parent_structure_labelinit-labelfin_%s"
             % (testdir, subdir))
         self.assertEqual(myrelaxed[subdir].data, givenstr.data)
Exemple #12
0
 def test_run_staged_ingredients(self):
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("recipedir/metadata.txt")
     #metad = MASTFile("files/metadata_single")
     #metad.to_file("%s/metadata.txt" % ingdir)
     rp = RecipePlan("recipedir")
     rp.ingredients['ing1']="C"
     rp.ingredients['ing2a'] = "W"
     rp.ingredients['ing2b'] = "S"
     rp.ingredients['ing3'] = "W"
     kdict=dict()
     kdict['mast_program']='vasp'
     kdict['mast_xc']='pw91'
     kdict['mast_kpoints']=[1,2,3,"G"]
     rp.ingred_input_options['ing2b']=dict()
     rp.ingred_input_options['ing2b']['name']="recipedir/ing2b"
     rp.ingred_input_options['ing2b']['program_keys']=kdict
     rp.ingred_input_options['ing2b']['structure']=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     rp.write_methods['ing2b']=[['write_singlerun']]
     rp.write_ingredient('ing2b')
     rp.ready_methods['ing2b']=[['ready_singlerun']]
     rp.run_methods['ing2b']=[['run_singlerun']]
     rp.complete_methods['ing2b']=[['complete_singlerun']]
     rp.run_staged_ingredients()
     mysubmit = MASTFile("test_control/submitlist")
     self.assertEquals(mysubmit.data[0],"recipedir/ing2b\n")
     self.assertEquals(rp.ingredients,{'ing1':'C','ing2a':'W','ing2b':'P','ing3':'W'})
Exemple #13
0
 def test_run_ingredient(self):
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("recipedir/metadata.txt")
     #metad = MASTFile("files/metadata_single")
     #metad.to_file("%s/metadata.txt" % ingdir)
     rp = RecipePlan("recipedir")
     rp.ingredients['ing2b'] = "I"
     kdict = dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_xc'] = 'pw91'
     kdict['mast_kpoints'] = [1, 2, 3, "G"]
     rp.ingred_input_options['ing2b'] = dict()
     rp.ingred_input_options['ing2b']['name'] = "recipedir/ing2b"
     rp.ingred_input_options['ing2b']['program_keys'] = kdict
     rp.ingred_input_options['ing2b'][
         'structure'] = pymatgen.io.vaspio.Poscar.from_file(
             "files/perfect_structure").structure
     rp.write_methods['ing2b'] = [['write_singlerun']]
     rp.write_ingredient('ing2b')
     rp.run_methods['ing2b'] = [['run_singlerun']]
     rp.run_ingredient('ing2b')
     mysubmit = MASTFile("test_control/submitlist")
     self.assertEquals(mysubmit.data[0], "recipedir/ing2b\n")
Exemple #14
0
 def test_copy_a_file_child_file_exists(self):
     allowed = dict()
     allowed['name'] = (str, "", "Directory name")
     shutil.copy('files/another_alphatest', 'childdir/alphatest')
     mybc = BaseChecker(allowed, name='files')
     mybc.copy_a_file('childdir', 'third_alphatest', 'alphatest')
     compare = MASTFile("files/another_alphatest")
     myfile = MASTFile("childdir/alphatest")
     self.assertEqual(compare.data, myfile.data)
Exemple #15
0
 def test_print_status(self):
     rp = RecipePlan("%s/recipedir" % testdir)
     rp.ingredients['ing1'] = "S"
     rp.ingredients['ing2a'] = "W"
     rp.ingredients['ing2b'] = "C"
     rp.ingredients['ing3'] = "P"
     rp.print_status()
     mystatus = MASTFile("recipedir/status.txt")
     status_compare = MASTFile("files/status_artificial.txt")
     self.assertEqual(mystatus.data, status_compare.data)
 def test_give_phonon_multiple_forces_and_displacements(self):
     ingdir="%s/writedir/single_phonon_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single_phonon")
     metad.to_file("%s/metadata.txt" % ingdir)
     mypos = MASTFile("files/phonon_initial_POSCAR")
     mypos.to_file("%s/POSCAR" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     my_structure = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     myxdat=dict()
     mydynmat=dict()
     for subdir in ['phon_01','phon_02','phon_03']:
         os.mkdir("%s/%s" % (ingdir,subdir))
         myxdat[subdir] = MASTFile("files/XDATCAR_%s" % subdir)
         myxdat[subdir].to_file("%s/%s/XDATCAR" % (ingdir,subdir))
         mydynmat[subdir] = MASTFile("files/DYNMAT_%s" % subdir)
         mydynmat[subdir].to_file("%s/%s/DYNMAT" % (ingdir, subdir))
     myuci = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     myuci.give_phonon_multiple_forces_and_displacements("next_ingred") 
     newpos = MASTFile("%s/writedir/next_ingred/POSCAR_prePHON" % testdir)
     newdyn = MASTFile("%s/writedir/next_ingred/DYNMAT" % testdir)
     newxdat = MASTFile("%s/writedir/next_ingred/XDATCAR" % testdir)
     comparepos = MASTFile("files/phonon_initial_POSCAR")
     comparedyn = MASTFile("files/DYNMAT_compare")
     comparexdat = MASTFile("%s/XDATCAR" % ingdir)
     self.assertEqual(newpos.data, comparepos.data)
     self.assertEqual(newdyn.data, comparedyn.data)
     self.assertEqual(newxdat.data, comparexdat.data)
Exemple #17
0
 def test_run_singlerun(self):
     #raise SkipTest
     ingdir = "%s/writedir/single_label1" % testdir
     recipedir = "%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict = dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_kpoints'] = [2, 2, 2, "M"]
     kdict['mast_xc'] = 'pw91'
     my_structure = Poscar.from_file("files/perfect_structure").structure
     mywr = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     mywr.write_singlerun()
     myri = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     myri.run_singlerun()
     self.assertTrue(myri.checker.is_ready_to_run())
     mysubmit = MASTFile("%s/submitlist" % self.test_control)
     self.assertEquals(mysubmit.data[0], "%s\n" % ingdir)
Exemple #18
0
 def test_inputpythoncreator(self):
     raise SkipTest
     myip = InputParser(inputfile='mast.inp')
     myoptions=myip.parse()
     myipc = InputPythonCreator(input_options=myoptions) 
     mylines=myipc.print_input_options()
     myfile = MASTFile()
     myfile.data = mylines
     myfile.to_file("./input_python_created")
     #print mylines
     self.assertTrue(filecmp.cmp("input_python_created","test_input_python_created"))
Exemple #19
0
 def test_start(self):
     #rfile=os.path.join(testdir,'personalized')
     wdir=os.path.join(testdir,'workdir')
     struc=None
     iopt=MAST.parsers.inputparser.InputParser(inputfile='input.inp').parse()
     rfile = iopt.get_item('personal_recipe', 'personal_recipe_list')
     myrs=RecipeSetup(recipeFile=rfile, workingDirectory=wdir, inputOptions=iopt, structure=struc)
     myrs.start()
     compare_metadata=MASTFile('compare_metadata.txt')
     myrs_metadata=MASTFile(os.path.join(wdir,'metadata.txt'))
     self.assertEqual(myrs_metadata.data, compare_metadata.data)
     dirlist=MAST.utility.dirutil.walkdirs(wdir)
     print dirlist
     compare_dirlist=list()
     compare_dirlist.append('defect_1nn_q=p0_opt1')
     compare_dirlist.append('defect_1nn_q=p0_opt2')
     compare_dirlist.append('defect_1nn_q=p0_stat')
     compare_dirlist.append('defect_purefin_q=p0_opt1')
     compare_dirlist.append('defect_purefin_q=p0_opt2')
     compare_dirlist.append('defect_purefin_q=p0_stat')
     compare_dirlist.append('defect_pureinit_q=p0_opt1')
     compare_dirlist.append('defect_pureinit_q=p0_opt2')
     compare_dirlist.append('defect_pureinit_q=p0_stat')
     compare_dirlist.append('defect_solute_q=p0_opt1')
     compare_dirlist.append('defect_solute_q=p0_opt2')
     compare_dirlist.append('defect_solute_q=p0_stat')
     compare_dirlist.append('diffcoeff_utility')
     compare_dirlist.append('inducedefect_1nn')
     compare_dirlist.append('inducedefect_purefin')
     compare_dirlist.append('inducedefect_pureinit')
     compare_dirlist.append('inducedefect_solute')
     compare_dirlist.append('neb_1nn-solute_q=p0_opt1')
     compare_dirlist.append('neb_1nn-solute_q=p0_opt2')
     compare_dirlist.append('neb_1nn-solute_q=p0_stat')
     compare_dirlist.append('neb_pureinit-purefin_q=p0_opt1')
     compare_dirlist.append('neb_pureinit-purefin_q=p0_opt2')
     compare_dirlist.append('neb_pureinit-purefin_q=p0_stat')
     compare_dirlist.append('perfect_opt1')
     compare_dirlist.append('perfect_opt2')
     compare_dirlist.append('perfect_stat')
     compare_dirlist.append('phonon_1nn-solute_q=p0_movingsolute')
     compare_dirlist.append('phonon_1nn_q=p0_solute')
     compare_dirlist.append('phonon_pureinit-purefin_q=p0_movingsolvent')
     compare_dirlist.append('phonon_pureinit_q=p0_solvent')
     compare_dirlist_withpath=list()
     for diritem in compare_dirlist:
         compare_dirlist_withpath.append(os.path.join(wdir,diritem))
     mdiff=self.maxDiff
     self.maxDiff=None
     self.assertItemsEqual(dirlist,compare_dirlist_withpath)
     self.maxDiff=mdiff
Exemple #20
0
 def test_get_my_phonon_params(self):
     ingdir = "writedir/single_phonon_label1"
     topmetad = MASTFile("files/top_metadata_single_phonon")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single_phonon")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict = dict()
     kdict['mast_kpoints'] = [3, 3, 3, "G"]
     kdict['mast_xc'] = 'pbe'
     kdict['mast_program'] = 'vasp'
     kdict['mast_phonon_settings'] = dict()
     kdict['mast_phonon_settings']['phonon_center_site'] = "0.33 0.25 0.0"
     kdict['mast_phonon_settings']['phonon_center_radius'] = "1"
     kdict['mast_phonon_settings']['threshold'] = "0.075"
     my_structure = pymatgen.io.vaspio.Poscar.from_file(
         "files/perfect_structure").structure
     mywi = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     [mysite, myrad, mythresh] = mywi.get_my_phonon_params()
     self.assertEqual(mysite, "0.33 0.25 0.0")
     self.assertEqual(myrad, "1")
     self.assertEqual(mythresh, "0.075")
 def test_ready_neb_subfolders(self):
     ingdir = "%s/writedir/single_label1" % testdir
     recipedir = "%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict = dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_kpoints'] = [2, 2, 2, "M"]
     kdict['mast_xc'] = 'pw91'
     kdict['mast_neb_settings'] = dict()
     kdict['mast_neb_settings']['images'] = 3
     my_structure = pymatgen.io.vaspio.Poscar.from_file(
         "files/perfect_structure").structure
     mywr = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     for subdir in ['00', '01', '02', '03', '04']:
         subname = "%s/%s" % (ingdir, subdir)
         os.mkdir(subname)
         mywr.keywords['name'] = subname
         mywr.checker.keywords['name'] = subname
         if not subdir in ['00', '04']:
             mywr.write_singlerun()
             mywr.write_submit_script()
     myrdi = ChopIngredient(name=ingdir,
                            program_keys=kdict,
                            structure=my_structure)
     self.assertTrue(myrdi.ready_neb_subfolders())
     os.remove("%s/01/POSCAR" % ingdir)
     self.assertFalse(myrdi.ready_neb_subfolders())
 def test_ready_singlerun(self):
     ingdir = "%s/writedir/single_label1" % testdir
     recipedir = "%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" %
                          testdir)  #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict = dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_kpoints'] = [2, 2, 2, "M"]
     kdict['mast_xc'] = 'pw91'
     my_structure = pymatgen.io.vaspio.Poscar.from_file(
         "files/perfect_structure").structure
     mywr = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     mywr.write_singlerun()
     myrdi = ChopIngredient(name=ingdir,
                            program_keys=kdict,
                            structure=my_structure)
     self.assertTrue(myrdi.ready_singlerun())
     os.remove("%s/POSCAR" % ingdir)
     self.assertFalse(myrdi.ready_singlerun())
Exemple #23
0
    def create_archive_files(self):
        """Save off archive files.
            Returns:
                creates archive_input_options.txt
                creates archive_recipe_plan.txt
        """
        inputsave = MASTFile()
        inputsave.data = repr(self.input_options)
        inputsave.to_file(os.path.join(self.working_directory, 'archive_input_options.txt'))

        recipesave = MASTFile()
        recipesave.data = repr(self.recipe_plan)
        recipesave.to_file(os.path.join(self.working_directory, 'archive_recipe_plan.txt'))

        #pickle_plan = os.path.join(self.working_directory, 'archive_recipe_plan.pickle')
        #pm = PickleManager(pickle_plan)
        #pm.save_variable(self.recipe_plan)
        
        #pickle_options = os.path.join(self.working_directory, 'archive_input_options.pickle')
        #pm = PickleManager(pickle_options)
        #pm.save_variable(self.input_options)

        #create the *.py input script
        #ipc_obj = InputPythonCreator(input_options=self.input_options)
        #ipc_filename = ipc_obj.write_script(self.working_directory, 'archive_input_options.py')
        return
Exemple #24
0
 def test_get_statuses_from_file(self):
     rp = RecipePlan("recipedir")
     mystatus = MASTFile("files/status_random.txt")
     self.assertRaises(MASTError, rp.get_statuses_from_file)
     mystatus.to_file("recipedir/status.txt")
     rp.ingredients['ing1']="I"
     rp.ingredients['ing2a']="I"
     rp.ingredients['ing2b']="I"
     self.assertRaises(MASTError,rp.get_statuses_from_file)
     rp.ingredients['ing3']="I"
     rp.get_statuses_from_file()
     statusdict=dict()
     statusdict={'ing1':'alpha','ing2a':'beta','ing2b':'gamma','ing3':'delta'}
     self.assertEquals(rp.ingredients, statusdict)
Exemple #25
0
 def test_parse_phonon_section(self):
     raise SkipTest
     #Phonon section in input file is now obsolete!
     myip = InputParser(inputfile="neb_with_phonons.inp")
     minput = MASTFile("%s/phonon_lines.txt" % testdir)
     cleanlines = list()
     for line in minput.data:
         cleanlines.append(line.strip())
     myoptions = InputOptions()
     myip.parse_phonon_section('phonon', cleanlines, myoptions)
     print myoptions
     mdict = dict()
     mdict['perfect'] = dict()
     mdict['perfect']['phonon_center_site'] = '0.5 0.5 0'
     mdict['perfect']['phonon_center_radius'] = '1'
     mdict['vac1'] = dict()
     mdict['vac1']['phonon_center_site'] = '0.5 0.5 0'
     mdict['vac1']['phonon_center_radius'] = '1'
     mdict['vac2'] = dict()
     mdict['vac2']['phonon_center_site'] = '0.0 0.0 0'
     mdict['vac2']['phonon_center_radius'] = '1'
     mdict['vac1-vac2'] = dict()
     mdict['vac1-vac2']['phonon_center_site'] = '0.25 0.25 0'
     mdict['vac1-vac2']['phonon_center_radius'] = '1'
     self.assertEqual(myoptions.options['phonon']['phonon'], mdict)
Exemple #26
0
 def read_input_file(self, inputtxt=""):
     """Read the input file.
         Args:
             inputtxt <str>: Input file name (shortname)
         Returns:
             Sets self.dirs with perfect and defected directories
             Sets self.bandgap_lda_or_gga
             Sets self.bandgap_hse_or_expt
     """
     ifpath = os.path.join(self.ingdir, inputtxt)
     ifile = MASTFile(ifpath)
     for dline in ifile.data:
         dline = dline.strip()
         if dline[0] == "#":
             continue
         if len(dline) == 0:
             continue
         dsplit = dline.split("=", 1)
         dkey = dsplit[0]
         dval = dsplit[1]
         if dkey[0:4] == "dfe_":
             mylabel = dkey[4:]
             myperfect = dval.split()[0]
             mydefected = dval.split()[1]
             self.dirs[mylabel] = dict()
             self.dirs[mylabel]['perfect'] = myperfect
             self.dirs[mylabel]['defected'] = mydefected
         elif dkey == "bandgap_lda_or_gga":
             self.bandgap_lda_or_gga = float(dval)
         elif dkey == "bandgap_hse_or_expt":
             self.bandgap_hse_or_expt = float(dval)
         else:
             pass
     return
Exemple #27
0
 def test_parse_structure_section_noposfile(self):
     myip = InputParser(inputfile="neb_with_phonons.inp")
     minput = MASTFile("%s/structure_noposfile_lines.txt" % testdir)
     cleanlines = list()
     for line in minput.data:
         cleanlines.append(line.strip())
     myoptions = InputOptions()
     myip.parse_structure_section('structure', cleanlines, myoptions)
     #print myoptions
     self.assertEqual(myoptions.options['structure']['atom_list'],
                      ['Al', 'Mg', 'Al', 'Fe'])
     self.assertEqual(myoptions.options['structure']['coord_type'],
                      'fractional')
     self.assertTrue(
         np.array_equal(myoptions.options['structure']['lattice'],
                        np.array([[3.5, 1, 2], [3, 3.5, 4], [5, 6, 3.5]])))
     self.assertTrue(
         np.array_equal(
             myoptions.options['structure']['coordinates'],
             np.array([[0, 0, 0], [0.5, 0.5, 0], [0, 0.5, 0.5],
                       [0.5, 0, 0.5]])))
     self.assertItemsEqual(myoptions.options['structure']['element_map'],
                           dict({
                               'X1': 'Al',
                               'X2': 'Mg',
                               'X3': 'Fe'
                           }))
Exemple #28
0
def main(ingname=""):
    """Get the last lattice from an ingredient.
        Args:
            ingname <str>: Ingredient name, full path
        Returns:
            <string>: "Last lattice (Angstroms);scale, a, b, c", ex:
                "Last lattice (Angstroms); scale 1, 4.01 0.2 0, 0 4.01 0, 
                        0.1 0.1 4.01"
    """
    trymeta = "%s/metadata.txt" % ingname
    frontstr = "Last lattice (Angstroms);"
    if os.path.isfile(trymeta):
        mymeta = Metadata(metafile=trymeta)
        myprogram = mymeta.read_data("program")
    else:
        myprogram = "None"
    if myprogram in ['vasp', 'vasp_neb']:
        if os.path.isdir("%s/01" % ingname):
            tryfile = "%s/01/CONTCAR" % ingname
        else:
            tryfile = "%s/CONTCAR" % ingname
        cfile = MASTFile(tryfile)
        if len(cfile.data) == 0:
            return "%s N/A" % frontstr
        scale = cfile.data[1].strip()
        avec = cfile.data[2].strip()
        bvec = cfile.data[3].strip()
        cvec = cfile.data[4].strip()
        return "%s scale %s, %s, %s, %s" % (frontstr, scale, avec, bvec, cvec)
    else:
        return "%s N/A" % frontstr
Exemple #29
0
 def test_simple_optimization(self):
     [mystatus, my_test_dir
      ] = workflow_setup.generic_submit("simple_optimization.inp")
     if mystatus == "Unfinished":
         self.assertTrue(False)
         return
     elif mystatus == "Completed":
         recipedir = workflow_setup.get_finished_recipe_dir(my_test_dir)
         myfile = MASTFile(os.path.join(recipedir, "SUMMARY.txt"))
         okays = 0
         for myline in myfile.data:
             if "defect_int1_stat" in myline:
                 myenergy = myline.split()[-1]
                 self.assertEquals(myenergy, "-13.953")
                 okays = okays + 1
             if "defect_vac1_stat" in myline:
                 myenergy = myline.split()[-1]
                 self.assertEquals(myenergy, "-10.623")
                 okays = okays + 1
             if "defect_sub1_stat" in myline:
                 myenergy = myline.split()[-1]
                 self.assertEquals(myenergy, "-20.145")
                 okays = okays + 1
         self.assertEquals(okays, 3)
         return
     else:
         self.assertTrue(False)
         return
 def print_table(self,scsize):
     if not self.e_defects:
         self._calculate_defect_formation_energies(scsize)
     myfile = MASTFile()
     for conditions, defects in self.e_defects.items():
         myfile.data.append('\n\nDefect formation energies for %s conditions.\n' % conditions.upper())
         myfile.data.append('%-20s | %10s\n' % ('Defect', 'DFE'))
         myfile.data.append('---------------------------------\n')
         for defect, energies in defects.items():
             for energy in energies:
                 myfile.data.append('%-14s(q=%2i) | %8.4f\n' % (defect, energy[0], energy[1]))
             myfile.data.append(str()) # Add a blank line here
         myfile.data.append('---------------------------------\n')
     myfile.to_file(os.path.join(os.getcwd(),"dfe.txt"))
     for line in myfile.data:
         print line.strip()
Exemple #31
0
 def test_vasp_kpoints_setup_from_metafile(self):
     kdict = dict()
     mymeta = MASTFile("childdir/metadata.txt")
     mymeta.data.append("kpoints = 3x1x7 G 0.5 0.2 .1\n")
     mymeta.to_file("childdir/metadata.txt")
     mymeta2 = MASTFile("childdir/metadata.txt")
     print mymeta2.data
     myvc = VaspChecker(name="childdir", program_keys=kdict)
     mykpt = myvc._vasp_kpoints_setup()
     kpt_compare = pymatgen.io.vaspio.Kpoints.from_file("files/KPOINTS_317G")
     self.assertEqual(kpt_compare.kpts[0][0], mykpt.kpts[0][0])
     self.assertEqual(kpt_compare.kpts[0][1], mykpt.kpts[0][1])
     self.assertEqual(kpt_compare.kpts[0][2], mykpt.kpts[0][2])
     self.assertEqual(kpt_compare.num_kpts, mykpt.num_kpts)
     self.assertEqual(kpt_compare.style, mykpt.style)
     # self.assertEqual(kpt_compare.kpts_shift, mykpt.kpts_shift)
     self.assertEqual((0.5, 0.2, 0.1), mykpt.kpts_shift)
Exemple #32
0
 def test_dfe_tool(self):
     import subprocess
     os.chdir("archive/GaAs_defects_AsGa_recipe_defects_20131125T220427/dfe_ingredient")
     mydfetest=subprocess.Popen(["mast_defect_formation_energy dfe_input.txt"],shell=True)
     mydfetest.wait()
     os.chdir(testdir)
     compare_walk = dirutil.walkfiles("compare_results")
     compare_walk.remove("compare_results/__init__.py")
     compare_walk.remove("compare_results/__init__.pyc")
     res_walk = dirutil.walkfiles("archive/GaAs_defects_AsGa_recipe_defects_20131125T220427/dfe_ingredient/dfe_results")
     compare_walk.sort()
     res_walk.sort()
     self.assertEqual(len(compare_walk), len(res_walk))
     for idx in range(0,len(compare_walk)):
         compfile = MASTFile(compare_walk[idx])
         myfile = MASTFile(res_walk[idx])
         self.assertEqual(compfile.data, myfile.data)
Exemple #33
0
def main(mydir="", fname="", startat=0, childdir=""):
    """This method makes POSCAR-containing subfolders from a 
        list of structures,
        in childdir if a child directory is given, or in 
        mydir otherwise.
        File fname must reside in directory mydir.
        Args:
            mydir <str>: Ingredient directory
            fname <str>: File containing list of structures
            startat <str, will be converted to int>: 
                0 (default) - start subfolders at 00
                1 - start subfolders at 01
            childdir <str>: Child directory (optional)
        If xyz files, fname is required to be of the form:
            "xyz"
            <float a> <float b> <float c for box size>
            fileone.xyz
            filetwo.xyz
            ...
        If POSCAR or other structure files, fname may simply 
        start with file names:
            POSCAR_01
            POSCAR_02
    """
    logger = logging.getLogger(mydir)
    logger = loggerutils.add_handler_for_recipe(mydir, logger)

    if childdir == "":
        childdir = mydir
    fpath = os.path.join(mydir, fname)
    if not os.path.isfile(fpath):
        logger.error("No file found at %s" % fpath)
        return "File not found. No effect."
    str_list_file = MASTFile(fpath)
    if str_list_file.data[0].strip().lower() == "xyz":
        namelist = list(str_list_file.data[2:])
        structure_list = get_xyz_structures(mydir, str_list_file.data[1],
                                            namelist)
    else:
        namelist = list(str_list_file.data)
        structure_list = get_structures(mydir, namelist)
    if not (len(structure_list) == len(namelist)):
        logger.error("Not all structures in file %s found." % fname)
        return "Not all structures found. No effect."
    strct = int(startat)
    for one_structure in structure_list:
        subname = str(strct).zfill(2)
        subpath = os.path.join(childdir, subname)
        if not os.path.isdir(subpath):
            os.mkdir(subpath)
        one_poscar = pymatgen.io.vaspio.Poscar(one_structure)
        pospath = os.path.join(subpath, "POSCAR")
        if os.path.isfile(pospath):
            logger.error("POSCAR file already exists at %s" % subpath)
        else:
            one_poscar.write_file(os.path.join(subpath, "POSCAR"))
        strct = strct + 1
    return "Wrote all POSCAR files to subdirectories in %s" % childdir
Exemple #34
0
 def test_vasp_kpoints_setup_from_metafile(self):
     kdict = dict()
     mymeta = MASTFile("childdir/metadata.txt")
     mymeta.data.append("kpoints = 3x1x7 G 0.5 0.2 .1\n")
     mymeta.to_file("childdir/metadata.txt")
     mymeta2 = MASTFile("childdir/metadata.txt")
     print mymeta2.data
     myvc = VaspChecker(name="childdir", program_keys=kdict)
     mykpt = myvc._vasp_kpoints_setup()
     kpt_compare = pymatgen.io.vaspio.Kpoints.from_file(
         "files/KPOINTS_317G")
     self.assertEqual(kpt_compare.kpts[0][0], mykpt.kpts[0][0])
     self.assertEqual(kpt_compare.kpts[0][1], mykpt.kpts[0][1])
     self.assertEqual(kpt_compare.kpts[0][2], mykpt.kpts[0][2])
     self.assertEqual(kpt_compare.num_kpts, mykpt.num_kpts)
     self.assertEqual(kpt_compare.style, mykpt.style)
     #self.assertEqual(kpt_compare.kpts_shift, mykpt.kpts_shift)
     self.assertEqual((0.5, 0.2, 0.1), mykpt.kpts_shift)
Exemple #35
0
 def check(self):
     errfilepath = queue_commands.get_job_error_file(self.ingpath)
     self.logger.info("Checking file at %s" % errfilepath)
     if errfilepath == None:
         return False
     errfile = MASTFile(errfilepath)
     for errline in errfile.data:
         if 'insufficient virtual memory' in errline.lower():
             return True
Exemple #36
0
 def test_complete_ingredient(self):
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("recipedir/metadata.txt")
     #metad = MASTFile("files/metadata_single")
     #metad.to_file("%s/metadata.txt" % ingdir)
     rp = RecipePlan("recipedir")
     rp.ingredients['ing1'] = "I"
     kdict=dict()
     kdict['mast_program']='vasp'
     kdict['mast_xc']='pw91'
     kdict['mast_kpoints']=[1,2,3,"G"]
     rp.ingred_input_options['ing1']=dict()
     rp.ingred_input_options['ing1']['name']="%s/recipedir/ing1" % testdir
     rp.ingred_input_options['ing1']['program_keys']=kdict
     rp.ingred_input_options['ing1']['structure']=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     rp.complete_methods['ing1']=[['complete_singlerun']]
     self.assertTrue(rp.complete_ingredient('ing1'))
Exemple #37
0
 def check_recipe_dir(self, fulldir, verbose, single_ingred_mode):
     """Check a recipe directory.
         Args:
             fulldir <str>: full path of recipe directory
             verbose <int>: verbosity
             single_ingred_mode <str>: 0 for checking all ingredients
                        ingredient name for checking a single ingredient               
     """
     shortdir = os.path.basename(fulldir)  #only the recipe directory name
     if not os.path.exists(fulldir):
         raise MASTError(self.__class__.__name__,
                         "No recipe directory at %s" % fulldir)
     if os.path.exists(os.path.join(fulldir, "MAST_SKIP")):
         self.logger.warning(
             "Skipping recipe %s due to the presence of a MAST_SKIP file in the recipe directory."
             % shortdir)
         return
     if os.path.exists(os.path.join(fulldir, "MAST_ERROR")):
         self.logger.error(
             "ATTENTION!: Skipping recipe %s due to the presence of a MAST_ERROR file in the recipe directory."
             % shortdir)
         return
     self.logger.info("--------------------------------")
     self.logger.info("Processing recipe %s" % shortdir)
     self.logger.info("--------------------------------")
     my_recipe_plan_object = self.set_up_recipe_plan(fulldir, verbose)
     os.chdir(fulldir)  #need to change directories in order to submit jobs?
     try:
         my_recipe_plan_object.check_recipe_status(verbose,
                                                   single_ingred_mode)
     except Exception:
         import sys, traceback
         #ex_type, ex, trbck = sys.exc_info()
         errortext = traceback.format_exc()
         #del trbck
         errorfile = open(os.path.join(fulldir, "MAST_ERROR"), "ab")
         errorfile.write("ERROR LOGGED %s\n" % time.asctime())
         errorfile.write("%s\n" % errortext)
         errorfile.close()
         self.logger.warning(
             "ERROR in recipe %s. Check MAST_ERROR file in the %s directory."
             % (shortdir, fulldir))
         #raise MASTError(self.__class__.__name__,"Error in recipe %s as follows: %s %s %s" % (shortdir, ex_type, ex, errortext))
     os.chdir(self.scratch)
     if my_recipe_plan_object.status == "C":
         shutil.move(fulldir, self._ARCHIVE)
         summarypath = "%s/%s/SUMMARY.txt" % (self._ARCHIVE, shortdir)
         if os.path.isfile(summarypath):
             self.logger.info("Recipe %s completed." % shortdir)
             self.logger.info("SUMMARY.txt below:")
             summarytext = MASTFile(summarypath)
             for myline in summarytext.data:
                 self.logger.info(myline.strip())
     self.logger.info("-----------------------------")
     self.logger.info("Recipe %s processed." % shortdir)
     self.logger.info("-----------------------------")
Exemple #38
0
def get_variables():
    verify_checks()
    myvars = dict()
    checkfile = MASTFile(checkname)
    for myline in checkfile.data:
        if myline[0:9] == "workflow_":
            mykey = myline.split("=")[0].strip()
            myval = myline.split("=")[1].strip()
            myvars[mykey] = myval
    return myvars
Exemple #39
0
 def test_get_statuses_from_file(self):
     rp = RecipePlan("recipedir")
     mystatus = MASTFile("files/status_random.txt")
     self.assertRaises(MASTError, rp.get_statuses_from_file)
     mystatus.to_file("recipedir/status.txt")
     rp.ingredients['ing1'] = "I"
     rp.ingredients['ing2a'] = "I"
     rp.ingredients['ing2b'] = "I"
     self.assertRaises(MASTError, rp.get_statuses_from_file)
     rp.ingredients['ing3'] = "I"
     rp.get_statuses_from_file()
     statusdict = dict()
     statusdict = {
         'ing1': 'alpha',
         'ing2a': 'beta',
         'ing2b': 'gamma',
         'ing3': 'delta'
     }
     self.assertEquals(rp.ingredients, statusdict)
Exemple #40
0
 def check(self):
     errfilepath = queue_commands.get_job_error_file(self.ingpath)
     if errfilepath == None:
         return False
     errfile = MASTFile(errfilepath)
     for errline in errfile.data:
         if 'walltime' in errline.lower():
             return True
         elif 'time limit' in errline.lower():
             return True
Exemple #41
0
    def create_archive_files(self):
        """Save off archive files.
            Returns:
                creates archive_input_options.txt
                creates archive_recipe_plan.txt
        """
        inputsave = MASTFile()
        inputsave.data = repr(self.input_options)
        inputsave.to_file(
            os.path.join(self.recdir,
                         'archive_input_options_%s.txt' % self.timestamp))

        recipesave = MASTFile()
        recipesave.data = repr(self.recipe_plan)
        recipesave.to_file(
            os.path.join(self.recdir,
                         'archive_recipe_plan_%s.txt' % self.timestamp))

        return
Exemple #42
0
def main():
    recipe_name, script_head_dir = parse_arguments()   
    mast_scratch = dirutil.get_mast_scratch_path()
    mymon = MASTMon()
    my_recipe_plan = mymon.set_up_recipe_plan(os.path.join(mast_scratch, recipe_name), 1)
    my_dag_contents=list()
    for iname in my_recipe_plan.ingredients: #all JOB lines need to be at top
        my_dag_contents.append("JOB %s submit.sh DIR %s\n" % (iname, iname))
    for iname in my_recipe_plan.ingredients:
        my_dag_contents.append("SCRIPT PRE %s %s/mast_do_setup.sh %s %s\n" % (iname, script_head_dir, recipe_name, iname)) 
        my_dag_contents.append("SCRIPT POST %s %s/mast_check_is_complete.sh %s %s\n" % (iname, script_head_dir, recipe_name, iname)) 
        my_dag_contents.append("RETRY %s 5\n" % iname)
        ptc = list(my_recipe_plan.parents_to_check[iname])
        for pname in ptc:
            my_dag_contents.append("PARENT %s CHILD %s\n" % (pname, iname))
    my_dag_file = MASTFile()
    my_dag_file.data = my_dag_contents
    my_dag_file.to_file(os.path.join(mast_scratch, recipe_name, "recipe.dag"))
    #print_to_file(recipe_name, ing_name, "MAIN: is complete: %s" % is_complete)
    return 0
 def test_give_structure(self):
     ingdir="%s/writedir/single_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     my_structure = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     myrelaxed = MASTFile("files/relaxed_structure")
     myrelaxed.to_file("%s/CONTCAR" % ingdir)
     myuci = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     myuci.give_structure("next_ingred")
     givenstr = MASTFile("%s/writedir/next_ingred/POSCAR" % testdir)
     self.assertEqual(myrelaxed.data, givenstr.data)
 def test_give_saddle_structure(self):
     ingdir="%s/writedir/neb_labelinit-labelfin" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_neb")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_neb")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp_neb'
     kdict['images'] = 3
     my_structure = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     myrelaxed=dict()
     myosz=dict()
     mywav=dict()
     mychg=dict()
     for subdir in ['00','01','02','03','04']:
         os.mkdir("writedir/neb_labelinit-labelfin/%s" % subdir)
         myrelaxed[subdir] = MASTFile("files/POSCAR_%s" % subdir)
         myrelaxed[subdir].to_file("writedir/neb_labelinit-labelfin/%s/CONTCAR" % subdir)
         myosz[subdir] = MASTFile("files/OSZICAR_%s" % subdir)
         myosz[subdir].to_file("writedir/neb_labelinit-labelfin/%s/OSZICAR" % subdir)
         mychg[subdir] = MASTFile("files/CHGCAR")
         mychg[subdir].to_file("writedir/neb_labelinit-labelfin/%s/CHGCAR" % subdir)
         mywav[subdir] = MASTFile("files/WAVECAR")
         mywav[subdir].to_file("writedir/neb_labelinit-labelfin/%s/WAVECAR" % subdir)
     myuci = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     myuci.give_saddle_structure("next_ingred") #should be OSZ3
     saddle = MASTFile("%s/writedir/next_ingred/POSCAR" % testdir)
     self.assertEqual(myrelaxed['03'].data, saddle.data)
     saddledir = myuci.get_saddle_dir()
     self.assertEqual(saddledir, "03")
Exemple #45
0
 def test_check_if_ready_to_proceed_are_complete(self):
     metad = MASTFile("files/metadata_single")
     metad.to_file("recipedir/ing1/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("recipedir/ing2a/metadata.txt")
     rp = RecipePlan("recipedir")
     rp.ingredients['ing1'] = "P"
     rp.ingredients['ing2a'] = "I"
     rp.ingredients['ing2b'] = "I"
     rp.ingredients['ing3'] = "I"
     kdict=dict()
     kdict['mast_program']='vasp'
     kdict['mast_xc']='pw91'
     kdict['mast_kpoints']=[1,2,3,"G"]
     my_struc = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     rp.ingred_input_options['ing1']=dict()
     rp.ingred_input_options['ing1']['name']="%s/recipedir/ing1" % testdir
     rp.ingred_input_options['ing1']['program_keys']=kdict
     rp.ingred_input_options['ing1']['structure']=my_struc
     rp.complete_methods['ing1']=[['complete_singlerun']]
     rp.update_methods['ing1']=dict()
     rp.update_methods['ing1']['ing2a']=[['give_structure']]
     rp.update_methods['ing1']['ing2b']=[['give_structure']]
     rp.ingred_input_options['ing2a']=dict()
     rp.ingred_input_options['ing2a']['name']="%s/recipedir/ing2a" % testdir
     rp.ingred_input_options['ing2a']['program_keys']=kdict
     rp.ingred_input_options['ing2a']['structure']=my_struc
     rp.complete_methods['ing2a']=[['complete_singlerun']]
     rp.ready_methods['ing2a']=[['ready_structure']]
     rp.check_if_ready_to_proceed_are_complete()
     self.assertTrue(rp.ready_ingredient('ing2a'))
     self.assertEquals
     self.assertEquals(rp.ingredients,{'ing1':'C','ing2a':'I','ing2b':'I','ing3':'I'})
Exemple #46
0
 def test_run_subfolders(self):
     #raise SkipTest
     ingdir="%s/writedir/single_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_kpoints'] = [2,2,2,"M"]
     kdict['mast_xc'] = 'pw91'
     my_structure = Poscar.from_file("files/perfect_structure").structure
     for subfolder in ['sub1','sub2','sub3','sub4']:
         subname = "%s/%s" % (ingdir, subfolder)
         os.mkdir(subname)
         shutil.copy("files/metadata_single","%s/metadata.txt" % subname)
         mywr = ChopIngredient(name=subname, program_keys = kdict, structure=my_structure)
         mywr.write_singlerun()
     myri = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     myri.run_subfolders()
     self.assertFalse(myri.checker.is_ready_to_run())
     for subfolder in ['sub1','sub2','sub3','sub4']:
         subname = "%s/%s" % (ingdir, subfolder)
         myri.checker.keywords['name'] = subname
         self.assertTrue(myri.checker.is_ready_to_run())
     mysubmit = MASTFile("%s/submitlist" % self.test_control)
     self.assertEquals(mysubmit.data[0], "%s/sub1\n" % ingdir)
     self.assertEquals(mysubmit.data[1], "%s/sub2\n" % ingdir)
     self.assertEquals(mysubmit.data[2], "%s/sub3\n" % ingdir)
     self.assertEquals(mysubmit.data[3], "%s/sub4\n" % ingdir)
 def test_ready_neb_subfolders(self):
     ingdir="%s/writedir/single_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_kpoints'] = [2,2,2,"M"]
     kdict['mast_xc'] = 'pw91'
     kdict['mast_neb_settings']=dict()
     kdict['mast_neb_settings']['images'] = 3
     my_structure = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     mywr = ChopIngredient(name=ingdir, program_keys = kdict, structure=my_structure)
     for subdir in ['00','01','02','03','04']:
         subname = "%s/%s" % (ingdir, subdir)
         os.mkdir(subname)
         mywr.keywords['name'] = subname
         mywr.checker.keywords['name'] = subname 
         if not subdir in ['00','04']:
             mywr.write_singlerun()
             mywr.write_submit_script()
     myrdi = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     self.assertTrue(myrdi.ready_neb_subfolders())
     os.remove("%s/01/POSCAR" % ingdir)
     self.assertFalse(myrdi.ready_neb_subfolders())
Exemple #48
0
    def create_archive_files(self):
        """Save off archive files.
            Returns:
                creates archive_input_options.txt
                creates archive_recipe_plan.txt
        """
        inputsave = MASTFile()
        inputsave.data = repr(self.input_options)
        inputsave.to_file(os.path.join(self.recdir, 'archive_input_options_%s.txt' % self.timestamp))

        recipesave = MASTFile()
        recipesave.data = repr(self.recipe_plan)
        recipesave.to_file(os.path.join(self.recdir, 'archive_recipe_plan_%s.txt' % self.timestamp))

        return
Exemple #49
0
 def test_write_ingredient(self):
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("recipedir/metadata.txt")
     #metad = MASTFile("files/metadata_single")
     #metad.to_file("%s/metadata.txt" % ingdir)
     rp = RecipePlan("recipedir")
     rp.ingredients['ing2b'] = "I"
     kdict=dict()
     kdict['mast_program']='vasp'
     kdict['mast_xc']='pw91'
     kdict['mast_kpoints']=[1,2,3,"G"]
     rp.ingred_input_options['ing2b']=dict()
     rp.ingred_input_options['ing2b']['name']="recipedir/ing2b"
     rp.ingred_input_options['ing2b']['program_keys']=kdict
     rp.ingred_input_options['ing2b']['structure']=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     rp.write_methods['ing2b']=[['write_singlerun']]
     rp.write_ingredient('ing2b')
     self.assertTrue(os.path.isfile('recipedir/ing2b/INCAR'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/POSCAR'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/POTCAR'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/KPOINTS'))
     self.assertTrue(os.path.isfile('recipedir/ing2b/submit.sh'))
 def test_parse(self):
     #ipfile='small_workflow_with_scaling.inp'
     ipfile='phonon_with_neb.inp'
     workdir = os.path.join(testdir,'workdir')
     shutil.copy(os.path.join(testdir,ipfile),workdir)
     input_file = os.path.join(workdir,ipfile)
     parser_obj = InputParser(inputfile=input_file)
     input_options = parser_obj.parse()
     recipe_file_contents = input_options.get_item('recipe','recipe_file')
     myrtp = RecipeTemplateParser(inputOptions=input_options,
         working_directory=workdir,
         templateFile=recipe_file_contents,
         personalRecipe=input_file)
     parsed_lines = myrtp.parse()
     output_parsed = MASTFile()
     output_parsed.data = list(parsed_lines)
     output_parsed.to_file('workdir/personal_recipe_test_output.txt')
     self.assertEquals(len(myrtp.chunks),5)
     #mypr = MASTFile(pr)
     #for line in mypr.data:
     #    print line.rstrip()
     compare_pr = MASTFile(os.path.join(testdir,'compare','personal_recipe_test_output.txt'))
     self.assertEquals(parsed_lines, compare_pr.data)
Exemple #51
0
 def test_run_strain(self):
     #raise SkipTest
     ingdir="%s/writedir/single_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_strain']=" 0.98 0.92 1.03 \n"
     my_structure = Poscar.from_file("files/POSCAR_perfect").structure
     myunstrained = MASTFile("files/POSCAR_unstrained")
     myunstrained.to_file("%s/POSCAR" % ingdir)
     myri = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     myri.run_strain()
     my_strained = Poscar.from_file("%s/CONTCAR" % ingdir).structure
     strained_compare = Poscar.from_file("files/POSCAR_strained").structure
     self.assertEquals(my_strained, strained_compare)
     self.assertFalse(os.path.isfile("%s/submitlist" % self.test_control))
Exemple #52
0
 def test_run_scale(self):
     #raise SkipTest
     ingdir="%s/writedir/single_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.data.append("defect_label = label1\n")
     metad.data.append("scaling_size = [2,2,2]\n")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     my_structure = Poscar.from_file("files/POSCAR_perfect").structure
     myperf = MASTFile("files/POSCAR_perfect")
     myperf.to_file("%s/POSCAR" % ingdir)
     myri = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     myri.run_scale()
     my_scaled = Poscar.from_file("%s/CONTCAR" % ingdir).structure.get_sorted_structure()
     scaled_compare = Poscar.from_file("files/POSCAR_scaled").structure.get_sorted_structure()
     self.assertEquals(my_scaled, scaled_compare)
 def test__fullpath_childname(self):
     ingdir="%s/writedir/single_label1" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     my_structure = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     myuci = ChopIngredient(name=ingdir,program_keys=kdict,structure=my_structure)
     fullpath = myuci._fullpath_childname("next_ingred")
     self.assertEqual(fullpath, "%s/writedir/next_ingred" % testdir)
Exemple #54
0
 def test_set_up_program_input(self):
     mystrs=list()
     pos=dict()
     for posstr in ['00','01','02','03','04']:
         pos[posstr] = pymatgen.io.vaspio.Poscar.from_file("structures/POSCAR_%s" % posstr)
         mystrs.append(pos[posstr].structure)
     kdict=dict()
     kdict['mast_kpoints']=[3,3,3,"G"]
     kdict['mast_xc']="pw91"
     kdict['mast_neb_settings']=dict()
     kdict['mast_neb_settings']['images']=3
     kdict['mast_neb_settings']['image_structures'] = mystrs
     myvcneb=VaspNEBChecker(name="childdir",program_keys=kdict)
     myvcneb.set_up_program_input()
     submitscript = MASTFile()
     submitscript.data="Submission script placeholder."
     submitscript.to_file("childdir/submit.sh")
     ozholder = MASTFile()
     ozholder.data="OSZICAR placeholder."
     submitscript.to_file("childdir/00/OSZICAR")
     submitscript.to_file("childdir/04/OSZICAR")
     self.assertTrue(myvcneb.is_ready_to_run())
 def test_write_singlerun(self):
     ingdir="writedir/single_label1"
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_kpoints']=[3,3,3,"G"]
     kdict['mast_xc']='pbe'
     kdict['mast_program']='vasp'
     my_structure=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
     mywi = ChopIngredient(name=ingdir,program_keys=kdict,structure=my_structure)
     mywi.write_singlerun()
     self.assertTrue(mywi.checker.is_ready_to_run())
 def test_ready_structure(self):
     ingdir="%s/writedir/single_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_kpoints'] = [2,2,2,"M"]
     kdict['mast_xc'] = 'pw91'
     my_pos = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure")
     my_pos.write_file("writedir/single_label1/POSCAR")
     myrdi = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_pos.structure)
     self.assertTrue(myrdi.ready_structure())
     os.remove("%s/POSCAR" % ingdir)
     self.assertFalse(myrdi.ready_structure())
 def test_write_singlerun_automesh(self):
     ingdir="writedir/single_label1"
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_kpoints']=[3,3,3,"G"]
     kdict['mast_xc']='pbe'
     kdict['mast_program']='vasp'
     kdict['mast_kpoint_density']='1000'
     mypos=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure")
     mypos.write_file("writedir/single_label1/POSCAR")
     mywi = ChopIngredient(name=ingdir,program_keys=kdict,structure=mypos.structure)
     mywi.write_singlerun_automesh()
     mykpts = pymatgen.io.vaspio.Kpoints.from_file("writedir/single_label1/KPOINTS")
     self.assertEqual(mykpts.to_dict['kpoints'][0],[8,8,8])
     #print mykpts
     self.assertTrue(mywi.checker.is_ready_to_run())
Exemple #58
0
 def test_run_singlerun(self):
     #raise SkipTest
     ingdir="%s/writedir/single_label1" % testdir
     recipedir="%s/writedir" % testdir
     topmetad = MASTFile("files/top_metadata_single")
     topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_single")
     metad.to_file("%s/metadata.txt" % ingdir)
     kdict=dict()
     kdict['mast_program'] = 'vasp'
     kdict['mast_kpoints'] = [2,2,2,"M"]
     kdict['mast_xc'] = 'pw91'
     my_structure = Poscar.from_file("files/perfect_structure").structure
     mywr = ChopIngredient(name=ingdir, program_keys = kdict, structure=my_structure)
     mywr.write_singlerun()
     myri = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
     myri.run_singlerun()
     self.assertTrue(myri.checker.is_ready_to_run())
     mysubmit = MASTFile("%s/submitlist" % self.test_control)
     self.assertEquals(mysubmit.data[0], "%s\n" % ingdir)