ipyvasp 0.9.87__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.87 → ipyvasp-0.9.88}/PKG-INFO +1 -1
  2. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/__init__.py +1 -1
  3. ipyvasp-0.9.88/ipyvasp/_version.py +1 -0
  4. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/misc.py +7 -2
  5. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/utils.py +26 -10
  6. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/widgets.py +2 -2
  7. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp.egg-info/PKG-INFO +1 -1
  8. ipyvasp-0.9.87/ipyvasp/_version.py +0 -1
  9. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/LICENSE +0 -0
  10. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/README.md +0 -0
  11. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/__main__.py +0 -0
  12. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/_enplots.py +0 -0
  13. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/_lattice.py +0 -0
  14. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/bsdos.py +0 -0
  15. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/cli.py +0 -0
  16. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/core/__init__.py +0 -0
  17. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/core/parser.py +0 -0
  18. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/core/plot_toolkit.py +0 -0
  19. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/core/serializer.py +0 -0
  20. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/core/spatial_toolkit.py +0 -0
  21. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/evals_dataframe.py +0 -0
  22. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/lattice.py +0 -0
  23. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp/potential.py +0 -0
  24. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp.egg-info/SOURCES.txt +0 -0
  25. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp.egg-info/dependency_links.txt +0 -0
  26. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp.egg-info/entry_points.txt +0 -0
  27. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp.egg-info/requires.txt +0 -0
  28. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/ipyvasp.egg-info/top_level.txt +0 -0
  29. {ipyvasp-0.9.87 → ipyvasp-0.9.88}/setup.cfg +0 -0
  30. {ipyvasp-0.9.87 → 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.87
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
- "index",
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
 
@@ -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,17 +37,22 @@ def get_file_size(path: str):
36
37
  else:
37
38
  return ""
38
39
 
39
- def take(f, rows, cols=None, dtype=str, sep=None):
40
- """Read data from an opened file pointer `f` by indexing. Negative indexing is supported to read lines from end.
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.
41
42
  Negative indexing is not supported in cols because of variable length of each line.
42
43
  If `cols=None`, returns a single str of line if one integer given, otherwise a list of lines.
43
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`.
46
+
47
+ Returns list (nested or plain) or single value or None based on `rows` and `cols` selection.
44
48
 
45
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.
46
50
 
47
- Note: For more robust reading of structured files like `PROCAR` use `ipyvasp.parse_text` function.
51
+ .. note::
52
+ For more robust reading of structured files like `PROCAR` use `ipyvasp.parse_text` function.
48
53
 
49
- Tip: If your output is matrix-like, you can cast it to numpy array like `take(...)*np.array(1)`.
54
+ .. tip::
55
+ If your output is matrix-like, you can cast it to numpy array like `take(...)*np.array(1)`.
50
56
 
51
57
  >>> with open('some_file','r') as f:
52
58
  >>> take(f, -1, 1, float) # read last line, second column as float
@@ -61,20 +67,27 @@ def take(f, rows, cols=None, dtype=str, sep=None):
61
67
  rows = [rows]
62
68
  return_line = True
63
69
 
64
- if not isinstance(rows, (tuple,list, range)):
70
+ if rows and not isinstance(rows, (tuple,list, range)):
65
71
  raise TypeError(f"rows should int/list/tuple/range, got {type(rows)}")
66
72
 
67
73
  f.seek(0)
68
- if min(rows) < 0:
74
+ if rows and min(rows) < 0:
69
75
  if not hasattr(f, '_nlines'): # do this once, assuming file is not changed while reading
70
76
  f._nlines = sum(1 for _ in enumerate(f))
71
77
  f.seek(0)
72
78
 
73
79
  rows = [i + (f._nlines if i < 0 else 0) for i in rows] # make all positive
74
80
 
75
- lines = [l for i, l in enumerate(f) if i in rows]
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))
76
88
 
77
89
  if cols:
90
+ conv = dtype if callable(dtype) else (lambda v: v)
78
91
  return_col = False
79
92
  if isinstance(cols, int):
80
93
  cols = [cols]
@@ -83,12 +96,15 @@ def take(f, rows, cols=None, dtype=str, sep=None):
83
96
  if not isinstance(cols, (list,tuple, range)):
84
97
  raise TypeError(f"cols should be a sequce of integers or single int, got {type(cols)}")
85
98
 
86
- lines = [[dtype(v) for i, v in enumerate(l.split(sep)) if i in cols] for l in lines]
99
+ lines = ([conv(v) for i, v in enumerate(l.split(sep)) if i in cols] for l in lines)
87
100
 
88
101
  if return_col:
89
- lines = [line[0] for line in lines]
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
90
105
 
91
- return lines[0] if return_line else lines
106
+ # Try to return None where there is nothing
107
+ return next(lines,None) if return_line else (list(lines) or None)
92
108
 
93
109
 
94
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ipyvasp
3
- Version: 0.9.87
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.87"
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