- Add a function to output Mantid MDHistogramWorkspaces (
sw_spec2MDHisto
) - Add Python plotting of magnetic structure using vispy
- Add mex files to compute main loop in
spinwave()
enabling a 2x - 4x speed up depending on system size - Add python wrapper for all Matlab functions so e.g.
sw_plotspec
etc can be called without them.
prefix in pyspinw:q
- Replace
spinwavefast()
method with a newfastmode
option in the mainspinwave()
method to reduce confusion - Adds a
neutron_output
option tospinwave()
to compute only the neutron (Sperp
) cross-section and not the full spin-spin correlation tensor, saving memory
- Corrects equation for Q-range from
thetaMin
insw_instrument
and addthetaMax
option - Fixes
sw_issymspec
to recognise powder spectra - Fixes a parsing error in the
spinw.fourier
method if no sublat option given. - Fixes several bugs in
sw_plotspec
where it ignores user options in'auto'
mode, and where it inverts user supplied colormaps. - Fixes several bugs in
.fitspec()
for handling twins and where it only outputs the final chi^2 values.
This is an initial public beta version of PySpinW released on PyPI.
Please install using:
pip install spinw
This will install a module called pyspinw
(note the py
at the start).
You can then run SpinW with:
import numpy as np
import matplotlib.pyplot as plt
from pyspinw import Matlab
m = Matlab()
swobj = m.spinw()
swobj.genlattice('lat_const', [3, 3, 6], 'angled', [90, 90, 120], 'sym', 'P 1');
swobj.addatom('r', [0, 0, 0], 'S', 1/2, 'label', 'MCu2')
swobj.gencoupling('maxDistance', 5)
swobj.addmatrix('label', 'J1', 'value', 1.00, 'color', 'g')
swobj.addcoupling('mat', 'J1', 'bond', 1)
swobj.genmagstr('mode', 'helical', 'k', [-1/3, -1/3, 0], 'n',[0, 0, 1], 'unit', 'lu', 'S', [[1], [0], [0]])
spec = swobj.spinwave([[-1/2, 0, 0], [0, 0, 0], [1/2, 1/2, 0], 100], 'hermit', False)
spec = m.sw_egrid(spec, 'component', 'Sxx+Syy', 'imagChk', False, 'Evect', np.linspace(0, 3, 100))
ax = plt.imshow(np.real(np.flipud(spec['swConv'])), aspect='auto', vmax=1)
plt.show()
On Windows and Linux systems, as long as you're running PySpinW locally, Matlab plotting commands like m.plot(swobj)
will work. This is not the case on MacOS (a known bug) and on remote systems (e.g. via JupyterHub).
This is an initial release of pySpinW as a pip
installable wheel for python >= 3.8 and MATLAB >= R2021a
Please install with
pip install pyspinw*.whl
This package can now be used in python if you have a version of MATLAB or MCR available on the machine. The package will try to automatically detect your installation, however if it is in a non-standard location, the path and version will have to be specified.
from pyspinw import Matlab
m = Matlab(matlab_version='R2023a', matlab_path='/usr/local/MATLAB/R2023a/')
An example would be:
import numpy as np
from pyspinw import Matlab
m = Matlab()
# Create a spinw model, in this case a triangular antiferromagnet
s = m.sw_model('triAF', 1)
# Specify the start and end points of the q grid and the number of points
q_start = [0, 0, 0]
q_end = [1, 1, 0]
pts = 501
# Calculate the spin wave spectrum
spec = m.spinwave(s, [q_start, q_end, pts])
At the moment graphics will not work on macOS systems and is disabled.
- Change to preallocation of output energies in
spinwave
to reduce memory usage and improve calculation speed - Use a mex function (if mex is enabled) for matrix multiplication in
spinwave
withhermit=false
that reduces memory usage and improves calculation speed for large magnetic cells (in an example with 216 magnetic atoms the execution time was reduced by ~65%)
- Fix generation of lattice from basis vectors in
genlattice
, see issue #28 sortMode
inspinwave
now correctly sorts the spin wave modes within each twin- A
spinw
object can now be correctly created from a structure figure .cif
files with a mixture of tabs and spaces or containing a?
in the comments can now be read correctly- Rotation matrix
rotC
inaddtwin
is now required to be a valid rotation or reflection matrix. - Spin of atom in
addatom
must haveS>=0
. - Anisotropic g-tensor in
addg
must be physically valid - i.e. :math:g^\dagger.g
must be a symmetric positive definite matrix. - Fix bug in addcoupling that did not allow user to supply 'atom' with numeric array of atom indices (previously only worked for string or cell of strings corresponding to atom labels).
- Renamed undocumented
gencoupling
parametertol
totolMaxDist
(see doc string ofgencoupling
for more details). - Added validation to
gencoupling
to ensuremaxDistance > dMin
. - Fixed uncaught error in
gencoupling
by checking if any bonds have length <maxSym
- A warning will now be emitted if
saveSabp
is requested inspinwave
for a commensurate structure - Fix bug in definition of rotation matrix transforming to spinw coordinate system when left-handed set of basis vectors supplied to
genlattice
, see issue #57 - Validation added for
perm
andorigin
arguments supplied togenlattice
(and warn users that these will be ignored if no symmetry/spacegroup is supplied in the same function call). - Deprecated
spgr
argument togenlattice
(users should usesym
instead). - Fix
MATLAB:nonLogicalConditional
error raised when using multiple k ingenmagstr
withhelical
mode - Raise error if invalid shape
S
ork
is provided togenmagstr
, previously they would be silently set to zero - Raise error if wrong number of spins
S
is provided togenmagstr
inhelical
mode. Previously the structure would be silently initialised to a random structure. - Raise error if a complex spin
S
is provided togenmagstr
inhelical
mode. Previously this meant it would silently ignore then
option, and behave exactly likefourier
mode. - Raise error if
rotate
mode is used without first initialising a magnetic structure - Emit deprecation warning if the undocumented
extend
mode is used ingenmagstr
- Raise error if the first spin is parallel to
n
and no rotation angle is provided inrotate
mode ingenmagstr
. Previously this would silently result inNaN
- Raise error if
phi
orphid
is not real inrotate
mode ingenmagstr
. This was an undocumented feature which has been removed. - Emit warning that the spin amplitude will be moderated if components of
S
are parallel ton
inhelical
mode ingenmagstr
- Emit warning if
nExt
is unnecessarily large compared tok
inhelical
andfourier
modes ingenmagstr
- Emit warning if arguments that will be ignored are passed to a particular mode in
genmagstr
(e.g.S
is passed torandom
) - Raise error if complex values is provided for
n
ingenmagstr
. Previously this would've caused a crash. - Fix error when plotting progress of
optmagsteep
without existing figure - Correctly report magnetic moments in each iteration of
optmagsteep
. - Fix errors when calling
intmatrix
with dipolar bonds and symbolic spinw object with fitmode true and false - Ensure biquadratic exchange interactions are isotropic in
addcoupling
(previously checked inintmatrix
) - Raise error if invalid shape
kbase
is provided tooptmagk
, previously it would be silently set to empty - Ensure varargin is correctly passed through to
ndbase.pso
fromoptmagk
. Previously user providedTolFun
,TolX
andMaxIter
would be overwritten by the defaults. - Warn users that that the results of
spinwave
have not been scientifically validated for supercell structures with an incommensurate modulation. - Emit warning if wrong length
xmin
,xmax
orx0
is passed tooptmagstr
. Previously they would be silently ignored. - No longer require a magnetic structure be initialised with
genmagstr
before usingoptmagstr
. If not intialised, a defaultnExt
of[1 1 1]
is used. This has also been clarified in the docstring. - Fix bug where powder spectra was not recognised in
sw_plotspec
, introduced by a previous update to provide more helpful error messages. sw_instrument
now calculates the limits for thetaMax, before it was using the continuation of the thetaMin line to high Q which is incorrect.- Fixes a parsing error in the
spinw.fourier
method if no sublat option given.