<commit_before>import spirit.spiritlib as spiritlib
import ctypes

### Load Library
_spirit = spiritlib.load_spirit_library()

from spirit.scalar import scalar
from spirit import parameters
from numpy import frombuffer, ndarray as np

### Get Chain index
_Get_Index          = _spirit.System_Get_Index
_Get_Index.argtypes = [ctypes.c_void_p]
_Get_Index.restype  = ctypes.c_int
def get_index(p_state):
    return int(_Get_Index(ctypes.c_void_p(p_state)))

### Get Chain number of images
_Get_NOS            = _spirit.System_Get_NOS
_Get_NOS.argtypes   = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
_Get_NOS.restype    = ctypes.c_int
def get_nos(p_state, idx_image=-1, idx_chain=-1):
    return int(_Get_NOS(ctypes.c_void_p(p_state), ctypes.c_int(idx_image), ctypes.c_int(idx_chain)))

### Get Pointer to Spin Directions
# NOTE: Changing the values of the array_view one can alter the value of the data of the state
_Get_Spin_Directions            = _spirit.System_Get_Spin_Directions
_Get_Spin_Directions.argtypes   = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
_Get_Spin_Directions.restype    = ctypes.POINTER(scalar)
def get_spin_directions(p_state, idx_image=-1, idx_chain=-1):
    nos = get_nos(p_state, idx_image, idx_chain)
    ArrayType = scalar*3*nos
    Data = _Get_Spin_Directions(ctypes.c_void_p(p_state), ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
    array_pointer = ctypes.cast(Data, ctypes.POINTER(ArrayType))
    array = frombuffer(array_pointer.contents, dtype=scalar)
    array_view = array.view()
    array_view.shape = (nos, 3)
    return array_view

### Get Pointer to an eigenmode
# NOTE: Changing the values of the array_view one can alter the value of the data of the state
_Get_Eigenmode            = _spirit.System_Get_Eigenmode
_Get_Eigenmode.argtypes   = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int]
_Get_Eigenmode.restype    = ctypes.POINTER(scalar)
def get_eigenmode(p_state, idx_mode, idx_image=-1, idx_chain=-1):
    nos = get_nos(p_state, idx_image, idx_chain)
    ArrayType = scalar*3*nos
    Data = _Get_Eigenmode(ctypes.c_void_p(p_state), ctypes.c_int(idx_mode),
                          ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
    array_pointer = ctypes.cast(Data, ctypes.POINTER(ArrayType))
    array = frombuffer(array_pointer.contents, dtype=scalar)
    array_view = array.view()<commit_msg>Python API: added system.get_effective_field<commit_after>import spirit.spiritlib as spiritlib
import ctypes

### Load Library
_spirit = spiritlib.load_spirit_library()

from spirit.scalar import scalar
from spirit import parameters
from numpy import frombuffer, ndarray as np

### Get Chain index
_Get_Index          = _spirit.System_Get_Index
_Get_Index.argtypes = [ctypes.c_void_p]
_Get_Index.restype  = ctypes.c_int
def get_index(p_state):
    return int(_Get_Index(ctypes.c_void_p(p_state)))

### Get Chain number of images
_Get_NOS            = _spirit.System_Get_NOS
_Get_NOS.argtypes   = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
_Get_NOS.restype    = ctypes.c_int
def get_nos(p_state, idx_image=-1, idx_chain=-1):
    return int(_Get_NOS(ctypes.c_void_p(p_state), ctypes.c_int(idx_image), ctypes.c_int(idx_chain)))

### Get Pointer to Spin Directions
# NOTE: Changing the values of the array_view one can alter the value of the data of the state
_Get_Spin_Directions            = _spirit.System_Get_Spin_Directions
_Get_Spin_Directions.argtypes   = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
_Get_Spin_Directions.restype    = ctypes.POINTER(scalar)
def get_spin_directions(p_state, idx_image=-1, idx_chain=-1):
    nos = get_nos(p_state, idx_image, idx_chain)
    ArrayType = scalar*3*nos
    Data = _Get_Spin_Directions(ctypes.c_void_p(p_state), ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
    array_pointer = ctypes.cast(Data, ctypes.POINTER(ArrayType))
    array = frombuffer(array_pointer.contents, dtype=scalar)
    array_view = array.view()
    array_view.shape = (nos, 3)
    return array_view

### Get Pointer to Effective Field
# NOTE: Changing the values of the array_view one can alter the value of the data of the state
_Get_Effective_Field            = _spirit.System_Get_Effective_Field
_Get_Effective_Field.argtypes   = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
_Get_Effective_Field.restype    = ctypes.POINTER(scalar)
def get_effective_field(p_state, idx_image=-1, idx_chain=-1):
    nos = get_nos(p_state, idx_image, idx_chain)
    ArrayType = scalar*3*nos
    Data = _Get_Effective_Field(ctypes.c_void_p(p_state), ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
    array_pointer = ctypes.cast(Data, ctypes.POINTER(ArrayType))
    array = frombuffer(array_pointer.contents, dtype=scalar)
    array_view = array.view()
    array_view.shape = (nos, 3)
    return array_view

### Get Pointer to an eigenmode
# NOTE: Changing the values of the array_view one can alter the value of the data of the state
_Get_Eigenmode            = _spirit.System_Get_Eigenmode
_Get_Eigenmode.argtypes   = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int]
_Get_Eigenmode.restype    = ctypes.POINTER(scalar)
def get_eigenmode(p_state, idx_mode, idx_image=-1, idx_chain=-1):
    nos = get_nos(p_state, idx_image, idx_chain)
    ArrayType = scalar*3*nos
    Data = _Get_Eigenmode(ctypes.c_void_p(p_state), ctypes.c_int(idx_mode),
                          ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
    array_pointer = ctypes.cast(Data, ctypes.POINTER(ArrayType))
    array = frombuffer(array_pointer.contents, dtype=scalar)
    array_view = array.view()
{'fraction_non_alphanumeric': 0.09622302158273381, 'fraction_numerical': 0.003956834532374101, 'mean_word_length': 4.727085478887744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3193174', 'n_tokens_mistral': 2049, 'n_tokens_neox': 2011, 'n_words': 406}