Contents
Help on SpinW
Use the help command to get help on any SpinW function. For any function that starts with 'sw_' use help swfiles, for spinw class methods use help spinw.function_name. For help on plotting commands, use help swplot.
help swfiles % To find the location of the spinw library use sw_rootdir % To open any of the functions in the Matlab editor, use edit spinw.plot % To look at any of the spinw object properties, double click on the % "Workspace" view on the name of the object. Also the data files % (symmetry.dat, atom.dat, color.dat, magion.dat) can be easily edited, for % example edit symmetry.dat % Some settings are ekpt during the active Matlab session, these can be % set/get using the swpref.setpref and swpref.getpref commands. To change % the default values, it can be defined in the startup.m file. To get all % current value use swpref.getpref
This folder contains all the files related to SpinW but not yet split out into separate libraries. Files Transforming and plotting calculated spin wave spectrum: sw_econtract - converts (Q,omega) values to Qm values for diffraction instrument sw_egrid - creates energy for spectrum color plot sw_filelist - lists spinw data in the Matlab workspace or in a .mat file sw_instrument - includes instrumental factors into the calculated spectrum sw_magdomain - calculates the spin-spin correlation function for magnetic domains sw_neutron - calculates neutron scattering intensity for spin wave spectrum sw_omegasum - removes degenerate and ghost magnon modes from spectrum sw_plotspec - plots spin wave spectrum sw_xray - calculates X-ray scattering intensity for phonon spectrum Generate list of vectors in reciprocal space: sw_qgrid - creates a Q grid sw_qscan - creates linear scans between Q points in 3D Resolution claculation and convolution: sw_res - reads a tabulated energy resolution from a file and fits with polynomial sw_resconv - Convolute Gaussian with variable width along the first dimension of a matrix sw_tofres - includes Q resolution to the spectrum SpinW model related functions: sw_extendlattice - creates superlattice sw_fstat - calculates termodynamical averages during an annealing simulation sw_intsf - integrates the structure factor along given Q directions sw_model - creates different predefined spin models Constraint functions for spinw.optmagstr(): gm_planar - planar magnetic structure constraint function gm_planard - planar magnetic structure constraint function gm_spherical3d - magnetic structure constraint function with spherical parameterisation gm_spherical3dd - magnetic structure constraint function with spherical parameterisation Geometrical calculations: sw_angle - calculates the angle between 2 vectors sw_cartesian - creates a right handed Cartesian coordinate system sw_cmod - modulo one with tolerance sw_fsub - simple graph vertex coloring sw_mattype - determines the type of square input matrix sw_nvect - determines the best normal vector for the set of vectors sw_quadell - calculates and plots the parameters of an ellipsoid from a quadratic form sw_rot - rotates vectors around arbitrary axis in 3D sw_rotmat - rotates vectors around arbitrary axis in 3D sw_rotmatd - rotates vectors around arbitrary axis in 3D Text and graphical input/output for different high level commands: sw_annealfigure - creates a figure for displaying the status of the annealing simulation sw_annealplot - displays information about the annealing simulation sw_label - returns axis labels for spectrum plot sw_circle - creates an array of the 3D coordinates of the circle circumference sw_counter - print the number of calls to this functio to the Command Line sw_multicolor - creates RGB color data for multiple 2D overlapping plots sw_parstr - parses input string sw_plotcell - plots cell structure with circles sw_plotsf - plots the structure factor in the selected Q range in 1D or 2D sw_status - timer function that displays also the remaining time Acessing the SpinW database: sw_atomdata - returns information on elements stored in the atom.dat file sw_cff - returns the atomic charge form factor values for X-ray scattering sw_mff - returns the magnetic form factor values and the coefficients sw_nb - returns the bound coherent neutron scattering length (fm) Symmetry calculations: sw_basismat - determines allowed tensor components in a given point group symmetry sw_mirror - mirrors a 3D vector Useful functions for physics: sw_bose - coefficient for boson correlation functions for different temperatures sw_converter - converts energy and momentum units for a given particle sw_fibo - returns the last two Fibonacci number smaller or equal to the Import functions: sw_import - create SpinW object from .cif and FullProf Studio .fst files sw_readspec - read spin wave dispersion data from file sw_readtable - reads tabular data Export functions: sw_idata - creates iData object Other files: sw_freemem - gives the amount of free RAM in bytes sw_initialize - initializes spinw by removing user entries from the symmetry.dat file sw_readparam - parse input arguments (option, value pairs) sw_rootdir - gives the path to the SpinW code sw_uniquetol - returns the unique column vectors within tolerance sw_update - updates the SpinW installation from the internet sw_version - returns the installed version of SpinW sw_mex - compiles the mex files and test them ans = /Users/tothsa/spinw_git/ ans = struct with fields: fid: 0 expert: 1 tag: 'swplot' nmesh: 3 maxmesh: 6 npatch: 50 fontsize: 12 tid: 0 colormap: @cm_inferno usemex: 0
Generate lattice
We create a triangular lattice of magnetic atoms.
tri = spinw; % The lattice parameters in Angstrom and angles in degree can be defined. tri.genlattice('lat_const',[3 3 4],'angled',[90 90 120]) % To plot the lattice use the command spinw.plot. plot(tri) % In the plot window, you can zoom with the mouse wheel, pan by pressing % the Ctrl button while dragging. Change the plot range and view direction % by pressing the corresponding buttons on the top.
Warning: There are no atoms in the plotting range!

