def m2_(): mm = np.empty((480, 640), 'bool') speedup_ctypes.inrange(depth.ctypes.data_as(PTR(c_ushort)), mm.ctypes.data_as(PTR(c_byte)), bg['bgHi'].ctypes.data_as(PTR(c_ushort)), bg['bgLo'].ctypes.data_as(PTR(c_ushort)), 480 * 640) return mm
def gsl_idwt(x, family="haar", k=2, stride=1): # create a new array as GSL destroys input data, coerce to double too z = np.array(x, dtype=np.double) # allocate workspace and wavelet t = libgsl.gsl_wavelet_workspace_alloc(len(z)) w = libgsl.gsl_wavelet_alloc(_p_const(family), k) # do the transform libgsl.gsl_wavelet_transform_inverse(w, z.ctypes.data_as(PTR(c_double)), stride, len(z), t) # free objects libgsl.gsl_wavelet_free(w) libgsl.gsl_wavelet_workspace_free(t) # return result return z
class WSABUF(ctypes.Structure): _fields_ = [ ('len', ctypes.c_ulong), # u_long ('buf', PTR(ctypes.c_char)), # char FAR * ]
from ctypes import POINTER as PTR from ctypes import c_uint from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructDCluster, CStructDClusterBasis, CStructDClusterOperator) # ------------------------ CStructDClusterOperator._fields_ = [ ('t', PTR(CStructDCluster)), ('krow', PTR(c_uint)), ('kcol', PTR(c_uint)), ('dir', c_uint), ('C', PTR(CStructAMatrix)), ('sons', c_uint), ('son', PTR(PTR(CStructDClusterOperator))), ('refs', c_uint), ] # ------------------------ init_dclusteroperator = get_func('init_dclusteroperator', PTR(CStructDClusterOperator), [PTR(CStructDClusterOperator), PTR(CStructDCluster)]) init_leaf_dclusteroperator = get_func('init_leaf_dclusteroperator', PTR(CStructDClusterOperator), [PTR(CStructDClusterOperator), PTR(CStructDCluster)]) uninit_dclusteroperator = get_func('uninit_dclusteroperator', None, [PTR(CStructDClusterOperator)]) new_dclusteroperator = get_func('new_dclusteroperator', PTR(CStructDClusterOperator), [PTR(CStructDCluster)]) ref_dclusteroperator = get_func('ref_dclusteroperator', None, [PTR(PTR(CStructDClusterOperator)), PTR(CStructDClusterOperator)])
def inet_ntop(family, addrbytes): """converts raw bytes into IPv4 or IPv6 string""" addrstr = ctypes.create_string_buffer(80) # at least 46 bytes for IPv6 if not _inet_ntop(family, addrbytes, addrstr, ctypes.sizeof(addrstr)): raise ctypes.WinError(_WSAGetLastError()) return addrstr.value #=============================================================================== # WSASendTo #=============================================================================== _WSASendTo = winsockdll.WSASendTo _WSASendTo.argtypes = [ wintypes.HANDLE, # SOCKET s, PTR(WSABUF), # LPWSABUF lpBuffers, wintypes.DWORD, # DWORD dwBufferCount -- must be 1 PTR(wintypes.DWORD), # OUT LPDWORD lpNumberOfBytesSent -- must be NULL wintypes.DWORD, # DWORD dwFlags PTR(SockAddrIP4), # IN struct sockaddr *lpTo ctypes.c_int, # int iToLen PTR(OVERLAPPED), # IN LPWSAOVERLAPPED lpOverlapped wintypes. DWORD, # IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine -- must be NULL ] _WSASendTo.restype = ctypes.c_int # 0 means success def WSASendTo(hsock, data, sockaddr, overlapped, flags=0): """generic sendto (must pass a populated sockaddr object)""" buf = WSABUF(len(data), data)
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_bool, c_uint, c_void_p from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructBlock, CStructBlockEntry, CStructCluster) # ------------------------ CFuncAdmissible = CFUNCTYPE( c_bool, *(PTR(CStructCluster), PTR(CStructCluster), c_void_p)) CFuncBlockCallbackT = CFUNCTYPE( None, *(PTR(CStructBlock), c_uint, c_uint, c_uint, c_uint, c_void_p)) CFuncBlockEntryCallbackT = CFUNCTYPE( None, *(PTR(CStructBlockEntry), c_uint, c_void_p)) # ------------------------ CStructBlock._fields_ = [('rc', PTR(CStructCluster)), ('cc', PTR(CStructCluster)), ('a', c_bool), ('son', PTR(PTR(CStructBlock))), ('rsons', c_uint), ('csons', c_uint), ('desc', c_uint)] CStructBlockEntry._fields_ = [ ('b', PTR(CStructBlock)), ('bname', c_uint), ('rname', c_uint), ('cname', c_uint), ('father', PTR(CStructBlockEntry)), ('next', PTR(CStructBlockEntry)),
# ------------------------------------ norm2_matrix = get_func('norm2_matrix', real, [CFuncMvmT, c_void_p, c_uint, c_uint]) norm2diff_matrix = get_func( 'norm2diff_matrix', real, [CFuncMvmT, c_void_p, CFuncMvmT, c_void_p, c_uint, c_uint]) norm2diff_pre_matrix = get_func( 'norm2diff_pre_matrix', real, [CFuncMvmT, c_void_p, CFuncPrcdT, CFuncPrcdT, c_void_p, c_uint, c_uint]) norm2diff_id_pre_matrix = get_func( 'norm2diff_id_pre_matrix', real, [CFuncMvmT, c_void_p, CFuncPrcdT, CFuncPrcdT, c_void_p, c_uint, c_uint]) init_cg = get_func('init_cg', None, [ CFuncAddevalT, c_void_p, PTR(CStructAVector), PTR(CStructAVector), PTR(CStructAVector), PTR(CStructAVector), PTR(CStructAVector) ]) step_cg = get_func('step_cg', None, [ CFuncAddevalT, c_void_p, PTR(CStructAVector), PTR(CStructAVector), PTR(CStructAVector), PTR(CStructAVector), PTR(CStructAVector) ]) evalfunctional_cg = get_func('evalfunctional_cg', real, [ CFuncAddevalT, c_void_p,
from ctypes import POINTER as PTR from ctypes import c_uint, c_void_p from h2libpy.lib.bem3d import CEnumBasisFunctionBem3d from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructBem3d, CStructSurface3d # ------------------------ new_slp_laplace_bem3d = get_func('new_slp_laplace_bem3d', PTR(CStructBem3d), [ PTR(CStructSurface3d), c_uint, c_uint, CEnumBasisFunctionBem3d, CEnumBasisFunctionBem3d ]) new_dlp_laplace_bem3d = get_func('new_dlp_laplace_bem3d', PTR(CStructBem3d), [ PTR(CStructSurface3d), c_uint, c_uint, CEnumBasisFunctionBem3d, CEnumBasisFunctionBem3d, field ]) new_adlp_laplace_bem3d = get_func( 'new_adlp_laplace_bem3d', PTR(CStructBem3d), [ PTR(CStructSurface3d), c_uint, c_uint, CEnumBasisFunctionBem3d, CEnumBasisFunctionBem3d, field ]) del_laplace_bem3d = get_func('del_laplace_bem3d', None, [PTR(CStructBem3d)]) eval_dirichlet_linear_laplacebem3d = get_func( 'eval_dirichlet_linear_laplacebem3d', field, [PTR(real), PTR(real), c_void_p]) eval_neumann_linear_laplacebem3d = get_func( 'eval_neumann_linear_laplacebem3d', field, [PTR(real), PTR(real), c_void_p]) eval_dirichlet_quadratic_laplacebem3d = get_func(
def _decl(name, ret=None, args=()): fn = getattr(kernel32, name) fn.restype = ret fn.argtypes = args return fn CloseHandle = _decl("CloseHandle", BOOL, (HANDLE,)) CreateEvent = _decl("CreateEventW", HANDLE, (LPVOID, BOOL, BOOL, LPCWSTR)) CreateFile = _decl("CreateFileW", HANDLE, (LPCWSTR, DWORD, DWORD, LPVOID, DWORD, DWORD, HANDLE)) CreateNamedPipe = _decl("CreateNamedPipeW", HANDLE, (LPCWSTR, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPVOID)) ConnectNamedPipe = _decl("ConnectNamedPipe", BOOL, (HANDLE, LPOVERLAPPED)) WriteFile = _decl("WriteFile", BOOL, (HANDLE, LPCVOID, DWORD, PTR(DWORD), PTR(OVERLAPPED))) ReadFile = _decl("ReadFile", BOOL, (HANDLE, LPVOID, DWORD, PTR(DWORD), PTR(OVERLAPPED))) GetOverlappedResult = _decl("GetOverlappedResult", BOOL, (HANDLE, PTR(OVERLAPPED), PTR(DWORD), BOOL)) ERROR_IO_PENDING = 997 FILE_FLAG_OVERLAPPED = 0x40000000 FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000 GENERIC_READ = 0x80000000 GENERIC_WRITE = 0x40000000 INVALID_HANDLE_VALUE = -1 OPEN_EXISTING = 3 PIPE_ACCESS_DUPLEX = 0x00000003 PIPE_READMODE_BYTE = 0x00000000 PIPE_REJECT_REMOTE_CLIENTS = 0x00000008 PIPE_TYPE_BYTE = 0x00000000
def _get_inner_overlapped(ov): addr = id(ov) + _get_overlapped_offset() return ctypes.cast(addr, PTR(OVERLAPPED)).contents
from ctypes import POINTER as PTR from ctypes import c_bool, c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructAMatrix, CStructAVector # ------------------------ CStructAMatrix._fields_ = [('a', PTR(field)), ('ld', c_uint), ('rows', c_uint), ('cols', c_uint), ('owner', c_void_p)] # ------------------------ init_amatrix = get_func('init_amatrix', PTR(CStructAMatrix), [PTR(CStructAMatrix), c_uint, c_uint]) init_sub_amatrix = get_func( 'init_sub_amatrix', PTR(CStructAMatrix), [PTR(CStructAMatrix), PTR(CStructAMatrix), c_uint, c_uint, c_uint, c_uint]) init_vec_amatrix = get_func( 'init_vec_amatrix', PTR(CStructAMatrix), [PTR(CStructAMatrix), PTR(CStructAVector), c_uint, c_uint]) init_pointer_amatrix = get_func( 'init_pointer_amatrix', PTR(CStructAMatrix), [PTR(CStructAMatrix), PTR(field), c_uint, c_uint]) init_zero_amatrix = get_func('init_zero_amatrix', PTR(CStructAMatrix), [PTR(CStructAMatrix), c_uint, c_uint]) init_identity_amatrix = get_func('init_identity_amatrix', PTR(CStructAMatrix), [PTR(CStructAMatrix), c_uint, c_uint])
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_bool, c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructBlock, CStructCluster, CStructClusterBasis, CStructH2Matrix, CStructH2MatrixList, CStructHMatrix, CStructUniform) # ------------------------ CFuncH2MatrixCallbackT = CFUNCTYPE(None, *(PTR(CStructH2Matrix), c_uint, c_uint, c_uint, c_uint, c_void_p)) CFuncH2MatrixListCallbackT = CFUNCTYPE(None, *(PTR(CStructCluster), c_uint, c_uint, PTR(CStructH2MatrixList), c_void_p)) # ------------------------ CStructH2Matrix._fields_ = [ ('rb', PTR(CStructClusterBasis)), ('cb', PTR(CStructClusterBasis)), ('u', PTR(CStructUniform)), ('f', PTR(CStructAMatrix)), ('son', PTR(PTR(CStructH2Matrix))), ('rsons', c_uint), ('csons', c_uint), ('refs', c_uint),
import numpy as np import os from ctypes import POINTER as PTR, c_byte, c_ushort, c_size_t speedup_ctypes = np.ctypeslib.load_library('speedup_ctypes.so', os.path.dirname(__file__)) speedup_ctypes.inrange.argtypes = [ PTR(c_ushort), PTR(c_byte), PTR(c_ushort), PTR(c_ushort), c_size_t ] import speedup_cy def threshold_and_mask(depth, bg): import scipy from scipy.ndimage import binary_erosion def m_(): # Optimize this in C? return (depth > bg['bgLo']) & (depth < bg['bgHi']) # background def m2_(): mm = np.empty((480, 640), 'bool') speedup_ctypes.inrange(depth.ctypes.data_as(PTR(c_ushort)), mm.ctypes.data_as(PTR(c_byte)), bg['bgHi'].ctypes.data_as(PTR(c_ushort)), bg['bgLo'].ctypes.data_as(PTR(c_ushort)), 480 * 640) return mm
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructDBlock, CStructDCluster, CStructDClusterBasis, CStructDClusterOperator) # ------------------------ CFuncDClusterBasisCallbackT = CFUNCTYPE( None, *(PTR(CStructDClusterBasis), c_uint, c_uint, c_void_p)) # ------------------------ CStructDClusterBasis._fields_ = [ ('t', PTR(CStructDCluster)), ('directions', c_uint), ('k', PTR(c_uint)), ('koff', PTR(c_uint)), ('ktree', c_uint), ('kbranch', c_uint), ('V', PTR(CStructAMatrix)), ('E', PTR(PTR(CStructAMatrix))), ('sons', c_uint), ('son', PTR(PTR(CStructDClusterBasis))), ('dirson', PTR(PTR(c_uint))), ]
from ctypes import POINTER as PTR from ctypes import c_bool, c_char_p, c_size_t, c_uint from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructBlock, CStructCluster, CStructHMatrix, CStructRkMatrix, CStructSparseMatrix) # ------------------------ CStructHMatrix._fields_ = [ ('rc', PTR(CStructCluster)), ('cc', PTR(CStructCluster)), ('r', PTR(CStructRkMatrix)), ('f', PTR(CStructAMatrix)), ('son', PTR(PTR(CStructHMatrix))), ('rsons', c_uint), ('csons', c_uint), ('refs', c_uint), ('desc', c_uint), ] # ------------------------ init_hmatrix = get_func( 'init_hmatrix', PTR(CStructHMatrix), [PTR(CStructHMatrix), PTR(CStructCluster), PTR(CStructCluster)])
from ctypes import POINTER as PTR from ctypes import c_uint, c_void_p from h2libpy.lib.krylov import CFuncAddevalT, CFuncPrcdT from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructDH2Matrix, CStructH2Matrix, CStructHMatrix, CStructSparseMatrix) # ------------------------ solve_cg_avector = get_func('solve_cg_avector', c_uint, [ c_void_p, CFuncAddevalT, PTR(CStructAVector), PTR(CStructAVector), real, c_uint ]) solve_cg_amatrix_avector = get_func('solve_cg_amatrix_avector', c_uint, [ PTR(CStructAMatrix), PTR(CStructAVector), PTR(CStructAVector), real, c_uint ]) solve_cg_sparsematrix_avector = get_func('solve_cg_sparsematrix_avector', c_uint, [ PTR(CStructSparseMatrix), PTR(CStructAVector), PTR(CStructAVector), real, c_uint ]) solve_cg_hmatrix_avector = get_func('solve_cg_hmatrix_avector', c_uint, [ PTR(CStructHMatrix), PTR(CStructAVector),
import numpy as np import preprocess import opencl import lattice import config import os import dataset import stencil from ctypes import POINTER as PTR, c_byte, c_size_t, c_float speedup_ctypes = np.ctypeslib.load_library('speedup_ctypes.so', os.path.dirname(__file__)) speedup_ctypes.histogram.argtypes = [ PTR(c_byte), PTR(c_float), PTR(c_float), c_size_t, c_size_t, c_size_t, c_size_t ] def initialize(): b_width = [config.bounds[1][i] - config.bounds[0][i] for i in range(3)] global occ, vac, color, color_count, previous_estimate, good_alignment occ = np.zeros(b_width) > 0 vac = np.zeros(b_width) > 0 color = np.zeros((b_width[0], b_width[1], b_width[2], 3), 'u1') color_count = np.zeros(b_width, 'i') good_alignment = False previous_estimate = None
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_bool, c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructBlock, CStructDClusterBasis, CStructDClusterOperator, CStructDH2Matrix, CStructDUniform, CStructTruncMode) # ------------------------ CFuncDH2MatrixCallbackT = CFUNCTYPE( None, *(PTR(CStructDH2Matrix), c_uint, c_uint, c_uint, c_uint, c_void_p)) # ------------------------ CStructDH2Matrix._fields_ = [ ('rb', PTR(CStructDClusterBasis)), ('cb', PTR(CStructDClusterBasis)), ('u', PTR(CStructDUniform)), ('f', PTR(CStructAMatrix)), ('son', PTR(PTR(CStructDH2Matrix))), ('rsons', c_uint), ('csons', c_uint), ('desc', c_uint), ] # ------------------------
CEnumBasisFunctionBem3d, CStructAdmisBlock, CStructAMatrix, CStructAprxBem3d, CStructAVector, CStructBem3d, CStructBlock, CStructCluster, CStructClusterBasis, CStructClusterGeometry, CStructClusterOperator, CStructCompData, CStructDBlock, CStructDClusterBasis, CStructDClusterOperator, CStructDH2Matrix, CStructGreenCluster3d, CStructGreenClusterBasis3d, CStructH2Matrix, CStructHMatrix, CStructKernelBem3d, CStructListNode, CStructParBem3d, CStructRealAVector, CStructRkMatrix, CStructSingQuad2d, CStructSparseMatrix, CStructSurface3d, CStructTriList, CStructTruncMode, CStructVertList) # ------------------------------------ CFuncQuadPoints3d = CFUNCTYPE( None, *(PTR(CStructBem3d), real * 3, real * 3, real, PTR(PTR(real)) * 3, PTR(PTR(real)) * 3)) CFuncBoundaryFunc3d = CFUNCTYPE(field, *(PTR(real), PTR(real), c_void_p)) CFuncKernelFunc3d = CFUNCTYPE( field, *(PTR(real), PTR(real), PTR(real), PTR(real), c_void_p)) CFuncKernelWaveFunc3d = CFUNCTYPE( field, *(PTR(real), PTR(real), PTR(real), PTR(real), PTR(real), c_void_p)) CFuncNearField = CFUNCTYPE( None, *(PTR(c_uint), PTR(c_uint), PTR(CStructBem3d), c_bool, PTR(CStructAMatrix))) CFuncFarFieldRk = CFUNCTYPE( None, *(PTR(CStructCluster), c_uint, PTR(CStructCluster), c_uint, PTR(CStructBem3d), PTR(CStructRkMatrix)))
from ctypes import POINTER as PTR from ctypes import c_size_t, c_uint from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructCluster, CStructDCluster, CStructLevelDir) # ------------------------ CStructDCluster._fields_ = [ ('size', c_uint), ('idx', PTR(c_uint)), ('sons', c_uint), ('son', PTR(PTR(CStructDCluster))), ('dim', c_uint), ('bmin', PTR(real)), ('bmax', PTR(real)), ('directions', c_uint), ('dir', PTR(PTR(real))), ('dirson', PTR(PTR(c_uint))), ('desc', c_uint), ] CStructLevelDir._fields_ = [('depth', c_uint), ('dim', c_uint), ('maxdiam', PTR(real)), ('splits', PTR(c_uint)), ('directions', PTR(c_uint)), ('dir', PTR(PTR(PTR(real)))), ('dirmem', PTR(real))] # ------------------------
import ctypes import os from ctypes import POINTER as PTR from ctypes import c_char, c_int # Root folder of this module root = os.path.join(os.path.dirname(__file__), '..') # Init h2lib and load library instance lib = ctypes.CDLL(os.path.join(root, 'h2libpy/libh2.so')) init_h2lib = lib.init_h2lib init_h2lib.restype = None init_h2lib.argtypes = [PTR(c_int), PTR(PTR(PTR(c_char)))] init_h2lib(c_int(0), None)
except ImportError: # Fallback for python before version 2.7 from distutils.sysconfig import get_config_var from itertools import islice from ctypes import (cdll, CDLL, RTLD_GLOBAL, POINTER as PTR, CFUNCTYPE as CFT, Structure, cast, pointer, byref, c_int, c_uint, c_float, c_double, c_char, c_char_p, c_void_p) from ctypes.util import find_library # Maybe a bit ugly. Is there a more kosher way of making sure that the # libstdc++ (or similar) symbols are available to the molfile-plugins? _cxx = CDLL(find_library('stdc++'), mode=RTLD_GLOBAL) c_int_p = PTR(c_int) c_int_pp = PTR(c_int_p) c_char_pp = PTR(c_char_p) c_char_ppp = PTR(c_char_pp) c_float_p = PTR(c_float) c_float_pp = PTR(c_float_p) # # As of molfile_plugin abiversion 16, the following trajectory # formats are supported (pasted from the AMD web page): # # Molecular Dynamics Trajectory File Plugins # # AMBER 'binpos' trajectory reader (.binpos) # AMBER "CRD" trajectory reader (.crd, .crdbox) # AMBER NetCDF trajectory reader (.nc)
from ctypes import POINTER as PTR from ctypes import c_bool, c_char_p, c_size_t, c_uint from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructSparseMatrix, CStructSparsePattern) # ------------------------ CStructSparseMatrix._fields_ = [('rows', c_uint), ('cols', c_uint), ('nz', c_uint), ('row', PTR(c_uint)), ('col', PTR(c_uint)), ('coeff', PTR(field))] # ------------------------ new_raw_sparsematrix = get_func('new_raw_sparsematrix', PTR(CStructSparseMatrix), [c_uint, c_uint, c_uint]) new_identity_sparsematrix = get_func('new_identity_sparsematrix', PTR(CStructSparseMatrix), [c_uint, c_uint]) new_zero_sparsematrix = get_func('new_zero_sparsematrix', PTR(CStructSparseMatrix), [PTR(CStructSparsePattern)]) del_sparsematrix = get_func('del_sparsematrix', None, [PTR(CStructSparseMatrix)]) addentry_sparsematrix = get_func( 'addentry_sparsematrix', field, [PTR(CStructSparseMatrix), c_uint, c_uint, field])
class molfile_timestep_t(Structure): _fields_ = [('coords', PTR(c_float)), ('velocities', PTR(c_float)), ('A', c_float), ('B', c_float), ('C', c_float), ('alpha', c_float), ('beta', c_float), ('gamma', c_float), ('physical_time', c_double)]
import numpy as np import preprocess import opencl import lattice import config import os import dataset import stencil from ctypes import POINTER as PTR, c_byte, c_size_t, c_float speedup_ctypes = np.ctypeslib.load_library('speedup_ctypes.so', os.path.dirname(__file__)) speedup_ctypes.histogram.argtypes = [PTR(c_byte), PTR(c_float), PTR(c_float), c_size_t, c_size_t, c_size_t, c_size_t] def initialize(): b_width = [config.bounds[1][i]-config.bounds[0][i] for i in range(3)] global occ, vac, color, color_count, previous_estimate, good_alignment occ = np.zeros(b_width)>0 vac = np.zeros(b_width)>0 color = np.zeros((b_width[0], b_width[1], b_width[2], 3),'u1') color_count = np.zeros(b_width,'i') good_alignment = False previous_estimate = None if not 'previous_estimate' in globals():
class molfile_plugin_t(Structure): # ABI from molfile abiversion 16 # This is the important(TM) structure. # Only partial read support is considered for now, other # functions have been replaced by a dummy_fun_t placeholder. _fields_ = [ ('abiversion', c_int), ('type', c_char_p), ('name', c_char_p), ('prettyname', c_char_p), ('author', c_char_p), ('majorv', c_int), ('minorv', c_int), ('is_reentrant', c_int), ('filename_extension', c_char_p), # # void *(* open_file_read)(const char *filepath, const char *filetype, int *natoms); ('open_file_read', CFT(c_void_p, c_char_p, c_char_p, c_int_p)), # # int (*read_structure)(void *, int *optflags, molfile_atom_t *atoms); ('read_structure', CFT(c_int, c_void_p, c_int_p, PTR(molfile_atom_t))), # # int (*read_bonds)(void *, int *nbonds, int **from, int **to, float **bondorder, # int **bondtype, int *nbondtypes, char ***bondtypename); ('read_bonds', dummy_fun_t), # # int (* read_next_timestep)(void *, int natoms, molfile_timestep_t *); ('read_next_timestep', CFT(c_int, c_void_p, c_int, PTR(molfile_timestep_t))), # # void (* close_file_read)(void *); ('close_file_read', CFT(None, c_void_p)), # # void *(* open_file_write)(const char *filepath, const char *filetype, # int natoms); ('open_file_write', dummy_fun_t), # # int (* write_structure)(void *, int optflags, const molfile_atom_t *atoms); ('write_structure', dummy_fun_t), # # int (* write_timestep)(void *, const molfile_timestep_t *); ('write_timestep', dummy_fun_t), # # void (* close_file_write)(void *); ('close_file_write', dummy_fun_t), # # int (* read_volumetric_metadata)(void *, int *nsets, # molfile_volumetric_t **metadata); ('read_volumetric_metadata', CFT(c_int, c_void_p, c_int_p, PTR(PTR(molfile_volumetric_t)))), # # int (* read_volumetric_data)(void *, int set, float *datablock, # float *colorblock); ('read_volumetric_data', CFT(c_int, c_void_p, c_int, c_float_p, c_float_p)), # # int (* read_rawgraphics)(void *, int *nelem, const molfile_graphics_t **data); ('read_rawgraphics', dummy_fun_t), # # int (* read_molecule_metadata)(void *, molfile_metadata_t **metadata); ('read_molecule_metadata', CFT(c_int, c_void_p, PTR(PTR(molfile_metadata_t)))), # # int (* write_bonds)(void *, int nbonds, int *from, int *to, float *bondorder, # int *bondtype, int nbondtypes, char **bondtypename); ('write_bonds', dummy_fun_t), # # int (* write_volumetric_data)(void *, molfile_volumetric_t *metadata, # float *datablock, float *colorblock); ('write_volumetric_data', dummy_fun_t), # # int (* read_angles)(void *handle, int *numangles, int **angles, int **angletypes, # int *numangletypes, char ***angletypenames, int *numdihedrals, # int **dihedrals, int **dihedraltypes, int *numdihedraltypes, # char ***dihedraltypenames, int *numimpropers, int **impropers, # int **impropertypes, int *numimpropertypes, char ***impropertypenames, # int *numcterms, int **cterms, int *ctermcols, int *ctermrows); ('read_angles', dummy_fun_t), # # int (* write_angles)(void *handle, int numangles, const int *angles, const int *angletypes, # int numangletypes, const char **angletypenames, int numdihedrals, # const int *dihedrals, const int *dihedraltypes, int numdihedraltypes, # const char **dihedraltypenames, int numimpropers, # const int *impropers, const int *impropertypes, int numimpropertypes, # const char **impropertypenames, int numcterms, const int *cterms, # int ctermcols, int ctermrows); ('write_angles', dummy_fun_t), # # int (* read_qm_metadata)(void *, molfile_qm_metadata_t *metadata); ('read_qm_metadata', dummy_fun_t), # # int (* read_qm_rundata)(void *, molfile_qm_t *qmdata); ('read_qm_rundata', dummy_fun_t), # # int (* read_timestep)(void *, int natoms, molfile_timestep_t *, # molfile_qm_metadata_t *, molfile_qm_timestep_t *); ('read_timestep', CFT(c_int, c_void_p, c_int, PTR(molfile_timestep_t), PTR(molfile_qm_metadata_t), PTR(molfile_qm_timestep_t))), # # int (* read_timestep_metadata)(void *, molfile_timestep_metadata_t *); ('read_timestep_metadata', CFT(c_int, c_void_p, PTR(molfile_timestep_metadata_t))), # # int (* read_qm_timestep_metadata)(void *, molfile_qm_timestep_metadata_t *); ('read_qm_timestep_metadata', dummy_fun_t), # # int (* cons_fputs)(const int, const char*); ('cons_fputs', CFT(c_int, c_int, c_char_p)) ]
fn = getattr(kernel32, name) fn.restype = ret fn.argtypes = args return fn CloseHandle = _decl("CloseHandle", BOOL, (HANDLE, )) CreateEvent = _decl("CreateEventW", HANDLE, (LPVOID, BOOL, BOOL, LPCWSTR)) CreateFile = _decl("CreateFileW", HANDLE, (LPCWSTR, DWORD, DWORD, LPVOID, DWORD, DWORD, HANDLE)) CreateNamedPipe = _decl( "CreateNamedPipeW", HANDLE, (LPCWSTR, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPVOID)) ConnectNamedPipe = _decl("ConnectNamedPipe", BOOL, (HANDLE, LPOVERLAPPED)) WriteFile = _decl("WriteFile", BOOL, (HANDLE, LPCVOID, DWORD, PTR(DWORD), PTR(OVERLAPPED))) ReadFile = _decl("ReadFile", BOOL, (HANDLE, LPVOID, DWORD, PTR(DWORD), PTR(OVERLAPPED))) GetOverlappedResult = _decl("GetOverlappedResult", BOOL, (HANDLE, PTR(OVERLAPPED), PTR(DWORD), BOOL)) ERROR_ACCESS_DENIED = 5 ERROR_IO_PENDING = 997 FILE_FLAG_OVERLAPPED = 0x40000000 FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000 GENERIC_READ = 0x80000000 GENERIC_WRITE = 0x40000000 INVALID_HANDLE_VALUE = -1 OPEN_EXISTING = 3 PIPE_ACCESS_DUPLEX = 0x00000003 PIPE_READMODE_BYTE = 0x00000000 PIPE_REJECT_REMOTE_CLIENTS = 0x00000008
def py_reg_cb(v, p): pc = p.contents if pc.type == MOLFILE_PLUGIN_TYPE: if pc.abiversion >= MIN_ABI_VERSION: plugin_p.contents = cast(p, PTR(molfile_plugin_t)).contents return VMDPLUGIN_SUCCESS
from ctypes import POINTER as PTR from ctypes import c_size_t, c_uint from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructDClusterBasis, CStructDClusterOperator, CStructDUniform) # ------------------------ CStructDUniform._fields_ = [ ('rb', PTR(CStructDClusterBasis)), ('cb', PTR(CStructDClusterBasis)), ('rd', c_uint), ('cd', c_uint), ('S', CStructAMatrix), ] # ------------------------ new_duniform = get_func( 'new_duniform', PTR(CStructDUniform), [PTR(CStructDClusterBasis), c_uint, PTR(CStructDClusterBasis), c_uint]) del_duniform = get_func('del_duniform', None, [PTR(CStructDUniform)]) getsize_duniform = get_func('getsize_duniform', c_size_t, [PTR(CStructDUniform)]) clear_duniform = get_func('clear_duniform', None, [PTR(CStructDUniform)]) copy_duniform = get_func( 'copy_duniform', None,
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_uint, c_void_p from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CEnumClusterMode, CStructCluster, CStructClusterGeometry) # ------------------------ CFuncClusterCallbackT = CFUNCTYPE(None, *(PTR(CStructCluster), c_uint, c_void_p)) CEnumClusterMode.H2_ADAPTIVE = CEnumClusterMode(0) CEnumClusterMode.H2_REGULAR = CEnumClusterMode(1) CEnumClusterMode.H2_SIMSUB = CEnumClusterMode(2) CEnumClusterMode.H2_PCA = CEnumClusterMode(3) # ------------------------ CStructCluster._fields_ = [ ('size', c_uint), ('idx', PTR(c_uint)), ('sons', c_uint), ('dim', c_uint), ('bmin', PTR(real)), ('bmax', PTR(real)), ('desc', c_uint),