コード例 #1
0
ファイル: chempotswap.py プロジェクト: zhenming-xu/MAST
def chempotswap(indiv, Optimzier):
    """Fitness function to evaluate fitness of energy in which swaps are allowed
    Inputs:
        indiv = Individual class object to be evaluated
        Optimizer = Optimizer class object with needed parameters
    Outputs:
        indiv = Evaluated Individual class object
    """
    #logger = initialize_logger(Optimizer.loggername)
    logger = logging.getLogger(Optimizer.loggername)
    starting = indiv.duplicate()
    cwd = os.getcwd()
    try:
        outs = eval_energy(Optimizer, indiv)
    except Exception, e:
        logger.warn('Error in energy evaluation: {0}'.format(e), exc_info=True)
        stro = 'ERROR: Problem in Energy Evaluation'
        print stro
        print e
        stro += '\n' + repr(e)
        os.chdir(cwd)
        f = open('problem-structures.xyz', 'a')
        totalsol = indiv[0].copy()
        totalsol.extend(indiv.bulki)
        write_xyz(f,
                  totalsol,
                  data='Starting structure hindex={0}'.format(
                      indiv.history_index))
        indiv.energy = 10000
        f.close()
        print '    Writing structure to problemstructures.xyz file. Structure (hindex) : ' + indiv.history_index
        print '    Setting individual energy to 50000.'
        outs = [10000, starting.bulki, starting, stro]
コード例 #2
0
ファイル: stem_cost.py プロジェクト: zhenming-xu/MAST
def stem_cost(indiv, Optimizer):
    '''Function to calculate STEM_Cost fitness of individual.
    Input:
        indiv = structopt_stem Individual class object to be evaluated
        Optimizer = structopt_stem Optimizer class object
            Must have STEM Calc function attached
    Output:
        indiv = structopt_stem Individual class object with new fitness.
    '''
    #logger = initialize_logger(Optimizer.loggername)
    logger = logging.getLogger(Optimizer.loggername)
    starting = indiv.duplicate()
    cwd = os.getcwd()
    try:
        outs = eval_energy(Optimizer, indiv)
    except Exception, e:
        logger.warn('Error in energy evaluation: {0}'.format(e), exc_info=True)
        stro = 'ERROR: Problem in Energy Evaluation'
        print stro
        print e
        stro += '\n' + repr(e)
        os.chdir(cwd)
        f = open('problem-structures.xyz', 'a')
        totalsol = indiv[0].copy()
        #totalsol.extend(indiv.bulki)
        write_xyz(f,
                  totalsol,
                  data='Starting structure hindex={0}'.format(
                      indiv.history_index))
        indiv.energy = 10000
        f.close()
        print '    Writing structure to problemstructures.xyz file. Structure (hindex) : ' + indiv.history_index
        print '    Setting individual energy to 50000.'
        #outs = [10000, starting.bulki, starting, stro]
        outs = [10000, starting, starting, stro]
コード例 #3
0
ファイル: enpafit.py プロジェクト: uw-cmg/MAST
def enpafit(indiv,Optimizer):
    """Fitness function to evaluate the energy per atom of an individual structure.
    Inputs:
        indiv = Individual class object to be evaluated
        Optimizer = Optimizer class object with needed parameters
    Outputs:
        indiv = Evaluated Individual class object
    """
    #logger = initialize_logger(Optimizer.loggername)
    logger = logging.getLogger(Optimizer.loggername)
    starting = indiv.duplicate()
    cwd = os.getcwd()
    try:
        outs = eval_energy(Optimizer,indiv)
    except Exception, e:
        logger.warn('Error in energy evaluation: {0}'.format(e), exc_info=True)
        stro = 'ERROR: Problem in Energy Evaluation'
        print stro
        print e
        stro += '\n' + repr(e)
        os.chdir(cwd)
        f=open('problem-structures.xyz','a')
        totalsol = indiv[0].copy()
        totalsol.extend(indiv.bulki)
        write_xyz(f,totalsol,data='Starting structure hindex={0}'.format(indiv.history_index))
        indiv.energy = 10000
        f.close()
        print '    Writing structure to problemstructures.xyz file. Structure (hindex) : '+indiv.history_index
        print '    Setting individual energy to 50000.'
        outs = [10000, starting.bulki, starting, stro]
