zerothi / sisl

Electronic structure Python package for post analysis and large scale tight-binding DFT/NEGF calculations
https://zerothi.github.io/sisl
Mozilla Public License 2.0
177 stars 57 forks source link

Siles and opening them while retaining position #587

Open zerothi opened 1 year ago

zerothi commented 1 year ago

Describe the feature Currently nested openings of files are cumbersome.

It would be great if the (ascii) siles allows to step arbitrarily in the files.

Something like:

with sile:
    A1 = sile.read_*()
    with sile:
         B1 = sile.read_*()
         B2 = sile.read_*()
    A2 = sile.read_*()
assert A1 == B1
assert A2 == B2

it would ease lots of the functionality around, and especially output files where other settings in the files determine whether we can find certain stuff in them. (settings etc.)

zerothi commented 1 year ago

In this regard it might be useful to remove the _line and use some kind of stack for the positions at each with invocation.

stack = Stack()
stack.push(self.fh.tell())
self.fh.seek(0)
self.fh.seek(stack.pop())

or similar.