ipyvasp 0.9.86__tar.gz → 0.9.88__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/PKG-INFO +1 -1
  2. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/__init__.py +1 -1
  3. ipyvasp-0.9.88/ipyvasp/_version.py +1 -0
  4. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/misc.py +7 -2
  5. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/utils.py +54 -16
  6. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/widgets.py +5 -5
  7. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp.egg-info/PKG-INFO +1 -1
  8. ipyvasp-0.9.86/ipyvasp/_version.py +0 -1
  9. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/LICENSE +0 -0
  10. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/README.md +0 -0
  11. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/__main__.py +0 -0
  12. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/_enplots.py +0 -0
  13. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/_lattice.py +0 -0
  14. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/bsdos.py +0 -0
  15. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/cli.py +0 -0
  16. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/core/__init__.py +0 -0
  17. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/core/parser.py +0 -0
  18. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/core/plot_toolkit.py +0 -0
  19. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/core/serializer.py +0 -0
  20. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/core/spatial_toolkit.py +0 -0
  21. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/evals_dataframe.py +0 -0
  22. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/lattice.py +0 -0
  23. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp/potential.py +0 -0
  24. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp.egg-info/SOURCES.txt +0 -0
  25. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp.egg-info/dependency_links.txt +0 -0
  26. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp.egg-info/entry_points.txt +0 -0
  27. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp.egg-info/requires.txt +0 -0
  28. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/ipyvasp.egg-info/top_level.txt +0 -0
  29. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/setup.cfg +0 -0
  30. {ipyvasp-0.9.86 → ipyvasp-0.9.88}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ipyvasp
3
- Version: 0.9.86
3
+ Version: 0.9.88
4
4
  Summary: A processing tool for VASP DFT input/output processing in Jupyter Notebook.
5
5
  Home-page: https://github.com/massgh/ipyvasp
6
6
  Author: Abdul Saboor
@@ -18,7 +18,7 @@ __all__ = [ # For documentation purpose
18
18
  "webshow",
19
19
  "load_results",
20
20
  "parse_text",
21
- "get_lines",
21
+ "take",
22
22
  "summarize",
23
23
  ]
24
24
 
@@ -0,0 +1 @@
1
+ __version__ = "0.9.88"
@@ -3,6 +3,7 @@ __all__ = ["parse_text", "get_bib", "get_E0", "OUTCAR"]
3
3
  import requests
4
4
  from pathlib import Path
5
5
  from itertools import islice
6
+ import numpy as np
6
7
 
7
8
  from .core import parser as vp
8
9
  from .utils import _sig_kwargs, _sub_doc
@@ -35,8 +36,8 @@ def get_bib(DOI):
35
36
 
36
37
  return response.status_code
37
38
 
38
- def get_E0(path: Path = 'OSZICAR'):
39
- "Get the E0 from the last line of OSZICAR."
39
+ def get_E0(path: Path = 'OSZICAR',nsteps=0):
40
+ "Get the E0 from the last line of OSZICAR. If `nsteps > 0`, returns as many available last steps ."
40
41
  fh = Path(path)
41
42
  if fh.is_file():
42
43
  lines = fh.read_text().splitlines()
@@ -51,6 +52,10 @@ def get_E0(path: Path = 'OSZICAR'):
51
52
 
52
53
  if not line.lstrip().startswith('1'):
53
54
  print(f"Calculation may not be converged for {path!r}\n{line}")
55
+
56
+ if nsteps > 0: # not allow negative ones
57
+ lines = [float(line.split()[2]) for line in lines if (not 'dE' in line) and (not 'F=' in line)]
58
+ return np.array(lines[-nsteps:]) # as many last steps
54
59
 
55
60
  return float(line.split('=')[1].split()[0])
56
61
 
