예제 #1
0
def test_axis_layout():
    system = Atoms('H')
    a = 3.
    system.cell = (a, a, a)
    system.pbc = 1

    for axis in range(3):
        system.center()
        system.positions[0, axis] = 0.0
        calc = Octopus(**getkwargs(label='ink-%s' % 'xyz'[axis],
                                   Output='density + potential + wfs'))
        system.set_calculator(calc)
        system.get_potential_energy()
        rho = calc.get_pseudo_density(pad=False)
        #for dim in rho.shape:
        #    assert dim % 2 == 1, rho.shape

        maxpoint = np.unravel_index(rho.argmax(), rho.shape)
        print('axis=%d: %s/%s' % (axis, maxpoint, rho.shape))

        expected_max = [dim // 2 for dim in rho.shape]
        expected_max[axis] = 0
        assert maxpoint == tuple(expected_max), '%s vs %s' % (maxpoint,
                                                              expected_max)

    errs = check_interface(calc)

    for err in errs:
        if err.code == 'not implemented':
            continue

        if err.methname == 'get_dipole_moment':
            assert isinstance(err.error, OctopusIOError)
        else:
            raise AssertionError(err.error)
예제 #2
0
def test_axis_layout():
    system = Atoms('H')
    a = 3.
    system.cell = (a, a, a)
    system.pbc = 1

    for axis in range(3):
        system.center()
        system.positions[0, axis] = 0.0
        calc = Octopus(**getkwargs(label='ink-%s' % 'xyz'[axis],
                                   Output='density + potential + wfs'))
        system.set_calculator(calc)
        system.get_potential_energy()
        rho = calc.get_pseudo_density(pad=False)
        #for dim in rho.shape:
        #    assert dim % 2 == 1, rho.shape

        maxpoint = np.unravel_index(rho.argmax(), rho.shape)
        print('axis=%d: %s/%s' % (axis, maxpoint, rho.shape))

        expected_max = [dim // 2 for dim in rho.shape]
        expected_max[axis] = 0
        assert maxpoint == tuple(expected_max), '%s vs %s' % (maxpoint,
                                                              expected_max)

    errs = check_interface(calc)

    for err in errs:
        if err.code == 'not implemented':
            continue

        if err.methname == 'get_dipole_moment':
            assert isinstance(err.error, OctopusIOError)
        else:
            raise AssertionError(err.error)
예제 #3
0
def calculate(name, system, **kwargs):
    print('Calculate', name, system)
    label = 'ink-%s' % name

    kwargs0 = dict(stdout="'stdout.txt'",
                   FromScratch=True,
                   RestartWrite=False,
                   command='mpirun -np 4 octopus')
    kwargs.update(**kwargs0)

    calc = Octopus(label=label, **kwargs)
    system.calc = calc
    E = system.get_potential_energy()
    eig = calc.get_eigenvalues()
    check_interface(calc)

    restartcalc = Octopus(label)
    check_interface(restartcalc)

    # Check reconstruction of Atoms object
    new_atoms = restartcalc.get_atoms()
    print('new')
    print(new_atoms.positions)
    calc2 = Octopus(label='ink-restart-%s' % name, **kwargs)
    new_atoms.calc = calc2
    E2 = new_atoms.get_potential_energy()
    #print('energy', E, E2)
    eig2 = calc2.get_eigenvalues()
    eig_err = np.abs(eig - eig2).max()
    e_err = abs(E - E2)
    print('Restart E err', e_err)
    print('Restart eig err', eig_err)
    assert e_err < 5e-5
    assert eig_err < 5e-5
    return calc
def test_restart_octopus():
    from ase.calculators.octopus import Octopus
    from ase.calculators.interfacechecker import check_interface
    from ase.build import molecule

    system = molecule('H2')
    system.center(vacuum=2.0)

    directory = 'ink'

    calc0 = Octopus(directory=directory,
                    check_keywords=False,
                    FromScratch=True,
                    stdout="'stdout.txt'",
                    stderr="'stderr.txt'",
                    Spacing='0.25 * Angstrom',
                    OutputFormat='cube + xcrysden')

    system.set_calculator(calc0)
    system.get_potential_energy()

    # Must make one test with well-defined cell and one without.

    calc1 = Octopus(directory)
    system = calc1.get_atoms()

    E = system.get_potential_energy()
    print('energy', E)

    check_interface(calc1)
    # view(system)

    atoms = Octopus.read_atoms(directory)
    check_interface(atoms.calc)

    changes = calc1.check_state(atoms)
    print('changes', changes)
    assert len(changes) == 0
예제 #5
0
from __future__ import print_function

from ase.calculators.octopus import Octopus
from ase.calculators.interfacechecker import check_interface
from ase.build import molecule

system = molecule('H2O')
system.center(vacuum=2.0)

label = 'ink'

calc0 = Octopus(label=label,
                FromScratch=True,
                stdout="'stdout.txt'",
                stderr="'stderr.txt'",
                Spacing='0.15 * Angstrom',
                Output='density + wfs + potential',
                OutputFormat='cube + xcrysden')

system.set_calculator(calc0)
system.get_potential_energy()

# Must make one test with well-defined cell and one without.

calc1 = Octopus(label)
system = calc1.get_atoms()

E = system.get_potential_energy()
print('energy', E)

errs = check_interface(calc1)
예제 #6
0
from ase.calculators.octopus import Octopus
from ase.build import bulk

system = bulk('Si', orthorhombic=True)

calc = Octopus(label='silicon',
               Spacing=0.25,
               KPointsGrid=[[4, 4, 4]],
               KPointsUseSymmetries=True,
               Output='dos + density + potential',
               OutputHow='xcrysden',
               DosGamma=0.1)

system.set_calculator(calc)
system.get_potential_energy()
예제 #7
0
from ase.calculators.octopus import Octopus
from ase.calculators.interfacechecker import check_interface
from ase.build import molecule

system = molecule('H2')
system.center(vacuum=2.0)

directory = 'ink'

calc0 = Octopus(directory=directory,
                check_keywords=False,
                FromScratch=True,
                stdout="'stdout.txt'",
                stderr="'stderr.txt'",
                Spacing='0.25 * Angstrom',
                OutputFormat='cube + xcrysden')

system.set_calculator(calc0)
system.get_potential_energy()

# Must make one test with well-defined cell and one without.

calc1 = Octopus(directory)
system = calc1.get_atoms()

E = system.get_potential_energy()
print('energy', E)

errs = check_interface(calc1)
# view(system)
예제 #8
0
 def calc(self, **kwargs):
     from ase.calculators.octopus import Octopus
     command = f'{self.executable} > stdout.log'
     return Octopus(command=command, **kwargs)
예제 #9
0
from ase.calculators.octopus import Octopus
from ase.build import molecule
from ase.optimize import QuasiNewton

# Ethanol molecule with somewhat randomized initial positions:
system = molecule('CH3CH2OH')
system.rattle(stdev=0.1, seed=42)
system.center(vacuum=3.0)

calc = Octopus(label='ethanol', Spacing=0.25, BoxShape='parallelepiped')
system.set_calculator(calc)

opt = QuasiNewton(system, logfile='opt.log', trajectory='opt.traj')
opt.run(fmax=0.05)
예제 #10
0
label = 'ink'

calc0 = Octopus(label=label,
               FromScratch=True,
               stdout="'stdout.txt'",
               stderr="'stderr.txt'",
               Spacing=0.15,
               Output='density + wfs + potential',
               OutputHow='cube + xcrysden')

system.set_calculator(calc0)
system.get_potential_energy()

# Must make one test with well-defined cell and one without.

calc1 = Octopus(label)
system = calc1.get_atoms()

E = system.get_potential_energy()
print('energy', E)

errs = check_interface(calc1)
#view(system)

atoms = Octopus.read_atoms(label)
errs = check_interface(atoms.calc)

changes = calc1.check_state(atoms)
print('changes', changes)
assert len(changes) == 0
예제 #11
0
from __future__ import print_function

from ase.calculators.octopus import Octopus
from ase.calculators.interfacechecker import check_interface
from ase.build import molecule

system = molecule('H2O')
system.center(vacuum=2.0)

label = 'ink'

calc0 = Octopus(label=label,
                FromScratch=True,
                stdout="'stdout.txt'",
                stderr="'stderr.txt'",
                Spacing=0.15,
                Output='density + wfs + potential',
                OutputHow='cube + xcrysden',
                _autofix_outputformats=True)

system.set_calculator(calc0)
system.get_potential_energy()

# Must make one test with well-defined cell and one without.

calc1 = Octopus(label)
system = calc1.get_atoms()

E = system.get_potential_energy()
print('energy', E)
예제 #12
0
def test_integrals(pbc=True):
    system = molecule('H2O')
    a = 2.6006  # So the spacing does not divide exactly
    system.cell = (a, a, a)
    system.center()
    system.pbc = pbc
    spacing = 0.2
    calc = Octopus(**getkwargs(label='ink-integrals-pbc-%s' % pbc,
                               # Restart destroys normalization of output
                               # ...........sometimes.
                               RestartWrite=False,
                               Output='density + potential + wfs',
                               OutputHow='cube + xcrysden',
                               ExtraStates=0,
                               Spacing=spacing,
                               SCFCalculateDipole=True))
    system.set_calculator(calc)
    E = system.get_potential_energy()

    if pbc:
        Eref = -496.98663392
    else:
        Eref = -451.05348602
    err = E - Eref
    print('Energy=%f :: err=%e' % (E, err))
    assert err < 1e-7

    rho = calc.get_pseudo_density(pad=False)
    v = calc.get_effective_potential(pad=False)

    if pbc:  # spacing adjusted but cell constant
        dv = system.get_volume() / rho.size
    else:  # cell adjusted but spacing constant
        dv = spacing**3

    ne = rho.sum() * dv
    err = abs(ne - 8.0)
    print('nelectrons: %f, err: %e' % (ne, err))
    assert err < 1e-12

    for n in range(calc.get_number_of_bands()):
        psi = calc.get_pseudo_wave_function(band=n, pad=True)
        norm = (np.abs(psi)**2).sum() * dv
        err = abs(norm - 1)
        print('norm=%f :: err=%e' % (norm, err))
        assert err < 1e-12

    eps = calc.get_eigenvalues()
    f = calc.get_occupation_numbers()
    E_band = (eps * f).sum()
    E_nv = (rho * v).sum() * dv
    if pbc:
        E_nl = -155.16024733 # Reference value from output.
        E_kin_ref = 377.899824
    else:
        E_nl = -151.28372313 # Ref from output.
        E_kin_ref = 396.66270596
    E_kin_ours = E_band - E_nv - E_nl
    err = abs(E_kin_ours - E_kin_ref)
    print('E_band=%f :: E_nv=%f :: E_kin_ours=%f :: err=%e'
          % (E_band, E_nv, E_kin_ours, err))
    assert err < 5e-4  # Orig err: 6.8e-05 (pbc=False) and 3.47e-07 (pbc=True)

    errs = check_interface(calc)
    for err in errs:
        if err.code == 'not implemented':
            continue
        else:
            raise AssertionError(err.error)
예제 #13
0
def test_integrals(pbc=True):
    system = molecule('H2O')
    a = 2.6006  # So the spacing does not divide exactly
    system.cell = (a, a, a)
    system.center()
    system.pbc = pbc
    spacing = 0.2
    calc = Octopus(**getkwargs(
        label='ink-integrals-pbc-%s' % pbc,
        # Restart destroys normalization of output
        # ...........sometimes.
        RestartWrite=False,
        Output='density + potential + wfs',
        OutputFormat='cube + xcrysden',
        ExtraStates=0,
        Spacing=spacing,
        SCFCalculateDipole=True))
    system.set_calculator(calc)
    E = system.get_potential_energy()

    if pbc:
        Eref = -496.98663392
    else:
        Eref = -451.05348602
    err = abs(E - Eref)
    #print('Energy=%f :: err=%e' % (E, err))
    # The reference has changed between version 5 and trunk,
    # so we will not check the total energy.
    # Checks of individual contributions that are physical and therefore
    # trustworthy will have to be sufficient.
    #assert err < 5e-3

    rho = calc.get_pseudo_density(pad=False)
    v = calc.get_effective_potential(pad=False)

    if pbc:  # spacing adjusted but cell constant
        dv = system.get_volume() / rho.size
    else:  # cell adjusted but spacing constant
        dv = spacing**3

    ne = rho.sum() * dv
    err = abs(ne - 8.0)
    print('nelectrons: %f, err: %e' % (ne, err))
    assert err < 1e-12

    for n in range(calc.get_number_of_bands()):
        psi = calc.get_pseudo_wave_function(band=n, pad=True)
        norm = (np.abs(psi)**2).sum() * dv
        err = abs(norm - 1)
        print('norm=%f :: err=%e' % (norm, err))
        assert err < 1e-12

    eps = calc.get_eigenvalues()
    f = calc.get_occupation_numbers()
    E_band = (eps * f).sum()
    E_nv = (rho * v).sum() * dv
    if pbc:
        E_nl = -155.16024733  # Reference value from output.
        E_kin_ref = 377.899824
    else:
        E_nl = -151.28372313  # Ref from output.
        E_kin_ref = 396.66270596
    E_kin_ours = E_band - E_nv - E_nl
    err = abs(E_kin_ours - E_kin_ref)
    print('E_band=%f :: E_nv=%f :: E_kin_ours=%f :: err=%e' %
          (E_band, E_nv, E_kin_ours, err))
    assert err < 5e-3  # Orig err: 6.8e-05 (pbc=False) and 3.47e-07 (pbc=True)

    errs = check_interface(calc)
    for err in errs:
        if err.code == 'not implemented':
            continue
        else:
            raise AssertionError(err.error)