예제 #1
0
def totalenfit(indiv, Optimizer):
    """Function to calculate total 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.
    """
    #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]
예제 #2
0
파일: StemCalc.py 프로젝트: uw-cmg/MAST
def find_stem_coeff(Optimizer, indiv):
    from MAST.structopt_stem.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
예제 #3
0
def find_stem_coeff(Optimizer, indiv):
    from MAST.structopt_stem.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