SpinW documentation¶
Introduction to SpinW¶
SpinW is a Matlab library that can solve spin Hamiltonians using mean field theory and linear spin wave theory. It is optimised for spin wave calculation on complex lattices that one often encounter experimentally.
Model¶
In short SpinW can solve the following spin Hamiltonian using classical and quasi classical numerical methods:
where \(\mathbf{s}_i\) are spin vector operators, \(J_{ij}\) are 3x3 exchange matrices describing coupling between spins, \(A_{ij}\) are 3x3 single ion anisotropy matrices, \(\mathbf{B}\) is external magnetic field, \(g_i\) are the g-tensors with 3x3 elements and \(\mu_B\) is the Bohr-magneton. The 3x3 matrices are necessary to include all possible anisotropic and antisymmetric interactions.
Features¶
Crystal structures¶
- definition of crystal lattice with arbitrary unit cell, using symmetry operators
- definition of non-magnetic atoms and magnetic atoms with arbitrary moment size
- publication quality plotting of crystal structures (atoms, labels, axes, surrounding polyhedron, anisotropy ellipsoids, DM vector, etc.)
Magnetic structures¶
- definition of 1D, 2D and 3D magnetic structures
- representation of single-Q incommensurate structures using rotating coordinate system or complex basis vectors
- generation of magnetic structures on a magnetic supercell
- plotting of magnetic structures
Magnetic interactions¶
- simple assignment of magnetic interactions to bonds based on bond length
- possible interactions: Heisenberg, Dzyaloshinskii-Moriya, anisotropic and general 3x3 exchange tensor
- arbitrary single ion anisotropy tensor (easy-plane, easy-axis, etc.)
- Zeeman energy in homogeneous magnetic field including arbitrary g-tensor
- calculation of symmetry allowed elements of the above tensors based on the crystallographic space group
Magnetic ground state optimisation¶
- minimization of the classical energy assuming single-Q magnetic structure
- simulated annealing using the Metropolis algorithm on large magnetic supercells
- calculation of properties in thermodynamical equilibrium (heat capacity, magnetic susceptibility, etc.)
- magnetic structure factor calculation using FFT
- simulation of magnetic neutron diffraction and diffuse scattering
Spin wave simulation¶
- solution for sommensurate and single-Q incommensurate magnetic structures
- calculation of spin wave dispersion, spin-spin correlation functions
- calculation of neutron scattering cross section for unpolarized neutrons including the magnetic form factor
- calculation of polarized neutron scattering cross sections
- possibility to include different moment sizes for different magnetic atoms
- calculation of powder averaged spin wave spectrum
Plotting of spin wave spectrum¶
- plotting of dispersions and correlation functions
- calculation and plotting of the convoluted spectra for direct comparison with inelastic neutron scattering
- full integration into Horace for plotting and comparison with time of flight neutron data, see http://horace.isis.rl.ac.uk
Fitting spin wave spectra¶
- possible to fit any parameter of the Hamiltonian
- robust fitting, even when the number of simulated spin wave modes differs from the measured number of modes
SW Class¶
To perform calculation using the SpinW library, we need to create an object (sw class type). It stores all the necessary parameters for the calculation (crystal structure, interactions, magnetic structure, etc.). In the object oriented programming dictionary, the data stored in an object, are called properties. Beside the data, the object also has assigned functions that perform different computations on the object data. These functions are called methods and they take the object as first input argument. To create an sw class object you can simply type:
model1 = sw
Properties¶
The output of the previous command shows all the data fields of model1. Each data field has an initial value and any of them can be modified directly:
model1.lattice.lat_const = [3 5 5];
The above command directly modifies the lattice parameters of the lattice. Modifying propoerties directly is quick and very flexible but prone to error. The most common mistake is that the new values are not the same data type as the original ones. For example the field that stores the lattice space group is integer type:
class(model1.lattice.sym)
Thus if we want to change it directly, we need an integer number:
model1.lattice.sym = int32(5);
This will change the crystal space group to ‘C 2’. To avoid most common mistakes, there are several methods (functions) for modifying the above properties that also perform additional error checking and makes certain input conversions. For example all lattice related properties can be modified using the genlattice() function:
model1.genlattice('lat_const',[3 5 5],'sym','C 2','angled',[90 90 90])
The alternative usage of the above function is the following:
genlattice(model1,'lat_const',[3 5 5],'sym','C 2','angled',[90 90 90])
This reflects better the input argument structure. The first argument is the sw object ‘model1’. After the first argument comes option name and value pairs. The first options is ‘lat_const’ and the value it expects is a vector with 3 elements if the input vector has different length, the function throws an error. The second option is ‘sym’ that also accepts string input (name of the space group) that is automatically converted to the index of the space group and stored in model1:
model1.lattice.sym
The last option is ‘angled’ that requires a vector with three elements and defines the alpha, beta, gamma lattice angles in degree. This will be converted into radian and stored:
model1.lattice.angle
List of properties¶
The sw object properties store all the information necessary for the spin wave calculation. There are eight public properties of the sw class each with several subfields:
- sw.lattice¶
The lattice field stores the lattice parameters and space group information. The subfields are:
- lat_const
- Lattice constants in a row vector with three elements (\(a\), \(b\) and \(c\)) in Å units.
- angle
- \(\alpha\), \(\beta\) and \(\gamma\) angles in a row vector with three elements in radian units.
- sym
- Crystal space group, single integer (int32 type) that gives the line number in the symmetry.dat file. This file stores the generators of the space group and by default contains the 230 crystallographic space groups with standard settings.
See also sw.genlattice(), sw.abc(), sw.basisvector(), sw.nosym().
- sw.unit_cell¶
The unit_cell field stores the information on the atoms in the crystallographic unit cell. Subfields are:
- r
- Atomic positions in lattice units, matrix with dimensions of [3 nAtom], in lattice units.
- S
- Spin (or angular momentum) quantum number of the atoms, row vector with nAtom number of elements. Non-magnetic atoms have \(S=0\).
- label
- String label of the atoms in a cell with dimensions of [1 nAtom].
- color
- Color of the atoms for plotting. Stored in a matrix with dimensions of [3 nAtom], every column is an RGB code (int32 numbers between 0-255).
See also sw.addatom(), sw.atom(), sw.matom(), sw.newcell().
- sw.twin¶
The twin field stores information on crystallographic twins. The subfields are:
- rotc
- Rotation matrices in the xyz coordinate system for every twin, stored in a matrix with dimensions of [3 3 nTwin].
- vol
- Relative volume of the twins, stored in a row vector with nTwin elements.
See also sw.addtwin(), sw.twinq(), sw.ntwin().
- sw.matrix¶
The matrix field stores 3x3 matrices that can be referenced in the magnetic Hailtonian. The subfields are:
- mat
- It stores the actual values of 3x3 matrices stacked along the third dimension with dimensions of [3 3 nMat].
- color
- RGB color codes assigned for every matrix, stored in a matrix with dimensions of [3 nMatrix], each column is an [R;G;B] code with int32 numbers between 0 and 255.
- label
- Label for every matrix, stored as strings in a cell with dimensions of [1 nCell].
See also sw.addmatrix(), sw.getmatrix(), sw.setmatrix().
- sw.single_ion¶
The single_ion field stores the single ion expression of the Hamiltonian. The subfields are:
- aniso
- Row vector contains nMagAtom integers, each integer assignes one of the matrices from the sw.matrix field to a magnetic atom in the sw.matom() list as a single ion anisotropy. Zero means no assigned anisotropy matrix.
- g
- Row vector of nMagAtom integers, each integer assignes one of the matrices from the sw.matrix field to a magnetic atom in the sw.matom() list as a g-tensor.
- field
- External magnetic field stored in a row vector with the 3 components in the xyz coordinate system, default unit is Tesla.
- T
- Temperature, scalar, default unit is Kelvin.
See also sw.addaniso(), sw.addg(), sw.getmatrix(), sw.setmatrix(), sw.intmatrix(), sw.field().
- sw.coupling¶
The coupling field stores the list of bonds. Where each bond is defined between two magnetic atom. Each bond has a direction, it points from atom 1 to atom 2. In the subfiels every column defines a bond, the subfields are:
- dl
- Translation vector between the unit cells of the two interacting spins, stored in a matrix of integer numbers with dimensions of [3 nCoupling].
- atom1
- Stores the index of atom 1 for every bond pointing to the list of magnetic atoms in sw.matom() list, stored in a row vector with nCoupling elements.
- atom2
- Index of atom 2 for each bond.
- mat_idx
- Integer indices selecting exchange matrices from sw.matrix field for every bond, stored in a matrix with dimensions of [3 nCoupling]. Maximum three matrices per bond can be assigned (zeros for no coupling).
- idx
- An integer index for every bond, an increasing number with bond length. Symmetry equivalent bonds have the same index.
See also sw.gencoupling(), sw.addcoupling().
- sw.mag_str¶
The mag_str field stores the magnetic structure. It can store single-Q structures or multi-Q structures on a magnetic supercell. Strictly speaking it stores the expectation value of the spin of each magnetic atom. The magnetic moment directions are given by \(g_i\cdot \langle S_i\rangle\). The subfields are:
- S
It stores the spin directions for every magnetic atom either in the crystallographic unit cell or in a magnetic supercell in a matrix with dimensions of [3 nMagExt]. Every column stores \(\langle S_x\rangle, \langle S_y\rangle, \langle S_z\rangle\) spin components in the xyz coordinate system. The number of spins in the supercell is:
nMagExt = nMagAtom*prod(mag_str.N_ext);
- k
- Magnetic ordering wave vector stored in a row vector with 3 components in reciprocal lattice units. Default value is [0 0 0].
- n
- Normal vector to the rotation of the moments in case of non-zero ordering wave vector (single-Q magnetic structures), row vector with three elements. The components are in the xyz coordinate system. Default value is [0 0 1].
- N_ext
- Dimensions of the magnetic supercell in lattice units stored in a row vector with three elements. Default value is [1 1 1] if the magnetic cell is identical to the crystallographic cell. The three elements extends the cell along the \(a, b, c\) axes.
See also sw.genmagstr(), sw.optmagstr(), sw.anneal(), sw.nmagext(), sw.structfact(), sw.optmagsteep().
- sw.unit¶
The unit field stores the conversion factors between energy, magnetic field and temeprature units in the Hamiltonian. Defaults units are meV, Tesla and Kelvin for energy, magnetic field and temperature respectively. To use identical units for energy, magnetic field and temperature use 1 for each subfields. The subfields are:
- kB
- Boltzmann constant, default value is 0.0862 meV/K.
- muB
- Bohr magneton, default value is 0.0579 meV/T.
Methods¶
In line with the above example the general argument structure of the method functions is one of the following:
function(obj,'Option1',Value1,'Option2',Value2,...)
function(obj,Value1,Value2,...)
The first type of argument list is used for functions that require variable number of input parameters with default values. The second type of argument structure is used for functions that require maximum up to three fixed input parameter. Every method has help that can be called by one of the following methods:
selecting the function name in the Editor/Command Window and pressing F1
in the Command Window typing for example:
help sw.genlattice
This shows the help of the genlattice() function in the Command Window. To open the help in a separate window you need to write:
doc sw.genlattice
To unambiguously identify the functions it is usefull to refer them as sw.function() this way matlab knows which function to select from several that has the same name. For example the plot() funcion is also defined for the sw class. However by writing:
help plot
we get the help for the standard Matlab plot function. To get what we want use:
help sw.plot
By the way this function is one of the most usefull ones. It can show effectively all information stored in the sw object by plotting crystal structure, couplings, magnetic structure etc. Calling it on an empty object shows only the unit cell:
plot(model1)
As you might noticed, there is an alternative calling of any method function: obj.function(...), this is just equivalent to the previous argument structures.
Copy¶
The sw class belong to the so called handle class. It means in short that the model1 variable is just a pointer to the memory where the class is stored. Thus by doing the following:
model2 = model1;
will only duplicate the pointer but not the values stored in the sw object. Thus if I change something in model1, model2 will change as well. To clone the object (the equivalent of the usual ‘=’ operation in Matlab) the sw.copy() function is necessary:
model2 = copy(model1);
Coordinate systems¶
SpinW uses three different coordinate systems. It is important to consider every time, that a given vector/tensor data is in which coordinate system. In the following documentation the xyz, lu and rlu shorthand notation will be used for the three coordinate systems.
Lattice units (lu) coordinate system¶
This is the lattice coordinate system. The three axis are the a, b and c crystal axes. For example the vector [0,1,0] denotes a position translated from the origin by b vector. The following sw class properties are stored in lattice units:
- atomic positions (sw.unit_cell.r)
- translation vectors for bonds (sw.coupling.dl)
Also several function takes input or output in lattice units:
- atomic positions of the output of matom() and atom() methods of sw
- magnetic moments can be given in lattice units for the genmagstr() function (using the ‘unitS’ option with ‘lu’ value)
- calculated bond vectors from couplingtable()
xyz coordinate system¶
Most of the sw class properties are stored in the xyz coordinate system. The xyz coordinate system is right-handed Cartesian and fixed to the crystal lattice:
- x: parallel to a-axis,
- y: perpendicular to x and in the ab-plane,
- z: perpendicular to xy-plane
The following properties are in the xyz coordinate system:
- twin rotation matrices (sw.twin.rotc)
- stored 3x3 matrices (sw.matrix.mat)
- magnetic field (sw.single_ion.field)
- magnetic moment components (sw.mag_str.S)
- normal vector of the magnetic structure (sw.mag_str.n)
Also output of several functions are in xyz coordinate system:
- spin-spin correlation function matrix elements calculated by spinwave() method (spec.Sab matrices)
- interaction matrices calculated by couplingtable()
Vectors in reciprocal space in Å\(^{-1}\) units are also in a right handed Cartesian coordinate system:
- momentum transfer values in Å\(^{-1}\) reciprocal lattice units of the spec.hklA output of the spinwave() function
Reciprocal lattice (rlu) coordinate system¶
The reciprocal lattice coordinate system is the dual vector space of the lattice coordinate system. The three axis are the reciprocal lattice vectors denoted by a\(^*\), b\(^*\) and c\(^*\). The following sw class properties are stored in rlu units:
- magnetic ordering wave vector (sw.mag_str.k)
Also several function takes input in rlu units:
- the sw_neutron() function takes the option ‘uv’, that defines the scattering plane by two vectors in rlu
- the first input of the spinwave() function is a list of Q points in rlu units
Transformation between coordinate systems¶
To transform vectors and tensors between the above coordinate systems, the output of basisvector() function can be used:
tri = sw;
tri.genlattice('lat_const',[3 3 5],'angled',[90 90 120])
BV = tri.basisvector
The BV 3x3 matrix contains the coordinates of the lattice vectors as column vectors: [a b c]. To convert vectors from the abc coordinate system to the xyz, we can do the following:
r_abc = [1/2 1/2; 0];
r_xyz = BV * r_abc
Crystal structure¶
Definition of the magnetic Hamiltonian¶
Magnetic structures¶
Plotting¶
Determination of magnetic structure from Hamiltonian¶
Calculation of the spin-spin correlation function¶
List of functions¶
- gm_planar(absS, x)¶
planar magnetic structure constraint function
[S, k, n, name, pname, limit] = GM_PLANAR(M0, x)
The function generates the parameters of arbitrary planar magnetic structure from phi angles (radian), ordering wave vector (rlu) and spin plane normal vector (xyz).
Parameters: - x – Input parameters in the following order: \((\varphi_1, \varphi_2, ... , k_x, k_y, k_z, n_\theta, n_\phi)\).
- absS – Size of the spins: \((S_1, S_2, ...)\) or scalar if all moments are equal.
Returns: - S – Array, containing the spin orientations with dimensions of [3 nMagExt]. Every column contain the \([S_x; S_y; S_z]\) magnetic moment components of a magnetic atom in the xyz coordinate system.
- k – Magnetic ordering wavevector in rlu units in a row vector.
- n – Normal vector around which the spins are rotating for non-zero k-vector in a row vector.
- name – String, storing the name of the function. Optional.
- pname – Name of the input parameters in a cell: {‘Phi1_rad’, ...}. Optional.
- limit – Limits on the input parameters, dimensions are [2 nParam]. Every column contains a lower and upper limit on the corresponding parameter. Optional.
See also
gm_spherical3d(), gm_planard.()
TEST2.
- doctest2()¶
Summary line.
[b1, b2] = doctest2(a,b)
Extended description of function.
Parameters: - a1 – Description of arg1.
- a2 – Description of arg2.
Returns: - b1 – Description of return value.
- b2 – Other output.
Examples
This will calculate the spectrum:
doctest(1,2);
- doctest(obj, varargin)¶
performs simulated annealing on the magnetic structure
The simulated annealing is performed using the Metropolis algorithm with parallel updating non-interacting sublattices. The function can deal with arbitrary exchange interactions, anisotropies in 1,2 and 3 dimensions.
stat = ANNEAL(obj, 'paramName', value1, ...)
Warning
The calculated energies doesn’t contain the self energy (moment coupled to itself), thus the energies calculated with this function can differ from the result of the energy() function. Also the g-tensor is fixed to 2.
Parameters: - obj – Input object contains structural data, sw type.
- spinDim –
Dimensionality of the magnetic moments:
- 1: Ising spins
- 2: XY spins
- 3: Heisenberg spins (default)
For Ising (spinDim=1) and XY (spinDim=2) models only isotropic exchange interaction and magnetic field can be used. For Ising the direction of the spins are along x-axis, for XY model the the xy-plane. Magnetic fields perpendicular to these directions are omitted.
- initT – The initial temperature, can be any positive number, unit is Kelvin. Default is 1.
- endT – Temperature at which to stop, can be any positive number smaller than InitTemp, unit is Kelvin. Default value is 1e-3.
- cool –
Generates a new temperature from the previous one. Any function handle that takes a scalar as input and returns a smaller but positive scalar as output. Default value is:
@(T) (.92*T)
- random – Random initial conditions, if initial spin configuration is undefined (sw.mag_str.S is empty) the initial configuration is automaticly random independently of the value of random. Default is false.
- nMC – Number of Monte-Carlo steps per spin at each temperature step to reach thermal equilibrium. Default is 100.
- nORel – Number of over-relaxation steps after every Monte-Carlo steps. It rotates the spins around the direction of the local field by 180 \(^\circ\). It is reversible and microcanonical if the single ion anisotropy is zero. Default is 0.
- nStat – Number of cycles at the last temperature to calculate statistical averages. It has to be smaller or equal nMC. Default value is 100.
- boundary –
Boundary conditions of the extended unit cell.
- ‘free’: Free, interactions between extedned unit cells are omitted.
- ‘per’: Periodic, interactions between extended unit cells are retained.
Default value is {'per' 'per' 'per'}.
- verbosity –
Controls output to the screen. Possible values:
- 0: suppresses all output
- 1: gives final report only
- 2: plots temperature changes and final report [default]
- nExt – The size of the magnetic cell in number of unit cells, to provide input information to ‘fStat’. Default is from obj.mag_str.N_ext.
- fStat –
Function handle to evaluate after at the end of the cooling scedule during the last nStat Monte-Carlo steps. The function returns a single structure and takes fixed input parameters:
struct = fStat(state, struct, T, E, M, nExt).
The function is called once before the annealing process when state=1 to initialise the parameters. The function is called after every Monte-Carlo steps with state=2 and the output of the previous function call is assigned to the input struct. fStat is called once again in the end with state=3 to calculate final parameters (in the last run, input struct.param contains all the annealing parameters). Default is sw_fstat().
- fSub –
Function to define sublattices for Monte-Carlo speedup, with header:
cGraph = fSub(conn,nExt)
where cGraph is a (1,nMagExt) sized vector, conn is a (2,nConn) size matrix and nExt is equal to ‘nExt’. Default value is sw_fsub().
- subLat – Vector that assigns all magnetic moments into non-interacting sublattices, contains a single index (1,2,3...) for every magnetic moment, size is (1,nMagExt). If undefined, the function defined in ‘fSub’ will be used to partition the lattice.
- title – Gives a title string to the simulation that is saved in the output.
- autoK – Bin length of the autocorrelation vector. Should be a few times smaller than nMC. Default is zero, no autocorrelation function is calculated.
Returns: stat – Struct that contains the calculated thermodynamical averages and the parameters of the simulation in the following fields:
fields definition param All input parameter values of the anneal function. obj The copy of the input sw class obj with the final magnetic structure. M Components of the magnetisation after the last annealing run, dimensions are [3 nMagExt]. E Magnetic energy of the system after the last annealing run. T Final temperature of the sample. Depending on the ‘fStat’ parameter, additional fields are included. Using the default function (sw_fstat()) the following parameters are calculated:
fields definition avgM Average components of the magnetisation over nStat runs, dimensions are [3 nMagExt]. stdM Standard deviation of the mgnetisation components over nStat runs, dimensions are [3 nMagExt]. avgE Average system energy per spin over nStat runs, scalar. stdE Standard deviation of the system energy per spin over nStat runs, scalar. Cp Heat capacity of the sample: \((\langle E^2\rangle-\langle E\rangle^2)/k_B/T^2\). Chi Magnetic susceptibility of the sample: \((\langle M^2\rangle-\langle M\rangle^2)/k_B/T\). Return type: struct
Example
The following example does annealing on a triangular lattice:
model1 = sw_model('triAF',1); model1.anneal;
References
S. Kirkpatrick, et al., “Optimization by Simulated Annealing”, Science, 220, 671 (1983).