"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "examples/devel/webgui02.py" between
pymol-v1.8.6.0.tar.bz2 and pymol-v2.1.0.tar.bz2

About: PyMOL is a Python-enhanced molecular graphics tool. It excels at 3D visualization of proteins, small molecules, density, surfaces, and trajectories. It also includes molecular editing, ray tracing, and movies. Open Source version.

webgui02.py  (pymol-v1.8.6.0.tar.bz2):webgui02.py  (pymol-v2.1.0.tar.bz2)
# Another simple example of how PyMOL can be controlled using a web browser # Another simple example of how PyMOL can be controlled using a web browser
# using Python's built-in web server capabilities # using Python's built-in web server capabilities
import SocketServer try:
import BaseHTTPServer import BaseHTTPServer
except ImportError:
import http.server as BaseHTTPServer
import time import time
import cgi import cgi
import threading import threading
import traceback import traceback
import os, sys, re import os, sys, re
from pymol import cmd from pymol import cmd
from chempy.sdf import SDF from chempy.sdf import SDF
skipping to change at line 140 skipping to change at line 142
''') ''')
def do_pymol(self): def do_pymol(self):
if "table.pymol" in self.path: # send table if "table.pymol" in self.path: # send table
session = ServerState[default_token] session = ServerState[default_token]
self.send_response(200) self.send_response(200)
self.send_header('Content-type', 'text/html') self.send_header('Content-type', 'text/html')
self.send_header('Cache-control', 'no-cache') self.send_header('Cache-control', 'no-cache')
self.send_header('Pragma', 'no-cache') self.send_header('Pragma', 'no-cache')
self.end_headers() self.end_headers()
if not session.has_key('table'): if 'table' not in session:
self.wfile.write("<p>No table defined.</p>\n") self.wfile.write("<p>No table defined.</p>\n")
else: else:
write_table(self.wfile, session['table']) write_table(self.wfile, session['table'])
elif "quit.pymol" in self.path: elif "quit.pymol" in self.path:
self.wfile.write('<html><body><p>Quitting...</p></body></html>') self.wfile.write('<html><body><p>Quitting...</p></body></html>')
self.wfile.flush() self.wfile.flush()
_shutdown() _shutdown()
elif "load.pymol" in self.path: elif "load.pymol" in self.path:
self.send_response(200) self.send_response(200)
self.send_header('Content-type', 'text/html') self.send_header('Content-type', 'text/html')
skipping to change at line 214 skipping to change at line 216
def do_POST(self): # not currently used def do_POST(self): # not currently used
global rootnode global rootnode
try: try:
ctype, pdict = cgi.parse_header(self.headers.getheader('content-type ')) ctype, pdict = cgi.parse_header(self.headers.getheader('content-type '))
if ctype == 'multipart/form-data': if ctype == 'multipart/form-data':
query=cgi.parse_multipart(self.rfile, pdict) query=cgi.parse_multipart(self.rfile, pdict)
self.send_response(301) self.send_response(301)
self.end_headers() self.end_headers()
upfilecontent = query.get('upfile') upfilecontent = query.get('upfile')
print "filecontent", upfilecontent[0] print("filecontent", upfilecontent[0])
self.wfile.write('<HTML>POST OK.<BR><BR>'); self.wfile.write('<HTML>POST OK.<BR><BR>');
self.wfile.write(upfilecontent[0]); self.wfile.write(upfilecontent[0]);
except : except :
pass pass
def table_from_data(data): def table_from_data(data):
# pull MOLID to the far left # pull MOLID to the far left
col_id_list = ['MOLID'] + filter(lambda x:x!='MOLID',data['col_id_list']) col_id_list = ['MOLID'] + [x for x in data['col_id_list'] if x!='MOLID']
content = data['content'] content = data['content']
# create the header fields # create the header fields
header = [] header = []
for col_id in col_id_list: for col_id in col_id_list:
header.append(col_id) header.append(col_id)
# create the body # create the body
skipping to change at line 287 skipping to change at line 289
# store the MOL record # store the MOL record
mol_dict[mol_id] = string.join(mol,'') mol_dict[mol_id] = string.join(mol,'')
# add row (assuming mol_id is unique) # add row (assuming mol_id is unique)
row_id_list.append(mol_id) row_id_list.append(mol_id)
row_id_dict[mol_id] = None row_id_dict[mol_id] = None
# add column (if new) # add column (if new)
for key in rec.kees: for key in rec.kees:
if key != 'MOL': if key != 'MOL':
if not col_id_dict.has_key(key): if key not in col_id_dict:
col_id_list.append(key) col_id_list.append(key)
col_id_dict[key] = None col_id_dict[key] = None
# second pass, read the actual data into the table structure # second pass, read the actual data into the table structure
content = {} content = {}
sdf = SDF(sdf_file_path) sdf = SDF(sdf_file_path)
while 1: while 1:
rec = sdf.read() rec = sdf.read()
skipping to change at line 324 skipping to change at line 326
import webbrowser import webbrowser
time.sleep(1) time.sleep(1)
webbrowser.open('http://localhost:8080/table.pymol') webbrowser.open('http://localhost:8080/table.pymol')
# import os # import os
# os.system('open http://localhost:8080/start.pymol') # os.system('open http://localhost:8080/start.pymol')
def main(): def main():
try: try:
global _server global _server
_server = BaseHTTPServer.HTTPServer(('', 8080), PymolHandler) _server = BaseHTTPServer.HTTPServer(('', 8080), PymolHandler)
print 'started httpserver...' print('started httpserver...')
_server.serve_forever() _server.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
print '^C received, shutting down server' print('^C received, shutting down server')
_server.socket.close() _server.socket.close()
if __name__ == '__main__': if __name__ == '__main__':
print "this script must be run from within PyMOL" print("this script must be run from within PyMOL")
if __name__ == 'pymol': if __name__ == 'pymol':
session = SafeDict() session = SafeDict()
session['cmd'] = cmd # could replaced by instance instead of module session['cmd'] = cmd # could replaced by instance instead of module
session['data'] = data_from_sdf(input_sdf) session['data'] = data_from_sdf(input_sdf)
session['table'] = table_from_data(session['data']) session['table'] = table_from_data(session['data'])
ServerState[default_token] = session ServerState[default_token] = session
 End of changes. 8 change blocks. 
9 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)