pyspinw.interface#

Helper functions for python interface

Functions

axis_anisotropies(sites, a[, axis, name])

Create anisotropy objects with magnitude a in direction axis for each site

filter(direction[, perpendicular, ...])

Create a filter for directions (helper method for exchanges)

generate_exchanges(sites, unit_cell, ...)

Automatically creates a list of exchanges

generate_helical_structure(unit_cell, ...[, ...])

Creates a helical structure with a propagation vector and plane normal

generate_sites(positions[, spins, names])

Create a list of lattice sites

generate_structure(unit_cell, positions, spins)

Creates a magnetic structure from a list of positions and spins

get_spacegroup(search_string)

Get a spacegroup by name or symmetry operations

helical_supercell(perpendicular, propagation)

Generate a helical supercell

load_tb2j(inputfile)

Loads a TB2J output file and converts to a SpinW Hamiltonian object

matrix_anisotropies(sites, matrix[, name])

Create anisotropy objects specified by a matrix, the same for each site

propagation_vectors(directions[, phases, ...])

Create list of propagation vectors

rotation_supercell(directions, axes[, ...])

Create a supercell that rotates spins as we move along the propagation vector

summation_supercell(directions[, phases, ...])

Create a supercell based on the propagation vectors and partial spins

view(hamiltonian)

Show the current Hamiltonian in the viewer

pyspinw.interface.axis_anisotropies(sites: list[Site] | Structure, a: float, axis: ArrayLike = [0, 0, 1], name: str = '')#

Create anisotropy objects with magnitude a in direction axis for each site

pyspinw.interface.filter(direction: ArrayLike, perpendicular: bool = False, symmetric: bool = False, max_dev_angle_deg: float = 0.01) → DirectionalityFilter#

Create a filter for directions (helper method for exchanges)

Parameters:
  • direction – If not perpendicular, allowed direction of exchange If perpendicular, normal to plane containing exchange

  • perpendicular – Constrain to a line (perpendicular=False) or a plane (perpendicular=True)

  • symmetric – In the not perpendicular case, symmetric True generates exchanges in both directions

  • max_dev_angle_deg – Angular tolerance for the direction/normal in degrees

Returns:

A DirectionalityFilter object that can be used to select exchanges in particular directions

pyspinw.interface.generate_exchanges(sites: list[Site] | Structure, unit_cell: UnitCell | None = None, exchange_type: type[Exchange] = <class 'pyspinw.exchange.HeisenbergExchange'>, bond: int = 0, max_distance: float = 0.0, min_distance: float = 0.0, direction_filter: DirectionalityFilter | None = None, max_order: int | None = None, j: float | None = None, j_x: float | None = None, j_y: float | None = None, j_xy: float | None = None, j_z: float | None = None, d_x: float | None = None, d_y: float | None = None, d_z: float | None = None, exchange_parameters: dict | None = None, naming_pattern: str | None = None, color: tuple[float, float, float] | None=None)#

Automatically creates a list of exchanges

Parameters:
  • sites – required List of sites to make exchanges between or a Structure object

  • unit_cell – Unit cell (needed if first argument is a list of sites)

  • exchange_type – Type of exchange (defaults to HeisenbergExchange)

  • bond – The bond index (If this is given the _distance parameters are ignored)

  • max_distance – Maximum Cartesian distance (in Angstrom) at which exchanges are made

  • min_distance – Minimum Cartesian distance (in Angstrom) at which exchanges are made

  • direction_filter – Supply a DirectionalityFilter object (e.g. using filter()) to only create exchanges in certain directions

  • max_order – Maximum “order” of exchanges

  • j – Constant for scalar valued Heisenberg exchanges (only needed for Heisenberg)

  • j_x – Constant for x component of Heisenberg-like exchanges (only needed for Diagonal)

  • j_y – Constant for y component of Heisenberg-like exchanges (only needed for Diagonal)

  • j_z – Constant for z component of Heisenberg-like exchanges (only needed for Diagonal, Ising and XY)

  • j_xy – Constant for x and y components of Heisenberg-like exchanges (only needed for XY and XXZ)

  • d_x – Constant for x component of Dzyaloshinskii-Moriya exchange (DM)

  • d_y – Constant for y component of Dzyaloshinskii-Moriya exchange (DM)

  • d_z – Constant for z component of Dzyaloshinskii-Moriya exchange (DM)

  • exchange_parameters – Parameters can be supplied in a dictionary instead

  • naming_pattern – String used to assign names to exchanges, see apply_naming_convention()

  • color – Colour to draw the exchange with

Returns:

list of exchanges

pyspinw.interface.generate_helical_structure(unit_cell: UnitCell, positions: ArrayLike, spins: ArrayLike, perpendicular: ArrayLike, propagation_vector: ArrayLike, names: list[str] | None = None, magnitudes: ArrayLike | None = None, positions_unit: CoordsUnits | str = 'lu', spins_unit: CoordsUnits | str = 'xyz') → Structure#

Creates a helical structure with a propagation vector and plane normal

