def test_siesta_zmat():
    import os
    from ase.calculators.siesta.siesta import Siesta
    from ase.constraints import FixAtoms, FixedLine, FixedPlane
    from ase import Atoms

    pseudo_path = 'pseudos'
    if not os.path.exists(pseudo_path): os.makedirs(pseudo_path)

    # Make dummy pseudopotentials.
    for symbol in 'HCO':
        with open('{0}/{1}.lda.psf'.format(pseudo_path, symbol), 'w') as fd:
            fd.close()

    atoms = Atoms('CO2', [(0.0, 0.0, 0.0), (-1.178, 0.0, 0.0),
                          (1.178, 0.0, 0.0)])

    c1 = FixAtoms(indices=[0])
    c2 = FixedLine(1, [0.0, 1.0, 0.0])
    c3 = FixedPlane(2, [1.0, 0.0, 0.0])

    atoms.set_constraint([c1, c2, c3])

    custom_dir = './dir1/'

    # Test simple fdf-argument case.
    siesta = Siesta(label=custom_dir + 'test_label',
                    symlink_pseudos=False,
                    atomic_coord_format='zmatrix',
                    fdf_arguments={
                        'MD.TypeOfRun': 'CG',
                        'MD.NumCGsteps': 1000
                    })

    atoms.set_calculator(siesta)
    siesta.write_input(atoms, properties=['energy'])

    assert os.path.isfile(os.path.join(custom_dir, 'C.lda.1.psf'))
    assert os.path.isfile(os.path.join(custom_dir, 'O.lda.2.psf'))

    with open(os.path.join(custom_dir, 'test_label.fdf'), 'r') as fd:
        lines = fd.readlines()
    lsl = [line.split() for line in lines]
    assert ['cartesian'] in lsl
    assert ['%block', 'Zmatrix'] in lsl
    assert ['%endblock', 'Zmatrix'] in lsl
    assert ['MD.TypeOfRun', 'CG'] in lsl
    assert any(
        [line.split()[4:9] == ['0', '0', '0', '1', 'C'] for line in lines])
    assert any(
        [line.split()[4:9] == ['0', '1', '0', '2', 'O'] for line in lines])
    assert any(
        [line.split()[4:9] == ['0', '1', '1', '3', 'O'] for line in lines])
示例#2
0
atoms.set_constraint([c1, c2, c3])

custom_dir = './dir1/'

# Test simple fdf-argument case.
siesta = Siesta(label=custom_dir + 'test_label',
                symlink_pseudos=False,
                atomic_coord_format='zmatrix',
                fdf_arguments={
                    'MD.TypeOfRun': 'CG',
                    'MD.NumCGsteps': 1000
                })

atoms.set_calculator(siesta)
siesta.write_input(atoms, properties=['energy'])

assert os.path.isfile(os.path.join(custom_dir, 'C.lda.1.psf'))
assert os.path.isfile(os.path.join(custom_dir, 'O.lda.2.psf'))

with open(os.path.join(custom_dir, 'test_label.fdf'), 'r') as fd:
    lines = fd.readlines()
