File: xmlrpc01.py

package info (click to toggle)
pymol 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 42,288 kB
  • sloc: cpp: 476,472; python: 76,538; ansic: 29,510; javascript: 6,792; sh: 47; makefile: 24
file content (57 lines) | stat: -rw-r--r-- 1,598 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# This demonstration requires Python 2.2 and
# PyMOL compiled with Python 2.2

# Author: Greg Landum
# Commentary by Warren DeLano

# To Try:
# (1) in one process launch PyMOL with "-R" option "./pymol.com -R"
# (2) in another process "python xmlrpc01.py"

molData="""foo


  5  4  0  0  0                 1 V2000
    0.0000    0.0000    0.0000 C   0  0  0  0  0
    0.5000    0.5000    0.5000 C   0  0  0  0  0
   -0.5000   -0.5000    0.5000 C   0  0  0  0  0
   -0.5000    0.5000   -0.5000 C   0  0  0  0  0
    0.5000   -0.5000   -0.5000 C   0  0  0  0  0
  1  2  1  0  0  0
  1  3  1  0  0  0
  1  4  1  0  0  0
  1  5  1  0  0  0
M  END
"""
import sys,tempfile,os

try:
    import xmlrpclib
except ImportError:
    import xmlrpc.client as xmlrpclib

fName = tempfile.mktemp('.mol')
open(fName,'w+').write(molData)
port = 9123
if len(sys.argv)>1:
  port = int(sys.argv[1])

s = xmlrpclib.Server('http://localhost:%d'%(port))
s.do('delete fooby')
s.do('delete fooby-o')
s.do('load %s, fooby'%(fName))
s.sphere((.5,.5,.5),.5,(1,.5,1),'fooby-o',0)
s.sphere((-.5,-.5,.5),.5,(1,1,.5),'fooby-o')
s.sphere((-.5,.5,-.5),.5,(1,.5,5),'fooby-o')
s.sphere((.5,-.5,-.5),.5,(.5,1,.5),'fooby-o')

s.cylinder((.5,.5,.5),(-.5,-.5,.5),.1,(.5,.5,.5),'fooby-o')
s.cylinder((.5,.5,.5),(-.5,.5,-.5),.1,(.5,.5,.5),'fooby-o')
s.cylinder((.5,.5,.5),(.5,-.5,-.5),.1,(.5,.5,.5),'fooby-o')
s.cylinder((-.5,-.5,.5),(.5,-.5,-.5),.1,(.5,.5,.5),'fooby-o')
s.cylinder((-.5,-.5,.5),(-.5,.5,-.5),.1,(.5,.5,.5),'fooby-o')
s.cylinder((.5,-.5,-.5),(-.5,.5,-.5),.1,(.5,.5,.5),'fooby-o')

#s.label((1,0,0),"foobar")

os.unlink(fName)