-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add marda-extractors support for PW and CP input files (#73)
- Loading branch information
1 parent
c0e3c51
commit 8c50b4c
Showing
9 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
from pathlib import Path | ||
|
||
from qe_tools.exceptions import PathIsNotAFile | ||
from qe_tools.parsers import CpInputFile, PwInputFile | ||
|
||
SUPPORTED_PARSERS = [ | ||
'PW', | ||
'CP', | ||
] | ||
|
||
|
||
def extract(filepath: str, parser: str) -> dict: | ||
"""Extract QE input file as a dictionary. | ||
Parameters | ||
---------- | ||
`filepath` : `str` | ||
The path to the file. | ||
`parser` : `str` | ||
The QE parser type. Supported: ['PW', 'CP'] | ||
Returns | ||
------- | ||
`dict` | ||
The parsed input as a dictionary. | ||
Raises | ||
------ | ||
`FileNotFoundError` | ||
If the file does not exist. | ||
`PathIsNotAFile` | ||
If the path does not point to a file. | ||
`ValueError` | ||
If the parser type is not supported. | ||
""" | ||
|
||
path = Path(filepath) | ||
|
||
if not path.exists(): | ||
raise FileNotFoundError(f"'{filepath}' does not exist") | ||
|
||
if not path.is_file(): | ||
raise PathIsNotAFile(f"'{filepath}' is not a valid file.") | ||
|
||
input_str = path.read_text(encoding='utf-8') | ||
parser = parser.upper() | ||
|
||
if parser == 'PW': | ||
return PwInputFile(input_str).as_dict() | ||
|
||
if parser == 'CP': | ||
return CpInputFile(input_str).as_dict() | ||
|
||
raise ValueError(f"Supported parsers: {SUPPORTED_PARSERS}; given: '{parser}'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
&control | ||
title = ' Water Molecule ', | ||
calculation = 'cp', | ||
restart_mode = 'from_scratch', | ||
ndr = 51, | ||
ndw = 51, | ||
nstep = 100, | ||
iprint = 100, | ||
isave = 100, | ||
tstress = .TRUE., | ||
tprnfor = .TRUE., | ||
dt = 5.0d0, | ||
etot_conv_thr = 1.d-9, | ||
ekin_conv_thr = 1.d-4, | ||
prefix = 'h2o' | ||
verbosity = 'medium' | ||
/ | ||
&system | ||
ibrav = 14, | ||
celldm(1) = 12.0, | ||
celldm(2) = 1.0, | ||
celldm(3) = 1.0, | ||
celldm(4) = 0.0, | ||
celldm(5) = 0.0, | ||
celldm(6) = 0.0, | ||
nat = 3, | ||
ntyp = 2, | ||
nbnd = 4, | ||
ecutwfc = 80.0, | ||
/ | ||
&electrons | ||
emass = 400.d0, | ||
emass_cutoff = 2.5d0, | ||
orthogonalization = 'ortho', | ||
electron_dynamics = 'damp', | ||
electron_damping = 0.2 | ||
/ | ||
&ions | ||
ion_dynamics = 'none', | ||
ion_radius(1) = 0.8d0, | ||
ion_radius(2) = 0.8d0, | ||
/ | ||
ATOMIC_SPECIES | ||
O 16.0d0 O.blyp-mt.UPF | ||
H 1.00d0 H.blyp-vbc.UPF | ||
ATOMIC_POSITIONS (bohr) | ||
O 0.0099 0.0099 0.0000 0 0 0 | ||
H 1.8325 -0.2243 -0.0001 1 1 1 | ||
H -0.2243 1.8325 0.0002 1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"structure": { | ||
"positions": [ | ||
[0.005238854365041, 0.005238854365041, 0.0], | ||
[0.9697172347411749, -0.11869444788673698, -5.2917720858999996e-5], | ||
[-0.11869444788673698, 0.9697172347411749, 0.00010583544171799999] | ||
], | ||
"species": { | ||
"names": ["O", "H"], | ||
"masses": [16.0, 1.0], | ||
"pseudo_file_names": ["O.blyp-mt.UPF", "H.blyp-vbc.UPF"] | ||
}, | ||
"cell": [ | ||
[6.350126503079999, 0.0, 0.0], | ||
[0.0, 6.350126503079999, 0.0], | ||
[0.0, 0.0, 6.350126503079999] | ||
], | ||
"atom_names": ["O", "H", "H"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"structure": { | ||
"positions": [ | ||
[0.005238854365041, 0.005238854365041, 0.0], | ||
[0.9697172347411749, -0.11869444788673698, -5.2917720858999996e-5], | ||
[-0.11869444788673698, 0.9697172347411749, 0.00010583544171799999] | ||
], | ||
"species": { | ||
"names": ["O", "H"], | ||
"masses": [16.0, 1.0], | ||
"pseudo_file_names": ["O.blyp-mt.UPF", "H.blyp-vbc.UPF"] | ||
}, | ||
"cell": [ | ||
[6.350126503079999, 0.0, 0.0], | ||
[0.0, 6.350126503079999, 0.0], | ||
[0.0, 0.0, 6.350126503079999] | ||
], | ||
"atom_names": ["O", "H", "H"] | ||
}, | ||
"k-points": { "type": "gamma" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
&control | ||
calculation = 'relax', | ||
/ | ||
&system | ||
ibrav = 1, | ||
celldm(1) = 12.0, | ||
nat = 3, | ||
ntyp = 2, | ||
nbnd = 4, | ||
ecutwfc = 80, | ||
ecutfock=160, | ||
input_dft = 'X3LYP' | ||
exxdiv_treatment = 'gygi-baldereschi' | ||
x_gamma_extrapolation = .TRUE. | ||
/ | ||
&electrons | ||
/ | ||
&ions | ||
/ | ||
ATOMIC_SPECIES | ||
O 16.0d0 O.blyp-mt.UPF | ||
H 1.00d0 H.blyp-vbc.UPF | ||
ATOMIC_POSITIONS (bohr) | ||
O 0.0099 0.0099 0.0000 | ||
H 1.8325 -0.2243 -0.0001 | ||
H -0.2243 1.8325 0.0002 | ||
K_POINTS gamma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from qe_tools.extractors import extract | ||
|
||
|
||
@pytest.mark.parametrize('parser', ['pw', 'cp']) | ||
def test_input_dict_extraction(parser: str): | ||
datadir = Path(__file__).resolve().parent / 'data' | ||
filepath = datadir / f'{parser}.in' | ||
refpath = datadir / 'extractor_ref' / f'{parser}.json' | ||
assert extract(filepath.as_posix(), parser) == json.loads(refpath.read_text()) |