tsdev / spinw

SpinW Matlab library for spin wave calculation
www.psi.ch/spinw
GNU General Public License v3.0
30 stars 35 forks source link

Bug with addaniso when using atomIdx and plotting the structure #33

Closed henrikjacobsenfys closed 7 years ago

henrikjacobsenfys commented 7 years ago

Hi Sandor

I am looking into have different anisotropies on different ions, but get an error message when I try to plot the structure. The error is this:

Error using bsxfun Non-singleton dimensions of the two input arrays must match each other.

Error in swplot.plotion (line 303) posc = bsxfun(@plus,posc,repmat(pos,[1 3]));

Error in spinw/plot (line 263) hFigure = plotFun{ii}(selArg{:});

Below is a small example creating this error. The code seems to run correctly apart from this; it creates a figure with anisotropy only on the correct ions.

Cheers,

Henrik

CuO = spinw;
CuO.fileid(0)
CuO.genlattice('lat_const',[4.684  3.423 5.129],'angled',[90 99.54 90])
CuO.addatom('r', [1/4 1/4 0],'S', 1/2,'label','Cu1','color','blue')
CuO.addatom('r', [3/4 3/4 0],'S', 1/2,'label','Cu2','color','blue')
CuO.addatom('r', [3/4 1/4 1/2],'S', 1/2,'label','Cu3','color','blue')
CuO.addatom('r', [1/4 3/4 1/2],'S', 1/2,'label','Cu4','color','blue')
CuO.gencoupling
S0=[0 -1 0;
    0 -1 0;
    0 -1 0;
    0 1 0;].';
CuO.genmagstr('mode','helical','k',[1/2 0 -1/2],'n',[0 0 1],'unitS','lu','S',S0,'nExt',[2 1 2]);

D_matrix=diag([0 -0.15 0]);

CuO.addmatrix('value',D_matrix,'label','D','color','r')

% CuO.addaniso('D') 
% CuO.addaniso('D',[1 2  ])
CuO.addaniso('D',{'Cu1','Cu2'})

plot(CuO)
tsdev commented 7 years ago

This is certanly a bug, I will investigate.

tsdev commented 7 years ago

I checked the above code Matlab R2016b and R2017a using the latest version of SpinW from the master branch and I didn't get an error. The plot looks as expected: CuO magnetic structure Probably I fixed it sometime earlier. A little comment, if you use the latest unreleased version from GitHb, the spinw.genmagstr() changed an option name from unitS to unit. Please comment on whether this fixed the problem.

henrikjacobsenfys commented 7 years ago

Updating to the newest version fixed the problem. Thanks a lot :)