Exemplo n.º 1
0
 def test_complete_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 = pymatgen.io.vaspio.Poscar.from_file(
         "files/perfect_structure").structure
     mywr = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     mywr.write_singlerun()
     myoutcar = MASTFile("files/OUTCAR_completed")
     myoutcar.to_file("%s/OUTCAR" % ingdir)
     myoszicar = MASTFile("files/OSZICAR_completed")
     myoszicar.to_file("%s/OSZICAR" % ingdir)
     myrdi = ChopIngredient(name=ingdir,
                            program_keys=kdict,
                            structure=my_structure)
     self.assertTrue(myrdi.complete_singlerun())
     os.remove("%s/OUTCAR" % ingdir)
     self.assertFalse(myrdi.complete_singlerun())
Exemplo n.º 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
Exemplo n.º 3
0
 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())
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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")
Exemplo n.º 8
0
 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)
Exemplo n.º 9
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")
Exemplo n.º 10
0
 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)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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
Exemplo n.º 15
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
Exemplo n.º 16
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
Exemplo n.º 17
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'
                           }))
Exemplo n.º 18
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]
Exemplo n.º 19
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)
Exemplo n.º 20
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
Exemplo n.º 21
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
Exemplo n.º 22
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'))
Exemplo n.º 23
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"))
Exemplo n.º 24
0
 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)
Exemplo n.º 25
0
 def test_get_parent_image_structures(self):
     kdict = dict()
     kdict['mast_program'] = 'vasp_neb'
     neblines = list()
     neblines.append(["Cr", "0.0 0.9 0.8", "0.0 0.8 0.7"])
     neblines.append(["Cr", "0.4 0.2 0.1", "0.3 0.3 0.2"])
     neblines.append(["Cr", "0.29 0.05 0.05", "0.01 0.01 0.98"])
     neblines.append(["Ni", "0.61 0.99 0.98", "0.25 0.01 0.97"])
     kdict['mast_neb_settings'] = dict()
     kdict['mast_neb_settings']['images'] = 3
     kdict['mast_neb_settings']['lines'] = neblines
     ingdir = "writedir/neb_labelinit-labelfin"
     topmetad = MASTFile("files/top_metadata_neb")
     topmetad.to_file("writedir/metadata.txt")
     metad = MASTFile("files/metadata_neb")
     metad.to_file("%s/metadata.txt" % ingdir)
     unsorted_01 = MASTFile(
         "unsorted/parent_structure_labelinit-labelfin_01")
     unsorted_01.to_file("%s/parent_structure_labelinit-labelfin_01" %
                         ingdir)
     unsorted_02 = MASTFile(
         "unsorted/parent_structure_labelinit-labelfin_02")
     unsorted_02.to_file("%s/parent_structure_labelinit-labelfin_02" %
                         ingdir)
     unsorted_03 = MASTFile(
         "unsorted/parent_structure_labelinit-labelfin_03")
     unsorted_03.to_file("%s/parent_structure_labelinit-labelfin_03" %
                         ingdir)
     my_structure = pymatgen.io.vaspio.Poscar.from_file(
         "files/perfect_structure").structure
     mywi = ChopIngredient(name=ingdir,
                           program_keys=kdict,
                           structure=my_structure)
     imstrs = mywi.get_parent_image_structures()
     compare_01 = pymatgen.io.vaspio.Poscar.from_file(
         "files/parent_structure_labelinit-labelfin_01").structure
     compare_02 = pymatgen.io.vaspio.Poscar.from_file(
         "files/parent_structure_labelinit-labelfin_02").structure
     compare_03 = pymatgen.io.vaspio.Poscar.from_file(
         "files/parent_structure_labelinit-labelfin_03").structure
     self.assertEqual(imstrs[0].sites, compare_01.sites)
     self.assertEqual(imstrs[0].lattice, compare_01.lattice)
     self.assertEqual(imstrs[1].sites, compare_02.sites)
     self.assertEqual(imstrs[1].lattice, compare_02.lattice)
     self.assertEqual(imstrs[2].sites, compare_03.sites)
     self.assertEqual(imstrs[2].lattice, compare_03.lattice)
Exemplo n.º 26
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)
Exemplo n.º 27
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
Exemplo n.º 28
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)
Exemplo n.º 29
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
Exemplo n.º 30
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("-----------------------------")