Пример #1
0
    def create_recipe_plan(self):
        """Creates a recipe object which has the ingredients and dependency information
        """
        import inspect
        #'GRJ DEBUG: %s.%s' % (self.__class__.__name__, inspect.stack()[0][3])
        [how_to_update, parents_to_check, how_to_run] = ru.read_recipe(self.recipe_file)

        recipe_obj = RecipePlan(self.work_dir)
        ingredlist = how_to_run.keys()
        for ingred in ingredlist:
            self.update_top_meta_for_ingred(ingred)
            ingredtype = how_to_run[ingred]
            recipe_obj.ingredients[ingred]="I" #set all to initialized
            recipe_obj.ingred_input_options[ingred] = self.get_my_ingredient_options(ingred, ingredtype)
            if not os.path.isdir(os.path.join(self.work_dir, ingred)):
                self.create_ingredient(recipe_obj.ingred_input_options[ingred])
            recipe_obj.write_methods[ingred] = self.get_method_list(ingredtype, "mast_write_method")
            recipe_obj.ready_methods[ingred] = self.get_method_list(ingredtype, "mast_ready_method")
            recipe_obj.run_methods[ingred] = self.get_method_list(ingredtype, "mast_run_method")
            recipe_obj.complete_methods[ingred] = self.get_method_list(ingredtype, "mast_complete_method")
            recipe_obj.update_methods[ingred] = dict()
            for ichild in how_to_update[ingred].keys():
                updingredtype = how_to_update[ingred][ichild]
                recipe_obj.update_methods[ingred][ichild] = self.get_method_list(updingredtype, "mast_update_children_method")
            recipe_obj.parents_to_check = dict(parents_to_check)
        recipe_obj.summary_options = self.get_summary_options()
        return recipe_obj
Пример #2
0
    def create_recipe_plan(self):
        """Creates a recipe object which has the ingredients and dependency information
        """
        import inspect
        #'GRJ DEBUG: %s.%s' % (self.__class__.__name__, inspect.stack()[0][3])
        [how_to_update, parents_to_check,
         how_to_run] = ru.read_recipe(self.recipe_file)

        recipe_obj = RecipePlan(self.work_dir)
        ingredlist = how_to_run.keys()
        for ingred in ingredlist:
            self.update_top_meta_for_ingred(ingred)
            ingredtype = how_to_run[ingred]
            recipe_obj.ingredients[ingred] = "I"  #set all to initialized
            recipe_obj.ingred_input_options[
                ingred] = self.get_my_ingredient_options(ingred, ingredtype)
            if not os.path.isdir(os.path.join(self.work_dir, ingred)):
                self.create_ingredient(recipe_obj.ingred_input_options[ingred])
            recipe_obj.write_methods[ingred] = self.get_method_list(
                ingredtype, "mast_write_method")
            recipe_obj.ready_methods[ingred] = self.get_method_list(
                ingredtype, "mast_ready_method")
            recipe_obj.run_methods[ingred] = self.get_method_list(
                ingredtype, "mast_run_method")
            recipe_obj.complete_methods[ingred] = self.get_method_list(
                ingredtype, "mast_complete_method")
            recipe_obj.update_methods[ingred] = dict()
            for ichild in how_to_update[ingred].keys():
                updingredtype = how_to_update[ingred][ichild]
                recipe_obj.update_methods[ingred][
                    ichild] = self.get_method_list(
                        updingredtype, "mast_update_children_method")
            recipe_obj.parents_to_check = dict(parents_to_check)
        recipe_obj.summary_options = self.get_summary_options()
        return recipe_obj
Пример #3
0
 def test_read_recipe(self):
     fss_recipe = MASTFile(os.path.join(testdir, "fss_recipe.txt"))
     fss_recipe_lines = fss_recipe.data
     fss_recipe_lines.pop(0)  # remove recipe name
     [htu, ptc, htr] = recipeutility.read_recipe(fss_recipe_lines)
     self.assertEqual(htu["defect_2x2x3_int1_opt"]["neb_2x2x3_int1-int2_opt"], "relax_to_neb")
     self.assertItemsEqual(ptc["neb_1x2x4_int1-int2_opt"], ["defect_1x2x4_int1_opt", "defect_1x2x4_int2_opt"])
     self.assertEqual(htr["phonon_1x1x2_int1-int2_w0"], "phonon")
Пример #4
0
 def test_read_recipe(self):
     file_contents = MASTFile(os.path.join(testdir,'neb_int_personalized'))
     [htu, ptc,htr]=recipeutility.read_recipe(file_contents.data)
     #print htu
     #print ptc
     #print htr
     #print rname
     self.assertEqual(htu['neb_group1-group3_q=n1_opt2']['neb_group1-group3_q=n1_stat'],'neb_to_nebstat')
     self.assertItemsEqual(ptc['neb_group1-group3_q=n1_opt1'],['defect_group1_q=n1_stat','defect_group3_q=n1_stat'])
     self.assertEqual(htr['neb_group1-group3_q=n1_stat'],'nebstat_to_nebphonon')
