forked from aiidateam/aiida-cp2k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_precision.py
executable file
·118 lines (99 loc) · 3.34 KB
/
test_precision.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
116
117
118
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (c), The AiiDA team. All rights reserved. #
# This file is part of the AiiDA code. #
# #
# The code is hosted on GitHub at https://github.com/cp2k/aiida-cp2k #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
from __future__ import print_function
import sys
import ase.build
import numpy as np
from utils import wait_for_calc
from aiida import load_dbenv, is_dbenv_loaded
from aiida.backends import settings
if not is_dbenv_loaded():
load_dbenv(profile=settings.AIIDADB_PROFILE)
from aiida.common.example_helpers import test_and_get_code # noqa
from aiida.orm.data.structure import StructureData # noqa
from aiida.orm.data.parameter import ParameterData # noqa
from aiida.orm.data.singlefile import SinglefileData # noqa
# ==============================================================================
if len(sys.argv) != 2:
print("Usage: test_precision.py <code_name>")
sys.exit(1)
codename = sys.argv[1]
code = test_and_get_code(codename, expected_code_type='cp2k')
print("Testing structure roundtrip precision ase->aiida->cp2k->aiida->ase...")
# calc object
calc = code.new_calc()
# structure
epsilon = 1e-10 # expected precision in Angstrom
dist = 0.74 + epsilon
atoms = ase.Atoms('H2', positions=[(0, 0, 0), (0, 0, dist)], cell=[4, 4, 4])
structure = StructureData(ase=atoms)
calc.use_structure(structure)
# parameters
parameters = ParameterData(dict={
'GLOBAL': {
'RUN_TYPE': 'MD',
},
'MOTION': {
'MD': {
'TIMESTEP': 0.0, # do not move atoms
'STEPS': 1,
},
},
'FORCE_EVAL': {
'METHOD': 'Quickstep',
'DFT': {
'BASIS_SET_FILE_NAME': 'BASIS_MOLOPT',
'SCF': {
'MAX_SCF': 1,
},
'XC': {
'XC_FUNCTIONAL': {
'_': 'LDA',
},
},
},
'SUBSYS': {
'KIND': {
'_': 'DEFAULT',
'BASIS_SET': 'DZVP-MOLOPT-SR-GTH',
'POTENTIAL': 'GTH-LDA',
},
},
},
})
calc.use_parameters(parameters)
# resources
calc.set_max_wallclock_seconds(3*60) # 3 min
calc.set_resources({"num_machines": 1})
# store and submit
calc.store_all()
calc.submit()
print("submitted calculation: PK=%s" % calc.pk)
wait_for_calc(calc)
# check structure preservation
atoms2 = calc.out.output_structure.get_ase()
# zeros should be preserved exactly
if np.all(atoms2.positions[0] == 0.0):
print("OK, zeros in structure were preserved exactly")
else:
print("ERROR!")
print("Zeros in structure changed: ", atoms2.positions[0])
sys.exit(3)
# other values should be preserved with epsilon precision
dist2 = atoms2.get_distance(0, 1)
if abs(dist2 - dist) < epsilon:
print("OK, structure preserved with %.1e Angstrom precision" % epsilon)
else:
print("ERROR!")
print("Structure changed by %e Angstrom" % abs(dist - dist2))
sys.exit(3)
sys.exit(0)
# EOF