ipyvasp 0.9.85__py2.py3-none-any.whl → 0.9.87__py2.py3-none-any.whl

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.
ipyvasp/__init__.py CHANGED
@@ -18,6 +18,7 @@ __all__ = [ # For documentation purpose
18
18
  "webshow",
19
19
  "load_results",
20
20
  "parse_text",
21
+ "index",
21
22
  "summarize",
22
23
  ]
23
24
 
ipyvasp/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.9.85"
1
+ __version__ = "0.9.87"
ipyvasp/utils.py CHANGED
@@ -1,5 +1,6 @@
1
1
  __all__ = [
2
2
  "get_file_size",
3
+ "take",
3
4
  "set_dir",
4
5
  "interpolate_data",
5
6
  "rolling_mean",
@@ -10,6 +11,7 @@ __all__ = [
10
11
 
11
12
  import re
12
13
  import os
14
+ import io
13
15
  from contextlib import contextmanager
14
16
  from pathlib import Path
15
17
  from inspect import signature, getdoc
@@ -33,6 +35,60 @@ def get_file_size(path: str):
33
35
  size /= 1024.0
34
36
  else:
35
37
  return ""
38
+
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.
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
+
51
+ >>> with open('some_file','r') as f:
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
55
+ """
56
+ if not isinstance(f, io.TextIOWrapper):
57
+ raise TypeError(f"f should be file-like object. got {type(f)}")
58
+
59
+ return_line = False
60
+ if isinstance(rows, int):
61
+ rows = [rows]
62
+ return_line = True
63
+
64
+ if not isinstance(rows, (tuple,list, range)):
65
+ raise TypeError(f"rows should int/list/tuple/range, got {type(rows)}")
66
+
67
+ f.seek(0)
68
+ if min(rows) < 0:
69
+ if not hasattr(f, '_nlines'): # do this once, assuming file is not changed while reading
70
+ f._nlines = sum(1 for _ in enumerate(f))
71
+ f.seek(0)
72
+
73
+ rows = [i + (f._nlines if i < 0 else 0) for i in rows] # make all positive
74
+
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
+
91
+ return lines[0] if return_line else lines
36
92
 
37
93
 
38
94
  def _sig_kwargs(from_func, skip_params=()):
ipyvasp/widgets.py CHANGED
@@ -447,8 +447,10 @@ class Files:
447
447
  >>> import json
448
448
  >>> import ipyvasp as ipv
449
449
  >>> files = ipv.Files(...)
450
- >>> files.mapf(lambda fp: json.load(fp),to_df=True)
451
- >>> files.mapf(lambda fp: [fp.readline() for _ in range(5)]) # read first five lines
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.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
452
454
  """
453
455
  if not mode in 'rb':
454
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.85
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,8 +1,8 @@
1
- ipyvasp/__init__.py,sha256=rlorju9arMtHw1QRYPljday-PyZWJdSCxg4lw3g6t0Q,1409
1
+ ipyvasp/__init__.py,sha256=mV4WksglB6ZwUV30NnWVBmWWjF7fSZ0dB-7eyhJrWtw,1423
2
2
  ipyvasp/__main__.py,sha256=eJV1TZSiT8mC_VqAeksNnBI2I8mKMiPkEIlwikbtOjI,216
3
3
  ipyvasp/_enplots.py,sha256=D38paN8zqZgluNAwmCwcocd7-_h_T0HTGolI1eBkDes,37484
4
4
  ipyvasp/_lattice.py,sha256=kOseNCIWt-VCnkhFQZEcsXhyNYobjfqNfAl3seXHiVU,105584
5
- ipyvasp/_version.py,sha256=Bps2JzgHJGe5i7Dl3w8-wED4yHznnswvaC7aMe75PJk,24
5
+ ipyvasp/_version.py,sha256=Iig1hTfzlTrB9madAdxIjYYENfEZu438RjihVQ7fLT0,24
6
6
  ipyvasp/bsdos.py,sha256=JvYvHLqMp3eVaJ0amD-9kxp7FehQIFq3WFUxsO5dj0Q,31794
7
7
  ipyvasp/cli.py,sha256=aWFEVhNmnW8eSOp5uh95JaDwLQ9K9nlCQcbnOSuhWgw,6844
8
8
  ipyvasp/evals_dataframe.py,sha256=-sqxK7LPV6sYDO_XXmZ80FznOaXTkVdbqJKKvTUtMak,20637
@@ -10,16 +10,16 @@ ipyvasp/lattice.py,sha256=VfyhmbpRHA3nePWUmaoMmCiAehby_VvDuDcp34OK3rA,33685
10
10
  ipyvasp/misc.py,sha256=gPA-71V_fuzyvinHR4P1kYMm90lJYdt24733pA5_4Kk,2340
11
11
  ipyvasp/potential.py,sha256=tzA73c5lkp6ahLSJchMrU043-QWaOV0nIOUA7VMmfKQ,11408
12
12
  ipyvasp/surface.py,sha256=MjE5oB0wW6Pca_C-xu8rN6OMH7lUEeNPNyM7Kz_Im-8,23766
13
- ipyvasp/utils.py,sha256=t64GSW0MzOjcFDJM1QoDvm9XVGnckq8TCAmu10NHu0o,14245
14
- ipyvasp/widgets.py,sha256=bbzX6EqKKdNMg19ScEG3_v6KXRDDzUMOZZgTEk1nacw,49001
13
+ ipyvasp/utils.py,sha256=yPKMaqNKw0uCBO_RE3XWrY7MH8cJ8Jtoj1bqAaNU70g,16649
14
+ ipyvasp/widgets.py,sha256=yNTCmVPQgnIOFLxB8FwG9UhsInIE-g2sFhlS9qcQ5IU,49228
15
15
  ipyvasp/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  ipyvasp/core/parser.py,sha256=if5DsBpDS7qCIlWsl6JD0ovRBk01h0CdKYa4vE9SSzw,38945
17
17
  ipyvasp/core/plot_toolkit.py,sha256=V-IQo7MrOhmNCGpWHIMtV04TmmubgFvGgH_yd4YmoX4,36158
18
18
  ipyvasp/core/serializer.py,sha256=v0ma4htirybtQo_wFhIEjkRoZMQk9ETDz85iloaq3YY,38427
19
19
  ipyvasp/core/spatial_toolkit.py,sha256=dXowREhiFzBvvr5f_bApzFhf8IzjH2E2Ix90oCBUetY,14885
20
- ipyvasp-0.9.85.dist-info/LICENSE,sha256=F3SO5RiAZOMfmMGf1KOuk2g_c4ObvuBJhd9iBLDgXoQ,1263
21
- ipyvasp-0.9.85.dist-info/METADATA,sha256=dw-KrLBBa9vtB8W0jGnfj5-TVCGwz90Trhv5hpDLb4E,2421
22
- ipyvasp-0.9.85.dist-info/WHEEL,sha256=iYlv5fX357PQyRT2o6tw1bN-YcKFFHKqB_LwHO5wP-g,110
23
- ipyvasp-0.9.85.dist-info/entry_points.txt,sha256=C7m0Sjmr14wFjflCkWXLzr5N6-cQj8uJC9n82mUtzt8,44
24
- ipyvasp-0.9.85.dist-info/top_level.txt,sha256=ftziWlMWu_1VpDP1sRTFrkfBnWxAi393HYDVu4wRhUk,8
25
- ipyvasp-0.9.85.dist-info/RECORD,,
20
+ ipyvasp-0.9.87.dist-info/LICENSE,sha256=F3SO5RiAZOMfmMGf1KOuk2g_c4ObvuBJhd9iBLDgXoQ,1263
21
+ ipyvasp-0.9.87.dist-info/METADATA,sha256=I_GtZBZi2Se6P0wNJsrZsme1D74507cjcbpScMdMIpM,2421
22
+ ipyvasp-0.9.87.dist-info/WHEEL,sha256=iYlv5fX357PQyRT2o6tw1bN-YcKFFHKqB_LwHO5wP-g,110
23
+ ipyvasp-0.9.87.dist-info/entry_points.txt,sha256=C7m0Sjmr14wFjflCkWXLzr5N6-cQj8uJC9n82mUtzt8,44
24
+ ipyvasp-0.9.87.dist-info/top_level.txt,sha256=ftziWlMWu_1VpDP1sRTFrkfBnWxAi393HYDVu4wRhUk,8
25
+ ipyvasp-0.9.87.dist-info/RECORD,,