Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

#$Id: autodockWizard.py 270 2016-03-13 01:59:01Z sarkiss $ 

""" autoDockWizard.py contains StartPage and AutoDockWizard. 

""" 

import wx, wx.aui, os 

from wx.lib import flatnotebook 

import utils 

import pickle 

import shutil 

import urllib2 

try: 

    from webServices import QueryRemoteJobs 

except: 

    QueryRemoteJobs = None 

 

from icons import residuePNG, molPNG, cubePNG, adtPNG, eTablePNG 

from preferences import global_preferences 

from vsModel import autodockPreferencesPage, autodockRemotePreferencesPage 

runAutoDockOptions = ["Local", "Cluster (Portable Batch System)", "Remote (Opal Web Services)"] 

AutoDockServiceURI = autodockRemotePreferencesPage.URI+'/'+autodockRemotePreferencesPage.AutoDockService 

 

class StartPage(wx.Panel): 

    def __init__(self, parent): 

        wx.Panel.__init__(self, parent, -1) 

        sizer = wx.BoxSizer(wx.VERTICAL) 

        label = wx.StaticText(self, -1, "This wizard will guide you through setting up and running AutoGrid and AutoDock.") 

        sizer.Add(label, 0, wx.WEST|wx.NORTH, 5) 

 

        self.infoLabel = wx.StaticText(self, -1, "") 

        sizer.Add(self.infoLabel, 1, wx.ALL, 5) 

        self.runAutoDockOptions = runAutoDockOptions 

        if not utils.which('qsub'): #Cluster (Portable Batch System) execution mode is not supported for Windows 

            txt = "Cluster (Portable Batch System)" 

            if txt in self.runAutoDockOptions: 

                self.runAutoDockOptions.remove("Cluster (Portable Batch System)") 

        try: 

            txt = urllib2.urlopen(AutoDockServiceURI).read() 

            if not "autodock" in txt: 

                self.runAutoDockOptions.remove("Remote (Opal Web Services)") 

        except: 

            self.runAutoDockOptions.remove("Remote (Opal Web Services)") 

 

 

        self.rb = wx.RadioBox(self, -1, "AutoDock Execution Mode", choices=self.runAutoDockOptions) 

        self.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, self.rb) 

        sizer.Add(self.rb, 0, wx.EXPAND) 

 

        buttonSizer = wx.BoxSizer(wx.HORIZONTAL) 

 

        lin = wx.StaticLine(self) 

        startButton = wx.Button(self, wx.ID_FORWARD, "Start") 

        buttonSizer.Add(wx.StaticText(self, -1, "Click on Start button to begin --->"), 0, wx.WEST|wx.NORTH, 5) 

        buttonSizer.Add((150, -1), 1, flag=wx.EXPAND | wx.ALIGN_RIGHT) 

        buttonSizer.Add(startButton, 0, wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT|wx.EAST|wx.SOUTH, 1) 

 

        sizer.Add(lin,0,wx.EXPAND) 

        sizer.Add(buttonSizer, 0, wx.EXPAND|wx.ALIGN_BOTTOM) 

        self.SetSizer(sizer) 

        sizer.SetSizeHints(self) 

        self.Bind(wx.EVT_BUTTON, self.Start, startButton) 

        self.sizer = sizer 

#        self.Bind(wx.EVT_SHOW, self.SetActive) 

        self.frame = self.TopLevelParent 

 

    def Start(self, event): 

        self.Parent.SetSelection(1) 

        self.frame.navigator.Selection = 1 

 

    def SetActive(self, event): 

        "This method is bound to wx.EVT_SHOW, i.e., invoked when this page is shown" 

        if self.Shown: 

            pref = global_preferences 

            try: 

                mode = int(pref.get('AutoDock.executionMode')) 

                self.rb.SetSelection(mode) 

            except: 

                pref = global_preferences 

                pref.set('AutoDock.executionMode', 0) 

                pref.flush() 

                mode = 0 

            self.rb.SetSelection(mode) 

            self.EvtRadioBox(None) 

            #self.Fit() 

 

    def EvtRadioBox(self, event): 

        selection = self.rb.GetSelection() 

        if self.runAutoDockOptions[selection] != "Remote (Opal Web Services)": 

            ADPath = utils.which(autodockPreferencesPage.autodock) 

            if not ADPath: 

                self.infoLabel.SetLabel("Please set Autodock path using Edit -> Preferences....") 

                return 

            self.infoLabel.SetLabel(ADPath+" will be used for docking. " ) 

        else: 

            self.infoLabel.SetLabel("AutoDock Service running at " 

                                    + AutoDockServiceURI + " will be used for docking.") 

        try: 

            pref = global_preferences 

            pref.set('AutoDock.executionMode', selection) 

            pref.flush() 

        except: #avoid IOError when multiple copies are run 

            pass 

 

