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_2D.c

+001: ## ...........................................................................
  __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;
 002: ##
 003: ## PIMMS (Polymer Interactions in Multicomponent Mixtures)
 004: ## Author: Alex Holehouse
 005: ## Developed by the Holehouse and Pappu labs
 006: ## Copyright 2015 - 2026
 007: ##
 008: ## ...........................................................................
 009: 
 010: 
+011: 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;
 012: cimport numpy as cnp
+013: 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)
 014: 
 015: cimport cython
+016: 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;
 017: 
+018: from pimms import mega_crank
  {
    PyObject* const __pyx_imported_names[] = {__pyx_mstate_global->__pyx_n_u_mega_crank};
    __pyx_t_1 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_pimms, __pyx_imported_names, 1, NULL, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __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_mega_crank};
    __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, 18, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_imported_names[__pyx_t_10], __pyx_t_5) < (0)) __PYX_ERR(0, 18, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+019: from pimms import random_number
  {
    PyObject* const __pyx_imported_names[] = {__pyx_mstate_global->__pyx_n_u_random_number};
    __pyx_t_1 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_pimms, __pyx_imported_names, 1, NULL, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __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_random_number};
    __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, 19, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_imported_names[__pyx_t_10], __pyx_t_5) < (0)) __PYX_ERR(0, 19, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 020: 
 021: 
 022: #from numpy cimport int16_t as NUMPY_INT16_TYPE
 023: #ctypedef NUMPY_INT16_TYPE  NUMPY_INT_TYPE
 024: #ctypedef cnp.int64_t NUMPY_INT_TYPE_long
 025: 
 026: from pimms.cython_config cimport NUMPY_INT_TYPE
 027: from pimms.cython_config cimport NUMPY_INT_TYPE_long
+028: 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, 28, __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, 28, __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, 28, __pyx_L1_error)
        break;
        default:;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 029: 
 030: # RNG is delegated to mega_crank (splitmix64); see mega_crank.seed_C_rand /
 031: # randint_ext / accept_or_reject_ext.
 032: 
 033: ## Define high performance local min and max functions...
 034: ##
 035: 
+036: cdef inline int int_max(int a, int b): return a if a >= b else b
static CYTHON_INLINE int __pyx_f_5pimms_13mega_crank_2D_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;
}
+037: cdef inline int int_min(int a, int b): return a if a <= b else b
static CYTHON_INLINE int __pyx_f_5pimms_13mega_crank_2D_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;
}
 038: 
 039: 
 040: #-----------------------------------------------------------------
 041: #
+042: def update_position_2D(NUMPY_INT_TYPE[:] old_position, NUMPY_INT_TYPE[:,:]  grid, NUMPY_INT_TYPE x_off, NUMPY_INT_TYPE y_off, NUMPY_INT_TYPE XDIM, NUMPY_INT_TYPE YDIM):
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_13mega_crank_2D_1update_position_2D(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_13mega_crank_2D_1update_position_2D = {"update_position_2D", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_13mega_crank_2D_1update_position_2D, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_13mega_crank_2D_1update_position_2D(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_XDIM;
  __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_YDIM;
  #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_2D (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_XDIM,&__pyx_mstate_global->__pyx_n_u_YDIM,0};
  PyObject* values[6] = {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, 42, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case  6:
        values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 42, __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, 42, __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, 42, __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, 42, __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, 42, __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, 42, __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_2D", 0) < (0)) __PYX_ERR(0, 42, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 6; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("update_position_2D", 1, 6, 6, i); __PYX_ERR(0, 42, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 6)) {
      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, 42, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 42, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 42, __pyx_L3_error)
      values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 42, __pyx_L3_error)
      values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 42, __pyx_L3_error)
      values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 42, __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, 42, __pyx_L3_error)
    __pyx_v_grid = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_grid.memview)) __PYX_ERR(0, 42, __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, 42, __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, 42, __pyx_L3_error)
    __pyx_v_XDIM = __Pyx_PyLong_As_npy_int32(values[4]); if (unlikely((__pyx_v_XDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L3_error)
    __pyx_v_YDIM = __Pyx_PyLong_As_npy_int32(values[5]); if (unlikely((__pyx_v_YDIM == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("update_position_2D", 1, 6, 6, __pyx_nargs); __PYX_ERR(0, 42, __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_2D.update_position_2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_13mega_crank_2D_update_position_2D(__pyx_self, __pyx_v_old_position, __pyx_v_grid, __pyx_v_x_off, __pyx_v_y_off, __pyx_v_XDIM, __pyx_v_YDIM);
  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_13mega_crank_2D_update_position_2D(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_XDIM, __pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE __pyx_v_YDIM) {
  PyArrayObject *__pyx_v_new_position = 0;
  int __pyx_v_local_x;
  int __pyx_v_local_y;
  __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_2D.update_position_2D", __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_13mega_crank_2D_1update_position_2D, 0, __pyx_mstate_global->__pyx_n_u_update_position_2D, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank_2D, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 42, __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_2D, __pyx_t_4) < (0)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 043: 
+044:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position = np.zeros([2], 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, 44, __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, 44, __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, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 44, __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, 44, __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, 44, __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, 44, __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, 44, __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, 44, __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, 44, __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;
 045: 
+046:     cdef int local_x = pbc_correction(old_position[0] + x_off, XDIM)
  __pyx_t_8 = 0;
  __pyx_t_9 = -1;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_old_position.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 0;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_old_position.shape[0])) __pyx_t_9 = 0;
  if (unlikely(__pyx_t_9 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_9);
    __PYX_ERR(0, 46, __pyx_L1_error)
  }
  __pyx_t_9 = __pyx_f_5pimms_13mega_crank_2D_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, 46, __pyx_L1_error)
  __pyx_v_local_x = __pyx_t_9;
+047:     cdef int local_y = pbc_correction(old_position[1] + y_off, YDIM)
  __pyx_t_8 = 1;
  __pyx_t_9 = -1;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_old_position.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 0;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_old_position.shape[0])) __pyx_t_9 = 0;
  if (unlikely(__pyx_t_9 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_9);
    __PYX_ERR(0, 47, __pyx_L1_error)
  }
  __pyx_t_9 = __pyx_f_5pimms_13mega_crank_2D_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, 47, __pyx_L1_error)
  __pyx_v_local_y = __pyx_t_9;
 048: 
+049:     if grid[local_x, local_y] > 0:
  __pyx_t_8 = __pyx_v_local_x;
  __pyx_t_10 = __pyx_v_local_y;
  __pyx_t_9 = -1;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_grid.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 0;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_grid.shape[0])) __pyx_t_9 = 0;
  if (__pyx_t_10 < 0) {
    __pyx_t_10 += __pyx_v_grid.shape[1];
    if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 1;
  } else if (unlikely(__pyx_t_10 >= __pyx_v_grid.shape[1])) __pyx_t_9 = 1;
  if (unlikely(__pyx_t_9 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_9);
    __PYX_ERR(0, 49, __pyx_L1_error)
  }
  __pyx_t_11 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_8 * __pyx_v_grid.strides[0]) ) + __pyx_t_10 * __pyx_v_grid.strides[1]) ))) > 0);
  if (__pyx_t_11) {
/* … */
    goto __pyx_L3;
  }
 050:         # fail
+051:         new_position[0] = -1
    __pyx_t_10 = 0;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_pybuffernd_new_position.diminfo[0].shape;
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 51, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_new_position.diminfo[0].strides) = -1;
 052:     # hard sphere clash
 053:     else:
 054:         # success
+055:         new_position[0] = local_x
  /*else*/ {
    __pyx_t_10 = 0;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_pybuffernd_new_position.diminfo[0].shape;
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 55, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_x;
+056:         new_position[1] = local_y
    __pyx_t_10 = 1;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_pybuffernd_new_position.diminfo[0].shape;
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 56, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_new_position.diminfo[0].strides) = __pyx_v_local_y;
  }
  __pyx_L3:;
 057: 
+058:     return (new_position)
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_new_position);
  __pyx_r = ((PyObject *)__pyx_v_new_position);
  goto __pyx_L0;
 059: 
 060: 
 061: #-----------------------------------------------------------------
 062: #
+063: def mega_crank_2D(NUMPY_INT_TYPE[:,:] grid,
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_13mega_crank_2D_3mega_crank_2D(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_13mega_crank_2D_2mega_crank_2D, "\n    Some explanation is in order re: what the input variables here are\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    interaction_table - lookup table for the short range interactions of 2 beads\n    \n    interaction_table - lookup table for the long range interactions of 2 beads\n\n    angle_lookup - lookup table for angle energies \n\n    energy - current energy\n\n    invtemp - current inverse temperature\n\n    nsteps - number of steps to perform\n\n    passed_seeed - a random seed generated by the main program, ensures reproducibility\n\n\n    ");
static PyMethodDef __pyx_mdef_5pimms_13mega_crank_2D_3mega_crank_2D = {"mega_crank_2D", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_13mega_crank_2D_3mega_crank_2D, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pimms_13mega_crank_2D_2mega_crank_2D};
static PyObject *__pyx_pw_5pimms_13mega_crank_2D_3mega_crank_2D(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_2D (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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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, 63, __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_2D", 0) < (0)) __PYX_ERR(0, 63, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 13; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("mega_crank_2D", 1, 13, 13, i); __PYX_ERR(0, 63, __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, 63, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[11] = __Pyx_ArgRef_FASTCALL(__pyx_args, 11);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[11])) __PYX_ERR(0, 63, __pyx_L3_error)
      values[12] = __Pyx_ArgRef_FASTCALL(__pyx_args, 12);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[12])) __PYX_ERR(0, 63, __pyx_L3_error)
    }
    __pyx_v_grid = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_grid.memview)) __PYX_ERR(0, 63, __pyx_L3_error)
    __pyx_v_type_grid = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_type_grid.memview)) __PYX_ERR(0, 64, __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, 65, __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, 66, __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, 67, __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, 68, __pyx_L3_error)
    __pyx_v_angle_lookup = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsdsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[6], PyBUF_WRITABLE); if (unlikely(!__pyx_v_angle_lookup.memview)) __PYX_ERR(0, 69, __pyx_L3_error)
    __pyx_v_energy = __Pyx_PyLong_As_long(values[7]); if (unlikely((__pyx_v_energy == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 70, __pyx_L3_error)
    __pyx_v_invtemp = __Pyx_PyFloat_AsFloat(values[8]); if (unlikely((__pyx_v_invtemp == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L3_error)
    __pyx_v_nsteps = __Pyx_PyLong_As_int(values[9]); if (unlikely((__pyx_v_nsteps == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 72, __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, 73, __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, 74, __pyx_L3_error)
    __pyx_v_hardwall = __Pyx_PyLong_As_int(values[12]); if (unlikely((__pyx_v_hardwall == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 75, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("mega_crank_2D", 1, 13, 13, __pyx_nargs); __PYX_ERR(0, 63, __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_2D.mega_crank_2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_13mega_crank_2D_2mega_crank_2D(__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_13mega_crank_2D_2mega_crank_2D(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) {
  int __pyx_v_i;
  int __pyx_v_bead_index;
  int __pyx_v_accepted_moves;
  int __pyx_v_XDIM;
  int __pyx_v_YDIM;
  CYTHON_UNUSED int __pyx_v_num_beads;
  int __pyx_v_bead_flag;
  int __pyx_v_move_success;
  int __pyx_v_old_x;
  int __pyx_v_old_y;
  int __pyx_v_lr_vs_sr;
  int __pyx_v_bead_id;
  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_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_15, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_19, 1);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  __Pyx_XDECREF(__pyx_t_23);
  __Pyx_XDECREF(__pyx_t_24);
  __Pyx_XDECREF(__pyx_t_25);
  __Pyx_XDECREF(__pyx_t_26);
  { 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_2D.mega_crank_2D", __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_13mega_crank_2D_3mega_crank_2D, 0, __pyx_mstate_global->__pyx_n_u_mega_crank_2D, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank_2D, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 63, __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_2D, __pyx_t_4) < (0)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 064:                   NUMPY_INT_TYPE[:,:] type_grid,
 065:                   NUMPY_INT_TYPE_long[:,:] idx_to_bead,
 066:                   NUMPY_INT_TYPE[:,:] interaction_table,
 067:                   NUMPY_INT_TYPE[:,:] LR_interaction_table,
 068:                   NUMPY_INT_TYPE[:,:] SLR_interaction_table,
 069:                   NUMPY_INT_TYPE[:,:,:,:,:]  angle_lookup,
 070:                   long energy,
 071:                   float invtemp,
 072:                   int nsteps,
 073:                   NUMPY_INT_TYPE_long[:] bead_selector,
 074:                   int passed_seed,
 075:                   int hardwall):
 076: 
 077:     """
 078:     Some explanation is in order re: what the input variables here are
 079: 
 080:     grid - the main lattice grid
 081: 
 082:     type_grid - mirrors the lattice grid but the integers represent residue types not chain IDs
 083: 
 084:     interaction_table - lookup table for the short range interactions of 2 beads
 085: 
 086:     interaction_table - lookup table for the long range interactions of 2 beads
 087: 
 088:     angle_lookup - lookup table for angle energies
 089: 
 090:     energy - current energy
 091: 
 092:     invtemp - current inverse temperature
 093: 
 094:     nsteps - number of steps to perform
 095: 
 096:     passed_seeed - a random seed generated by the main program, ensures reproducibility
 097: 
 098: 
 099:     """
 100:     # set randomseed (shared splitmix64 state lives in mega_crank)
+101:     mega_crank.seed_C_rand(passed_seed)
  __pyx_t_2 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_mega_crank); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_seed_C_rand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyLong_From_int(__pyx_v_passed_seed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = 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_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_3};
    __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 102: 
 103:     cdef int i, bead_index;
 104:     cdef int accepted_moves;
 105:     cdef int XDIM, YDIM;
 106:     cdef int num_beads;
 107:     cdef int bead_flag, move_success
 108:     cdef int old_x, old_y
 109:     cdef int lr_vs_sr, bead_id
 110:     cdef long delta_energy, delta_angle_energy
 111: 
+112:     accepted_moves = 0
  __pyx_v_accepted_moves = 0;
 113: 
+114:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] position_triptic = np.zeros([3, 2], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_4 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __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, 114, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 1, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 114, __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, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    assert(__pyx_t_4);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
    __pyx_t_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_t_3};
    __pyx_t_7 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_6, __pyx_t_7, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 114, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_2, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __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, 114, __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, 114, __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;
+115:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] three_position_holder = np.zeros([3, 2], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_2 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyList_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 115, __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, 115, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_7, 1, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 115, __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, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    assert(__pyx_t_2);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_6, __pyx__function);
    __pyx_t_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, __pyx_t_7};
    __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 115, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_3, __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 115, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_6, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __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, 115, __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, 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, 115, __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;
+116:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] two_position_holder = np.zeros([2, 2], dtype=NUMPY_INT_TYPE_PYTHON)
  __pyx_t_6 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_4, 0, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 116, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_4, 1, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 116, __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, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
    assert(__pyx_t_6);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
    __pyx_t_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_6, __pyx_t_4};
    __pyx_t_2 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_7, __pyx_t_2, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 116, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_3, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_2);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __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, 116, __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, 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, 116, __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;
 117: 
+118:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] old_position = np.zeros([2], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_3 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __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, 118, __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, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = 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_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_3, __pyx_t_2};
    __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 118, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_4, __pyx_t_6, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 118, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_7, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __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, 118, __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, 118, __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;
+119:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] anchor_bead = np.zeros([2], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_7 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyList_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_6, 0, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 119, __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, 119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    assert(__pyx_t_7);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
    __pyx_t_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_7, __pyx_t_6};
    __pyx_t_3 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 119, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_2, __pyx_t_3, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 119, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __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, 119, __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, 119, __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;
+120:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] new_position = np.zeros([2], dtype = NUMPY_INT_TYPE_PYTHON)
  __pyx_t_4 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 120, __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, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    assert(__pyx_t_4);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
    __pyx_t_5 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_t_3};
    __pyx_t_7 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_6, __pyx_t_7, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 120, __pyx_L1_error)
    __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_2, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 120, __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, 120, __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, 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, 120, __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;
 121: 
 122: 
