Generated by Cython 3.2.8

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

Raw output: mega_crank.c

+0001: ## ...........................................................................
  __pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_4) < (0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 0002: ##
 0003: ## PIMMS (Polymer Interactions in Multicomponent Mixtures)
 0004: ## Author: Alex Holehouse
 0005: ## Developed by the Holehouse and Pappu labs
 0006: ## Copyright 2015 - 2026
 0007: ##
 0008: ## ...........................................................................
 0009: 
 0010: 
+0011: import numpy as np
  __pyx_t_1 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_numpy, 0, 0, NULL, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
  __pyx_t_4 = __pyx_t_1;
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_np, __pyx_t_4) < (0)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 0012: cimport numpy as cnp
+0013: cnp.import_array()
  __pyx_t_9 = __pyx_f_5numpy_import_array(); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 13, __pyx_L1_error)
 0014: 
 0015: cimport cython
+0016: import random
  __pyx_t_1 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_random, 0, 0, NULL, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error)
  __pyx_t_4 = __pyx_t_1;
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_random, __pyx_t_4) < (0)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 0017: from libc.math cimport exp
 0018: 
 0019: 
 0020: ## Define high performance local min and max functions...
 0021: ##
 0022: 
+0023: cdef inline int int_max(int a, int b): return a if a >= b else b
static CYTHON_INLINE int __pyx_f_5pimms_10mega_crank_int_max(int __pyx_v_a, int __pyx_v_b) {
  int __pyx_r;
  __pyx_t_2 = (__pyx_v_a >= __pyx_v_b);
  if (__pyx_t_2) {
    __pyx_t_1 = __pyx_v_a;
  } else {
    __pyx_t_1 = __pyx_v_b;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
+0024: cdef inline int int_min(int a, int b): return a if a <= b else b
static CYTHON_INLINE int __pyx_f_5pimms_10mega_crank_int_min(int __pyx_v_a, int __pyx_v_b) {
  int __pyx_r;
  __pyx_t_2 = (__pyx_v_a <= __pyx_v_b);
  if (__pyx_t_2) {
    __pyx_t_1 = __pyx_v_a;
  } else {
    __pyx_t_1 = __pyx_v_b;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
 0025: 
 0026: # ---- Monte-Carlo PRNG (splitmix64) --------------------------------------
 0027: # Replaces libc rand()/srand() (macOS rand() is the weak Park-Miller MINSTD LCG;
 0028: # platform-dependent). splitmix64 has period 2^64, passes BigCrush, and is
 0029: # bit-identical to mega_crank_fast's PRNG so the two stay bit-exact. Single
 0030: # module-global state (these reference kernels are single-threaded).
 0031: cdef unsigned long long _RNG_STATE[1]   # module-global serial PRNG state (zero-init)
+0032: cdef int PRNG_MAX = 2147483647          # 2^31 - 1 (fixed, platform-independent)
  __pyx_v_5pimms_10mega_crank_PRNG_MAX = 0x7FFFFFFF;
 0033: 
+0034: cdef inline void mc_seed(unsigned int seedval) noexcept nogil:
static CYTHON_INLINE void __pyx_f_5pimms_10mega_crank_mc_seed(unsigned int __pyx_v_seedval) {
/* … */
  /* function exit code */
}
+0035:     _RNG_STATE[0] = <unsigned long long>seedval
  (__pyx_v_5pimms_10mega_crank__RNG_STATE[0]) = ((unsigned PY_LONG_LONG)__pyx_v_seedval);
 0036: 
+0037: cdef inline int mc_rand() noexcept nogil:
static CYTHON_INLINE int __pyx_f_5pimms_10mega_crank_mc_rand(void) {
  unsigned PY_LONG_LONG __pyx_v_z;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
 0038:     # one splitmix64 step; return the top 31 bits -> [0, PRNG_MAX]
+0039:     _RNG_STATE[0] = _RNG_STATE[0] + <unsigned long long>0x9E3779B97F4A7C15
  (__pyx_v_5pimms_10mega_crank__RNG_STATE[0]) = ((__pyx_v_5pimms_10mega_crank__RNG_STATE[0]) + ((unsigned PY_LONG_LONG)0x9E3779B97F4A7C15));
+0040:     cdef unsigned long long z = _RNG_STATE[0]
  __pyx_v_z = (__pyx_v_5pimms_10mega_crank__RNG_STATE[0]);
+0041:     z = (z ^ (z >> 30)) * <unsigned long long>0xBF58476D1CE4E5B9
  __pyx_v_z = ((__pyx_v_z ^ (__pyx_v_z >> 30)) * ((unsigned PY_LONG_LONG)0xBF58476D1CE4E5B9));
+0042:     z = (z ^ (z >> 27)) * <unsigned long long>0x94D049BB133111EB
  __pyx_v_z = ((__pyx_v_z ^ (__pyx_v_z >> 27)) * ((unsigned PY_LONG_LONG)0x94D049BB133111EB));
+0043:     z = z ^ (z >> 31)
  __pyx_v_z = (__pyx_v_z ^ (__pyx_v_z >> 31));
+0044:     return <int>(z >> 33)
  __pyx_r = ((int)(__pyx_v_z >> 33));
  goto __pyx_L0;
 0045: 
 0046: #from numpy cimport int16_t as NUMPY_INT16_TYPE
 0047: #ctypedef NUMPY_INT16_TYPE  NUMPY_INT_TYPE
 0048: #ctypedef cnp.int64_t NUMPY_INT_TYPE_long
 0049: 
 0050: from pimms.cython_config cimport NUMPY_INT_TYPE
 0051: from pimms.cython_config cimport NUMPY_INT_TYPE_long
+0052: from pimms.CONFIG import NP_INT_TYPE as NUMPY_INT_TYPE_PYTHON
  {
    PyObject* const __pyx_imported_names[] = {__pyx_mstate_global->__pyx_n_u_NP_INT_TYPE};
    __pyx_t_1 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_pimms_CONFIG, __pyx_imported_names, 1, NULL, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error)
  }
  __pyx_t_4 = __pyx_t_1;
  __Pyx_GOTREF(__pyx_t_4);
  {
    PyObject* const __pyx_imported_names[] = {__pyx_mstate_global->__pyx_n_u_NP_INT_TYPE};
    __pyx_t_10 = 0; {
      __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_imported_names[__pyx_t_10]); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 52, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      switch (__pyx_t_10) {
        case 0:
        if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON, __pyx_t_5) < (0)) __PYX_ERR(0, 52, __pyx_L1_error)
        break;
        default:;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 0053: 
 0054: 
+0055: def seed_C_rand(int seedval):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_1seed_C_rand(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_1seed_C_rand = {"seed_C_rand", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_1seed_C_rand, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_1seed_C_rand(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_seedval;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("seed_C_rand (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_seedval,0};
  PyObject* values[1] = {0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 55, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 55, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "seed_C_rand", 0) < (0)) __PYX_ERR(0, 55, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 1; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("seed_C_rand", 1, 1, 1, i); __PYX_ERR(0, 55, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 55, __pyx_L3_error)
    }
    __pyx_v_seedval = __Pyx_PyLong_As_int(values[0]); if (unlikely((__pyx_v_seedval == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 55, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("seed_C_rand", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 55, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_AddTraceback("pimms.mega_crank.seed_C_rand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_seed_C_rand(__pyx_self, __pyx_v_seedval);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_seed_C_rand(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_seedval) {
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_1seed_C_rand, 0, __pyx_mstate_global->__pyx_n_u_seed_C_rand, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_seed_C_rand, __pyx_t_4) < (0)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+0056:     mc_seed(seedval)
  __pyx_f_5pimms_10mega_crank_mc_seed(__pyx_v_seedval);
 0057: 
 0058: 
 0059: #-----------------------------------------------------------------
 0060: #
 0061: #def update_position(cnp.ndarray[NUMPY_INT_TYPE, ndim=1] old_position, cnp.ndarray[NUMPY_INT_TYPE, ndim=3] grid, NUMPY_INT_TYPE x_off, NUMPY_INT_TYPE y_off, NUMPY_INT_TYPE z_off, NUMPY_INT_TYPE XDIM, NUMPY_INT_TYPE YDIM, NUMPY_INT_TYPE ZDIM):
+0062: @cython.wraparound(False)
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_3update_position(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_3update_position = {"update_position", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_3update_position, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_3update_position(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  __Pyx_memviewslice __pyx_v_old_position = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_grid = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_x_off;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_y_off;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_z_off;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_XDIM;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_YDIM;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_ZDIM;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("update_position (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_old_position,&__pyx_mstate_global->__pyx_n_u_grid,&__pyx_mstate_global->__pyx_n_u_x_off,&__pyx_mstate_global->__pyx_n_u_y_off,&__pyx_mstate_global->__pyx_n_u_z_off,&__pyx_mstate_global->__pyx_n_u_XDIM,&__pyx_mstate_global->__pyx_n_u_YDIM,&__pyx_mstate_global->__pyx_n_u_ZDIM,0};
  PyObject* values[8] = {0,0,0,0,0,0,0,0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 62, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  8:
        values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  7:
        values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  6:
        values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  5:
        values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  4:
        values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  3:
        values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  2:
        values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 62, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "update_position", 0) < (0)) __PYX_ERR(0, 62, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 8; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("update_position", 1, 8, 8, i); __PYX_ERR(0, 62, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 8)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 62, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 62, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 62, __pyx_L3_error)
      values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 62, __pyx_L3_error)
      values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 62, __pyx_L3_error)
      values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 62, __pyx_L3_error)
      values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 62, __pyx_L3_error)
      values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 62, __pyx_L3_error)
    }
    __pyx_v_old_position = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_old_position.memview)) __PYX_ERR(0, 64, __pyx_L3_error)
    __pyx_v_grid = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_grid.memview)) __PYX_ERR(0, 64, __pyx_L3_error)
    __pyx_v_x_off = __Pyx_PyLong_As_npy_int32(values[2]); if (unlikely((__pyx_v_x_off == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 64, __pyx_L3_error)
    __pyx_v_y_off = __Pyx_PyLong_As_npy_int32(values[3]); if (unlikely((__pyx_v_y_off == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 64, __pyx_L3_error)
    __pyx_v_z_off = __Pyx_PyLong_As_npy_int32(values[4]); if (unlikely((__pyx_v_z_off == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 64, __pyx_L3_error)
    __pyx_v_XDIM = __Pyx_PyLong_As_npy_int32(values[5]); if (unlikely((__pyx_v_XDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 64, __pyx_L3_error)
    __pyx_v_YDIM = __Pyx_PyLong_As_npy_int32(values[6]); if (unlikely((__pyx_v_YDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 64, __pyx_L3_error)
    __pyx_v_ZDIM = __Pyx_PyLong_As_npy_int32(values[7]); if (unlikely((__pyx_v_ZDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 64, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("update_position", 1, 8, 8, __pyx_nargs); __PYX_ERR(0, 62, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_old_position, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_grid, 1);
  __Pyx_AddTraceback("pimms.mega_crank.update_position", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_2update_position(__pyx_self, __pyx_v_old_position, __pyx_v_grid, __pyx_v_x_off, __pyx_v_y_off, __pyx_v_z_off, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_v_ZDIM);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_old_position, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_grid, 1);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_2update_position(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_old_position, __Pyx_memviewslice __pyx_v_grid, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_x_off, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_y_off, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_z_off, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_XDIM, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_YDIM, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_ZDIM) {
  PyArrayObject *__pyx_v_new_position = 0;
  int __pyx_v_local_x;
  int __pyx_v_local_y;
  int __pyx_v_local_z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_new_position;
  __Pyx_Buffer __pyx_pybuffer_new_position;
  PyObject *__pyx_r = NULL;
  __pyx_pybuffer_new_position.pybuffer.buf = NULL;
  __pyx_pybuffer_new_position.refcount = 0;
  __pyx_pybuffernd_new_position.data = NULL;
  __pyx_pybuffernd_new_position.rcbuffer = &__pyx_pybuffer_new_position;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pimms.mega_crank.update_position", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_new_position);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_3update_position, 0, __pyx_mstate_global->__pyx_n_u_update_position, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 62, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_update_position, __pyx_t_4) < (0)) __PYX_ERR(0, 62, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 0063: @cython.boundscheck(False)
 0064: def update_position(NUMPY_INT_TYPE[:] old_position, NUMPY_INT_TYPE[:,:,:] grid, NUMPY_INT_TYPE x_off, NUMPY_INT_TYPE y_off, NUMPY_INT_TYPE z_off, NUMPY_INT_TYPE XDIM, NUMPY_INT_TYPE YDIM, NUMPY_INT_TYPE ZDIM):
 0065: 
+0066:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position = np.zeros([3], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_2 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 66, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    assert(__pyx_t_2);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, __pyx_t_3};
    __pyx_t_7 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 66, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_5, __pyx_t_7, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 66, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 66, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_new_position = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 66, __pyx_L1_error)
    } else {__pyx_pybuffernd_new_position.diminfo[0].strides = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_position.diminfo[0].shape = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_new_position = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
 0067: 
+0068:     cdef int local_x = pbc_correction(old_position[0] + x_off, XDIM)
  __pyx_t_8 = 0;
  __pyx_t_9 = __pyx_f_5pimms_10mega_crank_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_8 * __pyx_v_old_position.strides[0]) ))) + __pyx_v_x_off), __pyx_v_XDIM); if (unlikely(__pyx_t_9 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L1_error)
  __pyx_v_local_x = __pyx_t_9;
+0069:     cdef int local_y = pbc_correction(old_position[1] + y_off, YDIM)
  __pyx_t_8 = 1;
  __pyx_t_9 = __pyx_f_5pimms_10mega_crank_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_8 * __pyx_v_old_position.strides[0]) ))) + __pyx_v_y_off), __pyx_v_YDIM); if (unlikely(__pyx_t_9 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 69, __pyx_L1_error)
  __pyx_v_local_y = __pyx_t_9;
+0070:     cdef int local_z = pbc_correction(old_position[2] + z_off, ZDIM)
  __pyx_t_8 = 2;
  __pyx_t_9 = __pyx_f_5pimms_10mega_crank_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_8 * __pyx_v_old_position.strides[0]) ))) + __pyx_v_z_off), __pyx_v_ZDIM); if (unlikely(__pyx_t_9 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 70, __pyx_L1_error)
  __pyx_v_local_z = __pyx_t_9;
 0071: 
 0072:     #if grid[new_position[0], new_position[1], new_position[2]] > 0:
+0073:     if grid[local_x, local_y, local_z] > 0:
  __pyx_t_8 = __pyx_v_local_x;
  __pyx_t_10 = __pyx_v_local_y;
  __pyx_t_11 = __pyx_v_local_z;
  __pyx_t_12 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_8 * __pyx_v_grid.strides[0]) ) + __pyx_t_10 * __pyx_v_grid.strides[1]) ) + __pyx_t_11 * __pyx_v_grid.strides[2]) ))) > 0);
  if (__pyx_t_12) {
/* … */
    goto __pyx_L3;
  }
 0074:         # fail
+0075:         new_position[0] = -1
    __pyx_t_11 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_new_position.diminfo[0].strides) = -1;
 0076: 
 0077:     # hard sphere clash
 0078:     else:
 0079:         # success
+0080:         new_position[0] = local_x
  /*else*/ {
    __pyx_t_11 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_x;
+0081:         new_position[1] = local_y
    __pyx_t_11 = 1;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_y;
+0082:         new_position[2] = local_z
    __pyx_t_11 = 2;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_z;
  }
  __pyx_L3:;
 0083: 
+0084:     return (new_position)
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_new_position);
  __pyx_r = ((PyObject *)__pyx_v_new_position);
  goto __pyx_L0;
 0085: 
 0086: 
 0087: #-----------------------------------------------------------------
 0088: #
