cMolKit-1.5.7~rc1+cvs.20140424/0000755000175000017500000000000012326221060015232 5ustar moellermoellercMolKit-1.5.7~rc1+cvs.20140424/LICENSE0000644000175000017500000000436411033241716016252 0ustar moellermoellerThis software is copyrighted by Michel F. Sanner (sanner@scripps.edu) and TSRI. The following terms apply to all files associated with the software unless explicitly disclaimed in individual files. MGLTOOLS SOFTWARE LICENSE AGREEMENT. 1. Grant Of Limited License; Software Use Restrictions. The programs received by you will be used only for NON COMMERCIAL purposes. This license is issued to you as an individual. For COMMERCIAL use done with the software please contact Michel F. Sanner for details about commercial usage license agreements. For any question regarding license agreements, please contact Michel Sanner: TSRI, Molecular Biology Department, TCP 26, 10550 North Torrey Pines Road, La Jolla, CA 92037 sanner@scripps.edu tel (858) 784-7742 fax (858) 784-2341 2. COMMERCIAL USAGE is defined as revenues generating activities. These include using this software for consulting activities and selling applications built on top of, or using this software. Scientific research in an academic environment and teaching are considered NON COMMERCIAL. 3. Copying Restrictions. You will not sell or otherwise distribute commercially these programs or derivatives to any other party, whether with or without consideration. 4. Ownership of Software. You will not obtain, and will not attempt to obtain copyright coverage thereon without the express purpose written consent of The Scripps Research Institute and Dr. Sanner. 5. IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6. THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. cMolKit-1.5.7~rc1+cvs.20140424/MANIFEST0000644000175000017500000000024410513015402016360 0ustar moellermoellerMANIFEST.in setup.py mglutilc/__init__.py mglutilc/numarr.i mglutilc/xtcparser.i src/gmx_system_xdr.h src/libxdrf.c src/simple.h src/xdrf.h src/xtcio.c src/xtcio.h cMolKit-1.5.7~rc1+cvs.20140424/MANIFEST.in0000644000175000017500000000023411033243147016773 0ustar moellermoellerinclude MANIFEST.in include cMolKit/*.i exclude mglutils/xtcparser.py include src/*.h include CVS/* includ src/CVS/* include cMolKit/CVS/* include LICENSE cMolKit-1.5.7~rc1+cvs.20140424/setup.py0000644000175000017500000000454010675044310016755 0ustar moellermoeller# setup.py - Distutils interface for building mglutilc extensions from distutils.core import setup, Extension from distutils.command.build import build from distutils.command.sdist import sdist import sys from os import path pack_name = "cMolKit" xtc_source = [path.join(pack_name,"xtcparser.i"), path.join("src", "libxdrf.c"), path.join("src","xtcio.c")] if sys.platform == "win32": xtc_source.append(path.join("src","gmx_system_xdr.c")) import numpy numpy_include = numpy.get_include() include_dirs = [path.join(".", "src"), numpy_include] # Change the order of commands that are called by "build" # so that "build_py" command is called after "build_ext". In this case # "build_py" will install (copy to the build directory) python # modules generated by "build_ext'. class modified_build(build): sub_commands = [('build_clib', build.has_c_libraries), ('build_ext', build.has_ext_modules), ('build_py', build.has_pure_modules), ('build_scripts', build.has_scripts), ] # Overwrite the prune_file_list method of sdist to not # remove automatically the RCS/CVS directory from the distribution. class modified_sdist(sdist): def prune_file_list(self): build = self.get_finalized_command('build') base_dir = self.distribution.get_fullname() self.filelist.exclude_pattern(None, prefix=build.build_base) self.filelist.exclude_pattern(None, prefix=base_dir) try: from version import VERSION except: VERSION = "1.0" # setup() dist = setup(name="cMolKit", version=VERSION, description = "Python extension module", author = "Molecular Graphics Laboratory", author_email = "mgltools@scripps.edu", url = "http://www.scripps.edu/~sanner/python/packager.html", py_modules = ['cMolKit/xtcparser', 'cMolKit.__init__'], #packages = ["cMolKit.Tests"], cmdclass = {"build" : modified_build, 'sdist' : modified_sdist}, ext_package = pack_name, ext_modules = [Extension ("_xtcparser", xtc_source, include_dirs = include_dirs, #define_macros = [('UNIX', None),], ) ] ,) cMolKit-1.5.7~rc1+cvs.20140424/version.py0000644000175000017500000000002011475262514017276 0ustar moellermoellerVERSION="1.5.6" cMolKit-1.5.7~rc1+cvs.20140424/cMolKit/0000755000175000017500000000000012326221060016574 5ustar moellermoellercMolKit-1.5.7~rc1+cvs.20140424/cMolKit/__init__.py0000644000175000017500000000003110513015402020674 0ustar moellermoeller#init of mglutilc module cMolKit-1.5.7~rc1+cvs.20140424/cMolKit/numarr.i0000644000175000017500000001101610704725356020270 0ustar moellermoeller%init %{ import_array(); /* load the Numeric PyCObjects */ %} %{ #include "numpy/arrayobject.h" #define Get2D(arr, dims, i, j) arr[(i * dims[1]) + j] #define Get3D(arr, dims, i, j, k) arr[(i * dims[1] * dims[2]) + \ (j * dims[2]) + k] #define Get4D(arr, dims, i, j, k, l) arr[(i * dims[1] * dims[2] * dims[3]) + \ (j * dims[2] * dims[3]) + \ (k * dims[3]) + l] static PyArrayObject *contiguous_typed_array(PyObject *obj, int typecode, int expectnd, int *expectdims) { PyArrayObject *arr; int i; char buf[255]; /* if the shape and type are OK, this function increments the reference count and arr points to obj */ if((arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj, typecode, 0, 10)) == NULL) { sprintf(buf,"Failed to make a contiguous array of type %d\n", typecode); PyErr_SetString(PyExc_ValueError, buf); return NULL; } if(expectnd>0) { if(arr->nd > expectnd + 1 || arr->nd < expectnd) { Py_DECREF((PyObject *)arr); PyErr_SetString(PyExc_ValueError, "Array has wrong number of dimensions"); return NULL; } if(arr->nd == expectnd + 1) { if(arr->dimensions[arr->nd - 1] != 1) { Py_DECREF((PyObject *)arr); PyErr_SetString(PyExc_ValueError, "Array has wrong number of dimensions"); return NULL; } } if(expectdims) { for(i = 0; i < expectnd; i++) if(expectdims[i]>0) if(expectdims[i] != arr->dimensions[i]) { Py_DECREF((PyObject *)arr); sprintf(buf,"The extent of dimension %d is %d while %d was expected\n", i, arr->dimensions[i], expectdims[i]); PyErr_SetString(PyExc_ValueError, buf); return NULL; } } } return arr; } %} %define INT_VECTOR( ARRAYNAME, ARRAYSHAPE, LENGTH ) %typemap(in) (int ARRAYNAME##ARRAYSHAPE, int LENGTH) (PyArrayObject *array, int expected_dims[1]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; if (expected_dims[0]==1) expected_dims[0]=0; array = contiguous_typed_array($input, PyArray_INT, 1, expected_dims); if (! array) return NULL; $1 = (int *)array->data; $2 = ((PyArrayObject *)(array))->dimensions[0]; } else { array = NULL; $1 = NULL; $2 = 0; } %} %typemap(freearg) (int ARRAYNAME##ARRAYSHAPE, int LENGTH) %{ if (array$argnum) { Py_DECREF((PyObject *)array$argnum); } %} %enddef %define INT_ARRAY2D( ARRAYNAME, ARRAYSHAPE, DIMENSIONS ) %typemap(in) ( int ARRAYNAME##ARRAYSHAPE, int DIMENSIONS)(PyArrayObject *array, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; expected_dims[1] = $1_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_INT, 2, expected_dims); if (! array) return NULL; $1 = (int (*)[$1_dim1])array->data; $2 = ((PyArrayObject *)(array))->dimensions[0]; } else { array = NULL; $1 = NULL; $2 = 0; } %} %typemap(freearg) (int ARRAYNAME##ARRAYSHAPE, int DIMENSIONS) %{ if (array$argnum) { Py_DECREF((PyObject *)array$argnum); } %} %enddef %define FLOAT_ARRAY2D( ARRAYNAME, ARRAYSHAPE, DIMENSIONS ) %typemap(in) ( float ARRAYNAME##ARRAYSHAPE, int DIMENSIONS)(PyArrayObject *array, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; expected_dims[1] = $1_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_FLOAT, 2, expected_dims); if (! array) return NULL; $1 = (float (*)[$1_dim1])array->data; $2 = ((PyArrayObject *)(array))->dimensions[0]; } else { array = NULL; $1 = NULL; $2 = 0; } %} %typemap(freearg) (float ARRAYNAME##ARRAYSHAPE, int DIMENSIONS ) %{ if (array$argnum ) { Py_DECREF((PyObject *)array$argnum); } %} %enddef cMolKit-1.5.7~rc1+cvs.20140424/cMolKit/xtcparser.i0000644000175000017500000001326011037156536021000 0ustar moellermoeller%module xtcparser %{ // this file contains methods for reading GROMACS xtc trajectory files. #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined __CYGWIN__ || defined __CYGWIN32__ || defined GMX_INTERNAL_XDR) #include "gmx_system_xdr.h" #else #include #include #endif #include #include #include "xtcio.h" #define INDENT 3 #define true (1==1) #define false (!true) typedef struct { FILE * fp; XDR xdrs; } fileid; static fileid FIO; int pr_indent(FILE *fp,int n) { int i; for (i=0; inatoms) { fprintf(stderr, "Frame contains more atoms (%d) than expected (%d)", n, natoms); return 0; } /* Check magic number */ check_xtc_magic(magic); snew(x,natoms); bOK=xtc_coord(&(FIO.xdrs),&natoms,box,x,prec,TRUE); for (i=0; i #endif #include #include #include #include "gmx_system_xdr.h" /* NB - THIS FILE IS ONLY USED ON MICROSOFT WINDOWS, since that * system doesn't provide any standard XDR system libraries. It will * most probably work on other platforms too, but make sure you * test that the xtc files produced are ok before using it. * * This header file contains Gromacs versions of the definitions for * Sun External Data Representation (XDR) headers and routines. * * On most UNIX systems this is already present as part of your * system libraries, but since we want to make Gromacs portable to * platforms like Microsoft Windows we have created a private version * of the necessary routines and distribute them with the Gromacs source. * * Although the rest of Gromacs is GPL, you can copy and use the XDR * routines in any way you want as long as you obey Sun's license: * * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * for unit alignment */ static char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; static xdr_uint32_t xdr_swapbytes(xdr_uint32_t x) { xdr_uint32_t y; int i; char *px=(char *)&x; char *py=(char *)&y; for(i=0;i<4;i++) py[i]=px[3-i]; return y; } static xdr_uint32_t xdr_htonl(xdr_uint32_t x) { short s=0x0F00; if( *((char *)&s)==(char)0x0F) { /* bigendian, do nothing */ return x; } else { /* smallendian,swap bytes */ return xdr_swapbytes(x); } } static xdr_uint32_t xdr_ntohl(xdr_uint32_t x) { short s=0x0F00; if( *((char *)&s)==(char)0x0F) { /* bigendian, do nothing */ return x; } else { /* smallendian, swap bytes */ return xdr_swapbytes(x); } } /* * Free a data structure using XDR * Not a filter, but a convenient utility nonetheless */ void xdr_free (xdrproc_t proc, char *objp) { XDR x; x.x_op = XDR_FREE; (*proc) (&x, objp); } /* * XDR nothing */ bool_t xdr_void (void) { return TRUE; } /* * XDR integers */ bool_t xdr_int (XDR *xdrs, int *ip) { xdr_int32_t l; switch (xdrs->x_op) { case XDR_ENCODE: l = (xdr_int32_t) (*ip); return xdr_putint32 (xdrs, &l); case XDR_DECODE: if (!xdr_getint32 (xdrs, &l)) { return FALSE; } *ip = (int) l; case XDR_FREE: return TRUE; } return FALSE; } /* * XDR unsigned integers */ bool_t xdr_u_int (XDR *xdrs, unsigned int *up) { xdr_uint32_t l; switch (xdrs->x_op) { case XDR_ENCODE: l = (xdr_uint32_t) (*up); return xdr_putuint32 (xdrs, &l); case XDR_DECODE: if (!xdr_getuint32 (xdrs, &l)) { return FALSE; } *up = (unsigned int) l; case XDR_FREE: return TRUE; } return FALSE; } /* * XDR short integers */ bool_t xdr_short (XDR *xdrs, short *sp) { xdr_int32_t l; switch (xdrs->x_op) { case XDR_ENCODE: l = (xdr_int32_t) *sp; return xdr_putint32 (xdrs, &l); case XDR_DECODE: if (!xdr_getint32 (xdrs, &l)) { return FALSE; } *sp = (short) l; return TRUE; case XDR_FREE: return TRUE; } return FALSE; } /* * XDR unsigned short integers */ bool_t xdr_u_short (XDR *xdrs, unsigned short *usp) { xdr_uint32_t l; switch (xdrs->x_op) { case XDR_ENCODE: l = (xdr_uint32_t) *usp; return xdr_putuint32 (xdrs, &l); case XDR_DECODE: if (!xdr_getuint32 (xdrs, &l)) { return FALSE; } *usp = (unsigned short) l; return TRUE; case XDR_FREE: return TRUE; } return FALSE; } /* * XDR a char */ bool_t xdr_char (XDR *xdrs, char *cp) { int i; i = (*cp); if (!xdr_int (xdrs, &i)) { return FALSE; } *cp = i; return TRUE; } /* * XDR an unsigned char */ bool_t xdr_u_char (XDR *xdrs, unsigned char *cp) { unsigned int u; u = (*cp); if (!xdr_u_int (xdrs, &u)) { return FALSE; } *cp = u; return TRUE; } /* * XDR booleans */ bool_t xdr_bool (XDR *xdrs, int *bp) { #define XDR_FALSE ((xdr_int32_t) 0) #define XDR_TRUE ((xdr_int32_t) 1) xdr_int32_t lb; switch (xdrs->x_op) { case XDR_ENCODE: lb = *bp ? XDR_TRUE : XDR_FALSE; return xdr_putint32 (xdrs, &lb); case XDR_DECODE: if (!xdr_getint32 (xdrs, &lb)) { return FALSE; } *bp = (lb == XDR_FALSE) ? FALSE : TRUE; return TRUE; case XDR_FREE: return TRUE; } return FALSE; #undef XDR_FALSE #undef XDR_TRUE } /* * XDR opaque data * Allows the specification of a fixed size sequence of opaque bytes. * cp points to the opaque object and cnt gives the byte length. */ bool_t xdr_opaque (XDR *xdrs, char *cp, unsigned int cnt) { unsigned int rndup; static char crud[BYTES_PER_XDR_UNIT]; /* * if no data we are done */ if (cnt == 0) return TRUE; /* * round byte count to full xdr units */ rndup = cnt % BYTES_PER_XDR_UNIT; if (rndup > 0) rndup = BYTES_PER_XDR_UNIT - rndup; switch (xdrs->x_op) { case XDR_DECODE: if (!xdr_getbytes (xdrs, cp, cnt)) { return FALSE; } if (rndup == 0) return TRUE; return xdr_getbytes (xdrs, (char *)crud, rndup); case XDR_ENCODE: if (!xdr_putbytes (xdrs, cp, cnt)) { return FALSE; } if (rndup == 0) return TRUE; return xdr_putbytes (xdrs, xdr_zero, rndup); case XDR_FREE: return TRUE; } return FALSE; } /* * XDR null terminated ASCII strings * xdr_string deals with "C strings" - arrays of bytes that are * terminated by a NULL character. The parameter cpp references a * pointer to storage; If the pointer is null, then the necessary * storage is allocated. The last parameter is the max allowed length * of the string as specified by a protocol. */ bool_t xdr_string (xdrs, cpp, maxsize) XDR *xdrs; char **cpp; unsigned int maxsize; { char *sp = *cpp; /* sp is the actual string pointer */ unsigned int size = 0; unsigned int nodesize = 0; /* * first deal with the length since xdr strings are counted-strings */ switch (xdrs->x_op) { case XDR_FREE: if (sp == NULL) { return TRUE; /* already free */ } /* fall through... */ case XDR_ENCODE: if (sp == NULL) return FALSE; size = strlen (sp); break; case XDR_DECODE: break; } if (!xdr_u_int (xdrs, &size)) { return FALSE; } if (size > maxsize) { return FALSE; } nodesize = size + 1; /* * now deal with the actual bytes */ switch (xdrs->x_op) { case XDR_DECODE: if (nodesize == 0) { return TRUE; } if (sp == NULL) *cpp = sp = (char *) malloc (nodesize); if (sp == NULL) { (void) fputs ("xdr_string: out of memory\n", stderr); return FALSE; } sp[size] = 0; /* fall into ... */ case XDR_ENCODE: return xdr_opaque (xdrs, sp, size); case XDR_FREE: free (sp); *cpp = NULL; return TRUE; } return FALSE; } /* Floating-point stuff */ bool_t xdr_float(xdrs, fp) XDR *xdrs; float *fp; { xdr_int32_t tmp; switch (xdrs->x_op) { case XDR_ENCODE: tmp = *(xdr_int32_t *)fp; return (xdr_putint32(xdrs, &tmp)); break; case XDR_DECODE: if (xdr_getint32(xdrs, &tmp)) { *(xdr_int32_t *)fp = tmp; return (TRUE); } break; case XDR_FREE: return (TRUE); } return (FALSE); } bool_t xdr_double(xdrs, dp) XDR *xdrs; double *dp; { /* Windows and some other systems dont define double-precision * word order in the header files, so unfortunately we have * to calculate it! */ static int LSW=-1; /* Least significant fp word */ int *ip; xdr_int32_t tmp[2]; if(LSW<0) { double x=0.987654321; /* Just a number */ /* Possible representations in IEEE double precision: * (S=small endian, B=big endian) * * Byte order, Word order, Hex * S S b8 56 0e 3c dd 9a ef 3f * B S 3c 0e 56 b8 3f ef 9a dd * S B dd 9a ef 3f b8 56 0e 3c * B B 3f ef 9a dd 3c 0e 56 b8 */ unsigned char ix = *((char *)&x); if(ix==0xdd || ix==0x3f) LSW=1; /* Big endian word order */ else if(ix==0xb8 || ix==0x3c) LSW=0; /* Small endian word order */ else { /* Catch strange errors */ printf("Error when detecting floating-point word order.\n" "Do you have a non-IEEE system?\n" "If possible, use the XDR libraries provided with your system,\n" "instead of the Gromacs fallback XDR source.\n"); exit(0); } } switch (xdrs->x_op) { case XDR_ENCODE: ip = (int *)dp; tmp[0] = ip[!LSW]; tmp[1] = ip[LSW]; return (xdr_putint32(xdrs, tmp) && xdr_putint32(xdrs, tmp+1)); break; case XDR_DECODE: ip = (int *)dp; if (xdr_getint32(xdrs, tmp+!LSW) && xdr_getint32(xdrs, tmp+LSW)) { ip[0] = tmp[0]; ip[1] = tmp[1]; return (TRUE); } break; case XDR_FREE: return (TRUE); } return (FALSE); } /* Array routines */ /* * xdr_vector(): * * XDR a fixed length array. Unlike variable-length arrays, * the storage of fixed length arrays is static and unfreeable. * > basep: base of the array * > size: size of the array * > elemsize: size of each element * > xdr_elem: routine to XDR each element */ bool_t xdr_vector (xdrs, basep, nelem, elemsize, xdr_elem) XDR *xdrs; char *basep; unsigned int nelem; unsigned int elemsize; xdrproc_t xdr_elem; { #define LASTUNSIGNED ((unsigned int)0-1) unsigned int i; char *elptr; elptr = basep; for (i = 0; i < nelem; i++) { if (!(*xdr_elem) (xdrs, elptr, LASTUNSIGNED)) { return FALSE; } elptr += elemsize; } return TRUE; #undef LASTUNSIGNED } static bool_t xdrstdio_getbytes (XDR *, char *, unsigned int); static bool_t xdrstdio_putbytes (XDR *, char *, unsigned int); static unsigned int xdrstdio_getpos (XDR *); static bool_t xdrstdio_setpos (XDR *, unsigned int); static xdr_int32_t *xdrstdio_inline (XDR *, int); static void xdrstdio_destroy (XDR *); static bool_t xdrstdio_getint32 (XDR *, xdr_int32_t *); static bool_t xdrstdio_putint32 (XDR *, xdr_int32_t *); static bool_t xdrstdio_getuint32 (XDR *, xdr_uint32_t *); static bool_t xdrstdio_putuint32 (XDR *, xdr_uint32_t *); /* * Ops vector for stdio type XDR */ static const struct xdr_ops xdrstdio_ops = { xdrstdio_getbytes, /* deserialize counted bytes */ xdrstdio_putbytes, /* serialize counted bytes */ xdrstdio_getpos, /* get offset in the stream */ xdrstdio_setpos, /* set offset in the stream */ xdrstdio_inline, /* prime stream for inline macros */ xdrstdio_destroy, /* destroy stream */ xdrstdio_getint32, /* deserialize a int */ xdrstdio_putint32, /* serialize a int */ xdrstdio_getuint32, /* deserialize a int */ xdrstdio_putuint32 /* serialize a int */ }; /* * Initialize a stdio xdr stream. * Sets the xdr stream handle xdrs for use on the stream file. * Operation flag is set to op. */ void xdrstdio_create (XDR *xdrs, FILE *file, enum xdr_op op) { xdrs->x_op = op; /* We have to add the const since the `struct xdr_ops' in `struct XDR' is not `const'. */ xdrs->x_ops = (struct xdr_ops *) &xdrstdio_ops; xdrs->x_private = (char *) file; xdrs->x_handy = 0; xdrs->x_base = 0; } /* * Destroy a stdio xdr stream. * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create. */ static void xdrstdio_destroy (XDR *xdrs) { (void) fflush ((FILE *) xdrs->x_private); /* xx should we close the file ?? */ } static bool_t xdrstdio_getbytes (XDR *xdrs, char *addr, unsigned int len) { if ((len != 0) && (fread (addr, (int) len, 1, (FILE *) xdrs->x_private) != 1)) return FALSE; return TRUE; } static bool_t xdrstdio_putbytes (XDR *xdrs, char *addr, unsigned int len) { if ((len != 0) && (fwrite (addr, (int) len, 1, (FILE *) xdrs->x_private) != 1)) return FALSE; return TRUE; } static unsigned int xdrstdio_getpos (XDR *xdrs) { return (unsigned int) ftell ((FILE *) xdrs->x_private); } static bool_t xdrstdio_setpos (XDR *xdrs, unsigned int pos) { return fseek ((FILE *) xdrs->x_private, (xdr_int32_t) pos, 0) < 0 ? FALSE : TRUE; } static xdr_int32_t * xdrstdio_inline (XDR *xdrs, int len) { /* * Must do some work to implement this: must insure * enough data in the underlying stdio buffer, * that the buffer is aligned so that we can indirect through a * long *, and stuff this pointer in xdrs->x_buf. Doing * a fread or fwrite to a scratch buffer would defeat * most of the gains to be had here and require storage * management on this buffer, so we don't do this. */ return NULL; } static bool_t xdrstdio_getint32 (XDR *xdrs, xdr_int32_t *ip) { xdr_int32_t mycopy; if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1) return FALSE; *ip = xdr_ntohl (mycopy); return TRUE; } static bool_t xdrstdio_putint32 (XDR *xdrs, xdr_int32_t *ip) { xdr_int32_t mycopy = xdr_htonl (*ip); ip = &mycopy; if (fwrite ((char *) ip, 4, 1, (FILE *) xdrs->x_private) != 1) return FALSE; return TRUE; } static bool_t xdrstdio_getuint32 (XDR *xdrs, xdr_uint32_t *ip) { xdr_uint32_t mycopy; if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1) return FALSE; *ip = xdr_ntohl (mycopy); return TRUE; } static bool_t xdrstdio_putuint32 (XDR *xdrs, xdr_uint32_t *ip) { xdr_uint32_t mycopy = xdr_htonl (*ip); ip = &mycopy; if (fwrite ((char *) ip, 4, 1, (FILE *) xdrs->x_private) != 1) return FALSE; return TRUE; } cMolKit-1.5.7~rc1+cvs.20140424/src/gmx_system_xdr.h0000644000175000017500000002134210513015402021245 0ustar moellermoeller/* * $Id: gmx_system_xdr.h,v 1.1.1.1 2006/10/10 22:13:22 annao Exp $ * * This source code is part of * * G R O M A C S * * GROningen MAchine for Chemical Simulations * * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * If you want to redistribute modifications, please consider that * scientific software is very special. Version control is crucial - * bugs must be traceable. We will be happy to consider code for * inclusion in the official distribution, but derived work must not * be called official GROMACS. Details are found in the README & COPYING * files - if they are missing, get the official version at www.gromacs.org. * * To help us fund GROMACS development, we humbly ask that you cite * the papers on the package - you can find them in the top README file. * * For more info, check our website at http://www.gromacs.org * * And Hey: * Gromacs Runs On Most of All Computer Systems */ #ifndef _gmx_system_xdr_h #define _gmx_system_xdr_h #include #include #include /* * This header file is ONLY used on windows systems, since these do * not include the XDR routines present on a unix machine. It will * most probably work on other platforms too, but make sure you * test that the xtc files produced are ok before using it. * * This header file contains Gromacs versions of the definitions for * Sun External Data Representation (XDR) headers and routines. * * On most UNIX systems this is already present as part of your * system libraries, but since we want to make Gromacs portable to * platforms like Microsoft Windows we have created a private version * of the necessary routines and distribute them with the Gromacs source. * * Although the rest of Gromacs is GPL, you can copy and use the XDR * routines in any way you want as long as you obey Sun's license: * * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * Xdr operations. XDR_ENCODE causes the type to be encoded into the * stream. XDR_DECODE causes the type to be extracted from the stream. * XDR_FREE can be used to release the space allocated by an * XDR_DECODE request. */ /* We already have a boolean type in Gromacs, but the XDR library * one has a slightly different name (the calls should be identical). */ typedef int bool_t; /* * Aninteger type that is 32 bits wide. Check if int, * long or short is 32 bits and die if none of them is :-) */ #if (INT_MAX == 2147483647) typedef int xdr_int32_t; typedef unsigned int xdr_uint32_t; #elif (LONG_MAX == 2147483647L) typedef long xdr_int32_t; typedef unsigned long xdr_uint32_t; #elif (SHRT_MAX == 2147483647) typedef short xdr_int32_t; typedef unsigned short xdr_uint32_t; #else # error ERROR: No 32 bit wide integer type found! #endif enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; #ifndef FALSE # define FALSE (0) #endif #ifndef TRUE # define TRUE (1) #endif #define BYTES_PER_XDR_UNIT (4) /* Macro to round up to units of 4. */ #define XDR_RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1)) /* * The XDR handle. * Contains operation which is being applied to the stream, * an operations vector for the particular implementation (e.g. see xdr_mem.c), * and two private fields for the use of the particular implementation. */ typedef struct XDR XDR; struct XDR { enum xdr_op x_op; /* operation; fast additional param */ struct xdr_ops { bool_t (*x_getbytes) (XDR *__xdrs, char *__addr, unsigned int __len); /* get some bytes from " */ bool_t (*x_putbytes) (XDR *__xdrs, char *__addr, unsigned int __len); /* put some bytes to " */ unsigned int (*x_getpostn) (XDR *__xdrs); /* returns bytes off from beginning */ bool_t (*x_setpostn) (XDR *__xdrs, unsigned int __pos); /* lets you reposition the stream */ xdr_int32_t *(*x_inline) (XDR *__xdrs, int __len); /* buf quick ptr to buffered data */ void (*x_destroy) (XDR *__xdrs); /* free privates of this xdr_stream */ bool_t (*x_getint32) (XDR *__xdrs, xdr_int32_t *__ip); /* get a int from underlying stream */ bool_t (*x_putint32) (XDR *__xdrs, xdr_int32_t *__ip); /* put a int to " */ bool_t (*x_getuint32) (XDR *__xdrs, xdr_uint32_t *__ip); /* get a unsigned int from underlying stream */ bool_t (*x_putuint32) (XDR *__xdrs, xdr_uint32_t *__ip); /* put a int to " */ } *x_ops; char *x_public; /* users' data */ char *x_private; /* pointer to private data */ char *x_base; /* private used for position info */ int x_handy; /* extra private word */ }; /* * A xdrproc_t exists for each data type which is to be encoded or decoded. * * The second argument to the xdrproc_t is a pointer to an opaque pointer. * The opaque pointer generally points to a structure of the data type * to be decoded. If this pointer is 0, then the type routines should * allocate dynamic storage of the appropriate size and return it. */ typedef bool_t (*xdrproc_t) (XDR *, void *,...); /* * Operations defined on a XDR handle * * XDR *xdrs; * xdr_int32_t *int32p; * long *longp; * char *addr; * unsigned int len; * unsigned int pos; */ #define xdr_getint32(xdrs, int32p) \ (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) #define xdr_putint32(xdrs, int32p) \ (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) #define xdr_getuint32(xdrs, uint32p) \ (*(xdrs)->x_ops->x_getuint32)(xdrs, uint32p) #define xdr_putuint32(xdrs, uint32p) \ (*(xdrs)->x_ops->x_putuint32)(xdrs, uint32p) #define xdr_getbytes(xdrs, addr, len) \ (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define xdr_putbytes(xdrs, addr, len) \ (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define xdr_getpos(xdrs) \ (*(xdrs)->x_ops->x_getpostn)(xdrs) #define xdr_setpos(xdrs, pos) \ (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) #define xdr_inline(xdrs, len) \ (*(xdrs)->x_ops->x_inline)(xdrs, len) #define xdr_destroy(xdrs) \ do { \ if ((xdrs)->x_ops->x_destroy) \ (*(xdrs)->x_ops->x_destroy)(xdrs); \ } while (0) extern bool_t xdr_int (XDR *__xdrs, int *__ip); extern bool_t xdr_u_int (XDR *__xdrs, unsigned int *__ip); extern bool_t xdr_short (XDR *__xdrs, short *__ip); extern bool_t xdr_u_short (XDR *__xdrs, unsigned short *__ip); extern bool_t xdr_bool (XDR *__xdrs, int *__bp); extern bool_t xdr_opaque (XDR *__xdrs, char *__cp, unsigned int __cnt); extern bool_t xdr_string (XDR *__xdrs, char **__cpp, unsigned int __maxsize); extern bool_t xdr_char (XDR *__xdrs, char *__cp); extern bool_t xdr_u_char (XDR *__xdrs, unsigned char *__cp); extern bool_t xdr_vector (XDR *__xdrs, char *__basep, unsigned int __nelem, unsigned int __elemsize, xdrproc_t __xdr_elem); extern bool_t xdr_float (XDR *__xdrs, float *__fp); extern bool_t xdr_double (XDR *__xdrs, double *__dp); extern void xdrstdio_create (XDR *__xdrs, FILE *__file, enum xdr_op __xop); /* free memory buffers for xdr */ extern void xdr_free (xdrproc_t __proc, char *__objp); #endif /* _gmx_system_xdr_h */ cMolKit-1.5.7~rc1+cvs.20140424/src/libxdrf.c0000644000175000017500000003237410513015402017625 0ustar moellermoeller/* * $Id: libxdrf.c,v 1.1.1.1 2006/10/10 22:13:22 annao Exp $ * * This source code is part of * * G R O M A C S * * GROningen MAchine for Chemical Simulations * * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * If you want to redistribute modifications, please consider that * scientific software is very special. Version control is crucial - * bugs must be traceable. We will be happy to consider code for * inclusion in the official distribution, but derived work must not * be called official GROMACS. Details are found in the README & COPYING * files - if they are missing, get the official version at www.gromacs.org. * * To help us fund GROMACS development, we humbly ask that you cite * the papers on the package - you can find them in the top README file. * * For more info, check our website at http://www.gromacs.org * * And Hey: * GROningen Mixture of Alchemy and Childrens' Stories */ /* This file is modified by Anna Omelchenko, MGL, TSRI */ #include #include #include #include #include #include "xdrf.h" #define MAXID 256 #define MAXABS INT_MAX-2 #ifndef MIN #define MIN(x,y) ((x) < (y) ? (x):(y)) #endif #ifndef MAX #define MAX(x,y) ((x) > (y) ? (x):(y)) #endif #ifndef SQR #define SQR(x) ((x)*(x)) #endif static int magicints[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 101, 128, 161, 203, 256, 322, 406, 512, 645, 812, 1024, 1290, 1625, 2048, 2580, 3250, 4096, 5060, 6501, 8192, 10321, 13003, 16384, 20642, 26007, 32768, 41285, 52015, 65536, 82570, 104031, 131072, 165140, 208063, 262144, 330280, 416127, 524287, 660561, 832255, 1048576, 1321122, 1664510, 2097152, 2642245, 3329021, 4194304, 5284491, 6658042, 8388607, 10568983, 13316085, 16777216 }; #define FIRSTIDX 9 /* note that magicints[FIRSTIDX-1] == 0 */ #define LASTIDX (sizeof(magicints) / sizeof(*magicints)) int xdr_real(XDR *xdrs,real *r) { #ifdef GMX_DOUBLE float f; int ret; f=*r; ret=xdr_float(xdrs,&f); *r=f; return ret; #else return xdr_float(xdrs,(float *)r); #endif } /*_________________________________________________________________________ | | sizeofint - calculate bitsize of an integer | | return the number of bits needed to store an integer with given max size | */ static int sizeofint(const int size) { unsigned int num = 1; int num_of_bits = 0; while (size >= num && num_of_bits < 32) { num_of_bits++; num <<= 1; } return num_of_bits; } /*___________________________________________________________________________ | | sizeofints - calculate 'bitsize' of compressed ints | | given the number of small unsigned integers and the maximum value | return the number of bits needed to read or write them with the | routines receiveints and sendints. You need this parameter when | calling these routines. Note that for many calls I can use | the variable 'smallidx' which is exactly the number of bits, and | So I don't need to call 'sizeofints for those calls. */ static int sizeofints( const int num_of_ints, unsigned int sizes[]) { int i, num; unsigned int num_of_bytes, num_of_bits, bytes[32], bytecnt, tmp; num_of_bytes = 1; bytes[0] = 1; num_of_bits = 0; for (i=0; i < num_of_ints; i++) { tmp = 0; for (bytecnt = 0; bytecnt < num_of_bytes; bytecnt++) { tmp = bytes[bytecnt] * sizes[i] + tmp; bytes[bytecnt] = tmp & 0xff; tmp >>= 8; } while (tmp != 0) { bytes[bytecnt++] = tmp & 0xff; tmp >>= 8; } num_of_bytes = bytecnt; } num = 1; num_of_bytes--; while (bytes[num_of_bytes] >= num) { num_of_bits++; num *= 2; } return num_of_bits + num_of_bytes * 8; } /*___________________________________________________________________________ | | receivebits - decode number from buf using specified number of bits | | extract the number of bits from the array buf and construct an integer | from it. Return that value. | */ static int receivebits(int buf[], int num_of_bits) { int cnt, num; unsigned int lastbits, lastbyte; unsigned char * cbuf; int mask = (1 << num_of_bits) -1; cbuf = ((unsigned char *)buf) + 3 * sizeof(*buf); cnt = buf[0]; lastbits = (unsigned int) buf[1]; lastbyte = (unsigned int) buf[2]; num = 0; while (num_of_bits >= 8) { lastbyte = ( lastbyte << 8 ) | cbuf[cnt++]; num |= (lastbyte >> lastbits) << (num_of_bits - 8); num_of_bits -=8; } if (num_of_bits > 0) { if (lastbits < num_of_bits) { lastbits += 8; lastbyte = (lastbyte << 8) | cbuf[cnt++]; } lastbits -= num_of_bits; num |= (lastbyte >> lastbits) & ((1 << num_of_bits) -1); } num &= mask; buf[0] = cnt; buf[1] = lastbits; buf[2] = lastbyte; return num; } /*____________________________________________________________________________ | | receiveints - decode 'small' integers from the buf array | | this routine is the inverse from sendints() and decodes the small integers | written to buf by calculating the remainder and doing divisions with | the given sizes[]. You need to specify the total number of bits to be | used from buf in num_of_bits. | */ static void receiveints(int buf[], const int num_of_ints, int num_of_bits, unsigned int sizes[], int nums[]) { int bytes[32]; int i, j, num_of_bytes, p, num; bytes[1] = bytes[2] = bytes[3] = 0; num_of_bytes = 0; while (num_of_bits > 8) { bytes[num_of_bytes++] = receivebits(buf, 8); num_of_bits -= 8; } if (num_of_bits > 0) { bytes[num_of_bytes++] = receivebits(buf, num_of_bits); } for (i = num_of_ints-1; i > 0; i--) { num = 0; for (j = num_of_bytes-1; j >=0; j--) { num = (num << 8) | bytes[j]; p = num / sizes[i]; bytes[j] = p; num = num - p * sizes[i]; } nums[i] = num; } nums[0] = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); } /*____________________________________________________________________________ | | xdr3dfcoord - read or write compressed 3d coordinates to xdr file. | | this routine reads or writes (depending on how you opened the file with | xdropen() ) a large number of 3d coordinates (stored in *fp). | The number of coordinates triplets to write is given by *size. On | read this number may be zero, in which case it reads as many as were written | or it may specify the number if triplets to read (which should match the | number written). | Compression is achieved by first converting all floating numbers to integer | using multiplication by *precision and rounding to the nearest integer. | Then the minimum and maximum value are calculated to determine the range. | The limited range of integers so found, is used to compress the coordinates. | In addition the differences between succesive coordinates is calculated. | If the difference happens to be 'small' then only the difference is saved, | compressing the data even more. The notion of 'small' is changed dynamically | and is enlarged or reduced whenever needed or possible. | Extra compression is achieved in the case of GROMOS and coordinates of | water molecules. GROMOS first writes out the Oxygen position, followed by | the two hydrogens. In order to make the differences smaller (and thereby | compression the data better) the order is changed into first one hydrogen | then the oxygen, followed by the other hydrogen. This is rather special, but | it shouldn't harm in the general case. | */ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) { static int *ip = NULL; static int oldsize; static int *buf; int minint[3], maxint[3], *lip; int smallidx; int minidx, maxidx; unsigned sizeint[3], sizesmall[3], bitsizeint[3], size3; int flag, k; int smallnum, smaller, larger, i, is_smaller, run; float *lfp; int tmp, *thiscoord, prevcoord[3]; int bufsize, lsize; unsigned int bitsize; float inv_precision; bitsizeint[0] = bitsizeint[1] = bitsizeint[2] = 0; prevcoord[0] = prevcoord[1] = prevcoord[2] = 0; if (xdr_int(xdrs, &lsize) == 0) return 0; if (*size != 0 && lsize != *size) { fprintf(stderr, "wrong number of coordinates in xdr3dfcoord; " "%d arg vs %d in file", *size, lsize); } *size = lsize; size3 = *size * 3; if (*size <= 9) { return (xdr_vector(xdrs, (char *) fp, (unsigned int)size3, (unsigned int)sizeof(*fp), (xdrproc_t)xdr_float)); } xdr_float(xdrs, precision); if (ip == NULL) { ip = (int *)malloc((size_t)(size3 * sizeof(*ip))); if (ip == NULL) { fprintf(stderr,"malloc failed\n"); exit(1); } bufsize = size3 * 1.2; buf = (int *)malloc((size_t)(bufsize * sizeof(*buf))); if (buf == NULL) { fprintf(stderr,"malloc failed\n"); exit(1); } oldsize = *size; } else if (*size > oldsize) { ip = (int *)realloc(ip, (size_t)(size3 * sizeof(*ip))); if (ip == NULL) { fprintf(stderr,"malloc failed\n"); exit(1); } bufsize = size3 * 1.2; buf = (int *)realloc(buf, (size_t)(bufsize * sizeof(*buf))); if (buf == NULL) { fprintf(stderr,"malloc failed\n"); exit(1); } oldsize = *size; } buf[0] = buf[1] = buf[2] = 0; xdr_int(xdrs, &(minint[0])); xdr_int(xdrs, &(minint[1])); xdr_int(xdrs, &(minint[2])); xdr_int(xdrs, &(maxint[0])); xdr_int(xdrs, &(maxint[1])); xdr_int(xdrs, &(maxint[2])); sizeint[0] = maxint[0] - minint[0]+1; sizeint[1] = maxint[1] - minint[1]+1; sizeint[2] = maxint[2] - minint[2]+1; /* check if one of the sizes is to big to be multiplied */ if ((sizeint[0] | sizeint[1] | sizeint[2] ) > 0xffffff) { bitsizeint[0] = sizeofint(sizeint[0]); bitsizeint[1] = sizeofint(sizeint[1]); bitsizeint[2] = sizeofint(sizeint[2]); bitsize = 0; /* flag the use of large sizes */ } else { bitsize = sizeofints(3, sizeint); } if (xdr_int(xdrs, &smallidx) == 0) return 0; maxidx = MIN(LASTIDX, smallidx + 8) ; minidx = maxidx - 8; /* often this equal smallidx */ smaller = magicints[MAX(FIRSTIDX, smallidx-1)] / 2; smallnum = magicints[smallidx] / 2; sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx] ; larger = magicints[maxidx]; /* buf[0] holds the length in bytes */ if (xdr_int(xdrs, &(buf[0])) == 0) return 0; if (xdr_opaque(xdrs, (char *)&(buf[3]), (unsigned int)buf[0]) == 0) return 0; buf[0] = buf[1] = buf[2] = 0; lfp = fp; inv_precision = 1.0 / * precision; run = 0; i = 0; lip = ip; while ( i < lsize ) { thiscoord = (int *)(lip) + i * 3; if (bitsize == 0) { thiscoord[0] = receivebits(buf, bitsizeint[0]); thiscoord[1] = receivebits(buf, bitsizeint[1]); thiscoord[2] = receivebits(buf, bitsizeint[2]); } else { receiveints(buf, 3, bitsize, sizeint, thiscoord); } i++; thiscoord[0] += minint[0]; thiscoord[1] += minint[1]; thiscoord[2] += minint[2]; prevcoord[0] = thiscoord[0]; prevcoord[1] = thiscoord[1]; prevcoord[2] = thiscoord[2]; flag = receivebits(buf, 1); is_smaller = 0; if (flag == 1) { run = receivebits(buf, 5); is_smaller = run % 3; run -= is_smaller; is_smaller--; } if (run > 0) { thiscoord += 3; for (k = 0; k < run; k+=3) { receiveints(buf, 3, smallidx, sizesmall, thiscoord); i++; thiscoord[0] += prevcoord[0] - smallnum; thiscoord[1] += prevcoord[1] - smallnum; thiscoord[2] += prevcoord[2] - smallnum; if (k == 0) { /* interchange first with second atom for better * compression of water molecules */ tmp = thiscoord[0]; thiscoord[0] = prevcoord[0]; prevcoord[0] = tmp; tmp = thiscoord[1]; thiscoord[1] = prevcoord[1]; prevcoord[1] = tmp; tmp = thiscoord[2]; thiscoord[2] = prevcoord[2]; prevcoord[2] = tmp; *lfp++ = prevcoord[0] * inv_precision; *lfp++ = prevcoord[1] * inv_precision; *lfp++ = prevcoord[2] * inv_precision; } else { prevcoord[0] = thiscoord[0]; prevcoord[1] = thiscoord[1]; prevcoord[2] = thiscoord[2]; } *lfp++ = thiscoord[0] * inv_precision; *lfp++ = thiscoord[1] * inv_precision; *lfp++ = thiscoord[2] * inv_precision; } } else { *lfp++ = thiscoord[0] * inv_precision; *lfp++ = thiscoord[1] * inv_precision; *lfp++ = thiscoord[2] * inv_precision; } smallidx += is_smaller; if (is_smaller < 0) { smallnum = smaller; if (smallidx > FIRSTIDX) { smaller = magicints[smallidx - 1] /2; } else { smaller = 0; } } else if (is_smaller > 0) { smaller = smallnum; smallnum = magicints[smallidx] / 2; } sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx] ; } return 1; } cMolKit-1.5.7~rc1+cvs.20140424/src/simple.h0000644000175000017500000000741110513015402017463 0ustar moellermoeller/* * $Id: simple.h,v 1.1.1.1 2006/10/10 22:13:22 annao Exp $ * * This source code is part of * * G R O M A C S * * GROningen MAchine for Chemical Simulations * * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * If you want to redistribute modifications, please consider that * scientific software is very special. Version control is crucial - * bugs must be traceable. We will be happy to consider code for * inclusion in the official distribution, but derived work must not * be called official GROMACS. Details are found in the README & COPYING * files - if they are missing, get the official version at www.gromacs.org. * * To help us fund GROMACS development, we humbly ask that you cite * the papers on the package - you can find them in the top README file. * * For more info, check our website at http://www.gromacs.org * * And Hey: * GRoups of Organic Molecules in ACtion for Science */ #ifndef _simple_h #define _simple_h #ifdef HAVE_CONFIG_H #include #endif #ifdef CPLUSPLUS extern "C" { #endif #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif #define BOOL_NR 2 #define XX 0 /* Defines for indexing in */ #define YY 1 /* vectors */ #define ZZ 2 #define DIM 3 /* Dimension of vectors */ #define XXXX 0 /* defines to index matrices */ #define XXYY 1 #define XXZZ 2 #define YYXX 3 #define YYYY 4 #define YYZZ 5 #define ZZXX 6 #define ZZYY 7 #define ZZZZ 8 /* Max number of nodes */ #define MAXNODES 256 #ifndef HAVE_BOOL #define bool int /* typedef int bool; */ #endif typedef int atom_id; /* To indicate an atoms id */ #define NO_ATID (atom_id)(~0) /* Use this to indicate invalid atid */ /*! \brief Double precision accuracy */ #define GMX_DOUBLE_EPS 1.11022302E-16 /*! \brief Maximum double precision value */ #define GMX_DOUBLE_MAX 1.79769313E+308 /*! \brief Minimum double precision value */ #define GMX_DOUBLE_MIN 2.22507386E-308 /*! \brief Single precision accuracy */ #define GMX_FLOAT_EPS 5.96046448E-08 /*! \brief Maximum single precision value */ #define GMX_FLOAT_MAX 3.40282347E+38 /*! \brief Minimum single precision value */ #define GMX_FLOAT_MIN 1.17549435E-38 /* Check whether we already have a real type! */ #ifdef GMX_DOUBLE #ifndef HAVE_REAL typedef double real; #define HAVE_REAL #endif #define GMX_MPI_REAL MPI_DOUBLE #define GMX_REAL_EPS GMX_DOUBLE_EPS #define GMX_REAL_MIN GMX_DOUBLE_MIN #define GMX_REAL_MAX GMX_DOUBLE_MAX #else #ifndef HAVE_REAL typedef float real; #define HAVE_REAL #endif #define GMX_MPI_REAL MPI_FLOAT #define GMX_REAL_EPS GMX_FLOAT_EPS #define GMX_REAL_MIN GMX_FLOAT_MIN #define GMX_REAL_MAX GMX_FLOAT_MAX #endif #ifndef VECTORIZATION_BUFLENGTH #define VECTORIZATION_BUFLENGTH 1000 /* The total memory size of the vectorization buffers will * be 5*sizeof(real)*VECTORIZATION_BUFLENGTH */ #endif typedef real rvec[DIM]; typedef double dvec[DIM]; typedef real matrix[DIM][DIM]; typedef real tensor[DIM][DIM]; typedef int ivec[DIM]; typedef int imatrix[DIM][DIM]; #ifdef CPLUSPLUS } #endif #endif cMolKit-1.5.7~rc1+cvs.20140424/src/xdrf.h0000644000175000017500000000400710513015402017133 0ustar moellermoeller/* * $Id: xdrf.h,v 1.1.1.1 2006/10/10 22:13:22 annao Exp $ * * This source code is part of * * G R O M A C S * * GROningen MAchine for Chemical Simulations * * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * If you want to redistribute modifications, please consider that * scientific software is very special. Version control is crucial - * bugs must be traceable. We will be happy to consider code for * inclusion in the official distribution, but derived work must not * be called official GROMACS. Details are found in the README & COPYING * files - if they are missing, get the official version at www.gromacs.org. * * To help us fund GROMACS development, we humbly ask that you cite * the papers on the package - you can find them in the top README file. * * For more info, check our website at http://www.gromacs.org * * And Hey: * Gromacs Runs On Most of All Computer Systems */ /* This file is modified by Anna Omelchenko, MGL, TSRI */ #ifndef _xdrf_h #define _xdrf_h #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined __CYGWIN__ || defined __CYGWIN32__ || defined GMX_INTERNAL_XDR) #include "gmx_system_xdr.h" #else #include #include #endif #include "simple.h" /* Read or write reduced precision *float* coordinates */ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision); /* Read or write a *real* value (stored as float) */ int xdr_real(XDR *xdrs,real *r); #endif cMolKit-1.5.7~rc1+cvs.20140424/src/xtcio.c0000644000175000017500000001160210513015402017310 0ustar moellermoeller/* * * This source code is part of * * G R O M A C S * * GROningen MAchine for Chemical Simulations * * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * If you want to redistribute modifications, please consider that * scientific software is very special. Version control is crucial - * bugs must be traceable. We will be happy to consider code for * inclusion in the official distribution, but derived work must not * be called official GROMACS. Details are found in the README & COPYING * files - if they are missing, get the official version at www.gromacs.org. * * To help us fund GROMACS development, we humbly ask that you cite * the papers on the package - you can find them in the top README file. * * For more info, check our website at http://www.gromacs.org * * And Hey: * GROningen Mixture of Alchemy and Childrens' Stories */ /* This file is modified by Anna Omelchenko, MGL, TSRI */ #include "xtcio.h" void *save_calloc(char *name,char *file,int line, unsigned nelem,unsigned elsize) { void *p; p=NULL; if ((nelem==0)||(elsize==0)) p=NULL; else { if ((p=calloc((size_t)nelem,(size_t)elsize))==NULL) fprintf(stderr, "calloc for %s (nelem=%d, elsize=%d, file %s" ", line %d)",name,nelem,elsize,file,line); } return p; } void save_free(char *name,char *file,int line, void *ptr) { if (ptr != NULL) free(ptr); } int check_xtc_magic(int magic) { if (magic != XTC_MAGIC) { fprintf(stderr,"Magic Number Error in XTC file (read %d, should be %d)", magic,XTC_MAGIC); return 0; } else return 1; } int xtc_check(char *str,bool bResult,char *file,int line) { if (!bResult) { fprintf(stderr,"\nXTC error: read/write of %s failed, " "source file %s, line %d\n",str,file,line); return 0; } return 1; } #define XTC_CHECK(s,b) xtc_check(s,b,__FILE__,__LINE__) int xtc_header(XDR *xd,int *magic,int *natoms,int *step,real *time, bool *bOK) { int result; if (xdr_int(xd,magic) == 0) return 0; result=XTC_CHECK("natoms", xdr_int(xd,natoms)); /* number of atoms */ if (result) result=XTC_CHECK("step", xdr_int(xd,step)); /* frame number */ if (result) result=XTC_CHECK("time", xdr_real(xd,time)); /* time */ *bOK=(result!=0); return result; } int xtc_coord(XDR *xd,int *natoms,matrix box,rvec *x,real *prec, bool bRead) { int i,j,result; #ifdef GMX_DOUBLE float *ftmp; float fprec; #endif /* box */ result=1; for(i=0; ((inatoms) { fprintf(stderr, "Frame contains more atoms (%d) than expected (%d)", n, natoms); return 0; } /* Check magic number */ check_xtc_magic(magic); *bOK=xtc_coord(xd,&natoms,box,x,prec,TRUE); return *bOK; } cMolKit-1.5.7~rc1+cvs.20140424/src/xtcio.h0000644000175000017500000000520110513015402017313 0ustar moellermoeller/* * $Id: xtcio.h,v 1.1.1.1 2006/10/10 22:13:22 annao Exp $ * * This source code is part of * * G R O M A C S * * GROningen MAchine for Chemical Simulations * * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * If you want to redistribute modifications, please consider that * scientific software is very special. Version control is crucial - * bugs must be traceable. We will be happy to consider code for * inclusion in the official distribution, but derived work must not * be called official GROMACS. Details are found in the README & COPYING * files - if they are missing, get the official version at www.gromacs.org. * * To help us fund GROMACS development, we humbly ask that you cite * the papers on the package - you can find them in the top README file. * * For more info, check our website at http://www.gromacs.org * * And Hey: * Gromacs Runs On Most of All Computer Systems */ /* This file is modified by Anna Omelchenko, MGL, TSRI */ #ifndef _xtcio_h #define _xtcio_h #include #include #ifdef CPLUSPLUS extern "C" { #endif #ifndef XTC_MAGIC #define XTC_MAGIC 1995 #endif #ifdef CPLUSPLUS extern "C" { #endif #include "xdrf.h" void *save_calloc(char *name,char *file,int line, unsigned nelem,unsigned elsize); void save_free(char *name,char *file,int line, void *ptr); #define snew(ptr,nelem) (ptr)=save_calloc(#ptr,__FILE__,__LINE__,\ (nelem),sizeof(*(ptr))) #define sfree(ptr) save_free(#ptr,__FILE__,__LINE__,(ptr)) int xtc_header(XDR *xd,int *magic,int *natoms,int *step,real *time, bool *bOK); extern int check_xtc_magic(int magic); extern int xtc_coord(XDR *xd,int *natoms,matrix box,rvec *x,real *prec, bool bRead); extern int xtc_check(char *str,bool bResult,char *file,int line); /* read xtc file first time, allocate memory for x */ extern int read_first_xtc(XDR *xd,int *natoms,int *step,real *time, matrix box,rvec **x,real *prec,bool *bOK); /* Read subsequent frames */ extern int read_next_xtc(XDR *xd, int natoms,int *step,real *time, matrix box,rvec *x,real *prec,bool *bOK); #ifdef CPLUSPLUS } #endif #endif