diff --git a/swfiles/+ndbase/spaghetti.m b/swfiles/+ndbase/spaghetti.m index ef080b8b3..d038e4e02 100644 --- a/swfiles/+ndbase/spaghetti.m +++ b/swfiles/+ndbase/spaghetti.m @@ -26,6 +26,8 @@ % coo = cell(1,2); % [coo{:}] = ndgrid(udat.x,udat.y); % surf(coo{:},udat.sig); +% axscale Scale of the unit on the x-axis. Defines what A^-1 value +% corresponds to unit 1. Default value is 1. % % Output: % @@ -40,10 +42,10 @@ % clim Limits of the c-axis, row vector with 2 elements. % -inpForm.fname = {'flip' 'label' 'dashed' 'ylim' 'plot' 'pad'}; -inpForm.defval = {[] [] true 'auto' true false}; -inpForm.size = {[1 -1] [1 -2] [1 1] [1 -3] [1 1] [1 1]}; -inpForm.soft = {true true false false false false}; +inpForm.fname = {'flip' 'label' 'dashed' 'ylim' 'plot' 'pad' 'axscale'}; +inpForm.defval = {[] [] true 'auto' true false 1 }; +inpForm.size = {[1 -1] [1 -2] [1 1] [1 -3] [1 1] [1 1] [1 1] }; +inpForm.soft = {true true false false false false false }; param = sw_readparam(inpForm, varargin{:}); @@ -59,6 +61,10 @@ param.flip = logical(param.flip); end +if isa(dat,'sqw') + dat = d2d(dat); +end + if ~isa(dat,'d2d') error('spaghetti:WrongDataType','The given data is not d2d type!') end @@ -83,8 +89,9 @@ end ax0 = spags.p{1}(:)*spags.ulen(spags.pax(1)); -%ax{1} = ax0-mean(ax0(1:2)); -ax{1} = ax0; +% start from 0 +ax{1} = ax0-mean(ax0(1:2)); +%ax{1} = ax0; ax{2} = spags.p{2}(:); dash = zeros(1,nDat-1); @@ -135,9 +142,15 @@ cLim = [min(sig(:)) max(sig(:))]; end +% scale x-axis for plotting +axscale = 1/param.axscale; +axp = ax; +axp{1} = axp{1}*axscale; +axLim(1:2) = axLim(1:2)*axscale; + % draw the plot if param.plot - [xx, yy] = ndgrid(ax{:}); + [xx, yy] = ndgrid(axp{:}); % pad signal sigP = sig; sigP(end+1,:) = nan; @@ -149,12 +162,12 @@ if param.dashed && nDat>1 xD = [dash(:) dash(:) nan*dash(:)]'; - yD = repmat([min(ax{2}) max(ax{2}) nan],[size(xD,2) 1])'; + yD = repmat([min(axp{2}) max(axp{2}) nan],[size(xD,2) 1])'; line(xD(:),yD(:),'LineStyle','--','Color','k'); end if ~isempty(param.label) - hAxis.XTick = [0 dash mean(ax{1}(end-1:end))]; + hAxis.XTick = [mean(axp{1}(1:2)) dash mean(axp{1}(end-1:end))]; hAxis.XTickLabel = param.label; end @@ -167,6 +180,7 @@ box on grid off colormap(cm_viridis(500)) + set(gca,'layer','top') end udat.x = ax{1}; diff --git a/swfiles/@spinw/addatom.m b/swfiles/@spinw/addatom.m index 314221613..5a5f8aa50 100644 --- a/swfiles/@spinw/addatom.m +++ b/swfiles/@spinw/addatom.m @@ -315,7 +315,7 @@ function addatom(obj, varargin) newAtom.color = int32(newAtom.color); newObj.unit_cell = newAtom; -validate(newObj,'unit_cell'); +spinw.validate(newObj,'unit_cell'); cField = {'r' 'label' 'S' 'color' 'ox' 'occ' 'b' 'A' 'Z' 'biso'}; @@ -351,7 +351,7 @@ function addatom(obj, varargin) obj.unit_cell.ff = cat(3,obj.unit_cell.ff,newObj.unit_cell.ff); end -%validate(obj); +%spinw.validate(obj); [~,~,rIdx] = unique(obj.unit_cell.r','rows'); diff --git a/swfiles/@spinw/addmatrix.m b/swfiles/@spinw/addmatrix.m index 80bebf40b..08c246247 100644 --- a/swfiles/@spinw/addmatrix.m +++ b/swfiles/@spinw/addmatrix.m @@ -137,7 +137,7 @@ function addmatrix(obj, varargin) newJItem.color = int32(newMat.color(:,ii)); newObj.matrix = newJItem; - %validate(newObj,'matrix'); + %spinw.validate(newObj,'matrix'); cIdx = find(strcmp(obj.matrix.label,newJItem.label)); @@ -174,6 +174,6 @@ function addmatrix(obj, varargin) end end -%validate(obj); +%spinw.validate(obj); end \ No newline at end of file diff --git a/swfiles/@spinw/gencoupling.m b/swfiles/@spinw/gencoupling.m index 1f03fe8c1..f5fbcf618 100644 --- a/swfiles/@spinw/gencoupling.m +++ b/swfiles/@spinw/gencoupling.m @@ -248,7 +248,7 @@ function gencoupling(obj, varargin) obj.single_ion.aniso = aniso; obj.single_ion.g = g; -validate(obj); +spinw.validate(obj); end diff --git a/swfiles/@spinw/genmagstr.m b/swfiles/@spinw/genmagstr.m index 5977923d2..e6d511d77 100644 --- a/swfiles/@spinw/genmagstr.m +++ b/swfiles/@spinw/genmagstr.m @@ -451,6 +451,6 @@ function genmagstr(obj, varargin) mag_str.F = S; obj.mag_str = mag_str; -validate(obj); +spinw.validate(obj); end \ No newline at end of file diff --git a/swfiles/@spinw/optmagstr.m b/swfiles/@spinw/optmagstr.m index 73eb14b03..f80a203af 100644 --- a/swfiles/@spinw/optmagstr.m +++ b/swfiles/@spinw/optmagstr.m @@ -235,7 +235,7 @@ %obj.mag_str.n = n; obj.genmagstr('mode','helical','S',M,'k',k,'n',n); -validate(obj); +spinw.validate(obj); % Create output struct if nargout > 0 diff --git a/swfiles/@spinw/private/datastruct.m b/swfiles/@spinw/private/datastruct.m index b1d559985..8763b1165 100644 --- a/swfiles/@spinw/private/datastruct.m +++ b/swfiles/@spinw/private/datastruct.m @@ -14,7 +14,7 @@ 'aniso' 'g' 'field' 'T' '' '' '' '' '' '' '';... % SINGLE_ION 'dl' 'atom1' 'atom2' 'mat_idx' 'idx' 'type' 'sym' 'rdip' 'nsym' '' '';... % COUPLING 'F' 'k' 'nExt' '' '' '' '' '' '' '' '';... % MAG_STR - 'kB' 'muB' 'mu0' 'label' 'nformula' '' '' '' '' '' ''}; % UNIT + 'kB' 'muB' 'mu0' 'label' 'nformula' 'qmat' '' '' '' '' ''}; % UNIT Datastruct.sizefield = {... {1 3} {1 3} {3 4 'nSymOp'} {1 3} {1 'nStr'} {} {} {} {} {} {};... {3 'nAtom'} {1 'nAtom'} {1 'nAtom'} {3 'nAtom'} {1 'nAtom'} {1 'nAtom'} {2 'nAtom'} {2 11 'nAtom'} {1 'nAtom'} {1 'nAtom'} {1 'nAtom'};... @@ -23,7 +23,7 @@ {1 'nMagAtom'} {1 'nMagAtom'} {1 3} {1 1} {} {} {} {} {} {} {};... {3 'nBond'} {1 'nBond'} {1 'nBond'} {3 'nBond'} {1 'nBond'} {3 'nBond'} {3 'nBond'} {1 1} {1 1} {} {};... {3 'nMagExt' 'nK'} {3 'nK'} {1 3} {} {} {} {} {} {} {} {};... - {1 1} {1 1} {1 1} {1 4} {1 1} {} {} {} {} {} {}}; + {1 1} {1 1} {1 1} {1 4} {1 1} {3 3} {} {} {} {} {}}; Datastruct.typefield = {... 'double' 'double' 'double' 'double' 'char' '' '' '' '' '' '' ;... 'double' 'double' 'char' 'integer' 'double' 'double' 'double' 'double' 'integer' 'integer' 'double';... @@ -32,19 +32,19 @@ 'integer' 'integer' 'double' 'double' '' '' '' '' '' '' '' ;... 'integer' 'integer' 'integer' 'integer' 'integer' 'integer' 'integer' 'double' 'integer' '' '' ;... 'double' 'double' 'integer' '' '' '' '' '' '' '' '' ;... - 'double' 'double' 'double' 'char' 'integer' '' '' '' '' '' '' }; + 'double' 'double' 'double' 'char' 'integer' 'double' '' '' '' '' '' }; uLabel = {char(197) 'meV' 'T' 'K'}; Datastruct.defval = {... - pi/2*ones(1,3) [3 3 3] zeros(3,4,0) zeros(1,3) 'P 0' [] [] [] [] [] [];... - zeros(3,0) zeros(1,0) cell(1,0) int32(zeros(3,0)) zeros(1,0) zeros(1,0) zeros(2,0) zeros(2,11,0) int32(zeros(1,0)) int32(zeros(1,0)) zeros(1,0);... - 1 eye(3) [] [] [] [] [] [] [] [] [];... - zeros(3,3,0) int32(zeros(3,0)) cell(1,0) [] [] [] [] [] [] [] [];... - int32(zeros(1,0)) int32(zeros(1,0)) [0 0 0] 0 [] [] [] [] [] [] [];... + pi/2*ones(1,3) [3 3 3] zeros(3,4,0) zeros(1,3) 'P 0' [] [] [] [] [] [];... + zeros(3,0) zeros(1,0) cell(1,0) int32(zeros(3,0)) zeros(1,0) zeros(1,0) zeros(2,0) zeros(2,11,0) int32(zeros(1,0)) int32(zeros(1,0)) zeros(1,0);... + 1 eye(3) [] [] [] [] [] [] [] [] [];... + zeros(3,3,0) int32(zeros(3,0)) cell(1,0) [] [] [] [] [] [] [] [];... + int32(zeros(1,0)) int32(zeros(1,0)) [0 0 0] 0 [] [] [] [] [] [] [];... int32(zeros(3,0)) int32(zeros(1,0)) int32(zeros(1,0)) int32(zeros(3,0)) int32(zeros(1,0)) int32(zeros(3,0)) int32(zeros(3,0)) 0 int32(0) [] [];... - zeros(3,0,0) zeros(3,0) int32([1 1 1]) [] [] [] [] [] [] [] [];... - 0.086173324 0.057883818066 201.335431 uLabel int32(0) [] [] [] [] [] []}; + zeros(3,0,0) zeros(3,0) int32([1 1 1]) [] [] [] [] [] [] [] [];... + 0.086173324 0.057883818066 201.335431 uLabel int32(0) eye(3) [] [] [] [] []}; % 0.086173324 Boltzmann constant: k_B [meV/K] % 0.057883818066 Bohr magneton: mu_B [meV/T] % 1.602176565e-19 electron charge: e [C] diff --git a/swfiles/@spinw/private/validate.m b/swfiles/@spinw/private/validate.m deleted file mode 100644 index 73e1ae3ad..000000000 --- a/swfiles/@spinw/private/validate.m +++ /dev/null @@ -1,133 +0,0 @@ -function validate(varargin) -% validates spinw object properties -% -% VALIDATE(obj, {fieldToValidate}) -% - -% Load data structure. -Datstruct = datastruct(); - -mainfield = Datstruct.mainfield; -subfield = Datstruct.subfield; -sizefield = Datstruct.sizefield; -typefield = Datstruct.typefield; - - - -% Validate only selected mainfield of the struct. -indexFieldToValidate = []; -if (nargin > 1) - if isa(varargin{2},'char') - fieldToValidate = varargin(2); - end - - for ii = 1:length(fieldToValidate) - indexFieldToValidate = [indexFieldToValidate find(strcmp(mainfield,fieldToValidate{ii}))]; %#ok - - end -end - -if isempty(indexFieldToValidate) - indexFieldToValidate = 1:length(mainfield); -end - -valid = true; -objS = struct(varargin{1}); -fieldM = ''; - -for ii = indexFieldToValidate - selectMainField = mainfield{ii}; - validT = isfield(objS,selectMainField); - if valid && ~validT - fieldM = selectMainField; - end - valid = valid && validT; - - for jj = 1:size(subfield,2) - selectSubField = subfield{ii,jj}; - if ~isempty(selectSubField) - validT = isfield(objS.(selectMainField),selectSubField); - if valid && ~validT - fieldM = [selectMainField '.' selectSubField]; - end - valid = valid && validT; - - end - end -end - -if ~valid - error('spinw:sw_valid:MissingField',['Input struct missing necessary field: ' fieldM '!']) -end - -% Save the type of error for easier debugging. -errorType = 0; -errorData = ''; - -for ii = indexFieldToValidate - selectMainField = mainfield{ii}; - for jj = 1:size(subfield,2) - selectSubField = subfield{ii,jj}; - selectType = typefield{ii,jj}; - selectSize = sizefield{ii,jj}; - - if ~isempty(selectSubField) - selectField = objS.(selectMainField).(selectSubField); - - % Check the dimension of the selected field. - objsize = size(selectField); - if length(objsize) < length(selectSize) - objsize((length(objsize)+1):length(selectSize)) = 1; - end - - % Check the size of th selected field. - for kk = 1:length(selectSize) - if ~ischar(selectSize{kk}) - valid = valid && (objsize(kk) == selectSize{kk}); - if ~errorType && ~valid - errorType = 1; - errorData = ['objS.' selectMainField '.' selectSubField]; - end - else - if exist(selectSize{kk},'var') - valid = valid && (objsize(kk) == eval(selectSize{kk})); - if ~errorType && ~valid - errorType = 1; - errorData = ['objS.' selectMainField '.' selectSubField]; - end - else - %assignin('caller',selectSize{kk},objsize(kk)); - eval([selectSize{kk} '=' num2str(objsize(kk)) ';']); - end - end - end - - % Check the type of the selected field. - if isa(selectField,'cell') - if ~isempty(selectField) - selectField = selectField{1}; - valid = valid && (isa(selectField,selectType) || isa(selectField,'sym')); - if ~errorType && ~valid - errorType = 2; - errorData = ['objS.' selectMainField '.' selectSubField]; - end - end - else - valid = valid && (isa(selectField,selectType) || isa(selectField,'sym')); - if ~errorType && ~valid - errorType = 2; - errorData = ['objS.' selectMainField '.' selectSubField]; - end - end - end - end -end - -switch errorType - case 1 - error('spinw:sw_valid:SizeMismatch',['Input argument size mismatch in: ' errorData]); - case 2 - error('spinw:sw_valid:TypeMismatch',['Input argument type mismatch in: ' errorData]); -end - -end \ No newline at end of file diff --git a/swfiles/@spinw/spinw.m b/swfiles/@spinw/spinw.m index f429391f5..894ec6daf 100644 --- a/swfiles/@spinw/spinw.m +++ b/swfiles/@spinw/spinw.m @@ -256,6 +256,7 @@ % kB Boltzmann constant, default is 0.0862 [meV/K] % muB Bohr magneton, default is 0.0579 [meV/T] % mu0 vacuum permeability, 201.335431 [T^2*Angstrom^3/meV] + % qmat transformation matrix that converts the given q-values unit % Stores the cache, it should be only used to check consistency of the code. % The stored values should not be changed by the user in any case! @@ -280,6 +281,11 @@ ver = sw_version; end + methods (Static) + % static methods + validate(varargin) + end + methods function obj = spinw(varargin) % SPINW constructor @@ -330,7 +336,7 @@ objS.lattice.angle = objS.lattice.angle'; end - validate(objS); + spinw.validate(objS); fNames = fieldnames(objS); for ii = 1:length(fNames) obj.(fNames{ii}) = objS.(fNames{ii}); diff --git a/swfiles/@spinw/spinwave.m b/swfiles/@spinw/spinwave.m index 5ac273a4c..8809b2abe 100644 --- a/swfiles/@spinw/spinwave.m +++ b/swfiles/@spinw/spinwave.m @@ -255,6 +255,9 @@ % whether the structure is incommensurate incomm = any(abs(km-round(km)) > param.tol); +% Transform the momentum values to the new lattice coordinate system +hkl = obj.unit.qmat*hkl; + % Calculates momentum transfer in A^-1 units. hklA = 2*pi*(hkl'/obj.basisvector)'; diff --git a/swfiles/@spinw/spinwavesym.m b/swfiles/@spinw/spinwavesym.m index 72c1d4b64..1e4bed2e4 100644 --- a/swfiles/@spinw/spinwavesym.m +++ b/swfiles/@spinw/spinwavesym.m @@ -118,8 +118,8 @@ % whether the structure is incommensurate incomm = any(~sw_always(abs(km-round(km)) <= param.tol)); -% symbolic wavevectors -hkl = param.hkl; +% symbolic wavevectors, convert to the model rlu +hkl = obj.unit.qmat*param.hkl; fid = obj.fid; diff --git a/swfiles/@spinw/validate.m b/swfiles/@spinw/validate.m index 73e1ae3ad..0a9413987 100644 --- a/swfiles/@spinw/validate.m +++ b/swfiles/@spinw/validate.m @@ -16,7 +16,7 @@ function validate(varargin) % Validate only selected mainfield of the struct. indexFieldToValidate = []; -if (nargin > 1) +if nargin > 1 if isa(varargin{2},'char') fieldToValidate = varargin(2); end diff --git a/swfiles/sw_res.m b/swfiles/sw_res.m index 9cc670c54..eb07fe502 100644 --- a/swfiles/sw_res.m +++ b/swfiles/sw_res.m @@ -25,11 +25,21 @@ % the length of p is n+1. % p(x)=p_1*x^n+p_2*x^(n-1)+...+p_n*x+p_(n+1). % +% Example: +% +% To calculate the resolution at an arbitrary energy use: +% +% pRes = sw_res(file,5,false); +% Evec = linspace(0,100,501); +% Eres = polyval(polyRes,Evec); +% plot(Evec,Eres); +% +% % See also POLYFIT, SW_INSTRUMENT. % if nargin == 0 - help sw_res; + help sw_res return end