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 opening a Molmol pipe."""
44
45
46 self.relax.data.molmol = popen("molmol -f -", 'w', 0)
47
48
49 if len(self.command_history) > 0:
50 self.write(self.command_history, store_command=0)
51 return
52
53
54 if hasattr(self.relax.data, 'pdb'):
55 self.open_pdb()
56
57
58 else:
59 self.write("InitAll yes")
60
61
63 """Function for opening the PDB file in Molmol."""
64
65
66 if run:
67 self.run = run
68
69
70 if not self.pipe_open():
71 return
72
73
74 self.write("InitAll yes")
75
76
77 self.write("ReadPdb " + self.relax.data.pdb[self.run].file_name)
78
79
81 """Function for testing if the Molmol pipe is open."""
82
83
84 if not hasattr(self.relax.data, 'molmol'):
85 return 0
86
87
88 try:
89 self.relax.data.molmol.write('\n')
90 except IOError:
91 return 0
92
93
94 return 1
95
96
97 - def view(self, run=None):
98 """Function for running Molmol."""
99
100
101 self.run = run
102
103
104 if self.pipe_open():
105 raise RelaxError, "The Molmol pipe already exists."
106 else:
107 self.open_pipe()
108
109
110 - def write(self, command=None, store_command=1):
111 """Function for writing to the Molmol pipe.
112
113 This function is also used to execute a user supplied Molmol command.
114 """
115
116
117 if not self.pipe_open():
118 self.open_pipe()
119
120
121 self.relax.data.molmol.write(command + '\n')
122
123
124 if store_command:
125 self.command_history = self.command_history + command + "\n"
126