-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix parser for v2024.3. * Add tests for CP2K v2024.3. * Add an example run for the advanced parser. * Improve regexes for getting step info. * Simplify reading end-of-step info. * Base workchain: improve output parsing. --------- Co-authored-by: Aliaksandr Yakutovich <yakutovicha@gmail.com>
- Loading branch information
1 parent
1a44be7
commit f5116d8
Showing
7 changed files
with
3,903 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
examples/single_calculations/example_geopt_advanced_parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
############################################################################### | ||
# 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 DFT geometry optimization.""" | ||
|
||
import os | ||
import sys | ||
|
||
import ase.io | ||
import click | ||
from aiida.common import NotExistent | ||
from aiida.engine import run | ||
from aiida.orm import Dict, SinglefileData, load_code | ||
from aiida.plugins import DataFactory | ||
|
||
StructureData = DataFactory("core.structure") | ||
|
||
|
||
def example_geopt(cp2k_code): | ||
"""Run DFT geometry optimization.""" | ||
|
||
print("Testing CP2K GEO_OPT on H2O (DFT)...") | ||
|
||
thisdir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
# Structure. | ||
structure = StructureData( | ||
ase=ase.io.read(os.path.join(thisdir, "..", "files", "h2.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( | ||
{ | ||
"GLOBAL": { | ||
"RUN_TYPE": "GEO_OPT", | ||
}, | ||
"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": { | ||
"_": "PBE", | ||
}, | ||
}, | ||
"POISSON": { | ||
"PERIODIC": "none", | ||
"PSOLVER": "MT", | ||
}, | ||
}, | ||
"SUBSYS": { | ||
"KIND": [ | ||
{ | ||
"_": "O", | ||
"BASIS_SET": "DZVP-MOLOPT-SR-GTH", | ||
"POTENTIAL": "GTH-PBE-q6", | ||
}, | ||
{ | ||
"_": "H", | ||
"BASIS_SET": "DZVP-MOLOPT-SR-GTH", | ||
"POTENTIAL": "GTH-PBE-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 | ||
builder.metadata.options.parser_name = "cp2k_advanced_parser" | ||
|
||
print("Submitted calculation...") | ||
calc = run(builder) | ||
|
||
# Check walltime not exceeded. | ||
assert calc["output_parameters"]["exceeded_walltime"] is False | ||
|
||
# Check energy. | ||
expected_energy = -1.17212345935 | ||
if abs(calc["output_parameters"]["energy"] - expected_energy) < 1e-10: | ||
print("OK, energy has the expected value.") | ||
else: | ||
print("ERROR!") | ||
print(f"Expected energy value: {expected_energy}") | ||
print(f"Actual energy value: {calc['output_parameters']['energy']}") | ||
sys.exit(3) | ||
|
||
# Check geometry. | ||
expected_dist = 0.732594809575 | ||
dist = calc["output_structure"].get_ase().get_distance(0, 1) | ||
if abs(dist - expected_dist) < 1e-7: | ||
print("OK, H-H distance has the expected value.") | ||
else: | ||
print("ERROR!") | ||
print(f"Expected dist value: {expected_dist}") | ||
print(f"Actual dist value: {dist}") | ||
sys.exit(3) | ||
|
||
# Check motion step information. | ||
assert calc["output_parameters"]["motion_step_info"]["step"] == [ | ||
0, | ||
1, | ||
2, | ||
], "ERROR: motion step info is incorrect" | ||
assert calc["output_parameters"]["motion_step_info"]["cell_a_angs"] == [ | ||
4.0, | ||
4.0, | ||
4.0, | ||
], "ERROR: motion step info is incorrect" | ||
|
||
|
||
@click.command("cli") | ||
@click.argument("codelabel") | ||
def cli(codelabel): | ||
"""Click interface.""" | ||
try: | ||
code = load_code(codelabel) | ||
except NotExistent: | ||
print(f"The code '{codelabel}' does not exist.") | ||
sys.exit(1) | ||
example_geopt(code) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.