1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This file is part of Gromacs Copyright (c) 1991-2008
5 * David van der Spoel, Erik Lindahl, Berk Hess, University of Groningen.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * To help us fund GROMACS development, we humbly ask that you cite
13 * the research papers on the package. Check out http://www.gromacs.org
16 * Gnomes, ROck Monsters And Chili Sauce
24 /* Derived from PluginMgr.C and catdcd.c */
26 /* PluginMgr.C: Copyright: */
27 /***************************************************************************
29 *cr (C) Copyright 1995-2009 The Board of Trustees of the
30 *cr University of Illinois
31 *cr All Rights Reserved
33 Developed by: Theoretical and Computational Biophysics Group
34 University of Illinois at Urbana-Champaign
35 http://www.ks.uiuc.edu/
37 Permission is hereby granted, free of charge, to any person obtaining a copy of
38 this software and associated documentation files (the Software), to deal with
39 the Software without restriction, including without limitation the rights to
40 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
41 of the Software, and to permit persons to whom the Software is furnished to
42 do so, subject to the following conditions:
44 Redistributions of source code must retain the above copyright notice,
45 this list of conditions and the following disclaimers.
47 Redistributions in binary form must reproduce the above copyright notice,
48 this list of conditions and the following disclaimers in the documentation
49 and/or other materials provided with the distribution.
51 Neither the names of Theoretical and Computational Biophysics Group,
52 University of Illinois at Urbana-Champaign, nor the names of its contributors
53 may be used to endorse or promote products derived from this Software without
54 specific prior written permission.
56 THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
59 THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
60 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
61 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
62 OTHER DEALINGS WITH THE SOFTWARE.
63 ***************************************************************************/
65 /* catdcd.c: Copyright: */
66 /*****************************************************************************/
68 /* (C) Copyright 2001-2005 Justin Gullingsrud and the University of Illinois.*/
70 /*****************************************************************************/
77 * Plugin header files; get plugin source from www.ks.uiuc.edu/Research/vmd"
79 #include "molfile_plugin.h"
80 #include "vmddlopen.h"
81 #if !((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
92 #include "types/simple.h"
97 typedef int (*initfunc
)(void);
98 typedef int (*regfunc
)(void *, vmdplugin_register_cb
);
99 typedef int (*finifunc
)(void);
103 static int register_cb(void *v
, vmdplugin_t
*p
) {
104 const char *key
= p
->name
;
105 t_gmxvmdplugin
*vmdplugin
= (t_gmxvmdplugin
*)v
;
107 if (strcmp(key
,vmdplugin
->filetype
)==0)
109 vmdplugin
->api
= (molfile_plugin_t
*)p
;
111 return VMDPLUGIN_SUCCESS
;
114 static int load_sharedlibrary_plugins(const char *fullpath
,t_gmxvmdplugin
* vmdplugin
) {
115 /* Open the dll; try to execute the init function. */
116 void *handle
, *ifunc
, *registerfunc
;
117 handle
= vmddlopen(fullpath
);
119 if (debug
) fprintf(debug
, "\nUnable to open dynamic library %s.\n%s\n", fullpath
, vmddlerror()); /*only to debug because of stdc++ erros */
123 ifunc
= vmddlsym(handle
, "vmdplugin_init");
124 if (ifunc
&& ((initfunc
)(ifunc
))()) {
125 printf("\nvmdplugin_init() for %s returned an error; plugin(s) not loaded.\n", fullpath
);
130 registerfunc
= vmddlsym(handle
, "vmdplugin_register");
132 printf("\nDidn't find the register function in %s; plugin(s) not loaded.\n", fullpath
);
136 /* Load plugins from the library.*/
137 ((regfunc
)registerfunc
)(vmdplugin
, register_cb
);
140 /* in case this library does not support the filetype, close it */
141 if (vmdplugin
->api
== NULL
)
149 /*return: 1: success, 0: last frame, -1: error*/
150 gmx_bool
read_next_vmd_frame(int status
,t_trxframe
*fr
)
154 molfile_timestep_t ts
;
157 fr
->bV
= fr
->vmdplugin
.bV
;
160 snew(ts
.coords
, fr
->natoms
*3);
163 snew(ts
.velocities
, fr
->natoms
*3);
166 ts
.coords
= (float*)fr
->x
;
169 ts
.velocities
= (float*)fr
->v
;
173 rc
= fr
->vmdplugin
.api
->read_next_timestep(fr
->vmdplugin
.handle
, fr
->natoms
, &ts
);
176 fprintf(stderr
, "\nError reading input file (error code %d)\n", rc
);
180 fr
->vmdplugin
.api
->close_file_read(fr
->vmdplugin
.handle
);
185 for (i
=0;i
<fr
->natoms
;i
++)
187 fr
->x
[i
][0] = .1*ts
.coords
[i
*3];
188 fr
->x
[i
][1] = .1*ts
.coords
[i
*3+1];
189 fr
->x
[i
][2] = .1*ts
.coords
[i
*3+2];
192 fr
->v
[i
][0] = .1*ts
.velocities
[i
*3];
193 fr
->v
[i
][1] = .1*ts
.velocities
[i
*3+1];
194 fr
->v
[i
][2] = .1*ts
.velocities
[i
*3+2];
200 sfree(ts
.velocities
);
203 for (i
=0;i
<fr
->natoms
;i
++)
205 svmul(.1,fr
->x
[i
],fr
->x
[i
]);
208 svmul(.1,fr
->v
[i
],fr
->v
[i
]);
215 vec
[0] = .1*ts
.A
; vec
[1] = .1*ts
.B
; vec
[2] = .1*ts
.C
;
216 angle
[0] = ts
.alpha
; angle
[1] = ts
.beta
; angle
[2] = ts
.gamma
;
217 matrix_convert(fr
->box
,vec
,angle
);
218 if (fr
->vmdplugin
.api
->abiversion
>10)
221 fr
->time
= ts
.physical_time
;
232 int load_vmd_library(const char *fn
, t_gmxvmdplugin
*vmdplugin
)
234 char pathname
[GMX_PATH_MAX
],filename
[GMX_PATH_MAX
];
239 #if !((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
241 const char *defpathenv
= "/usr/local/lib/vmd/plugins/*/molfile";
244 HANDLE hFind
= INVALID_HANDLE_VALUE
;
245 char progfolder
[GMX_PATH_MAX
];
246 char defpathenv
[GMX_PATH_MAX
];
247 SHGetFolderPath(NULL
,CSIDL_PROGRAM_FILES
,NULL
,SHGFP_TYPE_CURRENT
,progfolder
);
248 sprintf(defpathenv
,"%s\\University of Illinois\\VMD\\plugins\\WIN32\\molfile",progfolder
);
251 vmdplugin
->api
= NULL
;
252 vmdplugin
->filetype
= strrchr(fn
,'.');
253 if (!vmdplugin
->filetype
)
257 vmdplugin
->filetype
++;
259 pathenv
= getenv("VMD_PLUGIN_PATH");
262 printf("\nVMD_PLUGIN_PATH not set. ");
263 printf("Using default location:\n%s\n",defpathenv
);
266 strncpy(pathname
,pathenv
,sizeof(pathname
));
267 #if !((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
268 strcat(pathname
,"/*.so");
269 glob(pathname
, 0, NULL
, &globbuf
);
270 if (globbuf
.gl_pathc
== 0)
272 printf("\nNo VMD Plugins found\n"
273 "Set the environment variable VMD_PLUGIN_PATH to the molfile folder within the\n"
274 "VMD installation.\n"
275 "The architecture (e.g. 32bit versus 64bit) of Gromacs and VMD has to match.\n");
278 for (i
=0; i
<globbuf
.gl_pathc
&& vmdplugin
->api
== NULL
; i
++)
280 ret
|=load_sharedlibrary_plugins(globbuf
.gl_pathv
[i
],vmdplugin
);
284 strcat(pathname
,"\\*.so");
285 hFind
= FindFirstFile(pathname
, &ffd
);
286 if (INVALID_HANDLE_VALUE
== hFind
)
288 printf("\nNo VMD Plugins found\n");
293 sprintf(filename
,"%s\\%s",pathenv
,ffd
.cFileName
);
294 ret
|=load_sharedlibrary_plugins(filename
,vmdplugin
);
296 while (FindNextFile(hFind
, &ffd
) != 0 && vmdplugin
->api
== NULL
);
302 printf("\nCould not open any VMD library.\n");
306 printf("Compiled with dlopen?\n");
310 printf("Last error:\n%s\n",err
);
315 if (vmdplugin
->api
== NULL
)
317 printf("\nNo plugin for %s found\n",vmdplugin
->filetype
);
321 printf("\nUsing VMD plugin: %s (%s)\n",vmdplugin
->api
->name
,vmdplugin
->api
->prettyname
);
327 int read_first_vmd_frame(int *status
,const char *fn
,t_trxframe
*fr
,int flags
)
329 molfile_timestep_metadata_t
*metadata
=NULL
;
331 if (!load_vmd_library(fn
,&(fr
->vmdplugin
)))
336 fr
->vmdplugin
.handle
= fr
->vmdplugin
.api
->open_file_read(fn
, fr
->vmdplugin
.filetype
, &fr
->natoms
);
338 if (!fr
->vmdplugin
.handle
) {
339 fprintf(stderr
, "\nError: could not open file '%s' for reading.\n",
344 if (fr
->natoms
== MOLFILE_NUMATOMS_UNKNOWN
) {
345 fprintf(stderr
, "\nFormat of file %s does not record number of atoms.\n", fn
);
347 } else if (fr
->natoms
== MOLFILE_NUMATOMS_NONE
) {
348 fprintf(stderr
, "\nNo atoms found by VMD plugin in file %s.\n", fn
);
350 } else if (fr
->natoms
< 1) { /*should not be reached*/
351 fprintf(stderr
, "\nUnknown number of atoms %d for VMD plugin opening file %s.\n",
356 snew(fr
->x
,fr
->natoms
);
358 fr
->vmdplugin
.bV
= 0;
359 if (fr
->vmdplugin
.api
->abiversion
> 10 && fr
->vmdplugin
.api
->read_timestep_metadata
)
361 fr
->vmdplugin
.api
->read_timestep_metadata(fr
->vmdplugin
.handle
, metadata
);
362 fr
->vmdplugin
.bV
= metadata
->has_velocities
;
363 if (fr
->vmdplugin
.bV
)
365 snew(fr
->v
,fr
->natoms
);