Skip to content

Commit 84a33e4

Browse files
committed
normalize importing and namespacing
1 parent 20b52f1 commit 84a33e4

File tree

7 files changed

+83
-78
lines changed

7 files changed

+83
-78
lines changed

docs/api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# API Reference
22

3-
::: w90io
3+
::: w90io.parse_win
4+
::: w90io.parse_nnkp
5+
::: w90io.read_amn
6+
::: w90io.read_eig

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ plugins:
2929
selection:
3030
docstring_style: google
3131
rendering:
32+
show_root_heading: true
3233
show_root_toc_entry: false
3334
show_signature_annotations: true
3435
show_source: true

src/w90io/__init__.py

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,5 @@
1-
from __future__ import annotations
2-
3-
from . import _core
4-
from . import _nnkp
5-
from . import _win
61
from ._amn import *
72
from ._eig import *
8-
from ._wout import parse_iteration_info
9-
10-
11-
__all__ = [
12-
'parse_iteration_info',
13-
]
14-
15-
16-
def parse_win(string: str) -> dict:
17-
"""
18-
Parse WIN
19-
20-
Arguments:
21-
string: the WIN text
22-
23-
Returns:
24-
the parsed WIN
25-
"""
26-
comments = _core.extract_comments(string)
27-
parameters = _core.parse_parameters(_core.extract_parameters(string))
28-
blocks = _core.parse_blocks(_core.extract_blocks(string))
29-
30-
parsed_win = {
31-
'comments': comments,
32-
'parameters': parameters,
33-
'blocks': blocks,
34-
}
35-
if 'unit_cell_cart' in blocks:
36-
parsed_win['unit_cell_cart'] =_win.parse_unit_cell(blocks['unit_cell_cart'])
37-
if 'atoms_cart' in blocks:
38-
parsed_win['atoms_cart'] = _win.parse_atoms(blocks['atoms_cart'])
39-
if 'atoms_frac' in blocks:
40-
parsed_win['atoms_frac'] = _win.parse_atoms(blocks['atoms_frac'])
41-
if 'projections' in blocks:
42-
parsed_win['projections'] = _win.parse_projections(blocks['projections'])
43-
if 'kpoints' in blocks:
44-
parsed_win['kpoints'] =_win.parse_kpoints(blocks['kpoints'])
45-
46-
return parsed_win
47-
48-
49-
def parse_nnkp(string: str) -> dict:
50-
"""
51-
Parse NNKP
52-
53-
Arguments:
54-
string: the NNKP text
55-
56-
Returns:
57-
the parsed NNKP
58-
"""
59-
comments = _core.extract_comments(string)
60-
parameters = _core.parse_parameters(_core.extract_parameters(string))
61-
blocks = _core.parse_blocks(_core.extract_blocks(string))
62-
63-
parsed_nnkp = {
64-
'comments': comments,
65-
'parameters': parameters,
66-
'blocks': blocks,
67-
'direct_lattice': _nnkp.parse_direct_lattice(blocks['real_lattice']),
68-
'reciprocal_lattice': _nnkp.parse_reciprocal_lattice(blocks['recip_lattice']),
69-
'kpoints': _nnkp.parse_kpoints(blocks['kpoints']),
70-
'exclude_bands': _nnkp.parse_exclude_bands(blocks['exclude_bands']),
71-
}
72-
if 'projections' in 'blocks':
73-
parsed_nnkp['projections'] = _nnkp.parse_projections(blocks['projections'])
74-
if 'spinor_projections' in blocks:
75-
parsed_nnkp['spinor_projections'] = _nnkp.parse_spinor_projections(blocks['spinor_projections'])
76-
77-
return parsed_nnkp
3+
from ._nnkp import *
4+
from ._win import *
5+
from ._wout import *

src/w90io/_nnkp.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from . import _core
77

88

