The aiida-cp2k plugin for AiiDA¶
aiida-cp2k
is available at https://github.com/aiidateam/aiida-cp2k
Features¶
Following the philosophy to ‘’enable without getting in the way’’, this plugin provides access to all of CP2K’s capabilities through a small set of well-tested features:
A full CP2K input has to be provided as a nested Python dictionary example:
params = {'FORCE_EVAL': {'METHOD': 'Quickstep', 'DFT': { ... }}}
builder.parameters = Dict(dict=params)
Section parameters are stored as key _ in the dictionary:
xc_section = {'XC_FUNCTIONAL': {'_': 'LDA'}}
Repeated sections are stored as a list:
kind_section = [{'_': 'H', 'BASIS_SET': 'DZVP-MOLOPT-GTH', 'POTENTIAL': 'GTH-LDA'},
{'_': 'O', 'BASIS_SET': 'DZVP-MOLOPT-GTH', 'POTENTIAL': 'GTH-LDA'}]
Most data files (basis sets, pseudo potentials, VdW, etc.) are auto-discovered from CP2K’s data directory.
dft_section = {'BASIS_SET_FILE_NAME': 'BASIS_MOLOPT', ...}
Additional data files can be added as AiiDA SinglefileData (example):
water_pot = SinglefileData(file=os.path.join("/tmp", "water.pot"))
builder.file = {"water_pot": water_pot}
The start geometry can be provided as AiiDA StructureData (example):
structure = StructureData(ase=ase.io.read(os.path.join(thisdir, '..', "files", 'h2o.xyz')))
Alternatively the start geometry can be contained in the CP2K input (example):
'COORD': {' ': ['H 2.0 2.0 2.737166', 'H 2.0 2.0 2.000000']}
For restarting a calculation a parent folder can be attached (example):
builder.parent_calc_folder = calc1['remote_folder']
By default only the output and restart file (if present) are retrieved. Additional files are retrieved upon request (example):
settings = Dict(dict={'additional_retrieve_list': ["runtime.callgraph"]})
builder.settings = settings
The final geometry is extracted from the restart file (if present) and stored in AiiDA (example):
dist = calc['output_structure'].get_ase().get_distance(0, 1)
The conversion of geometries between AiiDA and CP2K has a precision of at least 1e-10 Ångström (example).
Examples¶
See examples folder for complete examples of setting up a calculation or a work chain.
Simple calculation¶
cd examples/single_calculations
verdi run example_dft.py <code_label> # Submit example calculation.
verdi process list -a -p1 # Check status of calculation.
Work chain¶
cd examples/workchains
verdi run example_base.py <code_label> # Submit test calculation.
verdi process list -a -p1 # Check status of the work chain.
Workflows¶
-
workchain
aiida_cp2k.workchains.base.
Cp2kBaseWorkChain
Workchain to run a CP2K calculation with automated error handling and restarts.
Inputs:
- clean_workdir, Bool, optional – If True, work directories of all called calculation jobs will be cleaned at the end of execution.
- cp2k, Namespace
Namespace Ports
- code, Code, required – The Code to use for this job.
- file, Namespace – additional input files
- metadata, Namespace
Namespace Ports
- call_link_label, str, optional, non_db – The label to use for the CALL link if the process is called by another process.
- computer, Computer, optional, non_db – When using a “local” code, set the computer on which the calculation should be run.
- description, str, optional, non_db – Description to set on the process node.
- dry_run, bool, optional, non_db – When set to True will prepare the calculation job for submission but not actually launch it.
- label, str, optional, non_db – Label to set on the process node.
- options, Namespace
Namespace Ports
- account, str, optional, non_db – Set the account to use in for the queue on the remote computer
- append_text, str, optional, non_db – Set the calculation-specific append text, which is going to be appended in the scheduler-job script, just after the code execution
- custom_scheduler_commands, str, optional, non_db – Set a (possibly multiline) string with the commands that the user wants to manually set for the scheduler. The difference of this option with respect to the prepend_text is the position in the scheduler submission file where such text is inserted: with this option, the string is inserted before any non-scheduler command
- environment_variables, dict, optional, non_db – Set a dictionary of custom environment variables for this calculation
- import_sys_environment, bool, optional, non_db – If set to true, the submission script will load the system environment variables
- input_filename, str, optional, non_db
- max_memory_kb, int, optional, non_db – Set the maximum memory (in KiloBytes) to be asked to the scheduler
- max_wallclock_seconds, int, optional, non_db – Set the wallclock in seconds asked to the scheduler
- mpirun_extra_params, (list, tuple), optional, non_db – Set the extra params to pass to the mpirun (or equivalent) command after the one provided in computer.mpirun_command. Example: mpirun -np 8 extra_params[0] extra_params[1] … exec.x
- output_filename, str, optional, non_db
- parser_name, str, optional, non_db
- prepend_text, str, optional, non_db – Set the calculation-specific prepend text, which is going to be prepended in the scheduler-job script, just before the code execution
- priority, str, optional, non_db – Set the priority of the job to be queued
- qos, str, optional, non_db – Set the quality of service to use in for the queue on the remote computer
- queue_name, str, optional, non_db – Set the name of the queue on the remote computer
- resources, dict, required, non_db – Set the dictionary of resources to be used by the scheduler plugin, like the number of nodes, cpus etc. This dictionary is scheduler-plugin dependent. Look at the documentation of the scheduler for more details.
- scheduler_stderr, str, optional, non_db – Filename to which the content of stderr of the scheduler is written.
- scheduler_stdout, str, optional, non_db – Filename to which the content of stdout of the scheduler is written.
- submit_script_filename, str, optional, non_db – Filename to which the job submission script is written.
- withmpi, bool, optional, non_db
- store_provenance, bool, optional, non_db – If set to False provenance will not be stored in the database.
- parameters, Dict, required – the input parameters
- parent_calc_folder, RemoteData, optional – remote folder used for restarts
- resources, dict, optional – special settings
- settings, Dict, optional – additional input parameters
- structure, StructureData, optional – the main input structure
- handler_overrides, Dict, optional – Mapping where keys are process handler names and the values are a boolean, where True will enable the corresponding handler and False will disable it. This overrides the default value set by the enabled keyword of the process_handler decorator with which the method is decorated.
- max_iterations, Int, optional – Maximum number of iterations the work chain will restart the process to finish successfully.
- metadata, Namespace
Namespace Ports
- call_link_label, str, optional, non_db – The label to use for the CALL link if the process is called by another process.
- description, str, optional, non_db – Description to set on the process node.
- label, str, optional, non_db – Label to set on the process node.
- store_provenance, bool, optional, non_db – If set to False provenance will not be stored in the database.
Outputs:
- output_bands, BandsData, optional – optional band structure
- output_parameters, Dict, required – the results of the calculation
- output_structure, StructureData, optional – optional relaxed structure
- remote_folder, RemoteData, required – Input files necessary to run the process will be stored in this folder node.
- retrieved, FolderData, required – Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added, but one can add more by specifying them in CalcInfo.retrieve_list.
Outline:
setup(Call the `setup` of the `BaseRestartWorkChain` and then create the inputs dictionary in `self.ctx.inputs`. This `self.ctx.inputs` dictionary will be used by the `BaseRestartWorkChain` to submit the calculations in the internal loop.) while(should_run_process) run_process(Run the next process, taking the input dictionary from the context at `self.ctx.inputs`.) inspect_process(Analyse the results of the previous process and call the handlers when necessary. If the process is excepted or killed, the work chain will abort. Otherwise any attached handlers will be called in order of their specified priority. If the process was failed and no handler returns a report indicating that the error was handled, it is considered an unhandled process failure and the process is relaunched. If this happens twice in a row, the work chain is aborted. In the case that at least one handler returned a report the following matrix determines the logic that is followed: Process Handler Handler Action result report? exit code ----------------------------------------- Success yes == 0 Restart Success yes != 0 Abort Failed yes == 0 Restart Failed yes != 0 Abort If no handler returned a report and the process finished successfully, the work chain's work is considered done and it will move on to the next step that directly follows the `while` conditional, if there is one defined in the outline.) results(Attach the outputs specified in the output specification from the last completed process.)
aiida_cp2k package¶
Subpackages¶
aiida_cp2k.calculations package¶
Module contents¶
AiiDA-CP2K input plugin.
-
class
aiida_cp2k.calculations.
Cp2kCalculation
(*args, **kwargs)[source]¶ Bases:
aiida.engine.processes.calcjobs.calcjob.CalcJob
This is a Cp2kCalculation, subclass of JobCalculation, to prepare input for an ab-initio CP2K calculation.
For information on CP2K, refer to: https://www.cp2k.org.
-
_DEFAULT_COORDS_FILE_NAME
= 'aiida.coords.xyz'¶
-
_DEFAULT_INPUT_FILE
= 'aiida.inp'¶
-
_DEFAULT_OUTPUT_FILE
= 'aiida.out'¶
-
_DEFAULT_PARENT_CALC_FLDR_NAME
= 'parent_calc/'¶
-
_DEFAULT_PARSER
= 'cp2k_base_parser'¶
-
_DEFAULT_PROJECT_NAME
= 'aiida'¶
-
_DEFAULT_RESTART_FILE_NAME
= 'aiida-1.restart'¶
-
_DEFAULT_TRAJECT_FILE_NAME
= 'aiida-pos-1.dcd'¶
-
__abstractmethods__
= frozenset({})¶
-
__module__
= 'aiida_cp2k.calculations'¶
-
_abc_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version
= 110¶
-
_abc_registry
= <_weakrefset.WeakSet object>¶
-
static
_write_structure
(structure, folder, name)[source]¶ Function that writes a structure and takes care of element tags.
-
aiida_cp2k.parsers package¶
Module contents¶
AiiDA-CP2K output parser.
-
class
aiida_cp2k.parsers.
Cp2kAdvancedParser
(node)[source]¶ Bases:
aiida_cp2k.parsers.Cp2kBaseParser
Advanced AiiDA parser class for the output of CP2K.
-
__abstractmethods__
= frozenset({})¶
-
__module__
= 'aiida_cp2k.parsers'¶
-
_abc_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version
= 110¶
-
_abc_registry
= <_weakrefset.WeakSet object>¶
-
-
class
aiida_cp2k.parsers.
Cp2kBaseParser
(node)[source]¶ Bases:
aiida.parsers.parser.Parser
Basic AiiDA parser for the output of CP2K.
-
__abstractmethods__
= frozenset({})¶
-
__module__
= 'aiida_cp2k.parsers'¶
-
_abc_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version
= 110¶
-
_abc_registry
= <_weakrefset.WeakSet object>¶
-
aiida_cp2k.utils package¶
Submodules¶
aiida_cp2k.utils.input_generator module¶
AiiDA-CP2K input generator.
-
class
aiida_cp2k.utils.input_generator.
Cp2kInput
(params=None)[source]¶ Bases:
object
Transforms dictionary into CP2K input
-
DISCLAIMER
= '!!! Generated by AiiDA !!!'¶
-
__dict__
= mappingproxy({'__module__': 'aiida_cp2k.utils.input_generator', '__doc__': 'Transforms dictionary into CP2K input', 'DISCLAIMER': '!!! Generated by AiiDA !!!', '__init__': <function Cp2kInput.__init__>, '__getitem__': <function Cp2kInput.__getitem__>, 'add_keyword': <function Cp2kInput.add_keyword>, 'render': <function Cp2kInput.render>, '_add_keyword': <staticmethod object>, '_render_section': <staticmethod object>, '__dict__': <attribute '__dict__' of 'Cp2kInput' objects>, '__weakref__': <attribute '__weakref__' of 'Cp2kInput' objects>})¶
-
__module__
= 'aiida_cp2k.utils.input_generator'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
static
_add_keyword
(kwpath, value, params, ovrd, cfct)[source]¶ Add keyword into the given nested dictionary
-
static
_render_section
(output, params, indent=0)[source]¶ It takes a dictionary and recurses through.
For key-value pair it checks whether the value is a dictionary and prepends the key with & (CP2K section). It passes the valued to the same function, increasing the indentation. If the value is a list, I assume that this is something the user wants to store repetitively eg: .. highlight:
dict['KEY'] = ['val1', 'val2'] ===> KEY val1 KEY val2 or dict['KIND'] = [{'_': 'Ba', 'ELEMENT':'Ba'}, {'_': 'Ti', 'ELEMENT':'Ti'}, {'_': 'O', 'ELEMENT':'O'}] ====> &KIND Ba ELEMENT Ba &END KIND &KIND Ti ELEMENT Ti &END KIND &KIND O ELEMENT O &END KIND
-
add_keyword
(kwpath, value, override=True, conflicting_keys=None)[source]¶ Add a value for the given keyword.
Args:
- kwpath: Can be a single keyword, a path with / as divider for sections & key,
or a sequence with sections and key.
value: the value to set the given key to
override: whether to override the key if it is already present in the self._params
conflicting_keys: list of keys that cannot live together with the provided key (SOMETHING1/[..]/SOMETHING2/KEY). In case override is True, all conflicting keys will be removed, if override is False and conflicting_keys are present the new key won’t be added.
-
aiida_cp2k.utils.parser module¶
AiiDA-CP2K input plugin.
aiida_cp2k.utils.workchains module¶
AiiDA-CP2K utilities for workchains
-
aiida_cp2k.utils.workchains.
check_resize_unit_cell
(struct, threshold)[source]¶ Returns the multiplication factors for the cell vectors to respect, in every direction: min(perpendicular_width) > threshold.
-
aiida_cp2k.utils.workchains.
get_input_multiplicity
(structure, protocol_settings)[source]¶ Compute the total multiplicity of the structure, by summing the atomic magnetizations: multiplicity = 1 + sum_i ( natoms_i * magnetization_i ), for each atom_type i
-
aiida_cp2k.utils.workchains.
get_kinds_section
(structure, protocol_settings)[source]¶ Write the &KIND sections given the structure and the settings_dict
-
aiida_cp2k.utils.workchains.
merge_Dict
(d1, d2)[source]¶ Make all the data in the second Dict overwrite the corrisponding data in the first Dict
-
aiida_cp2k.utils.workchains.
merge_dict
(dct, merge_dct)[source]¶ Taken from https://gist.github.com/angstwad/bf22d1822c38a92ec0a9 Recursive dict merge. Inspired by :meth:
dict.update()
, instead of updating only top-level keys, merge_dict recurses down into dicts nested to an arbitrary depth, updating keys. Themerge_dct
is merged intodct
. :param dct: dict onto which the merge is executed :param merge_dct: dct merged into dct (overwrites dct data if in both) :return: None
-
aiida_cp2k.utils.workchains.
ot_has_small_bandgap
(cp2k_input, cp2k_output, bandgap_thr_ev)[source]¶ Returns True if the calculation used OT and had a smaller bandgap then the guess needed for the OT. (NOTE: It has been observed also negative bandgap with OT in CP2K!) cp2k_input: dict cp2k_output: dict bandgap_thr_ev: float [eV]
Module contents¶
AiiDA-CP2K utils
aiida_cp2k.workchains package¶
Submodules¶
aiida_cp2k.workchains.base module¶
Base work chain to run a CP2K calculation.
-
class
aiida_cp2k.workchains.base.
Cp2kBaseWorkChain
(*args, **kwargs)[source]¶ Bases:
aiida.engine.processes.workchains.restart.BaseRestartWorkChain
Workchain to run a CP2K calculation with automated error handling and restarts.
-
__abstractmethods__
= frozenset({})¶
-
__module__
= 'aiida_cp2k.workchains.base'¶
-
_abc_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version
= 110¶
-
_abc_registry
= <_weakrefset.WeakSet object>¶
-
_process_class
¶
-
Module contents¶
AiiDA-CP2K workchains
Module contents¶
AiiDA-CP2K plugins, parsers, workflows, etc …
If you use AiiDA for your research, please cite the following work:
Giovanni Pizzi, Andrea Cepellotti, Riccardo Sabatini, Nicola Marzari, and Boris Kozinsky, AiiDA: automated interactive infrastructure and database for computational science, Comp. Mat. Sci 111, 218-230 (2016); https://doi.org/10.1016/j.commatsci.2015.09.013; http://www.aiida.net.
aiida-cp2k
is released under the MIT license.