コード例 #4
0
ファイル: stem_cost_rotation.py プロジェクト: uw-cmg/MAST
def stem_cost_rotation(indiv, Optimizer):
    '''Function to calculate STEM_Cost fitness of individual.
    Input:
        indiv = structopt_stem Individual class object to be evaluated
        Optimizer = structopt_stem Optimizer class object
            Must have STEM Calc function attached
    Output:
        indiv = structopt_stem Individual class object with new fitness.
    '''
    if 'FIT' in Optimizer.debug:
        debug=True
    else:
        debug=False
    logger = logging.getLogger(Optimizer.loggername)
    starting = indiv.duplicate()
    cwd = os.getcwd()
    try:
        outs = eval_energy(Optimizer,indiv)
    except Exception, e:
        logger.warn('Error in energy evaluation: {0}'.format(e), exc_info=True)
        stro = 'ERROR: Problem in Energy Evaluation'
        print stro
        print e
        stro += '\n' + repr(e)
        os.chdir(cwd)
        f=open('problem-structures.xyz','a')
        totalsol = indiv[0].copy()
        totalsol.extend(indiv.bulki)
        write_xyz(f,totalsol,data='Starting structure hindex={0}'.format(indiv.history_index))
        indiv.energy = 10000
        f.close()
        print '    Writing structure to problemstructures.xyz file. Structure (hindex) : '+indiv.history_index
        print '    Setting individual energy to 50000.'
        outs = [10000, starting.bulki, starting, stro]
コード例 #5
0
def formationenergy(indiv, Optimizer):
    """Function to calculate formation energy fitness of individual.
    Input:
        indiv = structopt_stem Individual class object to be evaluated
        Optimizer = structopt_stem Optimizer class object
    Output:
        indiv = structopt_stem Individual class object with new fitness.
    """
    if Optimizer.structure != 'Defect':
        if Optimizer.generation < 1:
            print 'WARNING: Formation Energy fitness calculator only available for Defect structure simulation.'
            print '     Using total energy fitness calculator instead'
        indiv = totalenfit(indiv, Optimizer)
        stro = ''
    else:
        logger = logging.getLogger(Optimizer.loggername)
        #logger = initialize_logger(Optimizer.loggername)
        starting = indiv.duplicate()
        cwd = os.getcwd()
        try:
            outs = eval_energy(Optimizer, indiv)
        except Exception, e:
            logger.warn('Error in energy evaluation: {0}'.format(e),
                        exc_info=True)
            stro = 'ERROR: Problem in Energy Evaluation'
            print stro
            print e
            stro += '\n' + repr(e)
            os.chdir(cwd)
            f = open('problem-structures.xyz', 'a')
            totalsol = indiv[0].copy()
            totalsol.extend(indiv.bulki)
            write_xyz(f,
                      totalsol,
                      data='Starting structure hindex={0}'.format(
                          indiv.history_index))
            indiv.energy = 10000
            f.close()
            print '    Writing structure to problemstructures.xyz file. Structure (hindex) : ' + indiv.history_index
            print '    Setting individual energy to 50000.'
            outs = [10000, starting.bulki, starting, stro]
        indiv.energy = outs[0]
        stro = outs[3]
        indiv.bulki = outs[1]
        #fit = (indiv.purebulkenpa*(indiv[0].get_number_of_atoms()+indiv.bulki.get_number_of_atoms()) - indiv.energy)/(indiv[0].get_number_of_atoms()+indiv.bulki.get_number_of_atoms()-indiv.natomsbulk)
        solid = Atoms()
        solid.extend(indiv[0])
        solid.extend(indiv.bulki)
        fit = indiv.energy
        passflag = True
        if abs(fit) > Optimizer.energy_cutoff_factor * (len(indiv[0]) +
                                                        len(indiv.bulki)):
            fit = 10000
            message = 'Warning: Found oddly large energy from Lammps in structure HI={0}'.format(
                indiv.history_index)
            logger.warn(message)
            print message
            print '    Setting fitness to 10000'
            passflag = False
        if math.isnan(fit):
            logger.warn('Found NAN energy structure HI={0}'.format(
                indiv.history_index))
            fit = 10000
            passflag = False
            indiv.energy = 10000
        if passflag:
            for sym, c, m, u in Optimizer.atomlist:
                nc = len([atm for atm in solid if atm.symbol == sym])
                fit -= float(nc) * float(u)
        indiv.fitness = fit
