Skip to content

Instantly share code, notes, and snippets.

@mducle
Last active April 3, 2026 11:36
Show Gist options
  • Select an option

  • Save mducle/1026b0940f3f9cf4f722261e728885d7 to your computer and use it in GitHub Desktop.

Select an option

Save mducle/1026b0940f3f9cf4f722261e728885d7 to your computer and use it in GitHub Desktop.
Generates test data for PySpinW from Matlab SpinW.
QVECS = [0.1 0 0; 0.2 0 0; 0.1 0.1 0; 0.1 0.1 0.1; 0 0.1 0.1; 0 0 0.1]';
%%
AFMchain = spinw;
AFMchain.genlattice('lat_const',[3 8 8],'angled',[90 90 90],'spgr',0);
AFMchain.addatom('r',[0 0 0],'S',1,'label','MCu1','color','blue');
AFMchain.gencoupling('maxDistance',7)
AFMchain.addmatrix('label','Ja','value',1,'color','red');
AFMchain.addcoupling('mat','Ja','bond',1);
AFMchain.genmagstr('mode','direct','nExt',[2 1 1],'S',[0 0; 1 -1; 0 0]);
afcSpec = sw_neutron(AFMchain.spinwave(QVECS, 'hermit',true));
antiferro_chain = {afcSpec.omega afcSpec.Sperp};
%%
afc = spinw;
afc.genlattice('lat_const',[4 6 6])
afc.addatom('r',[ 0 0 0],'S',1)
afc.addatom('r',[1/2 0 0],'S',1)
afc.addmatrix('label','J','value',1)
afc.gencoupling
afc.addcoupling('mat','J','bond',1)
afc.addmatrix('label','A','value',diag([0 0 -0.1]))
afc.addaniso('A')
afc.genmagstr('mode','direct','S',[0 0; 0 0; 1 -1]);
afc.field([0 0 7]);
afcSpec = sw_neutron(afc.spinwave(QVECS, 'hermit',true));
antiferro_chain_with_field = {afcSpec.omega afcSpec.Sperp};
%%
AFkagome = spinw;
AFkagome.genlattice('lat_const',[6 6 10],'angled',[90 90 120],'spgr','P -3')
AFkagome.addatom('r',[1/2 0 0],'S', 1,'label','MCu1','color','r')
AFkagome.gencoupling('maxDistance',7)
AFkagome.addmatrix('label','J1','value',1.00,'color','r')
AFkagome.addmatrix('label','J2','value',0.11,'color','g')
AFkagome.addcoupling('mat','J1','bond',1)
AFkagome.addcoupling('mat','J2','bond',2)
S0 = [1 -2 1; 2 -1 -1; 0 0 0];
AFkagome.genmagstr('mode','direct','k',[0 0 0],'n',[0 0 1],'unit','lu','S',S0);
afcSpec = sw_neutron(AFkagome.spinwave(QVECS, 'hermit',true));
kagome_antiferro = {afcSpec.omega afcSpec.Sperp};
%%
AF33kagome = spinw;
AF33kagome.genlattice('lat_const',[6 6 40],'angled',[90 90 120],'spgr','P -3')
AF33kagome.addatom('r',[1/2 0 0],'S', 1,'label','MCu1','color','r')
AF33kagome.gencoupling('maxDistance',7)
AF33kagome.addmatrix('label','J1','value',1.00,'color','g')
AF33kagome.addcoupling('mat','J1','bond',1)
S0 = [0 0 -1;
1 1 -1;
0 0 0];
AF33kagome.genmagstr('mode','helical','k',[-1/3 -1/3 0],...
'n',[0 0 1],'unit','lu','S',S0,'nExt',0.1);
afcSpec = sw_neutron(AF33kagome.spinwave(QVECS, 'hermit',true));
kagome_supercell = {afcSpec.omega afcSpec.Sperp};
%%
tri = spinw;
tri.genlattice('lat_const',[3 3 4],'angled',[90 90 120])
tri.addatom('r',[0 0 0],'S',3/2,'label','MCr3','color','orange')
tri.gencoupling()
tri.addmatrix('value',1,'label','J','color','SteelBlue')
tri.addcoupling('mat','J','bond',1)
tri.addmatrix('value',diag([0 0 0.2]),'label','D','color','r')
tri.addaniso('D')
tri.genmagstr('mode','helical','S',[0; 1; 0],'k',[1/3 1/3 0],'n', [0 0 1])%,'nExt',0.1);
afcSpec = sw_neutron(tri.spinwave(QVECS, 'hermit',true));
tri_antiferro = {afcSpec.omega afcSpec.Sperp};
%%
save('matlab_test_data', 'antiferro_chain', 'antiferro_chain_with_field', 'kagome_antiferro', 'kagome_supercell', 'tri_antiferro')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment