Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python wrapper class for spinw #176

Open
mducle opened this issue Apr 8, 2024 · 1 comment
Open

Python wrapper class for spinw #176

mducle opened this issue Apr 8, 2024 · 1 comment
Labels
enhancement New feature or request python Related to PySpinW

Comments

@mducle
Copy link
Member

mducle commented Apr 8, 2024

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)

@mducle mducle added enhancement New feature or request python Related to PySpinW labels Apr 8, 2024
@Artemkth
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Related to PySpinW
Projects
None yet
Development

No branches or pull requests

2 participants