Example #1
0
def totalenfit(indiv, Optimizer):
    """Function to calculate total energy fitness of individual.
    Input:
        indiv = structopt Individual class object to be evaluated
        Optimizer = structopt Optimizer class object
    Output:
        indiv = structopt 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]
Example #2
0
def sibias2(indiv, Optimizer):
    """Function to calculate total energy fitness of individual and bias away 
    from Si-Interstitials.
    Input:
        indiv = structopt Individual class object to be evaluated
        Optimizer = structopt Optimizer class object
    Output:
        indiv = structopt 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]
Example #3
0
def find_stem_coeff(Optimizer, indiv):
    from MAST.structopt.tools.eval_energy import eval_energy
    outs = eval_energy([Optimizer, indiv])
    indiv.energy = outs[0]
    stro = outs[3]
    if Optimizer.structure == 'Defect' or Optimizer.structure == 'Surface':
        indiv.bulki = outs[1]
    chisq = Optimizer.stemcalc.run(indiv[0])
    aflag = True
    alpha = 1.0
    while True:
        value = alpha * chisq
        div = abs(indiv.energy) / value
        if div < 1:
            alpha *= 0.1
        elif div > 10:
            alpha *= 10
        else:
            break
    indiv.fitness = indiv.energy + alpha * chisq
    return alpha, indiv
Example #4
0
def find_stem_coeff(Optimizer, indiv):
    from MAST.structopt.tools.eval_energy import eval_energy
    outs = eval_energy([Optimizer,indiv])
    indiv.energy = outs[0]
    stro=outs[3]
    if Optimizer.structure == 'Defect' or Optimizer.structure=='Surface':
        indiv.bulki = outs[1]
    chisq = Optimizer.stemcalc.run(indiv[0])
    aflag=True
    alpha = 1.0
    while True:
        value=alpha*chisq
        div=abs(indiv.energy)/value
        if div <1:
            alpha*=0.1
        elif div >10:
            alpha*=10
        else:
            break
    indiv.fitness=indiv.energy/indiv[0].get_number_of_atoms()+alpha*chisq
    return alpha, indiv