Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
pymolfile
Commits
672baac3
Commit
672baac3
authored
Sep 20, 2017
by
Berk Onat
Browse files
Added Numpy example wrapper for molfile_atom_t
parent
c013427c
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
pymolfile/molfile/_libpymolfile.so
View file @
672baac3
No preview for this file type
pymolfile/molfile/compile.sh
View file @
672baac3
swig
-Wall
-c
++
-python
libpymolfile.i
swig
-py3
-Wall
-c
++
-python
libpymolfile.i
g++
-fPIC
-Wall
-Wextra
-Wunused-function
-shared
-I
/labEnv3/lib/python3.6/site-packages/numpy/core/include/
-I
.
libpymolfile_wrap.cxx pymolfile.c
-o
_libpymolfile.so
-Ivmd_molfile_plugins
/include/
-Ilib
/
-L
.
lib/libmolfile_plugin.a
-I
/labEnv3/include/python3.6m/
-L
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib
-lpython3
.6
pymolfile/molfile/deneme
0 → 100644
View file @
672baac3
This diff is collapsed.
Click to expand it.
pymolfile/molfile/libpymolfile.i
View file @
672baac3
...
...
@@ -24,10 +24,12 @@
Published under BSD LICENSE
*/
#
define
SWIG_FILE_WITH_INIT
#
define
__STDC_FORMAT_MACROS
#
include
<
stdio
.
h
>
#
include
<
stdlib
.
h
>
#
include
<
ctype
.
h
>
#
include
<
string
.
h
>
#
include
<
inttypes
.
h
>
#
include
"molfile_plugin.h"
#
include
"libmolfile_plugin.h"
#
include
"vmdplugin.h"
...
...
@@ -37,6 +39,7 @@
%
include
"numpy.i"
%
init
%
{
Py_Initialize
()
;
import_array
()
;
%
}
...
...
@@ -54,6 +57,57 @@ import_array();
enum
{
pluginOK
,
pluginNOINIT
,
pluginCLOSE
,
pluginNOMEM
,
pluginENDOFFILE
,
pluginFILENOTFOUND
,
pluginFORMATERROR
}
;
/* Definition of molfile_atoms_t from molfile_plugin.h */
%
inline
%
{
/*
struct MolAtoms {
char name[16];
char type[16];
char resname[8];
int resid;
char segid[8];
char chain[2];
char altloc[2];
char insertion[2];
float occupancy;
float bfactor;
float mass;
float charge;
float radius;
float atomicnumber;
float ctnumber;
};
void del_plugin_structure(PyObject* pymolfile_atoms){
delete (MolAtoms*)PyCapsule_GetPointer(pymolfile_atoms, "plugin_structure");
}
static PyObject* alloc_plugin_structure(PyObject *self, PyObject *args) {
return PyCapsule_New((void*)new MolAtoms(), "plugin_structure", del_plugin_structure);
}
*/
void
del_plugin
(
PyObject
*
pymolfile_plugin
)
{
delete
(
MolObject
*
)
PyCapsule_GetPointer
(
pymolfile_plugin
,
"plugin"
)
;
}
void
del_atoms
(
PyObject
*
pymolfile_atoms
)
{
delete
(
PyObject
*
)
PyCapsule_GetPointer
(
pymolfile_atoms
,
"atoms"
)
;
}
void
del_atomname
(
PyObject
*
pymolfile_atoms
)
{
delete
(
PyObject
*
)
PyCapsule_GetPointer
(
pymolfile_atoms
,
"atomname"
)
;
}
static
PyObject
*
alloc_plugin
(
PyObject
*
self
,
PyObject
*
args
)
{
return
PyCapsule_New
((
void
*
)
new
MolObject
(),
"plugin_handle"
,
del_plugin
)
;
}
%
}
/* pymolfile.c
initialize and finalize molfile plugins
*/
...
...
@@ -126,20 +180,290 @@ PyObject * molfile_plugin_info(molfile_plugin_t** plugin_list, int plugin_no) {
}
%
}
%
feature
(
"autodoc"
,
"0"
)
my_open_file_read
;
%
rename
(
open_file_read
)
my_open_file_read
;
%
exception
my_open_file_read
{
$
action
if
(
PyErr_Occurred
())
SWIG_fail
;
}
%
inline
%
{
PyObject
*
my_open_file_read
(
molfile_plugin_t
*
plugin
,
char
*
fname
,
char
*
ftype
,
int
natoms
)
{
if
(
PyType_Ready
(
&
MolObjectType)
<
0
)
return
NULL
;
PyTypeObject
*
type
=
&
MolObjectType;
/*plugin_handle = PyCapsule_New((void*)new MolObject(), "plugin", del_plugin); */
/*MolObject* plugin_c = new MolObject;*/
MolObject
*
plugin_c
;
plugin_c
=
(
MolObject
*
)
type-
>
tp_alloc
(
type
,
0
)
;
/*PyObject * plugin_c = MolObject_new(&MolObjectType, args, kwds);*/
plugin_c-
>
plugin
=
plugin
;
plugin_c-
>
file_handle
=
plugin-
>
open_file_read
(
fname
,
ftype
,
&
natoms);
plugin_c-
>
natoms
=
natoms
;
/* PyCapsule_SetPointer(plugin_handle, &plugin_c); */
/* PyObject* plugin_handle = PyCapsule_New((void*)plugin_c, "plugin", del_plugin); */
PyObject
*
plugin_handle
=
(
PyObject
*
)
plugin_c
;
/*if(!plugin_handle) printf("Not assigned\n");*/
/*PyObject *tuple = PyTuple_New(2);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)natoms));
PyTuple_SET_ITEM(tuple, 1, plugin_handle);*/
return
plugin_handle
;
}
%
}
/*
%typemap( argout ) ( char **MolfileAtomT_CharArray )
{
// The result variable is the return value from
// c_ephcom_read_constants, the number of actual values that are
// defined for cnames/values.
npy_intp dims[] = { result };
PyArray_Dims newshape_location;
PyArray_Dims * newshape = &newshape_location;
PyObject * status_check;
newshape->len = 1;
newshape->ptr = dims;
// resize array$argnum to actual size needed.
// Follow directions at http://www.mail-archive.com/numpy-discussion@scipy.org/msg13013.html
status_check = PyArray_Resize( (PyArrayObject *) array$argnum, newshape, 0, NPY_CORDER );
if ( !status_check )
SWIG_fail;
Py_DECREF( status_check );
$result = SWIG_Python_AppendOutput( $result, array$argnum );
}
%typemap( freearg ) ( char **MolfileAtomT_CharArray )
{
free( $1 );
}
*/
/*
%feature("autodoc", "0") molfile_open;
%exception molfile_open {
#define DIM 3
typedef int imatrix[DIM][DIM];
typedef int ivec[DIM];
typedef float fmatrix[DIM][DIM];
typedef float fvec[DIM];
*/
/* Reading from xdr files */
/*
%apply (float INPLACE_ARRAY2[ANY][ANY]) {(matrix box)}
%apply (int DIM1, int DIM2, float* INPLACE_ARRAY2) {(int natoms, int _DIM, float *x),
(int vnatoms, int v_DIM, float *v),
(int fnatoms, int f_DIM, float *f)}
*/
/*
%apply (int INPLACE_IARRAY2[ANY][ANY]) {(imatrix intdata)}
%apply (float INPLACE_FARRAY2[ANY][ANY]) {(fmatrix floatdata)}
%apply (int DIM1, int* INPLACE_IARRAY2) {(int rnatoms, int* MolAtom_resid)}
%apply (int DIM1, float* INPLACE_FARRAY2) {(int mnatoms, float* MolAtom_mass),
(int anatoms, float* MolAtom_atomicnumber)}
*/
/*
%inline %{
int structure_read(molfile_plugin_t* plugin, void* fhandle, int *options,
int* natoms, char** MolAtom_name,
int* natoms, char** MolAtom_type,
int* natoms, char** MolAtom_resname,
int* natoms, int** MolAtom_resid,
int* natoms, char** MolAtom_segid,
int* natoms, char** MolAtom_chain,
int* natoms, char** MolAtom_altloc,
int* natoms, char** MolAtom_insertion,
int* natoms, float** MolAtom_occupancy,
int* natoms, float** MolAtom_bfactor,
int* natoms, float** MolAtom_mass,
int* natoms, float** MolAtom_charge,
int* natoms, float** MolAtom_radius,
int* natoms, float** MolAtom_atomicnumber,
int* natoms, float** MolAtom_ctnumber) {
molfile_atom_t* atoms;
atoms = (molfile_atom_t *)calloc(natoms,sizeof(molfile_atom_t));
plugin->read_structure(fhandle, options, atoms);
MolAtom_name = (char **)malloc(natoms,sizeof(char*));
MolAtom_type = (char **)malloc(natoms,sizeof(char*));
MolAtom_resname = (char **)malloc(natoms,sizeof(char*));
MolAtom_resid = (int **)malloc(natoms,sizeof(int*));
%}
*/
/*
%inline %{
int structure_read(molfile_plugin_t* plugin, void* fhandle, int *options,
int natoms, char** MolAtom_name,
int tnatoms, char** MolAtom_type,
int rnatoms, int* MolAtom_resid,
int mnatoms, float* MolAtom_mass,
int anatoms, float* MolAtom_atomicnumber) {
int i;
molfile_atom_t* atoms;
molfile_atom_t atm;
atoms = (molfile_atom_t *)calloc(natoms,sizeof(molfile_atom_t));
plugin->read_structure(fhandle, options, atoms);
if(atoms == NULL) { free(atoms); return 1; }
if(atoms->type == NULL || atoms->name == NULL){ free(atoms); return 1; }
MolAtom_name = (char **)malloc(natoms,sizeof(char*));
MolAtom_type = (char **)malloc(natoms,sizeof(char*));
MolAtom_resid = (int *)malloc(natoms,sizeof(int));
MolAtom_mass = (float *)malloc(natoms,sizeof(float));
MolAtom_atomicnumber = (float *)malloc(natoms,sizeof(float));
for (i=0;i<natoms;i++){
atm = atoms[i];
MolAtom_name[i] = atm.name;
MolAtom_type[i] = atm.type;
MolAtom_resid[i] = atm.resid;
MolAtom_mass[i] = atm.mass;
MolAtom_atomicnumber[i] = atm.atomicnumber;
}
return 0;
}
%}
*/
%
feature
(
"autodoc"
,
"0"
)
my_read_structure
;
%
rename
(
read_structure
)
my_read_structure
;
extern
PyObject
*
my_read_structure
(
PyObject
*
molpack
)
;
/*
%feature("autodoc", "0") my_read_structure;
%rename (read_structure) my_read_structure;
%exception my_read_structure {
$action
if (PyErr_Occurred()) SWIG_fail;
}
%inline %{
PyObject * molfile_open(molfile_plugin_t* plugin, ) {
int *plugno = &plugin_no;
return plugin;
PyObject * my_read_structure(PyObject* molpack) {
int options = 0;
int i;
molfile_plugin_t* plugin;
void* file_handle;
molfile_atom_t* atoms;
int numatoms, status;
char** atom_names;
char** atom_types;
PyObject *npatoms = NULL; */
/*MolObject* plugin_handle = (MolObject*)PyCapsule_GetPointer(molpack, "plugin");*/
/* MolObject* plugin_handle = (MolObject*)molpack;
plugin = plugin_handle->plugin;
file_handle = plugin_handle->file_handle;
numatoms = plugin_handle->natoms;
atoms = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t));
printf("Test1\n");
status = plugin->read_structure(file_handle, &options, atoms);
printf("Test2 %d\n",status);
if (status!=0){
PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into Python.");
return NULL;
}
printf("Test3\n");
npy_intp natoms[1] = { numatoms };
PyArrayObject* oresid;
int64_t* cresid;
int typenum;
int nd = 1;
npy_intp dims[1] = { numatoms }; */
/*dims[0] = numatoms;*/
/* oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT64);
npy_intp* n = PyArray_DIMS(oresid);
printf("dimensions %ld\n", n[0]);
cresid = (int64_t*) PyArray_DATA(oresid);
PyObject* npatomresid = NULL;
char** MolAtom_name = (char **)malloc(numatoms*sizeof(char*));
char** MolAtom_type = (char **)malloc(numatoms*sizeof(char*));
int64_t* MolAtom_resid = NULL; */
/*int64_t* MolAtom_resid = (int64_t *)malloc(numatoms*sizeof(int64_t));*/
/* float* MolAtom_mass = (float *)malloc(numatoms*sizeof(float));
float* MolAtom_atomicnumber = (float *)malloc(numatoms*sizeof(float));
for (i=0;i<numatoms;i++){
MolAtom_name[i] = atoms[i].name;
MolAtom_type[i] = atoms[i].type;
cresid[i] = (int64_t) atoms[i].resid;
MolAtom_mass[i] = atoms[i].mass;
MolAtom_atomicnumber[i] = atoms[i].atomicnumber;
} */
/*Py_DECREF( obj );*/
/*npy_intp dims[3];*/
/* PyArray_AsCArray is for ndim <= 3 */
/* PyArray_Descr *descr;
npatoms = PyArray_SimpleNewFromData(1, natoms, NPY_USERDEF, atoms);
printf("Test4 numatoms=%d\n", numatoms);
PyObject* npatomname = NULL;
npatomname = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, MolAtom_name[0]);
PyObject* npatomtype = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, MolAtom_type); */
/*PyObject* npatomresname = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->resname);*/
/*PyObject* npatomsegid = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->segid);*/
/*PyObject* npatomchain = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->chain);*/
/*PyObject* npatomaltloc = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->altloc);*/
/*PyObject* npatominsert = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->insertion);*/
/*PyObject* npatomoccup = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->occupancy);*/
/*PyObject* npatombfact = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->bfactor);*/
/* PyObject* npatommass = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, MolAtom_mass); */
/*PyObject* npatomcharge = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->charge);*/
/*PyObject* npatomradius = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->radius);*/
/* PyObject* npatomicnumber = PyArray_SimpleNewFromData(1, natoms, NPY_INT64, MolAtom_atomicnumber); */
/*if (npatomname==NULL || npatomtype==NULL || npatomresname==NULL ||
npatomresid==NULL || npatomsegid==NULL || npatomchain==NULL )
{
free(atoms);
Py_XDECREF(npatomname); Py_XDECREF(npatomtype);
Py_XDECREF(npatomresname); Py_XDECREF(npatomresid); Py_XDECREF(npatomsegid);
Py_XDECREF(npatomchain); Py_XDECREF(npatomaltloc); Py_XDECREF(npatominsert);
Py_XDECREF(npatomoccup); Py_XDECREF(npatombfact); Py_XDECREF(npatommass);
Py_XDECREF(npatomcharge); Py_XDECREF(npatomradius); Py_XDECREF(npatomicnumber);
PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into Python.");
return 0;
}
PyArray_BASE(npatomname) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomtype) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomresname) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomresid) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomsegid) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomchain) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomaltloc) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatominsert) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomoccup) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatombfact) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatommass) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomcharge) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomradius) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatomicnumber) = PyCObject_FromVoidPtr(*atoms, free);
PyArray_BASE(npatoms) = PyCObject_FromVoidPtr(atoms, free);
PyArray_BASE((PyArrayObject *)npatoms) = PyCapsule_New(atoms, "atoms", del_atoms);*/
/*PyArray_BASE((PyArrayObject *)npatoms); */
/* printf("Test4-2\n"); */
/*PyObject* Py_MolAtom_name = PyCapsule_New((void*)MolAtom_name, "atomname", del_atomname);*/
/*PyObject* Py_MolAtom_name;
Py_INCREF(Py_MolAtom_name);*/
/* printf("Test4-3\n"); */
/*PyArray_SetBaseObject((PyArrayObject *)npatomname, Py_MolAtom_name);*/
/*PyArray_SetBaseObject((PyArrayObject *)npatomtype, MolAtom_type);
PyArray_SetBaseObject((PyArrayObject *)npatomresid, MolAtom_resid);
PyArray_SetBaseObject((PyArrayObject *)npatommass, MolAtom_mass);
PyArray_SetBaseObject((PyArrayObject *)npatomicnumber, MolAtom_atomicnumber); */
/* printf("Test5\n");
PyObject *tuple = PyTuple_New(2);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)natoms));
printf("Test6\n");
PyTuple_SET_ITEM(tuple, 1, npatomname); */
/*PyTuple_SET_ITEM(tuple, 2, npatomtype);
PyTuple_SET_ITEM(tuple, 3, npatomresid);
PyTuple_SET_ITEM(tuple, 4, npatommass);
PyTuple_SET_ITEM(tuple, 5, npatomicnumber);
PyObject* vars = PyDict_New();
printf("Test7\n");
PyDict_SetItemString( vars, "name", npatomname ); */
/* printf("Test8\n"); */
/*PyDict_SetItemString( vars, "resid", npatomresid ); */
/*return Py_BuildValue("O", oresid); */
/*return PyArray_FromArray(oresid, PyArray_DESCR(oresid), 0);*/
/* return 0;
}
%}
*/
/*
python wrappers for functions
and structure data in molfile_plugin.h
...
...
@@ -167,7 +491,20 @@ PyObject * molfile_open(molfile_plugin_t* plugin, ) {
/* molfile_plugin_t */
/*
%feature("autodoc", "0") molfile_open_file_read;
%rename (open_file_read) molfile_open_file_read;
%exception molfile_open_file_read {
$action
if (PyErr_Occurred()) SWIG_fail;
}
%inline %{
PyObject * molfile_open_file_read(molfile_plugin_t* plugin, char *fname, int natoms) {
int *plugno = &plugin_no;
return plugin;
}
%}
*/
/*
void *(* open_file_read)(const char *filepath, const char *filetype,
int *natoms);
...
...
pymolfile/molfile/libpymolfile.py
View file @
672baac3
...
...
@@ -8,7 +8,7 @@
:Author: Berk Onat <b.onat@warwick.ac.uk>
:Year: 2017
:Licence:
BSD
LICENSE
:Licence:
UIUC
LICENSE
...
...
@@ -113,26 +113,136 @@ pluginNOMEM = _libpymolfile.pluginNOMEM
pluginENDOFFILE
=
_libpymolfile
.
pluginENDOFFILE
pluginFILENOTFOUND
=
_libpymolfile
.
pluginFILENOTFOUND
pluginFORMATERROR
=
_libpymolfile
.
pluginFORMATERROR
class
MolAtoms
(
_object
):
__swig_setmethods__
=
{}
__setattr__
=
lambda
self
,
name
,
value
:
_swig_setattr
(
self
,
MolAtoms
,
name
,
value
)
__swig_getmethods__
=
{}
__getattr__
=
lambda
self
,
name
:
_swig_getattr
(
self
,
MolAtoms
,
name
)
__repr__
=
_swig_repr
__swig_setmethods__
[
"name"
]
=
_libpymolfile
.
MolAtoms_name_set
__swig_getmethods__
[
"name"
]
=
_libpymolfile
.
MolAtoms_name_get
if
_newclass
:
name
=
_swig_property
(
_libpymolfile
.
MolAtoms_name_get
,
_libpymolfile
.
MolAtoms_name_set
)
__swig_setmethods__
[
"type"
]
=
_libpymolfile
.
MolAtoms_type_set
__swig_getmethods__
[
"type"
]
=
_libpymolfile
.
MolAtoms_type_get
if
_newclass
:
type
=
_swig_property
(
_libpymolfile
.
MolAtoms_type_get
,
_libpymolfile
.
MolAtoms_type_set
)
__swig_setmethods__
[
"resname"
]
=
_libpymolfile
.
MolAtoms_resname_set
__swig_getmethods__
[
"resname"
]
=
_libpymolfile
.
MolAtoms_resname_get
if
_newclass
:
resname
=
_swig_property
(
_libpymolfile
.
MolAtoms_resname_get
,
_libpymolfile
.
MolAtoms_resname_set
)
__swig_setmethods__
[
"resid"
]
=
_libpymolfile
.
MolAtoms_resid_set
__swig_getmethods__
[
"resid"
]
=
_libpymolfile
.
MolAtoms_resid_get
if
_newclass
:
resid
=
_swig_property
(
_libpymolfile
.
MolAtoms_resid_get
,
_libpymolfile
.
MolAtoms_resid_set
)
__swig_setmethods__
[
"segid"
]
=
_libpymolfile
.
MolAtoms_segid_set
__swig_getmethods__
[
"segid"
]
=
_libpymolfile
.
MolAtoms_segid_get
if
_newclass
:
segid
=
_swig_property
(
_libpymolfile
.
MolAtoms_segid_get
,
_libpymolfile
.
MolAtoms_segid_set
)
__swig_setmethods__
[
"chain"
]
=
_libpymolfile
.
MolAtoms_chain_set
__swig_getmethods__
[
"chain"
]
=
_libpymolfile
.
MolAtoms_chain_get
if
_newclass
:
chain
=
_swig_property
(
_libpymolfile
.
MolAtoms_chain_get
,
_libpymolfile
.
MolAtoms_chain_set
)
__swig_setmethods__
[
"altloc"
]
=
_libpymolfile
.
MolAtoms_altloc_set
__swig_getmethods__
[
"altloc"
]
=
_libpymolfile
.
MolAtoms_altloc_get
if
_newclass
:
altloc
=
_swig_property
(
_libpymolfile
.
MolAtoms_altloc_get
,
_libpymolfile
.
MolAtoms_altloc_set
)
__swig_setmethods__
[
"insertion"
]
=
_libpymolfile
.
MolAtoms_insertion_set
__swig_getmethods__
[
"insertion"
]
=
_libpymolfile
.
MolAtoms_insertion_get
if
_newclass
:
insertion
=
_swig_property
(
_libpymolfile
.
MolAtoms_insertion_get
,
_libpymolfile
.
MolAtoms_insertion_set
)
__swig_setmethods__
[
"occupancy"
]
=
_libpymolfile
.
MolAtoms_occupancy_set
__swig_getmethods__
[
"occupancy"
]
=
_libpymolfile
.
MolAtoms_occupancy_get
if
_newclass
:
occupancy
=
_swig_property
(
_libpymolfile
.
MolAtoms_occupancy_get
,
_libpymolfile
.
MolAtoms_occupancy_set
)
__swig_setmethods__
[
"bfactor"
]
=
_libpymolfile
.
MolAtoms_bfactor_set
__swig_getmethods__
[
"bfactor"
]
=
_libpymolfile
.
MolAtoms_bfactor_get
if
_newclass
:
bfactor
=
_swig_property
(
_libpymolfile
.
MolAtoms_bfactor_get
,
_libpymolfile
.
MolAtoms_bfactor_set
)
__swig_setmethods__
[
"mass"
]
=
_libpymolfile
.
MolAtoms_mass_set
__swig_getmethods__
[
"mass"
]
=
_libpymolfile
.
MolAtoms_mass_get
if
_newclass
:
mass
=
_swig_property
(
_libpymolfile
.
MolAtoms_mass_get
,
_libpymolfile
.
MolAtoms_mass_set
)
__swig_setmethods__
[
"charge"
]
=
_libpymolfile
.
MolAtoms_charge_set
__swig_getmethods__
[
"charge"
]
=
_libpymolfile
.
MolAtoms_charge_get
if
_newclass
:
charge
=
_swig_property
(
_libpymolfile
.
MolAtoms_charge_get
,
_libpymolfile
.
MolAtoms_charge_set
)
__swig_setmethods__
[
"radius"
]
=
_libpymolfile
.
MolAtoms_radius_set
__swig_getmethods__
[
"radius"
]
=
_libpymolfile
.
MolAtoms_radius_get
if
_newclass
:
radius
=
_swig_property
(
_libpymolfile
.
MolAtoms_radius_get
,
_libpymolfile
.
MolAtoms_radius_set
)
__swig_setmethods__
[
"atomicnumber"
]
=
_libpymolfile
.
MolAtoms_atomicnumber_set
__swig_getmethods__
[
"atomicnumber"
]
=
_libpymolfile
.
MolAtoms_atomicnumber_get
if
_newclass
:
atomicnumber
=
_swig_property
(
_libpymolfile
.
MolAtoms_atomicnumber_get
,
_libpymolfile
.
MolAtoms_atomicnumber_set
)
__swig_setmethods__
[
"ctnumber"
]
=
_libpymolfile
.
MolAtoms_ctnumber_set
__swig_getmethods__
[
"ctnumber"
]
=
_libpymolfile
.
MolAtoms_ctnumber_get
if
_newclass
:
ctnumber
=
_swig_property
(
_libpymolfile
.
MolAtoms_ctnumber_get
,
_libpymolfile
.
MolAtoms_ctnumber_set
)
def
__init__
(
self
):
this
=
_libpymolfile
.
new_MolAtoms
()
try
:
self
.
this
.
append
(
this
)
except
__builtin__
.
Exception
:
self
.
this
=
this
__swig_destroy__
=
_libpymolfile
.
delete_MolAtoms
__del__
=
lambda
self
:
None
MolAtoms_swigregister
=
_libpymolfile
.
MolAtoms_swigregister
MolAtoms_swigregister
(
MolAtoms
)
def
del_plugin_structure
(
pymolfile_atoms
:
'PyObject *'
)
->
"void"
:
return
_libpymolfile
.
del_plugin_structure
(
pymolfile_atoms
)
del_plugin_structure
=
_libpymolfile
.
del_plugin_structure
def
alloc_plugin_structure
(
arg1
:
'PyObject *'
,
args
:
'PyObject *'
)
->
"PyObject *"
:
return
_libpymolfile
.
alloc_plugin_structure
(
arg1
,
args
)
alloc_plugin_structure
=
_libpymolfile
.
alloc_plugin_structure
def
del_plugin
(
pymolfile_plugin
:
'PyObject *'
)
->
"void"
:
return
_libpymolfile
.
del_plugin
(
pymolfile_plugin
)
del_plugin
=
_libpymolfile
.
del_plugin
def
molfile_plugin_list
(
maxsize
):
def
del_atoms
(
pymolfile_atoms
:
'PyObject *'
)
->
"void"
:
return
_libpymolfile
.
del_atoms
(
pymolfile_atoms
)
del_atoms
=
_libpymolfile
.
del_atoms
def
del_atomname
(
pymolfile_atoms
:
'PyObject *'
)
->
"void"
:
return
_libpymolfile
.
del_atomname
(
pymolfile_atoms
)
del_atomname
=
_libpymolfile
.
del_atomname
def
alloc_plugin
(
arg1
:
'PyObject *'
,
args
:
'PyObject *'
)
->
"PyObject *"
:
return
_libpymolfile
.
alloc_plugin
(
arg1
,
args
)
alloc_plugin
=
_libpymolfile
.
alloc_plugin
def
molfile_plugin_list
(
maxsize
:
'int'
)
->
"molfile_plugin_t **"
:
"""molfile_plugin_list(maxsize) -> molfile_plugin_t **"""
return
_libpymolfile
.
molfile_plugin_list
(
maxsize
)
def
molfile_init
():
def
molfile_init
()
->
"int"
:
"""molfile_init() -> int"""
return
_libpymolfile
.
molfile_init
()
def
molfile_finish
():
def
molfile_finish
()
->
"int"
:
"""molfile_finish() -> int"""
return
_libpymolfile
.
molfile_finish
()
def
get_plugin
(
plugin_list
,
plugin_no
)
:
def
get_plugin
(
plugin_list
:
'molfile_plugin_t **'
,
plugin_no
:
'int'
)
->
"molfile_plugin_t *"
:
"""get_plugin(plugin_list, plugin_no) -> molfile_plugin_t *"""
return
_libpymolfile
.
get_plugin
(
plugin_list
,
plugin_no
)
def
molfile_plugin_info
(
plugin_list
,
plugin_no
)
:
def
molfile_plugin_info
(
plugin_list
:
'molfile_plugin_t **'
,
plugin_no
:
'int'
)
->
"PyObject *"
:
"""molfile_plugin_info(plugin_list, plugin_no) -> PyObject *"""
return
_libpymolfile
.
molfile_plugin_info
(
plugin_list
,
plugin_no
)
def
open_file_read
(
plugin
:
'molfile_plugin_t *'
,
fname
:
'char *'
,
ftype
:
'char *'
,
natoms
:
'int'
)
->
"PyObject *"
:
"""open_file_read(plugin, fname, ftype, natoms) -> PyObject *"""
return
_libpymolfile
.
open_file_read
(
plugin
,
fname
,
ftype
,
natoms
)
def
read_structure
(
molpack
:
'PyObject *'
)
->
"PyObject *"
:
"""read_structure(molpack) -> PyObject *"""
return
_libpymolfile
.
read_structure
(
molpack
)
# This file is compatible with both classic and new-style classes.
pymolfile/molfile/libpymolfile_wrap.c
View file @
672baac3
This diff is collapsed.
Click to expand it.
pymolfile/molfile/libpymolfile_wrap.cxx
View file @
672baac3
This diff is collapsed.
Click to expand it.
pymolfile/molfile/pymolfile.c
View file @
672baac3
...
...
@@ -36,6 +36,9 @@
int
numplugins
=
0
;
molfile_plugin_t
**
plugin_list
;
/* * * * * * * * * * * * * * * * * * * * * * *
* Helper functions to set and store plugins *
* * * * * * * * * * * * * * * * * * * * * * */
...
...
@@ -58,11 +61,13 @@ struct DICTHOLDER * plugin_find(struct DICTHOLDER *dict, const char *pluginname)
molfile_plugin_t
*
get_plugin
(
molfile_plugin_t
**
plug_list
,
int
plug_no
)
{
molfile_plugin_t
*
plugin
;
if
(
plug_no
<
0
){
return
NULL
;
plugin
=
NULL
;
}
else
{
return
plug_list
[
plug_no
];
plugin
=
plug_list
[
plug_no
];
}
return
plugin
;
}
#if 0
...
...
@@ -245,4 +250,55 @@ int molfile_finish(void)
/* Functions in molfile_plugin_t */
PyObject
*
my_read_structure
(
PyObject
*
molpack
)
{
Py_Initialize
();
import_array
();
int
options
=
0
;
int
i
;
molfile_plugin_t
*
plugin
;
void
*
file_handle
;
molfile_atom_t
*
atoms
;
int
numatoms
,
status
;
PyArray_Descr
*
descr
;
PyObject
p
*
;
if
(
PyType_Ready
(
&
MolAtomType
)
<
0
)
return
NULL
;
PyTypeObject
*
atype
=
&
MolAtomType
;
MolAtom
*
atom_t
;
atom_t
=
(
MolAtom
*
)
atype
->
tp_alloc
(
atype
,
0
);
p
=
(
PyObject
*
)
atom_t
;
descr
=
PyArray_DescrFromObject
(
p
,
NULL
)
MolObject
*
plugin_handle
=
(
MolObject
*
)
molpack
;
plugin
=
plugin_handle
->
plugin
;
file_handle
=
plugin_handle
->
file_handle
;
numatoms
=
plugin_handle
->
natoms
;
atoms
=
(
molfile_atom_t
*
)
calloc
(
numatoms
,
sizeof
(
molfile_atom_t
));
status
=
plugin
->
read_structure
(
file_handle
,
&
options
,
atoms
);
if
(
status
!=
0
){
PyErr_Format
(
PyExc_IOError
,
"Error accessing molfile_atom_t in read_structure function of plugin."
);
return
NULL
;
}