不明白Python是如何调用这个C函数的

Don't understand how Python calls this C function

提问人:pippo1980 提问时间:9/18/2023 最后编辑:pippo1980 更新时间:9/18/2023 访问量:106

问:

请耐心等待,我只是想学习Python,但试图弄清楚一些软件是如何工作的(https://github.com/LBC-LNBio/pyKVFinder/tree/master)。

https://github.com/LBC-LNBio/pyKVFinder/blob/master/pyKVFinder/grid.py#L960,我有:grid.py

 ncav, cavities = _detect(
            nvoxels,
            nx,
            ny,
            nz,
            xyzr,
            P1,
            sincos,
            step,
            probe_in,
            probe_out,
            removal_distance,
            volume_cutoff,
            box_adjustment,
            P2,
            surface,
            nthreads,
            verbose,
        )

但来自 C 编译库(我相信)及其源代码:https://github.com/LBC-LNBio/pyKVFinder/blob/master/C/pyKVFinder.c#L989C1-L994C2_detect from _pyKVFinder import _detect, _detect_ladjpyKVFinder.c

/* Cavity detection */

/*
 * Function: _detect
 * -----------------
 *
 * Detect and cluster cavities
 *
 * PI: 3D grid
 * size: number of voxels in 3D grid
 * nx: x grid units
 * ny: y grid units
 * nz: z grid units
 * atoms: xyz coordinates and radii of input pdb
 * natoms: number of atoms
 * xyzr: number of data per atom (4: xyzr)
 * reference: xyz coordinates of 3D grid origin
 * ndims: number of coordinates (3: xyz)
 * sincos: sin and cos of 3D grid angles
 * nvalues: number of sin and cos (sina, cosa, sinb, cosb)
 * step: 3D grid spacing (A)
 * probe_in: Probe In size (A)
 * probe_out: Probe Out size (A)
 * removal_distance: Length to be removed from the cavity-bulk frontier (A)
 * volume_cutoff: Cavities volume filter (A3)
 * box_adjustment: Box adjustment mode
 * P2: xyz coordinates of x-axis vertice
 * nndims: number of coordinates (3: xyz)
 * is_ses: surface mode (1: SES or 0: SAS)
 * nthreads: number of threads for OpenMP
 * verbose: print extra information to standard output
 *
 * returns: PI[size] (cavities 3D grid) and ncav (number of cavities)
 */

int _detect(int *PI, int size, int nx, int ny, int nz, double *atoms,
            int natoms, int xyzr, double *reference, int ndims, double *sincos,
            int nvalues, double step, double probe_in, double probe_out,
            double removal_distance, double volume_cutoff, int box_adjustment,
            double *P2, int nndims, int is_ses, int nthreads, int verbose)
{

关于不同数量的参数和它们的不同顺序,我错过了什么?Python如何在这样的差异下获得正确的结果?我认为 Python C 绑定是由 SWIG 提供的。我应该强调的是,我根本不懂C语言,只是想弄清楚这个非常好的工具的引擎盖下发生了什么。

Python C 函数 参数 swig

评论

4赞 n. m. could be an AI 9/18/2023
一个具有二十几个参数的函数一点也不好。
2赞 101 9/18/2023
您可以尝试使用 .ctypes
2赞 Mark Tolonen 9/18/2023
Swig 可以配置为将 Python 整数列表转换为多个 C 参数,例如 .这可能是缺少参数的原因[1,2,3]int *PI, int size
0赞 pippo1980 9/18/2023
比如在?它应该如何阅读(意思是它有什么作用?%apply (int* ARGOUT_ARRAY1, int DIM1) {(int* PI, int size)}pyKVFinder.i
1赞 David Conrad 9/19/2023
@Kz2023这通常称为“参数对象”。

答: 暂无答案