1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from os import popen
24
25
28 """Class containing the functions for viewing molecules."""
29
30 self.relax = relax
31
32
33 self.clear_history()
34
35
36 - def clear_history(self):
37 """Function for clearing the Molmol command history."""
38
39 self.command_history = ""
40
41
43 """Function for creating an array of Molmol commands."""
44
45
46 self.function_type = self.relax.data.run_types[self.relax.data.run_names.index(self.run)]
47
48
49 molmol_macro = self.relax.specific_setup.setup('molmol_macro', self.function_type)
50
51
52 self.commands = molmol_macro(self.run, self.data_type, self.style, self.colour_start, self.colour_end, self.colour_list)
53
54
55 - def macro_exec(self, run=None, data_type=None, style="classic", colour_start=None, colour_end=None, colour_list=None):
56 """Function for executing a Molmol macro."""
57
58
59 self.run = run
60 self.data_type = data_type
61 self.style = style
62 self.colour_start = colour_start
63 self.colour_end = colour_end
64 self.colour_list = colour_list
65
66
67 if not self.run in self.relax.data.run_names:
68 raise RelaxNoRunError, self.run
69
70
71 if not self.relax.data.res.has_key(self.run):
72 raise RelaxNoSequenceError, self.run
73
74
75 self.create_macro()
76
77
78 for command in self.commands:
79 self.pipe_write(command)
80
81
98
99
101 """Function for opening a Molmol pipe."""
102
103
104 self.relax.IO.test_binary('molmol')
105
106
107 self.relax.data.molmol = popen("molmol -f -", 'w', 0)
108
109
110 if len(self.command_history) > 0:
111 self.pipe_write(self.command_history, store_command=0)
112 return
113
114
115 if hasattr(self.relax.data, 'pdb') and self.relax.data.pdb.has_key(self.run):
116 self.open_pdb()
117
118
119 else:
120 self.pipe_write("InitAll yes")
121
122
124 """Function for testing if the Molmol pipe is open."""
125
126
127 if not hasattr(self.relax.data, 'molmol'):
128 return 0
129
130
131 try:
132 self.relax.data.molmol.write('\n')
133 except IOError:
134 return 0
135
136
137 return 1
138
139
140 - def pipe_write(self, command=None, store_command=1):
141 """Function for writing to the Molmol pipe.
142
143 This function is also used to execute a user supplied Molmol command.
144 """
145
146
147 if not self.pipe_open_test():
148 self.pipe_open()
149
150
151 self.relax.data.molmol.write(command + '\n')
152
153
154 if store_command:
155 self.command_history = self.command_history + command + "\n"
156
157
158 - def view(self, run=None):
169
170
171 - def write(self, run=None, data_type=None, style="classic", colour_start=None, colour_end=None, colour_list=None, file=None, dir=None, force=0):
172 """Function for creating a Molmol macro."""
173
174
175 self.run = run
176 self.data_type = data_type
177 self.style = style
178 self.colour_start = colour_start
179 self.colour_end = colour_end
180 self.colour_list = colour_list
181
182
183 if not self.run in self.relax.data.run_names:
184 raise RelaxNoRunError, self.run
185
186
187 if not self.relax.data.res.has_key(self.run):
188 raise RelaxNoSequenceError, self.run
189
190
191 self.create_macro()
192
193
194 if file == None:
195 file = data_type + '.mac'
196
197
198 file = self.relax.IO.open_write_file(file, dir, force)
199
200
201 for command in self.commands:
202 file.write(command + "\n")
203
204
205 file.close()
206