2 * This file is part of the GROMACS molecular simulation package.
4 * This file is part of Gromacs Copyright (c) 1991-2008
5 * David van der Spoel, Erik Lindahl, Berk Hess, University of Groningen.
6 * Copyright (c) 2012,2013, by the GROMACS development team, led by
7 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
8 * others, as listed in the AUTHORS file in the top-level source
9 * directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
43 /* Derived from PluginMgr.C and catdcd.c */
45 /* PluginMgr.C: Copyright: */
46 /***************************************************************************
48 *cr (C) Copyright 1995-2009 The Board of Trustees of the
49 *cr University of Illinois
50 *cr All Rights Reserved
52 Developed by: Theoretical and Computational Biophysics Group
53 University of Illinois at Urbana-Champaign
54 http://www.ks.uiuc.edu/
56 Permission is hereby granted, free of charge, to any person obtaining a copy of
57 this software and associated documentation files (the Software), to deal with
58 the Software without restriction, including without limitation the rights to
59 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
60 of the Software, and to permit persons to whom the Software is furnished to
61 do so, subject to the following conditions:
63 Redistributions of source code must retain the above copyright notice,
64 this list of conditions and the following disclaimers.
66 Redistributions in binary form must reproduce the above copyright notice,
67 this list of conditions and the following disclaimers in the documentation
68 and/or other materials provided with the distribution.
70 Neither the names of Theoretical and Computational Biophysics Group,
71 University of Illinois at Urbana-Champaign, nor the names of its contributors
72 may be used to endorse or promote products derived from this Software without
73 specific prior written permission.
75 THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
78 THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
79 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
80 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
81 OTHER DEALINGS WITH THE SOFTWARE.
82 ***************************************************************************/
84 /* catdcd.c: Copyright: */
85 /*****************************************************************************/
87 /* (C) Copyright 2001-2005 Justin Gullingsrud and the University of Illinois.*/
89 /*****************************************************************************/
97 * Plugin header files; get plugin source from www.ks.uiuc.edu/Research/vmd"
99 #include "molfile_plugin.h"
100 #include "vmddlopen.h"
101 #ifndef GMX_NATIVE_WINDOWS
112 #include "types/simple.h"
117 typedef int (*initfunc)(void);
118 typedef int (*regfunc)(void *, vmdplugin_register_cb);
119 typedef int (*finifunc)(void);
123 static int register_cb(void *v, vmdplugin_t *p) {
124 const char *key = p->name;
125 t_gmxvmdplugin *vmdplugin = (t_gmxvmdplugin*)v;
127 if (strcmp(key,vmdplugin->filetype)==0)
129 vmdplugin->api = (molfile_plugin_t *)p;
131 return VMDPLUGIN_SUCCESS;
134 static int load_sharedlibrary_plugins(const char *fullpath,t_gmxvmdplugin* vmdplugin) {
135 /* Open the dll; try to execute the init function. */
136 void *handle, *ifunc, *registerfunc;
137 handle = vmddlopen(fullpath);
139 if (debug) fprintf(debug, "\nUnable to open dynamic library %s.\n%s\n", fullpath, vmddlerror()); /*only to debug because of stdc++ erros */
143 ifunc = vmddlsym(handle, "vmdplugin_init");
144 if (!ifunc || ((initfunc)(ifunc))()) {
145 printf("\nvmdplugin_init() for %s returned an error; plugin(s) not loaded.\n", fullpath);
150 registerfunc = vmddlsym(handle, "vmdplugin_register");
152 printf("\nDidn't find the register function in %s; plugin(s) not loaded.\n", fullpath);
156 /* Load plugins from the library.*/
157 ((regfunc)registerfunc)(vmdplugin, register_cb);
160 /* in case this library does not support the filetype, close it */
161 if (vmdplugin->api == NULL)
169 /*return: 1: success, 0: last frame, -1: error*/
170 gmx_bool read_next_vmd_frame(int status,t_trxframe *fr)
174 molfile_timestep_t ts;
177 fr->bV = fr->vmdplugin->bV;
180 snew(ts.coords, fr->natoms*3);
183 snew(ts.velocities, fr->natoms*3);
186 ts.coords = (float*)fr->x;
189 ts.velocities = (float*)fr->v;
193 rc = fr->vmdplugin->api->read_next_timestep(fr->vmdplugin->handle, fr->natoms, &ts);
196 fprintf(stderr, "\nError reading input file (error code %d)\n", rc);
200 fr->vmdplugin->api->close_file_read(fr->vmdplugin->handle);
205 for (i=0;i<fr->natoms;i++)
207 fr->x[i][0] = .1*ts.coords[i*3];
208 fr->x[i][1] = .1*ts.coords[i*3+1];
209 fr->x[i][2] = .1*ts.coords[i*3+2];
212 fr->v[i][0] = .1*ts.velocities[i*3];
213 fr->v[i][1] = .1*ts.velocities[i*3+1];
214 fr->v[i][2] = .1*ts.velocities[i*3+2];
220 sfree(ts.velocities);
223 for (i=0;i<fr->natoms;i++)
225 svmul(.1,fr->x[i],fr->x[i]);
228 svmul(.1,fr->v[i],fr->v[i]);
235 vec[0] = .1*ts.A; vec[1] = .1*ts.B; vec[2] = .1*ts.C;
236 angle[0] = ts.alpha; angle[1] = ts.beta; angle[2] = ts.gamma;
237 matrix_convert(fr->box,vec,angle);
238 if (fr->vmdplugin->api->abiversion>10)
241 fr->time = ts.physical_time;
252 static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin)
254 char pathname[GMX_PATH_MAX],filename[GMX_PATH_MAX];
259 char pathenv_buffer[GMX_PATH_MAX];
260 #ifndef GMX_NATIVE_WINDOWS
262 const char *defpath_suffix = "/plugins/*/molfile";
263 const char *defpathenv = GMX_VMD_PLUGIN_PATH;
266 HANDLE hFind = INVALID_HANDLE_VALUE;
267 char progfolder[GMX_PATH_MAX];
268 char defpathenv[GMX_PATH_MAX];
269 const char *defpath_suffix = "\\plugins\\WIN32\\molfile";
270 SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES,NULL,SHGFP_TYPE_CURRENT,progfolder);
271 sprintf(defpathenv,"%s\\University of Illinois\\VMD\\plugins\\WIN32\\molfile",progfolder);
274 vmdplugin->api = NULL;
275 vmdplugin->filetype = strrchr(fn,'.');
276 if (!vmdplugin->filetype)
280 vmdplugin->filetype++;
282 /* First look for an explicit path given at run time for the
283 * plugins, then an implicit run-time path, and finally for one
284 * given at configure time. This last might be hard-coded to the
285 * default for VMD installs. */
286 pathenv = getenv("VMD_PLUGIN_PATH");
289 pathenv = getenv("VMDDIR");
292 printf("\nNeither VMD_PLUGIN_PATH or VMDDIR set. ");
293 printf("Using default location:\n%s\n",defpathenv);
298 printf("\nVMD_PLUGIN_PATH no set, but VMDDIR is set. ");
300 _snprintf_s(pathenv_buffer, sizeof(pathenv_buffer), _TRUNCATE, "%s%s", pathenv, defpath_suffix);
302 snprintf(pathenv_buffer, sizeof(pathenv_buffer), "%s%s", pathenv, defpath_suffix);
304 printf("Using semi-default location:\n%s\n",pathenv_buffer);
305 pathenv = pathenv_buffer;
308 strncpy(pathname,pathenv,sizeof(pathname));
309 #ifndef GMX_NATIVE_WINDOWS
310 strcat(pathname,"/*.so");
311 glob(pathname, 0, NULL, &globbuf);
312 if (globbuf.gl_pathc == 0)
314 printf("\nNo VMD Plugins found\n"
315 "Set the environment variable VMD_PLUGIN_PATH to the molfile folder within the\n"
316 "VMD installation.\n"
317 "The architecture (e.g. 32bit versus 64bit) of Gromacs and VMD has to match.\n");
320 for (i=0; i<globbuf.gl_pathc && vmdplugin->api == NULL; i++)
322 /* FIXME: Undefined which plugin is chosen if more than one plugin
323 can read a certain file ending. Requires some additional command
324 line option or enviroment variable to specify which plugin should
327 ret|=load_sharedlibrary_plugins(globbuf.gl_pathv[i],vmdplugin);
331 strcat(pathname,"\\*.so");
332 hFind = FindFirstFile(pathname, &ffd);
333 if (INVALID_HANDLE_VALUE == hFind)
335 printf("\nNo VMD Plugins found\n");
340 sprintf(filename,"%s\\%s",pathenv,ffd.cFileName);
341 ret|=load_sharedlibrary_plugins(filename,vmdplugin);
343 while (FindNextFile(hFind, &ffd ) != 0 && vmdplugin->api == NULL );
349 printf("\nCould not open any VMD library.\n");
353 printf("Compiled with dlopen?\n");
357 printf("Last error:\n%s\n",err);
362 if (vmdplugin->api == NULL)
364 printf("\nNo plugin for %s found\n",vmdplugin->filetype);
368 if (vmdplugin->api->abiversion < 10)
370 printf("\nPlugin and/or VMD is too old. At least VMD 1.8.6 is required.\n");
374 printf("\nUsing VMD plugin: %s (%s)\n",vmdplugin->api->name,vmdplugin->api->prettyname);
380 int read_first_vmd_frame(int *status,const char *fn,t_trxframe *fr,int flags)
382 molfile_timestep_metadata_t *metadata=NULL;
384 snew(fr->vmdplugin,1);
385 if (!load_vmd_library(fn,fr->vmdplugin))
390 fr->vmdplugin->handle = fr->vmdplugin->api->open_file_read(fn, fr->vmdplugin->filetype, &fr->natoms);
392 if (!fr->vmdplugin->handle) {
393 fprintf(stderr, "\nError: could not open file '%s' for reading.\n",
398 if (fr->natoms == MOLFILE_NUMATOMS_UNKNOWN) {
399 fprintf(stderr, "\nFormat of file %s does not record number of atoms.\n", fn);
401 } else if (fr->natoms == MOLFILE_NUMATOMS_NONE) {
402 fprintf(stderr, "\nNo atoms found by VMD plugin in file %s.\n", fn );
404 } else if (fr->natoms < 1) { /*should not be reached*/
405 fprintf(stderr, "\nUnknown number of atoms %d for VMD plugin opening file %s.\n",
410 snew(fr->x,fr->natoms);
412 fr->vmdplugin->bV = 0;
413 if (fr->vmdplugin->api->abiversion > 10 && fr->vmdplugin->api->read_timestep_metadata)
415 fr->vmdplugin->api->read_timestep_metadata(fr->vmdplugin->handle, metadata);
417 fr->vmdplugin->bV = metadata->has_velocities;
418 if (fr->vmdplugin->bV)
420 snew(fr->v,fr->natoms);
426 "\nThis trajectory is being read with a VMD plug-in from before VMD"
427 "\nversion 1.8, or from a trajectory that lacks time step metadata."
428 "\nEither way, GROMACS cannot tell whether the trajectory has velocities.\n");