+123:     XDIM = grid.shape[0]
  __pyx_v_XDIM = (__pyx_v_grid.shape[0]);
+124:     YDIM = grid.shape[1]
  __pyx_v_YDIM = (__pyx_v_grid.shape[1]);
 125: 
 126:     # get the number of beads
+127:     num_beads = len(idx_to_bead)
  __pyx_t_8 = __Pyx_MemoryView_Len(__pyx_v_idx_to_bead); 
  __pyx_v_num_beads = __pyx_t_8;
 128: 
 129:     # angle short-circuit
+130:     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;
 131: 
 132:         # select random a bead from the preallocated bead_selector
+133:         bead_index   = bead_selector[i]
    __pyx_t_12 = __pyx_v_i;
    __pyx_t_13 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_bead_selector.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_bead_selector.shape[0])) __pyx_t_13 = 0;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 133, __pyx_L1_error)
    }
    __pyx_v_bead_index = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=0 */ (__pyx_v_bead_selector.data + __pyx_t_12 * __pyx_v_bead_selector.strides[0]) )));
 134: 
 135:         # get position
+136:         bead_flag = idx_to_bead[bead_index,0]
    __pyx_t_12 = __pyx_v_bead_index;
    __pyx_t_14 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_v_idx_to_bead.shape[1];
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 136, __pyx_L1_error)
    }
    __pyx_v_bead_flag = (*((__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_14 * __pyx_v_idx_to_bead.strides[1]) )));
+137:         old_x = idx_to_bead[bead_index,5]
    __pyx_t_14 = __pyx_v_bead_index;
    __pyx_t_12 = 5;
    __pyx_t_13 = -1;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_v_idx_to_bead.shape[0];
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_idx_to_bead.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 137, __pyx_L1_error)
    }
    __pyx_v_old_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_14 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+138:         old_y = idx_to_bead[bead_index,6]
    __pyx_t_12 = __pyx_v_bead_index;
    __pyx_t_14 = 6;
    __pyx_t_13 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_v_idx_to_bead.shape[1];
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 138, __pyx_L1_error)
    }
    __pyx_v_old_y = (*((__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_14 * __pyx_v_idx_to_bead.strides[1]) )));
+139:         lr_vs_sr = idx_to_bead[bead_index,1]
    __pyx_t_14 = __pyx_v_bead_index;
    __pyx_t_12 = 1;
    __pyx_t_13 = -1;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_v_idx_to_bead.shape[0];
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_idx_to_bead.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 139, __pyx_L1_error)
    }
    __pyx_v_lr_vs_sr = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_14 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+140:         bead_id = idx_to_bead[bead_index,4]
    __pyx_t_12 = __pyx_v_bead_index;
    __pyx_t_14 = 4;
    __pyx_t_13 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_v_idx_to_bead.shape[1];
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 140, __pyx_L1_error)
    }
    __pyx_v_bead_id = (*((__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_14 * __pyx_v_idx_to_bead.strides[1]) )));
 141: 
+142:         old_position[0] = old_x
    __pyx_t_14 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_pybuffernd_old_position.diminfo[0].shape;
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_14 >= __pyx_pybuffernd_old_position.diminfo[0].shape)) __pyx_t_13 = 0;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 142, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_old_position.diminfo[0].strides) = __pyx_v_old_x;
+143:         old_position[1] = old_y
    __pyx_t_14 = 1;
    __pyx_t_13 = -1;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_pybuffernd_old_position.diminfo[0].shape;
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_14 >= __pyx_pybuffernd_old_position.diminfo[0].shape)) __pyx_t_13 = 0;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 143, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_old_position.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_old_position.diminfo[0].strides) = __pyx_v_old_y;
 144: 
 145:         # ------------------------------------------------------------
 146:         # if single bead (beadflag == 0)
+147:         if bead_flag == 0:
    switch (__pyx_v_bead_flag) {
      case 0:
/* … */
      break;
      case 1:
+148:             move_success = single_bead_crank_2D(old_position, grid, XDIM, YDIM, new_position)
      __pyx_t_15 = __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_15.memview)) __PYX_ERR(0, 148, __pyx_L1_error)
      __pyx_t_16 = __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_16.memview)) __PYX_ERR(0, 148, __pyx_L1_error)
      __pyx_t_13 = __pyx_f_5pimms_13mega_crank_2D_single_bead_crank_2D(__pyx_t_15, __pyx_v_grid, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_t_16); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error)
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_15, 1);
      __pyx_t_15.memview = NULL; __pyx_t_15.data = NULL;
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
      __pyx_t_16.memview = NULL; __pyx_t_16.data = NULL;
      __pyx_v_move_success = __pyx_t_13;
 149: 
 150:         # ------------------------------------------------------------
 151:         # if N-terminal bead (beadflag == 1)
+152:         elif bead_flag == 1:
      break;
      case 3:
+153:             anchor_bead[0] = idx_to_bead[bead_index+1,5]
      __pyx_t_14 = (__pyx_v_bead_index + 1);
      __pyx_t_12 = 5;
      __pyx_t_13 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 153, __pyx_L1_error)
      }
      __pyx_t_17 = 0;
      __pyx_t_13 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_anchor_bead.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_anchor_bead.diminfo[0].shape)) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 153, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_17, __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_14 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+154:             anchor_bead[1] = idx_to_bead[bead_index+1,6]
      __pyx_t_12 = (__pyx_v_bead_index + 1);
      __pyx_t_14 = 6;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 154, __pyx_L1_error)
      }
      __pyx_t_17 = 1;
      __pyx_t_13 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_anchor_bead.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_anchor_bead.diminfo[0].shape)) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 154, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_17, __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_14 * __pyx_v_idx_to_bead.strides[1]) )));
 155: 
+156:             move_success = single_bead_crank_2D(anchor_bead, grid, XDIM, YDIM, new_position)
      __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_anchor_bead), PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 156, __pyx_L1_error)
      __pyx_t_15 = __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_15.memview)) __PYX_ERR(0, 156, __pyx_L1_error)
      __pyx_t_13 = __pyx_f_5pimms_13mega_crank_2D_single_bead_crank_2D(__pyx_t_16, __pyx_v_grid, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_t_15); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 156, __pyx_L1_error)
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
      __pyx_t_16.memview = NULL; __pyx_t_16.data = NULL;
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_15, 1);
      __pyx_t_15.memview = NULL; __pyx_t_15.data = NULL;
      __pyx_v_move_success = __pyx_t_13;
 157: 
+158:             if hardwall == 1:
      __pyx_t_18 = (__pyx_v_hardwall == 1);
      if (__pyx_t_18) {
/* … */
      }
+159:                 two_position_holder[0] = new_position
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_two_position_holder), 0, ((PyObject *)__pyx_v_new_position), long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference) < 0))) __PYX_ERR(0, 159, __pyx_L1_error)
+160:                 two_position_holder[1] = anchor_bead
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_two_position_holder), 1, ((PyObject *)__pyx_v_anchor_bead), long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference) < 0))) __PYX_ERR(0, 160, __pyx_L1_error)
+161:                 if do_positions_stradle_pbc_boundary_2D(two_position_holder, 2) == 1:
        __pyx_t_19 = __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_19.memview)) __PYX_ERR(0, 161, __pyx_L1_error)
        __pyx_t_13 = __pyx_f_5pimms_13mega_crank_2D_do_positions_stradle_pbc_boundary_2D(__pyx_t_19, 2); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 161, __pyx_L1_error)
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_19, 1);
        __pyx_t_19.memview = NULL; __pyx_t_19.data = NULL;
        __pyx_t_18 = (__pyx_t_13 == 1);
        if (__pyx_t_18) {
/* … */
        }
+162:                     continue
          goto __pyx_L3_continue;
 163: 
 164:         # ------------------------------------------------------------
 165:         # if C-terminal bead (beadflag == 3)
+166:         elif bead_flag == 3:
      break;
      default:
 167: 
+168:             anchor_bead[0] = idx_to_bead[bead_index-1,5]
      __pyx_t_14 = (__pyx_v_bead_index - 1);
      __pyx_t_12 = 5;
      __pyx_t_13 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 168, __pyx_L1_error)
      }
      __pyx_t_17 = 0;
      __pyx_t_13 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_anchor_bead.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_anchor_bead.diminfo[0].shape)) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 168, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_17, __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_14 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+169:             anchor_bead[1] = idx_to_bead[bead_index-1,6]
      __pyx_t_12 = (__pyx_v_bead_index - 1);
      __pyx_t_14 = 6;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 169, __pyx_L1_error)
      }
      __pyx_t_17 = 1;
      __pyx_t_13 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_anchor_bead.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_anchor_bead.diminfo[0].shape)) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 169, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_anchor_bead.rcbuffer->pybuffer.buf, __pyx_t_17, __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_14 * __pyx_v_idx_to_bead.strides[1]) )));
+170:             move_success = single_bead_crank_2D(anchor_bead, grid, XDIM, YDIM, new_position)
      __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(((PyObject *)__pyx_v_anchor_bead), PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 170, __pyx_L1_error)
      __pyx_t_16 = __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_16.memview)) __PYX_ERR(0, 170, __pyx_L1_error)
      __pyx_t_13 = __pyx_f_5pimms_13mega_crank_2D_single_bead_crank_2D(__pyx_t_15, __pyx_v_grid, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_t_16); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 170, __pyx_L1_error)
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_15, 1);
      __pyx_t_15.memview = NULL; __pyx_t_15.data = NULL;
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
      __pyx_t_16.memview = NULL; __pyx_t_16.data = NULL;
      __pyx_v_move_success = __pyx_t_13;
 171: 
+172:             if hardwall == 1:
      __pyx_t_18 = (__pyx_v_hardwall == 1);
      if (__pyx_t_18) {
/* … */
      }
+173:                 two_position_holder[0] = anchor_bead
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_two_position_holder), 0, ((PyObject *)__pyx_v_anchor_bead), long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference) < 0))) __PYX_ERR(0, 173, __pyx_L1_error)
+174:                 two_position_holder[1] = new_position
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_two_position_holder), 1, ((PyObject *)__pyx_v_new_position), long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference) < 0))) __PYX_ERR(0, 174, __pyx_L1_error)
 175: 
+176:                 if do_positions_stradle_pbc_boundary_2D(two_position_holder,2) == 1:
        __pyx_t_19 = __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_19.memview)) __PYX_ERR(0, 176, __pyx_L1_error)
        __pyx_t_13 = __pyx_f_5pimms_13mega_crank_2D_do_positions_stradle_pbc_boundary_2D(__pyx_t_19, 2); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 176, __pyx_L1_error)
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_19, 1);
        __pyx_t_19.memview = NULL; __pyx_t_19.data = NULL;
        __pyx_t_18 = (__pyx_t_13 == 1);
        if (__pyx_t_18) {
/* … */
        }
+177:                     continue
          goto __pyx_L3_continue;
 178: 
 179:         # ------------------------------------------------------------
 180:         # we're somewhere inside the chain, and beadflag is 2,4,5, or 6
 181:         else:
+182:             position_triptic[0,0] = idx_to_bead[bead_index-1,5]
      __pyx_t_14 = (__pyx_v_bead_index - 1);
      __pyx_t_12 = 5;
      __pyx_t_13 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 182, __pyx_L1_error)
      }
      __pyx_t_17 = 0;
      __pyx_t_20 = 0;
      __pyx_t_13 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_position_triptic.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_position_triptic.diminfo[0].shape)) __pyx_t_13 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_pybuffernd_position_triptic.diminfo[1].shape;
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_pybuffernd_position_triptic.diminfo[1].shape)) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 182, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_17, __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_14 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+183:             position_triptic[0,1] = idx_to_bead[bead_index-1,6]
      __pyx_t_12 = (__pyx_v_bead_index - 1);
      __pyx_t_14 = 6;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 183, __pyx_L1_error)
      }
      __pyx_t_20 = 0;
      __pyx_t_17 = 1;
      __pyx_t_13 = -1;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_pybuffernd_position_triptic.diminfo[0].shape;
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_20 >= __pyx_pybuffernd_position_triptic.diminfo[0].shape)) __pyx_t_13 = 0;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_position_triptic.diminfo[1].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_position_triptic.diminfo[1].shape)) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 183, __pyx_L1_error)
      }
      *__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_17, __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_14 * __pyx_v_idx_to_bead.strides[1]) )));
 184: 