lsl = [line.split() for line in lines]
assert ['cartesian'] in lsl
assert ['%block', 'Zmatrix'] in lsl
assert ['%endblock', 'Zmatrix'] in lsl
assert ['MD.TypeOfRun', 'CG'] in lsl
assert any([line.split()[4:9] == ['0', '0', '0', '1', 'C'] for line in lines])
assert any([line.split()[4:9] == ['0', '1', '0', '2', 'O'] for line in lines])
assert any([line.split()[4:9] == ['0', '1', '1', '3', 'O'] for line in lines])
示例#3
0
def test_siesta():
    import numpy as np

    from ase.calculators.siesta.siesta import Siesta
    from ase.calculators.siesta.parameters import Species, PAOBasisBlock
    from ase.calculators.calculator import FileIOCalculator
    from ase import Atoms

    # Setup test structures.
    h = Atoms('H', [(0.0, 0.0, 0.0)])
    ch4 = Atoms('CH4', np.array([
        [0.000000, 0.000000, 0.000000],
        [0.682793, 0.682793, 0.682793],
        [-0.682793, -0.682793, 0.682790],
        [-0.682793, 0.682793, -0.682793],
        [0.682793, -0.682793, -0.682793]]))

    # Test the initialization.
    siesta = Siesta()
    assert isinstance(siesta, FileIOCalculator)
    assert isinstance(siesta.implemented_properties, tuple)
    assert isinstance(siesta.default_parameters, dict)
    assert isinstance(siesta.name, str)
    assert isinstance(siesta.default_parameters, dict)

    # Test simple fdf-argument case.
    atoms = h.copy()
    siesta = Siesta(
        label='test_label',
        fdf_arguments={'DM.Tolerance': 1e-3})
    atoms.set_calculator(siesta)
    siesta.write_input(atoms, properties=['energy'])
    atoms = h.copy()
    atoms.set_calculator(siesta)
    siesta.write_input(atoms, properties=['energy'])
    with open('test_label.fdf', 'r') as fd:
        lines = fd.readlines()
    assert any([line.split() == ['DM.Tolerance', '0.001'] for line in lines])

    # Test (slightly) more complex case of setting fdf-arguments.
    siesta = Siesta(
        label='test_label',
        mesh_cutoff=3000,
        fdf_arguments={
            'DM.Tolerance': 1e-3,
            'ON.eta': (5, 'Ry')})
    atoms.set_calculator(siesta)
    siesta.write_input(atoms, properties=['energy'])
    atoms = h.copy()
    atoms.set_calculator(siesta)
    siesta.write_input(atoms, properties=['energy'])
    with open('test_label.fdf', 'r') as f:
        lines = f.readlines()

    assert 'MeshCutoff\t3000\teV\n' in lines
    assert 'DM.Tolerance\t0.001\n' in lines
    assert 'ON.eta\t5\tRy\n' in lines

    # Test setting fdf-arguments after initiation.
    siesta.set_fdf_arguments(
        {'DM.Tolerance': 1e-2,
         'ON.eta': (2, 'Ry')})
    siesta.write_input(atoms, properties=['energy'])
    with open('test_label.fdf', 'r') as f:
        lines = f.readlines()
    assert 'MeshCutoff\t3000\teV\n' in lines
    assert 'DM.Tolerance\t0.01\n' in lines
    assert 'ON.eta\t2\tRy\n' in lines

    # Test initiation using Species.
    atoms = ch4.copy()
    species, numbers = siesta.species(atoms)
    assert all(numbers == np.array([1, 2, 2, 2, 2]))
    siesta = Siesta(species=[Species(symbol='C', tag=1)])
    species, numbers = siesta.species(atoms)
    assert all(numbers == np.array([1, 2, 2, 2, 2]))
    atoms.set_tags([0, 0, 0, 1, 0])
    species, numbers = siesta.species(atoms)
    assert all(numbers == np.array([1, 2, 2, 2, 2]))
    siesta = Siesta(species=[Species(symbol='H', tag=1, basis_set='SZ')])
    species, numbers = siesta.species(atoms)
    assert all(numbers == np.array([1, 2, 2, 3, 2]))
    siesta = Siesta(label='test_label', species=species)
    siesta.write_input(atoms, properties=['energy'])
    with open('test_label.fdf', 'r') as f:
        lines = f.readlines()
    lines = [line.split() for line in lines]
    assert ['1', '6', 'C.lda.1'] in lines
    assert ['2', '1', 'H.lda.2'] in lines
    assert ['3', '1', 'H.lda.3'] in lines
    assert ['C.lda.1', 'DZP'] in lines
    assert ['H.lda.2', 'DZP'] in lines
    assert ['H.lda.3', 'SZ'] in lines

    # Test if PAO block can be given as species.
    c_basis = """2 nodes 1.00
    0 1 S 0.20 P 1 0.20 6.00
    5.00
    1.00
    1 2 S 0.20 P 1 E 0.20 6.00
    6.00 5.00
    1.00 0.95"""
    basis_set = PAOBasisBlock(c_basis)
    species = Species(symbol='C', basis_set=basis_set)
    siesta = Siesta(label='test_label', species=[species])
    siesta.write_input(atoms, properties=['energy'])
    with open('test_label.fdf', 'r') as f:
        lines = f.readlines()
    lines = [line.split() for line in lines]
    assert ['%block', 'PAO.Basis'] in lines
    assert ['%endblock', 'PAO.Basis'] in lines
示例#4
0
# Test the initialization.
siesta = Siesta()
assert isinstance(siesta, FileIOCalculator)
assert isinstance(siesta.implemented_properties, tuple)
assert isinstance(siesta.default_parameters, dict)
assert isinstance(siesta.name, str)
assert isinstance(siesta.default_parameters, dict)

# Test simple fdf-argument case.
atoms = h.copy()
siesta = Siesta(
    label='test_label',
    fdf_arguments={'DM.Tolerance': 1e-3})
atoms.set_calculator(siesta)
siesta.write_input(atoms, properties=['energy'])
atoms = h.copy()
atoms.set_calculator(siesta)
siesta.write_input(atoms, properties=['energy'])
with open('test_label.fdf', 'r') as f:
    lines = f.readlines()
assert 'DM.Tolerance  0.001\n' == lines[0]

# Test (slightly) more complex case of setting fdf-arguments.
siesta = Siesta(
    label='test_label',
    mesh_cutoff=3000 * eV,
    fdf_arguments={
        'DM.Tolerance': 1e-3,
        'ON.eta': 5 * Ry})
atoms.set_calculator(siesta)