Exemplo n.º 1
0
 def calc(self, **kwargs):
     from ase.calculators.cp2k import CP2K
     return CP2K(command=self.executable, **kwargs)
Exemplo n.º 2
0
def main():
    """Adopted from ase/test/stress.py"""

    if "ASE_CP2K_COMMAND" not in os.environ:
        raise NotAvailable('$ASE_CP2K_COMMAND not defined')

    # setup a Fist Lennard-Jones Potential
    inp = """&FORCE_EVAL
                  &MM
                    &FORCEFIELD
                      &SPLINE
                        EMAX_ACCURACY 500.0
                        EMAX_SPLINE    1000.0
                        EPS_SPLINE 1.0E-9
                      &END
                      &NONBONDED
                        &LENNARD-JONES
                          atoms Ar Ar
                          EPSILON [eV] 1.0
                          SIGMA [angstrom] 1.0
                          RCUT [angstrom] 10.0
                        &END LENNARD-JONES
                      &END NONBONDED
                      &CHARGE
                        ATOM Ar
                        CHARGE 0.0
                      &END CHARGE
                    &END FORCEFIELD
                    &POISSON
                      &EWALD
                        EWALD_TYPE none
                      &END EWALD
                    &END POISSON
                  &END MM
                &END FORCE_EVAL"""

    calc = CP2K(label="test_stress", inp=inp, force_eval_method="Fist")

    # Theoretical infinite-cutoff LJ FCC unit cell parameters
    vol0 = 4 * 0.91615977036  # theoretical minimum
    a0 = vol0 ** (1 / 3)

    a = bulk('Ar', 'fcc', a=a0)
    cell0 = a.get_cell()

    a.calc = calc
    a.set_cell(np.dot(a.cell,
                      [[1.02, 0, 0.03],
                       [0, 0.99, -0.02],
                       [0.1, -0.01, 1.03]]),
               scale_atoms=True)

    a *= (1, 2, 3)
    cell0 *= np.array([1, 2, 3])[:, np.newaxis]

    a.rattle()

    # Verify analytical stress tensor against numerical value
    s_analytical = a.get_stress()
    s_numerical = a.calc.calculate_numerical_stress(a, 1e-5)
    s_p_err = 100 * (s_numerical - s_analytical) / s_numerical

    print("Analytical stress:\n", s_analytical)
    print("Numerical stress:\n", s_numerical)
    print("Percent error in stress:\n", s_p_err)
    assert np.all(abs(s_p_err) < 1e-5)

    # Minimize unit cell
    opt = MDMin(UnitCellFilter(a), dt=0.01)
    opt.run(fmax=1e-3)

    # Verify minimized unit cell using Niggli tensors
    g_minimized = np.dot(a.cell, a.cell.T)
    g_theory = np.dot(cell0, cell0.T)
    g_p_err = 100 * (g_minimized - g_theory) / g_theory

    print("Minimized Niggli tensor:\n", g_minimized)
    print("Theoretical Niggli tensor:\n", g_theory)
    print("Percent error in Niggli tensor:\n", g_p_err)
    assert np.all(abs(g_p_err) < 1)

    print('passed test "stress"')
