Skip to content

Commit

Permalink
Updating tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
tsdev committed Feb 7, 2017
1 parent b3610de commit bd231c1
Show file tree
Hide file tree
Showing 233 changed files with 6,912 additions and 3,621 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="spinw_logo.png" width="150">
<img src="spinw3_logo.png" width="150">

**SpinW** is a Matlab library that can calculate magnetic structure using mean field theory and spin wave dispersion and spin-spin correlation function for complex crystal structures.
**SpinW** is a Matlab library that can optimize magnetic structures using mean field theory and calculate spin wave dispersion and spin-spin correlation function for complex crystal and magnetic structures.

Binary file added spinw3_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions swfiles/+swplot/figure.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@
pbaspect([1 1 1]);

set(hFigure,...
'Name', 'swplot',...
'DockControls', 'off',...
'PaperType', 'A4',...
'Tag', swpref.getpref('tag',[]),...
'Toolbar', 'figure',...
'DeleteFcn', @closeSubFigs);
'Renderer', 'opengl',...
'Name', 'swplot',...
'DockControls', 'off',...
'PaperType', 'A4',...
'Tag', swpref.getpref('tag',[]),...
'Toolbar', 'figure',...
'DeleteFcn', @closeSubFigs...
);

hToolbarT = get(hFigure,'children');

Expand Down
20 changes: 15 additions & 5 deletions swfiles/+swplot/logo.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ function logo(varargin)
% See also: SPINW.
%

% determine the version of SpinW
ver = sw_version;

if ~isempty(ver.Version)
verStr = [' ' ver.Version ' ' 'R' ver.Revision];
else
verStr = [' ' 'R' ver.Revision];
end

hFigure = figure('menubar','none','toolbar','none','name',...
'About SpinW','NumberTitle','off','resize','off','Visible','off');
['About SpinW' verStr],'NumberTitle','off','resize','off','Visible','off');
hold on

% plot wave
Expand Down Expand Up @@ -56,10 +65,13 @@ function logo(varargin)

% add name
text(-2.3,-1.3,2.35,'Spin','fontsize',110,'fontname','Krungthep')

set(hFigure,'Visible','on');

% save logo
if nargin > 0 && ~isempty(varargin{end})
print(varargin{end},'-dpng','-r300')
close(gcf)
close(hFigure)
else
% add text
ver0 = evalc('sw_version');
Expand All @@ -82,11 +94,9 @@ function logo(varargin)
tt = text(0.65,0.5,txt0,'units','normal');
set(tt,'FontSize',9.2);

WinOnTop(hFigure, true);
end

set(hFigure,'Visible','on');
WinOnTop(hFigure, true);

end

function WasOnTop = WinOnTop(FigureHandle, IsOnTop)
Expand Down
14 changes: 14 additions & 0 deletions swfiles/+swpref/setpref.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ function setpref(prefName, varargin)
% See also SWPREF.SETPREF.
%

if nargin>0 && mod(nargin,2)==0
% check for usemex option
mexopt = find(strcmpi('usemex',varargin));

if ~isempty(mexopt) && varargin{mexopt+1}
% check for the existence of the necessary mex files
if exist('chol_omp','file')==3 && exist('eig_omp','file')==3
else
warning('setpref:MissingMex','Necessary mex files are missing, compile them!')
varargin{mexopt+1} = false;
end
end
end