+0089: @cython.wraparound(False)
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_5mega_crank(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pimms_10mega_crank_4mega_crank, "\n    Some explanation is in order re: what the input variables here below.\n\n\n    THE MOST IMPORT COMMENT: For some inexplicable reason, if we randomly select a bead and randomly select integers for\n    x, y, and z pertubation, we get a correlation between the bead index and the value associated with the final dimension\n    being perturbed. This pertains specifically to \n\n    grid - the main lattice grid\n\n    type_grid - mirrors the lattice grid but the integers represent residue types not chain IDs\n\n    idx_to_bead - this contains ALL the information we need to perturb the lattice. This a x by 6 matrix, where \n                        a is the TOTAL number of beads in the system. Each  index position reveals a vector of length \n                        5 that contains the following information:\n\n                        0 - bead_flag (0 = single bead, 1 = N-terminal bead, 2 = fully central bead (OOXOO), 3 = C-terminal bead\n                                      4 = central bead in a OXO configuration, 5 - N-terminal bead +1 from start)\n                        1 - LR binary flag\n                        2 - intcode value\n                        3 - skip angles (1 = true, 0 = false)\n                        4 - chainID\n                        5 - X position\n                        6 - Y position\n                        7 - Z position (optional - depends on if we're in 3D or not)\n\n    interaction_table - lookup table for the short range interactions of 2 beads\n    \n    LR_interaction_table - lookup table for the long range interactions of 2 beads\n\n    SLR_interaction_table - lookup table for the super long range interactions of 2 beads\n\n    energy - current energy\n\n    invtemp - current inverse temperature\n\n    nsteps - number of steps to perform\n\n    bead_selection - pre-alloacted random selection of beads. Avoids a bug in PRNG\n\n    passed_seeed - a random seed generated by the main program, ensures reproducibility\n\n    ");
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_5mega_crank = {"mega_crank", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_5mega_crank, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pimms_10mega_crank_4mega_crank};
static PyObject *__pyx_pw_5pimms_10mega_crank_5mega_crank(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  __Pyx_memviewslice __pyx_v_grid = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_type_grid = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_idx_to_bead = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_interaction_table = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_LR_interaction_table = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_SLR_interaction_table = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_angle_lookup = { 0, 0, { 0 }, { 0 }, { 0 } };
  long __pyx_v_energy;
  float __pyx_v_invtemp;
  int __pyx_v_nsteps;
  __Pyx_memviewslice __pyx_v_bead_selector = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_passed_seed;
  int __pyx_v_hardwall;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mega_crank (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_grid,&__pyx_mstate_global->__pyx_n_u_type_grid,&__pyx_mstate_global->__pyx_n_u_idx_to_bead,&__pyx_mstate_global->__pyx_n_u_interaction_table,&__pyx_mstate_global->__pyx_n_u_LR_interaction_table,&__pyx_mstate_global->__pyx_n_u_SLR_interaction_table,&__pyx_mstate_global->__pyx_n_u_angle_lookup,&__pyx_mstate_global->__pyx_n_u_energy,&__pyx_mstate_global->__pyx_n_u_invtemp,&__pyx_mstate_global->__pyx_n_u_nsteps,&__pyx_mstate_global->__pyx_n_u_bead_selector,&__pyx_mstate_global->__pyx_n_u_passed_seed,&__pyx_mstate_global->__pyx_n_u_hardwall,0};
  PyObject* values[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 89, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case 13:
        values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case 12:
        values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case 11:
        values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case 10:
        values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  9:
        values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  8:
        values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  7:
        values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  6:
        values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  5:
        values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  4:
        values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  3:
        values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  2:
        values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 89, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "mega_crank", 0) < (0)) __PYX_ERR(0, 89, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 13; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("mega_crank", 1, 13, 13, i); __PYX_ERR(0, 89, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 13)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 89, __pyx_L3_error)
      values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 89, __pyx_L3_error)
    }
    __pyx_v_grid = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_grid.memview)) __PYX_ERR(0, 91, __pyx_L3_error)
    __pyx_v_type_grid = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_type_grid.memview)) __PYX_ERR(0, 92, __pyx_L3_error)
    __pyx_v_idx_to_bead = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long(values[2], PyBUF_WRITABLE); if (unlikely(!__pyx_v_idx_to_bead.memview)) __PYX_ERR(0, 93, __pyx_L3_error)
    __pyx_v_interaction_table = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[3], PyBUF_WRITABLE); if (unlikely(!__pyx_v_interaction_table.memview)) __PYX_ERR(0, 94, __pyx_L3_error)
    __pyx_v_LR_interaction_table = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[4], PyBUF_WRITABLE); if (unlikely(!__pyx_v_LR_interaction_table.memview)) __PYX_ERR(0, 95, __pyx_L3_error)
    __pyx_v_SLR_interaction_table = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[5], PyBUF_WRITABLE); if (unlikely(!__pyx_v_SLR_interaction_table.memview)) __PYX_ERR(0, 96, __pyx_L3_error)
    __pyx_v_angle_lookup = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsdsdsdsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[6], PyBUF_WRITABLE); if (unlikely(!__pyx_v_angle_lookup.memview)) __PYX_ERR(0, 97, __pyx_L3_error)
    __pyx_v_energy = __Pyx_PyLong_As_long(values[7]); if (unlikely((__pyx_v_energy == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 98, __pyx_L3_error)
    __pyx_v_invtemp = __Pyx_PyFloat_AsFloat(values[8]); if (unlikely((__pyx_v_invtemp == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 99, __pyx_L3_error)
    __pyx_v_nsteps = __Pyx_PyLong_As_int(values[9]); if (unlikely((__pyx_v_nsteps == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 100, __pyx_L3_error)
    __pyx_v_bead_selector = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long(values[10], PyBUF_WRITABLE); if (unlikely(!__pyx_v_bead_selector.memview)) __PYX_ERR(0, 101, __pyx_L3_error)
    __pyx_v_passed_seed = __Pyx_PyLong_As_int(values[11]); if (unlikely((__pyx_v_passed_seed == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 102, __pyx_L3_error)
    __pyx_v_hardwall = __Pyx_PyLong_As_int(values[12]); if (unlikely((__pyx_v_hardwall == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 103, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("mega_crank", 1, 13, 13, __pyx_nargs); __PYX_ERR(0, 89, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_grid, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_type_grid, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_idx_to_bead, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_interaction_table, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_LR_interaction_table, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_SLR_interaction_table, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_angle_lookup, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_bead_selector, 1);
  __Pyx_AddTraceback("pimms.mega_crank.mega_crank", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_4mega_crank(__pyx_self, __pyx_v_grid, __pyx_v_type_grid, __pyx_v_idx_to_bead, __pyx_v_interaction_table, __pyx_v_LR_interaction_table, __pyx_v_SLR_interaction_table, __pyx_v_angle_lookup, __pyx_v_energy, __pyx_v_invtemp, __pyx_v_nsteps, __pyx_v_bead_selector, __pyx_v_passed_seed, __pyx_v_hardwall);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_grid, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_type_grid, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_idx_to_bead, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_interaction_table, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_LR_interaction_table, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_SLR_interaction_table, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_angle_lookup, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_bead_selector, 1);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_4mega_crank(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_grid, __Pyx_memviewslice __pyx_v_type_grid, __Pyx_memviewslice __pyx_v_idx_to_bead, __Pyx_memviewslice __pyx_v_interaction_table, __Pyx_memviewslice __pyx_v_LR_interaction_table, __Pyx_memviewslice __pyx_v_SLR_interaction_table, __Pyx_memviewslice __pyx_v_angle_lookup, long __pyx_v_energy, float __pyx_v_invtemp, int __pyx_v_nsteps, __Pyx_memviewslice __pyx_v_bead_selector, int __pyx_v_passed_seed, int __pyx_v_hardwall) {
  unsigned int __pyx_v_i;
  unsigned int __pyx_v_bead_index;
  int __pyx_v_accepted_moves;
  int __pyx_v_XDIM;
  int __pyx_v_YDIM;
  int __pyx_v_ZDIM;
  CYTHON_UNUSED int __pyx_v_num_beads;
  long __pyx_v_delta_energy;
  long __pyx_v_delta_angle_energy;
  PyArrayObject *__pyx_v_position_triptic = 0;
  PyArrayObject *__pyx_v_three_position_holder = 0;
  PyArrayObject *__pyx_v_two_position_holder = 0;
  PyArrayObject *__pyx_v_old_position = 0;
  PyArrayObject *__pyx_v_anchor_bead = 0;
  PyArrayObject *__pyx_v_new_position = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_anchor_bead;
  __Pyx_Buffer __pyx_pybuffer_anchor_bead;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_new_position;
  __Pyx_Buffer __pyx_pybuffer_new_position;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_old_position;
  __Pyx_Buffer __pyx_pybuffer_old_position;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_position_triptic;
  __Pyx_Buffer __pyx_pybuffer_position_triptic;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_three_position_holder;
  __Pyx_Buffer __pyx_pybuffer_three_position_holder;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_two_position_holder;
  __Pyx_Buffer __pyx_pybuffer_two_position_holder;
  PyObject *__pyx_r = NULL;
  __pyx_pybuffer_position_triptic.pybuffer.buf = NULL;
  __pyx_pybuffer_position_triptic.refcount = 0;
  __pyx_pybuffernd_position_triptic.data = NULL;
  __pyx_pybuffernd_position_triptic.rcbuffer = &__pyx_pybuffer_position_triptic;
  __pyx_pybuffer_three_position_holder.pybuffer.buf = NULL;
  __pyx_pybuffer_three_position_holder.refcount = 0;
  __pyx_pybuffernd_three_position_holder.data = NULL;
  __pyx_pybuffernd_three_position_holder.rcbuffer = &__pyx_pybuffer_three_position_holder;
  __pyx_pybuffer_two_position_holder.pybuffer.buf = NULL;
  __pyx_pybuffer_two_position_holder.refcount = 0;
  __pyx_pybuffernd_two_position_holder.data = NULL;
  __pyx_pybuffernd_two_position_holder.rcbuffer = &__pyx_pybuffer_two_position_holder;
  __pyx_pybuffer_old_position.pybuffer.buf = NULL;
  __pyx_pybuffer_old_position.refcount = 0;
  __pyx_pybuffernd_old_position.data = NULL;
  __pyx_pybuffernd_old_position.rcbuffer = &__pyx_pybuffer_old_position;
  __pyx_pybuffer_anchor_bead.pybuffer.buf = NULL;
  __pyx_pybuffer_anchor_bead.refcount = 0;
  __pyx_pybuffernd_anchor_bead.data = NULL;
  __pyx_pybuffernd_anchor_bead.rcbuffer = &__pyx_pybuffer_anchor_bead;
  __pyx_pybuffer_new_position.pybuffer.buf = NULL;
  __pyx_pybuffer_new_position.refcount = 0;
  __pyx_pybuffernd_new_position.data = NULL;
  __pyx_pybuffernd_new_position.rcbuffer = &__pyx_pybuffer_new_position;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_15);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_23, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_24, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_position.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_triptic.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pimms.mega_crank.mega_crank", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_position.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_triptic.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_position_triptic);
  __Pyx_XDECREF((PyObject *)__pyx_v_three_position_holder);
  __Pyx_XDECREF((PyObject *)__pyx_v_two_position_holder);
  __Pyx_XDECREF((PyObject *)__pyx_v_old_position);
  __Pyx_XDECREF((PyObject *)__pyx_v_anchor_bead);
  __Pyx_XDECREF((PyObject *)__pyx_v_new_position);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_5mega_crank, 0, __pyx_mstate_global->__pyx_n_u_mega_crank, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_mega_crank, __pyx_t_4) < (0)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 0090: @cython.boundscheck(False)
 0091: def mega_crank(NUMPY_INT_TYPE[:,:,:] grid,
 0092:                NUMPY_INT_TYPE[:,:,:] type_grid,
 0093:                NUMPY_INT_TYPE_long[:,:] idx_to_bead,
 0094:                NUMPY_INT_TYPE[:,:] interaction_table,
 0095:                NUMPY_INT_TYPE[:,:] LR_interaction_table,
 0096:                NUMPY_INT_TYPE[:,:] SLR_interaction_table,
 0097:                NUMPY_INT_TYPE[:,:,:,:,:,:,:] angle_lookup,
 0098:                long energy,
 0099:                float invtemp,
 0100:                int nsteps,
 0101:                NUMPY_INT_TYPE_long[:] bead_selector,
 0102:                int passed_seed,
 0103:                int hardwall):
 0104:     """
 0105:     Some explanation is in order re: what the input variables here below.
 0106: 
 0107: 
 0108:     THE MOST IMPORT COMMENT: For some inexplicable reason, if we randomly select a bead and randomly select integers for
 0109:     x, y, and z pertubation, we get a correlation between the bead index and the value associated with the final dimension
 0110:     being perturbed. This pertains specifically to
 0111: 
 0112:     grid - the main lattice grid
 0113: 
 0114:     type_grid - mirrors the lattice grid but the integers represent residue types not chain IDs
 0115: 
 0116:     idx_to_bead - this contains ALL the information we need to perturb the lattice. This a x by 6 matrix, where
 0117:                         a is the TOTAL number of beads in the system. Each  index position reveals a vector of length
 0118:                         5 that contains the following information:
 0119: 
 0120:                         0 - bead_flag (0 = single bead, 1 = N-terminal bead, 2 = fully central bead (OOXOO), 3 = C-terminal bead
 0121:                                       4 = central bead in a OXO configuration, 5 - N-terminal bead +1 from start)
 0122:                         1 - LR binary flag
 0123:                         2 - intcode value
 0124:                         3 - skip angles (1 = true, 0 = false)
 0125:                         4 - chainID
 0126:                         5 - X position
 0127:                         6 - Y position
 0128:                         7 - Z position (optional - depends on if we're in 3D or not)
 0129: 
 0130:     interaction_table - lookup table for the short range interactions of 2 beads
 0131: 
 0132:     LR_interaction_table - lookup table for the long range interactions of 2 beads
 0133: 
 0134:     SLR_interaction_table - lookup table for the super long range interactions of 2 beads
 0135: 
 0136:     energy - current energy
 0137: 
 0138:     invtemp - current inverse temperature
 0139: 
 0140:     nsteps - number of steps to perform
 0141: 
 0142:     bead_selection - pre-alloacted random selection of beads. Avoids a bug in PRNG
 0143: 
 0144:     passed_seeed - a random seed generated by the main program, ensures reproducibility
 0145: 
 0146:     """
 0147:     # set randomseed
+0148:     mc_seed(passed_seed)
  __pyx_f_5pimms_10mega_crank_mc_seed(__pyx_v_passed_seed);
 0149: 
 0150:     cdef unsigned int i, bead_index;
 0151:     cdef int accepted_moves;
 0152:     cdef int XDIM, YDIM, ZDIM;
 0153:     cdef int num_beads
 0154:     cdef long delta_energy, delta_angle_energy
 0155: 
+0156:     accepted_moves = 0
  __pyx_v_accepted_moves = 0;
 0157: 
+0158:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] position_triptic = np.zeros([3, 3], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_2 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 158, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 158, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 158, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 1, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 158, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 158, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    assert(__pyx_t_2);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, __pyx_t_3};
    __pyx_t_7 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 158, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_5, __pyx_t_7, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 158, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 158, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_triptic.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_position_triptic = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 158, __pyx_L1_error)
    } else {__pyx_pybuffernd_position_triptic.diminfo[0].strides = __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_position_triptic.diminfo[0].shape = __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_position_triptic.diminfo[1].strides = __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_position_triptic.diminfo[1].shape = __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_v_position_triptic = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+0159:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] three_position_holder = np.zeros([3, 3], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_4 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyList_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_7, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 159, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_7, 1, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 159, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    assert(__pyx_t_4);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_t_7};
    __pyx_t_2 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_3, __pyx_t_2, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 159, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_2);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 159, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_three_position_holder = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 159, __pyx_L1_error)
    } else {__pyx_pybuffernd_three_position_holder.diminfo[0].strides = __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_three_position_holder.diminfo[0].shape = __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_three_position_holder.diminfo[1].strides = __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_three_position_holder.diminfo[1].shape = __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_v_three_position_holder = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+0160:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] two_position_holder = np.zeros([2, 3], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_5 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 160, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 1, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 160, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    assert(__pyx_t_5);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_5, __pyx_t_2};
    __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_7, __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 160, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_3, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 160, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_two_position_holder = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 160, __pyx_L1_error)
    } else {__pyx_pybuffernd_two_position_holder.diminfo[0].strides = __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_two_position_holder.diminfo[0].shape = __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_two_position_holder.diminfo[1].strides = __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_two_position_holder.diminfo[1].shape = __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_v_two_position_holder = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
 0161: 
+0162:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] old_position = np.zeros([3], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_3 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_4, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 162, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
    assert(__pyx_t_3);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_7, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_3, __pyx_t_4};
    __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_2, __pyx_t_5, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 162, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_7, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 162, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_old_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_old_position = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 162, __pyx_L1_error)
    } else {__pyx_pybuffernd_old_position.diminfo[0].strides = __pyx_pybuffernd_old_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_old_position.diminfo[0].shape = __pyx_pybuffernd_old_position.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_old_position = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+0163:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] anchor_bead = np.zeros([3], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_7 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_5, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 163, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
    assert(__pyx_t_7);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_7, __pyx_t_5};
    __pyx_t_3 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_4, __pyx_t_3, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 163, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_2, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 163, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_anchor_bead = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 163, __pyx_L1_error)
    } else {__pyx_pybuffernd_anchor_bead.diminfo[0].strides = __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_anchor_bead.diminfo[0].shape = __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_anchor_bead = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
 0164:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position;
 0165: 
+0166:     XDIM = grid.shape[0]
  __pyx_v_XDIM = (__pyx_v_grid.shape[0]);
+0167:     YDIM = grid.shape[1]
  __pyx_v_YDIM = (__pyx_v_grid.shape[1]);
+0168:     ZDIM = grid.shape[2]
  __pyx_v_ZDIM = (__pyx_v_grid.shape[2]);
 0169: 
 0170: 
 0171:     # get the number of beads
+0172:     num_beads = len(idx_to_bead)
  __pyx_t_8 = __Pyx_MemoryView_Len(__pyx_v_idx_to_bead); 
  __pyx_v_num_beads = __pyx_t_8;
 0173: 
 0174:     # angle short-circuit
+0175:     for i in range(nsteps):
  __pyx_t_9 = __pyx_v_nsteps;
  __pyx_t_10 = __pyx_t_9;
  for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
    __pyx_v_i = __pyx_t_11;
 0176: 
 0177:         # select the bead from the bead_selector, a pre-allocated array of random numbers
+0178:         bead_index   = bead_selector[i]
    __pyx_t_6 = __pyx_v_i;
    __pyx_v_bead_index = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=0 */ (__pyx_v_bead_selector.data + __pyx_t_6 * __pyx_v_bead_selector.strides[0]) )));
 0179: 
 0180:         # get position
+0181:         old_position[0] = idx_to_bead[bead_index,5]
    __pyx_t_6 = __pyx_v_bead_index;
    __pyx_t_12 = 5;
    __pyx_t_13 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_old_position.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+0182:         old_position[1] = idx_to_bead[bead_index,6]
    __pyx_t_6 = __pyx_v_bead_index;
    __pyx_t_12 = 6;
    __pyx_t_13 = 1;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_old_position.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+0183:         old_position[2] = idx_to_bead[bead_index,7]
    __pyx_t_6 = __pyx_v_bead_index;
    __pyx_t_12 = 7;
    __pyx_t_13 = 2;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_old_position.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
 0184: 
 0185: 
 0186:         # ------------------------------------------------------------
 0187:         # if single bead (beadflag == 0)
+0188:         if idx_to_bead[bead_index,0] == 0:
    __pyx_t_6 = __pyx_v_bead_index;
    __pyx_t_12 = 0;
    __pyx_t_14 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) ))) == 0);
    if (__pyx_t_14) {
/* … */
      goto __pyx_L5;
    }
+0189:             new_position = single_bead_crank(old_position, grid, XDIM, YDIM, ZDIM)
      __pyx_t_2 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_single_bead_crank); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_grid, 3, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyLong_From_int(__pyx_v_XDIM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_YDIM); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_15 = __Pyx_PyLong_From_int(__pyx_v_ZDIM); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
        assert(__pyx_t_2);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[6] = {__pyx_t_2, ((PyObject *)__pyx_v_old_position), __pyx_t_4, __pyx_t_5, __pyx_t_7, __pyx_t_15};
        __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_3, __pyx_callargs+__pyx_t_6, (6-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 189, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 189, __pyx_L1_error)
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
        __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_16 < 0)) {
          PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)__pyx_v_new_position, &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
          }
          __pyx_t_17 = __pyx_t_18 = __pyx_t_19 = 0;
        }
        __pyx_pybuffernd_new_position.diminfo[0].strides = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_position.diminfo[0].shape = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.shape[0];
        if (unlikely((__pyx_t_16 < 0))) __PYX_ERR(0, 189, __pyx_L1_error)
      }
      __Pyx_XDECREF_SET(__pyx_v_new_position, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;
 0190: 
 0191: 
 0192:         # ------------------------------------------------------------
 0193:         # if N-terminal bead (beadflag == 1)
+0194:         elif idx_to_bead[bead_index,0] == 1:
    __pyx_t_6 = __pyx_v_bead_index;
    __pyx_t_12 = 0;
    __pyx_t_14 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) ))) == 1);
    if (__pyx_t_14) {
/* … */
      goto __pyx_L5;
    }
+0195:             anchor_bead[0] = idx_to_bead[bead_index+1,5]
      __pyx_t_12 = (__pyx_v_bead_index + 1);
      __pyx_t_13 = 5;
      __pyx_t_20 = 0;
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_anchor_bead.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_12 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
+0196:             anchor_bead[1] = idx_to_bead[bead_index+1,6]
      __pyx_t_13 = (__pyx_v_bead_index + 1);
      __pyx_t_12 = 6;
      __pyx_t_20 = 1;
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_anchor_bead.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_13 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+0197:             anchor_bead[2] = idx_to_bead[bead_index+1,7]
      __pyx_t_12 = (__pyx_v_bead_index + 1);
      __pyx_t_13 = 7;
      __pyx_t_20 = 2;
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_anchor_bead.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_12 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
 0198: 
+0199:             new_position = single_bead_crank(anchor_bead, grid, XDIM, YDIM, ZDIM)
      __pyx_t_3 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_mstate_global->__pyx_n_u_single_bead_crank); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_grid, 3, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_5 = __Pyx_PyLong_From_int(__pyx_v_XDIM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyLong_From_int(__pyx_v_YDIM); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_ZDIM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_15))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_15);
        assert(__pyx_t_3);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_15, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[6] = {__pyx_t_3, ((PyObject *)__pyx_v_anchor_bead), __pyx_t_7, __pyx_t_5, __pyx_t_4, __pyx_t_2};
        __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_15, __pyx_callargs+__pyx_t_6, (6-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 199, __pyx_L1_error)
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
        __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_16 < 0)) {
          PyErr_Fetch(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)__pyx_v_new_position, &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_17);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_19, __pyx_t_18, __pyx_t_17);
          }
          __pyx_t_19 = __pyx_t_18 = __pyx_t_17 = 0;
        }
        __pyx_pybuffernd_new_position.diminfo[0].strides = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_position.diminfo[0].shape = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.shape[0];
        if (unlikely((__pyx_t_16 < 0))) __PYX_ERR(0, 199, __pyx_L1_error)
      }
      __Pyx_XDECREF_SET(__pyx_v_new_position, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;
 0200: 
+0201:             if hardwall == 1:
      __pyx_t_14 = (__pyx_v_hardwall == 1);
      if (__pyx_t_14) {
/* … */
      }
+0202:                 two_position_holder[0,0] = new_position[0]
        __pyx_t_13 = 0;
        __pyx_t_12 = 0;
        __pyx_t_20 = 0;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0203:                 two_position_holder[0,1] = new_position[1]
        __pyx_t_13 = 1;
        __pyx_t_20 = 0;
        __pyx_t_12 = 1;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0204:                 two_position_holder[0,2] = new_position[2]
        __pyx_t_13 = 2;
        __pyx_t_12 = 0;
        __pyx_t_20 = 2;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides));
 0205: 
+0206:                 two_position_holder[1,0] = anchor_bead[0]
        __pyx_t_13 = 0;
        __pyx_t_20 = 1;
        __pyx_t_12 = 0;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_anchor_bead.diminfo[0].strides));
+0207:                 two_position_holder[1,1] = anchor_bead[1]
        __pyx_t_13 = 1;
        __pyx_t_12 = 1;
        __pyx_t_20 = 1;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_anchor_bead.diminfo[0].strides));
+0208:                 two_position_holder[1,2] = anchor_bead[2]
        __pyx_t_13 = 2;
        __pyx_t_20 = 1;
        __pyx_t_12 = 2;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_anchor_bead.diminfo[0].strides));
 0209: 
+0210:                 if do_positions_stradle_pbc_boundary(two_position_holder, 2) == 1:
        __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_two_position_holder), PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 210, __pyx_L1_error)
        __pyx_t_16 = __pyx_f_5pimms_10mega_crank_do_positions_stradle_pbc_boundary(__pyx_t_21, 2); if (unlikely(__pyx_t_16 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 210, __pyx_L1_error)
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 1);
        __pyx_t_21.memview = NULL; __pyx_t_21.data = NULL;
        __pyx_t_14 = (__pyx_t_16 == 1);
        if (__pyx_t_14) {
/* … */
        }
+0211:                     continue
          goto __pyx_L3_continue;
 0212: 
 0213:         # ------------------------------------------------------------
 0214:         # if C-terminal bead (beadflag == 3)
+0215:         elif idx_to_bead[bead_index,0] == 3:
    __pyx_t_6 = __pyx_v_bead_index;
    __pyx_t_13 = 0;
    __pyx_t_14 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) ))) == 3);
    if (__pyx_t_14) {
/* … */
      goto __pyx_L5;
    }
 0216: 
+0217:             anchor_bead[0] = idx_to_bead[bead_index-1,5]
      __pyx_t_13 = (__pyx_v_bead_index - 1);
      __pyx_t_12 = 5;
      __pyx_t_20 = 0;
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_anchor_bead.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_13 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+0218:             anchor_bead[1] = idx_to_bead[bead_index-1,6]
      __pyx_t_12 = (__pyx_v_bead_index - 1);
      __pyx_t_13 = 6;
      __pyx_t_20 = 1;
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_anchor_bead.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_12 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
+0219:             anchor_bead[2] = idx_to_bead[bead_index-1,7]
      __pyx_t_13 = (__pyx_v_bead_index - 1);
      __pyx_t_12 = 7;
      __pyx_t_20 = 2;
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_anchor_bead.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_13 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
 0220: 
+0221:             new_position = single_bead_crank(anchor_bead, grid, XDIM, YDIM, ZDIM)
      __pyx_t_15 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_single_bead_crank); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_grid, 3, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyLong_From_int(__pyx_v_XDIM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_YDIM); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_3 = __Pyx_PyLong_From_int(__pyx_v_ZDIM); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_2);
        assert(__pyx_t_15);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_15);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[6] = {__pyx_t_15, ((PyObject *)__pyx_v_anchor_bead), __pyx_t_4, __pyx_t_5, __pyx_t_7, __pyx_t_3};
        __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_2, __pyx_callargs+__pyx_t_6, (6-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 221, __pyx_L1_error)
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
        __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_16 < 0)) {
          PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)__pyx_v_new_position, &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
          }
          __pyx_t_17 = __pyx_t_18 = __pyx_t_19 = 0;
        }
        __pyx_pybuffernd_new_position.diminfo[0].strides = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_position.diminfo[0].shape = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.shape[0];
        if (unlikely((__pyx_t_16 < 0))) __PYX_ERR(0, 221, __pyx_L1_error)
      }
      __Pyx_XDECREF_SET(__pyx_v_new_position, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;
 0222: 
+0223:             if hardwall == 1:
      __pyx_t_14 = (__pyx_v_hardwall == 1);
      if (__pyx_t_14) {
/* … */
      }
+0224:                 two_position_holder[0,0] = anchor_bead[0]
        __pyx_t_12 = 0;
        __pyx_t_13 = 0;
        __pyx_t_20 = 0;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_anchor_bead.diminfo[0].strides));
+0225:                 two_position_holder[0,1] = anchor_bead[1]
        __pyx_t_12 = 1;
        __pyx_t_20 = 0;
        __pyx_t_13 = 1;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_anchor_bead.diminfo[0].strides));
+0226:                 two_position_holder[0,2] = anchor_bead[2]
        __pyx_t_12 = 2;
        __pyx_t_13 = 0;
        __pyx_t_20 = 2;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_anchor_bead.diminfo[0].strides));
 0227: 
+0228:                 two_position_holder[1,0] = new_position[0]
        __pyx_t_12 = 0;
        __pyx_t_20 = 1;
        __pyx_t_13 = 0;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0229:                 two_position_holder[1,1] = new_position[1]
        __pyx_t_12 = 1;
        __pyx_t_13 = 1;
        __pyx_t_20 = 1;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0230:                 two_position_holder[1,2] = new_position[2]
        __pyx_t_12 = 2;
        __pyx_t_20 = 1;
        __pyx_t_13 = 2;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_two_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_two_position_holder.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_two_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_new_position.diminfo[0].strides));
 0231: 
+0232:                 if do_positions_stradle_pbc_boundary(two_position_holder,2) == 1:
        __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_two_position_holder), PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 232, __pyx_L1_error)
        __pyx_t_16 = __pyx_f_5pimms_10mega_crank_do_positions_stradle_pbc_boundary(__pyx_t_21, 2); if (unlikely(__pyx_t_16 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 232, __pyx_L1_error)
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 1);
        __pyx_t_21.memview = NULL; __pyx_t_21.data = NULL;
        __pyx_t_14 = (__pyx_t_16 == 1);
        if (__pyx_t_14) {
/* … */
        }
+0233:                     continue
          goto __pyx_L3_continue;
 0234: 
 0235:         # ------------------------------------------------------------
 0236:         # we're somewhere inside the chain, and beadflag is 2,4,5, or 6
 0237:         else:
