aiidateam / qe-tools

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

Support integer cell params #71

Closed eimrek closed 11 months ago

eimrek commented 11 months ago

We had a Materials Cloud seekpath tool user complain that a valid QE input is not working [1].

I looked into it, and it seemed to come from the fact that the zeroes were integers (no decimal point).

Same issue has arisen a while ago: fixes #51

Took a while to go through the regexes, but the issue stems from here

https://github.com/aiidateam/qe-tools/blob/ee3f7d78fc5cfab35584e36ccee12a56d00ec5da/src/qe_tools/parsers/_input_base.py#L566-L577

This matches 1) \s+ (whitespace); and 2) a number. Not fully sure why, but if i add extra parentheses around the number part, everything works correctly.

But together with this issue, i refactored the whole script a bit, as this number-matching-pattern was duplicated in many places. I defined it as a constant, added parenthesis around it, so it's safe and just used that constant everywhere a number needed to be matched. i think it's more understandable and maintainable this way.

Additionally i added a test that would have failed before.

cc @giovannipizzi

[1]:

&control
    outdir = './out_nacl'
    prefix = 'nacl'
    calculation = 'scf'
    tprnfor = .true.
    tstress = .true.
    pseudo_dir = './pseudo/'
 /
 &system
    ibrav = 0
    nat = 8
    ntyp = 2
    ecutwfc = 70.0
 /
 &electrons
    diagonalization = 'david'
    conv_thr = 1.0d-9
 /
ATOMIC_SPECIES
 Na  22.98976928 Na.paw.z_9.ld1.psl.v1.0.0-low.upf
 Cl  35.453      Cl.pbe-n-rrkjus_psl.1.0.0.UPF
ATOMIC_POSITIONS crystal
 Na   0.0000000000000000  0.0000000000000000  0.0000000000000000
 Na   0.0000000000000000  0.5000000000000000  0.5000000000000000
 Na   0.5000000000000000  0.0000000000000000  0.5000000000000000
 Na   0.5000000000000000  0.5000000000000000  0.0000000000000000
 Cl   0.5000000000000000  0.5000000000000000  0.5000000000000000
 Cl   0.5000000000000000  0.0000000000000000  0.0000000000000000
 Cl   0.0000000000000000  0.5000000000000000  0.0000000000000000
 Cl   0.0000000000000000  0.0000000000000000  0.5000000000000000
CELL_PARAMETERS angstrom
 5.6903014761756712 0 0
 0 5.6903014761756712 0
 0 0 5.6903014761756712
K_POINTS automatic
8 8 8 1 1 1
codecov-commenter commented 11 months ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (ee3f7d7) 89.87% compared to head (b2a5657) 89.89%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #71 +/- ## ========================================== + Coverage 89.87% 89.89% +0.02% ========================================== Files 10 10 Lines 464 465 +1 ========================================== + Hits 417 418 +1 Misses 47 47 ``` | [Files](https://app.codecov.io/gh/aiidateam/qe-tools/pull/71?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | Coverage Δ | | |---|---|---| | [src/qe\_tools/parsers/\_input\_base.py](https://app.codecov.io/gh/aiidateam/qe-tools/pull/71?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam#diff-c3JjL3FlX3Rvb2xzL3BhcnNlcnMvX2lucHV0X2Jhc2UucHk=) | `88.25% <100.00%> (+0.03%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.