Skip to content

Commit

Permalink
mnt: ensured super calls on Siles._setup, fixed __iter__
Browse files Browse the repository at this point in the history
Now __iter__ reads and returns the file, but will not close
the file-handle. This should be done by some other means.

Also moved the _completed variable into the _setup method
such that it is not a class variable.
  • Loading branch information
zerothi committed Oct 10, 2022
1 parent 2dde1d7 commit ac525ef
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions sisl/io/bigdft/ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class asciiSileBigDFT(SileBigDFT):

def _setup(self, *args, **kwargs):
""" Initialize for `asciiSileBigDFT` """
super()._setup(*args, **kwargs)
self._comment = ['#', '!']

@sile_fh_open()
Expand Down
1 change: 1 addition & 0 deletions sisl/io/gulp/got.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class gotSileGULP(SileGULP):

def _setup(self, *args, **kwargs):
""" Setup `gotSileGULP` after initialization """
super()._setup(*args, **kwargs)
self._keys = dict()
self.set_supercell_key('Cartesian lattice vectors')
self.set_geometry_key('Final fractional coordinates')
Expand Down
1 change: 1 addition & 0 deletions sisl/io/openmx/omx.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def file(self):

def _setup(self, *args, **kwargs):
""" Setup the `omxSileOpenMX` after initialization """
super()._setup(*args, **kwargs)
# These are the comments
self._comment = ['#']

Expand Down
1 change: 1 addition & 0 deletions sisl/io/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class pdbSile(Sile):

def _setup(self, *args, **kwargs):
""" Instantiate counters """
super()._setup(*args, **kwargs)
self._model = 1
self._serial = 1
self._wrote_header = False
Expand Down
1 change: 1 addition & 0 deletions sisl/io/siesta/fdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class fdfSileSiesta(SileSiesta):

def _setup(self, *args, **kwargs):
""" Setup the `fdfSileSiesta` after initialization """
super()._setup(*args, **kwargs)
self._comment = ['#', '!', ';']

# List of parent file-handles used while reading
Expand Down
10 changes: 7 additions & 3 deletions sisl/io/siesta/out.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ class outSileSiesta(SileSiesta):
This enables reading the output quantities from the Siesta output.
"""
_completed = None

def readline(self):
line = super().readline()
def _setup(self, *args, **kwargs):
""" Ensure the class has a _completed tag """
super()._setup(*args, **kwargs)
self._completed = None

def readline(self, *args, **kwargs):
line = super().readline(*args, **kwargs)
if 'Job completed' in line:
self._completed = True
return line
Expand Down
7 changes: 5 additions & 2 deletions sisl/io/sile.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,11 @@ def line_has_keys(line, keys, case=True):
return found

def __iter__(self):
r""" Iterator for file """
yield from self.fh
""" Reading the entire content, without regarding comments """
l = self.readline(comment=True)
while l:
yield l
l = self.readline(comment=True)

def readline(self, comment=False):
r""" Reads the next line of the file """
Expand Down
1 change: 1 addition & 0 deletions sisl/io/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class tableSile(Sile):

def _setup(self, *args, **kwargs):
""" Setup the `tableSile` after initialization """
super()._setup(*args, **kwargs)
self._comment = ['#']

@sile_fh_open()
Expand Down
1 change: 1 addition & 0 deletions sisl/io/tbtrans/sile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SileCDFTBtrans(SileCDF):

# all netcdf output should not be masked
def _setup(self, *args, **kwargs):
super()._setup(*args, **kwargs)
# all NetCDF routines actually returns masked arrays
# this is to prevent TBtrans CDF files from doing this.
if hasattr(self, "fh"):
Expand Down
1 change: 1 addition & 0 deletions sisl/io/vasp/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class carSileVASP(SileVASP):

def _setup(self, *args, **kwargs):
""" Setup the `carSile` after initialization """
super()._setup(*args, **kwargs)
self._scale = 1.

@sile_fh_open()
Expand Down
10 changes: 7 additions & 3 deletions sisl/io/vasp/out.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
@set_module("sisl.io.vasp")
class outSileVASP(SileVASP):
""" Output file from VASP """
_completed = None

def readline(self):
line = super().readline()
def _setup(self, *args, **kwargs):
""" Ensure the class has a _completed tag """
super()._setup(*args, **kwargs)
self._completed = None

def readline(self, *args, **kwargs):
line = super().readline(*args, **kwargs)
if "General timing and accounting" in line:
self._completed = True
return line
Expand Down
1 change: 1 addition & 0 deletions sisl/io/wannier90/seedname.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class winSileWannier90(SileWannier90):

def _setup(self, *args, **kwargs):
""" Setup `winSileWannier90` after initialization """
super()._setup(*args, **kwargs)
self._comment = ['!', '#']
self._seed = str(self.file).replace('.win', '')

Expand Down
1 change: 1 addition & 0 deletions sisl/io/xsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class xsfSile(Sile):

def _setup(self, *args, **kwargs):
""" Setup the `xsfSile` after initialization """
super()._setup(*args, **kwargs)
self._comment = ['#']

def _write_key(self, key):
Expand Down

0 comments on commit ac525ef

Please sign in to comment.