How to use the spirit.spiritlib.load_spirit_library function in spirit

To help you get started, we’ve selected a few spirit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spirit-code / spirit / core / python / spirit / quantities.py View on Github external
"""
Quantities
====================
"""

import spirit.spiritlib as spiritlib
import spirit.system as system
from spirit.scalar import scalar
import ctypes

import numpy as np

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

_Get_Magnetization          = _spirit.Quantity_Get_Magnetization
_Get_Magnetization.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float),
                               ctypes.c_int, ctypes.c_int]
_Get_Magnetization.restype  = None
def get_magnetization(p_state, idx_image=-1, idx_chain=-1):
    """Calculates and returns the average magnetization of the system as
    an array of shape (3).
    """
    magnetization = (3*ctypes.c_float)()
    _Get_Magnetization(ctypes.c_void_p(p_state), magnetization,
                       ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
    return [float(i) for i in magnetization]


### Temporary info function for MMF
github spirit-code / spirit / core / python / spirit / chain.py View on Github external
"""
Chain
====================

Manipulate the chain of spin systems (also called images), e.g. add, remove or change active image.
Get information, such as number of images or energies and reaction coordinates.
"""

import spirit.spiritlib as spiritlib
import spirit.parameters as parameters
import spirit.system as system
import ctypes

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


### Get Chain number of images
_Get_NOI            = _spirit.Chain_Get_NOI
_Get_NOI.argtypes   = [ctypes.c_void_p, ctypes.c_int]
_Get_NOI.restype    = ctypes.c_int
def get_noi(p_state, idx_chain=-1):
    """Get number of images (NOI) in the chain."""
    return int(_Get_NOI(ctypes.c_void_p(p_state), ctypes.c_int(idx_chain)))


### Switch active to next image of chain
_next_Image             = _spirit.Chain_next_Image
_next_Image.argtypes    = [ctypes.c_void_p, ctypes.c_int]
_next_Image.restype     = ctypes.c_bool
def next_image(p_state, idx_chain=-1):
github spirit-code / spirit / core / python / spirit / constants.py View on Github external
"""
Constants
====================
"""

import spirit.spiritlib as spiritlib
import ctypes

from spirit.scalar import scalar

# Load Library
_spirit = spiritlib.load_spirit_library()

_mu_B           = _spirit.Constants_mu_B
_mu_B.argtypes  = None
_mu_B.restype   = scalar
mu_B = _mu_B()
"""The Bohr Magneton [meV / T]"""

_mu_0           = _spirit.Constants_mu_0
_mu_0.argtypes  = None
_mu_0.restype   = scalar
mu_0 = _mu_0()
"""The vacuum permeability [T^2 m^3 / meV]"""

_k_B            = _spirit.Constants_k_B
_k_B.argtypes   = None
_k_B.restype    = scalar
github spirit-code / spirit / core / python / spirit / htst.py View on Github external
"""
HTST
====================

Harmonic transition state theory.

Note that `calculate_prefactor` needs to be called before using any of the getter functions.
"""

import spirit.spiritlib as spiritlib
import spirit.parameters as parameters
import spirit.system as system
import ctypes

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


_Calculate          = _spirit.HTST_Calculate
_Calculate.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int]
_Calculate.restype  = ctypes.c_float
def calculate(p_state, idx_image_minimum, idx_image_sp, idx_chain=-1):
    """Performs an HTST calculation and returns rate prefactor.

    *Note:* this function must be called before any of the getters.
    """
    return _Calculate(p_state, idx_image_minimum, idx_image_sp, idx_chain)


### Get HTST transition rate components
_Get_Info          = _spirit.HTST_Get_Info
_Get_Info.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
github spirit-code / spirit / core / python / spirit / parameters / llg.py View on Github external
"""
Landau-Lifshitz-Gilbert (LLG)
-------------------------------------------------------------
"""

import spirit.spiritlib as spiritlib
from spirit.io import FILEFORMAT_OVF_TEXT
import ctypes

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

### ---------------------------------- Set ----------------------------------

_LLG_Set_Output_Tag          = _spirit.Parameters_LLG_Set_Output_Tag
_LLG_Set_Output_Tag.argtypes = [ctypes.c_void_p, ctypes.c_char_p,
                                ctypes.c_int, ctypes.c_int]
_LLG_Set_Output_Tag.restype  = None
def set_output_tag(p_state, tag, idx_image=-1, idx_chain=-1):
    """Set the tag placed in front of output file names.

    If the tag is "<time>", it will be the date-time of the creation of the state."""
    _LLG_Set_Output_Tag(ctypes.c_void_p(p_state), ctypes.c_char_p(tag.encode('utf-8')),
                        ctypes.c_int(idx_image), ctypes.c_int(idx_chain))

