-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_01.py
72 lines (52 loc) · 1.95 KB
/
example_01.py
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
#!/usr/bin/env python
"""Run a test calculation on localhost.
Usage: ./example_01.py
"""
from os import path
import click
from aiida import cmdline, engine
from aiida.plugins import CalculationFactory, DataFactory
from aiida_koopmans import helpers
INPUT_DIR = path.join(path.dirname(path.realpath(__file__)), "input_files")
def test_run(koopmans_code):
"""Run a calculation on the localhost computer.
Uses test helpers to create AiiDA Code on the fly.
"""
if not koopmans_code:
# get code
computer = helpers.get_computer()
koopmans_code = helpers.get_code(entry_point="koopmans", computer=computer)
# Prepare input parameters
DiffParameters = DataFactory("koopmans")
parameters = DiffParameters({"ignore-case": True})
SinglefileData = DataFactory("core.singlefile")
file1 = SinglefileData(file=path.join(INPUT_DIR, "file1.txt"))
file2 = SinglefileData(file=path.join(INPUT_DIR, "file2.txt"))
# set up calculation
inputs = {
"code": koopmans_code,
"parameters": parameters,
"file1": file1,
"file2": file2,
"metadata": {
"description": "Test job submission with the aiida_koopmans plugin",
},
}
# Note: in order to submit your calculation to the aiida daemon, do:
# from aiida.engine import submit
# future = submit(CalculationFactory('koopmans'), **inputs)
result = engine.run(CalculationFactory("koopmans"), **inputs)
computed_diff = result["koopmans"].get_content()
print(f"Computed diff between files: \n{computed_diff}")
@click.command()
@cmdline.utils.decorators.with_dbenv()
@cmdline.params.options.CODE()
def cli(code):
"""Run example.
Example usage: $ ./example_01.py --code diff@localhost
Alternative (creates diff@localhost-test code): $ ./example_01.py
Help: $ ./example_01.py --help
"""
test_run(code)
if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter