From bd80d20f9c0e8f53fee7609fa97028eabbd51c44 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 10:51:33 -0700 Subject: [PATCH 1/9] First draft of cp2k interface Copied from https://github.com/jan-janssen/pyiron-cp2k --- pyiron_contrib/__init__.py | 1 + pyiron_contrib/atomistics/cp2k/__init__.py | 0 pyiron_contrib/atomistics/cp2k/job.py | 119 +++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 pyiron_contrib/atomistics/cp2k/__init__.py create mode 100644 pyiron_contrib/atomistics/cp2k/job.py diff --git a/pyiron_contrib/__init__.py b/pyiron_contrib/__init__.py index 11cb57a31..c19768dce 100644 --- a/pyiron_contrib/__init__.py +++ b/pyiron_contrib/__init__.py @@ -44,6 +44,7 @@ JOB_CLASS_DICT['Atomicrex'] = 'pyiron_contrib.atomistics.atomicrex.atomicrex_job' JOB_CLASS_DICT['StructureMasterInt'] = 'pyiron_contrib.atomistics.atomistics.job.structurelistmasterinteractive' JOB_CLASS_DICT['StorageJob'] = 'pyiron_contrib.RDM.storagejob' +JOB_CLASS_DICT['Cp2kJob'] = 'pyiron_contrib.cp2k.job' from ._version import get_versions diff --git a/pyiron_contrib/atomistics/cp2k/__init__.py b/pyiron_contrib/atomistics/cp2k/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pyiron_contrib/atomistics/cp2k/job.py b/pyiron_contrib/atomistics/cp2k/job.py new file mode 100644 index 000000000..8c4fc8ee0 --- /dev/null +++ b/pyiron_contrib/atomistics/cp2k/job.py @@ -0,0 +1,119 @@ +import os +from pyiron_base import InputList +from pyiron_atomistics.atomistics.atoms import pyiron_to_ase, ase_to_pyiron +from pyiron.atomistics.job.atomistic import AtomisticGenericJob +from pycp2k import CP2K + + +pyiron_dict = { + "global": { + "run_type": "ENERGY_FORCE" + }, + "force_eval": { + "method": "Quickstep", + "print_forces_section": "ON" + }, + "dft": { + "qs": { + "eps": 1.0E-10 + }, + "mgrid": { + "ngrids": 4, + "cutoff": 300, + "rel_cutoff": 60 + }, + "xc": { + "functional": "PADE" + } + }, + "scf": { + "scf_guess": "ATOMIC", + "eps": 1.0E-7, + "max": 300, + "diagonalization": { + "algorthim": "STANDARD" + }, + "mixing": { + "method": "BROYDEN_MIXING", + "alpha": 0.4, + "n_broyden": 8, + } + }, + "kind": { + "basis_set": "DZVP-GTH-PADE", + "potential": "GTH-PADE-q4" + } +} + + +class Cp2kJob(AtomisticGenericJob): + def __init__(self, project, job_name): + super(Cp2kJob, self).__init__(project, job_name) + self.__name__ = "cp2k" + self.input = InputList(pyiron_dict) + + def to_hdf(self, hdf=None, group_name=None): + """ + Store the ExampleJob object in the HDF5 File + + Args: + hdf (ProjectHDFio): HDF5 group object - optional + group_name (str): HDF5 subgroup name - optional + """ + super(Cp2kJob, self).to_hdf(hdf=hdf, group_name=group_name) + self._structure_to_hdf() + with self.project_hdf5.open("input") as hdf5_input: + self.input.to_hdf(hdf5_input) + + def from_hdf(self, hdf=None, group_name=None): + """ + Restore the ExampleJob object in the HDF5 File + + Args: + hdf (ProjectHDFio): HDF5 group object - optional + group_name (str): HDF5 subgroup name - optional + """ + super(Cp2kJob, self).from_hdf(hdf=hdf, group_name=group_name) + self._structure_from_hdf() + with self.project_hdf5.open("input") as hdf5_input: + self.input.from_hdf(hdf5_input) + + def write_input(self): + calc = CP2K() + calc.working_directory = self.working_directory + calc.project_name = "pyiron" + CP2K_INPUT = calc.CP2K_INPUT + GLOBAL = CP2K_INPUT.GLOBAL + FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add() # Repeatable items have to be first created + SUBSYS = FORCE_EVAL.SUBSYS + DFT = FORCE_EVAL.DFT + SCF = DFT.SCF + GLOBAL.Run_type = self.input["global"]["run_type"] + FORCE_EVAL.Method = self.input["force_eval"]["method"] + FORCE_EVAL.PRINT.FORCES.Section_parameters = self.input["force_eval"]["print_forces_section"] + DFT.Basis_set_file_name = os.path.join(s.resource_paths[0], "cp2k", "potentials", "BASIS_SET") + DFT.Potential_file_name = os.path.join(s.resource_paths[0], "cp2k", "potentials", "GTH_POTENTIALS") + DFT.QS.Eps_default = self.input["dft"]["qs"]["eps"] + DFT.MGRID.Ngrids = self.input["dft"]["mgrid"]["ngrids"] + DFT.MGRID.Cutoff = self.input["dft"]["mgrid"]["cutoff"] + DFT.MGRID.Rel_cutoff = self.input["dft"]["mgrid"]["rel_cutoff"] + DFT.XC.XC_FUNCTIONAL.Section_parameters = self.input["dft"]["xc"]["functional"] + SCF.Scf_guess = self.input["scf"]["scf_guess"] + SCF.Eps_scf = self.input["scf"]["eps"] + SCF.Max_scf = self.input["scf"]["max"] + SCF.DIAGONALIZATION.Section_parameters = "ON" + SCF.DIAGONALIZATION.Algorithm = self.input["scf"]["diagonalization"]["algorthim"] + SCF.MIXING.Section_parameters = "T" + SCF.MIXING.Method = self.input["scf"]["mixing"]["method"] + SCF.MIXING.Alpha = self.input["scf"]["mixing"]["alpha"] + SCF.MIXING.Nbroyden = self.input["scf"]["mixing"]["n_broyden"] + for el in set(self.structure.get_chemical_symbols()): + KIND = SUBSYS.KIND_add(el) + KIND.Basis_set = self.input["kind"]["basis_set"] + KIND.Potential = self.input["kind"]["potential"] + calc.create_cell(SUBSYS, pyiron_to_ase(self.structure)) + calc.create_coord(SUBSYS, pyiron_to_ase(self.structure)) + calc.write_input_file() + + def collect_output(self): + pass \ No newline at end of file From 7fd7154b1e8af0bbe55bced698e5798fb1461845 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:02:58 -0700 Subject: [PATCH 2/9] Update job.py --- pyiron_contrib/atomistics/cp2k/job.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyiron_contrib/atomistics/cp2k/job.py b/pyiron_contrib/atomistics/cp2k/job.py index 8c4fc8ee0..8f86840fc 100644 --- a/pyiron_contrib/atomistics/cp2k/job.py +++ b/pyiron_contrib/atomistics/cp2k/job.py @@ -1,7 +1,7 @@ import os from pyiron_base import InputList from pyiron_atomistics.atomistics.atoms import pyiron_to_ase, ase_to_pyiron -from pyiron.atomistics.job.atomistic import AtomisticGenericJob +from pyiron_atomistics.atomistics.job.atomistic import AtomisticGenericJob from pycp2k import CP2K @@ -116,4 +116,4 @@ def write_input(self): calc.write_input_file() def collect_output(self): - pass \ No newline at end of file + pass From ebb83f54001a423b755737bf5e427b4cff202f52 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:14:17 -0700 Subject: [PATCH 3/9] Update environment.yml --- .ci_support/environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci_support/environment.yml b/.ci_support/environment.yml index f1175e106..5cb11adab 100644 --- a/.ci_support/environment.yml +++ b/.ci_support/environment.yml @@ -17,3 +17,4 @@ dependencies: - boto3 - moto - more-itertools +- pycp2k =0.2.2 From cd0af5901bdae32e826bfb31a040530a6532db57 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:14:42 -0700 Subject: [PATCH 4/9] Update setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 5b19c137c..e3e7e83d3 100644 --- a/setup.py +++ b/setup.py @@ -42,6 +42,7 @@ 'atomistic': [ 'ase==3.22.1', 'pyiron_atomistics==0.2.31', + 'pycp2k==0.2.2', ], 'fenics': [ 'fenics==2019.1.0', From a78eed88994bf37eb3b16170fa8961405e728025 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:27:46 -0700 Subject: [PATCH 5/9] Update __init__.py --- pyiron_contrib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_contrib/__init__.py b/pyiron_contrib/__init__.py index c19768dce..66b2f59f1 100644 --- a/pyiron_contrib/__init__.py +++ b/pyiron_contrib/__init__.py @@ -44,7 +44,7 @@ JOB_CLASS_DICT['Atomicrex'] = 'pyiron_contrib.atomistics.atomicrex.atomicrex_job' JOB_CLASS_DICT['StructureMasterInt'] = 'pyiron_contrib.atomistics.atomistics.job.structurelistmasterinteractive' JOB_CLASS_DICT['StorageJob'] = 'pyiron_contrib.RDM.storagejob' -JOB_CLASS_DICT['Cp2kJob'] = 'pyiron_contrib.cp2k.job' +JOB_CLASS_DICT['Cp2kJob'] = 'pyiron_contrib.atomistics.cp2k.job' from ._version import get_versions From 650f1707e7ea095e60559f28f1b7f1ec18df5aee Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:29:47 -0700 Subject: [PATCH 6/9] Update job.py --- pyiron_contrib/atomistics/cp2k/job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_contrib/atomistics/cp2k/job.py b/pyiron_contrib/atomistics/cp2k/job.py index 8f86840fc..06e19497f 100644 --- a/pyiron_contrib/atomistics/cp2k/job.py +++ b/pyiron_contrib/atomistics/cp2k/job.py @@ -1,6 +1,6 @@ import os from pyiron_base import InputList -from pyiron_atomistics.atomistics.atoms import pyiron_to_ase, ase_to_pyiron +from pyiron_atomistics.atomistics.structure.atoms import pyiron_to_ase, ase_to_pyiron from pyiron_atomistics.atomistics.job.atomistic import AtomisticGenericJob from pycp2k import CP2K From 5f3af5df8a30a2c232f6e5a6c44c5c395a4bebf5 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:30:46 -0700 Subject: [PATCH 7/9] Update job.py --- pyiron_contrib/atomistics/cp2k/job.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyiron_contrib/atomistics/cp2k/job.py b/pyiron_contrib/atomistics/cp2k/job.py index 06e19497f..2430b00bf 100644 --- a/pyiron_contrib/atomistics/cp2k/job.py +++ b/pyiron_contrib/atomistics/cp2k/job.py @@ -1,5 +1,5 @@ import os -from pyiron_base import InputList +from pyiron_base import DataContainer from pyiron_atomistics.atomistics.structure.atoms import pyiron_to_ase, ase_to_pyiron from pyiron_atomistics.atomistics.job.atomistic import AtomisticGenericJob from pycp2k import CP2K @@ -50,7 +50,7 @@ class Cp2kJob(AtomisticGenericJob): def __init__(self, project, job_name): super(Cp2kJob, self).__init__(project, job_name) self.__name__ = "cp2k" - self.input = InputList(pyiron_dict) + self.input = DataContainer(pyiron_dict) def to_hdf(self, hdf=None, group_name=None): """ From d0f1bd4e96dbba0911c12a40759dec19c59e4b2a Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:33:48 -0700 Subject: [PATCH 8/9] Update job.py --- pyiron_contrib/atomistics/cp2k/job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_contrib/atomistics/cp2k/job.py b/pyiron_contrib/atomistics/cp2k/job.py index 2430b00bf..94ab636a2 100644 --- a/pyiron_contrib/atomistics/cp2k/job.py +++ b/pyiron_contrib/atomistics/cp2k/job.py @@ -50,7 +50,7 @@ class Cp2kJob(AtomisticGenericJob): def __init__(self, project, job_name): super(Cp2kJob, self).__init__(project, job_name) self.__name__ = "cp2k" - self.input = DataContainer(pyiron_dict) + self.input = DataContainer(pyiron_dict, table_name="control_dict") def to_hdf(self, hdf=None, group_name=None): """ From fa4f0de206568c973706fa87079969e4ae80631a Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 10 Dec 2021 11:35:31 -0700 Subject: [PATCH 9/9] Update job.py --- pyiron_contrib/atomistics/cp2k/job.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyiron_contrib/atomistics/cp2k/job.py b/pyiron_contrib/atomistics/cp2k/job.py index 94ab636a2..0b47e1099 100644 --- a/pyiron_contrib/atomistics/cp2k/job.py +++ b/pyiron_contrib/atomistics/cp2k/job.py @@ -1,5 +1,5 @@ import os -from pyiron_base import DataContainer +from pyiron_base import DataContainer, state from pyiron_atomistics.atomistics.structure.atoms import pyiron_to_ase, ase_to_pyiron from pyiron_atomistics.atomistics.job.atomistic import AtomisticGenericJob from pycp2k import CP2K @@ -91,8 +91,8 @@ def write_input(self): GLOBAL.Run_type = self.input["global"]["run_type"] FORCE_EVAL.Method = self.input["force_eval"]["method"] FORCE_EVAL.PRINT.FORCES.Section_parameters = self.input["force_eval"]["print_forces_section"] - DFT.Basis_set_file_name = os.path.join(s.resource_paths[0], "cp2k", "potentials", "BASIS_SET") - DFT.Potential_file_name = os.path.join(s.resource_paths[0], "cp2k", "potentials", "GTH_POTENTIALS") + DFT.Basis_set_file_name = os.path.join(state.settings.resource_paths[0], "cp2k", "potentials", "BASIS_SET") + DFT.Potential_file_name = os.path.join(state.settings.resource_paths[0], "cp2k", "potentials", "GTH_POTENTIALS") DFT.QS.Eps_default = self.input["dft"]["qs"]["eps"] DFT.MGRID.Ngrids = self.input["dft"]["mgrid"]["ngrids"] DFT.MGRID.Cutoff = self.input["dft"]["mgrid"]["cutoff"]