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

Hamil getters #606

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion core/python/spirit/hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,64 @@ def get_ddi(p_state, idx_image=-1, idx_chain=-1):
"cutoff_radius" : cutoff_radius.value,
"pb_zero_padding" : pb_zero_padding.value }

_Get_Anisotropy = _spirit.Hamiltonian_Get_Anisotropy
_Get_Anisotropy.argtypes = [ctypes.c_void_p,ctypes.POINTER(ctypes.c_float)
, ctypes.POINTER(ctypes.c_float)
, ctypes.c_int, ctypes.c_int]
_Get_Anisotropy.restype = None
def get_anisotropy(p_state, idx_image=-1, idx_chain=-1):
"""Returns the magnitude and an array of `shape(3)` containing the direction of
the (homogeneous) magnetocrystalline anisotropy.
"""
magnitude = ctypes.c_float()
normal = (3*ctypes.c_float)()
_Get_Anisotropy(ctypes.c_void_p(p_state), ctypes.byref(magnitude), normal
,ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
return float(magnitude.value), [n for n in normal]

_Get_Exchange_Shells = _spirit.Hamiltonian_Get_Exchange_Shells
_Get_Exchange_Shells.argtypes = [ctypes.c_void_p,ctypes.POINTER(ctypes.c_int)
, ctypes.POINTER(ctypes.c_float)
, ctypes.c_int, ctypes.c_int]
_Get_Exchange_Shells.restype = None
def get_Exchange_shells(p_state, idx_image=-1, idx_chain=-1):
"""Returns the magnitude and an array of `n_shells` containing the direction of
the Exchange interaction.
"""
NULL = ctypes.POINTER(ctypes.c_float)()
#Null = None
n_shells = ctypes.c_int()
#Only write n_shells and chirality
_Get_Exchange_Shells(ctypes.c_void_p(p_state),ctypes.byref(n_shells),NULL
,ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
jij = (n_shells.value*ctypes.c_float)()
_Get_Exchange_Shells(ctypes.c_void_p(p_state),ctypes.byref(n_shells),jij
,ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
return int(n_shells.value), [float(j) for j in jij]

_Get_DMI_Shells = _spirit.Hamiltonian_Get_DMI_Shells
_Get_DMI_Shells.argtypes = [ctypes.c_void_p,ctypes.POINTER(ctypes.c_int)
, ctypes.POINTER(ctypes.c_float)
, ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_int]
_Get_DMI_Shells.restype = None
def get_DMI_shells(p_state, idx_image=-1, idx_chain=-1):
"""Returns the magnitude and an array of `n_shells` containing the direction of
the DMI interaction.
"""
NULL = ctypes.POINTER(ctypes.c_float)()
#Null = None
n_shells = ctypes.c_int()
chirality = ctypes.c_int()
#Only write n_shells and chirality
_Get_DMI_Shells(ctypes.c_void_p(p_state),ctypes.byref(n_shells),NULL
,ctypes.byref(chirality),ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
dij = (n_shells.value*ctypes.c_float)()
_Get_DMI_Shells(ctypes.c_void_p(p_state),ctypes.byref(n_shells),dij
,ctypes.byref(chirality),ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
return int(n_shells.value),[float(d) for d in dij], int(chirality.value)
_Write_Hessian = _spirit.Hamiltonian_Write_Hessian
_Write_Hessian.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_bool, ctypes.c_int, ctypes.c_int]
_Write_Hessian.restype = None
def write_hessian(p_state, filename, triplet_format=True, idx_image=-1, idx_chain=-1):
"""RWrites the embedding Hessian to a file"""
_Write_Hessian(ctypes.c_void_p(p_state), ctypes.c_char_p(filename.encode('utf-8')), ctypes.c_bool(triplet_format), ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
_Write_Hessian(ctypes.c_void_p(p_state), ctypes.c_char_p(filename.encode('utf-8')), ctypes.c_bool(triplet_format), ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
15 changes: 10 additions & 5 deletions core/src/Spirit/Hamiltonian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,12 @@ try
*n_shells = ham->exchange_shell_magnitudes.size();

// Note the array needs to be correctly allocated beforehand!
for( std::size_t i = 0; i < ham->exchange_shell_magnitudes.size(); ++i )
if(jij != nullptr)
{
jij[i] = (float)ham->exchange_shell_magnitudes[i];
for( int i = 0; i < ham->exchange_shell_magnitudes.size(); ++i )
{
jij[i] = (float)ham->exchange_shell_magnitudes[i];
}
}
}
}
Expand Down Expand Up @@ -523,10 +526,12 @@ try

*n_shells = ham->dmi_shell_magnitudes.size();
*chirality = ham->dmi_shell_chirality;

for( int i = 0; i < *n_shells; ++i )
if(dij != nullptr)
{
dij[i] = (float)ham->dmi_shell_magnitudes[i];
for( int i = 0; i < *n_shells; ++i )
{
dij[i] = (float)ham->dmi_shell_magnitudes[i];
}
}
}
}
Expand Down