_LLG_Set_Output_Folder          = _spirit.Parameters_LLG_Set_Output_Folder
_LLG_Set_Output_Folder.argtypes = [ctypes.c_void_p, ctypes.c_char_p,</time>
github spirit-code / spirit / core / python / spirit / configuration.py View on Github external
"""
Configuration
====================

Set various spin configurations, such as homogeneous domains, spirals or skyrmions.
"""

import spirit.spiritlib as spiritlib
import ctypes

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

_Domain             = _spirit.Configuration_Domain
_Domain.argtypes    = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float),
                       ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
                       ctypes.c_float, ctypes.c_float, ctypes.c_bool, ctypes.c_int, ctypes.c_int]
_Domain.restype     = None
def domain(p_state, dir, pos=[0,0,0], border_rectangular=[-1,-1,-1], border_cylindrical=-1,
           border_spherical=-1, inverted=False, idx_image=-1, idx_chain=-1):
    """Set a domain (homogeneous) configuration."""
    vec3 = ctypes.c_float * 3
    _Domain(ctypes.c_void_p(p_state), vec3(*dir), vec3(*pos), vec3(*border_rectangular),
            ctypes.c_float(border_cylindrical), ctypes.c_float(border_spherical),
            ctypes.c_bool(inverted), ctypes.c_int(idx_image), ctypes.c_int(idx_chain))

_PlusZ             = _spirit.Configuration_PlusZ
_PlusZ.argtypes    = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float),
github spirit-code / spirit / core / python / spirit / simulation.py View on Github external
====================

This module of Spirit is used to run and monitor iterative calculation methods.

If many iterations are called individually, one should use the single shot simulation functionality.
It avoids the allocations etc. involved when a simulation is started and ended and behaves like a
regular simulation, except that the iterations have to be triggered manually.

Note that the VP and NCG Solvers are only meant for direct minimization and not for dynamics.
"""

import spirit.spiritlib as spiritlib
import ctypes

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

import threading


###     We use a thread for PlayPause, so that KeyboardInterrupt can be forwarded to the CDLL call
###     We might want to think about using PyDLL and about a signal handler in the core library
###     see here: http://stackoverflow.com/questions/14271697/ctrlc-doesnt-interrupt-call-to-shared-library-using-ctypes-in-python


SOLVER_VP = 0
"""Verlet-like velocity projection method."""

SOLVER_SIB = 1
"""Semi-implicit midpoint method B."""

SOLVER_DEPONDT = 2
github spirit-code / spirit / core / python / spirit / transition.py View on Github external
import spirit.spiritlib as spiritlib
import ctypes

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


### Generate homogeneous transition between two images of a chain
_Homogeneous             = _spirit.Transition_Homogeneous
_Homogeneous.argtypes    = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int]
_Homogeneous.restype     = None
def homogeneous(p_state, idx_1, idx_2, idx_chain=-1):
    _Homogeneous(ctypes.c_void_p(p_state), ctypes.c_int(idx_1), ctypes.c_int(idx_2), 
                 ctypes.c_int(idx_chain))

### Add some temperature-scaled noise to a transition between two images of a chain
_Add_Noise_Temperature             = _spirit.Transition_Add_Noise_Temperature
_Add_Noise_Temperature.argtypes    = [ctypes.c_void_p, ctypes.c_float, ctypes.c_int, 
                                      ctypes.c_int, ctypes.c_int]
_Add_Noise_Temperature.restype     = None
def add_noise(p_state, temperature, idx_1, idx_2, idx_chain=-1):
github spirit-code / spirit / core / python / spirit / parameters / ema.py View on Github external
import spirit.spiritlib as spiritlib
import ctypes

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

## ---------------------------------- Set ----------------------------------

### Set number of modes
_EMA_Set_N_Modes          = _spirit.Parameters_EMA_Set_N_Modes
_EMA_Set_N_Modes.argtypes = [ctypes.c_void_p, ctypes.c_int,
                            ctypes.c_int, ctypes.c_int]
_EMA_Set_N_Modes.restype  = None
def set_n_modes(p_state, n_modes, idx_image=-1, idx_chain=-1):
    _EMA_Set_N_Modes(ctypes.c_void_p(p_state), ctypes.c_int(n_modes),
                          ctypes.c_int(idx_image), ctypes.c_int(idx_chain))

### Set index of mode to follow
_EMA_Set_N_Mode_Follow          = _spirit.Parameters_EMA_Set_N_Mode_Follow
_EMA_Set_N_Mode_Follow.argtypes = [ctypes.c_void_p, ctypes.c_int,
                                    ctypes.c_int, ctypes.c_int]