Commit 9d450070 authored by Berk Onat's avatar Berk Onat
Browse files

Add PyMolfileCapsule and destructure for molfile_plugin handle

parent c64460e2
cmake_minimum_required(VERSION 2.8.12)
project(molfile)
# Set source directory
set(SOURCE_DIR "molfile")
# Tell CMake that headers are also in SOURCE_DIR
include_directories(${SOURCE_DIR}, "./vmd_molfile_plugin/molfile_plugin/include", "./vmd_molfile_plugin/molfile_plugin/lib")
set(SOURCES "${SOURCE_DIR}/libpymolfile_wrap.cxx", "${SOURCE_DIR}/pymolfile.c")
...@@ -12,3 +12,5 @@ from . import pymolfile ...@@ -12,3 +12,5 @@ from . import pymolfile
__all__ = [ "pymolfile" ] __all__ = [ "pymolfile" ]
from .pymolfile import OpenMolfile, list_plugins
No preview for this file type
...@@ -68,64 +68,6 @@ extern PyObject* get_plugin(PyObject* molcapsule, int plug_no); ...@@ -68,64 +68,6 @@ extern PyObject* get_plugin(PyObject* molcapsule, int plug_no);
%feature("autodoc", "0") molfile_plugin_info; %feature("autodoc", "0") molfile_plugin_info;
extern PyObject * molfile_plugin_info(PyObject* molcapsule, int plugin_no); extern PyObject * molfile_plugin_info(PyObject* molcapsule, int plugin_no);
/*
%exception molfile_plugin_info {
$action
if (PyErr_Occurred()) SWIG_fail;
}
%inline %{
PyObject * molfile_plugin_info(PyObject* molcapsule, int plugin_no) {
molfile_plugin_t *plugin;
molfile_plugin_t** plugin_list = (molfile_plugin_t**) PyMolfileCapsule_AsVoidPtr(molcapsule);
int *plugno = &plugin_no;
int has_readstructure = 0;
int has_readbonds = 0;
int has_readangles = 0;
int has_writestructure = 0;
int has_writebonds = 0;
int has_writeangles = 0;
int has_readnexttimestep = 0;
int has_writetimestep = 0;
int plugin_list_size = sizeof(plugin_list) / sizeof(molfile_plugin_t**);
if (plugno==NULL || plugin_no<0){
PyErr_Format(PyExc_IOError, "Error: molfile plugin handle no should be given, be positive value and should not exceed the list length'%d'. You set '%d'", plugin_list_size, plugin_no);
return 0;
}
plugin = plugin_list[plugin_no];
if(plugin==NULL || !plugin->open_file_read){
PyErr_Format(PyExc_IOError, "Error: molfile plugin '%d' is not initialized.", plugin_no);
return 0;
}
if (plugin->read_structure) has_readstructure = 1;
if (plugin->read_bonds) has_readbonds = 1;
if (plugin->read_angles) has_readangles = 1;
if (plugin->read_next_timestep) has_readnexttimestep = 1;
if (plugin->write_structure) has_writestructure = 1;
if (plugin->write_bonds) has_writebonds = 1;
if (plugin->write_angles) has_writeangles = 1;
if (plugin->write_timestep) has_writetimestep = 1;
PyObject *tuple = PyTuple_New(17);
PyTuple_SET_ITEM(tuple, 0, PyString_FromString(plugin->filename_extension));
PyTuple_SET_ITEM(tuple, 1, PyString_FromString(plugin->name));
PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong((long)has_readstructure));
PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong((long)has_readbonds));
PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong((long)has_readangles));
PyTuple_SET_ITEM(tuple, 5, PyInt_FromLong((long)has_readnexttimestep));
PyTuple_SET_ITEM(tuple, 6, PyInt_FromLong((long)has_writestructure));
PyTuple_SET_ITEM(tuple, 7, PyInt_FromLong((long)has_writebonds));
PyTuple_SET_ITEM(tuple, 8, PyInt_FromLong((long)has_writeangles));
PyTuple_SET_ITEM(tuple, 9, PyInt_FromLong((long)has_writetimestep));
PyTuple_SET_ITEM(tuple, 10, PyString_FromString(plugin->prettyname));
PyTuple_SET_ITEM(tuple, 11, PyString_FromString(plugin->type));
PyTuple_SET_ITEM(tuple, 12, PyString_FromString(plugin->author));
PyTuple_SET_ITEM(tuple, 13, PyInt_FromLong((long)plugin->majorv));
PyTuple_SET_ITEM(tuple, 14, PyInt_FromLong((long)plugin->minorv));
PyTuple_SET_ITEM(tuple, 15, PyInt_FromLong((long)plugin->abiversion));
PyTuple_SET_ITEM(tuple, 16, PyInt_FromLong((long)plugin->is_reentrant));
return tuple;
}
%}
*/
%feature("autodoc", "0") my_open_file_read; %feature("autodoc", "0") my_open_file_read;
...@@ -140,13 +82,18 @@ PyObject * my_open_file_read(PyObject* molcapsule, char* fname, char* ftype, int ...@@ -140,13 +82,18 @@ PyObject * my_open_file_read(PyObject* molcapsule, char* fname, char* ftype, int
return NULL; return NULL;
PyTypeObject *type = &MolObjectType; PyTypeObject *type = &MolObjectType;
MolObject *plugin_c; MolObject *plugin_c;
molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(molcapsule); molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(molcapsule);
plugin_c = (MolObject *)type->tp_alloc(type, 0); plugin_c = (MolObject *)type->tp_alloc(type, 0);
plugin_c->plugin = plugin; /*plugin_c->plugin = plugin;*/
plugin_c->file_handle = plugin->open_file_read(fname, ftype, &natoms); plugin_c->plugin = molcapsule;
plugin_c->natoms = natoms; void *file_handle = plugin->open_file_read(fname, ftype, &natoms);
PyObject* plugin_handle = (PyObject *)plugin_c; plugin_c->file_handle = PyMolfileCapsule_FromVoidPtr(file_handle, del_molfile_file_handle);
return plugin_handle; if (!plugin_c->file_handle) {
Py_RETURN_NONE;
} else {
plugin_c->natoms = natoms;
return (PyObject *)plugin_c;
}
} }
%} %}
...@@ -158,18 +105,15 @@ PyObject * my_open_file_read(PyObject* molcapsule, char* fname, char* ftype, int ...@@ -158,18 +105,15 @@ PyObject * my_open_file_read(PyObject* molcapsule, char* fname, char* ftype, int
} }
%inline %{ %inline %{
PyObject * my_close_file_read(PyObject* molpack) { PyObject * my_close_file_read(PyObject* molpack) {
molfile_plugin_t* plugin;
void* file_handle;
int numatoms;
MolObject* plugin_handle = (MolObject*) molpack; MolObject* plugin_handle = (MolObject*) molpack;
plugin = plugin_handle->plugin; PyObject* plugincapsule = plugin_handle->plugin;
file_handle = plugin_handle->file_handle; PyObject* filecapsule = plugin_handle->file_handle;
numatoms = plugin_handle->natoms; molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugincapsule);
Py_INCREF(plugin_handle); void *file_handle = (void*) PyMolfileCapsule_AsVoidPtr(filecapsule);
plugin->close_file_read(file_handle); plugin->close_file_read(file_handle);
Py_DECREF(plugin_handle); Py_XDECREF(filecapsule);
/*Py_DECREF(molpack);*/ Py_XDECREF(plugin_handle->file_handle);
Py_RETURN_NONE; return (PyObject *)plugin_handle;
} }
%} %}
...@@ -185,9 +129,9 @@ extern PyObject * read_fill_angles(PyObject* molpack); ...@@ -185,9 +129,9 @@ extern PyObject * read_fill_angles(PyObject* molpack);
%feature("autodoc", "0") read_fill_next_timestep; %feature("autodoc", "0") read_fill_next_timestep;
extern PyObject * read_fill_next_timestep(PyObject* molpack); extern PyObject * read_fill_next_timestep(PyObject* molpack);
%feature("autodoc", "0") is_plugin_same; %feature("autodoc", "0") are_plugins_same;
PyObject* is_plugin_same(PyObject* molpack_a, PyObject* molpack_b); PyObject* are_plugins_same(PyObject* molpack_a, PyObject* molpack_b);
%feature("autodoc", "0") is_filehandle_same; %feature("autodoc", "0") are_filehandles_same;
PyObject* is_filehandle_same(PyObject* molpack_a, PyObject* molpack_b); PyObject* are_filehandles_same(PyObject* molpack_a, PyObject* molpack_b);
...@@ -151,13 +151,13 @@ def read_fill_next_timestep(molpack: 'PyObject *') -> "PyObject *": ...@@ -151,13 +151,13 @@ def read_fill_next_timestep(molpack: 'PyObject *') -> "PyObject *":
"""read_fill_next_timestep(molpack) -> PyObject *""" """read_fill_next_timestep(molpack) -> PyObject *"""
return _libpymolfile.read_fill_next_timestep(molpack) return _libpymolfile.read_fill_next_timestep(molpack)
def is_plugin_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *": def are_plugins_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *":
"""is_plugin_same(molpack_a, molpack_b) -> PyObject *""" """are_plugins_same(molpack_a, molpack_b) -> PyObject *"""
return _libpymolfile.is_plugin_same(molpack_a, molpack_b) return _libpymolfile.are_plugins_same(molpack_a, molpack_b)
def is_filehandle_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *": def are_filehandles_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *":
"""is_filehandle_same(molpack_a, molpack_b) -> PyObject *""" """are_filehandles_same(molpack_a, molpack_b) -> PyObject *"""
return _libpymolfile.is_filehandle_same(molpack_a, molpack_b) return _libpymolfile.are_filehandles_same(molpack_a, molpack_b)
# This file is compatible with both classic and new-style classes. # This file is compatible with both classic and new-style classes.
...@@ -3298,13 +3298,18 @@ PyObject * my_open_file_read(PyObject* molcapsule, char* fname, char* ftype, int ...@@ -3298,13 +3298,18 @@ PyObject * my_open_file_read(PyObject* molcapsule, char* fname, char* ftype, int
return NULL; return NULL;
PyTypeObject *type = &MolObjectType; PyTypeObject *type = &MolObjectType;
MolObject *plugin_c; MolObject *plugin_c;
molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(molcapsule); molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(molcapsule);
plugin_c = (MolObject *)type->tp_alloc(type, 0); plugin_c = (MolObject *)type->tp_alloc(type, 0);
plugin_c->plugin = plugin; /*plugin_c->plugin = plugin;*/
plugin_c->file_handle = plugin->open_file_read(fname, ftype, &natoms); plugin_c->plugin = molcapsule;
plugin_c->natoms = natoms; void *file_handle = plugin->open_file_read(fname, ftype, &natoms);
PyObject* plugin_handle = (PyObject *)plugin_c; plugin_c->file_handle = PyMolfileCapsule_FromVoidPtr(file_handle, del_molfile_file_handle);
return plugin_handle; if (!plugin_c->file_handle) {
Py_RETURN_NONE;
} else {
plugin_c->natoms = natoms;
return (PyObject *)plugin_c;
}
} }
...@@ -3438,18 +3443,15 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) ...@@ -3438,18 +3443,15 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
PyObject * my_close_file_read(PyObject* molpack) { PyObject * my_close_file_read(PyObject* molpack) {
molfile_plugin_t* plugin;
void* file_handle;
int numatoms;
MolObject* plugin_handle = (MolObject*) molpack; MolObject* plugin_handle = (MolObject*) molpack;
plugin = plugin_handle->plugin; PyObject* plugincapsule = plugin_handle->plugin;
file_handle = plugin_handle->file_handle; PyObject* filecapsule = plugin_handle->file_handle;
numatoms = plugin_handle->natoms; molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugincapsule);
Py_INCREF(plugin_handle); void *file_handle = (void*) PyMolfileCapsule_AsVoidPtr(filecapsule);
plugin->close_file_read(file_handle); plugin->close_file_read(file_handle);
Py_DECREF(plugin_handle); Py_XDECREF(filecapsule);
/*Py_DECREF(molpack);*/ Py_XDECREF(plugin_handle->file_handle);
Py_RETURN_NONE; return (PyObject *)plugin_handle;
} }
#ifdef __cplusplus #ifdef __cplusplus
...@@ -3691,7 +3693,7 @@ fail: ...@@ -3691,7 +3693,7 @@ fail:
} }
SWIGINTERN PyObject *_wrap_is_plugin_same(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { SWIGINTERN PyObject *_wrap_are_plugins_same(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0; PyObject *resultobj = 0;
PyObject *arg1 = (PyObject *) 0 ; PyObject *arg1 = (PyObject *) 0 ;
PyObject *arg2 = (PyObject *) 0 ; PyObject *arg2 = (PyObject *) 0 ;
...@@ -3699,10 +3701,10 @@ SWIGINTERN PyObject *_wrap_is_plugin_same(PyObject *SWIGUNUSEDPARM(self), PyObje ...@@ -3699,10 +3701,10 @@ SWIGINTERN PyObject *_wrap_is_plugin_same(PyObject *SWIGUNUSEDPARM(self), PyObje
PyObject * obj1 = 0 ; PyObject * obj1 = 0 ;
PyObject *result = 0 ; PyObject *result = 0 ;
if (!PyArg_ParseTuple(args,(char *)"OO:is_plugin_same",&obj0,&obj1)) SWIG_fail; if (!PyArg_ParseTuple(args,(char *)"OO:are_plugins_same",&obj0,&obj1)) SWIG_fail;
arg1 = obj0; arg1 = obj0;
arg2 = obj1; arg2 = obj1;
result = (PyObject *)is_plugin_same(arg1,arg2); result = (PyObject *)are_plugins_same(arg1,arg2);
resultobj = result; resultobj = result;
return resultobj; return resultobj;
fail: fail:
...@@ -3710,7 +3712,7 @@ fail: ...@@ -3710,7 +3712,7 @@ fail:
} }
SWIGINTERN PyObject *_wrap_is_filehandle_same(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { SWIGINTERN PyObject *_wrap_are_filehandles_same(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0; PyObject *resultobj = 0;
PyObject *arg1 = (PyObject *) 0 ; PyObject *arg1 = (PyObject *) 0 ;
PyObject *arg2 = (PyObject *) 0 ; PyObject *arg2 = (PyObject *) 0 ;
...@@ -3718,10 +3720,10 @@ SWIGINTERN PyObject *_wrap_is_filehandle_same(PyObject *SWIGUNUSEDPARM(self), Py ...@@ -3718,10 +3720,10 @@ SWIGINTERN PyObject *_wrap_is_filehandle_same(PyObject *SWIGUNUSEDPARM(self), Py
PyObject * obj1 = 0 ; PyObject * obj1 = 0 ;
PyObject *result = 0 ; PyObject *result = 0 ;
if (!PyArg_ParseTuple(args,(char *)"OO:is_filehandle_same",&obj0,&obj1)) SWIG_fail; if (!PyArg_ParseTuple(args,(char *)"OO:are_filehandles_same",&obj0,&obj1)) SWIG_fail;
arg1 = obj0; arg1 = obj0;
arg2 = obj1; arg2 = obj1;
result = (PyObject *)is_filehandle_same(arg1,arg2); result = (PyObject *)are_filehandles_same(arg1,arg2);
resultobj = result; resultobj = result;
return resultobj; return resultobj;
fail: fail:
...@@ -3742,8 +3744,8 @@ static PyMethodDef SwigMethods[] = { ...@@ -3742,8 +3744,8 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"read_fill_bonds", _wrap_read_fill_bonds, METH_VARARGS, (char *)"read_fill_bonds(molpack) -> PyObject *"}, { (char *)"read_fill_bonds", _wrap_read_fill_bonds, METH_VARARGS, (char *)"read_fill_bonds(molpack) -> PyObject *"},
{ (char *)"read_fill_angles", _wrap_read_fill_angles, METH_VARARGS, (char *)"read_fill_angles(molpack) -> PyObject *"}, { (char *)"read_fill_angles", _wrap_read_fill_angles, METH_VARARGS, (char *)"read_fill_angles(molpack) -> PyObject *"},
{ (char *)"read_fill_next_timestep", _wrap_read_fill_next_timestep, METH_VARARGS, (char *)"read_fill_next_timestep(molpack) -> PyObject *"}, { (char *)"read_fill_next_timestep", _wrap_read_fill_next_timestep, METH_VARARGS, (char *)"read_fill_next_timestep(molpack) -> PyObject *"},
{ (char *)"is_plugin_same", _wrap_is_plugin_same, METH_VARARGS, (char *)"is_plugin_same(molpack_a, molpack_b) -> PyObject *"}, { (char *)"are_plugins_same", _wrap_are_plugins_same, METH_VARARGS, (char *)"are_plugins_same(molpack_a, molpack_b) -> PyObject *"},
{ (char *)"is_filehandle_same", _wrap_is_filehandle_same, METH_VARARGS, (char *)"is_filehandle_same(molpack_a, molpack_b) -> PyObject *"}, { (char *)"are_filehandles_same", _wrap_are_filehandles_same, METH_VARARGS, (char *)"are_filehandles_same(molpack_a, molpack_b) -> PyObject *"},
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
......
...@@ -45,6 +45,12 @@ void del_molfile_plugin_list(PyObject* molcapsule) ...@@ -45,6 +45,12 @@ void del_molfile_plugin_list(PyObject* molcapsule)
free(plugin_list); free(plugin_list);
Py_XDECREF(molcapsule); Py_XDECREF(molcapsule);
} }
void del_molfile_file_handle(PyObject* molcapsule)
{
void *file_handle = (void*) PyMolfileCapsule_AsVoidPtr(molcapsule);
free(file_handle);
Py_XDECREF(molcapsule);
}
#else #else
void* del_molfile_plugin_list(void* molcapsule) void* del_molfile_plugin_list(void* molcapsule)
{ {
...@@ -52,6 +58,12 @@ void* del_molfile_plugin_list(void* molcapsule) ...@@ -52,6 +58,12 @@ void* del_molfile_plugin_list(void* molcapsule)
free(plugin_list); free(plugin_list);
Py_XDECREF(molcapsule); Py_XDECREF(molcapsule);
} }
void* del_molfile_file_handle(void* molcapsule)
{
void *file_handle = PyMolfileCapsule_AsVoidPtr((PyObject*)molcapsule);
free(file_handle);
Py_XDECREF(molcapsule);
}
#endif #endif
/* * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * *
...@@ -200,13 +212,15 @@ PyObject* read_fill_structure(PyObject* molpack, PyObject* prototype) ...@@ -200,13 +212,15 @@ PyObject* read_fill_structure(PyObject* molpack, PyObject* prototype)
// Access plugin_handle values // Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack; MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) { if (plugin_handle->plugin) {
plugin = plugin_handle->plugin; plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else { } else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active."); PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL; return NULL;
} }
if (plugin_handle->file_handle) { if (plugin_handle->file_handle) {
file_handle = plugin_handle->file_handle; file_handle = (void*) PyMolfileCapsule_AsVoidPtr(plugin_handle->file_handle);
//file_handle = plugin_handle->file_handle;
} else { } else {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle."); PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL; return NULL;
...@@ -261,13 +275,15 @@ PyObject* read_fill_bonds(PyObject* molpack) ...@@ -261,13 +275,15 @@ PyObject* read_fill_bonds(PyObject* molpack)
// Access plugin_handle values // Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack; MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) { if (plugin_handle->plugin) {
plugin = plugin_handle->plugin; plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else { } else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active."); PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL; return NULL;
} }
if (plugin_handle->file_handle) { if (plugin_handle->file_handle) {
file_handle = plugin_handle->file_handle; file_handle = (void*) PyMolfileCapsule_AsVoidPtr(plugin_handle->file_handle);
//file_handle = plugin_handle->file_handle;
} else { } else {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle."); PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL; return NULL;
...@@ -355,13 +371,15 @@ PyObject* read_fill_angles(PyObject* molpack) ...@@ -355,13 +371,15 @@ PyObject* read_fill_angles(PyObject* molpack)
// Access plugin_handle values // Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack; MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) { if (plugin_handle->plugin) {
plugin = plugin_handle->plugin; plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else { } else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active."); PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL; return NULL;
} }
if (plugin_handle->file_handle) { if (plugin_handle->file_handle) {
file_handle = plugin_handle->file_handle; file_handle = (void*) PyMolfileCapsule_AsVoidPtr(plugin_handle->file_handle);
//file_handle = plugin_handle->file_handle;
} else { } else {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle."); PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL; return NULL;
...@@ -550,13 +568,15 @@ PyObject* read_fill_next_timestep(PyObject* molpack) ...@@ -550,13 +568,15 @@ PyObject* read_fill_next_timestep(PyObject* molpack)
// Access plugin_handle values // Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack; MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) { if (plugin_handle->plugin) {
plugin = plugin_handle->plugin; plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else { } else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active."); PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL; return NULL;
} }
if (plugin_handle->file_handle) { if (plugin_handle->file_handle) {
file_handle = plugin_handle->file_handle; file_handle = (void*) PyMolfileCapsule_AsVoidPtr(plugin_handle->file_handle);
//file_handle = plugin_handle->file_handle;
} else { } else {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle."); PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL; return NULL;
...@@ -663,7 +683,7 @@ PyObject* read_fill_next_timestep(PyObject* molpack) ...@@ -663,7 +683,7 @@ PyObject* read_fill_next_timestep(PyObject* molpack)
} }
} }
PyObject* is_plugin_same(PyObject* molpack_a, PyObject* molpack_b) PyObject* are_plugins_same(PyObject* molpack_a, PyObject* molpack_b)
{ {
molfile_plugin_t* plugin_a; molfile_plugin_t* plugin_a;
molfile_plugin_t* plugin_b; molfile_plugin_t* plugin_b;
...@@ -671,13 +691,15 @@ PyObject* is_plugin_same(PyObject* molpack_a, PyObject* molpack_b) ...@@ -671,13 +691,15 @@ PyObject* is_plugin_same(PyObject* molpack_a, PyObject* molpack_b)
MolObject* plugin_handle_a = (MolObject*) molpack_a; MolObject* plugin_handle_a = (MolObject*) molpack_a;
MolObject* plugin_handle_b = (MolObject*) molpack_b; MolObject* plugin_handle_b = (MolObject*) molpack_b;
if (plugin_handle_a->plugin) { if (plugin_handle_a->plugin) {
plugin_a = plugin_handle_a->plugin; plugin_a = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle_a->plugin);
//plugin_a = plugin_handle_a->plugin;
} else { } else {
PyErr_Format(PyExc_IOError, "Arg 1 of the molfile plugin is not active."); PyErr_Format(PyExc_IOError, "Arg 1 of the molfile plugin is not active.");
return NULL; return NULL;
} }
if (plugin_handle_b->plugin) { if (plugin_handle_b->plugin) {
plugin_b = plugin_handle_b->plugin; plugin_b = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle_b->plugin);
//plugin_b = plugin_handle_b->plugin;
} else { } else {
PyErr_Format(PyExc_IOError, "Arg 2 of the molfile plugin is not active."); PyErr_Format(PyExc_IOError, "Arg 2 of the molfile plugin is not active.");
return NULL; return NULL;
...@@ -689,20 +711,22 @@ PyObject* is_plugin_same(PyObject* molpack_a, PyObject* molpack_b) ...@@ -689,20 +711,22 @@ PyObject* is_plugin_same(PyObject* molpack_a, PyObject* molpack_b)
} }
} }
PyObject* is_filehandle_same(PyObject* molpack_a, PyObject* molpack_b) PyObject* are_filehandles_same(PyObject* molpack_a, PyObject* molpack_b)
{ {
MolObject* plugin_handle_a = (MolObject*) molpack_a; MolObject* plugin_handle_a = (MolObject*) molpack_a;
MolObject* plugin_handle_b = (MolObject*) molpack_b; MolObject* plugin_handle_b = (MolObject*) molpack_b;
void* file_handle_a; void* file_handle_a;
void* file_handle_b; void* file_handle_b;
if (plugin_handle_a->file_handle) { if (plugin_handle_a->file_handle) {
file_handle_a = plugin_handle_a->file_handle; file_handle_a = (void*) PyMolfileCapsule_AsVoidPtr(plugin_handle_a->file_handle);
//file_handle_a = plugin_handle_a->file_handle;
} else { } else {
PyErr_Format(PyExc_IOError, "no file handle in arg 1 of molfile plugin."); PyErr_Format(PyExc_IOError, "no file handle in arg 1 of molfile plugin.");
return NULL; return NULL;
} }
if (plugin_handle_b->file_handle) { if (plugin_handle_b->file_handle) {
file_handle_b = plugin_handle_b->file_handle; file_handle_b = (void*) PyMolfileCapsule_AsVoidPtr(plugin_handle_b->file_handle);
//file_handle_b = plugin_handle_b->file_handle;
} else { } else {
PyErr_Format(PyExc_IOError, "no file handle in arg 2 of molfile plugin."); PyErr_Format(PyExc_IOError, "no file handle in arg 2 of molfile plugin.");
return NULL; return NULL;
......
...@@ -35,6 +35,14 @@ extern "C" ...@@ -35,6 +35,14 @@ extern "C"
#define MAXPLUGINS 200 #define MAXPLUGINS 200
#endif #endif
struct MolObject {
PyObject_HEAD
PyObject * plugin;
PyObject * file_handle;
int natoms;
MolObject(void) {}
};
/*
struct MolObject { struct MolObject {
PyObject_HEAD PyObject_HEAD
molfile_plugin_t* plugin; molfile_plugin_t* plugin;
...@@ -42,10 +50,12 @@ struct MolObject { ...@@ -42,10 +50,12 @@ struct MolObject {
int natoms; int natoms;
MolObject(void) {} MolObject(void) {}
}; };
*/
static void * PyMolfileCapsule_AsVoidPtr(PyObject *obj); static void * PyMolfileCapsule_AsVoidPtr(PyObject *obj);
static PyObject * PyMolfileCapsule_FromVoidPtr(void *ptr, void (*data)(PyObject *)); static PyObject * PyMolfileCapsule_FromVoidPtr(void *ptr, void (*data)(PyObject *));
void del_molfile_plugin_list(PyObject* molcapsule);