From 4224d6adbb9c5b48ef4cd6f949e69bc6e9218148 Mon Sep 17 00:00:00 2001 From: Carlo Antonio Pignedoli Date: Thu, 12 Sep 2024 13:59:21 +0000 Subject: [PATCH] modified to allow nics calculations --- aiida_gaussian/calculations/gaussian.py | 5 +++- aiida_gaussian/parsers/gaussian.py | 33 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/aiida_gaussian/calculations/gaussian.py b/aiida_gaussian/calculations/gaussian.py index 2067894..0f7c610 100644 --- a/aiida_gaussian/calculations/gaussian.py +++ b/aiida_gaussian/calculations/gaussian.py @@ -170,7 +170,10 @@ def prepare_for_submission(self, folder): input_string = GaussianCalculation._render_input_string_from_params( self.inputs.parameters.get_dict(), pmg_structure ) - + # for NICS replace X0+ with Bq + if "nmr" in self.inputs.parameters.get_dict()['route_parameters']: + input_string = input_string.replace("X0+", "Bq") + with open(folder.get_abs_path(self.INPUT_FILE), "w") as out_file: out_file.write(input_string) diff --git a/aiida_gaussian/parsers/gaussian.py b/aiida_gaussian/parsers/gaussian.py index 68f4898..533b681 100644 --- a/aiida_gaussian/parsers/gaussian.py +++ b/aiida_gaussian/parsers/gaussian.py @@ -53,7 +53,7 @@ def _parse_log(self, log_file_string, inputs): return self.exit_codes.ERROR_OUTPUT_PARSING property_dict.update(self._parse_electron_numbers(log_file_string)) - + # set output nodes self.out("output_parameters", Dict(dict=property_dict)) @@ -78,7 +78,7 @@ def _parse_electron_numbers(self, log_file_string): return {"num_electrons": [int(e) for e in find_el.groups()]} else: return {} - + def _parse_log_cclib(self, log_file_string): data = cclib.io.ccread(io.StringIO(log_file_string)) @@ -176,7 +176,9 @@ def _parse_log(self, log_file_string, inputs): if property_dict is None: return self.exit_codes.ERROR_OUTPUT_PARSING - + # parse nics + property_dict.update(self._parse_nics(log_file_string)) + property_dict.update(self._parse_electron_numbers(log_file_string)) # Add spin expectations in property_dict @@ -198,7 +200,30 @@ def _parse_log(self, log_file_string, inputs): return exit_code return None - + def _parse_nics(self,log_file_string): + + sigma = [] + + def extract_values(line): + parts = line.split() + return np.array([parts[1], parts[3], parts[5]], dtype=float) + + lines = log_file_string.splitlines() + i_line = 0 + while i_line < len(lines): + if "Bq Isotropic" in lines[i_line]: + s = np.zeros((3, 3)) + s[0] = extract_values(lines[i_line + 1]) + s[1] = extract_values(lines[i_line + 2]) + s[2] = extract_values(lines[i_line + 3]) + sigma.append(s) + i_line += 4 + else: + i_line += 1 + if len(sigma) == 0: + return {} + return {'nics':np.array(sigma)} + def _parse_log_spin_exp(self, log_file_string): """Parse spin expectation values"""