aiidateam / qe-tools

A set of useful tools for Quantum ESPRESSO
MIT License
29 stars 14 forks source link

Parsing PW input file #51

Closed hududed closed 11 months ago

hududed commented 3 years ago

Hello

I tried to parse an input file:

from qe_tools import PwInputFile

with open('aiida.in', 'r') as in_f:
    parsed_file = PwInputFile(in_f.read())
parsed_file.get_structure_from_qeinput()

and got the error that CELL_PARAMETERS is a nonetype.

The solution was proposed that my CELL_PARAMETERS values did not contain 0.0 instead of a 0.

Worked:

CELL_PARAMETERS angstrom
16.1762 0.0 0.0000000000
-8.0881 14.009 0.0000000000
0.0 0.0 18.3843

Failed:

CELL_PARAMETERS angstrom
16.1762 0 0.0000000000
-8.0881 14.009 0.0000000000
0 0 18.3843
greschd commented 3 years ago

@giovannipizzi @sphuber do you know if that is a limitation that QE itself puts on the input file, or is it just a limitation of our parser?

sphuber commented 3 years ago

To be honest I don't know. I have not written these parser nor ever worked with them. But looking at _parse_cell_parameters which defines the regex that parses the CELL_PARAMETERS block, the regex seems to allow 0, i.e. it considers the dot and decimals optional. So I am not sure why it fails just from looking at the code quickly. However, I would say that specifying an integer should work just fine and not return None.

greschd commented 3 years ago

To be honest I don't know. I have not written these parser nor ever worked with them.

Yeah, same here 😅

Also looking at the code quickly, it seems the cell_vector_regex allows integers:

https://github.com/aiidateam/qe-tools/blob/359579ee4a88fb6920270de39f49524e9365fda2/qe_tools/parsers/_input_base.py#L595-L613

But the cell_parameters_block_re does not:

https://github.com/aiidateam/qe-tools/blob/359579ee4a88fb6920270de39f49524e9365fda2/qe_tools/parsers/_input_base.py#L546-L592

If that one doesn't match, it never gets to trying to parse the individual vectors. Not sure why there are these two separate regex-es, instead of just using the matches from cell_parameters_block_re.

giovannipizzi commented 3 years ago

This was originally written by @lekah I think that we should accept ints (and convert them to floats)