Пример #5
0
 def test_read_recipe(self):
     fss_recipe = MASTFile(os.path.join(testdir, 'fss_recipe.txt'))
     fss_recipe_lines = fss_recipe.data
     fss_recipe_lines.pop(0)  #remove recipe name
     [htu, ptc, htr] = recipeutility.read_recipe(fss_recipe_lines)
     self.assertEqual(
         htu['defect_2x2x3_int1_opt']['neb_2x2x3_int1-int2_opt'],
         'relax_to_neb')
     self.assertItemsEqual(
         ptc['neb_1x2x4_int1-int2_opt'],
         ['defect_1x2x4_int1_opt', 'defect_1x2x4_int2_opt'])
     self.assertEqual(htr['phonon_1x1x2_int1-int2_w0'], 'phonon')
Пример #6
0
 def test_read_recipe(self):
     file_contents = MASTFile(os.path.join(testdir, 'neb_int_personalized'))
     [htu, ptc, htr] = recipeutility.read_recipe(file_contents.data)
     #print htu
     #print ptc
     #print htr
     #print rname
     self.assertEqual(
         htu['neb_group1-group3_q=n1_opt2']['neb_group1-group3_q=n1_stat'],
         'neb_to_nebstat')
     self.assertItemsEqual(
         ptc['neb_group1-group3_q=n1_opt1'],
         ['defect_group1_q=n1_stat', 'defect_group3_q=n1_stat'])
     self.assertEqual(htr['neb_group1-group3_q=n1_stat'],
                      'nebstat_to_nebphonon')
Пример #7
0
    def _calculate_defect_formation_energies(self,scsize):
        perf_dirs = []
        ingredients = self.recipe_plan.ingredients.keys()
        for i in range(len(ingredients)):
            if 'perfect' in ingredients[i]:
                perf_dirs.append(ingredients[i])
        if len(perf_dirs)==0:
            raise MASTError(self.__class__.__name__, "A perfect final directory (has no children and has the word 'perfect' in its name) could not be found. Check recipe %s for a perfect directory." % self.directory)
        

        def_dir = ru.read_recipe(self.input_options.get_item("personal_recipe","personal_recipe_list"))[1]['madelung_utility']
        defects = self.input_options.get_item('defects', 'defects')
        chempot = self.input_options.get_item('chemical_potentials')
        for i in range(len(perf_dirs)):
            perf_meta = Metadata(metafile='%s/%s/metadata.txt' % (self.directory, perf_dirs[i]))
            if scsize == perf_meta.read_data('scaling_size'): perf_dir = perf_dirs[i]
        
        perfpath = os.path.join(self.directory, perf_dir)
        if os.path.isfile(os.path.join(perfpath,"vasprun.xml")):
            e_perf = pmg.io.vaspio.vasp_output.Vasprun(os.path.join(perfpath, "vasprun.xml")).final_energy
        else:
            e_perf = float(open(os.path.join(perfpath, "OSZICAR")).readlines()[-1].split('E0=')[1].split()[0])
        efermi = self.get_fermi_energy(perf_dir)
        struct_perf = self.get_structure(perf_dir)

        perf_species = dict()
        for site in struct_perf:
            if (str(site.specie) not in perf_species):
                perf_species[str(site.specie)] = 1
            else:
                perf_species[str(site.specie)] += 1

        #print 'Perfect composition: ', perf_species
        #First Loop through the conditions for the defects
        for conditions, potentials in chempot.items():
            self.e_defects[conditions] = dict()
            # Loop through each defect
            for ddir in sorted(def_dir):
                def_meta = Metadata(metafile='%s/%s/metadata.txt' % (self.directory, ddir))
                if scsize == def_meta.read_data('scaling_size'):
                    label = def_meta.read_data('defect_label')+'_q='+def_meta.read_data('charge')
                    charge = int(def_meta.read_data('charge'))
                    if os.path.isfile(os.path.join(self.directory, ddir, "vasprun.xml")):
                        energy = pmg.io.vaspio.vasp_output.Vasprun(self.directory+'/'+ddir+'/vasprun.xml').final_energy
                    else:
                        energy = float(open(self.directory+'/'+ddir+'/OSZICAR').readlines()[-1].split('E0=')[1].split()[0])
                    structure = self.get_structure(ddir)
                    #if (label not in self.e_defects[conditions]):
                    #    self.e_defects[conditions][label] = list()
                    # Find out how many atoms of each type are in the defects
                    def_species = dict()
                    for site in structure.sites:
                        if (site.specie not in def_species):
                            def_species[site.specie] = 1
                        else:
                            def_species[site.specie] += 1
                    # Find the differences in the number of each atom type
                    # between the perfect and the defect
                    struct_diff = dict()
                    for specie, number in def_species.items():
                        try:
                            nperf = perf_species[str(specie)]
                        except KeyError:
                            nperf = 0
                        struct_diff[str(specie)] = number - nperf

                    # Get the potential alignment correction
                    alignment = self.get_potential_alignment(perf_dir, ddir)
                    # Calculate the base DFE energy
                    e_def = energy - e_perf # E_defect - E_perf
                    for specie, number in struct_diff.items():
                        mu = potentials[str(specie)]
                        e_def -= (number * mu)
                    e_def += charge * (efermi + alignment) # Add in the shift here!
                    #print '%-15s%-5i%12.5f%12.5f%12.5f%12.5f' % (label.split('_')[1], charge, energy, e_perf, efermi, alignment)
                    #print 'DFE = %f' % e_def
                    self.e_defects[conditions][label] = e_def 