コード例 #6
0
ファイル: formationenergy.py プロジェクト: uw-cmg/MAST
def formationenergy(indiv, Optimizer):
    """Function to calculate formation energy fitness of individual.
    Input:
        indiv = structopt_stem Individual class object to be evaluated
        Optimizer = structopt_stem Optimizer class object
    Output:
        indiv = structopt_stem Individual class object with new fitness.
    """
    if Optimizer.structure != 'Defect':
        if Optimizer.generation <1:
            print 'WARNING: Formation Energy fitness calculator only available for Defect structure simulation.'
            print '     Using total energy fitness calculator instead'
        indiv = totalenfit(indiv,Optimizer)
        stro = ''
    else:
        logger = logging.getLogger(Optimizer.loggername)
        #logger = initialize_logger(Optimizer.loggername)
        starting = indiv.duplicate()
        cwd = os.getcwd()
        try:
            outs = eval_energy(Optimizer,indiv)
        except Exception, e:
            logger.warn('Error in energy evaluation: {0}'.format(e), exc_info=True)
            stro = 'ERROR: Problem in Energy Evaluation'
            print stro
            print e
            stro += '\n' + repr(e)
            os.chdir(cwd)
            f=open('problem-structures.xyz','a')
            totalsol = indiv[0].copy()
            totalsol.extend(indiv.bulki)
            write_xyz(f,totalsol,data='Starting structure hindex={0}'.format(indiv.history_index))
            indiv.energy = 10000
            f.close()
            print '    Writing structure to problemstructures.xyz file. Structure (hindex) : '+indiv.history_index
            print '    Setting individual energy to 50000.'
            outs = [10000, starting.bulki, starting, stro]
        indiv.energy = outs[0]
        stro=outs[3]
        indiv.bulki = outs[1]
        #fit = (indiv.purebulkenpa*(indiv[0].get_number_of_atoms()+indiv.bulki.get_number_of_atoms()) - indiv.energy)/(indiv[0].get_number_of_atoms()+indiv.bulki.get_number_of_atoms()-indiv.natomsbulk)
        solid=Atoms()
        solid.extend(indiv[0])
        solid.extend(indiv.bulki)
        fit=indiv.energy
        passflag = True
        if abs(fit) > Optimizer.energy_cutoff_factor*(len(indiv[0])+len(indiv.bulki)):
            fit=10000
            message = 'Warning: Found oddly large energy from Lammps in structure HI={0}'.format(indiv.history_index)
            logger.warn(message)
            print message
            print '    Setting fitness to 10000'
            passflag=False
        if math.isnan(fit):
            logger.warn('Found NAN energy structure HI={0}'.format(indiv.history_index))
            fit=10000
            passflag=False
            indiv.energy = 10000
        if passflag:
            for sym,c,m,u in Optimizer.atomlist:
                nc=len([atm for atm in solid if atm.symbol==sym])
                fit-= float(nc)*float(u)
        indiv.fitness=fit