class AutoDockWizard(wx.Panel): 

    def __init__(self, frame): 

        wx.Panel.__init__(self, frame, -1) 

        book = wx.Notebook(self, wx.ID_ANY) 

        self.book = book 

        sizer = wx.BoxSizer(wx.VERTICAL) 

        sizer.Add(book, 1, wx.EXPAND) 

        self.SetSizer(sizer) 

        self.sizer = sizer 

        self.CreateIcons() 

        startPage = StartPage(book) 

        book.AddPage(startPage, "Start Here", imageId=0) 

        self.startPage = startPage 

        from selectMolecules import SelectMoleculesPage 

        selectMoleculesPage = SelectMoleculesPage(book) 

        book.AddPage(selectMoleculesPage, "Select Molecules", imageId=1) 

        self.selectMoleculesPage = selectMoleculesPage 

        from autogridPage import RunAutoGrid 

        runAutoGrid = RunAutoGrid(book) 

        book.AddPage(runAutoGrid, "Run AutoGrid", imageId=3) 

        self.runAutoGrid = runAutoGrid 

        from autodockPage import RunAutoDock 

        runAutoDock = RunAutoDock(book) 

        book.AddPage(runAutoDock, "Run AutoDock", imageId=4) 

        self.runAutoDock = runAutoDock 

        from analyzePage import Analyze 

        analyze = Analyze(book) 

        book.AddPage(analyze, "Analyze Results", imageId=5) 

        self.analyzePage = analyze 

        frame.controls.AddPage(self, "AutoDock Wizard", bitmap=adtPNG) 

        self.frame = frame 

        book.SetSelection(0) 

        wx.EVT_NOTEBOOK_PAGE_CHANGED(self.book, -1, self.PageChanged) 

        ID_DLG = wx.NewId() 

        frame.toolBar.AddLabelTool(ID_DLG, "Load DLG", adtPNG, 

                                  shortHelp="Load Docking Log File (DLG)", longHelp="Load Docking Log File (DLG)") 

        frame.Bind(wx.EVT_TOOL, analyze.Open, id=ID_DLG) 

        try: 

            from webServices import AutoDockWebService 

            self.frame.autodockWS = AutoDockWebService(self.frame) 

        except: 

            pass 

        wx.CallAfter(startPage.SetActive, None) 

 

        remoteJobsFilePath = os.path.join(self.frame.vsModel.etcFolder,'AutoDock_RemoteJobs') 

        if os.path.exists(remoteJobsFilePath): 

            if os.path.exists(remoteJobsFilePath+"_old"): 

                jobsList = open(remoteJobsFilePath).readlines() 

                jobsList.extend(open(remoteJobsFilePath+"_old").readlines()) 

                jobsList = list(set(jobsList)) 

                open(remoteJobsFilePath+"_old", 'w').writelines(jobsList) 

                os.remove(remoteJobsFilePath) 

            else: 

                open(remoteJobsFilePath+"_old", 'w').write(open(remoteJobsFilePath).read()) 

            wx.FutureCall(100, QueryRemoteJobs, remoteJobsFilePath+"_old", self.frame) 

        elif os.path.exists(remoteJobsFilePath+"_old"): 

            wx.FutureCall(100, QueryRemoteJobs, remoteJobsFilePath+"_old", self.frame) 

 

    def PageChanged(self, event): 

        if self.TopLevelParent: #make sure that SetActive is not called on Exit 

            self.book.GetPage(event.GetSelection()).SetActive(event) 

        event.Skip() 

 

    def CreateIcons(self): 

        imageSize = (16,16) 

        il = wx.ImageList(16,16) 

        self.il = il 

        tip = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_TOOLBAR, imageSize) 

        il.Add(tip) 

        il.Add(residuePNG) 

        il.Add(molPNG) 

        il.Add(cubePNG) 

        il.Add(adtPNG) 

        il.Add(eTablePNG) 

        self.book.SetImageList(il)