get_sile
- sisl.io.get_sile(file, *args, **kwargs)
Retrieve an object from the global lookup table via filename and the extension
Internally this is roughly equivalent to
get_sile_class(...)()
.When the file suffix is not recognized and you know which file-type it is it is recommended to get the file class from the known suffixes and use that class to construct the file object, see examples.
- Parameters:
file (
str
orpathlib.Path
) – the file to be quried for a correctSile
object. This file name may contain {<class-name>} which sets cls in case cls is not set. For instanceget_sile("water.dat{xyzSile}")
will read the filewater.dat
using thexyzSile
class.cls (
class
) – In case there are several files with similar file-suffixes you may query the exact base-less that should be chosen. If there are several files with similar file-endings this function returns a random one.
Examples
A file named
water.dat
contains the xyz-coordinates as thexyzSile
. One can forcefully get the sile by:>>> obj = get_sile("water.dat{xyzSile}")
Alternatively one can query the xyz file and use that class reference in future instantiations. This ensures a future proof method without explicitly typing the Sile object.
>>> cls = get_sile_class("anyfile.xyz") >>> obj = cls("water.dat") >>> another_xyz = cls("water2.dat")
To narrow the search one can clarify whether it should start or end with a string:
>>> cls = get_sile_class("water.dat{startswith=xyz}")