SpinW / spinw

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

Python wrapper class for spinw #176

Open mducle opened 7 months ago

mducle commented 7 months ago

As noted in issue #171 some properties of the Matlab spinw class cannot be easily accessed in Python. This is because the spinw class is has properties which are plain structs and these get converted (copied) to Python dicts. Modifying the dicts in Python does change the original Matlab structs. Moreover, libpymcr does not seem to support the assignment of a Python dict to a Matlab struct property - this should be investigated in libpymcr.

However, as part of the migration to Python, we should have a Python spinw class; In order to fix the issue mentioned above, this could initially be a light wrapper around the Matlab class with specific struct properties wrapped as Python objects to allow them to be modified from Python.

In order to make it easier for users, Python wrappers for all the sw_* functions in swfiles should also be created. Ideally then the user syntax would become something like:

from spinw import *

s1 = spinw()
s2 = sw_model('triAF', 1)
spec = s2.spinwave(([1,0,0], [1,1,1]))
sw_plotspec(spec)

(e.g. much closer to the Matlab syntax, without the m. prefix)

Artemkth commented 7 months ago

I just did a bit of research, and it seems python supports the normal getter/setter approach https://docs.python.org/3/library/functions.html#property . It sounds like a pain to implement if there are 2 additional wrappers required for all the properties in python, and possibly more code to marry the two in the matlab, I will look a bit more later at matlab python binds, I wonder if there is a clever way around (because in the example you provided it seems that every symbol is accessed through a string object).

Thank you for the reply on my original issue report!

Kind regards, Artem