Changeset 2680
- Timestamp:
- Nov 15, 2011, 11:56:36 AM (13 years ago)
- Location:
- branches/blt4/packages/vizservers/pymolproxy
- Files:
-
- 1 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/packages/vizservers/pymolproxy/Makefile.in
r2542 r2680 1 1 2 TARGETS = pymolproxy2 TARGETS = pymolproxy pymolproxy2 3 3 4 CC =@CC@5 CC_SWITCHES =$(CFLAGS) $(EXTRA_CFLAGS) $(DEFINES) $(INCLUDES)6 CFLAGS =@CFLAGS@7 DEFINES =-DSTANDALONE8 EXTRA_CFLAGS =-Wall9 INCLUDES =$(TCL_INC_SPEC)10 TCL_INC_SPEC =@TCL_INC_SPEC@11 TCL_LIB_SPEC =@TCL_LIB_SPEC@12 RP_LIB_DIR =@RP_LIB_DIR@4 CC = @CC@ 5 CC_SWITCHES = $(CFLAGS) $(EXTRA_CFLAGS) $(DEFINES) $(INCLUDES) 6 CFLAGS = @CFLAGS@ 7 DEFINES = -DSTANDALONE 8 EXTRA_CFLAGS = -Wall 9 INCLUDES = $(TCL_INC_SPEC) 10 TCL_INC_SPEC = @TCL_INC_SPEC@ 11 TCL_LIB_SPEC = @TCL_LIB_SPEC@ 12 RP_LIB_DIR = @RP_LIB_DIR@ 13 13 14 bindir =@bindir@15 datadir =@datadir@16 datarootdir =@datarootdir@17 exec_prefix =@exec_prefix@18 includedir =@includedir@19 libdir =@libdir@20 mandir =@mandir@21 prefix =@prefix@22 srcdir =@srcdir@14 bindir = @bindir@ 15 datadir = @datadir@ 16 datarootdir = @datarootdir@ 17 exec_prefix = @exec_prefix@ 18 includedir = @includedir@ 19 libdir = @libdir@ 20 mandir = @mandir@ 21 prefix = @prefix@ 22 srcdir = @srcdir@ 23 23 24 RP_DIR =@RP_DIR@25 INSTALL =@INSTALL@26 MKDIR_P =@MKDIR_P@27 VPATH =$(srcdir)24 RP_DIR = @RP_DIR@ 25 INSTALL = @INSTALL@ 26 MKDIR_P = @MKDIR_P@ 27 VPATH = $(srcdir) 28 28 29 29 .PHONY: all install clean distclean 30 30 31 OBJS = pymolproxy.o 32 LIBS = $(TCL_LIB_SPEC) \ 33 -Wl,-rpath,$(RP_LIB_DIR) 31 FILES = pymolproxy pymolproxy2 32 PROXY_OBJS = pymolproxy.o 33 PROXY2_OBJS = pymolproxy2.o 34 LIBS = $(TCL_LIB_SPEC) \ 35 -Wl,-rpath,$(RP_LIB_DIR) 34 36 35 37 SCRIPTS = $(srcdir)/scripts/box.py … … 37 39 all: $(TARGETS) 38 40 39 pymolproxy: $( OBJS)41 pymolproxy: $(PROXY_OBJS) 40 42 $(CC) $(CC_SWITCHES) -o $@ $^ $(LIBS) 43 44 pymolproxy2: $(PROXY2_OBJS) 45 $(CC) $(CC_SWITCHES) -o $@ $^ $(LIBS) -lpthread 41 46 42 47 .c.o: … … 45 50 install: install-pymolproxy install-scripts 46 51 47 install-pymolproxy: pymolproxy 52 install-pymolproxy: pymolproxy pymolproxy2 48 53 $(MKDIR_P) -m 0755 $(bindir) 49 $(INSTALL) -m 0555 pymolproxy $(bindir)/pymolproxy 50 $(INSTALL) -m 0555 $(srcdir)/pymol $(bindir)/pymol 54 for i in $(FILES) ; do \ 55 $(INSTALL) -m 0555 $$i $(bindir) ; \ 56 done 51 57 52 58 install-scripts: … … 60 66 61 67 distclean: clean 62 $(RM) Makefile 68 $(RM) Makefile pymol -
branches/blt4/packages/vizservers/pymolproxy/pymolproxy.c
r2542 r2680 10 10 * server. Responses from the pymol server are translated into Tcl 11 11 * commands and send to the molvisviewer widget. For example, resulting 12 * image rendered offscreen is returned as BMP-formatted image data.12 * image rendered offscreen is returned as ppm-formatted image data. 13 13 * 14 14 * Copyright (c) 2004-2006 Purdue Research Foundation … … 96 96 static Stats stats; 97 97 98 #define READTRACE 098 #define READTRACE 1 99 99 #define EXPECTTRACE 0 100 100 #define WRITETRACE 0 … … 446 446 proxyPtr->error = 0; 447 447 proxyPtr->status = TCL_OK; 448 }449 450 static int451 CreateTmpDir(Tcl_Interp *interp)452 {453 const char script[] = {454 "set path \"/tmp/pymol[pid]\"\n"455 "if { [file exists $path] } {\n"456 " file delete -force $path\n"457 "}\n"458 "file mkdir $path\n"459 };460 return Tcl_GlobalEval(interp, script);461 }462 463 static void464 DestroyTmpDir()465 {466 char cmd[BUFSIZ];467 468 sprintf(cmd, "/bin/rm -rf /tmp/pymol%d", getpid());469 if (system(cmd) < 0) {470 ERROR("can't delete tmp directory: %s\n", strerror(errno));471 }472 448 } 473 449 … … 872 848 } 873 849 874 875 static int876 BmpCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])877 {878 char buffer[BUFSIZ];879 unsigned int nBytes=0;880 PymolProxy *proxyPtr = clientData;881 Image *imgPtr;882 size_t length;883 clear_error(proxyPtr);884 885 if (proxyPtr->flags & INVALIDATE_CACHE)886 proxyPtr->cacheId++;887 888 proxyPtr->flags &= ~(UPDATE_PENDING|FORCE_UPDATE|INVALIDATE_CACHE);889 890 /* Force pymol to update the current scene. */891 UpdateSettings(proxyPtr);892 893 Pymol(proxyPtr, "refresh\n");894 Pymol(proxyPtr, "bmp -\n");895 if (Expect(proxyPtr, "bmp image follows: ", buffer, BUFSIZ) != TCL_OK) {896 return TCL_ERROR;897 }898 if (sscanf(buffer, "bmp image follows: %d\n", &nBytes) != 1) {899 Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"",900 (char *)NULL);901 return TCL_ERROR;902 }903 sprintf(buffer, "nv>image %d %d %d %d\n", nBytes, proxyPtr->cacheId,904 proxyPtr->frame, proxyPtr->rockOffset);905 906 length = strlen(buffer);907 imgPtr = NewImage(proxyPtr, nBytes + length);908 strcpy(imgPtr->data, buffer);909 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, nBytes)910 != BUFFER_OK) {911 ERROR("can't read %d bytes for \"image follows\" buffer: %s", nBytes,912 strerror(errno));913 return TCL_ERROR;914 }915 stats.nFrames++;916 stats.nBytes += nBytes;917 return proxyPtr->status;918 }919 920 850 static int 921 851 CartoonCmd(ClientData clientData, Tcl_Interp *interp, int argc, … … 1245 1175 } 1246 1176 { 1177 int f; 1178 ssize_t nWritten; 1247 1179 char fileName[200]; 1248 FILE *f; 1249 ssize_t nWritten; 1250 static unsigned long count = 0; 1251 1180 1181 strcpy(fileName, "/tmp/pdb.XXXXXX"); 1252 1182 proxyPtr->status = TCL_ERROR; 1253 sprintf(fileName, "/tmp/pymol%d/%ld.pdb", getpid(), count); 1254 count++; 1255 f = fopen(fileName, "w"); 1256 if (f == NULL) { 1257 Tcl_AppendResult(interp, "can't create temporary file \"", 1258 fileName, "\": ", Tcl_PosixError(interp), 1259 (char *)NULL); 1183 f = mkstemp(fileName); 1184 if (f < 0) { 1185 Tcl_AppendResult(interp, "can't create temporary file \"", 1186 fileName, "\":", Tcl_PosixError(interp), (char *)NULL); 1260 1187 goto error; 1261 1188 } 1262 nWritten = fwrite(data, sizeof(char), nBytes, f);1189 nWritten = write(f, data, nBytes); 1263 1190 if (nBytes != nWritten) { 1264 1191 Tcl_AppendResult(interp, "can't write PDB data to \"", 1265 1192 fileName, "\": ", Tcl_PosixError(interp), 1266 1193 (char *)NULL); 1267 fclose(f);1194 close(f); 1268 1195 goto error; 1269 1196 } 1270 fclose(f);1271 Pymol(proxyPtr, "load %s,%s,%d\n", fileName, name, state);1197 close(f); 1198 Pymol(proxyPtr, "loadandremovepdbfile %s,%s,%d\n", fileName, name, state); 1272 1199 proxyPtr->status = TCL_OK; 1273 1200 } … … 1400 1327 return TCL_ERROR; 1401 1328 } 1329 stats.nFrames++; 1330 stats.nBytes += nBytes; 1331 return proxyPtr->status; 1332 } 1333 1334 1335 static int 1336 PpmCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) 1337 { 1338 char buffer[BUFSIZ]; 1339 int nBytes=0; 1340 PymolProxy *proxyPtr = clientData; 1341 size_t length; 1342 Image *imgPtr; 1343 1344 clear_error(proxyPtr); 1345 1346 /* Force pymol to update the current scene. */ 1347 Pymol(proxyPtr, "refresh\n"); 1348 Pymol(proxyPtr, "png -,format=1\n"); 1349 1350 if (Expect(proxyPtr, "ppm image follows: ", buffer, BUFSIZ-1) != TCL_OK) { 1351 return TCL_ERROR; 1352 } 1353 if (sscanf(buffer, "ppm image follows: %d\n", &nBytes) != 1) { 1354 Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"", 1355 (char *)NULL); 1356 return TCL_ERROR; 1357 } 1358 sprintf(buffer, "nv>image %d %d %d %d\n", nBytes, proxyPtr->cacheId, 1359 proxyPtr->frame, proxyPtr->rockOffset); 1360 length = strlen(buffer); 1361 imgPtr = NewImage(proxyPtr, nBytes + length); 1362 strcpy(imgPtr->data, buffer); 1363 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, nBytes) 1364 != BUFFER_OK) { 1365 ERROR("can't read %d bytes for \"image follows\" buffer: %s", nBytes, 1366 strerror(errno)); 1367 return TCL_ERROR; 1368 } 1369 #ifdef notdef 1370 if (Expect(proxyPtr, " ScenePNG", buffer, BUFSIZ-1) != TCL_OK) { 1371 return TCL_ERROR; 1372 } 1373 #endif 1402 1374 stats.nFrames++; 1403 1375 stats.nBytes += nBytes; … … 2006 1978 ProxyInit(int cin, int cout, char *const *argv) 2007 1979 { 1980 char stderrFile[200]; 2008 1981 int status, result = 0; 2009 1982 int sin[2]; … … 2027 2000 2028 2001 parent = getpid(); 2002 sprintf(stderrFile, "/tmp/pymol%d.stderr", parent); 2029 2003 2030 2004 /* Fork the new process. Connect I/O to the new socket. */ … … 2037 2011 2038 2012 interp = Tcl_CreateInterp(); 2039 if (CreateTmpDir(interp) != TCL_OK) {2040 ERROR(Tcl_GetStringResult(interp));2041 }2042 2013 Tcl_MakeSafe(interp); 2043 2014 … … 2059 2030 dup2(sin[0], 0); // stdin 2060 2031 dup2(sout[1], 1); // stdout 2061 sprintf(path, "/tmp/pymol%d/stderr", parent); 2062 f = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600); 2032 f = open(stderrFile, O_WRONLY | O_CREAT | O_TRUNC, 0600); 2063 2033 if (f < 0) { 2064 2034 ERROR("can't open server error file `%s': %s", path, … … 2097 2067 proxy.interp = interp; 2098 2068 2099 Tcl_CreateCommand(interp, "bmp", BmpCmd, &proxy, NULL);2100 2069 Tcl_CreateCommand(interp, "cartoon", CartoonCmd, &proxy, NULL); 2101 2070 Tcl_CreateCommand(interp, "cartoontrace", CartoonTraceCmd, &proxy, NULL); … … 2108 2077 Tcl_CreateCommand(interp, "pan", PanCmd, &proxy, NULL); 2109 2078 Tcl_CreateCommand(interp, "png", PngCmd, &proxy, NULL); 2079 Tcl_CreateCommand(interp, "ppm", PpmCmd, &proxy, NULL); 2110 2080 Tcl_CreateCommand(interp, "print", PrintCmd, &proxy, NULL); 2111 2081 Tcl_CreateCommand(interp, "raw", RawCmd, &proxy, NULL); … … 2133 2103 PollForEvents(&proxy); 2134 2104 2105 unlink(stderrFile); 2135 2106 close(proxy.cout); 2136 2107 close(proxy.sout); … … 2159 2130 INFO("pymol server process ended (result=%d)", result); 2160 2131 2161 DestroyTmpDir();2162 2132 Tcl_DeleteInterp(interp); 2163 2133 … … 2232 2202 if (line != NULL) { 2233 2203 Debug("STDOUT>%.*s", nBytes, line); 2234 Debug("Done with pymol stdout\n");2204 INFO("Garbage found from pymol server: %.%s", nBytes, line); 2235 2205 } else if (nBytes == BUFFER_CONTINUE) { 2236 Debug(" Done withpymol stdout\n");2237 goto error; /* Pymol server died unexpectedly. */2206 Debug("No data found on pymol stdout\n"); 2207 continue; 2238 2208 } else { 2239 2209 ERROR("can't read pymol stdout (nBytes=%d): %s\n", nBytes, … … 2301 2271 if ((nChannels == 0) || (proxyPtr->flags & FORCE_UPDATE)) { 2302 2272 if (proxyPtr->flags & UPDATE_PENDING) { 2303 Tcl_Eval(proxyPtr->interp, " bmp");2273 Tcl_Eval(proxyPtr->interp, "ppm"); 2304 2274 proxyPtr->flags &= ~UPDATE_PENDING; 2305 2275 }
Note: See TracChangeset
for help on using the changeset viewer.