if nargin<=2
swpref.pref(prefName,'set',varargin{:});
elseif mod(nargin,2)==0
Expand Down
38 changes: 32 additions & 6 deletions swfiles/@spinw/fitspec.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
function fitsp = fitspec2(obj, varargin)
function fitsp = fitspec(obj, varargin)
% fits spin wave spectra to experimental spectral data
%
% fitsp = FITSPEC(obj, 'Option1', Value1, ...)
%
% The function uses a heuristic method to fit spin wave spectrum using a
% few simple rules to define the R-value of the fit:
% 1 All calculated spin wave modes that are outside of the measured
% energy range will be omitted.
% 2 Spin wave modes that are closer to each other than the given energy
% bin will be binned together and considered as one mode in the fit.
% 3 If the number of calculated spin wave modes after applying rule 1&2
% is larger than the observed number, the weakes simulated modes will
% be removed from the fit.
% 4 If the number of observed spin wave modes is larger than the observed
% number, fake spin wave modes are added with energy equal to the
% limits of the scan; at the upper or lower limit depending on which is
% closer to the observed spin wave mode.
% After these rules the number of observed and simulated spin wave modes
% will be equal. The R-value is defined as:
%
% R = sqrt( sum_i_q (E_i_q_sim - E_i_q_meas)^2/sigma_i_q^2 ),
%
% where (i,q) indexing the spin wave mode and momentum. E_sim and E_meas
% are the simulated and measured spin wave energies, sigma is the standard
% deviation of the measured spin wave energy determined previously by
% fitting the inelastic peak.
%
% The R value is optimized using particle swarm algorithm to find the
% global minimum.
%
% Options:
%
% func Function to change the Hamiltonian in obj, it has the following
Expand Down Expand Up @@ -99,10 +125,10 @@
inpForm.size = [inpForm.size {[1 1] [1 1] [1 1] [1 1] [1 -7] }];
inpForm.soft = [inpForm.soft {false false false false false }];

inpForm.fname = [inpForm.fname {'maxiter' 'sw' 'optmem' 'usemex' 'tid' }];
inpForm.defval = [inpForm.defval {20 1 0 false tid0 }];
inpForm.size = [inpForm.size {[1 1] [1 1] [1 1] [1 1] [1 1] }];
inpForm.soft = [inpForm.soft {false false false false false }];
inpForm.fname = [inpForm.fname {'maxiter' 'sw' 'optmem' 'tid' }];
inpForm.defval = [inpForm.defval {20 1 0 tid0 }];
inpForm.size = [inpForm.size {[1 1] [1 1] [1 1] [1 1] }];
inpForm.soft = [inpForm.soft {false false false false }];

param = sw_readparam(inpForm, varargin{:});

Expand Down Expand Up @@ -272,7 +298,7 @@

% calculate spin-spin correlation function
spec = obj.spinwave(data.Q,'fitmode',true,'hermit',param.hermit,...
'tid',0,'optMem',param.optmem,'useMex',param.usemex,'tid',param.tid);
'tid',0,'optMem',param.optmem,'tid',param.tid);
% calculate neutron scattering cross section
spec = sw_neutron(spec,'n',data.n,'pol',data.corr.type{1}(1) > 1);
% bin the data along energy
Expand Down
16 changes: 9 additions & 7 deletions swfiles/@spinw/powspec.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
%
% spectra = POWSPEC(obj, hklA, 'Option1', Value1, ...)
%
% The function calculates powder averaged spin wave spectrum by doing a 3D
% average in momentum space. This method is not efficient for low
% dimensional (2D, 1D) structures. To speed up the calculation with mex
% files use the swpref.setpref('usemex',true) option.
%
% Input:
%
% obj spinw class object.
Expand Down Expand Up @@ -34,9 +39,6 @@
% J. Phys. A: Math. Gen. 37 (2004) 11591
% The number of points on the sphere is given by the largest
% Fibonacci number below nRand. Default is false.
% useMex If true, the code will use compiled mex files (if they
% exist) to speed up the calculation, for details see
% sw_mex() function. Default is false.
% imagChk Checks that the imaginary part of the spin wave dispersion is
% smaller than the energy bin size. Default is true.
%
Expand Down Expand Up @@ -95,9 +97,9 @@
inpForm.defval = [inpForm.defval {true false title0 @spinwave true }];
inpForm.size = [inpForm.size {[1 1] [1 1] [1 -3] [1 1] [1 1] }];

inpForm.fname = [inpForm.fname {'extrap' 'fibo' 'optmem' 'binType' 'useMex'}];
inpForm.defval = [inpForm.defval {false false 0 'ebin' false }];
inpForm.size = [inpForm.size {[1 1] [1 1] [1 1] [1 -4] [1 1] }];
inpForm.fname = [inpForm.fname {'extrap' 'fibo' 'optmem' 'binType'}];
inpForm.defval = [inpForm.defval {false false 0 'ebin' }];
inpForm.size = [inpForm.size {[1 1] [1 1] [1 1] [1 -4] }];

