PyObject *exterior_electron_density_region(PyObject *self, PyObject *args) { PyArrayObject* ai; PyArrayObject* aatom_c; PyArrayObject* beg_c; PyArrayObject* end_c; PyArrayObject* hh_c; PyArrayObject* vdWrad; if (!PyArg_ParseTuple(args, "OOOOOO", &ai, &aatom_c, &beg_c, &end_c, &hh_c, &vdWrad)) return NULL; long *aindex = LONGP(ai); int natoms = PyArray_DIM(aatom_c, 0); double *atom_c = DOUBLEP(aatom_c); long *beg = LONGP(beg_c); long *end = LONGP(end_c); double *h_c = DOUBLEP(hh_c); double *vdWradius = DOUBLEP(vdWrad); int n[3], ij; double pos[3]; for (int c = 0; c < 3; c++) { n[c] = end[c] - beg[c]; } // loop over all points for (int i = 0; i < n[0]; i++) { pos[0] = (beg[0] + i) * h_c[0]; for (int j = 0; j < n[1]; j++) { pos[1] = (beg[1] + j) * h_c[1]; ij = (i*n[1] + j)*n[2]; for (int k = 0; k < n[2]; k++) { pos[2] = (beg[2] + k) * h_c[2]; aindex[ij + k] = (long) 1; /* assume outside the structure */ // loop over all atoms for (int a=0; a < natoms; a++) { double d = distance(atom_c + a*3, pos); if (d < vdWradius[a]) { aindex[ij + k] = (long) 0; /* this is inside */ a = natoms; } } } } } Py_RETURN_NONE; }
static PyObject * imageop_crop(PyObject *self, PyObject *args) { char *cp, *ncp; short *nsp; Py_Int32 *nlp; int len, size, x, y, newx1, newx2, newy1, newy2, nlen; int ix, iy, xstep, ystep; PyObject *rv; if ( !PyArg_ParseTuple(args, "s#iiiiiii", &cp, &len, &size, &x, &y, &newx1, &newy1, &newx2, &newy2) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(ImageopError, "Size should be 1, 2 or 4"); return 0; } if ( !check_multiply_size(len, x, "x", y, "y", size) ) return 0; xstep = (newx1 < newx2)? 1 : -1; ystep = (newy1 < newy2)? 1 : -1; nlen = (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size; if ( !check_multiply_size(nlen, abs(newx2-newx1)+1, "abs(newx2-newx1)+1", abs(newy2-newy1)+1, "abs(newy2-newy1)+1", size) ) return 0; rv = PyString_FromStringAndSize(NULL, nlen); if ( rv == 0 ) return 0; ncp = (char *)PyString_AsString(rv); nsp = (short *)ncp; nlp = (Py_Int32 *)ncp; newy2 += ystep; newx2 += xstep; for( iy = newy1; iy != newy2; iy+=ystep ) { for ( ix = newx1; ix != newx2; ix+=xstep ) { if ( iy < 0 || iy >= y || ix < 0 || ix >= x ) { if ( size == 1 ) *ncp++ = 0; else *nlp++ = 0; } else { if ( size == 1 ) *ncp++ = *CHARP(cp, x, ix, iy); else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, ix, iy); else *nlp++ = *LONGP(cp, x, ix, iy); } } } return rv; }
static PyObject * imageop_scale(PyObject *self, PyObject *args) { char *cp, *ncp; short *nsp; Py_Int32 *nlp; int len, size, x, y, newx, newy, nlen; int ix, iy; int oix, oiy; PyObject *rv; if ( !PyArg_ParseTuple(args, "s#iiiii", &cp, &len, &size, &x, &y, &newx, &newy) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(ImageopError, "Size should be 1, 2 or 4"); return 0; } if ( !check_multiply_size(len, x, "x", y, "y", size) ) return 0; nlen = newx*newy*size; if ( !check_multiply_size(nlen, newx, "newx", newy, "newy", size) ) return 0; rv = PyString_FromStringAndSize(NULL, nlen); if ( rv == 0 ) return 0; ncp = (char *)PyString_AsString(rv); nsp = (short *)ncp; nlp = (Py_Int32 *)ncp; for( iy = 0; iy < newy; iy++ ) { for ( ix = 0; ix < newx; ix++ ) { oix = ix * x / newx; oiy = iy * y / newy; if ( size == 1 ) *ncp++ = *CHARP(cp, x, oix, oiy); else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, oix, oiy); else *nlp++ = *LONGP(cp, x, oix, oiy); } } return rv; }