+0238:             position_triptic[0,0] = idx_to_bead[bead_index-1,5]
    /*else*/ {
      __pyx_t_12 = (__pyx_v_bead_index - 1);
      __pyx_t_13 = 5;
      __pyx_t_20 = 0;
      __pyx_t_22 = 0;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_12 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
+0239:             position_triptic[0,1] = idx_to_bead[bead_index-1,6]
      __pyx_t_13 = (__pyx_v_bead_index - 1);
      __pyx_t_12 = 6;
      __pyx_t_22 = 0;
      __pyx_t_20 = 1;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_13 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+0240:             position_triptic[0,2] = idx_to_bead[bead_index-1,7]
      __pyx_t_12 = (__pyx_v_bead_index - 1);
      __pyx_t_13 = 7;
      __pyx_t_20 = 0;
      __pyx_t_22 = 2;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_12 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
 0241: 
+0242:             position_triptic[1,0] = idx_to_bead[bead_index,5]
      __pyx_t_6 = __pyx_v_bead_index;
      __pyx_t_13 = 5;
      __pyx_t_12 = 1;
      __pyx_t_22 = 0;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
+0243:             position_triptic[1,1] = idx_to_bead[bead_index,6]
      __pyx_t_6 = __pyx_v_bead_index;
      __pyx_t_13 = 6;
      __pyx_t_22 = 1;
      __pyx_t_12 = 1;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
+0244:             position_triptic[1,2] = idx_to_bead[bead_index,7]
      __pyx_t_6 = __pyx_v_bead_index;
      __pyx_t_13 = 7;
      __pyx_t_12 = 1;
      __pyx_t_22 = 2;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
 0245: 
+0246:             position_triptic[2,0] = idx_to_bead[bead_index+1,5]
      __pyx_t_13 = (__pyx_v_bead_index + 1);
      __pyx_t_22 = 5;
      __pyx_t_12 = 2;
      __pyx_t_20 = 0;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_13 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_22 * __pyx_v_idx_to_bead.strides[1]) )));
+0247:             position_triptic[2,1] = idx_to_bead[bead_index+1,6]
      __pyx_t_22 = (__pyx_v_bead_index + 1);
      __pyx_t_13 = 6;
      __pyx_t_20 = 2;
      __pyx_t_12 = 1;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_22 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_13 * __pyx_v_idx_to_bead.strides[1]) )));
+0248:             position_triptic[2,2] = idx_to_bead[bead_index+1,7]
      __pyx_t_13 = (__pyx_v_bead_index + 1);
      __pyx_t_22 = 7;
      __pyx_t_12 = 2;
      __pyx_t_20 = 2;
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_13 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_22 * __pyx_v_idx_to_bead.strides[1]) )));
 0249: 
 0250:             # normal crank move!
+0251:             new_position = crank_it(position_triptic, grid, XDIM, YDIM, ZDIM)
      __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_position_triptic), PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 251, __pyx_L1_error)
      __pyx_t_1 = ((PyObject *)__pyx_f_5pimms_10mega_crank_crank_it(__pyx_t_21, __pyx_v_grid, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_v_ZDIM)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 1);
      __pyx_t_21.memview = NULL; __pyx_t_21.data = NULL;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
        __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_16 < 0)) {
          PyErr_Fetch(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)__pyx_v_new_position, &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_17);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_19, __pyx_t_18, __pyx_t_17);
          }
          __pyx_t_19 = __pyx_t_18 = __pyx_t_17 = 0;
        }
        __pyx_pybuffernd_new_position.diminfo[0].strides = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_position.diminfo[0].shape = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.shape[0];
        if (unlikely((__pyx_t_16 < 0))) __PYX_ERR(0, 251, __pyx_L1_error)
      }
      __Pyx_XDECREF_SET(__pyx_v_new_position, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;
 0252: 
+0253:             if hardwall == 1:
      __pyx_t_14 = (__pyx_v_hardwall == 1);
      if (__pyx_t_14) {
/* … */
      }
    }
    __pyx_L5:;
+0254:                 three_position_holder[0,0] = position_triptic[0,0]
        __pyx_t_22 = 0;
        __pyx_t_13 = 0;
        __pyx_t_20 = 0;
        __pyx_t_12 = 0;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_position_triptic.diminfo[1].strides));
+0255:                 three_position_holder[0,1] = position_triptic[0,1]
        __pyx_t_13 = 0;
        __pyx_t_22 = 1;
        __pyx_t_12 = 0;
        __pyx_t_20 = 1;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[1].strides));
+0256:                 three_position_holder[0,2] = position_triptic[0,2]
        __pyx_t_22 = 0;
        __pyx_t_13 = 2;
        __pyx_t_20 = 0;
        __pyx_t_12 = 2;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_position_triptic.diminfo[1].strides));
 0257: 
 0258: 
+0259:                 three_position_holder[1,0] = new_position[0]
        __pyx_t_13 = 0;
        __pyx_t_22 = 1;
        __pyx_t_12 = 0;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0260:                 three_position_holder[1,1] = new_position[1]
        __pyx_t_13 = 1;
        __pyx_t_12 = 1;
        __pyx_t_22 = 1;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0261:                 three_position_holder[1,2] = new_position[2]
        __pyx_t_13 = 2;
        __pyx_t_22 = 1;
        __pyx_t_12 = 2;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides));
 0262: 
+0263:                 three_position_holder[2,0] = position_triptic[2,0]
        __pyx_t_13 = 2;
        __pyx_t_12 = 0;
        __pyx_t_22 = 2;
        __pyx_t_20 = 0;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[1].strides));
+0264:                 three_position_holder[2,1] = position_triptic[2,1]
        __pyx_t_12 = 2;
        __pyx_t_13 = 1;
        __pyx_t_20 = 2;
        __pyx_t_22 = 1;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_position_triptic.diminfo[1].strides));
+0265:                 three_position_holder[2,2] = position_triptic[2,2]
        __pyx_t_13 = 2;
        __pyx_t_12 = 2;
        __pyx_t_22 = 2;
        __pyx_t_20 = 2;
        *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_three_position_holder.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_three_position_holder.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_three_position_holder.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[1].strides));
 0266: 
+0267:                 if do_positions_stradle_pbc_boundary(three_position_holder,3) == 1:
        __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_three_position_holder), PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 267, __pyx_L1_error)
        __pyx_t_16 = __pyx_f_5pimms_10mega_crank_do_positions_stradle_pbc_boundary(__pyx_t_21, 3); if (unlikely(__pyx_t_16 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 267, __pyx_L1_error)
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 1);
        __pyx_t_21.memview = NULL; __pyx_t_21.data = NULL;
        __pyx_t_14 = (__pyx_t_16 == 1);
        if (__pyx_t_14) {
/* … */
        }
+0268:                     continue
          goto __pyx_L3_continue;
 0269: 
 0270: 
 0271:         # if hardsphere success
+0272:         if not new_position[0] < 0:
    __pyx_t_12 = 0;
    __pyx_t_14 = (!((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_new_position.diminfo[0].strides)) < 0));
    if (__pyx_t_14) {
/* … */
      goto __pyx_L12;
    }
 0273: 
+0274:             delta_energy = get_energy_change(grid, type_grid, old_position, new_position, idx_to_bead[bead_index,1],  interaction_table, LR_interaction_table, SLR_interaction_table, XDIM, YDIM, ZDIM, hardwall)
      __pyx_t_23 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_old_position), PyBUF_WRITABLE); if (unlikely(!__pyx_t_23.memview)) __PYX_ERR(0, 274, __pyx_L1_error)
      __pyx_t_24 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_new_position), PyBUF_WRITABLE); if (unlikely(!__pyx_t_24.memview)) __PYX_ERR(0, 274, __pyx_L1_error)
      __pyx_t_6 = __pyx_v_bead_index;
      __pyx_t_12 = 1;
      __pyx_t_1 = __pyx_f_5pimms_10mega_crank_get_energy_change(__pyx_v_grid, __pyx_v_type_grid, __pyx_t_23, __pyx_t_24, (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) ))), __pyx_v_interaction_table, __pyx_v_LR_interaction_table, __pyx_v_SLR_interaction_table, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_v_ZDIM, __pyx_v_hardwall); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 274, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_23, 1);
      __pyx_t_23.memview = NULL; __pyx_t_23.data = NULL;
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_24, 1);
      __pyx_t_24.memview = NULL; __pyx_t_24.data = NULL;
      __pyx_t_25 = __Pyx_PyLong_As_long(__pyx_t_1); if (unlikely((__pyx_t_25 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 274, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_delta_energy = __pyx_t_25;
+0275:             delta_angle_energy = get_angle_energy_change(bead_index, idx_to_bead, new_position, angle_lookup)
      __pyx_t_24 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_new_position), PyBUF_WRITABLE); if (unlikely(!__pyx_t_24.memview)) __PYX_ERR(0, 275, __pyx_L1_error)
      __pyx_t_25 = __pyx_f_5pimms_10mega_crank_get_angle_energy_change(__pyx_v_bead_index, __pyx_v_idx_to_bead, __pyx_t_24, __pyx_v_angle_lookup); if (unlikely(__pyx_t_25 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(0, 275, __pyx_L1_error)
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_24, 1);
      __pyx_t_24.memview = NULL; __pyx_t_24.data = NULL;
      __pyx_v_delta_angle_energy = __pyx_t_25;
 0276: 
+0277:             if accept_or_reject(invtemp, energy, energy+delta_energy+delta_angle_energy) == 1:
      __pyx_t_16 = __pyx_f_5pimms_10mega_crank_accept_or_reject(__pyx_v_invtemp, __pyx_v_energy, ((__pyx_v_energy + __pyx_v_delta_energy) + __pyx_v_delta_angle_energy)); if (unlikely(__pyx_t_16 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 277, __pyx_L1_error)
      __pyx_t_14 = (__pyx_t_16 == 1);
      if (__pyx_t_14) {
/* … */
        goto __pyx_L13;
      }
 0278: 
 0279:                 #with open('crankshaft_accepted.txt','a') as fh:
 0280:                 #    fh.write('%i, %i, %i, %i, %i \n' % (old_position[0] - new_position[0], old_position[1] - new_position[1], old_position[2] - new_position[2], bead_index, chainID))
 0281: 
 0282:                 # delete from main grid and insert into new position
+0283:                 grid[old_position[0], old_position[1], old_position[2]] = 0
        __pyx_t_12 = 0;
        __pyx_t_13 = 1;
        __pyx_t_20 = 2;
        __pyx_t_22 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_old_position.diminfo[0].strides));
        __pyx_t_26 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_old_position.diminfo[0].strides));
        __pyx_t_27 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_old_position.diminfo[0].strides));
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_22 * __pyx_v_grid.strides[0]) ) + __pyx_t_26 * __pyx_v_grid.strides[1]) ) + __pyx_t_27 * __pyx_v_grid.strides[2]) )) = 0;
 0284: 
 0285:                 # inert the bead to its new position
+0286:                 grid[new_position[0],new_position[1],new_position[2]] = idx_to_bead[bead_index,4]
        __pyx_t_6 = __pyx_v_bead_index;
        __pyx_t_20 = 4;
        __pyx_t_13 = 0;
        __pyx_t_12 = 1;
        __pyx_t_27 = 2;
        __pyx_t_26 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides));
        __pyx_t_22 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_new_position.diminfo[0].strides));
        __pyx_t_28 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_new_position.diminfo[0].strides));
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_26 * __pyx_v_grid.strides[0]) ) + __pyx_t_22 * __pyx_v_grid.strides[1]) ) + __pyx_t_28 * __pyx_v_grid.strides[2]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_20 * __pyx_v_idx_to_bead.strides[1]) )));
 0287: 
 0288:                 # set new type grid to old type grid value
+0289:                 type_grid[new_position[0],new_position[1],new_position[2]] = type_grid[old_position[0], old_position[1], old_position[2]]
        __pyx_t_20 = 0;
        __pyx_t_27 = 1;
        __pyx_t_12 = 2;
        __pyx_t_13 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_old_position.diminfo[0].strides));
        __pyx_t_28 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_old_position.diminfo[0].strides));
        __pyx_t_22 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_old_position.diminfo[0].strides));
        __pyx_t_26 = 0;
        __pyx_t_29 = 1;
        __pyx_t_30 = 2;
        __pyx_t_31 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_new_position.diminfo[0].strides));
        __pyx_t_32 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_new_position.diminfo[0].strides));
        __pyx_t_33 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_new_position.diminfo[0].strides));
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_31 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_32 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_33 * __pyx_v_type_grid.strides[2]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_13 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_28 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_22 * __pyx_v_type_grid.strides[2]) )));
 0290: 
 0291:                 # zero out old position on type grid
+0292:                 type_grid[old_position[0], old_position[1], old_position[2]] = 0
        __pyx_t_12 = 0;
        __pyx_t_27 = 1;
        __pyx_t_20 = 2;
        __pyx_t_22 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_old_position.diminfo[0].strides));
        __pyx_t_28 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_old_position.diminfo[0].strides));
        __pyx_t_13 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_old_position.diminfo[0].strides));
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_22 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_28 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_13 * __pyx_v_type_grid.strides[2]) )) = 0;
 0293: 
 0294:                 # IMPORTANT!!! This change *MUST* be done last as the old_position is actually a reference
 0295:                 # to chain_position[bead_index] so changing it BEFORE hand changes the old_position variable and
 0296:                 # breaks everything
+0297:                 idx_to_bead[bead_index,5] = new_position[0]
        __pyx_t_20 = 0;
        __pyx_t_6 = __pyx_v_bead_index;
        __pyx_t_27 = 5;
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_27 * __pyx_v_idx_to_bead.strides[1]) )) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0298:                 idx_to_bead[bead_index,6] = new_position[1]
        __pyx_t_20 = 1;
        __pyx_t_6 = __pyx_v_bead_index;
        __pyx_t_27 = 6;
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_27 * __pyx_v_idx_to_bead.strides[1]) )) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_new_position.diminfo[0].strides));
+0299:                 idx_to_bead[bead_index,7] = new_position[2]
        __pyx_t_20 = 2;
        __pyx_t_6 = __pyx_v_bead_index;
        __pyx_t_27 = 7;
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_6 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_27 * __pyx_v_idx_to_bead.strides[1]) )) = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_new_position.diminfo[0].strides));
 0300: 
+0301:                 energy = energy + delta_energy + delta_angle_energy
        __pyx_v_energy = ((__pyx_v_energy + __pyx_v_delta_energy) + __pyx_v_delta_angle_energy);
+0302:                 accepted_moves = accepted_moves + 1
        __pyx_v_accepted_moves = (__pyx_v_accepted_moves + 1);
 0303: 
 0304:             else:
 0305:                 #with open('crankshaft_rejected.txt','a') as fh:
 0306:                 #    fh.write('%i, %i, %i, %i, %i \n' % (old_position[0] - new_position[0], old_position[1] - new_position[1], old_position[2] - new_position[2], bead_index, chainID))
+0307:                 pass
      /*else*/ {
      }
      __pyx_L13:;
 0308:         else:
 0309: 
 0310:             #with open('crankshaft_failed.txt','a') as fh:
 0311:             #        fh.write('%i, %i, %i, %i, %i \n' % (old_position[0] - new_position[0], old_position[1] - new_position[1], old_position[2] - new_position[2], bead_index, chainID))
+0312:             pass
    /*else*/ {
    }
    __pyx_L12:;
    __pyx_L3_continue:;
  }
 0313: 
 0314: 
 0315: 
 0316: 
