SpinW / spinw

SpinW Matlab library for spin wave calculation
http://www.spinw.org
GNU General Public License v3.0
36 stars 15 forks source link

hkl mismatch in powspec #47

Closed pastle closed 2 years ago

pastle commented 3 years ago

There seems to be a tiny bug in 'powspec'. In the situation where a unit cell is generated through the 'newcell' command with the 'keepq=1' option, the hkl generated in 'powspec' are defined in the new cell. However, in the following 'spinwave' calculations, the hkl are treated as indices in the old cell because of the 'keepq=1' option. This bug can be fixed easily by adding an hkl transforming command before running the spinwave calculations:

After ln294 in 'powspec'

hkl = (Q'*obj.basisvector)'/2/pi;

add:

hkl = inv(obj.unit.qmat)*hkl;

mducle commented 3 years ago

@pastle I haven't used the newcell method at all myself, but from reading the documentation in newcell - it seems to me that using the hkl indices of the old cell is the desired behaviour for keepq=true - so there is no bug. If you want to use the hkl indices of the new cell, you should set keepq to false (or omit the option since false is the default).

In any case, powspec.m just calls spinwave.m which is where the transformation using obj.unit.qmat is made (in line 334, to go from the old hkl indices to the new hkl indices) - the change you're suggesting in powspec.m just means that the transformation in spinwave.m just reverses what you want (e.g. treats obj.unit.qmat as the identity which is what would have happenned if newcell is called with keepq=false.