Parameters:
  • unit_cell – a UnitCell object

  • positions – positions of the sites

  • spins – spins of the sites

  • perpendicular – vector perpendicular to helix plane of rotation

  • propagation_vector – the propagation vector

  • names – (optional) a list of names for sites

  • magnitudes – (optional) a list of spin magnitudes (spin length S) If not specified, the norm of the spins vectors will be used as the spin length

  • positions_units – the units for atomic positions; either ‘lu’ or ‘xyz’ (default: ‘lu’, lattice units)

  • spins_units – the units for the magnetic spin directions; either ‘lu’ or ‘xyz’ (default: ‘xyz’, Cartesian axis with x||a)

  • convert_to_cell_with – (optional) Must be specified if positions_units is not ‘lu’ and spins_units is not ‘xyz’ and allows conversion from those units to the default used in LatticeSite. (see spin_fractional_to_cartesian() and spin_cartesian_to_fractional())

pyspinw.interface.generate_sites(positions: ArrayLike, spins: ArrayLike | None = None, names: list[str] | None = None) → list[Site]#

Create a list of lattice sites

Parameters:
  • positions – positions of the sites

  • spins – spins of the sites, if not specified, they will be set to zero

  • names – (optional) a list of names for sites

pyspinw.interface.generate_structure(unit_cell: UnitCell, positions: ArrayLike, spins: ArrayLike, propagation_vectors: ArrayLike | None = None, names: list[str] | None = None, magnitudes: ArrayLike | None = None, positions_unit: CoordsUnits | str = 'lu', spins_unit: CoordsUnits | str = 'xyz') → Structure#

Creates a magnetic structure from a list of positions and spins

Parameters:
  • unit_cell – a UnitCell object

  • positions – positions of the sites

  • spins – spins of the sites

  • perpendicular – vector perpendicular to helix plane of rotation

  • propagation_vectors – the propagation vector(s)

  • names – (optional) a list of names for sites

  • magnitudes – (optional) a list of spin magnitudes (spin length S) If not specified, the norm of the spins vectors will be used as the spin length

  • positions_units – the units for atomic positions; either ‘lu’ or ‘xyz’ (default: ‘lu’, lattice units)

  • spins_units – the units for the magnetic spin directions; either ‘lu’ or ‘xyz’ (default: ‘xyz’, Cartesian axis with x||a)

  • convert_to_cell_with – (optional) Must be specified if positions_units is not ‘lu’ and spins_units is not ‘xyz’ and allows conversion from those units to the default used in LatticeSite. (see spin_fractional_to_cartesian() and spin_cartesian_to_fractional())

pyspinw.interface.get_spacegroup(search_string: str)#

Get a spacegroup by name or symmetry operations

The searches are whitespace and case insensitive.

Examples

The following are equivalent:

spacegroup(“P1”) spacegroup(“p1”) spacegroup(“x,y,z”)

The following are equivalent:

spacegroup(“P-1”) spacegroup(“p-1”) spacegroup(“x,y,z; -x,-y,-z”)

Spacegroups with multiple settings sometimes need to have it specified, but some don’t:

spacegroup(“R3”) fails spacegroup(“R3H”) hexagonal setting spacegroup(“R3R”) rhombohedral setting

spacegroup(“B2/m”) this setting of C2/m spacegroup(“B 1 2/m 1”) another way for the same group

spacegroup(“P 4/n 2/b 2/m : 1”) setting 1 spacegroup(“P 4/n 2/b 2/m : 1”) setting 2

pyspinw.interface.helical_supercell(perpendicular: ArrayLike, propagation: ArrayLike)#

Generate a helical supercell

Parameters:
  • perpendicular – (3-vector) Direction perpendicular to propagation vector, needed to specify “start” cell

  • propagation – (3-vector) Propagation vector

pyspinw.interface.load_tb2j(inputfile)#

Loads a TB2J output file and converts to a SpinW Hamiltonian object

pyspinw.interface.matrix_anisotropies(sites: list[Site] | Structure, matrix: ArrayLike, name: str = '')#

Create anisotropy objects specified by a matrix, the same for each site

pyspinw.interface.propagation_vectors(directions: ndarray, phases: ndarray | None = None, incommensurate: bool = False) → list[PropagationVector]#

Create list of propagation vectors

Parameters:
  • directions – n-by-3 matrix of directions (in lattice units)

  • phases – n vector of phases

  • incommensurate – Whether or not to set them to be incommensuate

pyspinw.interface.rotation_supercell(directions: ArrayLike, axes: ArrayLike, phases: ArrayLike | None = None, scaling: tuple[int, int, int] = (1, 1, 1))#

Create a supercell that rotates spins as we move along the propagation vector

Parameters:
  • directions – propagation vector directions

  • axes – rotation axes for each propagation vector, or if only a single axis is specified, apply it to all of them

  • phases – Phases of the propagation vectors, 0.0 means starting with the spin as specified on the site

  • scaling – Make a larger supercell by tiling the result this many times in each axis

pyspinw.interface.summation_supercell(directions: ndarray, phases: ndarray | None = None, scaling: tuple[int, int, int] = (1, 1, 1))#

Create a supercell based on the propagation vectors and partial spins

i.e. $m = sum_j mu_j exp(2 pi i d_j.r + phi_j)$

Parameters:
  • directions – propagation vector directions

  • phases – Phases of the propagation vectors, 0.0 means starting with the spin as specified on the site

  • scaling – Make a larger supercell by tiling the result this many times in each axis

pyspinw.interface.view(hamiltonian: Hamiltonian)#

Show the current Hamiltonian in the viewer