Beispiel #1
0
def main(ingname=""):
    """Get the energy from an ingredient.
        Args:
            ingname <str>: Ingredient name, full path
        Returns:
            <string>: "energy (eV);<energy as a string>", ex:
                "energy (eV); 3.0"
                Returns last E0 energy for a VASP run.
                Returns last E0 energy for all images for a VASP neb.
                Returns "N/A" otherwise.
    """
    trymeta = "%s/metadata.txt" % ingname
    if os.path.isfile(trymeta):
        mymeta = Metadata(metafile=trymeta)
        myprogram = mymeta.read_data("program")
    else:
        myprogram = "None"
    if 'induce' in ingname: #skip inducedefect ingredients
        myprogram = "None"
    if 'vasp' in myprogram:
        if os.path.isdir("%s/01" % ingname):
            estr = "energies (eV)"
            for subdir in dirutil.immediate_subdirs(ingname):
                mychecker = VaspChecker(name="%s/%s" % (ingname, subdir))
                estr = estr + ";%3.3f" % mychecker.get_energy_from_energy_file()
            return estr
        else:
            mychecker = VaspChecker(name=ingname)
            return "energy (eV);%3.3f" % mychecker.get_energy_from_energy_file()
    else:
        return "energy (eV);N/A"
Beispiel #2
0
def main(ingname=""):
    """Get the energy from an ingredient.
        Args:
            ingname <str>: Ingredient name, full path
        Returns:
            <string>: "energy (eV);<energy as a string>", ex:
                "energy (eV); 3.0"
                Returns last E0 energy for a VASP run.
                Returns last E0 energy for all images for a VASP neb.
                Returns "N/A" otherwise.
    """
    trymeta = "%s/metadata.txt" % ingname
    if os.path.isfile(trymeta):
        mymeta = Metadata(metafile=trymeta)
        myprogram = mymeta.read_data("program")
    else:
        myprogram = "None"
    if 'induce' in ingname:  #skip inducedefect ingredients
        myprogram = "None"
    if 'vasp' in myprogram:
        if os.path.isdir("%s/01" % ingname):
            estr = "energies (eV)"
            for subdir in dirutil.immediate_subdirs(ingname):
                mychecker = VaspChecker(name="%s/%s" % (ingname, subdir))
                estr = estr + ";%3.3f" % mychecker.get_energy_from_energy_file(
                )
            return estr
        else:
            mychecker = VaspChecker(name=ingname)
            return "energy (eV);%3.3f" % mychecker.get_energy_from_energy_file(
            )
    else:
        return "energy (eV);N/A"
    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)
Beispiel #4
0
    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)
Beispiel #5
0
    def get_total_energy(self, directory):
        """Returns the total energy from a directory"""

        abspath = '%s/%s/' % (self.recdir, directory)
        mychecker = VaspChecker(name=abspath)
        return mychecker.get_energy_from_energy_file()
Beispiel #6
0
    def get_total_energy(self, directory):
        """Returns the total energy from a directory"""

        abspath = '%s/%s/' % (self.recdir, directory)
        mychecker = VaspChecker(name=abspath)
        return mychecker.get_energy_from_energy_file()