当前位置: 首页>>代码示例>>Python>>正文


Python utility.MASTFile类代码示例

本文整理汇总了Python中MAST.utility.MASTFile的典型用法代码示例。如果您正苦于以下问题:Python MASTFile类的具体用法?Python MASTFile怎么用?Python MASTFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MASTFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update_children

 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"))
开发者ID:ZhewenSong,项目名称:USIT,代码行数:25,代码来源:test_recipeplan.py

示例2: evaluate_ga_vasp_and_update

    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)
开发者ID:ZhewenSong,项目名称:USIT,代码行数:35,代码来源:customchopingredient.py

示例3: create_workflow_test_script

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]
开发者ID:uw-cmg,项目名称:MAST,代码行数:28,代码来源:workflow_setup.py

示例4: change_my_status

 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)
开发者ID:uw-cmg,项目名称:MAST,代码行数:27,代码来源:baseingredient.py

示例5: test_run_staged_ingredients

 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'})
开发者ID:ZhewenSong,项目名称:USIT,代码行数:28,代码来源:test_recipeplan.py

示例6: status_change_recommended

 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
开发者ID:uw-cmg,项目名称:MAST,代码行数:29,代码来源:recipeplan.py

示例7: test_give_phonon_multiple_forces_and_displacements

 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)
开发者ID:ZhewenSong,项目名称:USIT,代码行数:32,代码来源:test_updateingredient.py

示例8: test_inputpythoncreator

 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"))
开发者ID:ZhewenSong,项目名称:USIT,代码行数:11,代码来源:oldinputtest.py

示例9: test_get_statuses_from_file

 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)
开发者ID:ZhewenSong,项目名称:USIT,代码行数:14,代码来源:test_recipeplan.py

示例10: create_archive_files

    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
开发者ID:uw-cmg,项目名称:MAST,代码行数:26,代码来源:mastinput.py

示例11: print_table

 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()
开发者ID:ZhewenSong,项目名称:USIT,代码行数:16,代码来源:defectformationenergy.py

示例12: test_vasp_kpoints_setup_from_metafile

 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)
开发者ID:uw-cmg,项目名称:MAST,代码行数:17,代码来源:test_vaspchecker.py

示例13: test_complete_ingredient

 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'))
开发者ID:ZhewenSong,项目名称:USIT,代码行数:18,代码来源:test_recipeplan.py

示例14: main

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
开发者ID:uw-cmg,项目名称:MAST,代码行数:20,代码来源:make_my_dag.py

示例15: test_give_structure

 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)
开发者ID:ZhewenSong,项目名称:USIT,代码行数:17,代码来源:test_updateingredient.py


注:本文中的MAST.utility.MASTFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。