Exemplo n.º 3
0
def main():
    """Adopted from ase/test/stress.py"""

    if "ASE_CP2K_COMMAND" not in os.environ:
        raise NotAvailable('$ASE_CP2K_COMMAND not defined')

    # setup a Fist Lennard-Jones Potential
    inp = """&FORCE_EVAL
                  &MM
                    &FORCEFIELD
                      &SPLINE
                        EMAX_ACCURACY 500.0
                        EMAX_SPLINE    1000.0
                        EPS_SPLINE 1.0E-9
                      &END
                      &NONBONDED
                        &LENNARD-JONES
                          atoms Ar Ar
                          EPSILON [eV] 1.0
                          SIGMA [angstrom] 1.0
                          RCUT [angstrom] 10.0
                        &END LENNARD-JONES
                      &END NONBONDED
                      &CHARGE
                        ATOM Ar
                        CHARGE 0.0
                      &END CHARGE
                    &END FORCEFIELD
                    &POISSON
                      &EWALD
                        EWALD_TYPE none
                      &END EWALD
                    &END POISSON
                  &END MM
                &END FORCE_EVAL"""

    calc = CP2K(label="test_stress", inp=inp, force_eval_method="Fist")

    vol0 = 4 * 0.91615977036  # theoretical minimum
    a0 = vol0**(1 / 3)
    a = bulk('Ar', 'fcc', a=a0)
    a.calc = calc
    a.set_cell(np.dot(a.cell,
                      [[1.02, 0, 0.03], [0, 0.99, -0.02], [0.1, -0.01, 1.03]]),
               scale_atoms=True)

    a *= (1, 2, 3)
    a.rattle()
    sigma_vv = a.get_stress(voigt=False)
    # print(sigma_vv)
    # print(a.get_potential_energy() / len(a))
    vol = a.get_volume()

    # compare stress tensor with numeric derivative
    deps = 1e-5
    cell = a.cell.copy()
    for v in range(3):
        x = np.eye(3)
        x[v, v] += deps
        a.set_cell(np.dot(cell, x), scale_atoms=True)
        ep = a.calc.get_potential_energy(a, force_consistent=True)
        x[v, v] -= 2 * deps
        a.set_cell(np.dot(cell, x), scale_atoms=True)
        em = a.calc.get_potential_energy(a, force_consistent=True)
        s = (ep - em) / 2 / deps / vol
        # print(v, s, abs(s - sigma_vv[v, v]))
        assert abs(s - sigma_vv[v, v]) < 1e-7
    for v1 in range(3):
        v2 = (v1 + 1) % 3
        x = np.eye(3)
        x[v1, v2] = deps
        x[v2, v1] = deps
        a.set_cell(np.dot(cell, x), scale_atoms=True)
        ep = a.calc.get_potential_energy(a, force_consistent=True)
        x[v1, v2] = -deps
        x[v2, v1] = -deps
        a.set_cell(np.dot(cell, x), scale_atoms=True)
        em = a.calc.get_potential_energy(a, force_consistent=True)
        s = (ep - em) / deps / 4 / vol
        # print(v1, v2, s, abs(s - sigma_vv[v1, v2]))
        assert abs(s - sigma_vv[v1, v2]) < 1e-7

    # run a cell optimization, see if it finds back original crystal structure
    opt = MDMin(UnitCellFilter(a), dt=0.01, logfile=None)
    opt.run(fmax=0.5)
    # print(a.cell)
    for i in range(3):
        for j in range(3):
            x = np.dot(a.cell[i], a.cell[j])
            y = (i + 1) * (j + 1) * a0**2 / 2
            if i != j:
                y /= 2
            # print(i, j, x, (x - y) / x)
            assert abs((x - y) / x) < 0.01

    print('passed test "stress"')
Exemplo n.º 4
0
#!/usr/bin/env python
from ase.structure import molecule
from ase.calculators.cp2k import CP2K
from ase.io import read, write
from ase.optimize import BFGS
from ase.vibrations import Vibrations

import os

atoms = molecule('H2O')
atoms.center(vacuum=6.0)

atoms.pbc = [True, True, True]

calc = CP2K(label='molecules/h2o', xc='pbe')
atoms.set_calculator(calc)
e = atoms.get_potential_energy()
print('energy: {0:1.4f} '.format(e))
BFGS(atoms).run(fmax=0.001)
pos = atoms.get_positions()
bondlength = sum((pos[1] - pos[0])**2)**0.5
print('bond length = {0} A'.format(bondlength))

vib = Vibrations(atoms)
vib.run()
vib.summary()
Exemplo n.º 5
0
from ase.io import read
from ase.calculators.cp2k import CP2K

