From 86dd213d32b9b7a33aff0c23f113a5bc9c4f8fd8 Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Fri, 11 Sep 2020 12:52:02 +0200 Subject: [PATCH 01/10] Add elements coordination in schemas.py Add an optional key to the dictionary input of COOP calculation that includes the coordination number to be considered for each of the two elements --- nanoqm/workflows/schemas.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nanoqm/workflows/schemas.py b/nanoqm/workflows/schemas.py index a1b347375..b8894defd 100644 --- a/nanoqm/workflows/schemas.py +++ b/nanoqm/workflows/schemas.py @@ -303,7 +303,10 @@ def merge(d1: Dict[str, Any], d2: Dict[str, Any]) -> Dict[str, Any]: #: Input for a Crystal Orbital Overlap Population calculation dict_coop = { # List of the two elements to calculate the COOP for - "coop_elements": list} + "coop_elements": list, + # Coordination number to be considered for each of the two elements + Optional("elements_coordination", default=None): Or(None, list) +} dict_merged_single_points = merge(dict_general_options, dict_single_points) From 4432fe321d0ccbca180c62251793e3f233a9ebeb Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Fri, 11 Sep 2020 15:24:28 +0200 Subject: [PATCH 02/10] Update workflow_coop.py with coordination number --- nanoqm/workflows/workflow_coop.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/nanoqm/workflows/workflow_coop.py b/nanoqm/workflows/workflow_coop.py index 9e115ed0c..faf563640 100644 --- a/nanoqm/workflows/workflow_coop.py +++ b/nanoqm/workflows/workflow_coop.py @@ -10,12 +10,16 @@ __all__ = ['workflow_crystal_orbital_overlap_population'] import logging -from typing import List, Tuple +from typing import List, Tuple, Union import numpy as np +from scm.plams import Molecule + from qmflows.parsers.xyzParser import readXYZ +from nanoCAT.recipes import coordination_number + from ..common import (DictConfig, MolXYZ, h2ev, number_spherical_functions_per_atom, retrieve_hdf5_data) from ..integrals.multipole_matrices import compute_matrix_multipole @@ -44,11 +48,14 @@ def workflow_crystal_orbital_overlap_population(config: DictConfig): # Converting the xyz-file to a mol-file mol = readXYZ(config.path_traj_xyz) + if config.elements_coordination is not None: + geometry = Molecule(config.path_traj_xyz) + # Computing the indices of the atomic orbitals of the two selected # elements, and the overlap matrix that contains only elements related to # the two elements el_1_orbital_ind, el_2_orbital_ind, overlap_reduced = compute_overlap_and_atomic_orbitals( - mol, config) + mol, config, geometry) # Compute the crystal orbital overlap population between the two selected # elements @@ -83,7 +90,8 @@ def get_eigenvalues_coefficients(config: DictConfig) -> Tuple[np.ndarray, np.nda def compute_overlap_and_atomic_orbitals( - mol: MolXYZ, config: DictConfig) -> Tuple[List[int], List[int], List[int]]: + mol: MolXYZ, config: DictConfig, + geometry: Union[Molecule, None]) -> Tuple[List[int], List[int], List[int]]: """Compute the indices of the atomic orbitals of the two selected elements. Computes the overlap matrix, containing only the elements related to those two elements. @@ -102,8 +110,17 @@ def compute_overlap_and_atomic_orbitals( element_1 = config["coop_elements"][0] element_2 = config["coop_elements"][1] - element_1_index = [i for i, s in enumerate(mol) if element_1.lower() in s] - element_2_index = [i for i, s in enumerate(mol) if element_2.lower() in s] + if config["elements_coordination"] is None: + element_1_index = [i for i, s in enumerate(mol) if element_1.lower() in s] + element_2_index = [i for i, s in enumerate(mol) if element_2.lower() in s] + + # For the two selected elements, only the indices corresponding to a given coordination number + else: + coord = coordination_number(geometry) + cn_1 = config["elements_coordination"][0] + cn_2 = config["elements_coordination"][1] + element_1_index = [i - 1 for i in coord[element_1][cn_1]] + element_2_index = [i - 1 for i in coord[element_2][cn_2]] # Making a list of the indices of the atomic orbitals for each of the two # elements From 6541d2ac062072a1074fd1907b40dc96037e0279 Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Mon, 14 Sep 2020 11:42:58 +0200 Subject: [PATCH 03/10] Add a description of elements_coordination option --- nanoqm/workflows/workflow_coop.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nanoqm/workflows/workflow_coop.py b/nanoqm/workflows/workflow_coop.py index faf563640..d0d7d8e33 100644 --- a/nanoqm/workflows/workflow_coop.py +++ b/nanoqm/workflows/workflow_coop.py @@ -1,4 +1,7 @@ """Crystal Orbital Overlap Population calculation. +The COOP is calculated between two selected elements. +For each element, a specific coordination number can optionally be selected +by using the "elements_coordination" key in the yaml input. Index ----- From d19ef5390282350b01ec40cc5db71045292d3ae0 Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Mon, 14 Sep 2020 11:54:39 +0200 Subject: [PATCH 04/10] Add nano-CAT to setup.py --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2b3c51e2a..c17105275 100644 --- a/setup.py +++ b/setup.py @@ -151,7 +151,8 @@ def build_extensions(self): 'h5py', 'mendeleev', 'more-itertools', 'noodles==0.3.3', 'numpy', 'pybind11>=2.2.4', 'scipy', 'schema', 'pyyaml>=5.1', 'plams@git+https://github.com/SCM-NV/PLAMS@master', - 'qmflows@git+https://github.com/SCM-NV/qmflows@master' + 'qmflows@git+https://github.com/SCM-NV/qmflows@master', + 'nano-CAT@git+https://github.com/nlesc-nano/nano-CAT@master' ], cmdclass={'build_ext': BuildExt}, ext_modules=[ext_pybind], From 472e2e7a5e83007bf408c6689ed0ced46a055b47 Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Mon, 14 Sep 2020 12:10:55 +0200 Subject: [PATCH 05/10] Variable assignment in workflow_coop.py --- nanoqm/workflows/workflow_coop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nanoqm/workflows/workflow_coop.py b/nanoqm/workflows/workflow_coop.py index d0d7d8e33..34bf1ca6e 100644 --- a/nanoqm/workflows/workflow_coop.py +++ b/nanoqm/workflows/workflow_coop.py @@ -53,6 +53,8 @@ def workflow_crystal_orbital_overlap_population(config: DictConfig): if config.elements_coordination is not None: geometry = Molecule(config.path_traj_xyz) + else: + geometry = None # Computing the indices of the atomic orbitals of the two selected # elements, and the overlap matrix that contains only elements related to From 6a4c11f682442a3a32f2d81b2732505987b8ddfc Mon Sep 17 00:00:00 2001 From: felipez Date: Mon, 14 Sep 2020 15:04:00 +0200 Subject: [PATCH 06/10] fixed logger error --- test/test_distribute.py | 13 ++++++++----- test/test_run_workflow.py | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/test_distribute.py b/test/test_distribute.py index 641e3053a..0f55ea7dc 100644 --- a/test/test_distribute.py +++ b/test/test_distribute.py @@ -1,10 +1,12 @@ """Test the distribution script.""" -from qmflows.type_hints import PathLike -from pathlib import Path -from subprocess import (PIPE, Popen) import fnmatch -import shutil import os +import re +import shutil +from pathlib import Path +from subprocess import PIPE, Popen + +from qmflows.type_hints import PathLike def test_distribute(tmp_path: PathLike) -> None: @@ -20,7 +22,8 @@ def call_distribute(tmp_path: PathLike, cmd: str) -> None: try: p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) _, err = p.communicate() - if err: + error = re.search("error", err.decode(), re.IGNORECASE) + if error is not None: raise RuntimeError(err.decode()) check_scripts() finally: diff --git a/test/test_run_workflow.py b/test/test_run_workflow.py index 0735e1f90..cf53c7d55 100644 --- a/test/test_run_workflow.py +++ b/test/test_run_workflow.py @@ -1,6 +1,7 @@ """Test the CLI to run a workflow.""" import os +import re import shutil from pathlib import Path from subprocess import PIPE, Popen @@ -37,7 +38,8 @@ def test_run_workflow(tmp_path): try: p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) out, err = p.communicate() - if err: + error = re.search("error", err.decode(), re.IGNORECASE) + if error is not None: print("output: ", out) print("err: ", err) raise RuntimeError(err.decode()) From 6058891c1e4cd043949283b9d9cc0438c8080251 Mon Sep 17 00:00:00 2001 From: felipez Date: Mon, 14 Sep 2020 15:20:20 +0200 Subject: [PATCH 07/10] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 016c5d972..cfff42602 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ # 0.10.3 (Unreleased) ## New * Template to create B3LYP computations (#269) +* Add nanoCAT dependency (#280) ## Fixed * Fix distribution error (#272) From bb0820bfd25be51e5b67b1095da5769ab8ca000a Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Mon, 14 Sep 2020 16:49:21 +0200 Subject: [PATCH 08/10] Create input_test_coop_coordination.yml --- .../input_test_coop_coordination.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/test_files/input_test_coop_coordination.yml diff --git a/test/test_files/input_test_coop_coordination.yml b/test/test_files/input_test_coop_coordination.yml new file mode 100644 index 000000000..149553c4f --- /dev/null +++ b/test/test_files/input_test_coop_coordination.yml @@ -0,0 +1,26 @@ +workflow: + coop_calculation +project_name: Cd33Se33 + +active_space: [50, 50] +path_hdf5: "test/test_files/Cd33Se33.hdf5" +path_traj_xyz: "test/test_files/Cd33Se33.xyz" +scratch_path: "/tmp/COOP" + +coop_elements: ["Cd", "Se"] +elements_coordination: ["4", "3"] + +cp2k_general_settings: + basis: "DZVP-MOLOPT-SR-GTH" + potential: "GTH-PBE" + cell_parameters: 20.0 + periodic: none + + cp2k_settings_main: + specific: + template: pbe_main + + cp2k_settings_guess: + specific: + template: + pbe_guess From 67c44f0e2a562471e10ee7e0f676f750c9d398cc Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Mon, 14 Sep 2020 16:59:43 +0200 Subject: [PATCH 09/10] Test coordination functionality of coop workflow --- test/test_workflow_coop.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_workflow_coop.py b/test/test_workflow_coop.py index 8c9d74571..1403a7afd 100644 --- a/test/test_workflow_coop.py +++ b/test/test_workflow_coop.py @@ -29,3 +29,21 @@ def test_workflow_coop(tmp_path: PathLike) -> None: print("scratch_path: ", tmp_path) print("Unexpected error:", sys.exc_info()[0]) raise + + +def test_workflow_coop_coordination(tmp_path: PathLike) -> None: + """Test the Crystal Orbital Overlap Population workflow.""" + file_path = PATH_TEST / 'input_test_coop_coordination.yml' + config = process_input(file_path, 'coop_calculation') + + # create scratch path + shutil.copy(config.path_hdf5, tmp_path) + config.path_hdf5 = join(tmp_path, "Cd33Se33.hdf5") + config.workdir = tmp_path + try: + workflow_crystal_orbital_overlap_population(config) + os.remove("COOP.txt") + except BaseException: + print("scratch_path: ", tmp_path) + print("Unexpected error:", sys.exc_info()[0]) + raise From c822be2c4e83913ad39f71bdc6ef1cb3b870afd4 Mon Sep 17 00:00:00 2001 From: juliette1996 <48909188+juliette1996@users.noreply.github.com> Date: Thu, 15 Oct 2020 12:48:53 +0200 Subject: [PATCH 10/10] Update yml input test --- test/test_files/input_test_coop_coordination.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_files/input_test_coop_coordination.yml b/test/test_files/input_test_coop_coordination.yml index 149553c4f..b6ccf3a7c 100644 --- a/test/test_files/input_test_coop_coordination.yml +++ b/test/test_files/input_test_coop_coordination.yml @@ -8,7 +8,7 @@ path_traj_xyz: "test/test_files/Cd33Se33.xyz" scratch_path: "/tmp/COOP" coop_elements: ["Cd", "Se"] -elements_coordination: ["4", "3"] +elements_coordination: [4, 3] cp2k_general_settings: basis: "DZVP-MOLOPT-SR-GTH"