|
28 | 28 | % 'circle' Plot only the rotation plane of incommensurate |
29 | 29 | % magnetic structures. |
30 | 30 | % 'arrow' Plots only the moment directions. |
| 31 | +% 'none' Don't plot anything. |
31 | 32 | % figure Handle of the swplot figure. Default is the selected figure. |
32 | 33 | % legend Whether to add the plot to the legend, default is true. |
33 | 34 | % label Whether to plot labels for atoms, default is true. |
|
207 | 208 | % do nothing |
208 | 209 | case 'circle' |
209 | 210 | case 'arrow' |
| 211 | + case 'none' |
210 | 212 | otherwise |
211 | 213 | error('plotmag:WrongInput','The given mode string is invalid!'); |
212 | 214 | end |
213 | 215 |
|
214 | | -% number of unit cells |
215 | | -nCell = prod(nExtPlot); |
216 | | - |
217 | | -% keep track of types of atoms |
218 | | -aIdx = repmat(mAtom.idx,[nCell 1])'; |
219 | | -a2Idx = repmat(1:numel(mAtom.idx),[nCell 1])'; |
220 | | -pos = reshape(pos,3,[]); |
221 | | - |
222 | | -% cut out the atoms that are out of range |
223 | | -switch param.unit |
224 | | - case 'lu' |
225 | | - % L>= lower range, L<= upper range |
226 | | - pIdx = all(bsxfun(@ge,pos,range(:,1)-10*eps) & bsxfun(@le,pos,range(:,2)+10*eps),1); |
227 | | - case 'xyz' |
228 | | - % convert to xyz |
229 | | - posxyz = BV*pos; |
230 | | - pIdx = all(bsxfun(@ge,posxyz,range(:,1)-10*eps) & bsxfun(@le,posxyz,range(:,2)+10*eps),1); |
231 | | -end |
232 | | - |
233 | | -if ~any(pIdx) |
234 | | - warning('plotatom:EmptyPlot','There are no magnetic moments in the plotting range!') |
235 | | - return |
236 | | -end |
237 | | - |
238 | | -M = M(:,pIdx); |
239 | | -pos = pos(:,pIdx); |
240 | | -aIdx = aIdx(pIdx); |
241 | | -a2Idx = a2Idx(pIdx); |
242 | | - |
243 | | -% normalization |
244 | | -if param.normalize |
245 | | - % normalize moments |
246 | | - M = bsxfun(@rdivide,M,sqrt(sum(M.^2,1))); |
247 | | -end |
248 | | - |
249 | | -% save magnetic moment vector values into data before rescaling |
250 | | -MDat = mat2cell([M;pos;a2Idx],7,ones(1,size(M,2))); |
251 | | - |
252 | | -% scale moments |
253 | | -% get the length of the shortest bond |
254 | | -if ~isempty(obj.coupling.atom2) |
255 | | - apos1 = obj.matom.r(:,obj.coupling.atom1(1)); |
256 | | - apos2 = obj.matom.r(:,obj.coupling.atom2(1))+double(obj.coupling.dl(:,1)); |
257 | | - lBond = norm(BV*(apos2-apos1)); |
258 | | -else |
259 | | - lBond = 3; |
260 | | -end |
261 | | - |
262 | | -% normalize the longest moment vector to scale*(shortest bond length) |
263 | | -M = M/sqrt(max(sum(M.^2,1)))*param.scale*lBond; |
264 | | - |
265 | | -if param.centered |
266 | | - % double the length for centered moments |
267 | | - M = 2*M; |
268 | | -end |
269 | | - |
270 | | -% convert to lu units |
271 | | -Mlu = BV\M; |
272 | | - |
273 | | -if param.centered |
274 | | - % center on atoms |
275 | | - vpos = cat(3,pos-Mlu/2,pos+Mlu/2); |
276 | | -else |
277 | | - vpos = cat(3,pos,pos+Mlu); |
278 | | -end |
279 | | - |
280 | | -% color |
281 | | -if strcmp(param.color,'auto') |
282 | | - color = double(obj.unit_cell.color(:,aIdx)); |
| 216 | +if ~strcmp(param.mode,'none') |
| 217 | + |
| 218 | + % number of unit cells |
| 219 | + nCell = prod(nExtPlot); |
| 220 | + |
| 221 | + % keep track of types of atoms |
| 222 | + aIdx = repmat(mAtom.idx,[nCell 1])'; |
| 223 | + a2Idx = repmat(1:numel(mAtom.idx),[nCell 1])'; |
| 224 | + pos = reshape(pos,3,[]); |
| 225 | + |
| 226 | + % cut out the atoms that are out of range |
| 227 | + switch param.unit |
| 228 | + case 'lu' |
| 229 | + % L>= lower range, L<= upper range |
| 230 | + pIdx = all(bsxfun(@ge,pos,range(:,1)-10*eps) & bsxfun(@le,pos,range(:,2)+10*eps),1); |
| 231 | + case 'xyz' |
| 232 | + % convert to xyz |
| 233 | + posxyz = BV*pos; |
| 234 | + pIdx = all(bsxfun(@ge,posxyz,range(:,1)-10*eps) & bsxfun(@le,posxyz,range(:,2)+10*eps),1); |
| 235 | + end |
| 236 | + |
| 237 | + if ~any(pIdx) |
| 238 | + warning('plotatom:EmptyPlot','There are no magnetic moments in the plotting range!') |
| 239 | + return |
| 240 | + end |
| 241 | + |
| 242 | + M = M(:,pIdx); |
| 243 | + pos = pos(:,pIdx); |
| 244 | + aIdx = aIdx(pIdx); |
| 245 | + a2Idx = a2Idx(pIdx); |
| 246 | + |
| 247 | + % normalization |
| 248 | + if param.normalize |
| 249 | + % normalize moments |
| 250 | + M = bsxfun(@rdivide,M,sqrt(sum(M.^2,1))); |
| 251 | + end |
| 252 | + |
| 253 | + % save magnetic moment vector values into data before rescaling |
| 254 | + MDat = mat2cell([M;pos;a2Idx],7,ones(1,size(M,2))); |
| 255 | + |
| 256 | + % scale moments |
| 257 | + % get the length of the shortest bond |
| 258 | + if ~isempty(obj.coupling.atom2) |
| 259 | + apos1 = obj.matom.r(:,obj.coupling.atom1(1)); |
| 260 | + apos2 = obj.matom.r(:,obj.coupling.atom2(1))+double(obj.coupling.dl(:,1)); |
| 261 | + lBond = norm(BV*(apos2-apos1)); |
| 262 | + else |
| 263 | + lBond = 3; |
| 264 | + end |
| 265 | + |
| 266 | + % normalize the longest moment vector to scale*(shortest bond length) |
| 267 | + M = M/sqrt(max(sum(M.^2,1)))*param.scale*lBond; |
| 268 | + |
| 269 | + if param.centered |
| 270 | + % double the length for centered moments |
| 271 | + M = 2*M; |
| 272 | + end |
| 273 | + |
| 274 | + % convert to lu units |
| 275 | + Mlu = BV\M; |
| 276 | + |
| 277 | + if param.centered |
| 278 | + % center on atoms |
| 279 | + vpos = cat(3,pos-Mlu/2,pos+Mlu/2); |
| 280 | + else |
| 281 | + vpos = cat(3,pos,pos+Mlu); |
| 282 | + end |
| 283 | + |
| 284 | + % color |
| 285 | + if strcmp(param.color,'auto') |
| 286 | + color = double(obj.unit_cell.color(:,aIdx)); |
| 287 | + else |
| 288 | + color = swplot.color(param.color); |
| 289 | + end |
| 290 | + |
| 291 | + % shift positions |
| 292 | + vpos = bsxfun(@plus,vpos,BV\param.shift); |
| 293 | + |
| 294 | + % prepare legend labels |
| 295 | + mAtom.name = obj.unit_cell.label(mAtom.idx); |
| 296 | + lLabel = repmat(mAtom.name,[nCell 1]); |
| 297 | + lLabel = lLabel(pIdx); |
| 298 | + |
| 299 | + % plot moment vectors |
| 300 | + swplot.plot('type','arrow','name','mag','position',vpos,'text','',... |
| 301 | + 'figure',hFigure,'legend',false,'color',color,'R',param.radius0,... |
| 302 | + 'fontsize',param.fontsize,'tooltip',false,'replace',param.replace,... |
| 303 | + 'data',MDat,'label',lLabel,'nmesh',param.nmesh,'ang',param.ang,... |
| 304 | + 'lHead',param.lHead,'translate',param.translate,'zoom',param.zoom); |
| 305 | + |
283 | 306 | else |
284 | | - color = swplot.color(param.color); |
| 307 | + % don't plot anything just remove previous plot |
285 | 308 | end |
286 | 309 |
|
287 | | -% shift positions |
288 | | -vpos = bsxfun(@plus,vpos,BV\param.shift); |
289 | | - |
290 | | -% prepare legend labels |
291 | | -mAtom.name = obj.unit_cell.label(mAtom.idx); |
292 | | -lLabel = repmat(mAtom.name,[nCell 1]); |
293 | | -lLabel = lLabel(pIdx); |
294 | | - |
295 | | - |
296 | | -% plot moment vectors |
297 | | -swplot.plot('type','arrow','name','mag','position',vpos,'text','',... |
298 | | - 'figure',hFigure,'legend',false,'color',color,'R',param.radius0,... |
299 | | - 'fontsize',param.fontsize,'tooltip',false,'replace',param.replace,... |
300 | | - 'data',MDat,'label',lLabel,'nmesh',param.nmesh,'ang',param.ang,... |
301 | | - 'lHead',param.lHead,'translate',param.translate,'zoom',param.zoom); |
302 | 310 |
|
303 | 311 | % save range |
304 | 312 | setappdata(hFigure,'range',struct('range',range,'unit',param.unit)); |
|
0 commit comments