9+
__all__ = ['parse_nnkp']
10+
11+
912
patterns = {
1013
'lattice_vectors': re.compile(
1114
rf'(?P<v1>{_core.expressions["3-vector"]})\s+'
@@ -126,3 +129,34 @@ def parse_exclude_bands(string: str) -> dict:
126129
return {
127130
'exclude_bands': None
128131
}
132+
133+
134+
def parse_nnkp(string: str) -> dict:
135+
"""
136+
Parse NNKP
137+
138+
Arguments:
139+
string: the NNKP text
140+
141+
Returns:
142+
the parsed NNKP
143+
"""
144+
comments = _core.extract_comments(string)
145+
parameters = _core.parse_parameters(_core.extract_parameters(string))
146+
blocks = _core.parse_blocks(_core.extract_blocks(string))
147+
148+
parsed_nnkp = {
149+
'comments': comments,
150+
'parameters': parameters,
151+
'blocks': blocks,
152+
'direct_lattice': parse_direct_lattice(blocks['real_lattice']),
153+
'reciprocal_lattice': parse_reciprocal_lattice(blocks['recip_lattice']),
154+
'kpoints': parse_kpoints(blocks['kpoints']),
155+
'exclude_bands': parse_exclude_bands(blocks['exclude_bands']),
156+
}
157+
if 'projections' in 'blocks':
158+
parsed_nnkp['projections'] = parse_projections(blocks['projections'])
159+
if 'spinor_projections' in blocks:
160+
parsed_nnkp['spinor_projections'] = parse_spinor_projections(blocks['spinor_projections'])
161+
162+
return parsed_nnkp

src/w90io/_win.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import numpy as np
77

88

9+
__all__ = ['parse_win']
10+
11+
912
patterns = {
1013
'unit_cell': re.compile(
1114
r'((?P<units>bohr|ang)\s+)?'
@@ -78,3 +81,36 @@ def parse_kpoints(string: str) -> dict:
7881
return {
7982
'kpoints': np.fromstring(string, sep='\n').reshape((len(string.splitlines()), -1))[:, :3]
8083
}
84+
85+
86+
def parse_win(string: str) -> dict:
87+
"""
88+
Parse WIN
89+
90+
Arguments:
91+
string: the WIN text
92+
93+
Returns:
94+
the parsed WIN
95+
"""
96+
comments = _core.extract_comments(string)
97+
parameters = _core.parse_parameters(_core.extract_parameters(string))
98+
blocks = _core.parse_blocks(_core.extract_blocks(string))
99+
100+
parsed_win = {
101+
'comments': comments,
102+
'parameters': parameters,
103+
'blocks': blocks,
104+
}
105+
if 'unit_cell_cart' in blocks:
106+
parsed_win['unit_cell_cart'] = parse_unit_cell(blocks['unit_cell_cart'])
107+
if 'atoms_cart' in blocks:
108+
parsed_win['atoms_cart'] = parse_atoms(blocks['atoms_cart'])
109+
if 'atoms_frac' in blocks:
110+
parsed_win['atoms_frac'] = parse_atoms(blocks['atoms_frac'])
111+
if 'projections' in blocks:
112+
parsed_win['projections'] = parse_projections(blocks['projections'])
113+
if 'kpoints' in blocks:
114+
parsed_win['kpoints'] = parse_kpoints(blocks['kpoints'])
115+
116+
return parsed_win

src/w90io/_wout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from . import _core
66

77

8+
__all__ = ['parse_wout', 'parse_wout_iteration_info']
9+
10+
811
patterns = {
912
'convergence_line': re.compile(
1013
r'^\s*'
@@ -41,7 +44,7 @@
4144
}
4245

4346

44-
def parse_iteration_info(stream: typing.TextIO) -> dict:
47+
def parse_wout_iteration_info(stream: typing.TextIO) -> dict:
4548
convergence = []
4649
spread = []
4750
delta = []

tests/test_wout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
def test_parse_win(wannier90, example):
1010
with open(pathlib.Path(wannier90)/f'examples/{example}/wannier.wout', 'r') as fh:
1111
try:
12-
w90io.parse_iteration_info(fh)
12+
w90io.parse_wout_iteration_info(fh)
1313
except Exception:
1414
assert False

0 commit comments

Comments
 (0)