sisl.io.sile module¶
-
sisl.io.sile.
add_sile
(ending, cls, case=True, gzip=False, _parent_cls=None)[source]¶ Public for attaching lookup tables for allowing users to attach files for the IOSile function call
Parameters: ending : str
The file-name ending, it can be several file endings (.TBT.nc)
cls :
BaseSile
childAn object that is associated with the respective file. It must be inherited from a
BaseSile
.case : bool, (True)
Whether case sensitivity is applicable for determining file.
gzip : bool, (False)
Whether files with
.gz
endings can be read. This option should only be given to files with ASCII text output. It will automatically call:>>> add_sile(ending+'.gz',...,gzip=False)
to add the gzipped file to the list of possible files.
-
sisl.io.sile.
get_sile_class
(file, *args, **kwargs)[source]¶ Guess the
Sile
class corresponding to the input file and return the classParameters: file : str
the file to be quried for a correct
Sile
object. This file name may contain {<class-name>} which setscls
in casecls
is not set. For instance:water.xyz
will return an
XYZSile
.cls : class
In case there are several files with similar file-suffixes you may query the exact base-class that should be chosen. If there are several ``Sile``s with similar file-endings this function returns a random one.
-
sisl.io.sile.
get_sile
(file, *args, **kwargs)[source]¶ Guess the
Sile
corresponding to the input file and return an open object of the correspondingSile
Parameters: file : str
cls : class
In case there are several files with similar file-suffixes you may query the exact base-class that should be chosen. If there are several `Sile`s with similar file-endings this function returns a random one.
-
sisl.io.sile.
get_siles
(attrs=[None])[source]¶ Returns all siles with a specific attribute (or all)
Parameters: attrs : list of attribute names
limits the returned sile-objects to those that have the given attributes
hasattr(sile, attrs)
-
class
sisl.io.sile.
BaseSile
[source]¶ Bases:
object
Base class for the Siles
Methods
ArgumentParser
([parser])Returns the arguments that may be available for this Sile ArgumentParser_out
([parser])Appends additional arguments based on the output of the file read
(*args, **kwargs)Generic read method which should be overloaded in child-classes read_es
(*args, **kwargs)Deprecated function which is superseeded by read_hamiltonian
read_geom
(*args, **kwargs)Deprecated function which is superseeded by read_geometry
read_sc
(*args, **kwargs)Deprecated function which is superseeded by read_supercell
write
(*args, **kwargs)Generic write method which should be overloaded in child-classes write_es
(*args, **kwargs)Deprecated function which is superseeded by write_hamiltonian
write_geom
(*args, **kwargs)Deprecated function which is superseeded by write_geometry
write_sc
(*args, **kwargs)Deprecated function which is superseeded by write_supercell
-
ArgumentParser
(parser=None, *args, **kwargs)[source]¶ Returns the arguments that may be available for this Sile
Parameters: parser: ArgumentParser
the argument parser to add the arguments to.
-
ArgumentParser_out
(parser=None, *args, **kwargs)[source]¶ Appends additional arguments based on the output of the file
Parameters: parser: ArgumentParser
the argument parser to add the arguments to.
-
read
(*args, **kwargs)[source]¶ Generic read method which should be overloaded in child-classes
Parameters: **kwargs :
keyword arguments will try and search for the attribute
read_
and call it with the remaining**kwargs
as arguments.
-
read_es
(*args, **kwargs)[source]¶ Deprecated function which is superseeded by
read_hamiltonian
-
read_geom
(*args, **kwargs)[source]¶ Deprecated function which is superseeded by
read_geometry
-
read_sc
(*args, **kwargs)[source]¶ Deprecated function which is superseeded by
read_supercell
-
write
(*args, **kwargs)[source]¶ Generic write method which should be overloaded in child-classes
Parameters: **kwargs :
keyword arguments will try and search for the attribute
write_
and call it with the remaining**kwargs
as arguments.
-
write_es
(*args, **kwargs)[source]¶ Deprecated function which is superseeded by
write_hamiltonian
-
write_geom
(*args, **kwargs)[source]¶ Deprecated function which is superseeded by
write_geometry
-
-
class
sisl.io.sile.
Sile
(filename, mode='r', comment='#')[source]¶ Bases:
sisl.io.sile.BaseSile
Class to contain a file with easy access
Attributes
file
File of the current Sile
Methods
ArgumentParser
([parser])Returns the arguments that may be available for this Sile ArgumentParser_out
([parser])Appends additional arguments based on the output of the file is_keys
(keys)Returns true if isinstance(keys,(list,np.ndarray))
key2case
(key, case)Converts str/list of keywords to proper case keys2case
(keys, case)Converts str/list of keywords to proper case line_has_key
(line, key[, case])line_has_keys
(line, keys[, case])read
(*args, **kwargs)Generic read method which should be overloaded in child-classes read_es
(*args, **kwargs)Deprecated function which is superseeded by read_hamiltonian
read_geom
(*args, **kwargs)Deprecated function which is superseeded by read_geometry
read_sc
(*args, **kwargs)Deprecated function which is superseeded by read_supercell
readline
([comment])Reads the next line of the file step_either
(keywords[, case])Steps the file-handle until the keyword is found in the input step_to
(keywords[, case, reread])Steps the file-handle until the keyword is found in the input write
(*args, **kwargs)Generic write method which should be overloaded in child-classes write_es
(*args, **kwargs)Deprecated function which is superseeded by write_hamiltonian
write_geom
(*args, **kwargs)Deprecated function which is superseeded by write_geometry
write_sc
(*args, **kwargs)Deprecated function which is superseeded by write_supercell
-
class
sisl.io.sile.
SileCDF
(filename, mode='r', lvl=0, access=1, _open=True)[source]¶ Bases:
sisl.io.sile.BaseSile
Class to contain a file with easy access The file format for this file is the NetCDF file format
Attributes
file
Filename of the current Sile
Methods
ArgumentParser
([parser])Returns the arguments that may be available for this Sile ArgumentParser_out
([parser])Appends additional arguments based on the output of the file isDataset
(obj)Return true if obj
is an instance of the NetCDF4Dataset
typeisDimension
(obj)Return true if obj
is an instance of the NetCDF4Dimension
typeisGroup
(obj)Return true if obj
is an instance of the NetCDF4Group
typeisRoot
(obj)Return true if obj
is an instance of the NetCDF4Dataset
typeisVariable
(obj)Return true if obj
is an instance of the NetCDF4Variable
typeiter
([group, dimension, variable, levels, root])Iterator on all groups, variables and dimensions. read
(*args, **kwargs)Generic read method which should be overloaded in child-classes read_es
(*args, **kwargs)Deprecated function which is superseeded by read_hamiltonian
read_geom
(*args, **kwargs)Deprecated function which is superseeded by read_geometry
read_sc
(*args, **kwargs)Deprecated function which is superseeded by read_supercell
write
(*args, **kwargs)Generic write method which should be overloaded in child-classes write_es
(*args, **kwargs)Deprecated function which is superseeded by write_hamiltonian
write_geom
(*args, **kwargs)Deprecated function which is superseeded by write_geometry
write_sc
(*args, **kwargs)Deprecated function which is superseeded by write_supercell
Creates/Opens a SileCDF
Opens a SileCDF with
mode
and compression levellvl
. Ifmode
is in read-mode (r) the compression level is ignored.The final
access
parameter sets how the file should be open and subsequently accessed.- means direct file access for every variable read
- means stores certain variables in the object.
Attributes
file
Filename of the current Sile
Methods
ArgumentParser
([parser])Returns the arguments that may be available for this Sile ArgumentParser_out
([parser])Appends additional arguments based on the output of the file isDataset
(obj)Return true if obj
is an instance of the NetCDF4Dataset
typeisDimension
(obj)Return true if obj
is an instance of the NetCDF4Dimension
typeisGroup
(obj)Return true if obj
is an instance of the NetCDF4Group
typeisRoot
(obj)Return true if obj
is an instance of the NetCDF4Dataset
typeisVariable
(obj)Return true if obj
is an instance of the NetCDF4Variable
typeiter
([group, dimension, variable, levels, root])Iterator on all groups, variables and dimensions. read
(*args, **kwargs)Generic read method which should be overloaded in child-classes read_es
(*args, **kwargs)Deprecated function which is superseeded by read_hamiltonian
read_geom
(*args, **kwargs)Deprecated function which is superseeded by read_geometry
read_sc
(*args, **kwargs)Deprecated function which is superseeded by read_supercell
write
(*args, **kwargs)Generic write method which should be overloaded in child-classes write_es
(*args, **kwargs)Deprecated function which is superseeded by write_hamiltonian
write_geom
(*args, **kwargs)Deprecated function which is superseeded by write_geometry
write_sc
(*args, **kwargs)Deprecated function which is superseeded by write_supercell
-
classmethod
isDataset
(obj)[source]¶ Return true if
obj
is an instance of the NetCDF4Dataset
typeThis is just a wrapper for
isinstance(obj, netCDF4.Dataset)
.
-
classmethod
isDimension
(obj)[source]¶ Return true if
obj
is an instance of the NetCDF4Dimension
typeThis is just a wrapper for
isinstance(obj, netCDF4.Dimension)
.
-
classmethod
isGroup
(obj)[source]¶ Return true if
obj
is an instance of the NetCDF4Group
typeThis is just a wrapper for
isinstance(obj, netCDF4.Group)
.
-
classmethod
isRoot
(obj)¶ Return true if
obj
is an instance of the NetCDF4Dataset
typeThis is just a wrapper for
isinstance(obj, netCDF4.Dataset)
.
-
classmethod
isVariable
(obj)[source]¶ Return true if
obj
is an instance of the NetCDF4Variable
typeThis is just a wrapper for
isinstance(obj, netCDF4.Variable)
.
-
iter
(group=True, dimension=True, variable=True, levels=-1, root=None)[source]¶ Iterator on all groups, variables and dimensions.
This iterator iterates through all groups, variables and dimensions in the
Dataset
The generator sequence will _always_ be:
- Group
- Dimensions in group
- Variables in group
As the dimensions are generated before the variables it is possible to copy groups, dimensions, and then variables such that one always ensures correct dependencies in the generation of a new
SileCDF
.Parameters: group :
bool
(True
)whether the iterator yields
Group
instancesdimension :
bool
(True
)whether the iterator yields
Dimension
instancesvariable :
bool
(True
)whether the iterator yields
Variable
instanceslevels :
int
(-1
)number of levels to traverse, with respect to
root
variable, i.e. number of sub-groups this iterator will return.root :
str
(None
)the base root to start iterating from.
Examples
Script for looping and checking each instance. >>> for gv in self.iter(): >>> if self.isGroup(gv): >>> # is group >>> elif self.isDimension(gv): >>> # is dimension >>> elif self.isVariable(gv): >>> # is variable
-
class
sisl.io.sile.
SileBin
(filename, mode='r')[source]¶ Bases:
sisl.io.sile.BaseSile
Class to contain a file with easy access The file format for this file is a binary format.
Attributes
file
File of the current Sile
Methods
ArgumentParser
([parser])Returns the arguments that may be available for this Sile ArgumentParser_out
([parser])Appends additional arguments based on the output of the file read
(*args, **kwargs)Generic read method which should be overloaded in child-classes read_es
(*args, **kwargs)Deprecated function which is superseeded by read_hamiltonian
read_geom
(*args, **kwargs)Deprecated function which is superseeded by read_geometry
read_sc
(*args, **kwargs)Deprecated function which is superseeded by read_supercell
write
(*args, **kwargs)Generic write method which should be overloaded in child-classes write_es
(*args, **kwargs)Deprecated function which is superseeded by write_hamiltonian
write_geom
(*args, **kwargs)Deprecated function which is superseeded by write_geometry
write_sc
(*args, **kwargs)Deprecated function which is superseeded by write_supercell
Creates/Opens a SileBin
Opens a SileBin with
mode
(b). Ifmode
is in read-mode (r).Attributes
file
File of the current Sile
Methods
ArgumentParser
([parser])Returns the arguments that may be available for this Sile ArgumentParser_out
([parser])Appends additional arguments based on the output of the file read
(*args, **kwargs)Generic read method which should be overloaded in child-classes read_es
(*args, **kwargs)Deprecated function which is superseeded by read_hamiltonian
read_geom
(*args, **kwargs)Deprecated function which is superseeded by read_geometry
read_sc
(*args, **kwargs)Deprecated function which is superseeded by read_supercell
write
(*args, **kwargs)Generic write method which should be overloaded in child-classes write_es
(*args, **kwargs)Deprecated function which is superseeded by write_hamiltonian
write_geom
(*args, **kwargs)Deprecated function which is superseeded by write_geometry
write_sc
(*args, **kwargs)Deprecated function which is superseeded by write_supercell
-
exception
sisl.io.sile.
SileError
(value, obj=None)[source]¶ Bases:
exceptions.IOError
Define an error object related to the Sile objects