@@ -1,6 +1,6 @@
1
1
  __all__ = [
2
2
  "get_file_size",
3
- "get_lines",
3
+ "take",
4
4
  "set_dir",
5
5
  "interpolate_data",
6
6
  "rolling_mean",
@@ -15,6 +15,7 @@ import io
15
15
  from contextlib import contextmanager
16
16
  from pathlib import Path
17
17
  from inspect import signature, getdoc
18
+ from itertools import islice
18
19
 
19
20
 
20
21
  import numpy as np
@@ -36,37 +37,74 @@ def get_file_size(path: str):
36
37
  else:
37
38
  return ""
38
39
 
39
- def get_lines(f, indices):
40
- """Read lines by indexing from an opened file pointer `f`. Negative indexing is supported to read lines from end.
41
- Returns a single str of line if one integer given, otherwise a list of lines.
42
- This consumes a lot less memory then indexing over `f.readlines()[index]`.
40
+ def take(f, rows, cols=None, dtype=None, exclude=None,sep=None):
41
+ """Read data from an opened file pointer `f` by indexing. `rows=None` picks all lines. Negative indexing is supported to read lines from end.
42
+ Negative indexing is not supported in cols because of variable length of each line.
43
+ If `cols=None`, returns a single str of line if one integer given, otherwise a list of lines.
44
+ If `cols` is int ot sequence of int, each line is splitted by `sep` (default all whitespaces) and `dtype` is applied over resulting fields.
45
+ `exclude` should be regex. It removes lines after selection by `rows`.
43
46
 
47
+ Returns list (nested or plain) or single value or None based on `rows` and `cols` selection.
48
+
49
+ `take(f, -1, 1, float) == float(f.readlines()[-1].split()[1])` with advantage for consuming almost no memory as compared to `f.readlines()` on a huge file.
50
+
51
+ .. note::
52
+ For more robust reading of structured files like `PROCAR` use `ipyvasp.parse_text` function.
53
+
54
+ .. tip::
55
+ If your output is matrix-like, you can cast it to numpy array like `take(...)*np.array(1)`.
56
+
44
57
  >>> with open('some_file','r') as f:
45
- >>> get_lines(f, -1) # last line
46
- >>> get_lines(f, range(5)) # first 5 lines
47
- >>> get_lines(f, range(-5,0)) # last 5 lines
58
+ >>> take(f, -1, 1, float) # read last line, second column as float
59
+ >>> take(f, range(5)) # first 5 lines
60
+ >>> take(f, range(-5,0)) # last 5 lines
48
61
  """
49
62
  if not isinstance(f, io.TextIOWrapper):
50
63
  raise TypeError(f"f should be file-like object. got {type(f)}")
51
64
 
52
65
  return_line = False
53
- if isinstance(indices, int):
54
- indices = [indices]
66
+ if isinstance(rows, int):
67
+ rows = [rows]
55
68
  return_line = True
56
69
 
57
- if not isinstance(indices, (tuple,list, range)):
58
- raise TypeError(f"indices should int/list/tuple/range, got {type(indices)}")
70
+ if rows and not isinstance(rows, (tuple,list, range)):
71
+ raise TypeError(f"rows should int/list/tuple/range, got {type(rows)}")
59
72
 
60
73
  f.seek(0)
61
- if min(indices) < 0:
74
+ if rows and min(rows) < 0:
62
75
  if not hasattr(f, '_nlines'): # do this once, assuming file is not changed while reading
63
76
  f._nlines = sum(1 for _ in enumerate(f))
64
77
  f.seek(0)
65
78
 
66
- indices = [i + (f._nlines if i < 0 else 0) for i in indices] # make all positive
79
+ rows = [i + (f._nlines if i < 0 else 0) for i in rows] # make all positive
67
80
 
68
- lines = [l for i, l in enumerate(f) if i in indices]
69
- return lines[0] if return_line else lines
81
+ if rows is None:
82
+ lines = islice(f, None)
83
+ else:
84
+ lines = (l for i, l in enumerate(f) if i in rows)
85
+
86
+ if exclude:
87
+ lines = (l for l in lines if not re.search(exclude,l))
88
+
89
+ if cols:
90
+ conv = dtype if callable(dtype) else (lambda v: v)
91
+ return_col = False
92
+ if isinstance(cols, int):
93
+ cols = [cols]
94
+ return_col = True
95
+
96
+ if not isinstance(cols, (list,tuple, range)):
97
+ raise TypeError(f"cols should be a sequce of integers or single int, got {type(cols)}")
98
+
99
+ lines = ([conv(v) for i, v in enumerate(l.split(sep)) if i in cols] for l in lines)
100
+
101
+ if return_col:
102
+ lines = (line[0] if line else None for line in lines)
103
+ else:
104
+ return ''.join(lines) or None # just raw format as it is
105
+
106
+ # Try to return None where there is nothing
107
+ return next(lines,None) if return_line else (list(lines) or None)
70
108
 
71
109
 
72
110
  def _sig_kwargs(from_func, skip_params=()):
@@ -261,10 +261,10 @@ class Files:
261
261
  If you don't need to interpret the result of the function call, you can use the @self.interact decorator instead.
262
262
  """
263
263
  info = ipw.HTML().add_class("fprogess")
264
- dd = Dropdown(description='File', options=['Select a File',*self._files]) # allows single file workable
264
+ dd = Dropdown(description='File', options=['',*self._files]) # allows single file workable
265
265
 
266
266
  def interact_func(fname, **kws):
267
- if fname and str(fname) != 'Select a File': # This would be None if no file is selected
267
+ if fname and str(fname) != '': # This would be None if no file is selected
268
268
  info.value = _progress_svg
269
269
  try:
270
270
  start = time()
@@ -448,9 +448,9 @@ class Files:
448
448
  >>> import ipyvasp as ipv
449
449
  >>> files = ipv.Files(...)
450
450
  >>> files.mapf(lambda fp: json.load(fp,cls=ipv.DecodeToNumpy),to_df=True) # or use ipv.load(path) in map
451
- >>> files.mapf(lambda fp: ipv.get_lines(fp, range(5)) # read first five lines
452
- >>> files.mapf(lambda fp: ipv.get_lines(fp, range(-5,0)) # read last five lines
453
- >>> files.mapf(lambda fp: ipv.get_lines(fp, -1) # read last line
451
+ >>> files.mapf(lambda fp: ipv.take(fp, range(5)) # read first five lines
452
+ >>> files.mapf(lambda fp: ipv.take(fp, range(-5,0)) # read last five lines
453
+ >>> files.mapf(lambda fp: ipv.take(fp, -1, 1, float) # read last line, second column as float
454
454
  """
455
455
  if not mode in 'rb':
456
456
  raise ValueError("Only 'r'/'rb' mode is allowed in this context!")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ipyvasp
3
- Version: 0.9.86
3
+ Version: 0.9.88
4
4
  Summary: A processing tool for VASP DFT input/output processing in Jupyter Notebook.
5
5
  Home-page: https://github.com/massgh/ipyvasp
6
6
  Author: Abdul Saboor
@@ -1 +0,0 @@
1
- __version__ = "0.9.86"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes