diff --git a/hoomd/CMakeLists.txt b/hoomd/CMakeLists.txt index d60e48ffbf..03fac4ce00 100644 --- a/hoomd/CMakeLists.txt +++ b/hoomd/CMakeLists.txt @@ -97,18 +97,14 @@ set(_hoomd_sources Action.cc Variant.cc extern/BVLSSolver.cc extern/gsd.c - extern/imd.cc extern/kiss_fft.cc extern/kiss_fftnd.cc - extern/vmdsock.cc filter/export_filters.cc ) # ignore conversion warnings in external files if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set_source_files_properties(extern/kiss_fft.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion -Wno-float-conversion") - set_source_files_properties(extern/vmdsock.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion") - set_source_files_properties(extern/imd.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion") endif() set(_hoomd_headers diff --git a/hoomd/extern/imd.cc b/hoomd/extern/imd.cc deleted file mode 100644 index ca61d58e30..0000000000 --- a/hoomd/extern/imd.cc +++ /dev/null @@ -1,257 +0,0 @@ -/*************************************************************************** - *cr - *cr (C) Copyright 1995-2009 The Board of Trustees of the - *cr University of Illinois - *cr All Rights Reserved - *cr - ***************************************************************************/ - -/*************************************************************************** - * RCS INFORMATION: - * - * $RCSfile: imd.C,v $ - * $Author: johns $ $Locker: $ $State: Exp $ - * $Revision: 1.16 $ $Date: 2009/12/07 17:41:17 $ * - *************************************************************************** - * DESCRIPTION: - * Lowest level interactive MD communication routines. - * - * LICENSE: - * UIUC Open Source License - * http://www.ks.uiuc.edu/Research/vmd/plugins/pluginlicense.html - * - ***************************************************************************/ -#include "imd.h" -#include "vmdsock.h" -#include -#include -#include - -/// IMD communication protocol message header structure -typedef struct { - int32 type; - int32 length; -} IMDheader; - -#define HEADERSIZE 8 -#define IMDVERSION 2 - -/* Only works with aligned 4-byte quantities, will cause a bus error */ -/* on some platforms if used on unaligned data. */ -void swap4_aligned(void *v, long ndata) { - int *data = (int *) v; - long i; - int *N; - for (i=0; i>24)&0xff) | ((*N&0xff)<<24) | - ((*N>>8)&0xff00) | ((*N&0xff00)<<8)); - } -} - -static int32 imd_htonl(int32 h) { - int32 n; - ((char *)&n)[0] = (h >> 24) & 0x0FF; - ((char *)&n)[1] = (h >> 16) & 0x0FF; - ((char *)&n)[2] = (h >> 8) & 0x0FF; - ((char *)&n)[3] = h & 0x0FF; - return n; -} - -/// structure used to perform byte swapping operations -typedef struct { - unsigned int highest : 8; - unsigned int high : 8; - unsigned int low : 8; - unsigned int lowest : 8; -} netint; - -static int32 imd_ntohl(int32 n) { - int32 h = 0; - netint net; - - memcpy((void *)&net,(void *)&n, sizeof(n)); - h |= net.highest << 24 | net.high << 16 | net.low << 8 | net.lowest; - return h; -} - -static void fill_header(IMDheader *header, IMDType type, int32 length) { - header->type = imd_htonl((int32)type); - header->length = imd_htonl(length); -} - -static void swap_header(IMDheader *header) { - header->type = imd_ntohl(header->type); - header->length= imd_ntohl(header->length); -} - -static int32 imd_readn(void *s, char *ptr, int32 n) { - int32 nleft; - int32 nread; - - nleft = n; - while (nleft > 0) { - if ((nread = vmdsock_read(s, ptr, nleft)) < 0) { - if (errno == EINTR) - nread = 0; /* and call read() again */ - else - return -1; - } else if (nread == 0) - break; /* EOF */ - nleft -= nread; - ptr += nread; - } - return n-nleft; -} - -static int32 imd_writen(void *s, const char *ptr, int32 n) { - int32 nleft; - int32 nwritten; - - nleft = n; - while (nleft > 0) { - if ((nwritten = vmdsock_write(s, ptr, nleft)) <= 0) { - if (errno == EINTR) - nwritten = 0; - else - return -1; - } - nleft -= nwritten; - ptr += nwritten; - } - return n; -} - - -int imd_disconnect(void *s) { - IMDheader header; - fill_header(&header, IMD_DISCONNECT, 0); - return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); -} - -int imd_pause(void *s) { - IMDheader header; - fill_header(&header, IMD_PAUSE, 0); - return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); -} - -int imd_kill(void *s) { - IMDheader header; - fill_header(&header, IMD_KILL, 0); - return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); -} - -static int imd_go(void *s) { - IMDheader header; - fill_header(&header, IMD_GO, 0); - return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); -} - - -int imd_handshake(void *s) { - IMDheader header; - fill_header(&header, IMD_HANDSHAKE, 1); - header.length = IMDVERSION; /* Not byteswapped! */ - return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); -} - -int imd_trate(void *s, int32 rate) { - IMDheader header; - fill_header(&header, IMD_TRATE, rate); - return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); -} - -/* Data methods */ -int imd_send_mdcomm(void *s,int32 n,const int32 *indices,const float *forces) { - int rc; - int32 size = HEADERSIZE+16*n; - char *buf = (char *) malloc(sizeof(char) * size); - fill_header((IMDheader *)buf, IMD_MDCOMM, n); - memcpy(buf+HEADERSIZE, indices, 4*n); - memcpy(buf+HEADERSIZE+4*n, forces, 12*n); - rc = (imd_writen(s, buf, size) != size); - free(buf); - return rc; -} - -int imd_send_energies(void *s, const IMDEnergies *energies) { - int rc; - int32 size = HEADERSIZE+sizeof(IMDEnergies); - char *buf = (char *) malloc(sizeof(char) * size); - fill_header((IMDheader *)buf, IMD_ENERGIES, 1); - memcpy(buf+HEADERSIZE, energies, sizeof(IMDEnergies)); - rc = (imd_writen(s, buf, size) != size); - free(buf); - return rc; -} - -int imd_send_fcoords(void *s, int32 n, const float *coords) { - int rc; - int32 size = HEADERSIZE+12*n; - char *buf = (char *) malloc(sizeof(char) * size); - fill_header((IMDheader *)buf, IMD_FCOORDS, n); - memcpy(buf+HEADERSIZE, coords, 12*n); - rc = (imd_writen(s, buf, size) != size); - free(buf); - return rc; -} - -/* The IMD receive functions */ -IMDType imd_recv_header_nolengthswap(void *s, int32 *length) { - IMDheader header; - if (imd_readn(s, (char *)&header, HEADERSIZE) != HEADERSIZE) - return IMD_IOERROR; - *length = header.length; - swap_header(&header); - return (IMDType) header.type; -} - -IMDType imd_recv_header(void *s, int32 *length) { - IMDheader header; - if (imd_readn(s, (char *)&header, HEADERSIZE) != HEADERSIZE) - return IMD_IOERROR; - swap_header(&header); - *length = header.length; - return (IMDType) header.type; -} - -int imd_recv_handshake(void *s) { - int32 buf; - IMDType type; - - /* Wait up to 5 seconds for the handshake to come */ - if (vmdsock_selread(s, 5) != 1) return -1; - - /* Check to see that a valid handshake was received */ - type = imd_recv_header_nolengthswap(s, &buf); - if (type != IMD_HANDSHAKE) return -1; - - /* Check its endianness, as well as the IMD version. */ - if (buf == IMDVERSION) { - if (!imd_go(s)) return 0; - return -1; - } - - swap4_aligned(&buf, 1); - if (buf == IMDVERSION) { - if (!imd_go(s)) return 1; - } - - /* We failed to determine endianness. */ - return -1; -} - -int imd_recv_mdcomm(void *s, int32 n, int32 *indices, float *forces) { - if (imd_readn(s, (char *)indices, 4*n) != 4*n) return 1; - if (imd_readn(s, (char *)forces, 12*n) != 12*n) return 1; - return 0; -} - -int imd_recv_energies(void *s, IMDEnergies *energies) { - return (imd_readn(s, (char *)energies, sizeof(IMDEnergies)) - != sizeof(IMDEnergies)); -} - -int imd_recv_fcoords(void *s, int32 n, float *coords) { - return (imd_readn(s, (char *)coords, 12*n) != 12*n); -} diff --git a/hoomd/extern/imd.h b/hoomd/extern/imd.h deleted file mode 100644 index 5b3c05555f..0000000000 --- a/hoomd/extern/imd.h +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************** - *cr - *cr (C) Copyright 1995-2009 The Board of Trustees of the - *cr University of Illinois - *cr All Rights Reserved - *cr - ***************************************************************************/ - -/*************************************************************************** - * RCS INFORMATION: - * - * $RCSfile: imd.h,v $ - * $Author: johns $ $Locker: $ $State: Exp $ - * $Revision: 1.20 $ $Date: 2009/12/07 17:41:17 $ - * - * LICENSE: - * UIUC Open Source License - * http://www.ks.uiuc.edu/Research/vmd/plugins/pluginlicense.html - * - ***************************************************************************/ - -#ifndef IMD_H__ -#define IMD_H__ - -#include - -#if ( INT_MAX == 2147483647 ) -typedef int int32; -#else -typedef short int32; -#endif - - -typedef enum IMDType_t { - IMD_DISCONNECT, /**< close IMD connection, leaving sim running */ - IMD_ENERGIES, /**< energy data block */ - IMD_FCOORDS, /**< atom coordinates */ - IMD_GO, /**< start the simulation */ - IMD_HANDSHAKE, /**< endianism and version check message */ - IMD_KILL, /**< kill the simulation job, shutdown IMD */ - IMD_MDCOMM, /**< MDComm style force data */ - IMD_PAUSE, /**< pause the running simulation */ - IMD_TRATE, /**< set IMD update transmission rate */ - IMD_IOERROR /**< indicate an I/O error */ -} IMDType; /**< IMD command message type enumerations */ - - -typedef struct { - int32 tstep; /**< integer timestep index */ - float T; /**< Temperature in degrees Kelvin */ - float Etot; /**< Total energy, in Kcal/mol */ - float Epot; /**< Potential energy, in Kcal/mol */ - float Evdw; /**< Van der Waals energy, in Kcal/mol */ - float Eelec; /**< Electrostatic energy, in Kcal/mol */ - float Ebond; /**< Bond energy, Kcal/mol */ - float Eangle; /**< Angle energy, Kcal/mol */ - float Edihe; /**< Dihedral energy, Kcal/mol */ - float Eimpr; /**< Improper energy, Kcal/mol */ -} IMDEnergies; /**< IMD simulation energy report structure */ - - -/* Send control messages - these consist of a header with no subsequent data */ -extern int imd_disconnect(void *); /**< leave sim running but close IMD */ -extern int imd_pause(void *); /**< pause simulation */ -extern int imd_kill(void *); /**< kill simulation, shutdown IMD */ -extern int imd_handshake(void *); /**< check endianness, version compat */ -extern int imd_trate(void *, int32); /**< set IMD update transmission rate */ - -/* Send data update messages */ - -/** Send MDComm compatible forces, units are Kcal/mol/angstrom */ -extern int imd_send_mdcomm(void *, int32, const int32 *, const float *); - -/** Send energies */ -extern int imd_send_energies(void *, const IMDEnergies *); - -/** Send atom forces and coordinates, units are Kcal/mol/angstrom */ -extern int imd_send_fcoords(void *, int32, const float *); - -/** - * recv_handshake returns 0 if server and client have the same relative - * endianism; returns 1 if they have opposite endianism, and -1 if there - * was an error in the handshake process. - */ -extern int imd_recv_handshake(void *); - -/** Receive header and data */ -extern IMDType imd_recv_header(void *, int32 *); - -/** Receive MDComm-style forces, units are Kcal/mol/angstrom */ -extern int imd_recv_mdcomm(void *, int32, int32 *, float *); - -/** Receive energies */ -extern int imd_recv_energies(void *, IMDEnergies *); - -/** Receive atom coordinates and forces, units are Kcal/mol/angstrom */ -extern int imd_recv_fcoords(void *, int32, float *); - -#endif diff --git a/hoomd/extern/vmdsock.cc b/hoomd/extern/vmdsock.cc deleted file mode 100644 index b0434bfff6..0000000000 --- a/hoomd/extern/vmdsock.cc +++ /dev/null @@ -1,220 +0,0 @@ -/*************************************************************************** - *cr - *cr (C) Copyright 1995-2009 The Board of Trustees of the - *cr University of Illinois - *cr All Rights Reserved - *cr - ***************************************************************************/ - -/*************************************************************************** - * RCS INFORMATION: - * - * $RCSfile: vmdsock.c,v $ - * $Author: johns $ $Locker: $ $State: Exp $ - * $Revision: 1.22 $ $Date: 2009/12/07 17:36:41 $ - * - *************************************************************************** - * DESCRIPTION: - * Socket interface, abstracts machine dependent APIs/routines. - * - * LICENSE: - * UIUC Open Source License - * http://www.ks.uiuc.edu/Research/vmd/plugins/pluginlicense.html - * - ***************************************************************************/ - -#define VMDSOCKINTERNAL 1 - -#include -#include -#include - -#if defined(_MSC_VER) -#include -typedef int socklen_t; -#else -#include -#include - -#include -#include /* for Linux */ -#include -#include -#endif - -#include - -#include "vmdsock.h" - -int vmdsock_init(void) { -#if defined(_MSC_VER) - int rc = 0; - static int initialized=0; - - if (!initialized) { - WSADATA wsdata; - rc = WSAStartup(MAKEWORD(1,1), &wsdata); - if (rc == 0) - initialized = 1; - } - - return rc; -#else - return 0; -#endif -} - - -void * vmdsock_create(void) { - vmdsocket * s; - - s = (vmdsocket *) malloc(sizeof(vmdsocket)); - if (s != NULL) - memset(s, 0, sizeof(vmdsocket)); - - if ((s->sd = (int)socket(PF_INET, SOCK_STREAM, 0)) == -1) { - printf("Failed to open socket."); - free(s); - return NULL; - } - - return (void *) s; -} - -int vmdsock_connect(void *v, const char *host, int port) { - vmdsocket *s = (vmdsocket *) v; - char address[1030]; - struct hostent *h; - - h=gethostbyname(host); - if (h == NULL) - return -1; - sprintf(address, "%d.%d.%d.%d", - (unsigned char) h->h_addr_list[0][0], - (unsigned char) h->h_addr_list[0][1], - (unsigned char) h->h_addr_list[0][2], - (unsigned char) h->h_addr_list[0][3]); - - memset(&(s->addr), 0, sizeof(s->addr)); - s->addr.sin_family = PF_INET; - s->addr.sin_addr.s_addr = inet_addr(address); - s->addr.sin_port = htons(port); - - return connect(s->sd, (struct sockaddr *) &s->addr, sizeof(s->addr)); -} - -int vmdsock_bind(void * v, int port) { - vmdsocket *s = (vmdsocket *) v; - memset(&(s->addr), 0, sizeof(s->addr)); - s->addr.sin_family = PF_INET; - s->addr.sin_port = htons(port); - - return bind(s->sd, (struct sockaddr *) &s->addr, sizeof(s->addr)); -} - -int vmdsock_listen(void * v) { - vmdsocket *s = (vmdsocket *) v; - return listen(s->sd, 5); -} - -void *vmdsock_accept(void * v) { - int rc; - vmdsocket *new_s = NULL, *s = (vmdsocket *) v; -#if defined(ARCH_AIX5) || defined(ARCH_AIX5_64) || defined(ARCH_AIX6_64) - unsigned int len; -#elif defined(SOCKLEN_T) - SOCKLEN_T len; -#elif defined(ARCH_LINUXALPHA) - socklen_t len; -#else - int len; -#endif - - len = sizeof(s->addr); - rc = (int)accept(s->sd, (struct sockaddr *) &s->addr, (socklen_t *)&len); - if (rc >= 0) { - new_s = (vmdsocket *) malloc(sizeof(vmdsocket)); - if (new_s != NULL) { - *new_s = *s; - new_s->sd = rc; - } - } - return (void *)new_s; -} - -int vmdsock_write(void * v, const void *buf, int len) { - vmdsocket *s = (vmdsocket *) v; -#if defined(_MSC_VER) - return send(s->sd, (const char*) buf, len, 0); // windows lacks the write() call -#else - return write(s->sd, buf, len); -#endif -} - -int vmdsock_read(void * v, void *buf, int len) { - vmdsocket *s = (vmdsocket *) v; -#if defined(_MSC_VER) - return recv(s->sd, (char*) buf, len, 0); // windows lacks the read() call -#else - return read(s->sd, buf, len); -#endif - -} - -void vmdsock_shutdown(void *v) { - vmdsocket * s = (vmdsocket *) v; - if (s == NULL) - return; - -#if defined(_MSC_VER) - shutdown(s->sd, SD_SEND); -#else - shutdown(s->sd, 1); /* complete sends and send FIN */ -#endif -} - -void vmdsock_destroy(void * v) { - vmdsocket * s = (vmdsocket *) v; - if (s == NULL) - return; - -#if defined(_MSC_VER) - closesocket(s->sd); -#else - close(s->sd); -#endif - free(s); -} - -int vmdsock_selread(void *v, int sec) { - vmdsocket *s = (vmdsocket *)v; - fd_set rfd; - struct timeval tv; - int rc; - - FD_ZERO(&rfd); - FD_SET(s->sd, &rfd); - memset((void *)&tv, 0, sizeof(struct timeval)); - tv.tv_sec = sec; - do { - rc = select(s->sd+1, &rfd, NULL, NULL, &tv); - } while (rc < 0 && errno == EINTR); - return rc; - -} - -int vmdsock_selwrite(void *v, int sec) { - vmdsocket *s = (vmdsocket *)v; - fd_set wfd; - struct timeval tv; - int rc; - - FD_ZERO(&wfd); - FD_SET(s->sd, &wfd); - memset((void *)&tv, 0, sizeof(struct timeval)); - tv.tv_sec = sec; - do { - rc = select(s->sd + 1, NULL, &wfd, NULL, &tv); - } while (rc < 0 && errno == EINTR); - return rc; -} diff --git a/hoomd/extern/vmdsock.h b/hoomd/extern/vmdsock.h deleted file mode 100644 index dd7be3cf6f..0000000000 --- a/hoomd/extern/vmdsock.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - *cr - *cr (C) Copyright 1995-2009 The Board of Trustees of the - *cr University of Illinois - *cr All Rights Reserved - *cr - ***************************************************************************/ - -/*************************************************************************** - * RCS INFORMATION: - * - * $RCSfile: vmdsock.h,v $ - * $Author: johns $ $Locker: $ $State: Exp $ - * $Revision: 1.14 $ $Date: 2009/12/07 17:36:41 $ - * - *************************************************************************** - * DESCRIPTION: - * socket interface layer, abstracts platform-dependent routines/APIs - * - * LICENSE: - * UIUC Open Source License - * http://www.ks.uiuc.edu/Research/vmd/plugins/pluginlicense.html - * - ***************************************************************************/ - -#if defined(VMDSOCKINTERNAL) - -#if !defined(_MSC_VER) -#include -#include -#include -#include -#include -#include -#endif - -typedef struct { - struct sockaddr_in addr; /* address of socket provided by bind() */ - int addrlen; /* size of the addr struct */ - int sd; /* socket file descriptor */ -} vmdsocket; - -#endif /* VMDSOCKINTERNAL */ - -#ifdef __cplusplus -extern "C" { -#endif - -int vmdsock_init(void); -void *vmdsock_create(void); -int vmdsock_bind(void *, int); -int vmdsock_listen(void *); -void *vmdsock_accept(void *); /* return new socket */ -int vmdsock_connect(void *, const char *, int); -int vmdsock_write(void *, const void *, int); -int vmdsock_read(void *, void *, int); -int vmdsock_selread(void *, int); -int vmdsock_selwrite(void *, int); -void vmdsock_shutdown(void *); -void vmdsock_destroy(void *); - -#ifdef __cplusplus -} -#endif diff --git a/sphinx-doc/license.rst b/sphinx-doc/license.rst index bacd3d920a..893da76cb6 100644 --- a/sphinx-doc/license.rst +++ b/sphinx-doc/license.rst @@ -50,9 +50,6 @@ Libraries Additionally, HOOMD-blue links to or compiles in code from the following libraries: -**Sockets code** from `VMD `_, used under the -UIUC Open Source License. - **Molfile plugin code** from VMD, used under the UIUC Open Source License:: University of Illinois Open Source License