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

io.pwscf.PWInput.from_file() incorrectly reads decimal numbers and the K_POINTS card in automatic mode #4114

Open
jsukpark opened this issue Oct 17, 2024 · 1 comment · May be fixed by #4115
Labels

Comments

@jsukpark
Copy link
Contributor

jsukpark commented Oct 17, 2024

Python version

Python 3.12.4

Pymatgen version

2024.10.3

Operating system version

Ubuntu 22.04.5 LTS

Current behavior

The io.pwscf.PWInput.from_file() method fails to correctly parse:

  • decimal numbers written in scientific notation with exponent part prefixed with e or E (note that as of QE v7.3, pw.x can still parse such cases correctly; i.e., exponent prefix need not be d), and
  • the K_POINTS card with mode set to automatic.

Example input file scf.in:

&CONTROL
  calculation = 'scf',
/
&SYSTEM
  ecutwfc = 100,
  ibrav = 0,
  nat = 2,
  ntyp = 1,
/
&ELECTRONS
  conv_thr = 2e-12,    ! same behavior with 2E-12
/
ATOMIC_SPECIES
  C  12.0107 C.upf
ATOMIC_POSITIONS crystal
  C  0.2500000000  0.2500000000 0.2500000000
  C -0.0000000000 -0.0000000000 0.0000000000
K_POINTS automatic
  4 4 4 1 1 1
CELL_PARAMETERS angstrom
  -1.786119886   0.000000000   1.786119886
  -0.000000000   1.786119886   1.786119886
  -1.786119886   1.786119886   0.000000000

Current behavior:

>>> from pymatgen.io.pwscf import PWInput
>>> pwi = PWInput.from_file("scf.in")
>>> print(pwi.sections["electrons"]["conv_thr"])
2.0
>>> print(pwi.kpoints_grid, pwi.kpoints_shift)
(1, 1, 1) (0, 0, 0)

Expected Behavior

I expect both the conv_thr value and the K_POINTS card in the above example input file to be parsed correctly.

>>> from pymatgen.io.pwscf import PWInput
>>> pwi = PWInput.from_file("scf.in")
>>> print(pwi.sections["electrons"]["conv_thr"])
2e-12
>>> print(pwi.kpoints_grid, pwi.kpoints_shift)
(4, 4, 4) (1, 1, 1)

Minimal example

contents = """&CONTROL
  calculation = 'scf',
/
&SYSTEM
  ecutwfc = 100,
  ibrav = 0,
  nat = 2,
  ntyp = 1,
/
&ELECTRONS
  conv_thr = 2e-12,    ! same behavior with 2E-12
/
ATOMIC_SPECIES
  C  12.0107 C.upf
ATOMIC_POSITIONS crystal
  C  0.2500000000  0.2500000000 0.2500000000
  C -0.0000000000 -0.0000000000 0.0000000000
K_POINTS automatic
  4 4 4 1 1 1
CELL_PARAMETERS angstrom
  -1.786119886   0.000000000   1.786119886
  -0.000000000   1.786119886   1.786119886
  -1.786119886   1.786119886   0.000000000
"""

with open("scf.in", "w") as fp:
    fp.write(contents)

from pymatgen.io.pwscf import PWInput

pwi = PWInput.from_file("scf.in")
print(pwi.sections["electrons"]["conv_thr"])  # Prints "2.0", should print "2e-12"
print(pwi.kpoints_grid, pwi.kpoints_shift)  # Prints "(1, 1, 1) (0, 0, 0)", should print "(4, 4, 4) (1, 1, 1)"

Relevant files to reproduce this bug

No response

@jsukpark jsukpark added the bug label Oct 17, 2024
@jsukpark jsukpark linked a pull request Oct 17, 2024 that will close this issue
@jsukpark
Copy link
Contributor Author

Seems there is one more bug in parsing K_POINTS card, adding that to this issue

@jsukpark jsukpark changed the title io.pwscf.PWInput.from_file() incorrectly reads decimal numbers io.pwscf.PWInput.from_file() incorrectly reads decimal numbers and the K_POINTS card in automatic mode Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant