mt_fast_calc.pyx 1.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# **************************************************************************
#
# MDANSE: Molecular Dynamics Analysis for Neutron Scattering Experiments
#
# @file      Extensions/mt_fast_calc.pyx
# @brief     Implements module/class/test mt_fast_calc
#
# @homepage  https://mdanse.org
# @license   GNU General Public License v3 or higher (see LICENSE)
# @copyright Institut Laue Langevin 2013-now
# @authors   Scientific Computing Group at ILL (see AUTHORS)
#
# **************************************************************************

eric pellegrini's avatar
eric pellegrini committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import cython
cimport numpy as np 
import numpy as np
from numpy cimport ndarray

cdef extern from "math.h":
    double floor(double x)
    double ceil(double x)

@cython.boundscheck(False)
@cython.wraparound(False)
def mt(ndarray[np.float64_t, ndim = 2] config not None,
       ndarray[np.int32_t, ndim = 3] grid not None,
       double resolution,ndarray[np.float64_t, ndim = 1] mini not None): 
    
30 31
    cdef int at, nbatom, atom, i, j, k
    cdef double Xpos, Ypos, Zpos, mx, my, mz
eric pellegrini's avatar
eric pellegrini committed
32 33 34 35 36 37 38 39
    
    mx = mini[0] 
    my = mini[1]
    mz = mini[2]
    
    nbatom = config.shape[0]
    for atom in range(nbatom):
        # The  of atoms |i| in the current configuration.
40 41 42 43
        i = int(floor((config[atom,0]-mx)/resolution))
        j = int(floor((config[atom,1]-my)/resolution))
        k = int(floor((config[atom,2]-mz)/resolution))
        grid[i][j][k] += 1