File: test_aims_interface.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (104 lines) | stat: -rw-r--r-- 3,877 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import tempfile
import os

import pytest
from ase.calculators.aims import Aims
from ase import Atoms


@pytest.mark.skip('legacy test with hardcoded paths and commands')
def test_aims_interface():
    # test the new command handling + legacy behavior
    aims_command = 'aims.x'
    aims_command_alternative = 'mpirun -np 4 fhiaims.x'
    outfilename = 'alternative_aims.out'
    outfilename_default = 'aims.out'
    command = '{0:s} > {1:s}'.format(aims_command, outfilename)
    #command_alternative = '{0:s} > {1:s}'.format(aims_command_alternative, outfilename)
    command_default = '{0:s} > {1:s}'.format(aims_command, outfilename_default)
    legacy_command = 'aims.version.serial.x > aims.out'
    legacy_aims_command = legacy_command.split('>')[0].strip()
    legacy_outfilename = legacy_command.split('>')[-1].strip()

    # legacy behavior of empty init
    calc = Aims()
    assert calc.command == legacy_command
    assert calc.outfilename == legacy_outfilename
    assert calc.aims_command == legacy_aims_command

    # behavior of empty init with env variable
    os.environ['ASE_AIMS_COMMAND'] = aims_command_alternative
    calc = Aims()
    assert calc.command == '{0} > {1}'.format(aims_command_alternative, outfilename_default)
    assert calc.outfilename == outfilename_default
    assert calc.aims_command == aims_command_alternative

    # legacy behavior of "proper" command
    calc = Aims(run_command=command)
    assert calc.command == command
    assert calc.outfilename == outfilename
    assert calc.aims_command == aims_command

    # legacy behavior of an "improper" command
    calc = Aims(run_command=aims_command)
    assert calc.command == command_default
    assert calc.aims_command == aims_command
    assert calc.outfilename == outfilename_default

    # fixed "command"  behavior
    calc = Aims(command=command)
    assert calc.command == command
    assert calc.outfilename == outfilename
    assert calc.aims_command == aims_command

    # novel way to use aims_command, no specific outfile
    calc = Aims(aims_command=aims_command)
    assert calc.command == command_default
    assert calc.outfilename == outfilename_default
    assert calc.aims_command == aims_command

    calc = Aims(aims_command=aims_command,
                outfilename=outfilename)
    assert calc.command == command
    assert calc.outfilename == outfilename
    assert calc.aims_command == aims_command

    # # testing the setters
    calc.command = command_default
    assert calc.outfilename == outfilename_default
    assert calc.aims_command == aims_command
    assert calc.command == command_default

    #calc.set_aims_command(aims_command_alternative)
    calc.aims_command = aims_command_alternative
    assert calc.aims_command == aims_command_alternative
    assert calc.outfilename == outfilename_default
    assert calc.command == '{} > {}'.format(aims_command_alternative, outfilename_default)

    calc.outfilename = outfilename
    assert calc.command == '{} > {}'.format(aims_command_alternative, outfilename)
    assert calc.aims_command == aims_command_alternative
    assert calc.outfilename == outfilename

    # test writing files
    tmp_dir = tempfile.mkdtemp()
    water = Atoms('HOH', [(1, 0, 0), (0, 0, 0), (0, 1, 0)])
    calc = Aims(xc='PBE',
                output=['dipole'],
                sc_accuracy_etot=1e-6,
                sc_accuracy_eev=1e-3,
                sc_accuracy_rho=1e-6,
                species_dir="/data/rittmeyer/FHIaims/species_defaults/light/",
                sc_accuracy_forces=1e-4,
                label=tmp_dir,
                )
    try:
        calc.prepare_input_files()
        raise AssertionError
    except ValueError:
        pass

    calc.atoms = water
    calc.prepare_input_files()
    for f in ['control.in', 'geometry.in']:
        assert os.path.isfile(os.path.join(tmp_dir, f))