Skip to content
Snippets Groups Projects
gtCrystSignedHKLs.m 3.03 KiB
Newer Older
function [allshkls, allhklinds, mult, hklsp, thtype]  = gtCrystSignedHKLs(hkl, symm)
% GTCRYSTSIGNEDHKLS  Gives a complete list of signed hkl planes, by
%     applying symmetry operators of the specified spacegroup to the input
%     list of plane families.
%     Should be revised for at least other than cubic lattices. Use of 
%     'lattice_system' and 'crystal_system' instead of spacegroups should
%     be considered.
%
%     [allshkls, allhklinds, mult, hklsp, thtype] = gtCrystSignedHKLs(hkl, symm)
%     --------------------------------------------------------------------------
%       hkl        = <double>     plane families (one in a row) as in
%                                 parameters.cryst
%                                 (n,3) for cubic lattices 
%                                 (n,4) for hexagonal lattices
%       symm       = <struct>     structure containing .g3/.g with symmetry
%                                 operators
%       allshkls   = <double>     complete list of signed hkl planes
%       allhklinds = <double>     indices in allshkls according to input hkl 
%       mult       = <double>     multiplicity of hkl families (1,k)
%       hklsp      = <double>     list of all the hkls (friedel not considered)
%       thtype     = <double>     theta types among the given reflections
%                                 according to input hkl
%
%
%     Version 003 21-08-2013 by LNervo
%       Added output hklsp and thtype to simplify calculation
%     Version 002 10-07-2013 by LNervo
%       Added check of class for hkl list


if ~isa(hkl,'double')
    hkl = double(hkl);
end

if ~exist('symm','var') || isempty(symm)
    load parameters
    % Get symmetry operators
    symm = gtCrystGetSymmetryOperators(parameters.cryst.crystal_system, parameters.cryst.spacegroup);
if size(hkl,2) == 4
    symm = {symm.g};
elseif size(hkl,2) == 3
    symm = {symm.g3};
if ncols > 4
    gtError('gtCrystSignedHKLs:wrongSize','Something went wrong with the size of hkl list...Quitting')
end
mult       = [];
hklsp      = [];
thtype     = [];
    % Apply all symmmetry operators to the hkl type to get signed hkl-s
	    	shkls(2*jj-1,:) =  hkl(ii,:)*symm{jj};
	    	shkls(2*jj,:)   = -shkls(2*jj-1,:);  % Friedel pair of previous one
	  % Remove duplicates and add to the complete list
    newshkls = unique(shkls, 'rows');
    % sort according to h > k > l
    newshkls = sortrows(newshkls, [-1 -2 -ncols]);
    nhkls = size(newshkls,1)/2;
    mult       = [mult; nhkls*2];
    allshkls   = [allshkls; newshkls];
    allhklinds = [allhklinds; repmat(ii,nhkls*2,1)];
    %newshkls   = sortrows(newshkls, [ncols 1 2]); 
    hklsp      = [hklsp; newshkls(nhkls+1:end,:)];
    thtype     = [thtype; repmat(ii,nhkls,1)];
end % end of function