+185:             position_triptic[1,0] = old_x
      __pyx_t_14 = 1;
      __pyx_t_12 = 0;
      __pyx_t_13 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_pybuffernd_position_triptic.diminfo[0].shape;
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_pybuffernd_position_triptic.diminfo[0].shape)) __pyx_t_13 = 0;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_pybuffernd_position_triptic.diminfo[1].shape;
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_position_triptic.diminfo[1].shape)) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 185, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_position_triptic.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = __pyx_v_old_x;
+186:             position_triptic[1,1] = old_y
      __pyx_t_12 = 1;
      __pyx_t_14 = 1;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_pybuffernd_position_triptic.diminfo[0].shape;
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_position_triptic.diminfo[0].shape)) __pyx_t_13 = 0;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_pybuffernd_position_triptic.diminfo[1].shape;
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_14 >= __pyx_pybuffernd_position_triptic.diminfo[1].shape)) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 186, __pyx_L1_error)
      }
      *__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_14, __pyx_pybuffernd_position_triptic.diminfo[1].strides) = __pyx_v_old_y;
 187: 
+188:             position_triptic[2,0] = idx_to_bead[bead_index+1,5]
      __pyx_t_14 = (__pyx_v_bead_index + 1);
      __pyx_t_12 = 5;
      __pyx_t_13 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 188, __pyx_L1_error)
      }
      __pyx_t_17 = 2;
      __pyx_t_20 = 0;
      __pyx_t_13 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_position_triptic.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_position_triptic.diminfo[0].shape)) __pyx_t_13 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_pybuffernd_position_triptic.diminfo[1].shape;
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_pybuffernd_position_triptic.diminfo[1].shape)) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 188, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_position_triptic.rcbuffer->pybuffer.buf, __pyx_t_17, __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_14 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __pyx_v_idx_to_bead.strides[1]) )));
+189:             position_triptic[2,1] = idx_to_bead[bead_index+1,6]
      __pyx_t_12 = (__pyx_v_bead_index + 1);
      __pyx_t_14 = 6;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_idx_to_bead.shape[1];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 189, __pyx_L1_error)
      }
      __pyx_t_20 = 2;
      __pyx_t_17 = 1;
      __pyx_t_13 = -1;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_pybuffernd_position_triptic.diminfo[0].shape;
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_20 >= __pyx_pybuffernd_position_triptic.diminfo[0].shape)) __pyx_t_13 = 0;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_position_triptic.diminfo[1].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_position_triptic.diminfo[1].shape)) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 189, __pyx_L1_error)
      }
      *__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_17, __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_14 * __pyx_v_idx_to_bead.strides[1]) )));
 190: 
 191: 
 192: 
 193:             # normal crank move!
+194:             move_success = crank_it_2D(position_triptic, grid, XDIM, YDIM, new_position)
      __pyx_t_19 = __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_19.memview)) __PYX_ERR(0, 194, __pyx_L1_error)
      __pyx_t_16 = __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_16.memview)) __PYX_ERR(0, 194, __pyx_L1_error)
      __pyx_t_13 = __pyx_f_5pimms_13mega_crank_2D_crank_it_2D(__pyx_t_19, __pyx_v_grid, __pyx_v_XDIM, __pyx_v_YDIM, __pyx_t_16); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 194, __pyx_L1_error)
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_19, 1);
      __pyx_t_19.memview = NULL; __pyx_t_19.data = NULL;
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
      __pyx_t_16.memview = NULL; __pyx_t_16.data = NULL;
      __pyx_v_move_success = __pyx_t_13;
 195: 
+196:             if hardwall == 1:
      __pyx_t_18 = (__pyx_v_hardwall == 1);
      if (__pyx_t_18) {
/* … */
      }
      break;
    }
+197:                 three_position_holder[0] = position_triptic[0]
        __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_position_triptic), 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_three_position_holder), 0, __pyx_t_1, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference) < 0))) __PYX_ERR(0, 197, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+198:                 three_position_holder[1] = new_position
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_three_position_holder), 1, ((PyObject *)__pyx_v_new_position), long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference) < 0))) __PYX_ERR(0, 198, __pyx_L1_error)
+199:                 three_position_holder[2] = position_triptic[2]
        __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_position_triptic), 2, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_three_position_holder), 2, __pyx_t_1, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1, __Pyx_ReferenceSharing_OwnStrongReference) < 0))) __PYX_ERR(0, 199, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 200: 
+201:                 if do_positions_stradle_pbc_boundary_2D(three_position_holder,3) == 1:
        __pyx_t_19 = __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_19.memview)) __PYX_ERR(0, 201, __pyx_L1_error)
        __pyx_t_13 = __pyx_f_5pimms_13mega_crank_2D_do_positions_stradle_pbc_boundary_2D(__pyx_t_19, 3); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 201, __pyx_L1_error)
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_19, 1);
        __pyx_t_19.memview = NULL; __pyx_t_19.data = NULL;
        __pyx_t_18 = (__pyx_t_13 == 1);
        if (__pyx_t_18) {
/* … */
        }
+202:                     continue
          goto __pyx_L3_continue;
 203: 
 204:         # if hardsphere success
+205:         if move_success == 1:
    __pyx_t_18 = (__pyx_v_move_success == 1);
    if (__pyx_t_18) {
/* … */
    }
    __pyx_L3_continue:;
  }
 206: 
+207:             delta_energy = get_energy_change_2D(grid, type_grid, old_position, new_position, lr_vs_sr,  interaction_table, LR_interaction_table, SLR_interaction_table, XDIM, YDIM, hardwall)
      __pyx_t_2 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_get_energy_change_2D); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_grid, 2, (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, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_type_grid, 2, (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_3)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyLong_From_int(__pyx_v_lr_vs_sr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_21 = __pyx_memoryview_fromslice(__pyx_v_interaction_table, 2, (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_21)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_21);
      __pyx_t_22 = __pyx_memoryview_fromslice(__pyx_v_LR_interaction_table, 2, (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_22)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_22);
      __pyx_t_23 = __pyx_memoryview_fromslice(__pyx_v_SLR_interaction_table, 2, (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_23)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_23);
      __pyx_t_24 = __Pyx_PyLong_From_int(__pyx_v_XDIM); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_24);
      __pyx_t_25 = __Pyx_PyLong_From_int(__pyx_v_YDIM); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_25);
      __pyx_t_26 = __Pyx_PyLong_From_int(__pyx_v_hardwall); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_26);
      __pyx_t_5 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
        assert(__pyx_t_2);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_7, __pyx__function);
        __pyx_t_5 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[12] = {__pyx_t_2, __pyx_t_6, __pyx_t_3, ((PyObject *)__pyx_v_old_position), ((PyObject *)__pyx_v_new_position), __pyx_t_4, __pyx_t_21, __pyx_t_22, __pyx_t_23, __pyx_t_24, __pyx_t_25, __pyx_t_26};
        __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_7, __pyx_callargs+__pyx_t_5, (12-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
        __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
        __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
        __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
        __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 207, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __pyx_t_27 = __Pyx_PyLong_As_long(__pyx_t_1); if (unlikely((__pyx_t_27 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 207, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_delta_energy = __pyx_t_27;
+208:             delta_angle_energy = get_angle_energy_change_2D(bead_index, idx_to_bead, new_position, angle_lookup)
      __pyx_t_16 = __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_16.memview)) __PYX_ERR(0, 208, __pyx_L1_error)
      __pyx_t_27 = __pyx_f_5pimms_13mega_crank_2D_get_angle_energy_change_2D(__pyx_v_bead_index, __pyx_v_idx_to_bead, __pyx_t_16, __pyx_v_angle_lookup); if (unlikely(__pyx_t_27 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(0, 208, __pyx_L1_error)
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
      __pyx_t_16.memview = NULL; __pyx_t_16.data = NULL;
      __pyx_v_delta_angle_energy = __pyx_t_27;
 209: 
+210:             if mega_crank.accept_or_reject_ext(invtemp, energy, energy+delta_energy+delta_angle_energy) == 1:
      __pyx_t_7 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_26, __pyx_mstate_global->__pyx_n_u_mega_crank); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_26);
      __pyx_t_25 = __Pyx_PyObject_GetAttrStr(__pyx_t_26, __pyx_mstate_global->__pyx_n_u_accept_or_reject_ext); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_25);
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      __pyx_t_26 = PyFloat_FromDouble(__pyx_v_invtemp); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_26);
      __pyx_t_24 = __Pyx_PyLong_From_long(__pyx_v_energy); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_24);
      __pyx_t_23 = __Pyx_PyLong_From_long(((__pyx_v_energy + __pyx_v_delta_energy) + __pyx_v_delta_angle_energy)); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_23);
      __pyx_t_5 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_25))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_25);
        assert(__pyx_t_7);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_25);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_25, __pyx__function);
        __pyx_t_5 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[4] = {__pyx_t_7, __pyx_t_26, __pyx_t_24, __pyx_t_23};
        __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_25, __pyx_callargs+__pyx_t_5, (4-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
        __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
        __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __pyx_t_18 = (__Pyx_PyLong_BoolEqObjC(__pyx_t_1, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_18 < 0))) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_18) {
/* … */
      }
 211: 
 212:                 # delete from main grid and insert into new position
+213:                 grid[old_x, old_y] = 0
        __pyx_t_14 = __pyx_v_old_x;
        __pyx_t_12 = __pyx_v_old_y;
        __pyx_t_13 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_grid.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_grid.shape[0])) __pyx_t_13 = 0;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_grid.shape[1];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_grid.shape[1])) __pyx_t_13 = 1;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 213, __pyx_L1_error)
        }
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_14 * __pyx_v_grid.strides[0]) ) + __pyx_t_12 * __pyx_v_grid.strides[1]) )) = 0;
 214: 
 215:                 # inert the bead to its new position
+216:                 grid[new_position[0], new_position[1]] = bead_id
        __pyx_t_12 = 0;
        __pyx_t_13 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_pybuffernd_new_position.diminfo[0].shape;
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 216, __pyx_L1_error)
        }
        __pyx_t_14 = 1;
        __pyx_t_13 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_pybuffernd_new_position.diminfo[0].shape;
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 216, __pyx_L1_error)
        }
        __pyx_t_17 = (*__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_20 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_new_position.diminfo[0].strides));
        __pyx_t_13 = -1;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_grid.shape[0];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_grid.shape[0])) __pyx_t_13 = 0;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_grid.shape[1];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_13 = 1;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_grid.shape[1])) __pyx_t_13 = 1;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 216, __pyx_L1_error)
        }
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_17 * __pyx_v_grid.strides[0]) ) + __pyx_t_20 * __pyx_v_grid.strides[1]) )) = __pyx_v_bead_id;
 217: 
 218:                 # set new type grid to old type grid value
+219:                 type_grid[new_position[0], new_position[1]] = type_grid[old_x, old_y]
        __pyx_t_14 = __pyx_v_old_x;
        __pyx_t_12 = __pyx_v_old_y;
        __pyx_t_13 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_type_grid.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_type_grid.shape[0])) __pyx_t_13 = 0;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_type_grid.shape[1];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_type_grid.shape[1])) __pyx_t_13 = 1;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 219, __pyx_L1_error)
        }
        __pyx_t_20 = 0;
        __pyx_t_13 = -1;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_pybuffernd_new_position.diminfo[0].shape;
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_20 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 219, __pyx_L1_error)
        }
        __pyx_t_17 = 1;
        __pyx_t_13 = -1;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_pybuffernd_new_position.diminfo[0].shape;
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 219, __pyx_L1_error)
        }
        __pyx_t_28 = (*__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));
        __pyx_t_29 = (*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_new_position.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_new_position.diminfo[0].strides));
        __pyx_t_13 = -1;
        if (__pyx_t_28 < 0) {
          __pyx_t_28 += __pyx_v_type_grid.shape[0];
          if (unlikely(__pyx_t_28 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_28 >= __pyx_v_type_grid.shape[0])) __pyx_t_13 = 0;
        if (__pyx_t_29 < 0) {
          __pyx_t_29 += __pyx_v_type_grid.shape[1];
          if (unlikely(__pyx_t_29 < 0)) __pyx_t_13 = 1;
        } else if (unlikely(__pyx_t_29 >= __pyx_v_type_grid.shape[1])) __pyx_t_13 = 1;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 219, __pyx_L1_error)
        }
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_28 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_29 * __pyx_v_type_grid.strides[1]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_14 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_12 * __pyx_v_type_grid.strides[1]) )));
 220: 
 221:                 # zero out old position on type grid
+222:                 type_grid[old_x, old_y] = 0
        __pyx_t_12 = __pyx_v_old_x;
        __pyx_t_14 = __pyx_v_old_y;
        __pyx_t_13 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_type_grid.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_type_grid.shape[0])) __pyx_t_13 = 0;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_type_grid.shape[1];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 1;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_type_grid.shape[1])) __pyx_t_13 = 1;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 222, __pyx_L1_error)
        }
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_12 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_14 * __pyx_v_type_grid.strides[1]) )) = 0;
 223: 
 224:                 # IMPORTANT!!! This change *MUST* be done last as the old_position is actually a reference
 225:                 # to chain_position[bead_index] so changing it BEFORE hand changes the old_position variable and
 226:                 # breaks everything
+227:                 idx_to_bead[bead_index,5] = new_position[0]
        __pyx_t_14 = 0;
        __pyx_t_13 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_pybuffernd_new_position.diminfo[0].shape;
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 227, __pyx_L1_error)
        }
        __pyx_t_12 = __pyx_v_bead_index;
        __pyx_t_17 = 5;
        __pyx_t_13 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_idx_to_bead.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_idx_to_bead.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 227, __pyx_L1_error)
        }
        *((__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_17 * __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_14, __pyx_pybuffernd_new_position.diminfo[0].strides));
