Newer
Older
function list = gtCrystCalculateReflections(cryst, detgeo, energy, filename)
% GTCRYSTCALCULATEREFLECTIONS Calculate the reflections list using python
Laura Nervo
committed
% from xfab library in fable
% list = gtCrystCalculateReflections(cryst, detgeo, energy, [filename])
% -------------------------------------------------------------------
Laura Nervo
committed
% List of theoretical reflections for a given crystal system and spacegroup
%
% INPUT:
Laura Nervo
committed
% cryst = <struct> parameters.cryst(phaseid)
% labgeo = <struct> parameters.labgeo
% energy = <double> parameters.acq.energy (keV)
% filename = <string> filename for reflections list {'reflections_*.txt'}
%
% OUTPUT:
Laura Nervo
committed
% list = structure with fields (the same with 'sp' for the full lists)
% .hkl = reflection list <double>
% .theta = theta value for each reflection <double>
% .thetatype = theta type <double>
% .sinthl = sind(theta)/lambda <double>
Laura Nervo
committed
% .dspacing = d-spacing <double>
% .mult = multiplicity of each reflections <double>
%
%
Laura Nervo
committed
% Version 002 12-12-2012 by LNervo
% Compact output as a structure
%
% Version 001 03-12-2012 by LNervo
latticepar = cryst.latticepar;
sg = cryst.spacegroup;
minsintl = min(0.0001, sind(tmp)/gtConvEnergyToWavelength(energy));
maxsintl = sind(tmp)/gtConvEnergyToWavelength(energy);
if ~exist('filename','var') || isempty(filename)
Laura Nervo
committed
filename = 'reflections_';
end
Laura Nervo
committed
latticepar_str = sprintf('%f ',latticepar);
latticepar_str = strtrim(latticepar_str);
Laura Nervo
committed
% python script to be used
global GT_MATLAB_HOME;
script_file = fullfile(GT_MATLAB_HOME, 'zUtil_Python', 'reflections_list.py');
Laura Nervo
committed
% run the command for all the reflections
cmd = sprintf('%s %s %f %f %d %s %s', ...
script_file,latticepar_str,minsintl,maxsintl,sg,'all',filename);
[~, msg] = gtPythonCommand(cmd, true); disp(msg);
Laura Nervo
committed
% run the command for only the reflections unique
cmd = sprintf('%s %s %f %f %d %s %s', ...
script_file,latticepar_str,minsintl,maxsintl,sg,'unique',filename);
[~, msg] = gtPythonCommand(cmd, true); disp(msg);
Laura Nervo
committed
% read the full list of reflections
[~,Cmat] = gtReadTextFile([filename 'all.txt'],'%f %f %f %f',[1 3],true,'Delimiter','\n','CommentStyle','#');
Laura Nervo
committed
% extracting information
hklsp = Cmat(:,1:3);
sinthlsp = Cmat(:,4);
Laura Nervo
committed
Laura Nervo
committed
% read the full list of reflections
[~,Cmat] = gtReadTextFile([filename 'unique.txt'],'%f %f %f %f',[1 3],true,'Delimiter','\n','CommentStyle','#');
Laura Nervo
committed
% extracting information
hkl = Cmat(:,1:3);
sinthl = Cmat(:,4);
Laura Nervo
committed
if strcmp(cryst.crystal_system, 'hexagonal')
Laura Nervo
committed
% getting 4-indexes notation
hklsp(:,4) = hklsp(:,3);
hklsp(:,3) = -hklsp(:,1)-hklsp(:,2);
hkl(:,4) = hkl(:,3);
hkl(:,3) = -hkl(:,1)-hkl(:,2);
disp(' h k i l theta thetatype mult d-spacing');
disp('----------------------------------------------------------');
else
Laura Nervo
committed
disp(' h k l theta thetatype mult d-spacing');
disp('------------------------------------------------------');
end
Laura Nervo
committed
% extracting theta from sinthl = sin(theta)/lambda
thetasp = asind(sinthlsp*gtConvEnergyToWavelength(energy)); % fixed BUG !!!
theta = asind(sinthl*gtConvEnergyToWavelength(energy)); % fixed BUG !!!
[~, ind, thetatypesp] = unique(sinthlsp, 'stable');
thetatype = thetatypesp(ind);
mult = [ind(2:end)',length(thetatypesp)+1]-ind';
Bmat = gtCrystHKL2CartesianMatrix(latticepar);
dspacingsp = gtCrystDSpacing(hklsp', Bmat)';
dspacing = gtCrystDSpacing(hkl', Bmat)';
list.hklsp = hklsp';
list.hkl = hkl';
Laura Nervo
committed
list.thetasp = thetasp';
Laura Nervo
committed
list.theta = theta';
list.sinthlsp = sinthlsp';
Laura Nervo
committed
list.sinthl = sinthl';
Laura Nervo
committed
list.dspacingsp = dspacingsp';
Laura Nervo
committed
list.dspacing = dspacing';
list.thetatypesp = thetatypesp';
list.thetatype = thetatype';
Laura Nervo
committed
list.mult = mult;
list.int = ones(1,length(thetatype)); %dummy values
list.intsp = ones(1,length(thetatypesp)); %dummy values
Laura Nervo
committed
list.indfam = ind';
for ii=1:length(list.thetatype)
if ~strcmp(cryst.crystal_system, 'hexagonal')
fprintf( '%3d %3d %3d %9.3f %5d %10d %10.3f\n',list.hkl(:,ii),list.theta(ii),list.thetatype(ii),list.mult(ii),list.dspacing(ii) );
else
fprintf( '%3d %3d %3d %3d %9.3f %5d %10d %10.3f\n',list.hkl(:,ii),list.theta(ii),list.thetatype(ii),list.mult(ii),list.dspacing(ii) );
end
end
Laura Nervo
committed
end % end of function