+0317:     return (energy, accepted_moves)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyLong_From_long(__pyx_v_energy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_accepted_moves); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 317, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 317, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2) != (0)) __PYX_ERR(0, 317, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;
 0318: 
 0319: 
 0320: #-----------------------------------------------------------------
 0321: #
+0322: cdef int get_random_position(int chain_length):
static int __pyx_f_5pimms_10mega_crank_get_random_position(int __pyx_v_chain_length) {
  int __pyx_v_r;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pimms.mega_crank.get_random_position", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}
 0323:     """
 0324:     Returns a random number between 0 and chain_length,
 0325:     where both 0 and chain_length are inclusive
 0326: 
 0327:     """
 0328: 
 0329:     cdef  int r;
+0330:     r = randint(0, chain_length)
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_randint(0, __pyx_v_chain_length); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 330, __pyx_L1_error)
  __pyx_v_r = __pyx_t_1;
 0331: 
+0332:     return (r)
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;
 0333: 
+0334: def get_random_position_python(int chain_length):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_7get_random_position_python(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_7get_random_position_python = {"get_random_position_python", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_7get_random_position_python, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_7get_random_position_python(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_chain_length;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_random_position_python (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_chain_length,0};
  PyObject* values[1] = {0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 334, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 334, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "get_random_position_python", 0) < (0)) __PYX_ERR(0, 334, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 1; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("get_random_position_python", 1, 1, 1, i); __PYX_ERR(0, 334, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 334, __pyx_L3_error)
    }
    __pyx_v_chain_length = __Pyx_PyLong_As_int(values[0]); if (unlikely((__pyx_v_chain_length == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 334, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_random_position_python", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 334, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_AddTraceback("pimms.mega_crank.get_random_position_python", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_6get_random_position_python(__pyx_self, __pyx_v_chain_length);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_6get_random_position_python(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_chain_length) {
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pimms.mega_crank.get_random_position_python", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_7get_random_position_python, 0, __pyx_mstate_global->__pyx_n_u_get_random_position_python, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[3])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_get_random_position_python, __pyx_t_4) < (0)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+0335:     return get_random_position(chain_length)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_get_random_position(__pyx_v_chain_length); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 335, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;
 0336: 
+0337: def randint_python(start,end):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_9randint_python(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_9randint_python = {"randint_python", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_9randint_python, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_9randint_python(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("randint_python (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_start,&__pyx_mstate_global->__pyx_n_u_end,0};
  PyObject* values[2] = {0,0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 337, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  2:
        values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 337, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 337, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "randint_python", 0) < (0)) __PYX_ERR(0, 337, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 2; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("randint_python", 1, 2, 2, i); __PYX_ERR(0, 337, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 337, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 337, __pyx_L3_error)
    }
    __pyx_v_start = values[0];
    __pyx_v_end = values[1];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("randint_python", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 337, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_AddTraceback("pimms.mega_crank.randint_python", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_8randint_python(__pyx_self, __pyx_v_start, __pyx_v_end);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_8randint_python(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) {
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pimms.mega_crank.randint_python", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_9randint_python, 0, __pyx_mstate_global->__pyx_n_u_randint_python, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[4])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_randint_python, __pyx_t_4) < (0)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+0338:     return randint(start, end)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyLong_As_int(__pyx_v_start); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 338, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyLong_As_int(__pyx_v_end); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 338, __pyx_L1_error)
  __pyx_t_3 = __pyx_f_5pimms_10mega_crank_randint(__pyx_t_1, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 338, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyLong_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;
 0339: 
 0340: 
 0341: #-----------------------------------------------------------------
 0342: #
+0343: cdef int randint(int start, int end):
static int __pyx_f_5pimms_10mega_crank_randint(int __pyx_v_start, int __pyx_v_end) {
  int __pyx_v_r;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pimms.mega_crank.randint", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0344:     """
 0345:     returns a random integer between start and end inclusive
 0346:     of ends.
 0347: 
 0348:     This mirrors random.randint's behaviour. NOTE
 0349:     numpy.random.randint and random.randint HAVE DIFFERENT
 0350:     BEHAVIOUR. This is daft... We use random.randint here
 0351:     (where start and end are both incusive).
 0352: 
 0353:     e.g. start = 0 and end=5 gives one of 0,1,2,3,4,5
 0354: 
 0355:     """
 0356: 
 0357:     # this is inelegant but makes everything work out...
+0358:     if start == 0:
  __pyx_t_1 = (__pyx_v_start == 0);
  if (__pyx_t_1) {
/* … */
    goto __pyx_L3;
  }
+0359:         end=end+1
    __pyx_v_end = (__pyx_v_end + 1);
 0360:     else:
+0361:         pass
  /*else*/ {
  }
  __pyx_L3:;
 0362: 
 0363:     # ok so this is kind of inelegant too, but the rand()-1 is actually important
 0364:     # if we don'te have this we risk the situation where rand() == RAND_MAX
 0365:     # which would cause r = (start+end) which if start was 0 end has
 0366:     # become end+1 so we get a value of end+1 (i.e. outside the range)
+0367:     cdef  int r = start+int((float(mc_rand()-1)/float(PRNG_MAX))*(end))
  __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (unlikely(((double)__pyx_v_5pimms_10mega_crank_PRNG_MAX) == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 367, __pyx_L1_error)
  }
  __pyx_t_3 = PyLong_FromDouble(((((double)(__pyx_f_5pimms_10mega_crank_mc_rand() - 1)) / ((double)__pyx_v_5pimms_10mega_crank_PRNG_MAX)) * __pyx_v_end)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyLong_As_int(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_r = __pyx_t_5;
 0368: 
 0369: 
+0370:     return r
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;
 0371: 
 0372: 
 0373: #-----------------------------------------------------------------
 0374: #
+0375: @cython.wraparound(False)
static PyArrayObject *__pyx_f_5pimms_10mega_crank_crank_it(__Pyx_memviewslice __pyx_v_position_triptic, __Pyx_memviewslice __pyx_v_grid, int __pyx_v_XDIM, int __pyx_v_YDIM, int __pyx_v_ZDIM) {
  int __pyx_v_N_side_x;
  int __pyx_v_N_side_y;
  int __pyx_v_N_side_z;
  int __pyx_v_C_side_x;
  int __pyx_v_C_side_y;
  int __pyx_v_C_side_z;
  int __pyx_v_x_min;
  int __pyx_v_x_max;
  int __pyx_v_y_min;
  int __pyx_v_y_max;
  int __pyx_v_z_min;
  int __pyx_v_z_max;
  PyArrayObject *__pyx_v_new_position = 0;
  int __pyx_v_local_x;
  int __pyx_v_local_y;
  int __pyx_v_local_z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_new_position;
  __Pyx_Buffer __pyx_pybuffer_new_position;
  PyArrayObject *__pyx_r = NULL;
  __pyx_pybuffer_new_position.pybuffer.buf = NULL;
  __pyx_pybuffer_new_position.refcount = 0;
  __pyx_pybuffernd_new_position.data = NULL;
  __pyx_pybuffernd_new_position.rcbuffer = &__pyx_pybuffer_new_position;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pimms.mega_crank.crank_it", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_new_position);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0376: @cython.boundscheck(False)
 0377: cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] crank_it(NUMPY_INT_TYPE[:,:] position_triptic, NUMPY_INT_TYPE[:,:,:] grid, int XDIM, int YDIM, int ZDIM):
 0378:     """
 0379:     Perform crankshaft move! This uses then i-1 and i+1 positions to constraint the
 0380:     possible locations the ith bead can move to, and then offers a random new
 0381:     position within these constraints. If this move leads to a hardwall clash, the
 0382:     move is rejected, otherwise the new position is returned and the energy of the
 0383:     new configuration is calculated elsewhere for metropolis acceptance.
 0384: 
 0385:     Parameters
 0386:     ----------
 0387:     position_triptic : numpy.ndarray
 0388:         A 3x3 numpy array containing the x,y,z positions of the -1, 0 and 1 positions
 0389:         of the chain, where position 0 is the one to be moved constrained by positions
 0390:         -1 and 1.
 0391: 
 0392:     grid : numpy.ndarray
 0393:         The grid of the system; used to reject hardwall clashes after a move is proposed
 0394: 
 0395:     XDIM : int
 0396:         The x dimension of the grid
 0397: 
 0398:     YDIM : int
 0399:         The y dimension of the grid
 0400: 
 0401:     ZDIM : int
 0402:         The z dimension of the grid
 0403: 
 0404:     Returns
 0405:     -------
 0406:     cnp.ndarray
 0407:          A 1x3 numpy array containing the PBC corrected position of the bead to be moved. If
 0408:          the move is rejected, the first elemented in the 1x3 array is set to -1, else all values
 0409:          in the array are positive integers that fall within the grid (0 or larger).
 0410: 
 0411:     """
 0412: 
 0413:     cdef int N_side_x, N_side_y, N_side_z, C_side_x, C_side_y, C_side_z;
 0414:     cdef int x_min, x_max, y_min, y_max, z_min, z_max
+0415:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position = np.zeros([3], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_2 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 415, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    assert(__pyx_t_2);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, __pyx_t_3};
    __pyx_t_7 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 415, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_5, __pyx_t_7, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 415, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 415, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 415, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_new_position = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 415, __pyx_L1_error)
    } else {__pyx_pybuffernd_new_position.diminfo[0].strides = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_position.diminfo[0].shape = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_new_position = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
 0416: 
 0417: 
 0418:     # extract out x and y positions and perform a series of PBC corrections as needed
+0419:     N_side_x = position_triptic[0,0]
  __pyx_t_8 = 0;
  __pyx_t_9 = 0;
  __pyx_v_N_side_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) )));
+0420:     N_side_y = position_triptic[0,1]
  __pyx_t_9 = 0;
  __pyx_t_8 = 1;
  __pyx_v_N_side_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) )));
+0421:     N_side_z = position_triptic[0,2]
  __pyx_t_8 = 0;
  __pyx_t_9 = 2;
  __pyx_v_N_side_z = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) )));
 0422: 
+0423:     C_side_x = position_triptic[2,0]
  __pyx_t_9 = 2;
  __pyx_t_8 = 0;
  __pyx_v_C_side_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) )));
+0424:     C_side_y = position_triptic[2,1]
  __pyx_t_8 = 2;
  __pyx_t_9 = 1;
  __pyx_v_C_side_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) )));
+0425:     C_side_z = position_triptic[2,2]
  __pyx_t_9 = 2;
  __pyx_t_8 = 2;
  __pyx_v_C_side_z = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) )));
 0426: 
 0427: 
 0428:     #print "Before 'correction' "
 0429:     #print "Before positions (from var) [%i, %i, %i]]" % (N_side_x, N_side_y, N_side_z)
 0430:     #print "After positions  (from var) [%i, %i, %i]]" % (C_side_x, C_side_y, C_side_z)
 0431: 
 0432: 
 0433:     ## Periodicity fix 1
 0434:     # move into a non-periodic space just for now
 0435: 
 0436:     # if we're over 2 lattice sites away in any dimension
 0437:     # this must be straddling a PBC, so figure out which of
 0438:     # the two dimensions is the biggest and move the smaller
 0439:     # into the 'fake' space so they're no longer in PBC
+0440:     if abs(N_side_x - C_side_x) > 2:
  __pyx_t_10 = abs((__pyx_v_N_side_x - __pyx_v_C_side_x)); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 440, __pyx_L1_error)
  __pyx_t_11 = (__pyx_t_10 > 2);
  if (__pyx_t_11) {
/* … */
  }
+0441:         if N_side_x > C_side_x:
    __pyx_t_11 = (__pyx_v_N_side_x > __pyx_v_C_side_x);
    if (__pyx_t_11) {
/* … */
      goto __pyx_L4;
    }
+0442:             C_side_x = C_side_x + XDIM
      __pyx_v_C_side_x = (__pyx_v_C_side_x + __pyx_v_XDIM);
 0443:         else:
+0444:             N_side_x = N_side_x + XDIM
    /*else*/ {
      __pyx_v_N_side_x = (__pyx_v_N_side_x + __pyx_v_XDIM);
    }
    __pyx_L4:;
 0445: 
+0446:     if abs(N_side_y - C_side_y) > 2:
  __pyx_t_10 = abs((__pyx_v_N_side_y - __pyx_v_C_side_y)); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 446, __pyx_L1_error)
  __pyx_t_11 = (__pyx_t_10 > 2);
  if (__pyx_t_11) {
/* … */
  }
+0447:         if N_side_y > C_side_y:
    __pyx_t_11 = (__pyx_v_N_side_y > __pyx_v_C_side_y);
    if (__pyx_t_11) {
/* … */
      goto __pyx_L6;
    }
+0448:             C_side_y = C_side_y + YDIM
      __pyx_v_C_side_y = (__pyx_v_C_side_y + __pyx_v_YDIM);
 0449:         else:
+0450:             N_side_y = N_side_y + YDIM
    /*else*/ {
      __pyx_v_N_side_y = (__pyx_v_N_side_y + __pyx_v_YDIM);
    }
    __pyx_L6:;
 0451: 
+0452:     if abs(N_side_z - C_side_z) > 2:
  __pyx_t_10 = abs((__pyx_v_N_side_z - __pyx_v_C_side_z)); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 452, __pyx_L1_error)
  __pyx_t_11 = (__pyx_t_10 > 2);
  if (__pyx_t_11) {
/* … */
  }
+0453:         if N_side_z > C_side_z:
    __pyx_t_11 = (__pyx_v_N_side_z > __pyx_v_C_side_z);
    if (__pyx_t_11) {
/* … */
      goto __pyx_L8;
    }
+0454:             C_side_z = C_side_z + ZDIM
      __pyx_v_C_side_z = (__pyx_v_C_side_z + __pyx_v_ZDIM);
 0455:         else:
+0456:             N_side_z = N_side_z + ZDIM
    /*else*/ {
      __pyx_v_N_side_z = (__pyx_v_N_side_z + __pyx_v_ZDIM);
    }
    __pyx_L8:;
 0457: 
 0458:     ## So we are now no longer in periodic space
 0459: 
 0460:     # get smallest/largest possible new x value
+0461:     x_min = int_max(N_side_x-1, C_side_x-1)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_int_max((__pyx_v_N_side_x - 1), (__pyx_v_C_side_x - 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 461, __pyx_L1_error)
  __pyx_v_x_min = __pyx_t_10;
+0462:     x_max = int_min(N_side_x+1, C_side_x+1)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_int_min((__pyx_v_N_side_x + 1), (__pyx_v_C_side_x + 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 462, __pyx_L1_error)
  __pyx_v_x_max = __pyx_t_10;
 0463: 
 0464:     # get smallest/largest possible new y value
+0465:     y_min = int_max(N_side_y-1, C_side_y-1)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_int_max((__pyx_v_N_side_y - 1), (__pyx_v_C_side_y - 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 465, __pyx_L1_error)
  __pyx_v_y_min = __pyx_t_10;
+0466:     y_max = int_min(N_side_y+1, C_side_y+1)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_int_min((__pyx_v_N_side_y + 1), (__pyx_v_C_side_y + 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 466, __pyx_L1_error)
  __pyx_v_y_max = __pyx_t_10;
 0467: 
 0468:     # get smallest/largest possible new z value
+0469:     z_min = int_max(N_side_z-1, C_side_z-1)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_int_max((__pyx_v_N_side_z - 1), (__pyx_v_C_side_z - 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 469, __pyx_L1_error)
  __pyx_v_z_min = __pyx_t_10;
+0470:     z_max = int_min(N_side_z+1, C_side_z+1)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_int_min((__pyx_v_N_side_z + 1), (__pyx_v_C_side_z + 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 470, __pyx_L1_error)
  __pyx_v_z_max = __pyx_t_10;
 0471: 
 0472: 
 0473:     # if a random bead is selected in the code, the ORDER in which these are defined introduce a bias
 0474:     # such that the system drives high number beads up in the Z dimension but low number beads dow
 0475: 
+0476:     cdef int local_x = pbc_correction((x_min + randint(1, (x_max - x_min + 1)) - 1 ) , XDIM)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_randint(1, ((__pyx_v_x_max - __pyx_v_x_min) + 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 476, __pyx_L1_error)
  __pyx_t_12 = __pyx_f_5pimms_10mega_crank_pbc_correction(((__pyx_v_x_min + __pyx_t_10) - 1), __pyx_v_XDIM); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 476, __pyx_L1_error)
  __pyx_v_local_x = __pyx_t_12;
+0477:     cdef int local_y = pbc_correction((y_min + randint(1, (y_max - y_min + 1)) - 1 ) , YDIM)
  __pyx_t_12 = __pyx_f_5pimms_10mega_crank_randint(1, ((__pyx_v_y_max - __pyx_v_y_min) + 1)); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 477, __pyx_L1_error)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_pbc_correction(((__pyx_v_y_min + __pyx_t_12) - 1), __pyx_v_YDIM); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 477, __pyx_L1_error)
  __pyx_v_local_y = __pyx_t_10;
+0478:     cdef int local_z = pbc_correction((z_min + randint(1, (z_max - z_min + 1)) - 1 ) , ZDIM)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_randint(1, ((__pyx_v_z_max - __pyx_v_z_min) + 1)); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 478, __pyx_L1_error)
  __pyx_t_12 = __pyx_f_5pimms_10mega_crank_pbc_correction(((__pyx_v_z_min + __pyx_t_10) - 1), __pyx_v_ZDIM); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 478, __pyx_L1_error)
  __pyx_v_local_z = __pyx_t_12;
 0479: 
 0480: 
 0481: 
 0482:     ## code below used for debugging - left here in case we want to return to this...
 0483:     # -----------------------------------------------------------------------------
 0484:     # debugging 03/2024
 0485:     #cdef int rand_x, rand_y, rand_z;
 0486:     #rand_z = z_min + randint(1, (z_max - z_min + 1)) - 1
 0487:     #rand_x = x_min + randint(1, (x_max - x_min + 1)) - 1
 0488:     #rand_y = y_min + randint(1, (y_max - y_min + 1)) - 1
 0489: 
 0490: 
 0491:     #cdef int local_x = pbc_correction(rand_x, XDIM)
 0492:     #cdef int local_y = pbc_correction(rand_y, YDIM)
 0493:     #cdef int local_z = pbc_correction(rand_z, ZDIM)
 0494: 
 0495:     #with open('crankshaft_moves','a') as fh:
 0496:         #fh.write(f'{x_min}, {x_max}, {rand_x - position_triptic[1,0]}, {y_min}, {y_max}, {rand_y - position_triptic[1,1]}, {z_min}, {z_max}, {rand_z - position_triptic[1,2]}\n')
 0497:         #fh.write(f'{x_max-x_min}, {y_max-y_min}, {z_max-z_min}\n')
 0498: 
 0499: 
 0500:     # debugging 2020
 0501:     # leave this in - can be used to check moves maintain detailed balance
 0502:     #with open('crankshaft_moves','a') as fh:
 0503:     #    fh.write('%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i \n' % (x_min, x_max, y_min, y_max, z_min, z_max, local_x, local_y, local_z, position_triptic[1,0] - local_x, position_triptic[1,1] - local_y, position_triptic[1,2] - local_z))
 0504:     # -----------------------------------------------------------------------------
 0505: 
 0506: 
 0507:     # hard sphere clash
+0508:     if grid[local_x, local_y, local_z] > 0:
  __pyx_t_8 = __pyx_v_local_x;
  __pyx_t_9 = __pyx_v_local_y;
  __pyx_t_13 = __pyx_v_local_z;
  __pyx_t_11 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_8 * __pyx_v_grid.strides[0]) ) + __pyx_t_9 * __pyx_v_grid.strides[1]) ) + __pyx_t_13 * __pyx_v_grid.strides[2]) ))) > 0);
  if (__pyx_t_11) {
/* … */
  }
 0509: 
 0510: 
 0511:         # -----------------------------------------------------------------------------
 0512:         # debugging 20202
 0513:         #with open('crankshaft_fail_move.txt','a') as fh:
 0514:             #fh.write('%i, %i, %i \n' % (position_triptic[1,0] - local_x, position_triptic[1,1] - local_y, position_triptic[1,2] - local_z))
 0515:             #fh.write('%i, %i, %i \n' % (local_x, local_y, local_z))
 0516: 
 0517:         # fail
+0518:         new_position[0] = -1
    __pyx_t_13 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides) = -1;
+0519:         return (new_position)
    __Pyx_XDECREF((PyObject *)__pyx_r);
    __Pyx_INCREF((PyObject *)__pyx_v_new_position);
    __pyx_r = ((PyArrayObject *)__pyx_v_new_position);
    goto __pyx_L0;
 0520: 
 0521: 
 0522:     else:
 0523: 
 0524:         # -----------------------------------------------------------------------------
 0525:         # debugging 20202
 0526:         #with open('crankshaft_success_move.txt','a') as fh:
 0527:             #fh.write('%i, %i, %i \n' % (position_triptic[1,0] - local_x, position_triptic[1,1] - local_y, position_triptic[1,2] - local_z))
 0528:             #fh.write('%i, %i, %i \n' % (local_x, local_y, local_z))
 0529: 
 0530:         # success
+0531:         new_position[0] = local_x;
  /*else*/ {
    __pyx_t_13 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_x;
+0532:         new_position[1] = local_y;
    __pyx_t_13 = 1;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_y;
+0533:         new_position[2] = local_z;
    __pyx_t_13 = 2;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_z;
+0534:         return (new_position)
    __Pyx_XDECREF((PyObject *)__pyx_r);
    __Pyx_INCREF((PyObject *)__pyx_v_new_position);
    __pyx_r = ((PyArrayObject *)__pyx_v_new_position);
    goto __pyx_L0;
  }
 0535: 
 0536: 
 0537: 
 0538: #-----------------------------------------------------------------
 0539: #
 0540: #cdef crank_it_good (cnp.ndarray[NUMPY_INT_TYPE, ndim=2] position_triptic, cnp.ndarray[NUMPY_INT_TYPE, ndim=3] grid, int XDIM, int YDIM, int ZDIM):
+0541: cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] crank_it_good(NUMPY_INT_TYPE[:,:] position_triptic,
static PyArrayObject *__pyx_f_5pimms_10mega_crank_crank_it_good(__Pyx_memviewslice __pyx_v_position_triptic, __Pyx_memviewslice __pyx_v_grid, int __pyx_v_XDIM, int __pyx_v_YDIM, int __pyx_v_ZDIM) {
  int __pyx_v_new_x;
  int __pyx_v_new_y;
  int __pyx_v_new_z;
  PyArrayObject *__pyx_v_new_position = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_new_position;
  __Pyx_Buffer __pyx_pybuffer_new_position;
  PyArrayObject *__pyx_r = NULL;
  __pyx_pybuffer_new_position.pybuffer.buf = NULL;
  __pyx_pybuffer_new_position.refcount = 0;
  __pyx_pybuffernd_new_position.data = NULL;
  __pyx_pybuffernd_new_position.rcbuffer = &__pyx_pybuffer_new_position;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pimms.mega_crank.crank_it_good", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_new_position);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0542:                                                        NUMPY_INT_TYPE[:,:,:] grid,
 0543:                                                        int XDIM,
 0544:                                                        int YDIM,
 0545:                                                        int ZDIM):
 0546:     """
 0547:     Perform crankshaft move!
 0548: 
 0549:     Returns a tuple of success and the PBC corrected posistion. This is just a less
 0550:     optimized and differently implemented version of crank_it. Was used in debugging,
 0551:     but is totally legit, so keeping around incase its needed again.
 0552: 
 0553: 
 0554:     """
 0555: 
 0556:     cdef int N_side_x, N_side_y, N_side_z, C_side_x, C_side_y, C_side_z;
 0557:     cdef int new_x, new_y, new_z
+0558:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position = np.zeros([3], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_2 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 558, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    assert(__pyx_t_2);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
    __pyx_t_6 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, __pyx_t_3};
    __pyx_t_7 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 558, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_5, __pyx_t_7, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 558, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 558, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 558, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_position.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_new_position = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 558, __pyx_L1_error)
    } else {__pyx_pybuffernd_new_position.diminfo[0].strides = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_position.diminfo[0].shape = __pyx_pybuffernd_new_position.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_new_position = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
 0559: 
 0560:     # randomly perturb in 3D
+0561:     new_x = pbc_correction(position_triptic[1,0] + (randint(0,2)-1), XDIM)
  __pyx_t_8 = 1;
  __pyx_t_9 = 0;
  __pyx_t_10 = -1;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_10 = 0;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_10 = 0;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_10 = 1;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_10 = 1;
  if (unlikely(__pyx_t_10 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_10);
    __PYX_ERR(0, 561, __pyx_L1_error)
  }
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_randint(0, 2); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 561, __pyx_L1_error)
  __pyx_t_11 = __pyx_f_5pimms_10mega_crank_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))) + (__pyx_t_10 - 1)), __pyx_v_XDIM); if (unlikely(__pyx_t_11 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 561, __pyx_L1_error)
  __pyx_v_new_x = __pyx_t_11;
+0562:     new_y = pbc_correction(position_triptic[1,1] + (randint(0,2)-1), YDIM)
  __pyx_t_9 = 1;
  __pyx_t_8 = 1;
  __pyx_t_11 = -1;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
  if (unlikely(__pyx_t_11 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_11);
    __PYX_ERR(0, 562, __pyx_L1_error)
  }
  __pyx_t_11 = __pyx_f_5pimms_10mega_crank_randint(0, 2); if (unlikely(__pyx_t_11 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 562, __pyx_L1_error)
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) ))) + (__pyx_t_11 - 1)), __pyx_v_YDIM); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 562, __pyx_L1_error)
  __pyx_v_new_y = __pyx_t_10;
+0563:     new_z = pbc_correction(position_triptic[1,2] + (randint(0,2)-1), ZDIM)
  __pyx_t_8 = 1;
  __pyx_t_9 = 2;
  __pyx_t_10 = -1;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_10 = 0;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_10 = 0;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_10 = 1;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_10 = 1;
  if (unlikely(__pyx_t_10 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_10);
    __PYX_ERR(0, 563, __pyx_L1_error)
  }
  __pyx_t_10 = __pyx_f_5pimms_10mega_crank_randint(0, 2); if (unlikely(__pyx_t_10 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 563, __pyx_L1_error)
  __pyx_t_11 = __pyx_f_5pimms_10mega_crank_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))) + (__pyx_t_10 - 1)), __pyx_v_ZDIM); if (unlikely(__pyx_t_11 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 563, __pyx_L1_error)
  __pyx_v_new_z = __pyx_t_11;
 0564: 
 0565:     # first check if the position is empty (note this rejects if we don't move, whic is good)
+0566:     if grid[new_x, new_y, new_z] > 0:
  __pyx_t_9 = __pyx_v_new_x;
  __pyx_t_8 = __pyx_v_new_y;
  __pyx_t_12 = __pyx_v_new_z;
  __pyx_t_11 = -1;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_grid.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_grid.shape[0])) __pyx_t_11 = 0;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_grid.shape[1];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_grid.shape[1])) __pyx_t_11 = 1;
  if (__pyx_t_12 < 0) {
    __pyx_t_12 += __pyx_v_grid.shape[2];
    if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 2;
  } else if (unlikely(__pyx_t_12 >= __pyx_v_grid.shape[2])) __pyx_t_11 = 2;
  if (unlikely(__pyx_t_11 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_11);
    __PYX_ERR(0, 566, __pyx_L1_error)
  }
  __pyx_t_13 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_9 * __pyx_v_grid.strides[0]) ) + __pyx_t_8 * __pyx_v_grid.strides[1]) ) + __pyx_t_12 * __pyx_v_grid.strides[2]) ))) > 0);
  if (__pyx_t_13) {
/* … */
  }
+0567:         new_position[0] = -1
    __pyx_t_12 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_pybuffernd_new_position.diminfo[0].shape;
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 567, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_new_position.diminfo[0].strides) = -1;
+0568:         return new_position
    __Pyx_XDECREF((PyObject *)__pyx_r);
    __Pyx_INCREF((PyObject *)__pyx_v_new_position);
    __pyx_r = ((PyArrayObject *)__pyx_v_new_position);
    goto __pyx_L0;
 0569: 
+0570:     new_position[0] = -1
  __pyx_t_12 = 0;
  __pyx_t_11 = -1;
  if (__pyx_t_12 < 0) {
    __pyx_t_12 += __pyx_pybuffernd_new_position.diminfo[0].shape;
    if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
  } else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_11 = 0;
  if (unlikely(__pyx_t_11 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_11);
    __PYX_ERR(0, 570, __pyx_L1_error)
  }
  *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_new_position.diminfo[0].strides) = -1;
 0571: 
 0572:     #print "CRANK IT GOOOOOOOOOOOD"
 0573: 
+0574:     if grid[new_x, new_y, new_z ] > 0:
  __pyx_t_12 = __pyx_v_new_x;
  __pyx_t_8 = __pyx_v_new_y;
  __pyx_t_9 = __pyx_v_new_z;
  __pyx_t_11 = -1;
  if (__pyx_t_12 < 0) {
    __pyx_t_12 += __pyx_v_grid.shape[0];
    if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
  } else if (unlikely(__pyx_t_12 >= __pyx_v_grid.shape[0])) __pyx_t_11 = 0;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_grid.shape[1];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_grid.shape[1])) __pyx_t_11 = 1;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_grid.shape[2];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 2;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_grid.shape[2])) __pyx_t_11 = 2;
  if (unlikely(__pyx_t_11 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_11);
    __PYX_ERR(0, 574, __pyx_L1_error)
  }
  __pyx_t_13 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_12 * __pyx_v_grid.strides[0]) ) + __pyx_t_8 * __pyx_v_grid.strides[1]) ) + __pyx_t_9 * __pyx_v_grid.strides[2]) ))) > 0);
  if (__pyx_t_13) {
/* … */
  }
+0575:         return new_position
    __Pyx_XDECREF((PyObject *)__pyx_r);
    __Pyx_INCREF((PyObject *)__pyx_v_new_position);
    __pyx_r = ((PyArrayObject *)__pyx_v_new_position);
    goto __pyx_L0;
 0576: 
 0577: 
 0578:     # next check we're within 1 in each direction including PBC considerations (x)
+0579:     if (abs(new_x - position_triptic[0,0]) < 2) or (abs(new_x - position_triptic[0,0]) == XDIM-1):
  __pyx_t_9 = 0;
  __pyx_t_8 = 0;
  __pyx_t_11 = -1;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
  if (unlikely(__pyx_t_11 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_11);
    __PYX_ERR(0, 579, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_x - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_mstate_global->__pyx_int_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_14) {
  } else {
    __pyx_t_13 = __pyx_t_14;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_8 = 0;
  __pyx_t_9 = 0;
  __pyx_t_11 = -1;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 0;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 1;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
  if (unlikely(__pyx_t_11 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_11);
    __PYX_ERR(0, 579, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_x - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyLong_From_long((__pyx_v_XDIM - 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_13 = __pyx_t_14;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_13) {
/* … */
  }
+0580:            if (abs(new_x - position_triptic[2,0]) < 2) or (abs(new_x - position_triptic[2,0]) == XDIM-1):
    __pyx_t_9 = 2;
    __pyx_t_8 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_9 < 0) {
      __pyx_t_9 += __pyx_v_position_triptic.shape[0];
      if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
    if (__pyx_t_8 < 0) {
      __pyx_t_8 += __pyx_v_position_triptic.shape[1];
      if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
    } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 580, __pyx_L1_error)
    }
    __pyx_t_7 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_x - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = __Pyx_PyNumber_Absolute(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_1, __pyx_mstate_global->__pyx_int_2, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!__pyx_t_14) {
    } else {
      __pyx_t_13 = __pyx_t_14;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_8 = 2;
    __pyx_t_9 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_8 < 0) {
      __pyx_t_8 += __pyx_v_position_triptic.shape[0];
      if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
    if (__pyx_t_9 < 0) {
      __pyx_t_9 += __pyx_v_position_triptic.shape[1];
      if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 1;
    } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 580, __pyx_L1_error)
    }
    __pyx_t_7 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_x - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = __Pyx_PyNumber_Absolute(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyLong_From_long((__pyx_v_XDIM - 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_13 = __pyx_t_14;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_13) {
/* … */
    }
 0581: 
 0582:                   # in y
+0583:                   if (abs(new_y - position_triptic[0,1]) < 2) or (abs(new_y - position_triptic[0,1]) == YDIM-1):
      __pyx_t_9 = 0;
      __pyx_t_8 = 1;
      __pyx_t_11 = -1;
      if (__pyx_t_9 < 0) {
        __pyx_t_9 += __pyx_v_position_triptic.shape[0];
        if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
      if (__pyx_t_8 < 0) {
        __pyx_t_8 += __pyx_v_position_triptic.shape[1];
        if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
      } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 583, __pyx_L1_error)
      }
      __pyx_t_4 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_y - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_7, __pyx_mstate_global->__pyx_int_2, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!__pyx_t_14) {
      } else {
        __pyx_t_13 = __pyx_t_14;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_8 = 0;
      __pyx_t_9 = 1;
      __pyx_t_11 = -1;
      if (__pyx_t_8 < 0) {
        __pyx_t_8 += __pyx_v_position_triptic.shape[0];
        if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
      if (__pyx_t_9 < 0) {
        __pyx_t_9 += __pyx_v_position_triptic.shape[1];
        if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 1;
      } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 583, __pyx_L1_error)
      }
      __pyx_t_4 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_y - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyLong_From_long((__pyx_v_YDIM - 1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_7, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 583, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_13 = __pyx_t_14;
      __pyx_L12_bool_binop_done:;
      if (__pyx_t_13) {
/* … */
      }
+0584:                          if (abs(new_y - position_triptic[2,1]) < 2) or (abs(new_y - position_triptic[2,1]) == YDIM-1):
        __pyx_t_9 = 2;
        __pyx_t_8 = 1;
        __pyx_t_11 = -1;
        if (__pyx_t_9 < 0) {
          __pyx_t_9 += __pyx_v_position_triptic.shape[0];
          if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
        } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
        if (__pyx_t_8 < 0) {
          __pyx_t_8 += __pyx_v_position_triptic.shape[1];
          if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
        } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
        if (unlikely(__pyx_t_11 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_11);
          __PYX_ERR(0, 584, __pyx_L1_error)
        }
        __pyx_t_1 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_y - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_mstate_global->__pyx_int_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (!__pyx_t_14) {
        } else {
          __pyx_t_13 = __pyx_t_14;
          goto __pyx_L15_bool_binop_done;
        }
        __pyx_t_8 = 2;
        __pyx_t_9 = 1;
        __pyx_t_11 = -1;
        if (__pyx_t_8 < 0) {
          __pyx_t_8 += __pyx_v_position_triptic.shape[0];
          if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 0;
        } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
        if (__pyx_t_9 < 0) {
          __pyx_t_9 += __pyx_v_position_triptic.shape[1];
          if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 1;
        } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
        if (unlikely(__pyx_t_11 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_11);
          __PYX_ERR(0, 584, __pyx_L1_error)
        }
        __pyx_t_1 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_y - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyLong_From_long((__pyx_v_YDIM - 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 584, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_13 = __pyx_t_14;
        __pyx_L15_bool_binop_done:;
        if (__pyx_t_13) {
/* … */
        }
 0585: 
 0586:                                 # in z
+0587:                                 if (abs(new_z - position_triptic[0,2]) < 2) or (abs(new_z - position_triptic[0,2]) == ZDIM-1):
          __pyx_t_9 = 0;
          __pyx_t_8 = 2;
          __pyx_t_11 = -1;
          if (__pyx_t_9 < 0) {
            __pyx_t_9 += __pyx_v_position_triptic.shape[0];
            if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
          if (__pyx_t_8 < 0) {
            __pyx_t_8 += __pyx_v_position_triptic.shape[1];
            if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
          } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 587, __pyx_L1_error)
          }
          __pyx_t_7 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_z - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_1 = __Pyx_PyNumber_Absolute(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyObject_RichCompare(__pyx_t_1, __pyx_mstate_global->__pyx_int_2, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (!__pyx_t_14) {
          } else {
            __pyx_t_13 = __pyx_t_14;
            goto __pyx_L18_bool_binop_done;
          }
          __pyx_t_8 = 0;
          __pyx_t_9 = 2;
          __pyx_t_11 = -1;
          if (__pyx_t_8 < 0) {
            __pyx_t_8 += __pyx_v_position_triptic.shape[0];
            if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
          if (__pyx_t_9 < 0) {
            __pyx_t_9 += __pyx_v_position_triptic.shape[1];
            if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 1;
          } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 587, __pyx_L1_error)
          }
          __pyx_t_7 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_z - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_1 = __Pyx_PyNumber_Absolute(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyLong_From_long((__pyx_v_ZDIM - 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 587, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_13 = __pyx_t_14;
          __pyx_L18_bool_binop_done:;
          if (__pyx_t_13) {
/* … */
          }
+0588:                                        if (abs(new_z - position_triptic[2,2]) < 2) or (abs(new_z - position_triptic[2,2]) == ZDIM-1):
            __pyx_t_9 = 2;
            __pyx_t_8 = 2;
            __pyx_t_11 = -1;
            if (__pyx_t_9 < 0) {
              __pyx_t_9 += __pyx_v_position_triptic.shape[0];
              if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
            } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
            if (__pyx_t_8 < 0) {
              __pyx_t_8 += __pyx_v_position_triptic.shape[1];
              if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 1;
            } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
            if (unlikely(__pyx_t_11 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_11);
              __PYX_ERR(0, 588, __pyx_L1_error)
            }
            __pyx_t_4 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_z - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_9 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_8 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_4 = PyObject_RichCompare(__pyx_t_7, __pyx_mstate_global->__pyx_int_2, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            if (!__pyx_t_14) {
            } else {
              __pyx_t_13 = __pyx_t_14;
              goto __pyx_L21_bool_binop_done;
            }
            __pyx_t_8 = 2;
            __pyx_t_9 = 2;
            __pyx_t_11 = -1;
            if (__pyx_t_8 < 0) {
              __pyx_t_8 += __pyx_v_position_triptic.shape[0];
              if (unlikely(__pyx_t_8 < 0)) __pyx_t_11 = 0;
            } else if (unlikely(__pyx_t_8 >= __pyx_v_position_triptic.shape[0])) __pyx_t_11 = 0;
            if (__pyx_t_9 < 0) {
              __pyx_t_9 += __pyx_v_position_triptic.shape[1];
              if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 1;
            } else if (unlikely(__pyx_t_9 >= __pyx_v_position_triptic.shape[1])) __pyx_t_11 = 1;
            if (unlikely(__pyx_t_11 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_11);
              __PYX_ERR(0, 588, __pyx_L1_error)
            }
            __pyx_t_4 = __Pyx_PyLong_From_npy_int32((__pyx_v_new_z - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_8 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_9 * __pyx_v_position_triptic.strides[1]) ))))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_4 = __Pyx_PyLong_From_long((__pyx_v_ZDIM - 1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_1 = PyObject_RichCompare(__pyx_t_7, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 588, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_13 = __pyx_t_14;
            __pyx_L21_bool_binop_done:;
            if (__pyx_t_13) {
/* … */
            }
 0589: 
+0590:                                               new_position[0] = new_x
              __pyx_t_9 = 0;
              __pyx_t_11 = -1;
              if (__pyx_t_9 < 0) {
                __pyx_t_9 += __pyx_pybuffernd_new_position.diminfo[0].shape;
                if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
              } else if (unlikely(__pyx_t_9 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_11 = 0;
              if (unlikely(__pyx_t_11 != -1)) {
                __Pyx_RaiseBufferIndexError(__pyx_t_11);
                __PYX_ERR(0, 590, __pyx_L1_error)
              }
              *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_new_x;
+0591:                                               new_position[1] = new_y
              __pyx_t_9 = 1;
              __pyx_t_11 = -1;
              if (__pyx_t_9 < 0) {
                __pyx_t_9 += __pyx_pybuffernd_new_position.diminfo[0].shape;
                if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
              } else if (unlikely(__pyx_t_9 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_11 = 0;
              if (unlikely(__pyx_t_11 != -1)) {
                __Pyx_RaiseBufferIndexError(__pyx_t_11);
                __PYX_ERR(0, 591, __pyx_L1_error)
              }
              *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_new_y;
+0592:                                               new_position[2] = new_z
              __pyx_t_9 = 2;
              __pyx_t_11 = -1;
              if (__pyx_t_9 < 0) {
                __pyx_t_9 += __pyx_pybuffernd_new_position.diminfo[0].shape;
                if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0;
              } else if (unlikely(__pyx_t_9 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_11 = 0;
              if (unlikely(__pyx_t_11 != -1)) {
                __Pyx_RaiseBufferIndexError(__pyx_t_11);
                __PYX_ERR(0, 592, __pyx_L1_error)
              }
              *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_new_z;
+0593:     return new_position
  __Pyx_XDECREF((PyObject *)__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_new_position);
  __pyx_r = ((PyArrayObject *)__pyx_v_new_position);
  goto __pyx_L0;
 0594: 
 0595: 
 0596: #-----------------------------------------------------------------
 0597: #
 0598: #def single_bead_crank (cnp.ndarray[NUMPY_INT_TYPE, ndim=1] old_position, cnp.ndarray[NUMPY_INT_TYPE, ndim=3] grid, int XDIM, int YDIM, int ZDIM):
+0599: def single_bead_crank (NUMPY_INT_TYPE[:] old_position, NUMPY_INT_TYPE[:,:,:] grid, NUMPY_INT_TYPE XDIM, NUMPY_INT_TYPE YDIM, NUMPY_INT_TYPE ZDIM):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_11single_bead_crank(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pimms_10mega_crank_10single_bead_crank, "\n    Perform crankshaft move for a single bead.\n\n    Single beads are easy as the new position is just a random pertubation \n    in all three coordinates. We then update the position, returning a new\n    position if there were no hardsphere clashes or a [-1, 0, 0] position \n    if there were hardsphere clases.\n\n    Parameters\n    ----------\n    old_position : np.ndarray\n        The old position of the bead.\n\n    grid : np.ndarray\n        The grid of the system.\n\n    XDIM : int\n        The x dimension of the grid.\n\n    YDIM : int\n        The y dimension of the grid.\n\n    ZDIM : int\n        The z dimension of the grid.\n\n    Returns\n    -------\n    new_position : np.ndarray\n        The new position of the bead.\n    \n    ");
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_11single_bead_crank = {"single_bead_crank", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_11single_bead_crank, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pimms_10mega_crank_10single_bead_crank};
static PyObject *__pyx_pw_5pimms_10mega_crank_11single_bead_crank(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  __Pyx_memviewslice __pyx_v_old_position = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_grid = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_XDIM;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_YDIM;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_ZDIM;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("single_bead_crank (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_old_position,&__pyx_mstate_global->__pyx_n_u_grid,&__pyx_mstate_global->__pyx_n_u_XDIM,&__pyx_mstate_global->__pyx_n_u_YDIM,&__pyx_mstate_global->__pyx_n_u_ZDIM,0};
  PyObject* values[5] = {0,0,0,0,0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 599, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  5:
        values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 599, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  4:
        values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 599, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  3:
        values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 599, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  2:
        values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 599, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 599, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "single_bead_crank", 0) < (0)) __PYX_ERR(0, 599, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 5; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("single_bead_crank", 1, 5, 5, i); __PYX_ERR(0, 599, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 5)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 599, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 599, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 599, __pyx_L3_error)
      values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 599, __pyx_L3_error)
      values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 599, __pyx_L3_error)
    }
    __pyx_v_old_position = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_old_position.memview)) __PYX_ERR(0, 599, __pyx_L3_error)
    __pyx_v_grid = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_grid.memview)) __PYX_ERR(0, 599, __pyx_L3_error)
    __pyx_v_XDIM = __Pyx_PyLong_As_npy_int32(values[2]); if (unlikely((__pyx_v_XDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 599, __pyx_L3_error)
    __pyx_v_YDIM = __Pyx_PyLong_As_npy_int32(values[3]); if (unlikely((__pyx_v_YDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 599, __pyx_L3_error)
    __pyx_v_ZDIM = __Pyx_PyLong_As_npy_int32(values[4]); if (unlikely((__pyx_v_ZDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 599, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("single_bead_crank", 1, 5, 5, __pyx_nargs); __PYX_ERR(0, 599, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_old_position, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_grid, 1);
  __Pyx_AddTraceback("pimms.mega_crank.single_bead_crank", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_10single_bead_crank(__pyx_self, __pyx_v_old_position, __pyx_v_grid, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_v_ZDIM);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_old_position, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_grid, 1);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_10single_bead_crank(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_old_position, __Pyx_memviewslice __pyx_v_grid, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_XDIM, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_YDIM, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_ZDIM) {
  int __pyx_v_x_off;
  int __pyx_v_y_off;
  int __pyx_v_z_off;
  PyObject *__pyx_v_RETURN = NULL;
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pimms.mega_crank.single_bead_crank", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_RETURN);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_11single_bead_crank, 0, __pyx_mstate_global->__pyx_n_u_single_bead_crank, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[5])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_single_bead_crank, __pyx_t_4) < (0)) __PYX_ERR(0, 599, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 0600:     """
 0601:     Perform crankshaft move for a single bead.
 0602: 
 0603:     Single beads are easy as the new position is just a random pertubation
 0604:     in all three coordinates. We then update the position, returning a new
 0605:     position if there were no hardsphere clashes or a [-1, 0, 0] position
 0606:     if there were hardsphere clases.
 0607: 
 0608:     Parameters
 0609:     ----------
 0610:     old_position : np.ndarray
 0611:         The old position of the bead.
 0612: 
 0613:     grid : np.ndarray
 0614:         The grid of the system.
 0615: 
 0616:     XDIM : int
 0617:         The x dimension of the grid.
 0618: 
 0619:     YDIM : int
 0620:         The y dimension of the grid.
 0621: 
 0622:     ZDIM : int
 0623:         The z dimension of the grid.
 0624: 
 0625:     Returns
 0626:     -------
 0627:     new_position : np.ndarray
 0628:         The new position of the bead.
 0629: 
 0630:     """
 0631: 
 0632:     cdef int x_off, y_off, z_off
+0633:     x_off = (randint(0,2)-1)
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_randint(0, 2); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 633, __pyx_L1_error)
  __pyx_v_x_off = (__pyx_t_1 - 1);
+0634:     y_off = (randint(0,2)-1)
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_randint(0, 2); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 634, __pyx_L1_error)
  __pyx_v_y_off = (__pyx_t_1 - 1);
+0635:     z_off = (randint(0,2)-1)
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_randint(0, 2); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 635, __pyx_L1_error)
  __pyx_v_z_off = (__pyx_t_1 - 1);
 0636: 
+0637:     RETURN = update_position(old_position, grid, x_off, y_off, z_off, XDIM, YDIM, ZDIM)
  __pyx_t_3 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_update_position); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_old_position, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_grid, 3, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyLong_From_int(__pyx_v_x_off); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyLong_From_int(__pyx_v_y_off); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyLong_From_int(__pyx_v_z_off); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = __Pyx_PyLong_From_npy_int32(__pyx_v_XDIM); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = __Pyx_PyLong_From_npy_int32(__pyx_v_YDIM); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_12 = __Pyx_PyLong_From_npy_int32(__pyx_v_ZDIM); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_13 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    assert(__pyx_t_3);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
    __pyx_t_13 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[9] = {__pyx_t_3, __pyx_t_5, __pyx_t_6, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10, __pyx_t_11, __pyx_t_12};
    __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_13, (9-__pyx_t_13) | (__pyx_t_13*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 637, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  }
  __pyx_v_RETURN = __pyx_t_2;
  __pyx_t_2 = 0;
 0638: 
 0639: 
 0640:     # debugging (2020)
 0641:     #if RETURN[0] == -1:
 0642:     #    with open('single_bead_crank_fail.txt','a') as fh:
 0643:     #        fh.write('%i, %i, %i \n' % (x_off, y_off, z_off))
 0644:     #else:
 0645:     #    with open('single_bead_crank_success.txt','a') as fh:
 0646:     #        fh.write('%i, %i, %i \n' % (x_off, y_off, z_off))
 0647: 
 0648: 
+0649:     return RETURN
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_RETURN);
  __pyx_r = __pyx_v_RETURN;
  goto __pyx_L0;
 0650: 
 0651: 
 0652: 
+0653: cdef int accept_or_reject(float invtemp, long old_energy, long new_energy):
static int __pyx_f_5pimms_10mega_crank_accept_or_reject(float __pyx_v_invtemp, long __pyx_v_old_energy, long __pyx_v_new_energy) {
  float __pyx_v_expterm;
  float __pyx_v_randval;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pimms.mega_crank.accept_or_reject", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}
 0654:     """
 0655:     Accept or reject a move based on the energy change and the temperature using
 0656:     the Metropolis criterion.
 0657: 
 0658:     Parameters
 0659:     ----------
 0660:     invtemp : float
 0661:         The inverse temperature.
 0662: 
 0663:     old_energy : long
 0664:         The old energy of the system.
 0665: 
 0666:     new_energy : long
 0667:         The new energy of the system.
 0668: 
 0669:     Returns
 0670:     -------
 0671:     int
 0672:         1 if the move is accepted, 0 if it is rejected.
 0673: 
 0674:     """
 0675: 
 0676:     cdef float expterm
 0677:     cdef float randval
 0678: 
 0679:     # return
+0680:     if new_energy <= old_energy:
  __pyx_t_1 = (__pyx_v_new_energy <= __pyx_v_old_energy);
  if (__pyx_t_1) {
/* … */
  }
+0681:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
 0682: 
 0683:     # note exp here is from libc and is imported at the start
+0684:     expterm = exp(-(new_energy-old_energy)*invtemp)
  __pyx_v_expterm = exp(((-(__pyx_v_new_energy - __pyx_v_old_energy)) * __pyx_v_invtemp));
+0685:     randval = float(mc_rand())/float(PRNG_MAX)
  if (unlikely(((double)__pyx_v_5pimms_10mega_crank_PRNG_MAX) == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 685, __pyx_L1_error)
  }
  __pyx_v_randval = (((double)__pyx_f_5pimms_10mega_crank_mc_rand()) / ((double)__pyx_v_5pimms_10mega_crank_PRNG_MAX));
 0686: 
+0687:     if randval < expterm:
  __pyx_t_1 = (__pyx_v_randval < __pyx_v_expterm);
  if (__pyx_t_1) {
/* … */
  }
+0688:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
 0689:     else:
+0690:         return 0
  /*else*/ {
    __pyx_r = 0;
    goto __pyx_L0;
  }
 0691: 
 0692: 
 0693: #cdef long get_angle_energy_change(NUMPY_INT_TYPE bead_index,
+0694: @cython.wraparound(False)
static long __pyx_f_5pimms_10mega_crank_get_angle_energy_change(int __pyx_v_bead_index, __Pyx_memviewslice __pyx_v_idx_to_bead, __Pyx_memviewslice __pyx_v_new_position, __Pyx_memviewslice __pyx_v_angle_lookup) {
  PyArrayObject *__pyx_v_a = 0;
  PyArrayObject *__pyx_v_b = 0;
  long __pyx_v_angle_penalty_new;
  long __pyx_v_angle_penalty_old;
  PyArrayObject *__pyx_v_angle_positions = 0;
  PyArrayObject *__pyx_v_intcode_lookup = 0;
  int __pyx_v_offset;
  int __pyx_v_offset_start;
  int __pyx_v_offset_end;
  int __pyx_v_i;
  int __pyx_v_angle_idx;
  int __pyx_v_local_move_idx;
  int __pyx_v_pos;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_a;
  __Pyx_Buffer __pyx_pybuffer_a;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_angle_positions;
  __Pyx_Buffer __pyx_pybuffer_angle_positions;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_b;
  __Pyx_Buffer __pyx_pybuffer_b;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_intcode_lookup;
  __Pyx_Buffer __pyx_pybuffer_intcode_lookup;
  long __pyx_r;
  __pyx_pybuffer_a.pybuffer.buf = NULL;
  __pyx_pybuffer_a.refcount = 0;
  __pyx_pybuffernd_a.data = NULL;
  __pyx_pybuffernd_a.rcbuffer = &__pyx_pybuffer_a;
  __pyx_pybuffer_b.pybuffer.buf = NULL;
  __pyx_pybuffer_b.refcount = 0;
  __pyx_pybuffernd_b.data = NULL;
  __pyx_pybuffernd_b.rcbuffer = &__pyx_pybuffer_b;
  __pyx_pybuffer_angle_positions.pybuffer.buf = NULL;
  __pyx_pybuffer_angle_positions.refcount = 0;
  __pyx_pybuffernd_angle_positions.data = NULL;
  __pyx_pybuffernd_angle_positions.rcbuffer = &__pyx_pybuffer_angle_positions;
  __pyx_pybuffer_intcode_lookup.pybuffer.buf = NULL;
  __pyx_pybuffer_intcode_lookup.refcount = 0;
  __pyx_pybuffernd_intcode_lookup.data = NULL;
  __pyx_pybuffernd_intcode_lookup.rcbuffer = &__pyx_pybuffer_intcode_lookup;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_a.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_angle_positions.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pimms.mega_crank.get_angle_energy_change", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_a.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_angle_positions.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XDECREF((PyObject *)__pyx_v_b);
  __Pyx_XDECREF((PyObject *)__pyx_v_angle_positions);
  __Pyx_XDECREF((PyObject *)__pyx_v_intcode_lookup);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0695: @cython.boundscheck(False)
 0696: cdef long get_angle_energy_change(int bead_index,
 0697:                                   NUMPY_INT_TYPE_long[:,:] idx_to_bead,
 0698:                                   NUMPY_INT_TYPE[:] new_position,
 0699:                                   NUMPY_INT_TYPE[:,:,:,:,:,:,:] angle_lookup):
 0700: 
 0701:     """
 0702:     cdef long get_angle_energy_change(NUMPY_INT_TYPE bead_index,
 0703:     cnp.ndarray[NUMPY_INT_TYPE, ndim=2] idx_to_bead,
 0704:     cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position,
 0705:     cnp.ndarray[long, ndim=7] angle_lookup):
 0706:     """
 0707: 
 0708:     """
 0709:     Function that takes a pre-computed angle energy lookup table and returns the change
 0710:     in angle energy before and after the move, where the move must be moving a single bead.
 0711:     Note this function is almost purely C (as measured by the output from cython -a)
 0712: 
 0713:     ## Parameters are as follows:
 0714: 
 0715:     bead_index
 0716:     Index position of the specific bead of interest
 0717: 
 0718:     idx_to_bead
 0719:     Full matrix containing the complete system information (see the description in
 0720:     the mega_crank function description for a full summary of this variable)
 0721: 
 0722:     new_position
 0723:     3D np.array ([x,y,z]) that defines the position that the moved bead
 0724:     is moving to
 0725: 
 0726:     angle_lookup
 0727:     6D lookup table that translates vector distances into an angle energy
 0728:     penalty based on precomputed values.
 0729: 
 0730:     """
 0731: 
 0732:     #print "Angle energy:"
 0733:     #print bead_index
 0734:     #print idx_to_bead
 0735:     #print idx_to_bead[bead_index]
 0736: 
 0737: 
 0738: 
 0739:     # if the skip angle is set to true
+0740:     if idx_to_bead[bead_index,3] == 1:
  __pyx_t_1 = __pyx_v_bead_index;
  __pyx_t_2 = 3;
  __pyx_t_3 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_1 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_2 * __pyx_v_idx_to_bead.strides[1]) ))) == 1);
  if (__pyx_t_3) {
/* … */
  }
+0741:         return 0
    __pyx_r = 0;
    goto __pyx_L0;
 0742: 
 0743:     # initialize a bunch of values
+0744:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] a = np.zeros([3], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_5 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyList_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_6, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 744, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
    assert(__pyx_t_5);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_7, __pyx__function);
    __pyx_t_9 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_5, __pyx_t_6};
    __pyx_t_10 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 744, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_8, __pyx_t_10, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 744, __pyx_L1_error)
    __pyx_t_4 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_7, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_10);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 744, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  }
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 744, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_a.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_4), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_a = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_a.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 744, __pyx_L1_error)
    } else {__pyx_pybuffernd_a.diminfo[0].strides = __pyx_pybuffernd_a.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_a.diminfo[0].shape = __pyx_pybuffernd_a.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_a = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
+0745:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] b = np.zeros([3], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_7 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyList_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_10, 0, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 745, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_9 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
    assert(__pyx_t_7);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
    __pyx_t_9 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_7, __pyx_t_10};
    __pyx_t_5 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_6, __pyx_t_5, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 745, __pyx_L1_error)
    __pyx_t_4 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_8, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  }
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 745, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_b.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_4), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_b = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_b.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 745, __pyx_L1_error)
    } else {__pyx_pybuffernd_b.diminfo[0].strides = __pyx_pybuffernd_b.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_b.diminfo[0].shape = __pyx_pybuffernd_b.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_b = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
 0746: 
+0747:     cdef long angle_penalty_new = 0;
  __pyx_v_angle_penalty_new = 0;
+0748:     cdef long angle_penalty_old = 0;
  __pyx_v_angle_penalty_old = 0;
 0749: 
+0750:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] angle_positions  = np.zeros([5, 3], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_8 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_5);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_5);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_5, 0, __pyx_mstate_global->__pyx_int_5) != (0)) __PYX_ERR(0, 750, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_3);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_5, 1, __pyx_mstate_global->__pyx_int_3) != (0)) __PYX_ERR(0, 750, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_9 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
    assert(__pyx_t_8);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_8);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_6, __pyx__function);
    __pyx_t_9 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_8, __pyx_t_5};
    __pyx_t_7 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 750, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_10, __pyx_t_7, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 750, __pyx_L1_error)
    __pyx_t_4 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_6, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 750, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  }
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 750, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_angle_positions.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_4), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_angle_positions = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 750, __pyx_L1_error)
    } else {__pyx_pybuffernd_angle_positions.diminfo[0].strides = __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_angle_positions.diminfo[0].shape = __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_angle_positions.diminfo[1].strides = __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_angle_positions.diminfo[1].shape = __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_v_angle_positions = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
+0751:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] intcode_lookup = np.zeros([5], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_6 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_5);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_5);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_7, 0, __pyx_mstate_global->__pyx_int_5) != (0)) __PYX_ERR(0, 751, __pyx_L1_error);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_9 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_10))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_10);
    assert(__pyx_t_6);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_10);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_10, __pyx__function);
    __pyx_t_9 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_6, __pyx_t_7};
    __pyx_t_8 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 751, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_5, __pyx_t_8, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 751, __pyx_L1_error)
    __pyx_t_4 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_10, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  }
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 751, __pyx_L1_error)
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_4), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_intcode_lookup = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 751, __pyx_L1_error)
    } else {__pyx_pybuffernd_intcode_lookup.diminfo[0].strides = __pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_intcode_lookup.diminfo[0].shape = __pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_intcode_lookup = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
 0752:     cdef int offset;
 0753:     cdef int offset_start, offset_end;
 0754:     cdef int i;
 0755:     cdef int angle_idx;
 0756: 
+0757:     cdef int local_move_idx = -1
  __pyx_v_local_move_idx = -1;
 0758: 
 0759: 
 0760:     ## Firstly we assess what the type of bead is, as this determines over
 0761:     #  what range we are assessing
 0762: 
 0763:     # N-terminal bead
+0764:     if idx_to_bead[bead_index,0] == 1:
  __pyx_t_2 = __pyx_v_bead_index;
  __pyx_t_1 = 0;
  __pyx_t_3 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_2 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_1 * __pyx_v_idx_to_bead.strides[1]) ))) == 1);
  if (__pyx_t_3) {
/* … */
    goto __pyx_L4;
  }
+0765:         offset_start = 0
    __pyx_v_offset_start = 0;
+0766:         offset_end   = 3
    __pyx_v_offset_end = 3;
 0767: 
 0768:     # central bead
+0769:     elif idx_to_bead[bead_index,0] == 2:
  __pyx_t_1 = __pyx_v_bead_index;
  __pyx_t_2 = 0;
  __pyx_t_3 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_1 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_2 * __pyx_v_idx_to_bead.strides[1]) ))) == 2);
  if (__pyx_t_3) {
/* … */
    goto __pyx_L4;
  }
+0770:         offset_start = -2
    __pyx_v_offset_start = -2;
+0771:         offset_end   = 3
    __pyx_v_offset_end = 3;
 0772: 
 0773:     # central bead in an OXO configuration
+0774:     elif idx_to_bead[bead_index,0] == 4:
  __pyx_t_2 = __pyx_v_bead_index;
  __pyx_t_1 = 0;
  __pyx_t_3 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_2 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_1 * __pyx_v_idx_to_bead.strides[1]) ))) == 4);
  if (__pyx_t_3) {
/* … */
    goto __pyx_L4;
  }
+0775:         offset_start = -1
    __pyx_v_offset_start = -1;
+0776:         offset_end   = 2
    __pyx_v_offset_end = 2;
 0777: 
 0778:     # C terminal bead
+0779:     elif idx_to_bead[bead_index,0] == 3:
  __pyx_t_1 = __pyx_v_bead_index;
  __pyx_t_2 = 0;
  __pyx_t_3 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_1 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_2 * __pyx_v_idx_to_bead.strides[1]) ))) == 3);
  if (__pyx_t_3) {
/* … */
    goto __pyx_L4;
  }
+0780:         offset_start = -2
    __pyx_v_offset_start = -2;
+0781:         offset_end   = 1
    __pyx_v_offset_end = 1;
 0782: 
 0783:     # N terminal bead +1 from start
+0784:     elif idx_to_bead[bead_index,0] == 5:
  __pyx_t_2 = __pyx_v_bead_index;
  __pyx_t_1 = 0;
  __pyx_t_3 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_2 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_1 * __pyx_v_idx_to_bead.strides[1]) ))) == 5);
  if (__pyx_t_3) {
/* … */
    goto __pyx_L4;
  }
+0785:         offset_start = -1
    __pyx_v_offset_start = -1;
+0786:         offset_end   = 3
    __pyx_v_offset_end = 3;
 0787: 
 0788:     # C terminal bead -1 from end
+0789:     elif idx_to_bead[bead_index,0] == 6:
  __pyx_t_1 = __pyx_v_bead_index;
  __pyx_t_2 = 0;
  __pyx_t_3 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_1 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_2 * __pyx_v_idx_to_bead.strides[1]) ))) == 6);
  if (__pyx_t_3) {
/* … */
  }
  __pyx_L4:;
+0790:         offset_start = -2
    __pyx_v_offset_start = -2;
+0791:         offset_end   = 2
    __pyx_v_offset_end = 2;
 0792: 
 0793:     # this is the index we use to keep track of the dynamic angle_positions array
+0794:     angle_idx = 0
  __pyx_v_angle_idx = 0;
 0795: 
 0796:     # next construct a dynamic list of positions over which the angles will be evaliated
+0797:     for offset in range(offset_start,offset_end):
  __pyx_t_11 = __pyx_v_offset_end;
  __pyx_t_12 = __pyx_t_11;
  for (__pyx_t_13 = __pyx_v_offset_start; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_offset = __pyx_t_13;
+0798:         pos = bead_index + offset
    __pyx_v_pos = (__pyx_v_bead_index + __pyx_v_offset);
 0799: 
+0800:         angle_positions[angle_idx, 0] = idx_to_bead[pos,5] # x pos
    __pyx_t_2 = __pyx_v_pos;
    __pyx_t_1 = 5;
    __pyx_t_14 = __pyx_v_angle_idx;
    __pyx_t_15 = 0;
    *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_2 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_1 * __pyx_v_idx_to_bead.strides[1]) )));
+0801:         angle_positions[angle_idx, 1] = idx_to_bead[pos,6] # y pos
    __pyx_t_1 = __pyx_v_pos;
    __pyx_t_2 = 6;
    __pyx_t_15 = __pyx_v_angle_idx;
    __pyx_t_14 = 1;
    *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_1 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_2 * __pyx_v_idx_to_bead.strides[1]) )));
+0802:         angle_positions[angle_idx, 2] = idx_to_bead[pos,7] # z pos
    __pyx_t_2 = __pyx_v_pos;
    __pyx_t_1 = 7;
    __pyx_t_14 = __pyx_v_angle_idx;
    __pyx_t_15 = 2;
    *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_2 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_1 * __pyx_v_idx_to_bead.strides[1]) )));
+0803:         intcode_lookup[angle_idx]     = idx_to_bead[pos,2] # intcode
    __pyx_t_1 = __pyx_v_pos;
    __pyx_t_2 = 2;
    __pyx_t_15 = __pyx_v_angle_idx;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_intcode_lookup.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_1 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_2 * __pyx_v_idx_to_bead.strides[1]) )));
 0804: 
+0805:         if pos == bead_index:
    __pyx_t_3 = (__pyx_v_pos == __pyx_v_bead_index);
    if (__pyx_t_3) {
/* … */
    }
+0806:             local_move_idx = angle_idx
      __pyx_v_local_move_idx = __pyx_v_angle_idx;
 0807: 
+0808:         angle_idx = angle_idx + 1
    __pyx_v_angle_idx = (__pyx_v_angle_idx + 1);
  }
 0809: 
 0810: 
+0811:     for i in xrange(0, (angle_idx)-2):
  __pyx_t_16 = (__pyx_v_angle_idx - 2);
  __pyx_t_17 = __pyx_t_16;
  for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_17; __pyx_t_11+=1) {
    __pyx_v_i = __pyx_t_11;
 0812: 
 0813:         # compute the two vectors between the positions
+0814:         a[0] = fix_angle_pbc_issues(angle_positions[i+1, 0] - angle_positions[i, 0])
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_1 = 0;
    __pyx_t_15 = __pyx_v_i;
    __pyx_t_14 = 0;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_1, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 814, __pyx_L1_error)
    __pyx_t_14 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_a.diminfo[0].strides) = __pyx_t_12;
+0815:         a[1] = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i, 1])
    __pyx_t_14 = (__pyx_v_i + 1);
    __pyx_t_15 = 1;
    __pyx_t_1 = __pyx_v_i;
    __pyx_t_2 = 1;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_2, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 815, __pyx_L1_error)
    __pyx_t_2 = 1;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_a.diminfo[0].strides) = __pyx_t_12;
+0816:         a[2] = fix_angle_pbc_issues(angle_positions[i+1, 2] - angle_positions[i, 2])
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_1 = 2;
    __pyx_t_15 = __pyx_v_i;
    __pyx_t_14 = 2;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_1, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 816, __pyx_L1_error)
    __pyx_t_14 = 2;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_a.diminfo[0].strides) = __pyx_t_12;
 0817: 
 0818:         #pritn "P2 to P1 [X] --> [%i] to [%i] = %i" % (angle_positions[i+1, 0], angle_positions[i, 0], a[0])
 0819:         #print "P2 to P1 [Y] --> [%i] to [%i] = %i" % (angle_positions[i+1, 1], angle_positions[i, 1], a[1])
 0820:         #print "P2 to P1 [Z] --> [%i] to [%i] = %i" % (angle_positions[i+1, 2], angle_positions[i, 2], a[2])
 0821: 
+0822:         b[0] = fix_angle_pbc_issues(angle_positions[i+1, 0] - angle_positions[i+2, 0])
    __pyx_t_14 = (__pyx_v_i + 1);
    __pyx_t_15 = 0;
    __pyx_t_1 = (__pyx_v_i + 2);
    __pyx_t_2 = 0;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_2, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 822, __pyx_L1_error)
    __pyx_t_2 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_b.diminfo[0].strides) = __pyx_t_12;
+0823:         b[1] = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i+2, 1])
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_1 = 1;
    __pyx_t_15 = (__pyx_v_i + 2);
    __pyx_t_14 = 1;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_1, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 823, __pyx_L1_error)
    __pyx_t_14 = 1;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_b.diminfo[0].strides) = __pyx_t_12;
+0824:         b[2] = fix_angle_pbc_issues(angle_positions[i+1, 2] - angle_positions[i+2, 2])
    __pyx_t_14 = (__pyx_v_i + 1);
    __pyx_t_15 = 2;
    __pyx_t_1 = (__pyx_v_i + 2);
    __pyx_t_2 = 2;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_2, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 824, __pyx_L1_error)
    __pyx_t_2 = 2;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_b.diminfo[0].strides) = __pyx_t_12;
 0825: 
+0826:         angle_penalty_old = angle_lookup[intcode_lookup[i+1], a[0]+1, a[1]+1, a[2]+1, b[0]+1, b[1]+1, b[2]+1] + angle_penalty_old
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_1 = 0;
    __pyx_t_15 = 1;
    __pyx_t_14 = 2;
    __pyx_t_18 = 0;
    __pyx_t_19 = 1;
    __pyx_t_20 = 2;
    __pyx_t_21 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_intcode_lookup.diminfo[0].strides));
    __pyx_t_22 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_a.diminfo[0].strides)) + 1);
    __pyx_t_23 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_a.diminfo[0].strides)) + 1);
    __pyx_t_24 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_a.diminfo[0].strides)) + 1);
    __pyx_t_25 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_b.diminfo[0].strides)) + 1);
    __pyx_t_26 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_b.diminfo[0].strides)) + 1);
    __pyx_t_27 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_b.diminfo[0].strides)) + 1);
    __pyx_v_angle_penalty_old = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=6 */ (( /* dim=5 */ (( /* dim=4 */ (( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_angle_lookup.data + __pyx_t_21 * __pyx_v_angle_lookup.strides[0]) ) + __pyx_t_22 * __pyx_v_angle_lookup.strides[1]) ) + __pyx_t_23 * __pyx_v_angle_lookup.strides[2]) ) + __pyx_t_24 * __pyx_v_angle_lookup.strides[3]) ) + __pyx_t_25 * __pyx_v_angle_lookup.strides[4]) ) + __pyx_t_26 * __pyx_v_angle_lookup.strides[5]) ) + __pyx_t_27 * __pyx_v_angle_lookup.strides[6]) ))) + __pyx_v_angle_penalty_old);
  }
 0827: 
+0828:     angle_positions[local_move_idx,0] = new_position[0]
  __pyx_t_20 = 0;
  __pyx_t_19 = __pyx_v_local_move_idx;
  __pyx_t_18 = 0;
  *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_20 * __pyx_v_new_position.strides[0]) )));
+0829:     angle_positions[local_move_idx,1] = new_position[1]
  __pyx_t_20 = 1;
  __pyx_t_18 = __pyx_v_local_move_idx;
  __pyx_t_19 = 1;
  *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_20 * __pyx_v_new_position.strides[0]) )));
+0830:     angle_positions[local_move_idx,2] = new_position[2]
  __pyx_t_20 = 2;
  __pyx_t_19 = __pyx_v_local_move_idx;
  __pyx_t_18 = 2;
  *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[1].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_20 * __pyx_v_new_position.strides[0]) )));
 0831: 
+0832:     for i in xrange(0, (angle_idx)-2):
  __pyx_t_16 = (__pyx_v_angle_idx - 2);
  __pyx_t_17 = __pyx_t_16;
  for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_17; __pyx_t_11+=1) {
    __pyx_v_i = __pyx_t_11;
 0833: 
 0834:         # compute the two vectors between the positions
+0835:         a[0] = fix_angle_pbc_issues(angle_positions[i+1, 0] - angle_positions[i, 0])
    __pyx_t_20 = (__pyx_v_i + 1);
    __pyx_t_18 = 0;
    __pyx_t_19 = __pyx_v_i;
    __pyx_t_14 = 0;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 835, __pyx_L1_error)
    __pyx_t_14 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_a.diminfo[0].strides) = __pyx_t_12;
+0836:         a[1] = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i, 1])
    __pyx_t_14 = (__pyx_v_i + 1);
    __pyx_t_19 = 1;
    __pyx_t_18 = __pyx_v_i;
    __pyx_t_20 = 1;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 836, __pyx_L1_error)
    __pyx_t_20 = 1;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_a.diminfo[0].strides) = __pyx_t_12;
+0837:         a[2] = fix_angle_pbc_issues(angle_positions[i+1, 2] - angle_positions[i, 2])
    __pyx_t_20 = (__pyx_v_i + 1);
    __pyx_t_18 = 2;
    __pyx_t_19 = __pyx_v_i;
    __pyx_t_14 = 2;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 837, __pyx_L1_error)
    __pyx_t_14 = 2;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_a.diminfo[0].strides) = __pyx_t_12;
 0838: 
+0839:         b[0] = fix_angle_pbc_issues(angle_positions[i+1, 0] - angle_positions[i+2, 0])
    __pyx_t_14 = (__pyx_v_i + 1);
    __pyx_t_19 = 0;
    __pyx_t_18 = (__pyx_v_i + 2);
    __pyx_t_20 = 0;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 839, __pyx_L1_error)
    __pyx_t_20 = 0;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_b.diminfo[0].strides) = __pyx_t_12;
+0840:         b[1] = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i+2, 1])
    __pyx_t_20 = (__pyx_v_i + 1);
    __pyx_t_18 = 1;
    __pyx_t_19 = (__pyx_v_i + 2);
    __pyx_t_14 = 1;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 840, __pyx_L1_error)
    __pyx_t_14 = 1;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_b.diminfo[0].strides) = __pyx_t_12;
+0841:         b[2] = fix_angle_pbc_issues(angle_positions[i+1, 2] - angle_positions[i+2, 2])
    __pyx_t_14 = (__pyx_v_i + 1);
    __pyx_t_19 = 2;
    __pyx_t_18 = (__pyx_v_i + 2);
    __pyx_t_20 = 2;
    __pyx_t_12 = __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(((*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_angle_positions.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_angle_positions.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 841, __pyx_L1_error)
    __pyx_t_20 = 2;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_b.diminfo[0].strides) = __pyx_t_12;
 0842: 
+0843:         angle_penalty_new = angle_lookup[intcode_lookup[i+1], a[0]+1, a[1]+1, a[2]+1, b[0]+1, b[1]+1, b[2]+1] + angle_penalty_new
    __pyx_t_20 = (__pyx_v_i + 1);
    __pyx_t_18 = 0;
    __pyx_t_19 = 1;
    __pyx_t_14 = 2;
    __pyx_t_15 = 0;
    __pyx_t_1 = 1;
    __pyx_t_2 = 2;
    __pyx_t_27 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_intcode_lookup.diminfo[0].strides));
    __pyx_t_26 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_a.diminfo[0].strides)) + 1);
    __pyx_t_25 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_a.diminfo[0].strides)) + 1);
    __pyx_t_24 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_a.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_a.diminfo[0].strides)) + 1);
    __pyx_t_23 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_b.diminfo[0].strides)) + 1);
    __pyx_t_22 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_b.diminfo[0].strides)) + 1);
    __pyx_t_21 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_b.diminfo[0].strides)) + 1);
    __pyx_v_angle_penalty_new = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=6 */ (( /* dim=5 */ (( /* dim=4 */ (( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_angle_lookup.data + __pyx_t_27 * __pyx_v_angle_lookup.strides[0]) ) + __pyx_t_26 * __pyx_v_angle_lookup.strides[1]) ) + __pyx_t_25 * __pyx_v_angle_lookup.strides[2]) ) + __pyx_t_24 * __pyx_v_angle_lookup.strides[3]) ) + __pyx_t_23 * __pyx_v_angle_lookup.strides[4]) ) + __pyx_t_22 * __pyx_v_angle_lookup.strides[5]) ) + __pyx_t_21 * __pyx_v_angle_lookup.strides[6]) ))) + __pyx_v_angle_penalty_new);
  }
 0844: 
+0845:     return (angle_penalty_new - angle_penalty_old)
  __pyx_r = (__pyx_v_angle_penalty_new - __pyx_v_angle_penalty_old);
  goto __pyx_L0;
 0846: 
 0847: 
 0848: 
+0849: @cython.cdivision(True)
static int __pyx_f_5pimms_10mega_crank_fix_angle_pbc_issues(int __pyx_v_distance) {
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
 0850: cdef int fix_angle_pbc_issues(int distance):
 0851:     """
 0852:     Hack that takes advantage of the fact that the distances all must be -1,0, +1 and
 0853:     we're always computing a X->O vector where O is the bend point
 0854: 
 0855:     """
+0856:     if distance < -1:
  __pyx_t_1 = (__pyx_v_distance < -1L);
  if (__pyx_t_1) {
/* … */
  }
+0857:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
+0858:     elif distance > 1:
  __pyx_t_1 = (__pyx_v_distance > 1);
  if (__pyx_t_1) {
/* … */
  }
+0859:         return -1
    __pyx_r = -1;
    goto __pyx_L0;
 0860:     else:
+0861:         return distance
  /*else*/ {
    __pyx_r = __pyx_v_distance;
    goto __pyx_L0;
  }
 0862: 
 0863: 
 0864: 
 0865: 
 0866: # these directives made the function slower...
+0867: @cython.wraparound(False)
static PyObject *__pyx_f_5pimms_10mega_crank_get_energy_change(CYTHON_UNUSED __Pyx_memviewslice __pyx_v_grid, __Pyx_memviewslice __pyx_v_type_grid, __Pyx_memviewslice __pyx_v_old_position, __Pyx_memviewslice __pyx_v_new_position, int __pyx_v_LR_vs_SR, __Pyx_memviewslice __pyx_v_interaction_table, __Pyx_memviewslice __pyx_v_LR_interaction_table, __Pyx_memviewslice __pyx_v_SLR_interaction_table, int __pyx_v_XDIM, int __pyx_v_YDIM, int __pyx_v_ZDIM, int __pyx_v_hardwall) {
  long __pyx_v_energy_old;
  long __pyx_v_energy_old_empty;
  long __pyx_v_energy_new;
  long __pyx_v_energy_new_empty;
  int __pyx_v_old_x;
  int __pyx_v_old_y;
  int __pyx_v_old_z;
  int __pyx_v_new_x;
  int __pyx_v_new_y;
  int __pyx_v_new_z;
  int __pyx_v_tmp_x;
  int __pyx_v_tmp_y;
  int __pyx_v_tmp_z;
  int __pyx_v_x;
  int __pyx_v_y;
  int __pyx_v_z;
  unsigned int __pyx_v_site_bead_type;
  unsigned int __pyx_v_bead_type;
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("pimms.mega_crank.get_energy_change", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0868: @cython.boundscheck(False)
 0869: cdef get_energy_change(NUMPY_INT_TYPE[:,:,:] grid,
 0870:                        NUMPY_INT_TYPE[:,:,:] type_grid,
 0871:                        NUMPY_INT_TYPE[:] old_position,
 0872:                        NUMPY_INT_TYPE[:] new_position,
 0873:                        int LR_vs_SR,
 0874:                        NUMPY_INT_TYPE[:,:] interaction_table,
 0875:                        NUMPY_INT_TYPE[:,:] LR_interaction_table,
 0876:                        NUMPY_INT_TYPE[:,:] SLR_interaction_table,
 0877:                        int XDIM,
 0878:                        int YDIM,
 0879:                        int ZDIM,
 0880:                        int hardwall):
 0881: 
 0882:     """
 0883:     cdef get_energy_change(cnp.ndarray[NUMPY_INT_TYPE, ndim=3] grid,
 0884:     cnp.ndarray[NUMPY_INT_TYPE, ndim=3] type_grid,
 0885:     cnp.ndarray[NUMPY_INT_TYPE, ndim=1] old_position,
 0886:     cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position,
 0887:     int LR_vs_SR,
 0888:     cnp.ndarray[long, ndim=2] interaction_table,
 0889:     cnp.ndarray[long, ndim=2] LR_interaction_table,
 0890:     cnp.ndarray[long, ndim=2] SLR_interaction_table,
 0891:     int XDIM,
 0892:     int YDIM,
 0893:     int ZDIM,
 0894:     int hardwall):
 0895:     """
 0896: 
 0897:     # We define four energy variables which are going to be used to calcualte
 0898:     # the DELTA energy.
 0899:     #
 0900:     # --> energy old is the interactions between the bead and its
 0901:     # partners in its current location
 0902:     #
 0903:     # --> energy_old_empy is the energy associated with the site after this
 0904:     # bead has been removed (i.e. solvent to local partners only)
 0905:     #
 0906:     # --> energy_new is the interaction between the bead and its partners in
 0907:     #     its NEW location!
 0908:     #
 0909:     # --> energy_new_empty is the interaction between the bead and its
 0910: 
+0911:     cdef long energy_old       = 0
  __pyx_v_energy_old = 0;
+0912:     cdef long energy_old_empty = 0
  __pyx_v_energy_old_empty = 0;
+0913:     cdef long energy_new       = 0
  __pyx_v_energy_new = 0;
+0914:     cdef long energy_new_empty = 0
  __pyx_v_energy_new_empty = 0;
 0915: 
 0916: 
 0917:     cdef int old_x, old_y, old_z;
 0918:     cdef int new_x, new_y, new_z;
 0919:     cdef int tmp_x, tmp_y, tmp_z;
 0920: 
 0921:     cdef int x, y, z
 0922: 
 0923:     cdef unsigned int site_bead_type, bead_type;
 0924: 
 0925:     # extract
+0926:     new_x = new_position[0]
  __pyx_t_1 = 0;
  __pyx_v_new_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_1 * __pyx_v_new_position.strides[0]) )));
+0927:     new_y = new_position[1]
  __pyx_t_1 = 1;
  __pyx_v_new_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_1 * __pyx_v_new_position.strides[0]) )));
+0928:     new_z = new_position[2]
  __pyx_t_1 = 2;
  __pyx_v_new_z = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_1 * __pyx_v_new_position.strides[0]) )));
 0929: 
+0930:     old_x = old_position[0]
  __pyx_t_1 = 0;
  __pyx_v_old_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_1 * __pyx_v_old_position.strides[0]) )));
+0931:     old_y = old_position[1]
  __pyx_t_1 = 1;
  __pyx_v_old_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_1 * __pyx_v_old_position.strides[0]) )));
+0932:     old_z = old_position[2]
  __pyx_t_1 = 2;
  __pyx_v_old_z = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_1 * __pyx_v_old_position.strides[0]) )));
 0933: 
 0934:     # get the type of the current beads
+0935:     bead_type = type_grid[old_x, old_y, old_z]
  __pyx_t_1 = __pyx_v_old_x;
  __pyx_t_2 = __pyx_v_old_y;
  __pyx_t_3 = __pyx_v_old_z;
  __pyx_v_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[2]) )));
 0936: 
 0937:     ## ************************************************************************************************
 0938:     ##  Long range energy
 0939:     ##
 0940:     # if we're looking at a bead which engages in longrange interactions
+0941:     if LR_vs_SR == 1:
  __pyx_t_4 = (__pyx_v_LR_vs_SR == 1);
  if (__pyx_t_4) {
/* … */
    goto __pyx_L3;
  }
 0942: 
 0943:         ## First evaluate the old energy
+0944:         for x in range(-3,4):
    for (__pyx_t_5 = -3; __pyx_t_5 < 4; __pyx_t_5+=1) {
      __pyx_v_x = __pyx_t_5;
+0945:             for y in range(-3,4):
      for (__pyx_t_6 = -3; __pyx_t_6 < 4; __pyx_t_6+=1) {
        __pyx_v_y = __pyx_t_6;
+0946:                 for z in range(-3,4):
        for (__pyx_t_7 = -3; __pyx_t_7 < 4; __pyx_t_7+=1) {
          __pyx_v_z = __pyx_t_7;
 0947: 
+0948:                     tmp_x = pbc_correction(old_x + x, XDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_old_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 948, __pyx_L1_error)
          __pyx_v_tmp_x = __pyx_t_8;
+0949:                     tmp_y = pbc_correction(old_y + y, YDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_old_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 949, __pyx_L1_error)
          __pyx_v_tmp_y = __pyx_t_8;
+0950:                     tmp_z = pbc_correction(old_z + z, ZDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_old_z + __pyx_v_z), __pyx_v_ZDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 950, __pyx_L1_error)
          __pyx_v_tmp_z = __pyx_t_8;
 0951: 
+0952:                     site_bead_type = type_grid[tmp_x, tmp_y, tmp_z]
          __pyx_t_3 = __pyx_v_tmp_x;
          __pyx_t_2 = __pyx_v_tmp_y;
          __pyx_t_1 = __pyx_v_tmp_z;
          __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[2]) )));
 0953: 
 0954:                     # short-range interactions
+0955:                     if abs(x) < 2 and abs(y) < 2 and abs(z) < 2:
          __pyx_t_8 = abs(__pyx_v_x); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 955, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 2);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L11_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_y); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 955, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 2);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L11_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_z); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 955, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 2);
          __pyx_t_4 = __pyx_t_9;
          __pyx_L11_bool_binop_done:;
          if (__pyx_t_4) {
/* … */
            goto __pyx_L10;
          }
 0956: 
 0957:                         # if harwall boundary is on and the site bead is jumping over the PBC then it is by
 0958:                         # definition solvent (type = 0)
+0959:                         if hardwall == 1:
            __pyx_t_4 = (__pyx_v_hardwall == 1);
            if (__pyx_t_4) {
/* … */
            }
+0960:                             if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3 or abs(tmp_z - old_z) > 3:
              __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 960, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L16_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 960, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L16_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_old_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 960, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              __pyx_t_4 = __pyx_t_9;
              __pyx_L16_bool_binop_done:;
              if (__pyx_t_4) {
/* … */
              }
+0961:                                 site_bead_type=0
                __pyx_v_site_bead_type = 0;
 0962: 
 0963:                         # bead-site interaction
+0964:                         energy_old = energy_old + interaction_table[bead_type, site_bead_type]
            __pyx_t_10 = __pyx_v_bead_type;
            __pyx_t_11 = __pyx_v_site_bead_type;
            __pyx_v_energy_old = (__pyx_v_energy_old + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_10 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_interaction_table.strides[1]) ))));
 0965: 
 0966:                         # might be faster to just read this from memory every time - is if or a memory read and addition faster?
+0967:                         if site_bead_type > 0:
            __pyx_t_4 = (__pyx_v_site_bead_type > 0);
            if (__pyx_t_4) {
/* … */
            }
+0968:                             energy_old_empty = energy_old_empty + interaction_table[0, site_bead_type]
              __pyx_t_1 = 0;
              __pyx_t_11 = __pyx_v_site_bead_type;
              __pyx_v_energy_old_empty = (__pyx_v_energy_old_empty + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_1 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_interaction_table.strides[1]) ))));
 0969: 
 0970:                     # long range interactions (maybe optimize this in future...) - note long range interactions cannot
 0971:                     # contribute to the energy_old_empty variable
+0972:                     elif abs(x) < 3 and abs(y) < 3 and abs(z) <3:
          __pyx_t_8 = abs(__pyx_v_x); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 972, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 3);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L20_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_y); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 972, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 3);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L20_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_z); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 972, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 3);
          __pyx_t_4 = __pyx_t_9;
          __pyx_L20_bool_binop_done:;
          if (__pyx_t_4) {
/* … */
            goto __pyx_L10;
          }
 0973: 
 0974:                         # if harwall boundary is on - don't feel LR or SLR interactions over boundary
+0975:                         if hardwall == 1:
            __pyx_t_4 = (__pyx_v_hardwall == 1);
            if (__pyx_t_4) {
/* … */
            }
+0976:                             if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3 or abs(tmp_z - old_z) > 3:
              __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 976, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L25_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 976, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L25_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_old_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 976, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              __pyx_t_4 = __pyx_t_9;
              __pyx_L25_bool_binop_done:;
              if (__pyx_t_4) {
/* … */
              }
+0977:                                 continue
                goto __pyx_L8_continue;
 0978: 
+0979:                         energy_old = energy_old + LR_interaction_table[bead_type, site_bead_type]
            __pyx_t_11 = __pyx_v_bead_type;
            __pyx_t_10 = __pyx_v_site_bead_type;
            __pyx_v_energy_old = (__pyx_v_energy_old + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_LR_interaction_table.data + __pyx_t_11 * __pyx_v_LR_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_LR_interaction_table.strides[1]) ))));
 0980: 
 0981:                     else:
 0982: 
 0983:                         # if harwall boundary is on - don't feel LR or SLR interactions over boundary
+0984:                         if hardwall == 1:
          /*else*/ {
            __pyx_t_4 = (__pyx_v_hardwall == 1);
            if (__pyx_t_4) {
/* … */
            }
+0985:                             if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3 or abs(tmp_z - old_z) > 3:
              __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 985, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L30_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 985, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L30_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_old_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 985, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              __pyx_t_4 = __pyx_t_9;
              __pyx_L30_bool_binop_done:;
              if (__pyx_t_4) {
/* … */
              }
+0986:                                 continue
                goto __pyx_L8_continue;
 0987: 
+0988:                         energy_old = energy_old + SLR_interaction_table[bead_type, site_bead_type]
            __pyx_t_10 = __pyx_v_bead_type;
            __pyx_t_11 = __pyx_v_site_bead_type;
            __pyx_v_energy_old = (__pyx_v_energy_old + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_SLR_interaction_table.data + __pyx_t_10 * __pyx_v_SLR_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_SLR_interaction_table.strides[1]) ))));
          }
          __pyx_L10:;
          __pyx_L8_continue:;
        }
      }
    }
 0989: 
 0990: 
 0991: 
 0992:         # reset the typegrid to the new configuation
+0993:         type_grid[new_x,new_y,new_z] = type_grid[old_x,old_y,old_z]
    __pyx_t_1 = __pyx_v_old_x;
    __pyx_t_2 = __pyx_v_old_y;
    __pyx_t_3 = __pyx_v_old_z;
    __pyx_t_12 = __pyx_v_new_x;
    __pyx_t_13 = __pyx_v_new_y;
    __pyx_t_14 = __pyx_v_new_z;
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_12 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_13 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_14 * __pyx_v_type_grid.strides[2]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[2]) )));
+0994:         type_grid[old_x,old_y,old_z] = 0
    __pyx_t_3 = __pyx_v_old_x;
    __pyx_t_2 = __pyx_v_old_y;
    __pyx_t_1 = __pyx_v_old_z;
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[2]) )) = 0;
 0995: 
 0996:         ## then evaluate the new energy
+0997:         for x in range(-3,4):
    for (__pyx_t_5 = -3; __pyx_t_5 < 4; __pyx_t_5+=1) {
      __pyx_v_x = __pyx_t_5;
+0998:             for y in range(-3,4):
      for (__pyx_t_6 = -3; __pyx_t_6 < 4; __pyx_t_6+=1) {
        __pyx_v_y = __pyx_t_6;
+0999:                 for z in range(-3,4):
        for (__pyx_t_7 = -3; __pyx_t_7 < 4; __pyx_t_7+=1) {
          __pyx_v_z = __pyx_t_7;
 1000: 
 1001:                     # get PBC corrected positions of interest
+1002:                     tmp_x = pbc_correction(new_x + x, XDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_new_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1002, __pyx_L1_error)
          __pyx_v_tmp_x = __pyx_t_8;
+1003:                     tmp_y = pbc_correction(new_y + y, YDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_new_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1003, __pyx_L1_error)
          __pyx_v_tmp_y = __pyx_t_8;
+1004:                     tmp_z = pbc_correction(new_z + z, ZDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_new_z + __pyx_v_z), __pyx_v_ZDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1004, __pyx_L1_error)
          __pyx_v_tmp_z = __pyx_t_8;
 1005: 
+1006:                     site_bead_type = type_grid[tmp_x, tmp_y, tmp_z]
          __pyx_t_1 = __pyx_v_tmp_x;
          __pyx_t_2 = __pyx_v_tmp_y;
          __pyx_t_3 = __pyx_v_tmp_z;
          __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[2]) )));
 1007: 
 1008:                     # short-range interactions
+1009:                     if abs(x) < 2 and abs(y) < 2 and abs(z) <2:
          __pyx_t_8 = abs(__pyx_v_x); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1009, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 2);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L40_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_y); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1009, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 2);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L40_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_z); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1009, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 2);
          __pyx_t_4 = __pyx_t_9;
          __pyx_L40_bool_binop_done:;
          if (__pyx_t_4) {
/* … */
            goto __pyx_L39;
          }
 1010: 
 1011:                         # if harwall boundary is on... (see previous codeblock for an explanation)
+1012:                         if hardwall == 1:
            __pyx_t_4 = (__pyx_v_hardwall == 1);
            if (__pyx_t_4) {
/* … */
            }
+1013:                             if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3 or abs(tmp_z - new_z) > 3:
              __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1013, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L45_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1013, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L45_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_new_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1013, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              __pyx_t_4 = __pyx_t_9;
              __pyx_L45_bool_binop_done:;
              if (__pyx_t_4) {
/* … */
              }
+1014:                                 site_bead_type=0
                __pyx_v_site_bead_type = 0;
 1015: 
 1016:                         # bead-site interaction
+1017:                         energy_new = energy_new + interaction_table[bead_type, site_bead_type]
            __pyx_t_11 = __pyx_v_bead_type;
            __pyx_t_10 = __pyx_v_site_bead_type;
            __pyx_v_energy_new = (__pyx_v_energy_new + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_11 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_interaction_table.strides[1]) ))));
 1018: 
+1019:                         if site_bead_type > 0:
            __pyx_t_4 = (__pyx_v_site_bead_type > 0);
            if (__pyx_t_4) {
/* … */
            }
+1020:                             energy_new_empty = energy_new_empty + interaction_table[0, site_bead_type]
              __pyx_t_3 = 0;
              __pyx_t_10 = __pyx_v_site_bead_type;
              __pyx_v_energy_new_empty = (__pyx_v_energy_new_empty + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_3 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_interaction_table.strides[1]) ))));
 1021: 
 1022:                     # long range interactions (maybe optimize this in future...) - note long range interactions cannot
 1023:                     # contribute to the energy_old_empty variable
+1024:                     elif abs(x) < 3 and abs(y) < 3 and abs(z) <3:
          __pyx_t_8 = abs(__pyx_v_x); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1024, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 3);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L49_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_y); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1024, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 3);
          if (__pyx_t_9) {
          } else {
            __pyx_t_4 = __pyx_t_9;
            goto __pyx_L49_bool_binop_done;
          }
          __pyx_t_8 = abs(__pyx_v_z); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1024, __pyx_L1_error)
          __pyx_t_9 = (__pyx_t_8 < 3);
          __pyx_t_4 = __pyx_t_9;
          __pyx_L49_bool_binop_done:;
          if (__pyx_t_4) {
/* … */
            goto __pyx_L39;
          }
 1025: 
 1026:                         # if harwall boundary is on - skip LR interactions
+1027:                         if hardwall == 1:
            __pyx_t_4 = (__pyx_v_hardwall == 1);
            if (__pyx_t_4) {
/* … */
            }
+1028:                             if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3 or abs(tmp_z - new_z) > 3:
              __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1028, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L54_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1028, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L54_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_new_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1028, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              __pyx_t_4 = __pyx_t_9;
              __pyx_L54_bool_binop_done:;
              if (__pyx_t_4) {
/* … */
              }
+1029:                                 continue
                goto __pyx_L37_continue;
 1030: 
+1031:                         energy_new = energy_new + LR_interaction_table[bead_type, site_bead_type]
            __pyx_t_10 = __pyx_v_bead_type;
            __pyx_t_11 = __pyx_v_site_bead_type;
            __pyx_v_energy_new = (__pyx_v_energy_new + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_LR_interaction_table.data + __pyx_t_10 * __pyx_v_LR_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_LR_interaction_table.strides[1]) ))));
 1032: 
 1033:                     else:
 1034: 
 1035:                         # if harwall boundary is on - skip LR interactions
+1036:                         if hardwall == 1:
          /*else*/ {
            __pyx_t_4 = (__pyx_v_hardwall == 1);
            if (__pyx_t_4) {
/* … */
            }
+1037:                             if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3 or abs(tmp_z - new_z) > 3:
              __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1037, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L59_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1037, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              if (!__pyx_t_9) {
              } else {
                __pyx_t_4 = __pyx_t_9;
                goto __pyx_L59_bool_binop_done;
              }
              __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_new_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1037, __pyx_L1_error)
              __pyx_t_9 = (__pyx_t_8 > 3);
              __pyx_t_4 = __pyx_t_9;
              __pyx_L59_bool_binop_done:;
              if (__pyx_t_4) {
/* … */
              }
+1038:                                 continue
                goto __pyx_L37_continue;
 1039: 
+1040:                         energy_new = energy_new + SLR_interaction_table[bead_type, site_bead_type]
            __pyx_t_11 = __pyx_v_bead_type;
            __pyx_t_10 = __pyx_v_site_bead_type;
            __pyx_v_energy_new = (__pyx_v_energy_new + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_SLR_interaction_table.data + __pyx_t_11 * __pyx_v_SLR_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_SLR_interaction_table.strides[1]) ))));
          }
          __pyx_L39:;
          __pyx_L37_continue:;
        }
      }
    }
 1041: 
 1042: 
 1043:     ## ************************************************************************************************
 1044:     ##  only short range brah!
 1045:     ##
 1046:     else:
+1047:         for x in range(-1,2):
  /*else*/ {
    for (__pyx_t_5 = -1; __pyx_t_5 < 2; __pyx_t_5+=1) {
      __pyx_v_x = __pyx_t_5;
+1048:             for y in range(-1,2):
      for (__pyx_t_6 = -1; __pyx_t_6 < 2; __pyx_t_6+=1) {
        __pyx_v_y = __pyx_t_6;
+1049:                 for z in range(-1,2):
        for (__pyx_t_7 = -1; __pyx_t_7 < 2; __pyx_t_7+=1) {
          __pyx_v_z = __pyx_t_7;
 1050: 
 1051:                     # get PBC corrected positions of interest
+1052:                     tmp_x = pbc_correction(old_x + x, XDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_old_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1052, __pyx_L1_error)
          __pyx_v_tmp_x = __pyx_t_8;
+1053:                     tmp_y = pbc_correction(old_y + y, YDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_old_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1053, __pyx_L1_error)
          __pyx_v_tmp_y = __pyx_t_8;
+1054:                     tmp_z = pbc_correction(old_z + z, ZDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_old_z + __pyx_v_z), __pyx_v_ZDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1054, __pyx_L1_error)
          __pyx_v_tmp_z = __pyx_t_8;
 1055: 
 1056: 
+1057:                     site_bead_type = type_grid[tmp_x, tmp_y, tmp_z]
          __pyx_t_3 = __pyx_v_tmp_x;
          __pyx_t_2 = __pyx_v_tmp_y;
          __pyx_t_1 = __pyx_v_tmp_z;
          __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[2]) )));
 1058: 
 1059:                     # if harwall boundary is on... then interactions that would straddle the boundary
 1060:                     # must be solvent, so overwrite
+1061:                     if hardwall == 1:
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+1062:                         if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3 or abs(tmp_z - old_z) > 3:
            __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1062, __pyx_L1_error)
            __pyx_t_9 = (__pyx_t_8 > 3);
            if (!__pyx_t_9) {
            } else {
              __pyx_t_4 = __pyx_t_9;
              goto __pyx_L70_bool_binop_done;
            }
            __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1062, __pyx_L1_error)
            __pyx_t_9 = (__pyx_t_8 > 3);
            if (!__pyx_t_9) {
            } else {
              __pyx_t_4 = __pyx_t_9;
              goto __pyx_L70_bool_binop_done;
            }
            __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_old_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1062, __pyx_L1_error)
            __pyx_t_9 = (__pyx_t_8 > 3);
            __pyx_t_4 = __pyx_t_9;
            __pyx_L70_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+1063:                             site_bead_type = 0
              __pyx_v_site_bead_type = 0;
 1064: 
 1065:                     # bead-site interaction
+1066:                     energy_old = energy_old + interaction_table[bead_type, site_bead_type]
          __pyx_t_10 = __pyx_v_bead_type;
          __pyx_t_11 = __pyx_v_site_bead_type;
          __pyx_v_energy_old = (__pyx_v_energy_old + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_10 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_interaction_table.strides[1]) ))));
 1067: 
 1068:                     # might be faster to just read this from memory every time - is if or a memory read and addition faster?
+1069:                     if site_bead_type > 0:
          __pyx_t_4 = (__pyx_v_site_bead_type > 0);
          if (__pyx_t_4) {
/* … */
          }
        }
      }
    }
+1070:                         energy_old_empty = energy_old_empty + interaction_table[0, site_bead_type]
            __pyx_t_1 = 0;
            __pyx_t_11 = __pyx_v_site_bead_type;
            __pyx_v_energy_old_empty = (__pyx_v_energy_old_empty + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_1 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_interaction_table.strides[1]) ))));
 1071: 
 1072:         # reset the typegrid to the new configuation
+1073:         type_grid[new_x,new_y,new_z] = type_grid[old_x,old_y,old_z]
    __pyx_t_1 = __pyx_v_old_x;
    __pyx_t_2 = __pyx_v_old_y;
    __pyx_t_3 = __pyx_v_old_z;
    __pyx_t_14 = __pyx_v_new_x;
    __pyx_t_13 = __pyx_v_new_y;
    __pyx_t_12 = __pyx_v_new_z;
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_14 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_13 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_12 * __pyx_v_type_grid.strides[2]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[2]) )));
+1074:         type_grid[old_x,old_y,old_z] = 0
    __pyx_t_3 = __pyx_v_old_x;
    __pyx_t_2 = __pyx_v_old_y;
    __pyx_t_1 = __pyx_v_old_z;
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[2]) )) = 0;
 1075: 
+1076:         for x in range(-1,2):
    for (__pyx_t_5 = -1; __pyx_t_5 < 2; __pyx_t_5+=1) {
      __pyx_v_x = __pyx_t_5;
+1077:             for y in range(-1,2):
      for (__pyx_t_6 = -1; __pyx_t_6 < 2; __pyx_t_6+=1) {
        __pyx_v_y = __pyx_t_6;
+1078:                 for z in range(-1,2):
        for (__pyx_t_7 = -1; __pyx_t_7 < 2; __pyx_t_7+=1) {
          __pyx_v_z = __pyx_t_7;
 1079: 
 1080:                     # get PBC corrected positions of interest
+1081:                     tmp_x = pbc_correction(new_x + x, XDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_new_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1081, __pyx_L1_error)
          __pyx_v_tmp_x = __pyx_t_8;
+1082:                     tmp_y = pbc_correction(new_y + y, YDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_new_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1082, __pyx_L1_error)
          __pyx_v_tmp_y = __pyx_t_8;
+1083:                     tmp_z = pbc_correction(new_z + z, ZDIM)
          __pyx_t_8 = __pyx_f_5pimms_10mega_crank_pbc_correction((__pyx_v_new_z + __pyx_v_z), __pyx_v_ZDIM); if (unlikely(__pyx_t_8 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1083, __pyx_L1_error)
          __pyx_v_tmp_z = __pyx_t_8;
 1084: 
 1085:                     #tmp_x = (new_x + x) % XDIM
 1086:                     #tmp_y = (new_y + y) % YDIM
 1087:                     #tmp_z = (new_z + z) % ZDIM
 1088: 
 1089:                     # if harwall boundary is on...
+1090:                     site_bead_type = type_grid[tmp_x, tmp_y, tmp_z]
          __pyx_t_1 = __pyx_v_tmp_x;
          __pyx_t_2 = __pyx_v_tmp_y;
          __pyx_t_3 = __pyx_v_tmp_z;
          __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[2]) )));
+1091:                     if hardwall == 1:
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+1092:                         if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3 or abs(tmp_z - new_z) > 3:
            __pyx_t_8 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1092, __pyx_L1_error)
            __pyx_t_9 = (__pyx_t_8 > 3);
            if (!__pyx_t_9) {
            } else {
              __pyx_t_4 = __pyx_t_9;
              goto __pyx_L82_bool_binop_done;
            }
            __pyx_t_8 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1092, __pyx_L1_error)
            __pyx_t_9 = (__pyx_t_8 > 3);
            if (!__pyx_t_9) {
            } else {
              __pyx_t_4 = __pyx_t_9;
              goto __pyx_L82_bool_binop_done;
            }
            __pyx_t_8 = abs((__pyx_v_tmp_z - __pyx_v_new_z)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1092, __pyx_L1_error)
            __pyx_t_9 = (__pyx_t_8 > 3);
            __pyx_t_4 = __pyx_t_9;
            __pyx_L82_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+1093:                             site_bead_type = 0
              __pyx_v_site_bead_type = 0;
 1094: 
 1095:                     # bead-site interaction
+1096:                     energy_new = energy_new + interaction_table[bead_type, site_bead_type]
          __pyx_t_11 = __pyx_v_bead_type;
          __pyx_t_10 = __pyx_v_site_bead_type;
          __pyx_v_energy_new = (__pyx_v_energy_new + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_11 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_interaction_table.strides[1]) ))));
 1097: 
 1098:                     # might be faster to just read this from memory every time - is if or a memory read and addition faster?
+1099:                     if site_bead_type > 0:
          __pyx_t_4 = (__pyx_v_site_bead_type > 0);
          if (__pyx_t_4) {
/* … */
          }
        }
      }
    }
  }
  __pyx_L3:;
+1100:                         energy_new_empty = energy_new_empty + interaction_table[0, site_bead_type]
            __pyx_t_3 = 0;
            __pyx_t_10 = __pyx_v_site_bead_type;
            __pyx_v_energy_new_empty = (__pyx_v_energy_new_empty + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_3 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_interaction_table.strides[1]) ))));
 1101: 
 1102: 
 1103:     # finally correct for the self-self interactions we cover when x == y == z == 0
+1104:     energy_old_empty = energy_old_empty - interaction_table[0, bead_type]
  __pyx_t_3 = 0;
  __pyx_t_10 = __pyx_v_bead_type;
  __pyx_v_energy_old_empty = (__pyx_v_energy_old_empty - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_3 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_interaction_table.strides[1]) ))));
+1105:     energy_old       = energy_old - interaction_table[bead_type, bead_type]
  __pyx_t_10 = __pyx_v_bead_type;
  __pyx_t_11 = __pyx_v_bead_type;
  __pyx_v_energy_old = (__pyx_v_energy_old - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_10 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_interaction_table.strides[1]) ))));
+1106:     energy_new_empty = energy_new_empty - interaction_table[0, bead_type]
  __pyx_t_3 = 0;
  __pyx_t_11 = __pyx_v_bead_type;
  __pyx_v_energy_new_empty = (__pyx_v_energy_new_empty - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_3 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_11 * __pyx_v_interaction_table.strides[1]) ))));
+1107:     energy_new       = energy_new - interaction_table[bead_type, bead_type]
  __pyx_t_11 = __pyx_v_bead_type;
  __pyx_t_10 = __pyx_v_bead_type;
  __pyx_v_energy_new = (__pyx_v_energy_new - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_interaction_table.data + __pyx_t_11 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_10 * __pyx_v_interaction_table.strides[1]) ))));
 1108: 
 1109:     # reset the type grid again...
+1110:     type_grid[old_x,old_y,old_z] = type_grid[new_x,new_y,new_z]
  __pyx_t_3 = __pyx_v_new_x;
  __pyx_t_2 = __pyx_v_new_y;
  __pyx_t_1 = __pyx_v_new_z;
  __pyx_t_12 = __pyx_v_old_x;
  __pyx_t_13 = __pyx_v_old_y;
  __pyx_t_14 = __pyx_v_old_z;
  *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_12 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_13 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_14 * __pyx_v_type_grid.strides[2]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[2]) )));
+1111:     type_grid[new_x,new_y,new_z] = 0
  __pyx_t_1 = __pyx_v_new_x;
  __pyx_t_2 = __pyx_v_new_y;
  __pyx_t_3 = __pyx_v_new_z;
  *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_type_grid.strides[1]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[2]) )) = 0;
 1112: 
 1113: 
+1114:     return (energy_new + energy_old_empty) - (energy_old + energy_new_empty)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_15 = __Pyx_PyLong_From_long(((__pyx_v_energy_new + __pyx_v_energy_old_empty) - (__pyx_v_energy_old + __pyx_v_energy_new_empty))); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_r = __pyx_t_15;
  __pyx_t_15 = 0;
  goto __pyx_L0;
 1115: 
+1116: @cython.cdivision(True)
static int __pyx_f_5pimms_10mega_crank_pbc_correction(int __pyx_v_value, int __pyx_v_DIM) {
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
 1117: cdef int pbc_correction(int value, int DIM):
 1118:     """
 1119:     Performs intelligent periodic boundary correction
 1120:     which FIRST checks to see if we have a negative
 1121:     value and IF NOT uses the % operator - this means
 1122:     we can use % without checking the sign giving
 1123:     a 35% speedup per call
 1124:     """
 1125: 
+1126:     if value < 0:
  __pyx_t_1 = (__pyx_v_value < 0);
  if (__pyx_t_1) {
/* … */
  }
+1127:         return DIM+value
    __pyx_r = (__pyx_v_DIM + __pyx_v_value);
    goto __pyx_L0;
 1128:     else:
+1129:         return (value % DIM)
  /*else*/ {
    __pyx_r = (__pyx_v_value % __pyx_v_DIM);
    goto __pyx_L0;
  }
 1130: 
 1131: 
 1132: 
+1133: @cython.wraparound(False)
static int __pyx_f_5pimms_10mega_crank_do_positions_stradle_pbc_boundary(__Pyx_memviewslice __pyx_v_chain_positions, int __pyx_v_chain_length) {
  int __pyx_v_pidx;
  int __pyx_v_p1_x;
  int __pyx_v_p2_x;
  int __pyx_v_p1_y;
  int __pyx_v_p2_y;
  int __pyx_v_p1_z;
  int __pyx_v_p2_z;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pimms.mega_crank.do_positions_stradle_pbc_boundary", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}
 1134: @cython.boundscheck(False)
 1135: cdef int do_positions_stradle_pbc_boundary(NUMPY_INT_TYPE[:,:] chain_positions, int chain_length):
 1136:     """
 1137:     For a set of positions returns true if the positions straddle a boundary
 1138:     else return false
 1139: 
 1140:     """
 1141: 
 1142:     cdef int pidx
 1143:     cdef int p1_x, p2_x, p1_y, p2_y, p1_z, p2_z
 1144: 
 1145: 
 1146: 
+1147:     for pidx in range(0, chain_length-1):
  __pyx_t_1 = (__pyx_v_chain_length - 1);
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_pidx = __pyx_t_3;
+1148:         p1_x = chain_positions[pidx,0]
    __pyx_t_4 = __pyx_v_pidx;
    __pyx_t_5 = 0;
    __pyx_v_p1_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_chain_positions.data + __pyx_t_4 * __pyx_v_chain_positions.strides[0]) ) + __pyx_t_5 * __pyx_v_chain_positions.strides[1]) )));
+1149:         p2_x = chain_positions[pidx+1,0]
    __pyx_t_5 = (__pyx_v_pidx + 1);
    __pyx_t_4 = 0;
    __pyx_v_p2_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_chain_positions.data + __pyx_t_5 * __pyx_v_chain_positions.strides[0]) ) + __pyx_t_4 * __pyx_v_chain_positions.strides[1]) )));
 1150: 
+1151:         p1_y = chain_positions[pidx,1]
    __pyx_t_4 = __pyx_v_pidx;
    __pyx_t_5 = 1;
    __pyx_v_p1_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_chain_positions.data + __pyx_t_4 * __pyx_v_chain_positions.strides[0]) ) + __pyx_t_5 * __pyx_v_chain_positions.strides[1]) )));
+1152:         p2_y = chain_positions[pidx+1,1]
    __pyx_t_5 = (__pyx_v_pidx + 1);
    __pyx_t_4 = 1;
    __pyx_v_p2_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_chain_positions.data + __pyx_t_5 * __pyx_v_chain_positions.strides[0]) ) + __pyx_t_4 * __pyx_v_chain_positions.strides[1]) )));
 1153: 
+1154:         p1_z = chain_positions[pidx,2]
    __pyx_t_4 = __pyx_v_pidx;
    __pyx_t_5 = 2;
    __pyx_v_p1_z = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_chain_positions.data + __pyx_t_4 * __pyx_v_chain_positions.strides[0]) ) + __pyx_t_5 * __pyx_v_chain_positions.strides[1]) )));
+1155:         p2_z = chain_positions[pidx+1,2]
    __pyx_t_5 = (__pyx_v_pidx + 1);
    __pyx_t_4 = 2;
    __pyx_v_p2_z = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_chain_positions.data + __pyx_t_5 * __pyx_v_chain_positions.strides[0]) ) + __pyx_t_4 * __pyx_v_chain_positions.strides[1]) )));
 1156: 
+1157:         if abs(p1_x - p2_x) > 1:
    __pyx_t_6 = abs((__pyx_v_p1_x - __pyx_v_p2_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 1157, __pyx_L1_error)
    __pyx_t_7 = (__pyx_t_6 > 1);
    if (__pyx_t_7) {
/* … */
    }
+1158:             return 1
      __pyx_r = 1;
      goto __pyx_L0;
 1159: 
+1160:         if abs(p1_y - p2_y) > 1:
    __pyx_t_6 = abs((__pyx_v_p1_y - __pyx_v_p2_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 1160, __pyx_L1_error)
    __pyx_t_7 = (__pyx_t_6 > 1);
    if (__pyx_t_7) {
/* … */
    }
+1161:             return 1
      __pyx_r = 1;
      goto __pyx_L0;
 1162: 
+1163:         if abs(p1_z - p2_z) > 1:
    __pyx_t_6 = abs((__pyx_v_p1_z - __pyx_v_p2_z)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 1163, __pyx_L1_error)
    __pyx_t_7 = (__pyx_t_6 > 1);
    if (__pyx_t_7) {
/* … */
    }
  }
+1164:             return 1
      __pyx_r = 1;
      goto __pyx_L0;
 1165: 
+1166:     return 0
  __pyx_r = 0;
  goto __pyx_L0;
 1167: 
 1168: 
 1169: 
 1170: ###
 1171: ###        EXTERNAL FUNCTIONS
 1172: ###
 1173: 
+1174: def accept_or_reject_ext(float invtemp, long old_energy, long new_energy):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_13accept_or_reject_ext(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_13accept_or_reject_ext = {"accept_or_reject_ext", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_13accept_or_reject_ext, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_13accept_or_reject_ext(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  float __pyx_v_invtemp;
  long __pyx_v_old_energy;
  long __pyx_v_new_energy;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("accept_or_reject_ext (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_invtemp,&__pyx_mstate_global->__pyx_n_u_old_energy,&__pyx_mstate_global->__pyx_n_u_new_energy,0};
  PyObject* values[3] = {0,0,0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 1174, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  3:
        values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 1174, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  2:
        values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 1174, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1174, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "accept_or_reject_ext", 0) < (0)) __PYX_ERR(0, 1174, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("accept_or_reject_ext", 1, 3, 3, i); __PYX_ERR(0, 1174, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 3)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1174, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 1174, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 1174, __pyx_L3_error)
    }
    __pyx_v_invtemp = __Pyx_PyFloat_AsFloat(values[0]); if (unlikely((__pyx_v_invtemp == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 1174, __pyx_L3_error)
    __pyx_v_old_energy = __Pyx_PyLong_As_long(values[1]); if (unlikely((__pyx_v_old_energy == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1174, __pyx_L3_error)
    __pyx_v_new_energy = __Pyx_PyLong_As_long(values[2]); if (unlikely((__pyx_v_new_energy == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1174, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("accept_or_reject_ext", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 1174, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_AddTraceback("pimms.mega_crank.accept_or_reject_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_12accept_or_reject_ext(__pyx_self, __pyx_v_invtemp, __pyx_v_old_energy, __pyx_v_new_energy);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_12accept_or_reject_ext(CYTHON_UNUSED PyObject *__pyx_self, float __pyx_v_invtemp, long __pyx_v_old_energy, long __pyx_v_new_energy) {
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pimms.mega_crank.accept_or_reject_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_13accept_or_reject_ext, 0, __pyx_mstate_global->__pyx_n_u_accept_or_reject_ext, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[6])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_accept_or_reject_ext, __pyx_t_4) < (0)) __PYX_ERR(0, 1174, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1175:     return accept_or_reject(invtemp, old_energy, new_energy)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_accept_or_reject(__pyx_v_invtemp, __pyx_v_old_energy, __pyx_v_new_energy); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1175, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1175, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;
 1176: 
 1177: 
+1178: def get_random_position_ext(int chain_length):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_15get_random_position_ext(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_15get_random_position_ext = {"get_random_position_ext", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_15get_random_position_ext, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_15get_random_position_ext(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_chain_length;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_random_position_ext (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_chain_length,0};
  PyObject* values[1] = {0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 1178, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1178, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "get_random_position_ext", 0) < (0)) __PYX_ERR(0, 1178, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 1; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("get_random_position_ext", 1, 1, 1, i); __PYX_ERR(0, 1178, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1178, __pyx_L3_error)
    }
    __pyx_v_chain_length = __Pyx_PyLong_As_int(values[0]); if (unlikely((__pyx_v_chain_length == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1178, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_random_position_ext", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1178, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_AddTraceback("pimms.mega_crank.get_random_position_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_14get_random_position_ext(__pyx_self, __pyx_v_chain_length);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_14get_random_position_ext(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_chain_length) {
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pimms.mega_crank.get_random_position_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_15get_random_position_ext, 0, __pyx_mstate_global->__pyx_n_u_get_random_position_ext, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[7])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_get_random_position_ext, __pyx_t_4) < (0)) __PYX_ERR(0, 1178, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1179:     return get_random_position(chain_length)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_get_random_position(__pyx_v_chain_length); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1179, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;
 1180: 
 1181: 
+1182: def randint_ext(int start, int end):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_17randint_ext(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_17randint_ext = {"randint_ext", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_17randint_ext, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_17randint_ext(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_start;
  int __pyx_v_end;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("randint_ext (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_start,&__pyx_mstate_global->__pyx_n_u_end,0};
  PyObject* values[2] = {0,0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 1182, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  2:
        values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 1182, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1182, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "randint_ext", 0) < (0)) __PYX_ERR(0, 1182, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 2; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("randint_ext", 1, 2, 2, i); __PYX_ERR(0, 1182, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1182, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 1182, __pyx_L3_error)
    }
    __pyx_v_start = __Pyx_PyLong_As_int(values[0]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1182, __pyx_L3_error)
    __pyx_v_end = __Pyx_PyLong_As_int(values[1]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1182, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("randint_ext", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 1182, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_AddTraceback("pimms.mega_crank.randint_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_16randint_ext(__pyx_self, __pyx_v_start, __pyx_v_end);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_16randint_ext(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_start, int __pyx_v_end) {
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pimms.mega_crank.randint_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_17randint_ext, 0, __pyx_mstate_global->__pyx_n_u_randint_ext, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[8])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_randint_ext, __pyx_t_4) < (0)) __PYX_ERR(0, 1182, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1183:     return randint(start,end)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pimms_10mega_crank_randint(__pyx_v_start, __pyx_v_end); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1183, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1183, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;
 1184: 
 1185: 
 1186: ##
 1187: ## TESTER FUNCTIONS
 1188: ##
 1189: 
 1190: 
 1191: 
 1192: 
+1193: def randint_tester(int start, int end, int randval):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_19randint_tester(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pimms_10mega_crank_18randint_tester, "\n    returns a random integer between start and end-1 (exclusive\n    of ends\n    This mirrors random.randint's behaviour\n    \n    e.g. start = 0 and end=5 gives one of 0,1,2,3,4,5\n\n    ");
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_19randint_tester = {"randint_tester", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_10mega_crank_19randint_tester, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pimms_10mega_crank_18randint_tester};
static PyObject *__pyx_pw_5pimms_10mega_crank_19randint_tester(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_start;
  int __pyx_v_end;
  int __pyx_v_randval;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("randint_tester (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_SIZE
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_start,&__pyx_mstate_global->__pyx_n_u_end,&__pyx_mstate_global->__pyx_n_u_randval,0};
  PyObject* values[3] = {0,0,0};
    const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
    if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 1193, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  3:
        values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 1193, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  2:
        values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 1193, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  1:
        values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1193, __pyx_L3_error)
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      const Py_ssize_t kwd_pos_args = __pyx_nargs;
      if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "randint_tester", 0) < (0)) __PYX_ERR(0, 1193, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("randint_tester", 1, 3, 3, i); __PYX_ERR(0, 1193, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 3)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1193, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 1193, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 1193, __pyx_L3_error)
    }
    __pyx_v_start = __Pyx_PyLong_As_int(values[0]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1193, __pyx_L3_error)
    __pyx_v_end = __Pyx_PyLong_As_int(values[1]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1193, __pyx_L3_error)
    __pyx_v_randval = __Pyx_PyLong_As_int(values[2]); if (unlikely((__pyx_v_randval == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1193, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("randint_tester", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 1193, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_AddTraceback("pimms.mega_crank.randint_tester", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_10mega_crank_18randint_tester(__pyx_self, __pyx_v_start, __pyx_v_end, __pyx_v_randval);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
    Py_XDECREF(values[__pyx_temp]);
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_18randint_tester(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_start, int __pyx_v_end, int __pyx_v_randval) {
  int __pyx_v_r;
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pimms.mega_crank.randint_tester", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_19randint_tester, 0, __pyx_mstate_global->__pyx_n_u_randint_tester, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[9])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_randint_tester, __pyx_t_4) < (0)) __PYX_ERR(0, 1193, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 1194:     """
 1195:     returns a random integer between start and end-1 (exclusive
 1196:     of ends
 1197:     This mirrors random.randint's behaviour
 1198: 
 1199:     e.g. start = 0 and end=5 gives one of 0,1,2,3,4,5
 1200: 
 1201:     """
+1202:     if start == 0:
  __pyx_t_1 = (__pyx_v_start == 0);
  if (__pyx_t_1) {
/* … */
    goto __pyx_L3;
  }
+1203:         end=end+1
    __pyx_v_end = (__pyx_v_end + 1);
 1204:     else:
+1205:         pass
  /*else*/ {
  }
  __pyx_L3:;
 1206: 
 1207:     # ok so this is kind of inelegant, but the rand()-1 is actually important
 1208:     # if we don'te have this we risk the situation where
+1209:     cdef  int r = start+int((float(randval-1)/float(PRNG_MAX))*(end))
  __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (unlikely(((double)__pyx_v_5pimms_10mega_crank_PRNG_MAX) == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 1209, __pyx_L1_error)
  }
  __pyx_t_3 = PyLong_FromDouble(((((double)(__pyx_v_randval - 1)) / ((double)__pyx_v_5pimms_10mega_crank_PRNG_MAX)) * __pyx_v_end)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyLong_As_int(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_r = __pyx_t_5;
 1210: 
+1211:     return r
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyLong_From_int(__pyx_v_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1211, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;
 1212: 
+1213: def crand_test():
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_21crand_test(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_21crand_test = {"crand_test", (PyCFunction)__pyx_pw_5pimms_10mega_crank_21crand_test, METH_NOARGS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_21crand_test(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("crand_test (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pimms_10mega_crank_20crand_test(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_20crand_test(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pimms.mega_crank.crand_test", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_21crand_test, 0, __pyx_mstate_global->__pyx_n_u_crand_test, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[10])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_crand_test, __pyx_t_4) < (0)) __PYX_ERR(0, 1213, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1214:     return mc_rand()
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyLong_From_int(__pyx_f_5pimms_10mega_crank_mc_rand()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 1215: 
+1216: def RAND_MAX_test():
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_10mega_crank_23RAND_MAX_test(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyMethodDef __pyx_mdef_5pimms_10mega_crank_23RAND_MAX_test = {"RAND_MAX_test", (PyCFunction)__pyx_pw_5pimms_10mega_crank_23RAND_MAX_test, METH_NOARGS, 0};
static PyObject *__pyx_pw_5pimms_10mega_crank_23RAND_MAX_test(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("RAND_MAX_test (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pimms_10mega_crank_22RAND_MAX_test(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_10mega_crank_22RAND_MAX_test(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
/* … */
  __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_10mega_crank_23RAND_MAX_test, 0, __pyx_mstate_global->__pyx_n_u_RAND_MAX_test, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[11])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000
  PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4);
  #endif
  if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_RAND_MAX_test, __pyx_t_4) < (0)) __PYX_ERR(0, 1216, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1217:     return PRNG_MAX
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyLong_From_int(__pyx_v_5pimms_10mega_crank_PRNG_MAX); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 1218: