mt_fast_calc.pyx 859 Bytes
Newer Older
eric pellegrini's avatar
eric pellegrini committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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): 
    
16
17
    cdef int at, nbatom, atom, i, j, k
    cdef double Xpos, Ypos, Zpos, mx, my, mz
eric pellegrini's avatar
eric pellegrini committed
18
19
20
21
22
23
24
25
    
    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.
26
27
28
29
        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