+228:                 idx_to_bead[bead_index,6] = new_position[1]
        __pyx_t_14 = 1;
        __pyx_t_13 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_pybuffernd_new_position.diminfo[0].shape;
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_pybuffernd_new_position.diminfo[0].shape)) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 228, __pyx_L1_error)
        }
        __pyx_t_17 = __pyx_v_bead_index;
        __pyx_t_12 = 6;
        __pyx_t_13 = -1;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_idx_to_bead.shape[0];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_idx_to_bead.shape[0])) __pyx_t_13 = 0;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_idx_to_bead.shape[1];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_idx_to_bead.shape[1])) __pyx_t_13 = 1;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 228, __pyx_L1_error)
        }
        *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE_long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_idx_to_bead.data + __pyx_t_17 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_12 * __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_14, __pyx_pybuffernd_new_position.diminfo[0].strides));
 229: 
 230: 
+231:                 energy = energy + delta_energy + delta_angle_energy
        __pyx_v_energy = ((__pyx_v_energy + __pyx_v_delta_energy) + __pyx_v_delta_angle_energy);
+232:                 accepted_moves = accepted_moves + 1
        __pyx_v_accepted_moves = (__pyx_v_accepted_moves + 1);
 233: 
 234: 
+235:     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, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_25 = __Pyx_PyLong_From_int(__pyx_v_accepted_moves); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_25);
  __pyx_t_23 = PyTuple_New(2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_23);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_23, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 235, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_25);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_23, 1, __pyx_t_25) != (0)) __PYX_ERR(0, 235, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_25 = 0;
  __pyx_r = __pyx_t_23;
  __pyx_t_23 = 0;
  goto __pyx_L0;
 236: 
 237: 
 238: 
 239: # --------------------------------------------------------------------------------------------------------
 240: #
 241: #
+242: cdef int crank_it_2D(NUMPY_INT_TYPE[:,:] position_triptic,
static int __pyx_f_5pimms_13mega_crank_2D_crank_it_2D(__Pyx_memviewslice __pyx_v_position_triptic, __Pyx_memviewslice __pyx_v_grid, int __pyx_v_XDIM, int __pyx_v_YDIM, __Pyx_memviewslice __pyx_v_new_position) {
  int __pyx_v_N_side_x;
  int __pyx_v_N_side_y;
  int __pyx_v_C_side_x;
  int __pyx_v_C_side_y;
  int __pyx_v_x_min;
  int __pyx_v_x_max;
  int __pyx_v_y_min;
  int __pyx_v_y_max;
  int __pyx_v_local_x;
  int __pyx_v_local_y;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __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_AddTraceback("pimms.mega_crank_2D.crank_it_2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 243:                      NUMPY_INT_TYPE[:,:] grid,
 244:                      int XDIM,
 245:                      int YDIM,
 246:                      NUMPY_INT_TYPE[:] new_position):
 247:     """
 248:     Perform crankshaft move!
 249: 
 250:     Returns a tuple of success and the PBC corrected posistion
 251: 
 252:     """
 253: 
 254:     cdef int N_side_x, N_side_y, C_side_x, C_side_y;
 255:     cdef int x_min, x_max, y_min, y_max
 256:     # extract out x and y positions and perform a series of PBC corrections as needed
+257:     N_side_x = position_triptic[0,0]
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_position_triptic.shape[0])) __pyx_t_3 = 0;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 1;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_position_triptic.shape[1])) __pyx_t_3 = 1;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 257, __pyx_L1_error)
  }
  __pyx_v_N_side_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_1 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_2 * __pyx_v_position_triptic.strides[1]) )));
+258:     N_side_y = position_triptic[0,1]
  __pyx_t_2 = 0;
  __pyx_t_1 = 1;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_position_triptic.shape[0])) __pyx_t_3 = 0;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_3 = 1;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_position_triptic.shape[1])) __pyx_t_3 = 1;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 258, __pyx_L1_error)
  }
  __pyx_v_N_side_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_2 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_1 * __pyx_v_position_triptic.strides[1]) )));
 259: 
+260:     C_side_x = position_triptic[2,0]
  __pyx_t_1 = 2;
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_position_triptic.shape[0])) __pyx_t_3 = 0;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 1;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_position_triptic.shape[1])) __pyx_t_3 = 1;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 260, __pyx_L1_error)
  }
  __pyx_v_C_side_x = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_1 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_2 * __pyx_v_position_triptic.strides[1]) )));
+261:     C_side_y = position_triptic[2,1]
  __pyx_t_2 = 2;
  __pyx_t_1 = 1;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_position_triptic.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_position_triptic.shape[0])) __pyx_t_3 = 0;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_position_triptic.shape[1];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_3 = 1;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_position_triptic.shape[1])) __pyx_t_3 = 1;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 261, __pyx_L1_error)
  }
  __pyx_v_C_side_y = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_position_triptic.data + __pyx_t_2 * __pyx_v_position_triptic.strides[0]) ) + __pyx_t_1 * __pyx_v_position_triptic.strides[1]) )));
 262: 
 263:     ## Periodicity fix 1
 264:     # move into a non-periodic space just for now
+265:     if abs(N_side_x - C_side_x) > 2:
  __pyx_t_3 = abs((__pyx_v_N_side_x - __pyx_v_C_side_x)); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 265, __pyx_L1_error)
  __pyx_t_4 = (__pyx_t_3 > 2);
  if (__pyx_t_4) {
/* … */
  }
+266:         if N_side_x > C_side_x:
    __pyx_t_4 = (__pyx_v_N_side_x > __pyx_v_C_side_x);
    if (__pyx_t_4) {
/* … */
      goto __pyx_L4;
    }
+267:             C_side_x = C_side_x + XDIM
      __pyx_v_C_side_x = (__pyx_v_C_side_x + __pyx_v_XDIM);
 268:         else:
+269:             N_side_x = N_side_x + XDIM
    /*else*/ {
      __pyx_v_N_side_x = (__pyx_v_N_side_x + __pyx_v_XDIM);
    }
    __pyx_L4:;
 270: 
+271:     if abs(N_side_y - C_side_y) > 2:
  __pyx_t_3 = abs((__pyx_v_N_side_y - __pyx_v_C_side_y)); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 271, __pyx_L1_error)
  __pyx_t_4 = (__pyx_t_3 > 2);
  if (__pyx_t_4) {
/* … */
  }
+272:         if N_side_y > C_side_y:
    __pyx_t_4 = (__pyx_v_N_side_y > __pyx_v_C_side_y);
    if (__pyx_t_4) {
/* … */
      goto __pyx_L6;
    }
+273:             C_side_y = C_side_y + YDIM
      __pyx_v_C_side_y = (__pyx_v_C_side_y + __pyx_v_YDIM);
 274:         else:
+275:             N_side_y = N_side_y + YDIM
    /*else*/ {
      __pyx_v_N_side_y = (__pyx_v_N_side_y + __pyx_v_YDIM);
    }
    __pyx_L6:;
 276: 
 277:     # get smallest/largest possible new x value
+278:     x_min = int_max(N_side_x-1, C_side_x-1)
  __pyx_t_3 = __pyx_f_5pimms_13mega_crank_2D_int_max((__pyx_v_N_side_x - 1), (__pyx_v_C_side_x - 1)); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 278, __pyx_L1_error)
  __pyx_v_x_min = __pyx_t_3;
+279:     x_max = int_min(N_side_x+1, C_side_x+1)
  __pyx_t_3 = __pyx_f_5pimms_13mega_crank_2D_int_min((__pyx_v_N_side_x + 1), (__pyx_v_C_side_x + 1)); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 279, __pyx_L1_error)
  __pyx_v_x_max = __pyx_t_3;
 280: 
 281:     # get smallest/largest possible new y value
+282:     y_min = int_max(N_side_y-1, C_side_y-1)
  __pyx_t_3 = __pyx_f_5pimms_13mega_crank_2D_int_max((__pyx_v_N_side_y - 1), (__pyx_v_C_side_y - 1)); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 282, __pyx_L1_error)
  __pyx_v_y_min = __pyx_t_3;
+283:     y_max = int_min(N_side_y+1, C_side_y+1)
  __pyx_t_3 = __pyx_f_5pimms_13mega_crank_2D_int_min((__pyx_v_N_side_y + 1), (__pyx_v_C_side_y + 1)); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 283, __pyx_L1_error)
  __pyx_v_y_max = __pyx_t_3;
 284: 
+285:     cdef int local_x = pbc_correction((x_min + mega_crank.randint_ext(1, (x_max - x_min + 1)) - 1 ) , XDIM);
  __pyx_t_5 = __Pyx_PyLong_From_int(__pyx_v_x_min); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_mega_crank); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_randint_ext); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyLong_From_long(((__pyx_v_x_max - __pyx_v_x_min) + 1)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_10 = 1;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
    assert(__pyx_t_7);
    PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_9);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx__function);
    __Pyx_DECREF_SET(__pyx_t_9, __pyx__function);
    __pyx_t_10 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_mstate_global->__pyx_int_1, __pyx_t_8};
    __pyx_t_6 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_9, __pyx_callargs+__pyx_t_10, (3-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__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;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 285, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
  }
  __pyx_t_9 = PyNumber_Add(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyLong_SubtractObjC(__pyx_t_9, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_3 = __Pyx_PyLong_As_int(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 285, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_11 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction(__pyx_t_3, __pyx_v_XDIM); if (unlikely(__pyx_t_11 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 285, __pyx_L1_error)
  __pyx_v_local_x = __pyx_t_11;
+286:     cdef int local_y = pbc_correction((y_min + mega_crank.randint_ext(1, (y_max - y_min + 1)) - 1 ) , YDIM)
  __pyx_t_6 = __Pyx_PyLong_From_int(__pyx_v_y_min); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = NULL;
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_mega_crank); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_randint_ext); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyLong_From_long(((__pyx_v_y_max - __pyx_v_y_min) + 1)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_10 = 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_10 = 0;
  }
  #endif
  {
    PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_mstate_global->__pyx_int_1, __pyx_t_8};
    __pyx_t_9 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_7, __pyx_callargs+__pyx_t_10, (3-__pyx_t_10) | (__pyx_t_10*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 286, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
  }
  __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyLong_SubtractObjC(__pyx_t_7, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_11 = __Pyx_PyLong_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 286, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_3 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction(__pyx_t_11, __pyx_v_YDIM); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 286, __pyx_L1_error)
  __pyx_v_local_y = __pyx_t_3;
 287: 
+288:     if grid[local_x, local_y] > 0:
  __pyx_t_1 = __pyx_v_local_x;
  __pyx_t_2 = __pyx_v_local_y;
  __pyx_t_3 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_grid.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_grid.shape[0])) __pyx_t_3 = 0;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_grid.shape[1];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 1;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_grid.shape[1])) __pyx_t_3 = 1;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 288, __pyx_L1_error)
  }
  __pyx_t_4 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_1 * __pyx_v_grid.strides[0]) ) + __pyx_t_2 * __pyx_v_grid.strides[1]) ))) > 0);
  if (__pyx_t_4) {
/* … */
  }
 289:         # fail
+290:         new_position[0] = -1
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_new_position.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_new_position.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 290, __pyx_L1_error)
    }
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_2 * __pyx_v_new_position.strides[0]) )) = -1;
+291:         return 0
    __pyx_r = 0;
    goto __pyx_L0;
 292: 
 293:     # hard sphere clash
 294:     else:
 295:         # success
+296:         new_position[0] = local_x;
  /*else*/ {
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_new_position.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_new_position.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 296, __pyx_L1_error)
    }
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_2 * __pyx_v_new_position.strides[0]) )) = __pyx_v_local_x;
+297:         new_position[1] = local_y;
    __pyx_t_2 = 1;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_new_position.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_new_position.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 297, __pyx_L1_error)
    }
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_2 * __pyx_v_new_position.strides[0]) )) = __pyx_v_local_y;
+298:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
  }
 299: 
 300: # --------------------------------------------------------------------------------------------------------
 301: #
 302: #
+303: @cython.wraparound(False)
static int __pyx_f_5pimms_13mega_crank_2D_single_bead_crank_2D(__Pyx_memviewslice __pyx_v_old_position, __Pyx_memviewslice __pyx_v_grid, int __pyx_v_XDIM, int __pyx_v_YDIM, __Pyx_memviewslice __pyx_v_new_position) {
  int __pyx_v_x_off;
  int __pyx_v_y_off;
  int __pyx_v_local_x;
  int __pyx_v_local_y;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pimms.mega_crank_2D.single_bead_crank_2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 304: @cython.boundscheck(False)
 305: cdef int single_bead_crank_2D(NUMPY_INT_TYPE[:] old_position,
 306:                               NUMPY_INT_TYPE[:,:] grid,
 307:                               int XDIM,
 308:                               int YDIM,
 309:                               NUMPY_INT_TYPE[:] new_position):
 310:     """
 311:     Perform crankshaft move!
 312: 
 313:     Single beads are easy as the new position is just a random pertubation in all three coordinates
 314: 
 315:     """
 316: 
 317:     cdef int x_off, y_off;
 318: 
+319:     x_off = (mega_crank.randint_ext(0,2)-1)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_mega_crank); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 319, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_randint_ext); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 319, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_mstate_global->__pyx_tuple[1], NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 319, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyLong_SubtractObjC(__pyx_t_1, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 319, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyLong_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 319, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_x_off = __pyx_t_3;
+320:     y_off = (mega_crank.randint_ext(0,2)-1)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_mega_crank); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_randint_ext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_mstate_global->__pyx_tuple[1], NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyLong_SubtractObjC(__pyx_t_2, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyLong_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_y_off = __pyx_t_3;
 321: 
 322:     #x_off = random_number.randint_np(0,2)-1
 323:     #y_off = random_number.randint_np(0,2)-1
 324: 
+325:     cdef int local_x = pbc_correction(old_position[0] + x_off, XDIM)
  __pyx_t_4 = 0;
  __pyx_t_3 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_4 * __pyx_v_old_position.strides[0]) ))) + __pyx_v_x_off), __pyx_v_XDIM); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 325, __pyx_L1_error)
  __pyx_v_local_x = __pyx_t_3;
+326:     cdef int local_y = pbc_correction(old_position[1] + y_off, YDIM)
  __pyx_t_4 = 1;
  __pyx_t_3 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction(((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_old_position.data + __pyx_t_4 * __pyx_v_old_position.strides[0]) ))) + __pyx_v_y_off), __pyx_v_YDIM); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 326, __pyx_L1_error)
  __pyx_v_local_y = __pyx_t_3;
 327: 
 328:     #if grid[new_position[0], new_position[1], new_position[2]] > 0:
