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

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
__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);
%feature("autodoc", "0") molfile_plugin_info;
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;
......@@ -140,13 +82,18 @@ PyObject * my_open_file_read(PyObject* molcapsule, char* fname, char* ftype, int
return NULL;
PyTypeObject *type = &MolObjectType;
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->plugin = plugin;
plugin_c->file_handle = plugin->open_file_read(fname, ftype, &natoms);
plugin_c->natoms = natoms;
PyObject* plugin_handle = (PyObject *)plugin_c;
return plugin_handle;
/*plugin_c->plugin = plugin;*/
plugin_c->plugin = molcapsule;
void *file_handle = plugin->open_file_read(fname, ftype, &natoms);
plugin_c->file_handle = PyMolfileCapsule_FromVoidPtr(file_handle, del_molfile_file_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
}
%inline %{
PyObject * my_close_file_read(PyObject* molpack) {
molfile_plugin_t* plugin;
void* file_handle;
int numatoms;
MolObject* plugin_handle = (MolObject*) molpack;
plugin = plugin_handle->plugin;
file_handle = plugin_handle->file_handle;
numatoms = plugin_handle->natoms;
Py_INCREF(plugin_handle);
PyObject* plugincapsule = plugin_handle->plugin;
PyObject* filecapsule = plugin_handle->file_handle;
molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugincapsule);
void *file_handle = (void*) PyMolfileCapsule_AsVoidPtr(filecapsule);
plugin->close_file_read(file_handle);
Py_DECREF(plugin_handle);
/*Py_DECREF(molpack);*/
Py_RETURN_NONE;
Py_XDECREF(filecapsule);
Py_XDECREF(plugin_handle->file_handle);
return (PyObject *)plugin_handle;
}
%}
......@@ -185,9 +129,9 @@ extern PyObject * read_fill_angles(PyObject* molpack);
%feature("autodoc", "0") read_fill_next_timestep;
extern PyObject * read_fill_next_timestep(PyObject* molpack);
%feature("autodoc", "0") is_plugin_same;
PyObject* is_plugin_same(PyObject* molpack_a, PyObject* molpack_b);
%feature("autodoc", "0") are_plugins_same;
PyObject* are_plugins_same(PyObject* molpack_a, PyObject* molpack_b);
%feature("autodoc", "0") is_filehandle_same;
PyObject* is_filehandle_same(PyObject* molpack_a, PyObject* molpack_b);
%feature("autodoc", "0") are_filehandles_same;
PyObject* are_filehandles_same(PyObject* molpack_a, PyObject* molpack_b);
......@@ -151,13 +151,13 @@ def read_fill_next_timestep(molpack: 'PyObject *') -> "PyObject *":
"""read_fill_next_timestep(molpack) -> PyObject *"""
return _libpymolfile.read_fill_next_timestep(molpack)
def is_plugin_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *":
"""is_plugin_same(molpack_a, molpack_b) -> PyObject *"""
return _libpymolfile.is_plugin_same(molpack_a, molpack_b)
def are_plugins_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *":
"""are_plugins_same(molpack_a, molpack_b) -> PyObject *"""
return _libpymolfile.are_plugins_same(molpack_a, molpack_b)
def is_filehandle_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *":
"""is_filehandle_same(molpack_a, molpack_b) -> PyObject *"""
return _libpymolfile.is_filehandle_same(molpack_a, molpack_b)
def are_filehandles_same(molpack_a: 'PyObject *', molpack_b: 'PyObject *') -> "PyObject *":
"""are_filehandles_same(molpack_a, molpack_b) -> PyObject *"""
return _libpymolfile.are_filehandles_same(molpack_a, molpack_b)
# 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
return NULL;
PyTypeObject *type = &MolObjectType;
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->plugin = plugin;
plugin_c->file_handle = plugin->open_file_read(fname, ftype, &natoms);
plugin_c->natoms = natoms;
PyObject* plugin_handle = (PyObject *)plugin_c;
return plugin_handle;
/*plugin_c->plugin = plugin;*/
plugin_c->plugin = molcapsule;
void *file_handle = plugin->open_file_read(fname, ftype, &natoms);
plugin_c->file_handle = PyMolfileCapsule_FromVoidPtr(file_handle, del_molfile_file_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)
PyObject * my_close_file_read(PyObject* molpack) {
molfile_plugin_t* plugin;
void* file_handle;
int numatoms;
MolObject* plugin_handle = (MolObject*) molpack;
plugin = plugin_handle->plugin;
file_handle = plugin_handle->file_handle;
numatoms = plugin_handle->natoms;
Py_INCREF(plugin_handle);
PyObject* plugincapsule = plugin_handle->plugin;
PyObject* filecapsule = plugin_handle->file_handle;
molfile_plugin_t* plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugincapsule);
void *file_handle = (void*) PyMolfileCapsule_AsVoidPtr(filecapsule);
plugin->close_file_read(file_handle);
Py_DECREF(plugin_handle);
/*Py_DECREF(molpack);*/
Py_RETURN_NONE;
Py_XDECREF(filecapsule);
Py_XDECREF(plugin_handle->file_handle);
return (PyObject *)plugin_handle;
}
#ifdef __cplusplus
......@@ -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 *arg1 = (PyObject *) 0 ;
PyObject *arg2 = (PyObject *) 0 ;
......@@ -3699,10 +3701,10 @@ SWIGINTERN PyObject *_wrap_is_plugin_same(PyObject *SWIGUNUSEDPARM(self), PyObje
PyObject * obj1 = 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;
arg2 = obj1;
result = (PyObject *)is_plugin_same(arg1,arg2);
result = (PyObject *)are_plugins_same(arg1,arg2);
resultobj = result;
return resultobj;
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 *arg1 = (PyObject *) 0 ;
PyObject *arg2 = (PyObject *) 0 ;
......@@ -3718,10 +3720,10 @@ SWIGINTERN PyObject *_wrap_is_filehandle_same(PyObject *SWIGUNUSEDPARM(self), Py
PyObject * obj1 = 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;
arg2 = obj1;
result = (PyObject *)is_filehandle_same(arg1,arg2);
result = (PyObject *)are_filehandles_same(arg1,arg2);
resultobj = result;
return resultobj;
fail:
......@@ -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_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 *)"is_plugin_same", _wrap_is_plugin_same, METH_VARARGS, (char *)"is_plugin_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_plugins_same", _wrap_are_plugins_same, METH_VARARGS, (char *)"are_plugins_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 }
};
......
......@@ -45,6 +45,12 @@ void del_molfile_plugin_list(PyObject* molcapsule)
free(plugin_list);
Py_XDECREF(molcapsule);
}
void del_molfile_file_handle(PyObject* molcapsule)
{
void *file_handle = (void*) PyMolfileCapsule_AsVoidPtr(molcapsule);
free(file_handle);
Py_XDECREF(molcapsule);
}
#else
void* del_molfile_plugin_list(void* molcapsule)
{
......@@ -52,6 +58,12 @@ void* del_molfile_plugin_list(void* molcapsule)
free(plugin_list);
Py_XDECREF(molcapsule);
}
void* del_molfile_file_handle(void* molcapsule)
{
void *file_handle = PyMolfileCapsule_AsVoidPtr((PyObject*)molcapsule);
free(file_handle);
Py_XDECREF(molcapsule);
}
#endif
/* * * * * * * * * * * * * * * * * * * * * * *
......@@ -200,13 +212,15 @@ PyObject* read_fill_structure(PyObject* molpack, PyObject* prototype)
// Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) {
plugin = plugin_handle->plugin;
plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL;
}
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 {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL;
......@@ -261,13 +275,15 @@ PyObject* read_fill_bonds(PyObject* molpack)
// Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) {
plugin = plugin_handle->plugin;
plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL;
}
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 {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL;
......@@ -355,13 +371,15 @@ PyObject* read_fill_angles(PyObject* molpack)
// Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) {
plugin = plugin_handle->plugin;
plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL;
}
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 {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL;
......@@ -550,13 +568,15 @@ PyObject* read_fill_next_timestep(PyObject* molpack)
// Access plugin_handle values
MolObject* plugin_handle = (MolObject*) molpack;
if (plugin_handle->plugin) {
plugin = plugin_handle->plugin;
plugin = (molfile_plugin_t*) PyMolfileCapsule_AsVoidPtr(plugin_handle->plugin);
//plugin = plugin_handle->plugin;
} else {
PyErr_Format(PyExc_IOError, "molfile plugin is not active.");
return NULL;
}
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 {
PyErr_Format(PyExc_IOError, "no file handle in molfile plugin handle.");
return NULL;
......@@ -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_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_b = (MolObject*) molpack_b;
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 {
PyErr_Format(PyExc_IOError, "Arg 1 of the molfile plugin is not active.");
return NULL;
}
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 {
PyErr_Format(PyExc_IOError, "Arg 2 of the molfile plugin is not active.");
return NULL;
......@@ -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_b = (MolObject*) molpack_b;
void* file_handle_a;
void* file_handle_b;
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 {
PyErr_Format(PyExc_IOError, "no file handle in arg 1 of molfile plugin.");
return NULL;
}
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 {
PyErr_Format(PyExc_IOError, "no file handle in arg 2 of molfile plugin.");
return NULL;
......
......@@ -35,6 +35,14 @@ extern "C"
#define MAXPLUGINS 200
#endif
struct MolObject {
PyObject_HEAD
PyObject * plugin;
PyObject * file_handle;
int natoms;
MolObject(void) {}
};
/*
struct MolObject {
PyObject_HEAD
molfile_plugin_t* plugin;
......@@ -42,10 +50,12 @@ struct MolObject {
int natoms;
MolObject(void) {}
};
*/
static void * PyMolfileCapsule_AsVoidPtr(PyObject *obj);
static PyObject * PyMolfileCapsule_FromVoidPtr(void *ptr, void (*data)(PyObject *));
void del_molfile_plugin_list(PyObject* molcapsule);
void del_molfile_file_handle(PyObject* molcapsule);
#if PY_VERSION_HEX >= 0x03000000
#define PyInt_AsSsize_t PyLong_AsSsize_t
......@@ -115,10 +125,14 @@ static PyObject * MolObject_new(PyTypeObject *type, PyObject *args, PyObject *kw
static int MolObject_init(MolObject *self, PyObject *args, PyObject *kwds)
{
molfile_plugin_t *plugin = NULL;
void *file_handle = NULL;
molfile_plugin_t *tmp1 = NULL;
void *tmp2 = NULL;
//molfile_plugin_t *plugin = NULL;
//void *file_handle = NULL;
//molfile_plugin_t *tmp1 = NULL;
//void *tmp2 = NULL;
PyObject *plugin = NULL;
PyObject *file_handle = NULL;
PyObject *tmp1 = NULL;
PyObject *tmp2 = NULL;
static char *kwlist[] = {"plugin", "file_handle", "natoms", NULL};
......@@ -144,12 +158,14 @@ static int MolObject_init(MolObject *self, PyObject *args, PyObject *kwds)
return 0;
}
static molfile_plugin_t* MolObject_plugin(MolObject* self)
//static molfile_plugin_t* MolObject_plugin(MolObject* self)
static PyObject* MolObject_plugin(MolObject* self)
{
return self->plugin;
}
static void* MolObject_file_handle(MolObject* self)
//static void* MolObject_file_handle(MolObject* self)
static PyObject* MolObject_file_handle(MolObject* self)
{
return self->file_handle;
}
......@@ -235,8 +251,8 @@ PyObject * read_fill_structure(PyObject* molpack, PyObject* prototype);
PyObject * read_fill_bonds(PyObject* molpack);
PyObject * read_fill_angles(PyObject* molpack);
PyObject * read_fill_next_timestep(PyObject* molpack);
PyObject * is_plugin_same(PyObject* molpack_a, PyObject* molpack_b);
PyObject * is_filehandle_same(PyObject* molpack_a, PyObject* molpack_b);
PyObject * are_plugins_same(PyObject* molpack_a, PyObject* molpack_b);
PyObject * are_filehandles_same(PyObject* molpack_a, PyObject* molpack_b);
PyObject * get_plugin(PyObject* molcapsule, int plug_no);
PyObject * molfile_plugin_list(int maxsize);
......
......@@ -204,6 +204,12 @@ extern int molfile_maeffplugin_fini(void);
extern int molfile_netcdfplugin_init(void);
extern int molfile_netcdfplugin_register(void *, vmdplugin_register_cb);
extern int molfile_netcdfplugin_fini(void);
extern int molfile_hoomdplugin_init(void);
extern int molfile_hoomdplugin_register(void *, vmdplugin_register_cb);
extern int molfile_hoomdplugin_fini(void);
extern int molfile_tngplugin_init(void);
extern int molfile_tngplugin_register(void *, vmdplugin_register_cb);
extern int molfile_tngplugin_fini(void);
#define MOLFILE_INIT_ALL \
molfile_abinitplugin_init(); \
......@@ -272,6 +278,8 @@ extern int molfile_netcdfplugin_fini(void);
molfile_dtrplugin_init(); \
molfile_maeffplugin_init(); \
molfile_netcdfplugin_init(); \
molfile_hoomdplugin_init(); \
molfile_tngplugin_init(); \
#define MOLFILE_REGISTER_ALL(v, cb) \
molfile_abinitplugin_register(v, cb); \
......@@ -340,6 +348,8 @@ extern int molfile_netcdfplugin_fini(void);
molfile_dtrplugin_register(v, cb); \
molfile_maeffplugin_register(v, cb); \
molfile_netcdfplugin_register(v, cb); \
molfile_hoomdplugin_register(v, cb); \
molfile_tngplugin_register(v, cb); \
#define MOLFILE_FINI_ALL \
molfile_abinitplugin_fini(); \
......@@ -408,6 +418,8 @@ extern int molfile_netcdfplugin_fini(void);
molfile_dtrplugin_fini(); \
molfile_maeffplugin_fini(); \
molfile_netcdfplugin_fini(); \
molfile_hoomdplugin_fini(); \
molfile_tngplugin_fini(); \
#ifdef __cplusplus
}
......
......@@ -306,7 +306,7 @@ static const char *openbabel11filetypenames[] = {
static const char *babel16type_from_name(const char *name) {
const char **ptr = babel16filetypenames;
int i=0;
int i=0;
while (*ptr) {
if (!strcmp(*ptr, name))
return babel16filetypes[i];
......@@ -316,6 +316,18 @@ static const char *babel16type_from_name(const char *name) {
return NULL;
}
static const char *babel16type_support(const char *filetype) {
const char **ptr = babel16filetypes;
int i=0;
while (*ptr) {
if (!strcmp(*ptr, filetype))
return babel16filetypes[i];
ptr++;
i++;
}
return NULL;
}
static const char *openbabel11type_from_name(const char *name) {
const char **ptr = openbabel11filetypenames;
int i=0;
......@@ -367,7 +379,8 @@ static void *open_babel_read(const char *filename, const char *filetypename,
#endif
/* Try Babel 1.6 file type names if Open Babel didn't match */
filetype = babel16type_from_name(filetypename);
//filetype = babel16type_from_name(filetypename);
filetype = babel16type_support(filetypename);
if (!filetype) {
fprintf(stderr, "No Babel 1.6 file type for '%s'\n", filetypename);
return NULL;
......@@ -382,7 +395,8 @@ static void *open_babel_read(const char *filename, const char *filetypename,
// On windows its necessary to quote command names due to
// the high tendency for paths to have spaces in them.
*/
sprintf(s, "\"%s\" -i%s \"%s\" all -opdb \"%s\"",
//sprintf(s, "\"%s\" -i%s \"%s\" all -opdb \"%s\"",
sprintf(s, "\"%s\" -i%s \"%s\" -opdb \"%s\"",
babelbin, filetype, filename, (const char *)file(filename, 0, 0));
delete_all(filename); /* delete any conflicting existing files */
......
......@@ -12,7 +12,7 @@ C_MOLFILE_PLUGINS = libpymolfile.molfile_plugin_list(MAX_NUM_PLUGINS)
def byte_str_decode(data, dectype=None):
try:
return data.decode(dectype)
return data.decode(dectype).replace('\x00', '')
except AttributeError:
return data
......
This diff is collapsed.