xmlrpc02.py (pymol-v1.8.6.0.tar.bz2) | : | xmlrpc02.py (pymol-v2.1.0.tar.bz2) | ||
---|---|---|---|---|
""" simple demo for using the PyMol RPC server | """ simple demo for using the PyMol RPC server | |||
Author: Greg Landrum (Landrum@RationalDiscovery.com) | Author: Greg Landrum (Landrum@RationalDiscovery.com) | |||
Created: February 2004 | Created: February 2004 | |||
$LastChangedDate: 2009-02-01 14:02:14 -0500 (Sun, 01 Feb 2009) $ | $LastChangedDate: 2017-12-05 19:37:16 +0100 (Tue, 05 Dec 2017) $ | |||
License: PyMol | License: PyMol | |||
Requires: | Requires: | |||
- a python xmlrpclib distribution containing the SimpleXMLRPCServer | - a python xmlrpclib distribution containing the SimpleXMLRPCServer | |||
module (1.0 or greater should be fine) | module (1.0 or greater should be fine) | |||
RD Version: $Rev: 3570 $ | RD Version: $Rev: 4183 $ | |||
""" | """ | |||
import xmlrpclib | try: | |||
import xmlrpclib | ||||
except ImportError: | ||||
import xmlrpc.client as xmlrpclib | ||||
def startServer(host='localhost',startPort=9123,nToTry=5): | def startServer(host='localhost',startPort=9123,nToTry=5): | |||
done = 0 | done = 0 | |||
offset = 0 | offset = 0 | |||
while offset < nToTry: | while offset < nToTry: | |||
c = xmlrpclib.Server('http://%s:%d'%(host,startPort+offset)) | c = xmlrpclib.Server('http://%s:%d'%(host,startPort+offset)) | |||
try: | try: | |||
c.ping() | c.ping() | |||
except: | except: | |||
print 'Failed on port %d, trying another'%(startPort+offset) | print('Failed on port %d, trying another'%(startPort+offset)) | |||
offset = offset + 1 | offset = offset + 1 | |||
else: | else: | |||
done = 1 | done = 1 | |||
break | break | |||
if done: | if done: | |||
return c,startPort+offset | return c,startPort+offset | |||
else: | else: | |||
return None,-1 | return None,-1 | |||
molBlock="""3d.mol | molBlock="""3d.mol | |||
skipping to change at line 97 | skipping to change at line 100 | |||
8 25 1 6 0 0 | 8 25 1 6 0 0 | |||
10 26 1 6 0 0 | 10 26 1 6 0 0 | |||
10 27 1 0 0 0 | 10 27 1 0 0 0 | |||
M END | M END | |||
""" | """ | |||
if __name__=='__main__': | if __name__=='__main__': | |||
import sys | import sys | |||
serv,port = startServer() | serv,port = startServer() | |||
if serv is not None: | if serv is not None: | |||
print 'connected to PyMol rpc-server on port %d'%port | print('connected to PyMol rpc-server on port %d'%port) | |||
else: | else: | |||
print 'unable to connect to PyMol' | print('unable to connect to PyMol') | |||
sys.exit(-1) | sys.exit(-1) | |||
serv.loadMolBlock(molBlock,'sample-mol') | serv.loadMolBlock(molBlock,'sample-mol') | |||
serv.set('sphere_scale',0.25,'sample-mol') | serv.set('sphere_scale',0.25,'sample-mol') | |||
serv.do('show sticks;show spheres') | serv.do('show sticks;show spheres') | |||
serv.sphere((.28,-1.2,1.48),.5,(1,0,1),'demo') | serv.sphere((.28,-1.2,1.48),.5,(1,0,1),'demo') | |||
serv.sphere((0,1.87,.26),.5,(1,0,1),'demo') | serv.sphere((0,1.87,.26),.5,(1,0,1),'demo') | |||
serv.cylinder((.28,-1.2,1.48),(0,1.87,.26),.1,(.5,0,.5),'demo') | serv.cylinder((.28,-1.2,1.48),(0,1.87,.26),.1,(.5,0,.5),'demo') | |||
serv.zoom() | serv.zoom() | |||
End of changes. 6 change blocks. | ||||
6 lines changed or deleted | 9 lines changed or added |