+329:     if grid[local_x, local_y] > 0:
  __pyx_t_4 = __pyx_v_local_x;
  __pyx_t_5 = __pyx_v_local_y;
  __pyx_t_6 = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_4 * __pyx_v_grid.strides[0]) ) + __pyx_t_5 * __pyx_v_grid.strides[1]) ))) > 0);
  if (__pyx_t_6) {
/* … */
  }
 330:         # fail
+331:         new_position[0] = -1
    __pyx_t_5 = 0;
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_5 * __pyx_v_new_position.strides[0]) )) = -1;
+332:         return 0
    __pyx_r = 0;
    goto __pyx_L0;
 333: 
 334:     # hard sphere clash
 335:     else:
 336:         # success
+337:         new_position[0] = local_x
  /*else*/ {
    __pyx_t_5 = 0;
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_5 * __pyx_v_new_position.strides[0]) )) = __pyx_v_local_x;
+338:         new_position[1] = local_y
    __pyx_t_5 = 1;
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_new_position.data + __pyx_t_5 * __pyx_v_new_position.strides[0]) )) = __pyx_v_local_y;
+339:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
  }
 340: 
 341: 
+342: @cython.wraparound(False)
static long __pyx_f_5pimms_13mega_crank_2D_get_angle_energy_change_2D(int __pyx_v_bead_index, __Pyx_memviewslice __pyx_v_idx_to_bead, __Pyx_memviewslice __pyx_v_new_position, __Pyx_memviewslice __pyx_v_angle_lookup) {
  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_a0;
  int __pyx_v_a1;
  int __pyx_v_b0;
  int __pyx_v_b1;
  int __pyx_v_bead_flag;
  int __pyx_v_pos;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_angle_positions;
  __Pyx_Buffer __pyx_pybuffer_angle_positions;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_intcode_lookup;
  __Pyx_Buffer __pyx_pybuffer_intcode_lookup;
  long __pyx_r;
  __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_angle_positions.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pimms.mega_crank_2D.get_angle_energy_change_2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_angle_positions.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_angle_positions);
  __Pyx_XDECREF((PyObject *)__pyx_v_intcode_lookup);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 343: @cython.boundscheck(False)
 344: cdef long get_angle_energy_change_2D(int bead_index,
 345:                                      NUMPY_INT_TYPE_long[:,:] idx_to_bead,
 346:                                      NUMPY_INT_TYPE[:] new_position,
 347:                                      NUMPY_INT_TYPE[:,:,:,:,:,] angle_lookup):
 348: 
 349:     """
 350:     Function that takes a pre-computed angle energy lookup table and returns the change
 351:     in angle energy before and after the move, where the move must be moving a single bead.
 352:     Note this function is almost purely C (as measured by the output from cython -a)
 353: 
 354:     ## Parameters are as follows:
 355: 
 356:     bead_index
 357:     Index position of the specific bead of interest
 358: 
 359:     idx_to_bead
 360:     Full matrix containing the complete system information (see the description in
 361:     the mega_crank function description for a full summary of this variable)
 362: 
 363:     new_position
 364:     2D np.array ([x,y]) that defines the position that the moved bead
 365:     is moving to
 366: 
 367:     angle_lookup
 368:     5D lookup table that translates vector distances into an angle energy
 369:     penalty based on precomputed values.
 370: 
 371:     """
 372: 
 373:     # if the skip angle is set to true
+374:     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) {
/* … */
  }
+375:         return 0
    __pyx_r = 0;
    goto __pyx_L0;
 376: 
 377:     # initialize a bunch of values
+378:     cdef long angle_penalty_new = 0;
  __pyx_v_angle_penalty_new = 0;
+379:     cdef long angle_penalty_old = 0;
  __pyx_v_angle_penalty_old = 0;
 380: 
+381:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=2] angle_positions  = np.zeros([5, 2], 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, 381, __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, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_5);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_5);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_6, 0, __pyx_mstate_global->__pyx_int_5) != (0)) __PYX_ERR(0, 381, __pyx_L1_error);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_2);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_6, 1, __pyx_mstate_global->__pyx_int_2) != (0)) __PYX_ERR(0, 381, __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, 381, __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, 381, __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, 381, __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, 381, __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, 381, __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, 381, __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;
+382:     cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] intcode_lookup = np.zeros([5], 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, 382, __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, 382, __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, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_mstate_global->__pyx_int_5);
  __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_5);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_10, 0, __pyx_mstate_global->__pyx_int_5) != (0)) __PYX_ERR(0, 382, __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, 382, __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, 382, __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, 382, __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, 382, __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, 382, __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, 382, __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;
 383:     cdef int offset, offset_start, offset_end;
 384:     cdef int i;
 385:     cdef int angle_idx, local_move_idx;
 386:     cdef int a0, a1, b0, b1
 387:     cdef int bead_flag
 388: 
+389:     offset_start = 0
  __pyx_v_offset_start = 0;
+390:     offset_end = 0
  __pyx_v_offset_end = 0;
+391:     bead_flag = idx_to_bead[bead_index,0]
  __pyx_t_2 = __pyx_v_bead_index;
  __pyx_t_1 = 0;
  __pyx_v_bead_flag = (*((__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]) )));
 392: 
 393:     # N-terminal bead
+394:     if bead_flag == 1:
  switch (__pyx_v_bead_flag) {
    case 1:
/* … */
    break;
    case 2:
+395:         offset_start = 0
    __pyx_v_offset_start = 0;
+396:         offset_end   = 3
    __pyx_v_offset_end = 3;
 397: 
 398:     # central bead
+399:     elif bead_flag == 2:
    break;
    case 4:
+400:         offset_start = -2
    __pyx_v_offset_start = -2;
+401:         offset_end   = 3
    __pyx_v_offset_end = 3;
 402: 
 403:     # central bead in an OXO configuration
+404:     elif bead_flag == 4:
    break;
    case 3:
+405:         offset_start = -1
    __pyx_v_offset_start = -1;
+406:         offset_end   = 2
    __pyx_v_offset_end = 2;
 407: 
 408: 
 409:     # C terminal bead
+410:     elif bead_flag == 3:
    break;
    case 5:
+411:         offset_start = -2
    __pyx_v_offset_start = -2;
+412:         offset_end   = 1
    __pyx_v_offset_end = 1;
 413: 
 414:     # N terminal bead +1 from start
+415:     elif bead_flag == 5:
    break;
    case 6:
+416:         offset_start = -1
    __pyx_v_offset_start = -1;
+417:         offset_end   = 3
    __pyx_v_offset_end = 3;
 418: 
 419:     # C terminal bead -1 from end
+420:     elif bead_flag == 6:
    break;
    default: break;
  }
+421:         offset_start = -2
    __pyx_v_offset_start = -2;
+422:         offset_end   = 2
    __pyx_v_offset_end = 2;
 423: 
 424: 
 425:     # this is the index we use to keep track of the dynamic angle_positions array
+426:     angle_idx = 0
  __pyx_v_angle_idx = 0;
 427: 
+428:     local_move_idx  = -1
  __pyx_v_local_move_idx = -1;
+429:     angle_idx = 0
  __pyx_v_angle_idx = 0;
 430: 
+431:     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;
+432:         pos = bead_index + offset
    __pyx_v_pos = (__pyx_v_bead_index + __pyx_v_offset);
 433: 
+434:         angle_positions[angle_idx, 0] = idx_to_bead[pos,5] # x pos
    __pyx_t_1 = __pyx_v_pos;
    __pyx_t_2 = 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_1 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_2 * __pyx_v_idx_to_bead.strides[1]) )));
+435:         angle_positions[angle_idx, 1] = idx_to_bead[pos,6] # y pos
    __pyx_t_2 = __pyx_v_pos;
    __pyx_t_1 = 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_2 * __pyx_v_idx_to_bead.strides[0]) ) + __pyx_t_1 * __pyx_v_idx_to_bead.strides[1]) )));
+436:         intcode_lookup[angle_idx]     = idx_to_bead[pos,2] # intcode
    __pyx_t_1 = __pyx_v_pos;
    __pyx_t_2 = 2;
    __pyx_t_14 = __pyx_v_angle_idx;
    *__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_intcode_lookup.rcbuffer->pybuffer.buf, __pyx_t_14, __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]) )));
 437: 
+438:         if pos == bead_index:
    __pyx_t_3 = (__pyx_v_pos == __pyx_v_bead_index);
    if (__pyx_t_3) {
/* … */
    }
+439:             local_move_idx = angle_idx
      __pyx_v_local_move_idx = __pyx_v_angle_idx;
 440: 
+441:         angle_idx = angle_idx + 1
    __pyx_v_angle_idx = (__pyx_v_angle_idx + 1);
  }
 442: 
 443: 
+444:     for i in range(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;
 445: 
 446:         # compute the two vectors between the positions
+447:         a0 = 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_14 = __pyx_v_i;
    __pyx_t_15 = 0;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_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_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 447, __pyx_L1_error)
    __pyx_v_a0 = __pyx_t_12;
+448:         a1 = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i, 1])
    __pyx_t_15 = (__pyx_v_i + 1);
    __pyx_t_14 = 1;
    __pyx_t_1 = __pyx_v_i;
    __pyx_t_2 = 1;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_fix_angle_pbc_issues(((*__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_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, 448, __pyx_L1_error)
    __pyx_v_a1 = __pyx_t_12;
 449: 
+450:         b0 = fix_angle_pbc_issues(angle_positions[i+1, 0] - angle_positions[i+2, 0])
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_1 = 0;
    __pyx_t_14 = (__pyx_v_i + 2);
    __pyx_t_15 = 0;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_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_14, __pyx_pybuffernd_angle_positions.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 450, __pyx_L1_error)
    __pyx_v_b0 = __pyx_t_12;
+451:         b1 = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i+2, 1])
    __pyx_t_15 = (__pyx_v_i + 1);
    __pyx_t_14 = 1;
    __pyx_t_1 = (__pyx_v_i + 2);
    __pyx_t_2 = 1;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_fix_angle_pbc_issues(((*__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_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, 451, __pyx_L1_error)
    __pyx_v_b1 = __pyx_t_12;
 452: 
+453:         angle_penalty_old = angle_lookup[intcode_lookup[i+1], a0+1, a1+1, b0+1, b1+1] + angle_penalty_old
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_1 = (*__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_14 = (__pyx_v_a0 + 1);
    __pyx_t_15 = (__pyx_v_a1 + 1);
    __pyx_t_18 = (__pyx_v_b0 + 1);
    __pyx_t_19 = (__pyx_v_b1 + 1);
    __pyx_v_angle_penalty_old = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=4 */ (( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_angle_lookup.data + __pyx_t_1 * __pyx_v_angle_lookup.strides[0]) ) + __pyx_t_14 * __pyx_v_angle_lookup.strides[1]) ) + __pyx_t_15 * __pyx_v_angle_lookup.strides[2]) ) + __pyx_t_18 * __pyx_v_angle_lookup.strides[3]) ) + __pyx_t_19 * __pyx_v_angle_lookup.strides[4]) ))) + __pyx_v_angle_penalty_old);
  }
 454: 
+455:     angle_positions[local_move_idx,0] = new_position[0]
  __pyx_t_2 = 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_2 * __pyx_v_new_position.strides[0]) )));
+456:     angle_positions[local_move_idx,1] = new_position[1]
  __pyx_t_2 = 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_2 * __pyx_v_new_position.strides[0]) )));
 457: 
+458:     for i in range(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;
 459: 
 460:         # compute the two vectors between the positions
+461:         a0 = fix_angle_pbc_issues(angle_positions[i+1, 0] - angle_positions[i, 0])
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_19 = 0;
    __pyx_t_18 = __pyx_v_i;
    __pyx_t_15 = 0;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_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_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_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 461, __pyx_L1_error)
    __pyx_v_a0 = __pyx_t_12;
+462:         a1 = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i, 1])
    __pyx_t_15 = (__pyx_v_i + 1);
    __pyx_t_18 = 1;
    __pyx_t_19 = __pyx_v_i;
    __pyx_t_2 = 1;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_fix_angle_pbc_issues(((*__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_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_2, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 462, __pyx_L1_error)
    __pyx_v_a1 = __pyx_t_12;
 463: 
+464:         b0 = fix_angle_pbc_issues(angle_positions[i+1, 0] - angle_positions[i+2, 0])
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_19 = 0;
    __pyx_t_18 = (__pyx_v_i + 2);
    __pyx_t_15 = 0;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_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_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_15, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 464, __pyx_L1_error)
    __pyx_v_b0 = __pyx_t_12;
+465:         b1 = fix_angle_pbc_issues(angle_positions[i+1, 1] - angle_positions[i+2, 1])
    __pyx_t_15 = (__pyx_v_i + 1);
    __pyx_t_18 = 1;
    __pyx_t_19 = (__pyx_v_i + 2);
    __pyx_t_2 = 1;
    __pyx_t_12 = __pyx_f_5pimms_13mega_crank_2D_fix_angle_pbc_issues(((*__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_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_2, __pyx_pybuffernd_angle_positions.diminfo[1].strides)))); if (unlikely(__pyx_t_12 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 465, __pyx_L1_error)
    __pyx_v_b1 = __pyx_t_12;
 466: 
+467:         angle_penalty_new = angle_lookup[intcode_lookup[i+1], a0+1, a1+1, b0+1, b1+1] + angle_penalty_new
    __pyx_t_2 = (__pyx_v_i + 1);
    __pyx_t_19 = (*__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_18 = (__pyx_v_a0 + 1);
    __pyx_t_15 = (__pyx_v_a1 + 1);
    __pyx_t_14 = (__pyx_v_b0 + 1);
    __pyx_t_1 = (__pyx_v_b1 + 1);
    __pyx_v_angle_penalty_new = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=4 */ (( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_angle_lookup.data + __pyx_t_19 * __pyx_v_angle_lookup.strides[0]) ) + __pyx_t_18 * __pyx_v_angle_lookup.strides[1]) ) + __pyx_t_15 * __pyx_v_angle_lookup.strides[2]) ) + __pyx_t_14 * __pyx_v_angle_lookup.strides[3]) ) + __pyx_t_1 * __pyx_v_angle_lookup.strides[4]) ))) + __pyx_v_angle_penalty_new);
  }
 468: 
