ipyvasp 0.9.86__tar.gz → 0.9.87__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.87}/PKG-INFO +1 -1
  2. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/__init__.py +1 -1
  3. ipyvasp-0.9.87/ipyvasp/_version.py +1 -0
  4. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/utils.py +37 -15
  5. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/widgets.py +3 -3
  6. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp.egg-info/PKG-INFO +1 -1
  7. ipyvasp-0.9.86/ipyvasp/_version.py +0 -1
  8. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/LICENSE +0 -0
  9. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/README.md +0 -0
  10. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/__main__.py +0 -0
  11. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/_enplots.py +0 -0
  12. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/_lattice.py +0 -0
  13. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/bsdos.py +0 -0
  14. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/cli.py +0 -0
  15. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/core/__init__.py +0 -0
  16. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/core/parser.py +0 -0
  17. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/core/plot_toolkit.py +0 -0
  18. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/core/serializer.py +0 -0
  19. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/core/spatial_toolkit.py +0 -0
  20. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/evals_dataframe.py +0 -0
  21. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/lattice.py +0 -0
  22. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/misc.py +0 -0
  23. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp/potential.py +0 -0
  24. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp.egg-info/SOURCES.txt +0 -0
  25. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp.egg-info/dependency_links.txt +0 -0
  26. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp.egg-info/entry_points.txt +0 -0
  27. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp.egg-info/requires.txt +0 -0
  28. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/ipyvasp.egg-info/top_level.txt +0 -0
  29. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/setup.cfg +0 -0
  30. {ipyvasp-0.9.86 → ipyvasp-0.9.87}/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.87
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
+ "index",
22
22
  "summarize",
23
23
  ]
24
24
 
@@ -0,0 +1 @@
1
+ __version__ = "0.9.87"
@@ -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",
@@ -36,36 +36,58 @@ def get_file_size(path: str):
36
36
  else:
37
37
  return ""
38
38
 
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]`.
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.
41
+ Negative indexing is not supported in cols because of variable length of each line.
42
+ If `cols=None`, returns a single str of line if one integer given, otherwise a list of lines.
43
+ If `cols` is int ot sequence of int, each line is splitted by `sep` (default all whitespaces) and `dtype` is applied over resulting fields.
43
44
 
45
+ `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
+
47
+ Note: For more robust reading of structured files like `PROCAR` use `ipyvasp.parse_text` function.
48
+
49
+ Tip: If your output is matrix-like, you can cast it to numpy array like `take(...)*np.array(1)`.
50
+
44
51
  >>> 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
52
+ >>> take(f, -1, 1, float) # read last line, second column as float
53
+ >>> take(f, range(5)) # first 5 lines
54
+ >>> take(f, range(-5,0)) # last 5 lines
48
55
  """
49
56
  if not isinstance(f, io.TextIOWrapper):
50
57
  raise TypeError(f"f should be file-like object. got {type(f)}")
51
58
 
52
59
  return_line = False
53
- if isinstance(indices, int):
54
- indices = [indices]
60
+ if isinstance(rows, int):
61
+ rows = [rows]
55
62
  return_line = True
56
63
 
57
- if not isinstance(indices, (tuple,list, range)):
58
- raise TypeError(f"indices should int/list/tuple/range, got {type(indices)}")
64
+ if not isinstance(rows, (tuple,list, range)):
65
+ raise TypeError(f"rows should int/list/tuple/range, got {type(rows)}")
59
66
 
60
67
  f.seek(0)
61
- if min(indices) < 0:
68
+ if min(rows) < 0:
62
69
  if not hasattr(f, '_nlines'): # do this once, assuming file is not changed while reading
63
70
  f._nlines = sum(1 for _ in enumerate(f))
64
71
  f.seek(0)
65
72
 
66
- indices = [i + (f._nlines if i < 0 else 0) for i in indices] # make all positive
73
+ rows = [i + (f._nlines if i < 0 else 0) for i in rows] # make all positive
67
74
 
68
- lines = [l for i, l in enumerate(f) if i in indices]
75
+ lines = [l for i, l in enumerate(f) if i in rows]
76
+
77
+ if cols:
78
+ return_col = False
79
+ if isinstance(cols, int):
80
+ cols = [cols]
81
+ return_col = True
82
+
83
+ if not isinstance(cols, (list,tuple, range)):
84
+ raise TypeError(f"cols should be a sequce of integers or single int, got {type(cols)}")
85
+
86
+ lines = [[dtype(v) for i, v in enumerate(l.split(sep)) if i in cols] for l in lines]
87
+
88
+ if return_col:
89
+ lines = [line[0] for line in lines]
90
+
69
91
  return lines[0] if return_line else lines
70
92
 
71
93
 
@@ -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.87
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
File without changes