/
example_dft.py
115 lines (98 loc) · 3.55 KB
/
example_dft.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
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
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
# pylint: disable=invalid-name
###############################################################################
# Copyright (c), The AiiDA-CP2K authors. #
# SPDX-License-Identifier: MIT #
# AiiDA-CP2K is hosted on GitHub at https://github.com/aiidateam/aiida-cp2k #
# For further information on the license, see the LICENSE.txt file. #
###############################################################################
"""Run simple DFT calculation."""
import os
import sys
import click
import ase.io
from aiida.engine import run
from aiida.orm import (Code, Dict, SinglefileData, StructureData)
from aiida.common import NotExistent
def example_dft(cp2k_code):
"""Run simple DFT calculation."""
print("Testing CP2K ENERGY on H2O (DFT)...")
thisdir = os.path.dirname(os.path.realpath(__file__))
# Structure.
structure = StructureData(ase=ase.io.read(os.path.join(thisdir, '..', "files", 'h2o.xyz')))
# Basis set.
basis_file = SinglefileData(file=os.path.join(thisdir, "..", "files", "BASIS_MOLOPT"))
# Pseudopotentials.
pseudo_file = SinglefileData(file=os.path.join(thisdir, "..", "files", "GTH_POTENTIALS"))
# Parameters.
parameters = Dict(
dict={
'FORCE_EVAL': {
'METHOD': 'Quickstep',
'DFT': {
'BASIS_SET_FILE_NAME': 'BASIS_MOLOPT',
'POTENTIAL_FILE_NAME': 'GTH_POTENTIALS',
'QS': {
'EPS_DEFAULT': 1.0e-12,
'WF_INTERPOLATION': 'ps',
'EXTRAPOLATION_ORDER': 3,
},
'MGRID': {
'NGRIDS': 4,
'CUTOFF': 280,
'REL_CUTOFF': 30,
},
'XC': {
'XC_FUNCTIONAL': {
'_': 'LDA',
},
},
'POISSON': {
'PERIODIC': 'none',
'PSOLVER': 'MT',
},
},
'SUBSYS': {
'KIND': [
{
'_': 'O',
'BASIS_SET': 'DZVP-MOLOPT-SR-GTH',
'POTENTIAL': 'GTH-LDA-q6'
},
{
'_': 'H',
'BASIS_SET': 'DZVP-MOLOPT-SR-GTH',
'POTENTIAL': 'GTH-LDA-q1'
},
],
},
}
})
# Construct process builder.
builder = cp2k_code.get_builder()
builder.structure = structure
builder.parameters = parameters
builder.code = cp2k_code
builder.file = {
'basis': basis_file,
'pseudo': pseudo_file,
}
builder.metadata.options.resources = {
"num_machines": 1,
"num_mpiprocs_per_machine": 1,
}
builder.metadata.options.max_wallclock_seconds = 1 * 3 * 60
print("Submitted calculation...")
run(builder)
@click.command('cli')
@click.argument('codelabel')
def cli(codelabel):
"""Click interface."""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist.".format(codelabel))
sys.exit(1)
example_dft(code)
if __name__ == '__main__':
cli() # pylint: disable=no-value-for-parameter