+469:     return (angle_penalty_new - angle_penalty_old)
  __pyx_r = (__pyx_v_angle_penalty_new - __pyx_v_angle_penalty_old);
  goto __pyx_L0;
 470: 
 471: 
+472: @cython.cdivision(True)
static int __pyx_f_5pimms_13mega_crank_2D_fix_angle_pbc_issues(int __pyx_v_distance) {
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
 473: cdef int fix_angle_pbc_issues(int distance):
 474:     """
 475:     Hack that takes advantage of the fact that the distances all must be -1,0, +1 and
 476:     we're always computing a X->O vector where O is the bend point
 477: 
 478:     """
+479:     if distance < -1:
  __pyx_t_1 = (__pyx_v_distance < -1L);
  if (__pyx_t_1) {
/* … */
  }
+480:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
+481:     elif distance > 1:
  __pyx_t_1 = (__pyx_v_distance > 1);
  if (__pyx_t_1) {
/* … */
  }
+482:         return -1
    __pyx_r = -1;
    goto __pyx_L0;
 483:     else:
+484:         return distance
  /*else*/ {
    __pyx_r = __pyx_v_distance;
    goto __pyx_L0;
  }
 485: 
 486: 
 487: # these directives made the function slower...
 488: #@cython.wraparound(False)
 489: #@cython.boundscheck(False)
+490: def get_energy_change_2D(NUMPY_INT_TYPE[:,:] grid,
/* Python wrapper */
static PyObject *__pyx_pw_5pimms_13mega_crank_2D_5get_energy_change_2D(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_13mega_crank_2D_5get_energy_change_2D = {"get_energy_change_2D", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_13mega_crank_2D_5get_energy_change_2D, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5pimms_13mega_crank_2D_5get_energy_change_2D(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
) {
  CYTHON_UNUSED __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_old_position = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_new_position = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_LR_vs_SR;
  __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 } };
  int __pyx_v_XDIM;
  int __pyx_v_YDIM;
  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("get_energy_change_2D (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_old_position,&__pyx_mstate_global->__pyx_n_u_new_position,&__pyx_mstate_global->__pyx_n_u_LR_vs_SR,&__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_XDIM,&__pyx_mstate_global->__pyx_n_u_YDIM,&__pyx_mstate_global->__pyx_n_u_hardwall,0};
  PyObject* values[11] = {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, 490, __pyx_L3_error)
    if (__pyx_kwds_len > 0) {
      switch (__pyx_nargs) {
        case 11:
        values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10);
        if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 490, __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, 490, __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, 490, __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, 490, __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, 490, __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, 490, __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, 490, __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, 490, __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, 490, __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, 490, __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, 490, __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_energy_change_2D", 0) < (0)) __PYX_ERR(0, 490, __pyx_L3_error)
      for (Py_ssize_t i = __pyx_nargs; i < 11; i++) {
        if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("get_energy_change_2D", 1, 11, 11, i); __PYX_ERR(0, 490, __pyx_L3_error) }
      }
    } else if (unlikely(__pyx_nargs != 11)) {
      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, 490, __pyx_L3_error)
      values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[6] = __Pyx_ArgRef_FASTCALL(__pyx_args, 6);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[6])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[7] = __Pyx_ArgRef_FASTCALL(__pyx_args, 7);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[7])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[8] = __Pyx_ArgRef_FASTCALL(__pyx_args, 8);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[8])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[9] = __Pyx_ArgRef_FASTCALL(__pyx_args, 9);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[9])) __PYX_ERR(0, 490, __pyx_L3_error)
      values[10] = __Pyx_ArgRef_FASTCALL(__pyx_args, 10);
      if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[10])) __PYX_ERR(0, 490, __pyx_L3_error)
    }
    __pyx_v_grid = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_grid.memview)) __PYX_ERR(0, 490, __pyx_L3_error)
    __pyx_v_type_grid = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_type_grid.memview)) __PYX_ERR(0, 491, __pyx_L3_error)
    __pyx_v_old_position = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[2], PyBUF_WRITABLE); if (unlikely(!__pyx_v_old_position.memview)) __PYX_ERR(0, 492, __pyx_L3_error)
    __pyx_v_new_position = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[3], PyBUF_WRITABLE); if (unlikely(!__pyx_v_new_position.memview)) __PYX_ERR(0, 493, __pyx_L3_error)
    __pyx_v_LR_vs_SR = __Pyx_PyLong_As_int(values[4]); if (unlikely((__pyx_v_LR_vs_SR == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 494, __pyx_L3_error)
    __pyx_v_interaction_table = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[5], PyBUF_WRITABLE); if (unlikely(!__pyx_v_interaction_table.memview)) __PYX_ERR(0, 495, __pyx_L3_error)
    __pyx_v_LR_interaction_table = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[6], PyBUF_WRITABLE); if (unlikely(!__pyx_v_LR_interaction_table.memview)) __PYX_ERR(0, 496, __pyx_L3_error)
    __pyx_v_SLR_interaction_table = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[7], PyBUF_WRITABLE); if (unlikely(!__pyx_v_SLR_interaction_table.memview)) __PYX_ERR(0, 497, __pyx_L3_error)
    __pyx_v_XDIM = __Pyx_PyLong_As_int(values[8]); if (unlikely((__pyx_v_XDIM == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 498, __pyx_L3_error)
    __pyx_v_YDIM = __Pyx_PyLong_As_int(values[9]); if (unlikely((__pyx_v_YDIM == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 499, __pyx_L3_error)
    __pyx_v_hardwall = __Pyx_PyLong_As_int(values[10]); if (unlikely((__pyx_v_hardwall == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 500, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_energy_change_2D", 1, 11, 11, __pyx_nargs); __PYX_ERR(0, 490, __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_old_position, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_new_position, 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_AddTraceback("pimms.mega_crank_2D.get_energy_change_2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pimms_13mega_crank_2D_4get_energy_change_2D(__pyx_self, __pyx_v_grid, __pyx_v_type_grid, __pyx_v_old_position, __pyx_v_new_position, __pyx_v_LR_vs_SR, __pyx_v_interaction_table, __pyx_v_LR_interaction_table, __pyx_v_SLR_interaction_table, __pyx_v_XDIM, __pyx_v_YDIM, __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_old_position, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_new_position, 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_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pimms_13mega_crank_2D_4get_energy_change_2D(CYTHON_UNUSED PyObject *__pyx_self, 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_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_new_x;
  int __pyx_v_new_y;
  int __pyx_v_tmp_x;
  int __pyx_v_tmp_y;
  int __pyx_v_x;
  int __pyx_v_y;
  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_12);
  __Pyx_AddTraceback("pimms.mega_crank_2D.get_energy_change_2D", __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_13mega_crank_2D_5get_energy_change_2D, 0, __pyx_mstate_global->__pyx_n_u_get_energy_change_2D, NULL, __pyx_mstate_global->__pyx_n_u_pimms_mega_crank_2D, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 490, __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_energy_change_2D, __pyx_t_4) < (0)) __PYX_ERR(0, 490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 491:                          NUMPY_INT_TYPE[:,:] type_grid,
 492:                          NUMPY_INT_TYPE[:] old_position,
 493:                          NUMPY_INT_TYPE[:] new_position,
 494:                          int LR_vs_SR,
 495:                          NUMPY_INT_TYPE[:,:] interaction_table,
 496:                          NUMPY_INT_TYPE[:,:] LR_interaction_table,
 497:                          NUMPY_INT_TYPE[:,:] SLR_interaction_table,
 498:                          int XDIM,
 499:                          int YDIM,
 500:                          int hardwall):
 501: 
 502: 
 503:     # We define four energy variables which are going to be used to calcualte
 504:     # the DELTA energy.
 505:     #
 506:     # --> energy old is the interactions between the bead and its
 507:     # partners in its current location
 508:     #
 509:     # --> energy_old_empy is the energy associated with the site after this
 510:     # bead has been removed (i.e. solvent to local partners only)
 511:     #
 512:     # --> energy_new is the interaction between the bead and its partners in
 513:     #     its NEW location!
 514:     #
 515:     # --> energy_new_empty is the interaction between the bead and its
 516: 
+517:     cdef long energy_old       = 0
  __pyx_v_energy_old = 0;
+518:     cdef long energy_old_empty = 0
  __pyx_v_energy_old_empty = 0;
+519:     cdef long energy_new       = 0
  __pyx_v_energy_new = 0;
+520:     cdef long energy_new_empty = 0
  __pyx_v_energy_new_empty = 0;
 521: 
 522: 
 523:     cdef int old_x, old_y;
 524:     cdef int new_x, new_y;
 525:     cdef int tmp_x, tmp_y;
 526: 
 527:     cdef int x, y
 528: 
 529:     cdef unsigned int site_bead_type, bead_type;
 530: 
 531:     # extract
+532:     new_x = new_position[0]
  __pyx_t_1 = 0;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_new_position.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_new_position.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 532, __pyx_L1_error)
  }
  __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]) )));
+533:     new_y = new_position[1]
  __pyx_t_1 = 1;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_new_position.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_new_position.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 533, __pyx_L1_error)
  }
  __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]) )));
 534: 
+535:     old_x = old_position[0]
  __pyx_t_1 = 0;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_old_position.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_old_position.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 535, __pyx_L1_error)
  }
  __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]) )));
+536:     old_y = old_position[1]
  __pyx_t_1 = 1;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_old_position.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_old_position.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 536, __pyx_L1_error)
  }
  __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]) )));
 537: 
 538:     # get the type of the current beads
+539:     bead_type = type_grid[old_x, old_y]
  __pyx_t_1 = __pyx_v_old_x;
  __pyx_t_3 = __pyx_v_old_y;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_type_grid.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
  if (__pyx_t_3 < 0) {
    __pyx_t_3 += __pyx_v_type_grid.shape[1];
    if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 1;
  } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 539, __pyx_L1_error)
  }
  __pyx_v_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[1]) )));
 540: 
 541:     ## ************************************************************************************************
 542:     ##  Long range energy
 543:     ##
 544:     # if we're looking at a bead which engages in longrange interactions
+545:     if LR_vs_SR == 1:
  __pyx_t_4 = (__pyx_v_LR_vs_SR == 1);
  if (__pyx_t_4) {
/* … */
    goto __pyx_L3;
  }
 546: 
 547:         ## First evaluate the old energy
+548:         for x in range(-3,4):
    for (__pyx_t_2 = -3; __pyx_t_2 < 4; __pyx_t_2+=1) {
      __pyx_v_x = __pyx_t_2;
+549:             for y in range(-3,4):
      for (__pyx_t_5 = -3; __pyx_t_5 < 4; __pyx_t_5+=1) {
        __pyx_v_y = __pyx_t_5;
+550:                 tmp_x = pbc_correction(old_x + x, XDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_old_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 550, __pyx_L1_error)
        __pyx_v_tmp_x = __pyx_t_6;
+551:                 tmp_y = pbc_correction(old_y + y, YDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_old_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 551, __pyx_L1_error)
        __pyx_v_tmp_y = __pyx_t_6;
 552: 
+553:                 site_bead_type = type_grid[tmp_x, tmp_y]
        __pyx_t_3 = __pyx_v_tmp_x;
        __pyx_t_1 = __pyx_v_tmp_y;
        __pyx_t_6 = -1;
        if (__pyx_t_3 < 0) {
          __pyx_t_3 += __pyx_v_type_grid.shape[0];
          if (unlikely(__pyx_t_3 < 0)) __pyx_t_6 = 0;
        } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[0])) __pyx_t_6 = 0;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_type_grid.shape[1];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_6 = 1;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[1])) __pyx_t_6 = 1;
        if (unlikely(__pyx_t_6 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_6);
          __PYX_ERR(0, 553, __pyx_L1_error)
        }
        __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[1]) )));
 554: 
 555:                 # short-range interactions
+556:                 if abs(x) < 2 and abs(y) < 2:
        __pyx_t_6 = abs(__pyx_v_x); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 556, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 2);
        if (__pyx_t_7) {
        } else {
          __pyx_t_4 = __pyx_t_7;
          goto __pyx_L9_bool_binop_done;
        }
        __pyx_t_6 = abs(__pyx_v_y); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 556, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 2);
        __pyx_t_4 = __pyx_t_7;
        __pyx_L9_bool_binop_done:;
        if (__pyx_t_4) {
/* … */
          goto __pyx_L8;
        }
 557: 
 558:                     # if harwall boundary is on then short range interaction between a bead and something across
 559:                     # the boundary is by definition bead-solvent interaction (type 0)
+560:                     if hardwall == 1:
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+561:                         if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3:
            __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 561, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_4 = __pyx_t_7;
              goto __pyx_L13_bool_binop_done;
            }
            __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 561, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            __pyx_t_4 = __pyx_t_7;
            __pyx_L13_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+562:                             site_bead_type = 0
              __pyx_v_site_bead_type = 0;
 563: 
 564:                     # bead-site interaction
+565:                     energy_old = energy_old + interaction_table[bead_type, site_bead_type]
          __pyx_t_8 = __pyx_v_bead_type;
          __pyx_t_9 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 565, __pyx_L1_error)
          }
          __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_8 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_9 * __pyx_v_interaction_table.strides[1]) ))));
 566: 
 567:                     # might be faster to just read this from memory every time - is if or a memory read and addition faster?
+568:                     if site_bead_type > 0:
          __pyx_t_4 = (__pyx_v_site_bead_type > 0);
          if (__pyx_t_4) {
/* … */
          }
+569:                         energy_old_empty = energy_old_empty + interaction_table[0, site_bead_type]
            __pyx_t_1 = 0;
            __pyx_t_9 = __pyx_v_site_bead_type;
            __pyx_t_6 = -1;
            if (__pyx_t_1 < 0) {
              __pyx_t_1 += __pyx_v_interaction_table.shape[0];
              if (unlikely(__pyx_t_1 < 0)) __pyx_t_6 = 0;
            } else if (unlikely(__pyx_t_1 >= __pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
            if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
            if (unlikely(__pyx_t_6 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_6);
              __PYX_ERR(0, 569, __pyx_L1_error)
            }
            __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_9 * __pyx_v_interaction_table.strides[1]) ))));
 570: 
 571:                 # long range interactions (maybe optimize this in future...) - note long range interactions cannot
 572:                 # contribute to the energy_old_empty variable
