Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pp.x: fix gaussian cube file parsing. #535

Merged
merged 6 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions aiida_quantumespresso/parsers/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is apparently not being tested, correct? I guess that is because the output files we have are not from QE 6.1. However, why is there no imaginary_core_charge for the QE 6.4 branch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is apparently not being tested, correct?

Looks like it wasn't.

However, why is there no imaginary_core_charge for the QE 6.4 branch?

I don't know why, I can just say that there are no imaginary charges for QE 6.4, indeed:

Check: negative core charge= -0.000013

I should also mention, that in QE 6.5 this line is not present at all, while for 6.3 it is present, and looks as follows:

Check: negative/imaginary core charge=   -0.000001    0.000000

else: # QE6.4
output_dict['negative_core_charge'] = float(split_line[1])
if 'Min, Max, imaginary charge:' in line:
Expand Down Expand Up @@ -335,10 +335,15 @@ def parse_gaussian(self, data_file_str):
"""
lines = data_file_str.splitlines()

title = lines[0]
comment = lines[1]
yakutovicha marked this conversation as resolved.
Show resolved Hide resolved

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()
Expand All @@ -352,34 +357,31 @@ 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.zeros((xdim, ydim, zdim))

# The data is organised into columns with a fixed number of values
# Gather up all the data points into one list for easier unpacking
datalist = []
data_array = np.empty(xdim * ydim * zdim, dtype=float)
cursor = 0
for line in data_lines:
for i in range(0, len(line), 13):
data_point = line[i:i + 13].strip()
if data_point != '':
datalist.append(float(data_point))

# Unpack the list and repack as a 3D array
# Note the unusual indexing: cube files run over the z index first, then y and x.
# E.g. The first volumetric data point is x,y,z = (0,0,0) and the second is (0,0,1)
for i in range(0, xdim):
for j in range(0, ydim):
for k in range(0, zdim):
data_array[i, j, k] = (datalist[(i * ydim * zdim) + (j * zdim) + k])
ls = line.split()
yakutovicha marked this conversation as resolved.
Show resolved Hide resolved
data_array[cursor:cursor + len(ls)] = ls
cursor += len(ls)
data_array = data_array.reshape((xdim, ydim, zdim))

coordinates_units = 'bohr'
data_units = self.units_dict[self.output_parameters['plot_num']]

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)
yakutovicha marked this conversation as resolved.
Show resolved Hide resolved
arraydata.set_array('atomic_numbers', atomic_numbers)

return arraydata
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
1 0.141231 0.000000 0.141231
1 0.141231 0.141231 0.000000
14 14.000000 10.168616 10.168616 10.168616
0.16567E-01 0.14498E-01 0.96968E-02
0.16567E-01
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
1 0.141231 0.000000 0.141231
1 0.141231 0.141231 0.000000
14 14.000000 2.542154 2.542154 2.542154
0.22404E-01 0.19330E-01 0.12458E-01
0.22404E-01
6 changes: 3 additions & 3 deletions tests/parsers/test_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def test_pp_default_3d(
assert calcfunction.is_finished_ok, calcfunction.exit_message
assert 'output_parameters' in results
assert 'output_data' in results
assert len(results['output_data'].get_arraynames()) == 4
assert len(results['output_data'].get_arraynames()) == 6
data_array = results['output_data'].get_array('data').flatten()
voxel_array = results['output_data'].get_array('voxel').flatten()
data_units_array = results['output_data'].get_array('data_units')
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_pp_default_3d_keep_plot_file(
assert calcfunction.is_finished_ok, calcfunction.exit_message
assert 'output_parameters' in results
assert 'output_data' in results
assert len(results['output_data'].get_arraynames()) == 4
assert len(results['output_data'].get_arraynames()) == 6


def test_pp_default_3d_multiple(aiida_profile, generate_calc_job_node, generate_parser, generate_inputs_3d):
Expand All @@ -334,7 +334,7 @@ def test_pp_default_3d_multiple(aiida_profile, generate_calc_job_node, generate_
for key in ['K001_B001', 'K001_B002']:
assert key in results['output_data_multiple']
node = results['output_data_multiple'][key]
assert len(node.get_arraynames()) == 4
assert len(node.get_arraynames()) == 6


def test_pp_default_3d_failed_missing(
Expand Down