# Define atoms object

atoms = read("init.xyz", 0)

# Set CP2K calculator #################

workdir = "CP2Ktest"
aux_settings = {"label": workdir}

if "ASE_CP2K_COMMAND" not in os.environ:
    print("$ASE_CP2K_COMMAND not defined")
    print(
        'You can try with:\n "export ASE_CP2K_COMMAND=/usr/bin/cp2k_shell" \n\n'
    )
    sys.exit()

calc = CP2K(**aux_settings)

atoms.set_calculator(calc)

# Create Client
# inet
port = 10200
host = "localhost"
client = SocketClient(host=host, port=port)

client.run(atoms)
Exemplo n.º 6
0
 def exit(self):
     CP2K.__del__(self)
Exemplo n.º 7
0
    def getCalculator(self):
        """Mangle the supplied settings and return an Abinit ASE Calculator object."""

        ecut = self.settings["settings"]["cutoff_rho"]
        kind_settings = self.settings["kind_settings"]

        if 'pseudopotential' in self.settings.keys(
        ) and self.settings["pseudopotential"] == "ALL":
            pseudo = "ALL"
        else:
            pseudo = False

        if "kpoints" in self.settings.keys():
            kpoints = list(self.settings["kpoints"])
            if "kpoint_shift" in self.settings["settings"].keys(
            ):  # apply k-point origin shift
                kpoints.extend(self.settings["settings"]["kpoint_shift"])
        else:
            kpoints = None

        if "qs_settings" in self.settings["settings"].keys():
            qs_settings = self.settings["settings"]["qs_settings"]
        else:
            qs_settings = {}

        if "rel_settings" in self.settings["settings"].keys():
            rel_settings = self.settings["settings"]["rel_settings"]
        else:
            rel_settings = {}

        if "multiplicity" in self.settings.keys():
            multiplicity = self.settings["multiplicity"]
        else:
            multiplicity = 1

        if "charge" in self.settings.keys():
            charge = self.settings["charge"]
        else:
            charge = 0

        magmoms = self.structure.get_initial_magnetic_moments()

        inp_template = self.input_template

        calc = CP2K(
            label="test",
            command=
            "module load gcc-suite/5.3.0 >/dev/null 2>&1; mpirun -np 4 /users/ralph/cp2k/cp2k-code/exe/Linux-x86-64-gfortran-local/cp2k_shell.popt",
            kind_settings=kind_settings,
            basis_set_file=False,
            potential_file=False,
            basis_set=False,
            pseudo_potential=pseudo,
            kpoints=kpoints,
            xc="PBE",
            cutoff=ecut,
            max_scf=200,
            inp=inp_template,
            uks=magmoms.any() or (multiplicity > 1),
            qs_settings=qs_settings,
            rel_settings=rel_settings,
            charge=charge,
            multiplicity=multiplicity)

        return calc
Exemplo n.º 8
0
constraint_s = " ".join(
    [str(i + 1) for i in range(len(atoms)) if atoms[i].position[2] < 9])
print constraint_s
constraint = FixAtoms(
    indices=[atom.index for atom in atoms if atom.position[2] < 9])
c = FixBondLength(274, 276)

atoms.set_constraint([constraint, c])
io.write('InitialGeom.traj', atoms)

SYSNAME = 'MgAl2O4'

calc = CP2K(label=SYSNAME,
            xc='PBE',
            cutoff=None,
            basis_set_file=None,
            potential_file=None,
            basis_set=None,
            pseudo_potential=None,
            stress_tensor=False,
            max_scf=None,
            inp=inp,
            print_level='LOW')

atoms.set_calculator(calc)
from ase.io.trajectory import Trajectory
Traj = Trajectory('qn.traj', 'a', atoms)
dyn = QuasiNewton(atoms, trajectory=Traj, logfile='qn.log', restart='qn.pckl')
dyn.run(fmax=0.1)