Skip to content

Commit

Permalink
modified to allow nics calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
cpignedoli committed Sep 12, 2024
1 parent 0afb2fa commit 4224d6a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
5 changes: 4 additions & 1 deletion aiida_gaussian/calculations/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
33 changes: 29 additions & 4 deletions aiida_gaussian/parsers/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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"""

Expand Down

0 comments on commit 4224d6a

Please sign in to comment.