File: link_demo.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 (68 lines) | stat: -rw-r--r-- 1,453 bytes parent folder | download | duplicates (6)
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
58
59
60
61
62
63
64
65
66
67
68
# experimental demonstration of firing up a web browser based on
# clicks in the 3D viewer

# simply "run" this script from within PyMOL itself (file menu) or
# ./pymol link_demo.py

import webbrowser
import pymol
from pymol.wizard import Wizard
from pymol import cmd, util
import pymol

# Wizard class definition 

class Clickurl(Wizard):

    def __init__(self,_self=cmd):
        Wizard.__init__(self,_self)
        self.cmd.unpick()

    def get_prompt(self):
        self.prompt = [ 'Please click a labelled atom...' ]
        return self.prompt

    def get_panel(self):
        return [
            [ 2, 'Done','cmd.set_wizard()'],
            ]
    
    def do_select(self,name):
        pymol.stored.link = ''
        cmd.iterate(name,"stored.link=custom") 
        if len(pymol.stored.link):
            webbrowser.open(pymol.stored.link)
        cmd.delete(name)

# load an example structure

cmd.load("$TUT/1hpv.pdb")

# color by chain (aesthetics)

util.cbc()

# store the links as atom text_types

cmd.alter("name CA",r"custom='http://delsci.info/cgi-bin/click.cgi?residue=%s%s%s'%(resn,resi,chain)")

# put the mouse into single-atom selection mode

cmd.set('mouse_selection_mode',0)

# just show ribbon (means we can only select labelled C-alphas)

cmd.show_as("cartoon") 

# set up the labels

cmd.label("name CA","'Link'")

# color the labels white

cmd.set("label_color", 'white')

# activate the wizard

cmd.set_wizard(Clickurl())