Пример #8
0
    def _calculate_defect_formation_energies(self, scsize):
        perf_dirs = []
        ingredients = self.recipe_plan.ingredients.keys()
        for i in range(len(ingredients)):
            if 'perfect' in ingredients[i]:
                perf_dirs.append(ingredients[i])
        if len(perf_dirs) == 0:
            raise MASTError(
                self.__class__.__name__,
                "A perfect final directory (has no children and has the word 'perfect' in its name) could not be found. Check recipe %s for a perfect directory."
                % self.directory)

        def_dir = ru.read_recipe(
            self.input_options.get_item(
                "personal_recipe",
                "personal_recipe_list"))[1]['madelung_utility']
        defects = self.input_options.get_item('defects', 'defects')
        chempot = self.input_options.get_item('chemical_potentials')
        for i in range(len(perf_dirs)):
            perf_meta = Metadata(metafile='%s/%s/metadata.txt' %
                                 (self.directory, perf_dirs[i]))
            if scsize == perf_meta.read_data('scaling_size'):
                perf_dir = perf_dirs[i]

        perfpath = os.path.join(self.directory, perf_dir)
        if os.path.isfile(os.path.join(perfpath, "vasprun.xml")):
            e_perf = pmg.io.vaspio.vasp_output.Vasprun(
                os.path.join(perfpath, "vasprun.xml")).final_energy
        else:
            e_perf = float(
                open(os.path.join(
                    perfpath,
                    "OSZICAR")).readlines()[-1].split('E0=')[1].split()[0])
        efermi = self.get_fermi_energy(perf_dir)
        struct_perf = self.get_structure(perf_dir)

        perf_species = dict()
        for site in struct_perf:
            if (str(site.specie) not in perf_species):
                perf_species[str(site.specie)] = 1
            else:
                perf_species[str(site.specie)] += 1

        #print 'Perfect composition: ', perf_species
        #First Loop through the conditions for the defects
        for conditions, potentials in chempot.items():
            self.e_defects[conditions] = dict()
            # Loop through each defect
            for ddir in sorted(def_dir):
                def_meta = Metadata(metafile='%s/%s/metadata.txt' %
                                    (self.directory, ddir))
                if scsize == def_meta.read_data('scaling_size'):
                    label = def_meta.read_data(
                        'defect_label') + '_q=' + def_meta.read_data('charge')
                    charge = int(def_meta.read_data('charge'))
                    if os.path.isfile(
                            os.path.join(self.directory, ddir, "vasprun.xml")):
                        energy = pmg.io.vaspio.vasp_output.Vasprun(
                            self.directory + '/' + ddir +
                            '/vasprun.xml').final_energy
                    else:
                        energy = float(
                            open(self.directory + '/' + ddir +
                                 '/OSZICAR').readlines()[-1].split('E0=')
                            [1].split()[0])
                    structure = self.get_structure(ddir)
                    #if (label not in self.e_defects[conditions]):
                    #    self.e_defects[conditions][label] = list()
                    # Find out how many atoms of each type are in the defects
                    def_species = dict()
                    for site in structure.sites:
                        if (site.specie not in def_species):
                            def_species[site.specie] = 1
                        else:
                            def_species[site.specie] += 1
                    # Find the differences in the number of each atom type
                    # between the perfect and the defect
                    struct_diff = dict()
                    for specie, number in def_species.items():
                        try:
                            nperf = perf_species[str(specie)]
                        except KeyError:
                            nperf = 0
                        struct_diff[str(specie)] = number - nperf

                    # Get the potential alignment correction
                    alignment = self.get_potential_alignment(perf_dir, ddir)
                    # Calculate the base DFE energy
                    e_def = energy - e_perf  # E_defect - E_perf
                    for specie, number in struct_diff.items():
                        mu = potentials[str(specie)]
                        e_def -= (number * mu)
                    e_def += charge * (efermi + alignment
                                       )  # Add in the shift here!
                    #print '%-15s%-5i%12.5f%12.5f%12.5f%12.5f' % (label.split('_')[1], charge, energy, e_perf, efermi, alignment)
                    #print 'DFE = %f' % e_def
                    self.e_defects[conditions][label] = e_def