editCrystalDefinition

PURPOSE ^

text based tool to create a crystal definition

SYNOPSIS ^

function cdef = editCrystalDefinition(cdef)

DESCRIPTION ^

 text based tool to create a crystal definition

 Syntax: editCrystalDefinition
 
 editCrystalDefinition guides you in creating the data to define a
   crystal: symmetry, lattice parameters and Miller indices. From the
   tool, you can print these information, view the crystal with all facets
   and write it into the database folder.

 The above syntax starts with an empty crystal definition structure while
   using editCrystalDefinition(cdef) starts with the structure in cdef or
   when cdef is a string, it loads the case from the database (no generic
   parameter is supported).
 cdef = editCrystalDefinition also returns the data structure to the
   workspace. It has the fields:

 cdef = editCrystalDefinition(cdef) does return the defined crystal in a
 structure:
    .sym           symmetry information
    .sym.defined   just a number indexing the symmetry class
    .sym.system    crystal family, like cubic or tetragonal
    .lat           lattice parameters
      .unit_angle     unit for angles {degree, radian}
      .unit_length    unit for length scales {aengstroem}
      .a / .b / .c    length of crystallographic unit vectors
      .alpha / .beta / .gamma    angles between crystallographic axes
    .millerDefined    explicitely defined forms of the crystal
    .millerComplete   all facets of the crystal generated from
                       millerDefined by given symmetry
    .A             cartesian unit vectors of facets in an m by 3
                       matrix. Please refere to H-representation in
                       Elk-toolbox.
    .groupMappingMatrix - group mapping from millerDefined to vectors
                       in A.
    .mapMillerToReal - coordinate transformation from crystal system to
                   Cartesian system
    .mapRealToMiller - the reverse transformation from above

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cdef = editCrystalDefinition(cdef)
0002 % text based tool to create a crystal definition
0003 %
0004 % Syntax: editCrystalDefinition
0005 %
0006 % editCrystalDefinition guides you in creating the data to define a
0007 %   crystal: symmetry, lattice parameters and Miller indices. From the
0008 %   tool, you can print these information, view the crystal with all facets
0009 %   and write it into the database folder.
0010 %
0011 % The above syntax starts with an empty crystal definition structure while
0012 %   using editCrystalDefinition(cdef) starts with the structure in cdef or
0013 %   when cdef is a string, it loads the case from the database (no generic
0014 %   parameter is supported).
0015 % cdef = editCrystalDefinition also returns the data structure to the
0016 %   workspace. It has the fields:
0017 %
0018 % cdef = editCrystalDefinition(cdef) does return the defined crystal in a
0019 % structure:
0020 %    .sym           symmetry information
0021 %    .sym.defined   just a number indexing the symmetry class
0022 %    .sym.system    crystal family, like cubic or tetragonal
0023 %    .lat           lattice parameters
0024 %      .unit_angle     unit for angles {degree, radian}
0025 %      .unit_length    unit for length scales {aengstroem}
0026 %      .a / .b / .c    length of crystallographic unit vectors
0027 %      .alpha / .beta / .gamma    angles between crystallographic axes
0028 %    .millerDefined    explicitely defined forms of the crystal
0029 %    .millerComplete   all facets of the crystal generated from
0030 %                       millerDefined by given symmetry
0031 %    .A             cartesian unit vectors of facets in an m by 3
0032 %                       matrix. Please refere to H-representation in
0033 %                       Elk-toolbox.
0034 %    .groupMappingMatrix - group mapping from millerDefined to vectors
0035 %                       in A.
0036 %    .mapMillerToReal - coordinate transformation from crystal system to
0037 %                   Cartesian system
0038 %    .mapRealToMiller - the reverse transformation from above
0039  
0040 % The elk-library: convex geometry applied to crystallization modeling.
0041 %   Copyright (C) 2013 Alexander Reinhold
0042 %
0043 % This program is free software: you can redistribute it and/or modify it
0044 %   under the terms of the GNU General Public License as published by the
0045 %   Free Software Foundation, either version 3 of the License, or (at your
0046 %   option) any later version.
0047 %
0048 % This program is distributed in the hope that it will be useful, but
0049 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0050 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0051 %   General Public License for more details.
0052 %
0053 % You should have received a copy of the GNU General Public License along
0054 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0055 
0056 %% Initialize
0057 % handle input for crystal definition
0058 if ~exist('cdef', 'var')
0059     cdef = struct();
0060 end
0061 
0062 if ischar(cdef)
0063     cdef = obtainCrystal(cdef);
0064 elseif ~isstruct(cdef)
0065     error('elk:crystal:wrongInput', ['Input must be a crystal definition ' ...
0066         'structure or a string to be called with obtainCrystal']);
0067 end
0068 
0069 
0070 % load pointgroup informations
0071 P = executeExternBorchertFunction('pointgroup');
0072 P = reshape(struct2cell(P), [9,32]);
0073 % 1-Schonflies Notation, 2-Hermann-Mauguin Notation, 3-Symmetry Elements,
0074 %   4-Laue Class, 5-Crystal Family, 6-Number, 7-Trivialname, 8-, 9-Minv
0075 %   replace crystal family names
0076 
0077 % translate abbrevations in CF to full names and numbers to strings
0078 for i = 1:size(P, 2)
0079     P{5, i} = abbreviateCrystalSystem(P{5, i});
0080     P{6, i} = num2str(P{6, i});
0081 end
0082 
0083 % set some control value
0084 control = -1;
0085 
0086 while control ~= 0
0087     %% Main Program Loop
0088     clc
0089     disp(' /----------------------------------\');
0090     disp('|   Interactive Crystal Definition   |');
0091     disp(' \----------------------------------/');
0092     disp(' ');
0093     disp('   During this setup, you will specify crystal symmetry, lattice ');
0094     disp('   parameters and Miller indices of faces. From these informations');
0095     disp('   the facet normals in cartesian space are calculated.');
0096     disp(' ');
0097     disp('Main Menu');
0098     list = {};
0099     % Symmetry
0100     if isfield(cdef, 'sym') && isfield(cdef.sym, 'defined')
0101         list{1} = 'Delete Crystal Symmetry';
0102     elseif isfield(cdef, 'sym') && (isfield(cdef.sym, 'system') || isfield(cdef.sym, 'LC'))
0103         list{1} = 'Extend Crystal Symmetry Information';
0104     else
0105         list{1} = 'Define Crystal Symmetry';
0106     end
0107     % Lattice Parameters
0108     if isfield(cdef, 'lat')
0109         list{2} = 'Delete Lattice Parameters';
0110     else
0111         list{2} = 'Define Lattice Parameters';
0112     end
0113     clist = [1 2];
0114     % Miller facets
0115     if isfield(cdef, 'sym') && isfield(cdef.sym, 'defined')
0116         list{end+1} = 'Edit Miller Indices';
0117         clist(end+1) = 3;
0118     end
0119     % display informations
0120     list{end+1} = 'Display Current Informations';
0121     clist(end+1) = 4;
0122     % show crystal
0123     if isfield(cdef, 'sym') && isfield(cdef.sym, 'defined') && isfield(cdef, 'lat')
0124         list{end+1} = 'Show Image of Crystal';
0125         clist(end+1) = 5;
0126     end
0127     % save crystal
0128     list{end+1} = 'Save to database and exit';
0129     clist(end+1) = 6;
0130 
0131     
0132     control = selectFromList(list, 'Exit');
0133     if control ~= 0
0134         control = clist(control);
0135     end
0136     
0137     switch control
0138         %% Symmetry handling
0139         case 1
0140             if isfield(cdef, 'sym') && isfield(cdef.sym, 'defined')
0141                 % delete symmetry information
0142                 cdef = rmfield(cdef, 'sym');
0143                 % delete lattice informations
0144                 if isfield(cdef, 'lat');
0145                     cdef = rmfield(cdef, 'lat');
0146                 end
0147                 % delete defined miller indices
0148                 if isfield(cdef, 'millerDefined');
0149                     cdef = rmfield(cdef, 'millerDefined');
0150                 end
0151                 disp('..crystal definition deleted');
0152             elseif isfield(cdef, 'sym') && isfield(cdef.sym, 'system')
0153                 % set symmetry (family already defined)...
0154                 % prompt for selection of notation
0155                 disp(' ');
0156                 disp('Please choose a notation');
0157                 list = {'Schonflies Notation', 'Hermann-Mauguin Notation',...
0158                         'Trivialname (German)', 'Number'};
0159                 sel = selectFromList(list, 'Back');
0160                 % back to main menu, if desired
0161                 if sel == 0,control = -1;continue;end;
0162                 % translate selcetion into proper row of P (space group
0163                 % informations)
0164                 list = [1, 2, 7, 6];
0165                 sel = list(sel);
0166                 % filter for valid elements of family
0167                 sublistindices = [];
0168                 for i = 1:size(P, 2)
0169                     if strcmp(P(5, i), cdef.sym.system)
0170                         sublistindices(end+1) = i;
0171                     end
0172                 end
0173                 % prompt for entering crystal family
0174                 disp(' ');
0175                 disp('Please specify the symmetry group');
0176                 list = P(sel, sublistindices);
0177                 sel = selectFromList(list, 'Back')
0178                 % back to main menu, if desired
0179                 if sel == 0,control = -1;continue;end;
0180                 % translate to number of crystal definition
0181                 cdef.sym.defined = sublistindices(sel);
0182             else
0183                 % Select input type
0184                 disp(' ');
0185                 disp('Please choose a notation');
0186                 list = {'Schonflies Notation', 'Hermann-Mauguin Notation',...
0187                         'Trivialname (German)', 'Number', ...
0188                         'Crystal Family'};
0189                 sel = selectFromList(list, 'Back');
0190                 % back to main menu, if desired
0191                 if sel == 0,control = -1;continue;end;
0192                 % translate to coloumn in P (pointgroups)
0193                 list = [1, 2, 7, 6, 5];
0194                 sel = list(sel);
0195                 list = P(sel,:);
0196                 % filter for unique entries, if crystal family was choosen
0197                 if sel == 4 || sel == 5
0198                     list = unique(list);
0199                 end
0200                 % prompt for user input
0201                 disp(' ');
0202                 disp('Please specify the symmetry group');
0203                 selt = selectFromList(list, 'Back');
0204                 % back to main menu, if desired
0205                 if selt == 0,control = -1;continue;end;
0206                 % set symmetry informations
0207                 if sel == 1 || sel == 2 || sel == 7 || sel == 6
0208                     cdef.sym.defined = selt;
0209                     cdef.sym.system = P{5, selt};
0210                 elseif sel == 5
0211                     cdef.sym.system = list{selt};
0212                 end
0213             end
0214         %% Lattice Parameters
0215         case 2
0216             if isfield(cdef, 'lat')
0217                 % delete lattice informations
0218                 cdef = rmfield(cdef, 'lat');
0219                 disp('..lattice parameters deleted');
0220             else
0221                 % create lattice informations
0222                 [latspec cdef] = printLatticeSummary(cdef);
0223                 disp(' ');
0224                 disp('Please specify missing lattice parameters (lengths in aengstroem, angles in degree)');
0225                 cdef.lat.unit_length = 'angstrom';
0226                 cdef.lat.unit_angle = 'degree';
0227                 cdef.lat.a = input('  a = ');
0228                 if ~strcmp(latspec{2}, 'a')
0229                     cdef.lat.b = input('  b = ');
0230                 else
0231                     cdef.lat.b = cdef.lat.a;
0232                 end
0233                 if ~strcmp(latspec{3}, 'a')
0234                     cdef.lat.c = input('  c = ');
0235                 else
0236                     cdef.lat.c = cdef.lat.a;
0237                 end
0238                 if ~isfield(cdef.lat, 'alpha')
0239                     cdef.lat.alpha = input('  alpha = ');
0240                 end
0241                 if ~isfield(cdef.lat, 'beta')
0242                     cdef.lat.beta = input('  beta = ');
0243                 end
0244                 if ~isfield(cdef.lat, 'gamma')
0245                     cdef.lat.gamma = input('  gamma = ');
0246                 end
0247             end
0248         %% Defining Faces
0249         case 3
0250             cdef = editMiller(cdef, P);
0251 
0252         %% summary
0253         case 4
0254             disp(' ');
0255             printSymmetrySummary(cdef, P);
0256             
0257             disp(' ');
0258             printLatticeSummary(cdef);
0259             
0260             disp(' ');
0261             printMillerSummary(cdef, P);
0262             pause
0263         
0264         %% show crystal
0265         case 5
0266             try
0267                 figure
0268                 cdef_tmp = extendCdef(cdef);
0269                 viewCrystal(cdef_tmp);
0270             catch thisError
0271                 warning(thisError.message)
0272                 warning('Could not display crystal shape');
0273             end           
0274             pause
0275         case 6
0276             % request name
0277             disp(' ')
0278             fileName = input('File name (e.g. my_crystal): ', 's');
0279             
0280             disp(' ')
0281             disp('Proceed with file operation?');
0282             list = {['Save as elk' filesep 'crystal' ...
0283                     filesep 'database' filesep fileName '.m']};
0284             sel = selectFromList(list, 'Do not safe file.');
0285             if sel==1
0286                 writeCdefToDatabase(fileName, cdef);
0287                 control = 0;
0288             end
0289         otherwise
0290             if control ~= 0
0291                 disp('Choice was invalid');
0292             end
0293     end
0294 end
0295 
0296 % exitting program, try to give cartesian, if description is complete
0297 if nargout == 1;
0298     try
0299         cdef = extendCdef(cdef);
0300     end
0301 else
0302     clear cdef
0303 end
0304 
0305 
0306 end
0307 
0308 
0309

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005