from ase.calculators.emt import EMT
from ase.optimize import BFGS
#------------------------------------------------------------------------------------------
def ene_EMT(moleculein):
    """Calculate the potential energy of a structure using ASE's Effective Medium Theory.

in:
    moleculein (ase.Atoms): atomic structure to evaluate. The EMT calculator is
        attached in-place before evaluating.
out:
    float: potential energy in eV.
"""
    moleculein.calc = EMT()
    energy = moleculein.get_potential_energy()
    return energy
#------------------------------------------------------------------------------------------
def opt_EMT(moleculein):
    """Geometry-optimize a structure with the EMT calculator using BFGS.

in:
    moleculein (ase.Atoms): atomic structure to optimize. Modified in-place.
out:
    ase.Atoms: the optimized structure with info['e'] set to the final energy in eV.
    Optimization runs for at most 200 steps with fmax=0.001 eV/Ang.
"""
    moleculein.calc = EMT()
    optimizer = BFGS(moleculein, logfile=None)
    optimizer.run(fmax=0.001, steps=200)
    moleculein.info['e']=moleculein.get_potential_energy()
    return moleculein
#------------------------------------------------------------------------------------------
