Skip to content

Commit

Permalink
new spinw property to redefine rlu
Browse files Browse the repository at this point in the history
- added new spinw property spinw.unit.qmat that transforms any given
momentum value
- made spinw.validate() a static method
- minor changes
  • Loading branch information
tsdev committed Apr 11, 2017
1 parent d1a7b1b commit c3d48a7
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 164 deletions.
32 changes: 23 additions & 9 deletions swfiles/+ndbase/spaghetti.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
%
Expand All @@ -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{:});

Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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

Expand All @@ -167,6 +180,7 @@
box on
grid off
colormap(cm_viridis(500))
set(gca,'layer','top')
end

udat.x = ax{1};
Expand Down
4 changes: 2 additions & 2 deletions swfiles/@spinw/addatom.m
Original file line number Diff line number Diff line change
Expand Up @@ -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'};

Expand Down Expand Up @@ -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');

Expand Down
4 changes: 2 additions & 2 deletions swfiles/@spinw/addmatrix.m
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -174,6 +174,6 @@ function addmatrix(obj, varargin)
end
end

%validate(obj);
%spinw.validate(obj);

end
2 changes: 1 addition & 1 deletion swfiles/@spinw/gencoupling.m
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function gencoupling(obj, varargin)
obj.single_ion.aniso = aniso;
obj.single_ion.g = g;

validate(obj);
spinw.validate(obj);

end

Expand Down
2 changes: 1 addition & 1 deletion swfiles/@spinw/genmagstr.m
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,6 @@ function genmagstr(obj, varargin)
mag_str.F = S;

obj.mag_str = mag_str;
validate(obj);
spinw.validate(obj);

end
2 changes: 1 addition & 1 deletion swfiles/@spinw/optmagstr.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions swfiles/@spinw/private/datastruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -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'};...
Expand All @@ -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';...
Expand All @@ -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]
Expand Down
133 changes: 0 additions & 133 deletions swfiles/@spinw/private/validate.m

This file was deleted.

8 changes: 7 additions & 1 deletion swfiles/@spinw/spinw.m
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -280,6 +281,11 @@
ver = sw_version;
end

methods (Static)
% static methods
validate(varargin)
end

methods
function obj = spinw(varargin)
% SPINW constructor
Expand Down Expand Up @@ -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});
Expand Down
3 changes: 3 additions & 0 deletions swfiles/@spinw/spinwave.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)';

Expand Down
4 changes: 2 additions & 2 deletions swfiles/@spinw/spinwavesym.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion swfiles/@spinw/validate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit c3d48a7

Please sign in to comment.