+573:                 elif abs(x) < 3 and abs(y) < 3:
        __pyx_t_6 = abs(__pyx_v_x); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 573, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 3);
        if (__pyx_t_7) {
        } else {
          __pyx_t_4 = __pyx_t_7;
          goto __pyx_L16_bool_binop_done;
        }
        __pyx_t_6 = abs(__pyx_v_y); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 573, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 3);
        __pyx_t_4 = __pyx_t_7;
        __pyx_L16_bool_binop_done:;
        if (__pyx_t_4) {
/* … */
          goto __pyx_L8;
        }
 574: 
 575:                     # if harwall boundary is on - don't feel LR or SLR interactions over boundary
+576:                     if hardwall == 1:
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+577:                         if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3:
            __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 577, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_4 = __pyx_t_7;
              goto __pyx_L20_bool_binop_done;
            }
            __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 577, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            __pyx_t_4 = __pyx_t_7;
            __pyx_L20_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+578:                             continue
              goto __pyx_L6_continue;
+579:                     energy_old = energy_old + LR_interaction_table[bead_type, site_bead_type]
          __pyx_t_9 = __pyx_v_bead_type;
          __pyx_t_8 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_LR_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_LR_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 579, __pyx_L1_error)
          }
          __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_9 * __pyx_v_LR_interaction_table.strides[0]) ) + __pyx_t_8 * __pyx_v_LR_interaction_table.strides[1]) ))));
 580: 
 581:                 else:
 582:                     # if harwall boundary is on - don't feel LR or SLR interactions over boundary
+583:                     if hardwall == 1:
        /*else*/ {
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+584:                         if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3:
            __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 584, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_4 = __pyx_t_7;
              goto __pyx_L24_bool_binop_done;
            }
            __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 584, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            __pyx_t_4 = __pyx_t_7;
            __pyx_L24_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+585:                             continue
              goto __pyx_L6_continue;
+586:                     energy_old = energy_old + SLR_interaction_table[bead_type, site_bead_type]
          __pyx_t_8 = __pyx_v_bead_type;
          __pyx_t_9 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_SLR_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_SLR_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 586, __pyx_L1_error)
          }
          __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_8 * __pyx_v_SLR_interaction_table.strides[0]) ) + __pyx_t_9 * __pyx_v_SLR_interaction_table.strides[1]) ))));
        }
        __pyx_L8:;
        __pyx_L6_continue:;
      }
    }
 587: 
 588: 
 589:         # reset the typegrid to the new configuation
+590:         type_grid[new_x,new_y] = type_grid[old_x,old_y]
    __pyx_t_1 = __pyx_v_old_x;
    __pyx_t_3 = __pyx_v_old_y;
    __pyx_t_2 = -1;
    if (__pyx_t_1 < 0) {
      __pyx_t_1 += __pyx_v_type_grid.shape[0];
      if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
    } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
    if (__pyx_t_3 < 0) {
      __pyx_t_3 += __pyx_v_type_grid.shape[1];
      if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 1;
    } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
    if (unlikely(__pyx_t_2 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_2);
      __PYX_ERR(0, 590, __pyx_L1_error)
    }
    __pyx_t_10 = __pyx_v_new_x;
    __pyx_t_11 = __pyx_v_new_y;
    __pyx_t_2 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_type_grid.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_2 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
    if (__pyx_t_11 < 0) {
      __pyx_t_11 += __pyx_v_type_grid.shape[1];
      if (unlikely(__pyx_t_11 < 0)) __pyx_t_2 = 1;
    } else if (unlikely(__pyx_t_11 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
    if (unlikely(__pyx_t_2 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_2);
      __PYX_ERR(0, 590, __pyx_L1_error)
    }
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_10 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_11 * __pyx_v_type_grid.strides[1]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[1]) )));
+591:         type_grid[old_x,old_y] = 0
    __pyx_t_3 = __pyx_v_old_x;
    __pyx_t_1 = __pyx_v_old_y;
    __pyx_t_2 = -1;
    if (__pyx_t_3 < 0) {
      __pyx_t_3 += __pyx_v_type_grid.shape[0];
      if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 0;
    } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
    if (__pyx_t_1 < 0) {
      __pyx_t_1 += __pyx_v_type_grid.shape[1];
      if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 1;
    } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
    if (unlikely(__pyx_t_2 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_2);
      __PYX_ERR(0, 591, __pyx_L1_error)
    }
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[1]) )) = 0;
 592: 
 593:         ## then evaluate the new energy
+594:         for x in range(-3,4):
    for (__pyx_t_2 = -3; __pyx_t_2 < 4; __pyx_t_2+=1) {
      __pyx_v_x = __pyx_t_2;
+595:             for y in range(-3,4):
      for (__pyx_t_5 = -3; __pyx_t_5 < 4; __pyx_t_5+=1) {
        __pyx_v_y = __pyx_t_5;
 596: 
 597:                 # get PBC corrected positions of interest
+598:                 tmp_x = pbc_correction(new_x + x, XDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_new_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 598, __pyx_L1_error)
        __pyx_v_tmp_x = __pyx_t_6;
+599:                 tmp_y = pbc_correction(new_y + y, YDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_new_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 599, __pyx_L1_error)
        __pyx_v_tmp_y = __pyx_t_6;
 600: 
+601:                 site_bead_type = type_grid[tmp_x, tmp_y]
        __pyx_t_1 = __pyx_v_tmp_x;
        __pyx_t_3 = __pyx_v_tmp_y;
        __pyx_t_6 = -1;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_type_grid.shape[0];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_6 = 0;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[0])) __pyx_t_6 = 0;
        if (__pyx_t_3 < 0) {
          __pyx_t_3 += __pyx_v_type_grid.shape[1];
          if (unlikely(__pyx_t_3 < 0)) __pyx_t_6 = 1;
        } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[1])) __pyx_t_6 = 1;
        if (unlikely(__pyx_t_6 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_6);
          __PYX_ERR(0, 601, __pyx_L1_error)
        }
        __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[1]) )));
 602: 
 603:                 # short-range interactions
+604:                 if abs(x) < 2 and abs(y) < 2:
        __pyx_t_6 = abs(__pyx_v_x); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 604, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 2);
        if (__pyx_t_7) {
        } else {
          __pyx_t_4 = __pyx_t_7;
          goto __pyx_L31_bool_binop_done;
        }
        __pyx_t_6 = abs(__pyx_v_y); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 604, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 2);
        __pyx_t_4 = __pyx_t_7;
        __pyx_L31_bool_binop_done:;
        if (__pyx_t_4) {
/* … */
          goto __pyx_L30;
        }
 605: 
+606:                     if hardwall == 1:
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+607:                         if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3:
            __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 607, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_4 = __pyx_t_7;
              goto __pyx_L35_bool_binop_done;
            }
            __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 607, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            __pyx_t_4 = __pyx_t_7;
            __pyx_L35_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+608:                             site_bead_type = 0
              __pyx_v_site_bead_type = 0;
 609: 
 610:                     # bead-site interaction
+611:                     energy_new = energy_new + interaction_table[bead_type, site_bead_type]
          __pyx_t_9 = __pyx_v_bead_type;
          __pyx_t_8 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 611, __pyx_L1_error)
          }
          __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_9 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_8 * __pyx_v_interaction_table.strides[1]) ))));
 612: 
+613:                     if site_bead_type > 0:
          __pyx_t_4 = (__pyx_v_site_bead_type > 0);
          if (__pyx_t_4) {
/* … */
          }
+614:                         energy_new_empty = energy_new_empty + interaction_table[0, site_bead_type]
            __pyx_t_3 = 0;
            __pyx_t_8 = __pyx_v_site_bead_type;
            __pyx_t_6 = -1;
            if (__pyx_t_3 < 0) {
              __pyx_t_3 += __pyx_v_interaction_table.shape[0];
              if (unlikely(__pyx_t_3 < 0)) __pyx_t_6 = 0;
            } else if (unlikely(__pyx_t_3 >= __pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
            if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
            if (unlikely(__pyx_t_6 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_6);
              __PYX_ERR(0, 614, __pyx_L1_error)
            }
            __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_8 * __pyx_v_interaction_table.strides[1]) ))));
 615: 
 616:                 # long range interactions (maybe optimize this in future...) - note long range interactions cannot
 617:                 # contribute to the energy_old_empty variable
 618: 
 619:                 # long range interactions (maybe optimize this in future...) - note long range interactions cannot
 620:                 # contribute to the energy_old_empty variable
+621:                 elif abs(x) < 3 and abs(y) < 3:
        __pyx_t_6 = abs(__pyx_v_x); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 621, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 3);
        if (__pyx_t_7) {
        } else {
          __pyx_t_4 = __pyx_t_7;
          goto __pyx_L38_bool_binop_done;
        }
        __pyx_t_6 = abs(__pyx_v_y); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 621, __pyx_L1_error)
        __pyx_t_7 = (__pyx_t_6 < 3);
        __pyx_t_4 = __pyx_t_7;
        __pyx_L38_bool_binop_done:;
        if (__pyx_t_4) {
/* … */
          goto __pyx_L30;
        }
 622:                     # if harwall boundary is on - don't feel LR or SLR interactions over boundary
+623:                     if hardwall == 1:
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+624:                         if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3:
            __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 624, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_4 = __pyx_t_7;
              goto __pyx_L42_bool_binop_done;
            }
            __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 624, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            __pyx_t_4 = __pyx_t_7;
            __pyx_L42_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+625:                             continue
              goto __pyx_L28_continue;
 626: 
+627:                     energy_new = energy_new + LR_interaction_table[bead_type, site_bead_type]
          __pyx_t_8 = __pyx_v_bead_type;
          __pyx_t_9 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_LR_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_LR_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 627, __pyx_L1_error)
          }
          __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_8 * __pyx_v_LR_interaction_table.strides[0]) ) + __pyx_t_9 * __pyx_v_LR_interaction_table.strides[1]) ))));
 628: 
 629:                 else:
 630:                     # if harwall boundary is on - don't feel LR or SLR interactions over boundary
+631:                     if hardwall == 1:
        /*else*/ {
          __pyx_t_4 = (__pyx_v_hardwall == 1);
          if (__pyx_t_4) {
/* … */
          }
+632:                         if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3:
            __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 632, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_4 = __pyx_t_7;
              goto __pyx_L46_bool_binop_done;
            }
            __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 632, __pyx_L1_error)
            __pyx_t_7 = (__pyx_t_6 > 3);
            __pyx_t_4 = __pyx_t_7;
            __pyx_L46_bool_binop_done:;
            if (__pyx_t_4) {
/* … */
            }
+633:                             continue
              goto __pyx_L28_continue;
 634: 
+635:                     energy_new = energy_new + SLR_interaction_table[bead_type, site_bead_type]
          __pyx_t_9 = __pyx_v_bead_type;
          __pyx_t_8 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_SLR_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_SLR_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 635, __pyx_L1_error)
          }
          __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_9 * __pyx_v_SLR_interaction_table.strides[0]) ) + __pyx_t_8 * __pyx_v_SLR_interaction_table.strides[1]) ))));
        }
        __pyx_L30:;
        __pyx_L28_continue:;
      }
    }
 636: 
 637: 
 638:     ## ************************************************************************************************
 639:     ##  only short range brah!
 640:     ##
 641:     else:
+642:         for x in range(-1,2):
  /*else*/ {
    for (__pyx_t_2 = -1; __pyx_t_2 < 2; __pyx_t_2+=1) {
      __pyx_v_x = __pyx_t_2;
+643:             for y in range(-1,2):
      for (__pyx_t_5 = -1; __pyx_t_5 < 2; __pyx_t_5+=1) {
        __pyx_v_y = __pyx_t_5;
 644: 
 645:                 # get PBC corrected positions of interest
+646:                 tmp_x = pbc_correction(old_x + x, XDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_old_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 646, __pyx_L1_error)
        __pyx_v_tmp_x = __pyx_t_6;
+647:                 tmp_y = pbc_correction(old_y + y, YDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_old_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 647, __pyx_L1_error)
        __pyx_v_tmp_y = __pyx_t_6;
 648: 
+649:                 site_bead_type = type_grid[tmp_x, tmp_y]
        __pyx_t_3 = __pyx_v_tmp_x;
        __pyx_t_1 = __pyx_v_tmp_y;
        __pyx_t_6 = -1;
        if (__pyx_t_3 < 0) {
          __pyx_t_3 += __pyx_v_type_grid.shape[0];
          if (unlikely(__pyx_t_3 < 0)) __pyx_t_6 = 0;
        } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[0])) __pyx_t_6 = 0;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_type_grid.shape[1];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_6 = 1;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[1])) __pyx_t_6 = 1;
        if (unlikely(__pyx_t_6 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_6);
          __PYX_ERR(0, 649, __pyx_L1_error)
        }
        __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[1]) )));
 650: 
 651:                 # if harwall boundary is on then overwrite site_bead_type
+652:                 if hardwall == 1:
        __pyx_t_4 = (__pyx_v_hardwall == 1);
        if (__pyx_t_4) {
/* … */
        }
+653:                     if abs(tmp_x - old_x) > 3 or abs(tmp_y - old_y) > 3:
          __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_old_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 653, __pyx_L1_error)
          __pyx_t_7 = (__pyx_t_6 > 3);
          if (!__pyx_t_7) {
          } else {
            __pyx_t_4 = __pyx_t_7;
            goto __pyx_L54_bool_binop_done;
          }
          __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_old_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 653, __pyx_L1_error)
          __pyx_t_7 = (__pyx_t_6 > 3);
          __pyx_t_4 = __pyx_t_7;
          __pyx_L54_bool_binop_done:;
          if (__pyx_t_4) {
/* … */
          }
+654:                         site_bead_type = 0
            __pyx_v_site_bead_type = 0;
 655: 
 656:                 # bead-site interaction
