diff --git a/1_preprocessing/gtFillCrystFields.m b/1_preprocessing/gtFillCrystFields.m new file mode 100644 index 0000000000000000000000000000000000000000..3c3e65fbe212d95065e183a17fc800946989bcd3 --- /dev/null +++ b/1_preprocessing/gtFillCrystFields.m @@ -0,0 +1,312 @@ + +function parameters = gtFillCrystFields(parameters, phase_ndx) +% +% fill in the cryst(phase_ndx) +% handle all crystallography stuff in one easy function... +% +% concept - we need certain information about each phase, and we have to get +% this from somewhere. This could be from a .dat file created by XOP, a +% .cif file from Diamond or somewhere else, or could be supplied from the +% head of the user - we should not be fussy. +% +% The user should not have to copy anything - as long as the files are on +% disk, we should move them to the right place +% For the moment at least, keep the concept of archiving a dat and cif +% file for every dataset in id11/graintracking/ +% +% Information to deal with: +% +% We already have: +% energy, max and min two theta values +% +% We need to get: +% {hkl} or {hkil} reflections +% lattice parameters +% spacegroup +% +% Optional, but nice, are: +% calculated intensities +% symmetry operators (although we don't use this info yet...) +% +% We generate ourselves: +% crystal system and lattice type we can get from spacegroup number +% signed hkls we generate by applying the (hard coded) symmetry operators +% d spaces from hkls and lattice parameters +% theta from dspacing and energy +% +% + +disp(sprintf(' ~~~~~~~~~~~~~ Get crystallography information for phase %d ~~~~~~~~~~~~~ ', phase_ndx)) + +% now fill in this information for this phase +phase_ok=false; +while ~phase_ok + + % is this part of a series of measurements? In this case we can simply + % copy from another parameters file + disp(['If you have already measured this material with same geometry and conditions, ' ... + 'you can copy from another parameters file. If the experimental geometry is different, '... + 'it may be safer to load from a data file prepared for the specific conditions']) + + test = input('Do this? [y/n] ', 's'); + if strcmpi(test, 'y') | strcmpi(test, 'yes') + %%%% get complete information from another parameters file %%%%% + parameters = sfGetInfoFromParameters(parameters, phase_ndx); + + else + %%%% get information from files or user %%%%% + + + % Get reflection data + disp(['Do you want to load reflection data from .csv or .dat files?']) + test = input('Do this? [y/n] ', 's'); + if strcmpi(test, 'y') | strcmpi(test, 'yes') + parameters = sfGetReflectionInfoFromDataFiles(parameters, phase_ndx); + else + parameters = sfGetReflectionInfoFromUser(parameters, phase_ndx); + end + + % Get crystallographic data + disp(['Do you want to load crystallographic info (lattice pars, symmetry) from a .cif file?']) + test = input('Do this? [y/n] ', 's'); + if strcmpi(test, 'y') | strcmpi(test, 'yes') + parameters = sfGetCrystInfoFromDataFiles(parameters, phase_ndx); + else + parameters = sfGetCrystInfoFromUser(parameters, phase_ndx); + end + + % expand the input data + parameters = sfExpandData(parameters, phase_ndx); + + end + + + + + % Check things look okay + test = input(['Do you want to look at the contents of cryst for this phase? [y/n] '], 's'); + if strcmpi(test, 'y') | strcmpi(test, 'yes') + parameters = sfCheckWithUser(parameters, phase_ndx); + end + + + % does this look ok? + test = input(['Is this phase OK? [y/n] '], 's'); + if strcmpi(test, 'y') | strcmpi(test, 'yes') + phase_ok=true; + disp('') + + disp('Saving parameters.mat in the analysis directory...') + parameters_name=fullfile(parameters.acq.dir,'parameters.mat') + save(parameters_name, 'parameters') + disp(sprintf(' ~~~~~~~~~~~~~ Finished getting crystallography information for phase %d ~~~~~~~~~~~~~ ', phase_ndx)) + end + +end % end while loop + + +end % end of the main function + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% SUB FUNCTIONS + +function parameters=sfCheckWithUser(parameters, ii) +% show the user the cryst field so they can decide if it looks ok +parameters.cryst(ii) + +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%% COPY FROM A PARAMETERS.MAT FILE %%%%%%%%%%%%%% +% in this case, will fill cryst directly +function parameters = sfGetInfoFromParameters(parameters, ii) + +% get the master parameters +[masterfile, masterpath]=uigetfile('parameters.mat'); +if strcmp(masterfile, 'parameters.mat') + master=load(fullfile(masterpath, masterfile)); + % if there is more than one phase + if length(master.parameters.cryst)>1 + query='Which phase to use? '; + for m=1:length(master.parameters.cryst) + query=[query sprintf('(%d) %s; ', m, master.parameters.cryst(m).name)]; + end + query=[query '[1/2/3...] ']; + mm=input(query); + else + mm=1; + end + % add these values to our parameters field + parameters.cryst(ii) = gtAddMatFile(parameters.cryst(ii),master.parameters.cryst(mm),true,true,true); + % keep track of where we got the data from + + % create the xop directory in which to save the files used + [xop_dir,msg] = gtCrystXopInitializeDirectory(parameters.acq.name, parameters.cryst(ii).name); + parameters.xop(ii).xop_dir=xop_dir; + parameters.xop(ii).filename='master_parameters.mat'; + % copy the parameters file that we used as the reference + copyfile(fullfile(masterpath, masterfile), fullfile(xop_dir, 'master_parameters.mat')) + % return to the main loop to allow user to check manually +end +end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% LOAD FROM A DATA FILEs (.CSV or .DAT, AND .CIF) %%%%%%%% +% will fill xop with "raw" data +function parameters = sfGetReflectionInfoFromDataFiles(parameters, ii) + +% this is a "new" experiment, set up the names and read from the datafile +disp(sprintf('Before loading, please give a description for this phase (%d)', ii)) +% get this stuff via gtModfiyStructure +biglist=build_list_v2; +list=biglist.cryst; +listndx=find( strcmp(list(:,1), 'name') | strcmp(list(:,1), 'composition') | strcmp(list(:,1), 'material')); +list=list(listndx, 1:2); +parameters.cryst(ii)=gtModifyStructure(parameters.cryst(ii), list, sprintf('Manual input of crystallographic parameters for phase %d', ii)); + +% create the xop directory in which to save the files used +[xop_dir,msg] = gtCrystXopInitializeDirectory(parameters.acq.name, parameters.cryst(ii).name); + +% get a data file to try +disp('Please select a data file from which to load powder diffraction data') +% pick a suitable datafile +[datafile, datapath]=uigetfile('*.csv; *.dat', 'Select a powder diffraction data file', '/data/id11/graintracking/'); +% try to read from it +try + xop = gtLoadReflectionsFromFile(fullfile(datapath, datafile)); + parameters.xop(ii) = gtAddMatFile(parameters.xop(ii),xop,true,true,false); + clear xop + % copy the file that we used + copyfile(fullfile(datapath, datafile), fullfile(xop_dir, datafile)) + parameters.xop(ii).xop_dir=xop_dir; + parameters.xop(ii).filename=datafile; + disp('read some powder diffraction data') + % add this data to parameters.cryst + +catch + disp('Did not manage to read frlom the file you chose!') + disp('keep trying - possibly with a different datafile or manual input') + return +end +end % end sfGetReflectionInfoFromDataFiles +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function parameters = sfGetCrystInfoFromDataFiles(parameters, ii) +% need to get spacegroup and lattice parameters from a .cif file +% this goes into parameters.cryst + +[ciffile, cifpath]=uigetfile('*.cif', 'Select a suitable crystallography file', '/data/id11/graintracking/'); +cif = gtCrystCifInitialize(fullfile(cifpath, ciffile)); +parameters.cryst(ii) = gtAddMatFile(parameters.cryst(ii),cif,true,true,false); +clear cif +% copy the file that we used to the xop_dir +copyfile(fullfile(cifpath, ciffile), fullfile(parameters.xop(ii).xop_dir, ciffile)) + +end % read of sfGetCrystInfoFromDataFiles +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function parameters = sfGetReflectionInfoFromUser(parameters, ii) +% get info interactively + +disp(sprintf('Please give a description for this phase (%d)', ii)) + +% We need to get: +% {hkl} or {hkil} reflections +% lattice parameters +% spacegroup +% get the list for the fields we are interested in +% in parameters.cryst +biglist=build_list_v2; +list=biglist.cryst; +listndx=find( strcmp(list(:,1), 'name') | strcmp(list(:,1), 'composition') | strcmp(list(:,1), 'material')); +list=list(listndx, 1:2); +parameters.cryst(ii)=gtModifyStructure(parameters.cryst(ii), list, sprintf('Manual input of reflections for phase %d', ii)); + +% create the xop directory in which to save the files used +[xop_dir,msg] = gtCrystXopInitializeDirectory(parameters.acq.name, parameters.cryst(ii).name); +% no datafile to copy in this case + +% in parameters .xop +hkl=input('Manually input the hkl families as an nx3 matrix: [h1 k1 l1; h2 k2 l2; etc]') +parameters.xop(ii).hkl=hkl; +disp('filling parameters.xop.int and mult with ones') +parameters.xop(ii).int=ones(size(hkl)); +parameters.xop(ii).mult=ones(size(hkl)); + +end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function parameters = sfGetCrystInfoFromUser(parameters, ii) +% need to get spacegroup and lattice parameters from a .cif file +% We need to get: +% lattice parameters +% spacegroup +% get the list for the fields we are interested in +% in parameters.cryst +biglist=build_list_v2; +list=biglist.cryst; + listndx=find( strcmp(list(:,1), 'latticepar') | strcmp(list(:,1), 'spacegroup')) +list=list(listndx, 1:2); +parameters.cryst(ii)=gtModifyStructure(parameters.cryst(ii), list, sprintf('Manual input of crystallographic parameters for phase %d', ii)); +end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function parameters = sfExpandData(parameters, ii) +% file parameters.cryst from reflection data in parameters.xop and symmetry +% and lattice parameters in parameters.cryst + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Get crystal system and lattice from the spacegroup number +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +[lattice_system, crystal_system, ~] = gtReadSpaceGroup(parameters.cryst(ii).spacegroup); +parameters.cryst(ii).lattice_system = lattice_system; +parameters.cryst(ii).crystal_system = crystal_system; +clear lattice_system crystal_system + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% getting reflection on the detector, basing on theta max and min +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% after xop +% this cleans the xop output into distinct hkl families +% and recalculates dspacings and thetas according to parameters +% discards anything not on the detector +% this info goes into the parameters.cryst field +detector = gtDetectorTwotheta(parameters, ii); +parameters.cryst(ii) = gtAddMatFile(parameters.cryst(ii),detector,true,true,false); +clear detector + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Using symmetry operators getting all the possible reflections +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% this expands the hkl families in parameters.cryst +hklsymmetry = gtSymmetricReflections(parameters.cryst(ii),parameters.acq.energy); +parameters.cryst(ii) = gtAddMatFile(parameters.cryst(ii),hklsymmetry,true,true,false); +clear hklsymmetry + +% Transpose arrays to have rows +parameters.cryst(ii).hkl = parameters.cryst(ii).hkl'; +parameters.cryst(ii).thetatype = parameters.cryst(ii).thetatype'; +parameters.cryst(ii).theta = parameters.cryst(ii).theta'; +parameters.cryst(ii).dspacing = parameters.cryst(ii).dspacing'; +parameters.cryst(ii).int = parameters.cryst(ii).int'; +parameters.cryst(ii).mult = parameters.cryst(ii).mult'; + +parameters.cryst(ii).hklsp = parameters.cryst(ii).hklsp'; +parameters.cryst(ii).thetatypesp = parameters.cryst(ii).thetatypesp'; +parameters.cryst(ii).thetasp = parameters.cryst(ii).thetasp'; +parameters.cryst(ii).dspacingsp = parameters.cryst(ii).dspacingsp'; +parameters.cryst(ii).intsp = parameters.cryst(ii).intsp'; +end diff --git a/1_preprocessing/gtSetup.m b/1_preprocessing/gtSetup.m index f077ed4d37aa9db36eb402bc93c5f0320c18feaf..bea17844a47844111f24a164bc3b8ceb5025362e 100644 --- a/1_preprocessing/gtSetup.m +++ b/1_preprocessing/gtSetup.m @@ -319,105 +319,19 @@ save(parameters_name,'parameters'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nof_phases = 1; parameters.acq.nof_phases = inputwdefaultnumeric('Number of crystallographic phases to be analysed in this sample? ', num2str(nof_phases)); -p = make_parameters(2); - +% get Cryst field information for all phases +p = make_parameters(2); for ii = 1 : parameters.acq.nof_phases + % make a subfolder in 4_grains + [~,msg] = mkdir( fullfile(parameters.acq.dir, '4_grains', sprintf('phase_%02d', ii)) ); disp(msg) + % initialise empty fields parameters.xop(ii) = p.xop; parameters.cryst(ii) = p.cryst; + % fill cryst(ii) + parameters = gtFillCrystFields(parameters, ii); - [~,msg] = mkdir( fullfile(parameters.acq.dir, '4_grains', sprintf('phase_%02d', ii)) ); disp(msg) - - parameters.cryst(ii).name = ... - input(sprintf('Name of phase %d to display (e.g. Al, Austenite, Beta_Titanium): ',ii), 's'); - - parameters.cryst(ii).composition = ... - input(sprintf('Chemical composition of phase %d (eg. BaTiO3): ',ii), 's'); - - parameters.cryst(ii).material = ... - input(sprintf('Reference material name of phase %d (eg. AlLi_July2012_recrystallized): ',ii), 's'); - - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % Crystallography reflections from Diamond/xop - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % Get list of reflecting plane families (unique, no multiplicity) - - material = input(sprintf('Material name in XOP or Diamond file of phase %d (eg. Ti): ',ii), 's'); - - [xop,xopmsg] = gtCrystXopInitialize(parameters.acq.name, material); - parameters.xop(ii) = gtAddMatFile(parameters.xop(ii),xop,true,true,false); - clear xop - - disp('Saving parameters.mat in the analysis directory...') - save(parameters_name,'parameters'); - - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % Crystallography parameters - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % Add lattice parameters, crystal system, symm operators, etc. - % look for standard .cif file - cifname = fullfile( '/data','id11','graintracking','file_cif', [material '.cif']); - if ~exist(cifname,'file') - disp(['Create the right .cif file for the current phase with name\n\t' material '.cif' ... - 'and copy it to the folder:\n\t' parameters.xop(ii).xop_dir]) - else - [~,msg]=copyfile(cifname,parameters.xop(ii).xop_dir); disp(msg) - end - - cifname = fullfile( parameters.xop(ii).xop_dir, [material '.cif']); - % load the cif file - cif = gtCrystCifInitialize(cifname); - parameters.cryst(ii) = gtAddMatFile(parameters.cryst(ii),cif,true,true,false); - clear cif - - % crystal_system should be read from .cif file - % it is overwritten here - [lattice_system, crystal_system, ~] = gtReadSpaceGroup(parameters.cryst(ii).spacegroup); - parameters.cryst(ii).lattice_system = lattice_system; - parameters.cryst(ii).crystal_system = crystal_system; - clear lattice_system crystal_system - - disp('Saving parameters.mat in the analysis directory...') - save(parameters_name,'parameters'); - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % getting reflection on the detector, basing on theta max and min - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % after xop - detector = gtDetectorTwotheta(parameters, ii); - parameters.cryst(ii) = gtAddMatFile(parameters.cryst(ii),detector,true,true,false); - clear detector - - disp('Saving parameters.mat in the analysis directory...') - save(parameters_name,'parameters'); - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % Using symmetry operators getting all the possible reflections - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - hklsymmetry = gtSymmetricReflections(parameters.cryst(ii),parameters.acq.energy); - parameters.cryst(ii) = gtAddMatFile(parameters.cryst(ii),hklsymmetry,true,true,false); - clear hklsymmetry - - % Transpose arrays to have rows - parameters.cryst(ii).hkl = parameters.cryst(ii).hkl'; - parameters.cryst(ii).thetatype = parameters.cryst(ii).thetatype'; - parameters.cryst(ii).theta = parameters.cryst(ii).theta'; - parameters.cryst(ii).dspacing = parameters.cryst(ii).dspacing'; - parameters.cryst(ii).int = parameters.cryst(ii).int'; - parameters.cryst(ii).mult = parameters.cryst(ii).mult'; - - parameters.cryst(ii).hklsp = parameters.cryst(ii).hklsp'; - parameters.cryst(ii).thetatypesp = parameters.cryst(ii).thetatypesp'; - parameters.cryst(ii).thetasp = parameters.cryst(ii).thetasp'; - parameters.cryst(ii).dspacingsp = parameters.cryst(ii).dspacingsp'; - parameters.cryst(ii).intsp = parameters.cryst(ii).intsp'; - - disp('Saving parameters.mat in the analysis directory...') - save(parameters_name,'parameters'); - end % end crystallography diff --git a/zUtil_Cryst/gtCrystXopInitializeDirectory.m b/zUtil_Cryst/gtCrystXopInitializeDirectory.m new file mode 100644 index 0000000000000000000000000000000000000000..959f2918fcceae7b70ea57f7cbcb23f41905e7d6 --- /dev/null +++ b/zUtil_Cryst/gtCrystXopInitializeDirectory.m @@ -0,0 +1,74 @@ +function [xop_dir,msg] = gtCrystXopInitializeDirectory(name, material) +% GTCRYSTXOPINITIALIZEDIRECTORY +% Creates the directory in /data/id11/graintracking/file_xop for this sample +% ------------------------------------------------ +% +% INPUT: +% name = parameters.acq.name +% +% OUTPUT: +% xop_dir = the name of the directory created +% + +top_xop_dir=fullfile('/data','id11','graintracking','file_xop'); +dataset_xop_dir=fullfile('/data','id11','graintracking','file_xop', name); +material_xop_dir=fullfile('/data','id11','graintracking','file_xop', name, material); + +% create top level directory if needed +if ~exist(top_xop_dir,'dir') + [~,msg]=mkdir(top_xop_dir); disp(msg) +end + +% now create directory for the dataset +if ~exist(dataset_xop_dir,'dir') + % this is the first time - create directory for the dataset + [~,msg]=mkdir(dataset_xop_dir); disp(msg) +end + +% now create a sub-directory for this material +if ~exist(material_xop_dir,'dir') + % this is the first time - create sub-directory for the material + [~,msg]=mkdir(material_xop_dir); disp(msg) + xop_dir=material_xop_dir; +else + % we already have a directory, so create a new one for this date + xop_dir=fullfile(material_xop_dir, date()); + [~,msg]=mkdir(xop_dir); disp(msg) +end + + + +% for this function, nothing else is needed. Everything else will go +% inside this folder +%else + % xop_dir=fullfile(xop_dir, name, material, date()); + % [~,msg]=mkdir(xop_dir); disp(msg) +% elseif ~exist(fullfile(xop_dir,name, material),'dir') +% xop_dir=fullfile(xop_dir, name, material); +% [~,msg]=mkdir(xop_dir); disp(msg) + + +% % read info from xop/diamond +% disp('Please create the .csv or .dat file from Diamond or xop') +% disp('and copy it in this folder:') +% disp(xop_dir) +% disp('using <material>.csv from Diamond or <material>.dat from xop') +% check=inputwdefault('Have you done this? [y/n]','n'); +% if strcmpi(check,'y') +% xop=gtLoadReflections(xop_dir); +% msg=[]; +% else +% xop=[]; +% msg=['Before running gtPreprocessing, run by yourself this lines:'... +% ' cd(ANALYSIS_DIR) '... +% ' load(parameters);'... +% ' xop_dir=' xop_dir... +% ' xop=gtLoadReflections(xop_dir);'... +% ' parameters.xop=xop;'... +% ' save parameters parameters']; +% % need more instructions here to complete parameters.cryst +% end +% +% xop.xop_dir = xop_dir; + +end % end of function \ No newline at end of file diff --git a/zUtil_Cryst/gtDetectorTwotheta.m b/zUtil_Cryst/gtDetectorTwotheta.m index fb38ebf9363b98925d4620b8f97755f97cdd71d7..835227c82d011c2427b0c6645fabc92cc8faaa6d 100644 --- a/zUtil_Cryst/gtDetectorTwotheta.m +++ b/zUtil_Cryst/gtDetectorTwotheta.m @@ -46,13 +46,20 @@ disp(['Saved xop reflections: ' num2str(size(parameters.xop(phaseID).hkl,1))] results=[]; hkl = gtFindFamilies(parameters,'hkl', phaseID); -tt = gtFindFamilies(parameters,'twotheta', phaseID); -d0 = gtFindFamilies(parameters,'dspacing', phaseID); +%tt = gtFindFamilies(parameters,'twotheta', phaseID); +%d0 = gtFindFamilies(parameters,'dspacing', phaseID); int = gtFindFamilies(parameters,'int', phaseID); mult = gtFindFamilies(parameters,'mult', phaseID); disp(['hkl total families: ' num2str(size(hkl,1))]) +% ensure that the angles we have are correct for the energy and lattice parameters +% in the parameters file +for j = 1:size(hkl,1) + % calculate d-spacing and twotheta for each reflection + [d0(j), tt(j)] = gtCalculateDist(hkl(j,:), parameters.cryst(phaseID), parameters.acq.energy); +end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Keep only reflections on the detector %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/zUtil_Cryst/gtLoadReflectionsFromFile.m b/zUtil_Cryst/gtLoadReflectionsFromFile.m new file mode 100644 index 0000000000000000000000000000000000000000..519c192bf31dcda380001bc3eb201006f157341c --- /dev/null +++ b/zUtil_Cryst/gtLoadReflectionsFromFile.m @@ -0,0 +1,109 @@ +function xop = gtLoadReflectionsFromFile(file) +% GTLOADREFLECTIONSFROMFILE +% Specifiy the file from which to load +% Loads the list of reflections (hkl, intensity, +% multiplicity, 2theta, d-spacing) from text files saved from Diamond +% (.csv) or XOP (.dat). +% +% xop = gtLoadReflectionsFromFile(filename) +% -------------------------------- +% Reads from the specified file +% If the file is not the right type, it gives instructions for how to +% get the right thing. + +% Diamond -> .csv parameters file +% XOP -> .dat parameters file +% INPUT: +% filename (including path) +% +% OUTPUT : +% xop = structure with fields from the text file +% + + +isreflections=true; +if ~isempty(strfind(file,'.csv')) + % .csv file + delim=';'; + pattern='%d8 %f32 %f32 %f32 %f32 %d8 %d8 %d8 %d8'; + a=6;b=7; + columns=9; +elseif ~isempty(strfind(file,'.dat')) && ~strcmpi(file,'spacegroups.dat') + % .dat file + delim='space'; + pattern='%d8 %d8 %d8 %f32 %f32 %f32 %f32 %d8 %f32 %f32'; + a=1;b=2; + columns=10; +else + % give the info message + disp('The file selected is not the right kind (.csv or .dat) ') + disp(' ') + disp('If you have a .cif file for the current material, open it with Diamond') + disp(' and let the program create the structure picture. Check the option ''Create packaing diagram''') + disp(' and leave unchecked the option ''Connect atoms''.') + disp(' When finished, show the powder pattern (top right corner) and select a wavelength') + disp(' value in Angstrom, 2theta minimum and maximum in degrees.') + disp(' Press enter when finished to calculate the reflection parameters.') + disp(' Right-Click on the table header and save it as .csv file in the local directory. Close Diamond.') + disp(' ') + disp('If you don''t have a .cif file for the current material, open xop shell program.') + disp(' On the top menu choose ''Optics'', ''Crystals'' and ''XPOWDER''.') + disp(' In the tab ''Unit Cell'' insert the lattice parameters') + disp(' and the atoms positions in the unit cell. Refer to the International Tables of Crystallography.') + disp(' When done, click on tab ''Reflections'' and ''Set Parameters''.') + disp(' Set the wavelength and the maximum value for 2-theta and click on ''Accept''.') + disp(' Finally save the table in a .dat file in the local directory and use the function ''gtLoadReflections'' again.') + disp(' ') + disp('If you are really depressed, use this link to find the atoms positions:') + disp(' http://it.iucr.org/Ab/ch7o1v0001/') + + isreflections=false; +end + + + +if isreflections + disp(['Opening file ' char(file) '...']) + fid=fopen(file,'r'); + if fid==-1 + disp('Error opening file...') + return + end + if strcmpi(delim,'space') + testo = textscan(fid,'%s',columns); + C = textscan(fid,pattern); + else + testo = textscan(fid,'%s',columns,'delimiter',delim); + C = textscan(fid,pattern,'delimiter',delim); + end + fclose(fid); + + testo=char(testo{1}); + for i=1:columns + title = testo(i,:); + title = strtrim(title); + title = lower(title); + title = strrep(title,'.',''); + title = regexprep(title,'[^a-zA-Z]',''); + title = regexprep(title,'theta','twotheta'); + if length(title)==1 + title = regexprep(title,'m','mult'); + title = regexprep(title,'^f','formfactor'); + end + title = strtrim(title); + title = strrep(title,'dspc','dspacing'); + if ~strcmpi(title,'no') + reflections.(title)=C{i}; + end + end + + reflections.hkl=[reflections.h reflections.k reflections.l]; + reflections=rmfield(reflections,{'h','k','l'}); + + xop = reflections; + ind=strfind(file,filesep); + xop.filename = file(ind(end)+1:end); +end + +end % end of function + diff --git a/zUtil_Parameters/build_list_v2.m b/zUtil_Parameters/build_list_v2.m index 6d667af25f014036b65b285342e386fa0265878e..b41f95cbf92760ec657e55f2f0b8fed7ae03c1cf 100644 --- a/zUtil_Parameters/build_list_v2.m +++ b/zUtil_Parameters/build_list_v2.m @@ -165,7 +165,7 @@ list.xop{8,1} = 'xop_dir'; list.xop{8,2} = 'Director % In case of one phase only, both 'list.cryst(1)' and 'list.cryst' can be % used in Matlab to refer to that phase. -list.cryst{1,1} = 'name'; list.cryst{1,2} = 'Name of phase to display'; +list.cryst{1,1} = 'name'; list.cryst{1,2} = 'Name of phase to display (e.g. Al, Austenite, Beta_Titanium)'; list.cryst{1,3} = 'char'; list.cryst{2,1} = 'composition'; list.cryst{2,2} = 'Chemical composition of phase (e.g BaTiO3)'; list.cryst{2,3} = 'char';