Adding atoms
We add 1 atom at the origin of the unit cell, spin-3/2 Cr3+ ion using the spinw.addatom.
tri.addatom('r',[0 0 0],'S',3/2,'label','MCr3') plot(tri)

Definition of the spin-Hamiltonian
We create an antiferromagnetic first neighbor Hamiltonian plus easy plane single ion anisotropy red ellipsoids represent the single ion anistropy on the plot (equienergetic surface) examine the plot and test different values of A0 with different signs. The plot command can plot rectangular cut of the lattice setting the unit option to xyz and giving the plot range in Agnstrom.
A0 = 0.1; tri.addmatrix('label','J1','value',1) tri.addmatrix('label','A','value',[0 0 0;0 0 0;0 0 A0]) tri.gencoupling tri.addcoupling('mat','J1','bond',1) tri.addaniso('A') plot(tri,'range',[22 20 1/2],'unit','xyz','cellMode','single')

Magnetic structure
The ground state magnetic structure of the above Hamltonian is a spiral, with propagation vector of (1/3,1/3,0). We define the plane of the spiral as the ab plane. Careful: the given spin vector is column vector! What are the angles between neares neighbor moments?
tri.genmagstr('mode','helical','S',[1;0;0],'k',[1/3 1/3 0],'n',[0 0 1],'nExt',[1 1 1]) plot(tri,'range',[3 3 1/2],'cellMode','inside','magColor','red')

Spin wave dispersion
We calculate the spin wave dispersion along the (H,H,0) high symmetry direction. How many spin wave modes are there and why? What does the red line mean? Did you got any warning?
spec = tri.spinwave({[0 0 0] [1 1 0] 500},'hermit',false); figure sw_plotspec(spec,'mode','disp','imag',true,'colormap',[0 0 0],'colorbar',false) axis([0 1 0 5])
Warning: Eigenvectors of defective eigenvalues cannot be orthogonalised at some q-point!

Spin-spin correlation functions
The spin-spin correlations is already calculated, however the result contains 9 numbers per Q-point per mode. It is not possible to show this on a single plot.
BUT!
1. we can calculate the neutron scattering cross section 2. we can select one of the components S_alpha_beta(Q,w) 3. we can sum up the diagonal S_alpha_alpha(Q,w)
What do you see? Where is the largest intensity? How is it related to the magnetic propagation vector?
Why are some modes gapped? What type of spin-spin correlations are gapped?
Why do we have Szz?
Shouldn't the spins precess around M? Shouldn't each spin wave mode corresponds to a precession in a specific plane not a motion along a specific axis?
%spec = sw_egrid(spec,'component','Sperp','Evect',0:0.01:5.5); spec = sw_egrid(spec,'component',{'Sxx+Syy' 'Szz'},'Evect',0:0.01:5); %spec = sw_egrid(spec,'component','Syz','Evect',0:0.01:5); figure sw_plotspec(spec,'mode','color','dE',0.2,'imag',false) hold on axis([0 1 0 5.5]) caxis([0 3])

k=0 magnetic structure
We can generate the same magnetic structure with zero propagation vector on a magnetic supercell.
Why would we do that? Not for a triangular lattice, but in more complex cases, we will have to!
You can keep the previous structure plot by pressing the red circle on the figure to compare the new magnetic structure. Is there any difference?
What are we doing here? Can you tell from the script?
Check out the tri.magstr command? What data is stored there? What are the dimensions of the different matrices?
You can also compare the energy per spin of the old magnetic structure and the new magnetic structure using the spinw.energy() function. Is there any difference?
You can also store the new magnetic structure in a separate SpinW object by first duplicating the original object using the copy() command!
What happens when we use tri2 = triNew, without the copy command?
triNew = copy(tri); tri2 = triNew; triNew.genmagstr('mode','random','next',[3 3 1]) triNew.optmagsteep('nRun',1e4) % Converged? triNew.genmagstr('mode','rotate','n',[0 0 1]) phi1 = atan2(triNew.magstr.S(2,1),triNew.magstr.S(1,1)); triNew.genmagstr('mode','rotate','n',[0 0 1],'phi',-phi1) plot(triNew,'range',[3 3 1],'atomLegend',false) % How does the magnetic structures compare? Are they the same? Why? % tri.magstr tri2.magstr
ans = struct with fields: S: [3×1 double] k: [0.3333 0.3333 0] n: [0 0 1] N_ext: [1 1 1] exact: 1 ans = struct with fields: S: [3×9 double] k: [0 0 0] n: [0 0 1] N_ext: [3 3 1] exact: 1

Spin wave dispersion on the k=0 magnetic structure
We calculate the spin wave dispersion along the (H,H,0) high symmetry direction. How many modes do we have? Is there more than before? Which is the right one then?
Why are there vertical lines in the dispersion? Is it a bug?
spec = tri.spinwave({[0 0 0] [1 1 0] 500},'hermit',false); figure subplot(2,1,1) sw_plotspec(spec,'mode','disp','imag',true,'colormap',[0 0 0]) colorbar off axis([0 1 0 5]) % spin-spin correlation functions spec = sw_egrid(spec,'component','Sperp','Evect',0:0.01:5.5); subplot(2,1,2) sw_plotspec(spec,'mode','color','dE',0.2,'imag',false) axis([0 1 0 5.5]) caxis([0 3]) legend off colorbar off swplot.subfigure(1,3,1)
Warning: Eigenvectors of defective eigenvalues cannot be orthogonalised at some q-point!

Written by Sandor Toth 06-Feb-2016