+657:                 energy_old = energy_old + interaction_table[bead_type, site_bead_type]
        __pyx_t_8 = __pyx_v_bead_type;
        __pyx_t_9 = __pyx_v_site_bead_type;
        __pyx_t_6 = -1;
        if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
        if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
        if (unlikely(__pyx_t_6 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_6);
          __PYX_ERR(0, 657, __pyx_L1_error)
        }
        __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_8 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_9 * __pyx_v_interaction_table.strides[1]) ))));
 658: 
 659:                 # might be faster to just read this from memory every time - is if or a memory read and addition faster?
+660:                 if site_bead_type > 0:
        __pyx_t_4 = (__pyx_v_site_bead_type > 0);
        if (__pyx_t_4) {
/* … */
        }
      }
    }
+661:                     energy_old_empty = energy_old_empty + interaction_table[0, site_bead_type]
          __pyx_t_1 = 0;
          __pyx_t_9 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (__pyx_t_1 < 0) {
            __pyx_t_1 += __pyx_v_interaction_table.shape[0];
            if (unlikely(__pyx_t_1 < 0)) __pyx_t_6 = 0;
          } else if (unlikely(__pyx_t_1 >= __pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 661, __pyx_L1_error)
          }
          __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_9 * __pyx_v_interaction_table.strides[1]) ))));
 662: 
 663:         # reset the typegrid to the new configuation
+664:         type_grid[new_x,new_y] = type_grid[old_x,old_y]
    __pyx_t_1 = __pyx_v_old_x;
    __pyx_t_3 = __pyx_v_old_y;
    __pyx_t_2 = -1;
    if (__pyx_t_1 < 0) {
      __pyx_t_1 += __pyx_v_type_grid.shape[0];
      if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
    } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
    if (__pyx_t_3 < 0) {
      __pyx_t_3 += __pyx_v_type_grid.shape[1];
      if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 1;
    } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
    if (unlikely(__pyx_t_2 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_2);
      __PYX_ERR(0, 664, __pyx_L1_error)
    }
    __pyx_t_11 = __pyx_v_new_x;
    __pyx_t_10 = __pyx_v_new_y;
    __pyx_t_2 = -1;
    if (__pyx_t_11 < 0) {
      __pyx_t_11 += __pyx_v_type_grid.shape[0];
      if (unlikely(__pyx_t_11 < 0)) __pyx_t_2 = 0;
    } else if (unlikely(__pyx_t_11 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_type_grid.shape[1];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_2 = 1;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
    if (unlikely(__pyx_t_2 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_2);
      __PYX_ERR(0, 664, __pyx_L1_error)
    }
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_11 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_10 * __pyx_v_type_grid.strides[1]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[1]) )));
+665:         type_grid[old_x,old_y] = 0
    __pyx_t_3 = __pyx_v_old_x;
    __pyx_t_1 = __pyx_v_old_y;
    __pyx_t_2 = -1;
    if (__pyx_t_3 < 0) {
      __pyx_t_3 += __pyx_v_type_grid.shape[0];
      if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 0;
    } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
    if (__pyx_t_1 < 0) {
      __pyx_t_1 += __pyx_v_type_grid.shape[1];
      if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 1;
    } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
    if (unlikely(__pyx_t_2 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_2);
      __PYX_ERR(0, 665, __pyx_L1_error)
    }
    *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[1]) )) = 0;
 666: 
+667:         for x in range(-1,2):
    for (__pyx_t_2 = -1; __pyx_t_2 < 2; __pyx_t_2+=1) {
      __pyx_v_x = __pyx_t_2;
+668:             for y in range(-1,2):
      for (__pyx_t_5 = -1; __pyx_t_5 < 2; __pyx_t_5+=1) {
        __pyx_v_y = __pyx_t_5;
 669: 
 670:                 # get PBC corrected positions of interest
+671:                 tmp_x = pbc_correction(new_x + x, XDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_new_x + __pyx_v_x), __pyx_v_XDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 671, __pyx_L1_error)
        __pyx_v_tmp_x = __pyx_t_6;
+672:                 tmp_y = pbc_correction(new_y + y, YDIM)
        __pyx_t_6 = __pyx_f_5pimms_13mega_crank_2D_pbc_correction((__pyx_v_new_y + __pyx_v_y), __pyx_v_YDIM); if (unlikely(__pyx_t_6 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 672, __pyx_L1_error)
        __pyx_v_tmp_y = __pyx_t_6;
 673: 
+674:                 site_bead_type = type_grid[tmp_x, tmp_y]
        __pyx_t_1 = __pyx_v_tmp_x;
        __pyx_t_3 = __pyx_v_tmp_y;
        __pyx_t_6 = -1;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_type_grid.shape[0];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_6 = 0;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[0])) __pyx_t_6 = 0;
        if (__pyx_t_3 < 0) {
          __pyx_t_3 += __pyx_v_type_grid.shape[1];
          if (unlikely(__pyx_t_3 < 0)) __pyx_t_6 = 1;
        } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[1])) __pyx_t_6 = 1;
        if (unlikely(__pyx_t_6 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_6);
          __PYX_ERR(0, 674, __pyx_L1_error)
        }
        __pyx_v_site_bead_type = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[1]) )));
 675: 
 676:                 # if harwall boundary is on then overwrite site_bead_type
+677:                 if hardwall == 1:
        __pyx_t_4 = (__pyx_v_hardwall == 1);
        if (__pyx_t_4) {
/* … */
        }
+678:                     if abs(tmp_x - new_x) > 3 or abs(tmp_y - new_y) > 3:
          __pyx_t_6 = abs((__pyx_v_tmp_x - __pyx_v_new_x)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 678, __pyx_L1_error)
          __pyx_t_7 = (__pyx_t_6 > 3);
          if (!__pyx_t_7) {
          } else {
            __pyx_t_4 = __pyx_t_7;
            goto __pyx_L63_bool_binop_done;
          }
          __pyx_t_6 = abs((__pyx_v_tmp_y - __pyx_v_new_y)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 678, __pyx_L1_error)
          __pyx_t_7 = (__pyx_t_6 > 3);
          __pyx_t_4 = __pyx_t_7;
          __pyx_L63_bool_binop_done:;
          if (__pyx_t_4) {
/* … */
          }
+679:                         site_bead_type = 0
            __pyx_v_site_bead_type = 0;
 680: 
 681:                 # bead-site interaction
+682:                 energy_new = energy_new + interaction_table[bead_type, site_bead_type]
        __pyx_t_9 = __pyx_v_bead_type;
        __pyx_t_8 = __pyx_v_site_bead_type;
        __pyx_t_6 = -1;
        if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
        if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
        if (unlikely(__pyx_t_6 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_6);
          __PYX_ERR(0, 682, __pyx_L1_error)
        }
        __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_9 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_8 * __pyx_v_interaction_table.strides[1]) ))));
 683: 
 684:                 # might be faster to just read this from memory every time - is if or a memory read and addition faster?
+685:                 if site_bead_type > 0:
        __pyx_t_4 = (__pyx_v_site_bead_type > 0);
        if (__pyx_t_4) {
/* … */
        }
      }
    }
  }
  __pyx_L3:;
+686:                     energy_new_empty = energy_new_empty + interaction_table[0, site_bead_type]
          __pyx_t_3 = 0;
          __pyx_t_8 = __pyx_v_site_bead_type;
          __pyx_t_6 = -1;
          if (__pyx_t_3 < 0) {
            __pyx_t_3 += __pyx_v_interaction_table.shape[0];
            if (unlikely(__pyx_t_3 < 0)) __pyx_t_6 = 0;
          } else if (unlikely(__pyx_t_3 >= __pyx_v_interaction_table.shape[0])) __pyx_t_6 = 0;
          if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_6 = 1;
          if (unlikely(__pyx_t_6 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_6);
            __PYX_ERR(0, 686, __pyx_L1_error)
          }
          __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_8 * __pyx_v_interaction_table.strides[1]) ))));
 687: 
 688:     # finally correct for the self-self interactions we cover when x == y == 0
+689:     energy_old_empty = energy_old_empty - interaction_table[0, bead_type]
  __pyx_t_3 = 0;
  __pyx_t_8 = __pyx_v_bead_type;
  __pyx_t_2 = -1;
  if (__pyx_t_3 < 0) {
    __pyx_t_3 += __pyx_v_interaction_table.shape[0];
    if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_3 >= __pyx_v_interaction_table.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 689, __pyx_L1_error)
  }
  __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_8 * __pyx_v_interaction_table.strides[1]) ))));
+690:     energy_old       = energy_old - interaction_table[bead_type, bead_type]
  __pyx_t_8 = __pyx_v_bead_type;
  __pyx_t_9 = __pyx_v_bead_type;
  __pyx_t_2 = -1;
  if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 690, __pyx_L1_error)
  }
  __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_8 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_9 * __pyx_v_interaction_table.strides[1]) ))));
+691:     energy_new_empty = energy_new_empty - interaction_table[0, bead_type]
  __pyx_t_3 = 0;
  __pyx_t_9 = __pyx_v_bead_type;
  __pyx_t_2 = -1;
  if (__pyx_t_3 < 0) {
    __pyx_t_3 += __pyx_v_interaction_table.shape[0];
    if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_3 >= __pyx_v_interaction_table.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 691, __pyx_L1_error)
  }
  __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_9 * __pyx_v_interaction_table.strides[1]) ))));
+692:     energy_new       = energy_new - interaction_table[bead_type, bead_type]
  __pyx_t_9 = __pyx_v_bead_type;
  __pyx_t_8 = __pyx_v_bead_type;
  __pyx_t_2 = -1;
  if (unlikely(__pyx_t_9 >= (size_t)__pyx_v_interaction_table.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_8 >= (size_t)__pyx_v_interaction_table.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 692, __pyx_L1_error)
  }
  __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_9 * __pyx_v_interaction_table.strides[0]) ) + __pyx_t_8 * __pyx_v_interaction_table.strides[1]) ))));
 693: 
 694:     # reset the type grid again...
+695:     type_grid[old_x,old_y] = type_grid[new_x,new_y]
  __pyx_t_3 = __pyx_v_new_x;
  __pyx_t_1 = __pyx_v_new_y;
  __pyx_t_2 = -1;
  if (__pyx_t_3 < 0) {
    __pyx_t_3 += __pyx_v_type_grid.shape[0];
    if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_type_grid.shape[1];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 1;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 695, __pyx_L1_error)
  }
  __pyx_t_10 = __pyx_v_old_x;
  __pyx_t_11 = __pyx_v_old_y;
  __pyx_t_2 = -1;
  if (__pyx_t_10 < 0) {
    __pyx_t_10 += __pyx_v_type_grid.shape[0];
    if (unlikely(__pyx_t_10 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_10 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
  if (__pyx_t_11 < 0) {
    __pyx_t_11 += __pyx_v_type_grid.shape[1];
    if (unlikely(__pyx_t_11 < 0)) __pyx_t_2 = 1;
  } else if (unlikely(__pyx_t_11 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 695, __pyx_L1_error)
  }
  *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_10 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_11 * __pyx_v_type_grid.strides[1]) )) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_3 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_1 * __pyx_v_type_grid.strides[1]) )));
+696:     type_grid[new_x,new_y] = 0
  __pyx_t_1 = __pyx_v_new_x;
  __pyx_t_3 = __pyx_v_new_y;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_type_grid.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_type_grid.shape[0])) __pyx_t_2 = 0;
  if (__pyx_t_3 < 0) {
    __pyx_t_3 += __pyx_v_type_grid.shape[1];
    if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 1;
  } else if (unlikely(__pyx_t_3 >= __pyx_v_type_grid.shape[1])) __pyx_t_2 = 1;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 696, __pyx_L1_error)
  }
  *((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_type_grid.data + __pyx_t_1 * __pyx_v_type_grid.strides[0]) ) + __pyx_t_3 * __pyx_v_type_grid.strides[1]) )) = 0;
 697: 
+698:     return (energy_new + energy_old_empty) - (energy_old + energy_new_empty)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_12 = __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_12)) __PYX_ERR(0, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_r = __pyx_t_12;
  __pyx_t_12 = 0;
  goto __pyx_L0;
 699: 
 700: 
 701: 
+702: @cython.cdivision(True)
static int __pyx_f_5pimms_13mega_crank_2D_pbc_correction(int __pyx_v_value, int __pyx_v_DIM) {
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
 703: cdef int pbc_correction(int value, int DIM):
 704:     """
 705:     Performs intelligent periodic boundary correction
 706:     which FIRST checks to see if we have a negative
 707:     value and IF NOT uses the % operator - this means
 708:     we can use % without checking the sign giving
 709:     a 35% speedup per call
 710:     """
 711: 
+712:     if value < 0:
  __pyx_t_1 = (__pyx_v_value < 0);
  if (__pyx_t_1) {
/* … */
  }
+713:         return DIM+value
    __pyx_r = (__pyx_v_DIM + __pyx_v_value);
    goto __pyx_L0;
 714:     else:
+715:         return (value % DIM)
  /*else*/ {
    __pyx_r = (__pyx_v_value % __pyx_v_DIM);
    goto __pyx_L0;
  }
 716: 
 717: 
+718: @cython.wraparound(False)
static int __pyx_f_5pimms_13mega_crank_2D_do_positions_stradle_pbc_boundary_2D(__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_r;
 719: @cython.boundscheck(False)
 720: cdef int do_positions_stradle_pbc_boundary_2D(NUMPY_INT_TYPE[:,:] chain_positions, int chain_length):
 721:     """
 722:     For a set of positions returns true if the positions straddle a boundary
 723:     else return false
 724: 
 725:     """
 726: 
 727:     cdef int pidx
 728:     cdef int p1_x, p2_x, p1_y, p2_y
 729: 
 730: 
 731: 
+732:     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;
+733:         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]) )));
+734:         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]) )));
 735: 
+736:         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]) )));
+737:         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]) )));
 738: 
+739:         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, 739, __pyx_L1_error)
    __pyx_t_7 = (__pyx_t_6 > 1);
    if (__pyx_t_7) {
/* … */
    }
+740:             return 1
      __pyx_r = 1;
      goto __pyx_L0;
 741: 
+742:         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, 742, __pyx_L1_error)
    __pyx_t_7 = (__pyx_t_6 > 1);
    if (__pyx_t_7) {
/* … */
    }
  }
+743:             return 1
      __pyx_r = 1;
      goto __pyx_L0;
 744: 
+745:     return 0
  __pyx_r = 0;
  goto __pyx_L0;
 746: