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

Usage of transplant.MatlabStruct #43

Open
mincentatties opened this issue Aug 15, 2017 · 1 comment
Open

Usage of transplant.MatlabStruct #43

mincentatties opened this issue Aug 15, 2017 · 1 comment

Comments

@mincentatties
Copy link

mincentatties commented Aug 15, 2017

{mac OS 10.12.6, pyspinw}

Hi
I can see structures within spinw objects ok. For example:

from transplant import Matlab
from transplant import MatlabStruct
m=Matlab('/Applications/pyspinw.app/pyspinw.sh')

gto=m.spinw()
Flist = MatlabStruct(gto.mag_str)['F']

What I haven't figured out yet is how to write to the spinw object structures directly. (I would like to - in this case - manually change some of the spins in the 'F' array)

Cheers
Ross

@tsdev
Copy link
Owner

tsdev commented Aug 15, 2017

MatlabStruct() is used to make sure that a Python list is converted into a struct type in MATLAB, by default a Python list is converted into containers.Map in MATLAB. This might change in the future, as we are dicsussing this issue with the author of transplant. For more details check the transplant repo: https://github.com/bastibe/transplant.
Now, you can still modify the spinw structure, with the limitation that you can assign values of field down to 1 level. Let me show what this means:

from transplant import Matlab as pyspinw
from transplant import MatlabStruct as struct
import numpy as np

m = pyspinw(executable='/Applications/Pyspinw.app/pyspinw.sh')
tri = m.sw_model('triAF',1.)
F = tri.mag_str
F['k'][2,0] = 1.
tri.mag_str = struct(F)

The above example showed how to change the magnetic propagation vector. You might try to change the k-vector directly: tri.mag_str['k'][2,0] = 1. but this will not work, you can check by calling tri.mag_str['k'][2,0] and you will get the original unmodified value. In any case I suggest to change the spinw properties via its methods, the equivalent to the above code is

M = tri.magstr()
tri.genmagstr('mode','helical','S',M['S'],'n',M['n'],'k',np.array([1./3.,1./3.,1.]))

This might be a bit cumbersome, but might help to build your own commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants