sisl.io.xsfSile
- class sisl.io.xsfSile(filename, *args, **kwargs)
Bases:
Sile
XSF file for XCrySDen
When creating an XSF file one must denote how many geometries to write out. It is also necessary to use the xsf in a context manager, otherwise it will overwrite itself repeatedly.
>>> with xsfSile('file.xsf', 'w', steps=100) as xsf: ... for i in range(100): ... xsf.write_geometry(geom)
- Parameters:
steps (
int
, optional) – number of steps the xsf file contains. Defaults to 1
Plotting
Plotting functions for the
xsfSile
class.plot.geometry
([lattice, data_atoms, ...])Calls
read_geometry
and creates aGeometryPlot
from its output.Methods
base_directory
([relative_to])Retrieve the base directory of the file, relative to the path relative_to
close
()dir_file
([filename, filename_base])File of the current
Sile
read
(*args, **kwargs)Generic read method which should be overloaded in child-classes
Basis set (
Atoms
) contained in fileread_geometry
([lattice, atoms, ret_data])Geometry contained in file, and optionally the associated data
Lattice contained in file
write
(*args, **kwargs)Generic write method which should be overloaded in child-classes
write_geometry
(geometry[, fmt, data])Writes the geometry to the contained file
write_grid
(*args, **kwargs)Store grid(s) data to an XSF file
write_lattice
(lattice[, fmt])Writes the supercell to the contained file
Attributes
File of the current
Sile
File of the current
Sile
- base_directory(relative_to='.')
Retrieve the base directory of the file, relative to the path relative_to
- close()
- plot.geometry(lattice: Lattice | None = None, data_atoms=None, ret_data: bool = False, *, axes: Axes = ['x', 'y', 'z'], atoms: AtomsIndex = None, atoms_style: Sequence[AtomsStyleSpec] = [], atoms_scale: float = 1.0, atoms_colorscale: Colorscale | None = None, drawing_mode: Literal['scatter', 'balls', None] = None, bind_bonds_to_ats: bool = True, points_per_bond: int = 20, bonds_style: StyleSpec = {}, bonds_scale: float = 1.0, bonds_colorscale: Colorscale | None = None, show_atoms: bool = True, show_bonds: bool = True, show_cell: Literal['box', 'axes', False] = 'box', cell_style: StyleSpec = {}, nsc: tuple[int, int, int] = (1, 1, 1), atoms_ndim_scale: tuple[float, float, float] = (16, 16, 1), bonds_ndim_scale: tuple[float, float, float] = (1, 1, 10), dataaxis_1d: np.ndarray | Callable | None = None, arrows: Sequence[AtomArrowSpec] = (), backend='plotly') GeometryPlot
Calls
read_geometry
and creates aGeometryPlot
from its output.- Parameters:
lattice – the supercell in case the lattice vectors are not present in the current block.
atoms (
Atoms
, optional) – atomic species used regardless of the contained atomic speciesret_data – in case the the file has auxiliary data, return that as well.
axes – The axes to project the geometry to.
atoms – The atoms to plot. If None, all atoms are plotted.
atoms_style – List of style specifications for the atoms. See the showcase notebooks for examples.
atoms_scale – Scaling factor for the size of all atoms.
atoms_colorscale – Colorscale to use for the atoms in case the color attribute is an array of values. If None, the default colorscale is used for each backend.
drawing_mode – The method used to draw the atoms.
bind_bonds_to_ats – Whether to display only bonds between atoms that are being displayed.
points_per_bond – When the points are drawn using points instead of lines (e.g. in some frameworks to draw multicolor bonds), the number of points used per bond.
bonds_style – Style specification for the bonds. See the showcase notebooks for examples.
bonds_scale – Scaling factor for the width of all bonds.
bonds_colorscale – Colorscale to use for the bonds in case the color attribute is an array of values. If None, the default colorscale is used for each backend.
show_atoms – Whether to display the atoms.
show_bonds – Whether to display the bonds.
show_cell – Mode to display the cell. If False, the cell is not displayed.
cell_style – Style specification for the cell. See the showcase notebooks for examples.
nsc – Number of unit cells to display in each direction.
atoms_ndim_scale – Scaling factor for the size of the atoms for different dimensionalities (1D, 2D, 3D).
bonds_ndim_scale – Scaling factor for the width of the bonds for different dimensionalities (1D, 2D, 3D).
dataaxis_1d – Only meaningful for 1D plots. The data to plot on the Y axis.
arrows – List of arrow specifications to display. See the showcase notebooks for examples.
backend – The backend to use to generate the figure.
See also
GeometryPlot
The plot class used to generate the plot.
read_geometry
The method called to get the data.
- read(*args, **kwargs)
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_basis() Atoms [source]
Basis set (
Atoms
) contained in fileNotes
This method defaults to return the first item(s).
This method enables slicing for handling multiple values (see
[...|default]
).This is an optional handler enabling returning multiple elements if
read_basis[...|0]
allows this.>>> single = obj.read_basis() # returns the default entry of read_basis[...|0]
To retrieve the first two elements that
read_basis
will return>>> first_two = obj.read_basis[:2]()
Retrieving the last two is done equivalently:
>>> last_two = obj.read_basis[-2:]()
While one can store the sliced function
tmp = obj.read_basis[:]
one will loose the slice after each call.
- read_geometry(lattice: Lattice | None = None, atoms=None, ret_data: bool = False) Geometry [source]
Geometry contained in file, and optionally the associated data
- Parameters:
lattice – the supercell in case the lattice vectors are not present in the current block.
atoms (
Atoms
, optional) – atomic species used regardless of the contained atomic speciesret_data – in case the the file has auxiliary data, return that as well.
Notes
This method defaults to return the first item(s).
This method enables slicing for handling multiple values (see
[...|default]
).This is an optional handler enabling returning multiple elements if
read_geometry[...|0]
allows this.>>> single = obj.read_geometry() # returns the default entry of read_geometry[...|0]
To retrieve the first two elements that
read_geometry
will return>>> first_two = obj.read_geometry[:2]()
Retrieving the last two is done equivalently:
>>> last_two = obj.read_geometry[-2:]()
While one can store the sliced function
tmp = obj.read_geometry[:]
one will loose the slice after each call.
- read_lattice() Lattice [source]
Lattice contained in file
Notes
This method defaults to return the first item(s).
This method enables slicing for handling multiple values (see
[...|default]
).This is an optional handler enabling returning multiple elements if
read_lattice[...|0]
allows this.>>> single = obj.read_lattice() # returns the default entry of read_lattice[...|0]
To retrieve the first two elements that
read_lattice
will return>>> first_two = obj.read_lattice[:2]()
Retrieving the last two is done equivalently:
>>> last_two = obj.read_lattice[-2:]()
While one can store the sliced function
tmp = obj.read_lattice[:]
one will loose the slice after each call.
- write(*args, **kwargs)
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_geometry(geometry: Geometry, fmt: str = '.8f', data=None)[source]
Writes the geometry to the contained file
- Parameters:
geometry – the geometry to be written
fmt – used format for the precision of the data
data (
(geometry.na
,3)
, optional) – auxiliary data associated with the geometry to be saved along side. Internally in XCrySDen this data is named Forces
- write_grid(*args, **kwargs)[source]
Store grid(s) data to an XSF file
Examples
>>> g1 = Grid(0.1, lattice=2.) >>> g2 = Grid(0.1, lattice=2.) >>> get_sile('output.xsf', 'w').write_grid(g1, g2)
- Parameters:
*args (
Grid
) – a list of data-grids to be written to the XSF file. Each argument gets the field name?grid_<>
where <> starts with the integer 0, and ? isreal_
/imag_
for complex valued grids.geometry (
Geometry
, optional) – the geometry stored in the file, defaults toargs[0].geometry
fmt (
str
, optional) – floating point format for data (.5e)buffersize (
int
, optional) – size of the buffer while writing the data, (6144)