param = sw_readparam(inpForm, varargin{:});

Expand Down Expand Up @@ -157,7 +159,7 @@
specQ = param.specfun(obj,hkl,'fitmode',true,'notwin',true,...
'Hermit',param.hermit,'formfact',param.formfact,...
'formfactfun',param.formfactfun,'gtensor',param.gtensor,...
'optmem',param.optmem,'useMex',param.useMex,'tid',0,'fid',0);
'optmem',param.optmem,'tid',0,'fid',0);
end
specQ = sw_neutron(specQ,'pol',false);
specQ.obj = obj;
Expand Down
34 changes: 14 additions & 20 deletions swfiles/@spinw/spinwave.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
% calculated using a coordinate system rotating from cell to cell. In this
% case the spin Hamiltonian has to fulfill this extra rotational symmetry.
%
% Some of the code of the function can run faster is mex files are used. To
% switch on mex files, use the swpref.setpref('usemex',true) command. For
% details see the <a href="matlab:help('sw_mex.m')">sw_mex</a> function.
%
%
% Input:
%
% obj Input structure, spinw class object.
Expand Down Expand Up @@ -97,9 +102,6 @@
% frame is saved S'(k,omega). Default is false.
% title Gives a title string to the simulation that is saved in the
% output.
% useMex If true, the code will use compiled mex files (if they
% exist) to speed up the calculation, for details see
% sw_mex() function. Default is false.
%
% Output:
%
Expand Down Expand Up @@ -153,7 +155,7 @@
% triangular lattice antiferromagnet (S=1, J=1) along the [H H 0] direction
% in reciprocal space.
%
% See also SPINW, SPINW.SPINWAVESYM, SW_NEUTRON, SPINW.POWSPEC, SPINW.OPTMAGSTR, SPINW.FILEID, SW_INSTRUMENT.
% See also SPINW, SPINW.SPINWAVESYM, SW_MEX, SPINW.POWSPEC.
%

% for linear scans create the Q line(s)
Expand All @@ -166,6 +168,9 @@
% save warning of eigorth
orthWarn0 = false;

% use mex file by default?
useMex = swpref.getpref('usemex',[]);

% calculate symbolic spectrum if obj is in symbolic mode
if obj.symbolic
if numel(hkl) == 3
Expand Down Expand Up @@ -209,9 +214,9 @@
inpForm.defval = [inpForm.defval {false @sw_mff title0 false }];
inpForm.size = [inpForm.size {[1 -1] [1 1] [1 -2] [1 1] }];

inpForm.fname = [inpForm.fname {'useMex' 'cmplxBase' 'tid' 'fid' }];
inpForm.defval = [inpForm.defval {false false -1 nan }];
inpForm.size = [inpForm.size {[1 1] [1 1] [1 1] [1 1] }];
inpForm.fname = [inpForm.fname {'cmplxBase' 'tid' 'fid' }];
inpForm.defval = [inpForm.defval {false -1 nan }];
inpForm.size = [inpForm.size {[1 1] [1 1] [1 1] }];

param = sw_readparam(inpForm, varargin{:});

Expand All @@ -236,17 +241,6 @@
param.tid = swpref.getpref('tid',[]);
end

if param.useMex == -1
% don't check files (takes too much time)
param.useMex = true;
% elseif ~(param.useMex && exist('chol_omp','file')==3 && ...
% exist('eig_omp','file')==3 && exist('mtimesx','file')==3)
elseif ~(param.useMex && exist('chol_omp','file')==3 && ...
exist('eig_omp','file')==3)
% check if mex files exist
param.useMex = false;
end

% generate magnetic structure in the rotating noation
magStr = obj.magstr;

Expand Down Expand Up @@ -711,7 +705,7 @@
% basis functions of the magnon modes
V = zeros(2*nMagExt,2*nMagExt,nHklMEM);

