Пример #1
0
def test_qchem_calculator():
    import numpy as np
    from ase.build import molecule
    from ase.calculators.qchem import QChem
    from ase.optimize import LBFGS

    mol = molecule('C2H6')
    calc = QChem(label='calc/ethane', method='B3LYP', basis='6-31+G*')

    mol.set_calculator(calc)
    # Check energy and forces
    np.testing.assert_allclose(mol.get_potential_energy(),
                               -2172.379183703419,
                               atol=10.)
    np.testing.assert_allclose(mol.get_forces(),
                               np.array(
                                   [[0., 0.00240141, 0.04992568],
                                    [-0., -0.00240141, -0.04992568],
                                    [-0., 0.11626015, 0.07267481],
                                    [-0.10132204, -0.05804009, 0.07538475],
                                    [0.10132204, -0.05804009, 0.07538475],
                                    [-0., -0.11626015, -0.07267481],
                                    [-0.10132204, 0.05804009, -0.07538475],
                                    [0.10132204, 0.05804009, -0.07538475]]),
                               atol=0.05)

    opt = LBFGS(mol)
    opt.run()
    assert opt.converged()
Пример #2
0
def SurfaceEnergy(images, natoms, calc, fmax=0.01, debug=False):
    """Calculate the surface energy from a list of slab images.

    Parameters
    ----------
    images: List of slab images which the calculation is based on. The x and
    y dimensions of the images unit cell must be conserved.

    natoms: Number of atoms in a atomic layer in the slabs.

    calc: Calculator object that can be attached to the images.
    """
    ucell = images[0].get_cell()

    layers = np.zeros(len(images))
    energies = np.zeros(len(images))

    if debug:
        print "Layers   Energy   LBFGS steps"

    for i, atoms in enumerate(images):
        cell = atoms.get_cell()
        if (ucell[0] != cell[0]).any() or (ucell[1] != cell[1]).any():
            raise ValueError(
                "The x and y dimensions of the unit cell must be conserved.")

        atoms.set_calculator(calc)

        dyn = LBFGS(atoms, logfile=None, trajectory=None)
        dyn.run(fmax=fmax, steps=1000)
        assert dyn.converged(), "LBFGS not converged in 100 steps!"

        layers[i] = len(atoms) / natoms
        energies[i] = atoms.get_potential_energy()

        if debug:
            print "%4i%12.3f%10i" % (layers[i], energies[i],
                                     dyn.get_number_of_steps())

    p = polyfit(layers.reshape((-1, 1)), energies, 1)
    surface_energy = p.c[0] / (2 * natoms)
    assert surface_energy > 0.0

    return surface_energy
Пример #3
0
def SurfaceEnergy(images, natoms, calc, fmax=0.01, debug=False):
    """Calculate the surface energy from a list of slab images.

    Parameters
    ----------
    images: List of slab images which the calculation is based on. The x and
    y dimensions of the images unit cell must be conserved.

    natoms: Number of atoms in a atomic layer in the slabs.

    calc: Calculator object that can be attached to the images.
    """
    ucell = images[0].get_cell()

    layers = np.zeros(len(images))
    energies = np.zeros(len(images))

    if debug:
        print "Layers   Energy   LBFGS steps"

    for i, atoms in enumerate(images):
        cell = atoms.get_cell()
        if (ucell[0] != cell[0]).any() or (ucell[1] != cell[1]).any():
            raise ValueError("The x and y dimensions of the unit cell must be conserved.")

        atoms.set_calculator(calc)

        dyn = LBFGS(atoms, logfile=None, trajectory=None)
        dyn.run(fmax=fmax, steps=1000)
        assert dyn.converged(), "LBFGS not converged in 100 steps!"

        layers[i] = len(atoms) / natoms
        energies[i] = atoms.get_potential_energy()

        if debug:
            print "%4i%12.3f%10i" % (layers[i], energies[i], dyn.get_number_of_steps())

    p = polyfit(layers.reshape((-1,1)), energies, 1)
    surface_energy = p.c[0] / (2 * natoms)
    assert surface_energy > 0.0

    return surface_energy
Пример #4
0
import numpy as np
from ase.build import molecule
from ase.calculators.qchem import QChem
from ase.optimize import LBFGS

mol = molecule('C2H6')
calc = QChem(label='calc/ethane', method='B3LYP', basis='6-31+G*')

mol.set_calculator(calc)
# Check energy and forces
np.testing.assert_allclose(mol.get_potential_energy(),
                           -2172.379183703419,
                           atol=10.)
np.testing.assert_allclose(mol.get_forces(),
                           np.array([[0., 0.00240141, 0.04992568],
                                     [-0., -0.00240141, -0.04992568],
                                     [-0., 0.11626015, 0.07267481],
                                     [-0.10132204, -0.05804009, 0.07538475],
                                     [0.10132204, -0.05804009, 0.07538475],
                                     [-0., -0.11626015, -0.07267481],
                                     [-0.10132204, 0.05804009, -0.07538475],
                                     [0.10132204, 0.05804009, -0.07538475]]),
                           atol=0.05)

opt = LBFGS(mol)
opt.run()
assert opt.converged()