From 58d0fc2f4eec59e15baccf16af36b9e77c4f61d8 Mon Sep 17 00:00:00 2001 From: Carlo Pignedoli Date: Sun, 5 Jul 2020 20:33:56 +0000 Subject: [PATCH] Add structure parsing --- aiida_quantumespresso/parsers/pp.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/aiida_quantumespresso/parsers/pp.py b/aiida_quantumespresso/parsers/pp.py index 6b79c0436..40942a332 100644 --- a/aiida_quantumespresso/parsers/pp.py +++ b/aiida_quantumespresso/parsers/pp.py @@ -217,7 +217,7 @@ def detect_important_message(logs, line): split_line = line.split('=') if 'negative/imaginary' in line: # QE6.1 output_dict['negative_core_charge'] = float(split_line[-1].split()[0]) - output_dict['imaginary_core_charge'] = float(split_line.split()[-1]) + output_dict['imaginary_core_charge'] = float(split_line[-1].split()[-1]) else: # QE6.4 output_dict['negative_core_charge'] = float(split_line[1]) if 'Min, Max, imaginary charge:' in line: @@ -335,10 +335,15 @@ def parse_gaussian(self, data_file_str): """ lines = data_file_str.splitlines() + title = lines[0] + comment = lines[1] + atoms_line = lines[2].split() - atoms = int(atoms_line[0]) # The number of atoms listed in the file - header = lines[:6 + atoms] # Header of the file: comments, the voxel, and the number of atoms and datapoints - data_lines = lines[6 + atoms:] # The actual data: atoms and volumetric data + natoms = int(atoms_line[0]) # The number of atoms listed in the file + origin = np.array(atoms_line[1:], dtype=float) + + header = lines[:6 + natoms] # Header of the file: comments, the voxel, and the number of atoms and datapoints + data_lines = lines[6 + natoms:] # The actual data: atoms and volumetric data # Parse the declared dimensions of the volumetric data x_line = header[3].split() @@ -352,6 +357,12 @@ def parse_gaussian(self, data_file_str): voxel_array = np.array([[x_line[1], x_line[2], x_line[3]], [y_line[1], y_line[2], y_line[3]], [z_line[1], z_line[2], z_line[3]]], dtype=np.float64) + atomic_numbers = np.empty(natoms, int) + coordinates = np.empty((natoms, 3)) + for i in range(natoms): + line = header[6 + i].split() + atomic_numbers[i] = int(line[0]) + coordinates[i] = [float(s) for s in line[2:]] # Get the volumetric data data_array = np.empty(xdim * ydim * zdim, dtype=float) @@ -368,7 +379,9 @@ def parse_gaussian(self, data_file_str): arraydata = orm.ArrayData() arraydata.set_array('voxel', voxel_array) arraydata.set_array('data', data_array) - arraydata.set_array('coordinates_units', np.array(coordinates_units)) arraydata.set_array('data_units', np.array(data_units)) + arraydata.set_array('coordinates_units', np.array(coordinates_units)) + arraydata.set_array('coordinates', coordinates) + arraydata.set_array('atomic_numbers', atomic_numbers) return arraydata