if param.useMex && nHklMEM>1
if useMex && nHklMEM>1
% use mex files to speed up the calculation
% mex file will return an error if the matrix is not positive definite.
[K2, invK] = chol_omp(ham,'Colpa','tol',param.omega_tol);
Expand Down Expand Up @@ -773,7 +767,7 @@
gham = mmat(gComm,ham);
%gham = mtimesx(gComm,ham);

[V, D, orthWarn] = eigorth(gham,param.omega_tol, param.sortMode,param.useMex);
[V, D, orthWarn] = eigorth(gham,param.omega_tol, param.sortMode,useMex);

orthWarn0 = orthWarn || orthWarn0;

Expand Down
2 changes: 1 addition & 1 deletion swfiles/@spinw/table.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
% T Matlab table object.
%

if verLessThan('MATLAB','R2013b')
if verLessThan('MATLAB','8.2')
warning('spinw:table:Version','This function is supported only on MATLAB R2013b or newer!')
return
end
Expand Down
1 change: 1 addition & 0 deletions swfiles/Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@
% 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
7 changes: 7 additions & 0 deletions dev/sw_mex.m → swfiles/sw_mex.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ function sw_mex(varargin)
%
% SW_MEX('Option1',Value1, ...)
%
% The compiled mex files will speed up the spinw.spinwave function. The
% expected speedup is larger for smaller magnetic unit cells. Once the mex
% files are compiled, use the swpref.setpref('usemex',true) command to
% switch to mex in spinw.spinwave.
%
% Options:
%
% test If true, the compiled .mex files will be tested. Default is
% false.
% swtest If true, 3 spin wave calculation will run with and without .mex
% files and the results will be compared. Default is false.
%
% See also SWPREF.
%

inpForm.fname = {'test' 'compile' 'swtest' };
inpForm.defval = {false true false };
Expand Down
4 changes: 2 additions & 2 deletions swfiles/sw_plotspec.m
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@

if any(strfind(get(get(param.aHandle,'Parent'),'Tag'),'sw_crystal'))
% don't plot into the crystal structure window
fHandle = figure;
fHandle = figure('color','w');
param.aHandle = gca;
else
fHandle = get(gca,'Parent');
Expand All @@ -272,7 +272,7 @@
else
fHandle = sw_getfighandle('sw_spectra');
if isempty(fHandle)
fHandle = figure;
fHandle = figure('color','w');
end
end
% set Tag to find window later easily
Expand Down
26 changes: 18 additions & 8 deletions swfiles/sw_version.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%

% read file header from sw.m file
fid = fopen('spinw.m');
fid = fopen('sw_version.m');

% first line
fgets(fid);
Expand Down Expand Up @@ -54,9 +54,11 @@
if nField == 0
aDir = pwd;
cd(sw_rootdir);
[~, revNum] = system('svn info |grep Revision: |cut -c11-');
[~, revNum] = system('git rev-list --count HEAD');
revNum = strtrim(revNum);
%[~, revNum] = system('svn info |grep Revision: |cut -c11-');
cd(aDir);
revNum = str2double(revNum);
revNum = str2double(revNum)+1e3;
end

% Matlab version & Symbolic Toolbox
Expand Down Expand Up @@ -90,15 +92,23 @@
fprintf(['MATLAB version: ' version ', ' strSym '\n']);

else
ver0 = struct;
ver0.Name = 'SpinW';
ver0.Version = '';
ver0.Author = 'S. Toth';
ver0.Contact = '[email protected]';
ver0.Revision = '';
ver0.Date = datestr(now,'dd-mmm-yyyy');
ver0.License = 'GNU GENERAL PUBLIC LICENSE';

if nField == 0
if any(revNum)
varargout{1}.Revision = num2str(revNum);
else
varargout{1} = struct;
ver0.Revision = num2str(revNum);
end
varargout{1} = ver0;
else
if isempty(verStruct)
varargout{1} = 'beta';
if isempty(fieldnames(verStruct))
varargout{1} = ver0;
else
varargout{1} = verStruct;
end
Expand Down
Loading

0 comments on commit bd231c1

Please sign in to comment.