Package gui :: Package user_functions :: Module molecule
[hide private]
[frames] | no frames]

Source Code for Module gui.user_functions.molecule

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2010-2011 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """The molecule user function GUI elements.""" 
 25   
 26  # relax module imports. 
 27  from generic_fns.mol_res_spin import ALLOWED_MOL_TYPES, generate_spin_id, molecule_loop 
 28  from generic_fns.pipes import cdp_name, get_pipe, pipe_names 
 29   
 30  # GUI module imports. 
 31  from base import UF_base, UF_page 
 32  from gui.paths import WIZARD_IMAGE_PATH 
 33  from gui.misc import gui_to_str, str_to_gui 
 34   
 35   
 36  # The container class. 
37 -class Molecule(UF_base):
38 """The container class for holding all GUI elements.""" 39
40 - def copy(self):
41 """The molecule.copy user function.""" 42 43 # Execute the wizard. 44 wizard = self.create_wizard(size_x=700, size_y=500, name='molecule.copy', uf_page=Copy_page) 45 wizard.run()
46 47
48 - def create(self):
49 """The molecule.create user function.""" 50 51 # Execute the wizard. 52 wizard = self.create_wizard(size_x=700, size_y=400, name='molecule.create', uf_page=Create_page) 53 wizard.run()
54 55
56 - def delete(self, mol_name=None):
57 """The molecule.delete user function. 58 59 @param mol_name: The starting molecule name. 60 @type mol_name: str 61 """ 62 63 # Create the wizard. 64 wizard, page = self.create_wizard(size_x=700, size_y=400, name='molecule.delete', uf_page=Delete_page, return_page=True) 65 66 # Default molecule name. 67 if mol_name: 68 page.mol.SetValue(str_to_gui(mol_name)) 69 70 # Execute the wizard. 71 wizard.run()
72 73 74
75 -class Copy_page(UF_page):
76 """The molecule.copy() user function page.""" 77 78 # Some class variables. 79 image_path = WIZARD_IMAGE_PATH + 'molecule.png' 80 uf_path = ['molecule', 'copy'] 81
82 - def add_contents(self, sizer):
83 """Add the molecule specific GUI elements. 84 85 @param sizer: A sizer object. 86 @type sizer: wx.Sizer instance 87 """ 88 89 # The source pipe. 90 self.pipe_from = self.combo_box(sizer, "The source data pipe:", [], evt_fn=self.update_mol_list, tooltip=self.uf._doc_args_dict['pipe_from']) 91 92 # The molecule selection. 93 self.mol_from = self.combo_box(sizer, "The source molecule:", [], tooltip=self.uf._doc_args_dict['mol_from']) 94 95 # The destination pipe. 96 self.pipe_to = self.combo_box(sizer, "The destination data pipe name:", [], tooltip=self.uf._doc_args_dict['pipe_to']) 97 98 # The new molecule name. 99 self.mol_to = self.input_field(sizer, "The new molecule name:", tooltip=self.uf._doc_args_dict['mol_to'])
100 101
102 - def on_display(self):
103 """Update the pipe name lists.""" 104 105 # Set the default pipe name. 106 if not gui_to_str(self.pipe_from.GetValue()): 107 self.pipe_from.SetValue(str_to_gui(cdp_name())) 108 if not gui_to_str(self.pipe_to.GetValue()): 109 self.pipe_to.SetValue(str_to_gui(cdp_name())) 110 111 # Clear the previous data. 112 self.pipe_from.Clear() 113 self.pipe_to.Clear() 114 115 # The list of pipe names. 116 for name in pipe_names(): 117 self.pipe_from.Append(str_to_gui(name)) 118 self.pipe_to.Append(str_to_gui(name)) 119 120 # Update the molecule list. 121 self.update_mol_list()
122 123
124 - def on_execute(self):
125 """Execute the user function.""" 126 127 # Get the pipe names. 128 pipe_from = gui_to_str(self.pipe_from.GetValue()) 129 pipe_to = gui_to_str(self.pipe_to.GetValue()) 130 131 # The molecule names. 132 mol_from = gui_to_str(self.mol_from.GetValue()) 133 if mol_from: 134 mol_from = "#" + mol_from 135 mol_to = gui_to_str(self.mol_to.GetValue()) 136 if mol_to: 137 mol_to = "#" + mol_to 138 139 # Copy the molecule. 140 self.execute('molecule.copy', pipe_from=pipe_from, mol_from=mol_from, pipe_to=pipe_to, mol_to=mol_to)
141 142
143 - def update_mol_list(self, event=None):
144 """Update the list of molecules. 145 146 @param event: The wx event. 147 @type event: wx event 148 """ 149 150 # The source data pipe. 151 pipe_from = gui_to_str(self.pipe_from.GetValue()) 152 153 # Clear the previous data. 154 self.mol_from.Clear() 155 156 # The list of molecule names. 157 if cdp_name(): 158 for mol in molecule_loop(pipe=pipe_from): 159 self.mol_from.Append(str_to_gui(mol.name))
160 161 162
163 -class Create_page(UF_page):
164 """The molecule.create() user function page.""" 165 166 # Some class variables. 167 image_path = WIZARD_IMAGE_PATH + 'molecule.png' 168 uf_path = ['molecule', 'create'] 169 170
171 - def add_contents(self, sizer):
172 """Add the molecule specific GUI elements. 173 174 @param sizer: A sizer object. 175 @type sizer: wx.Sizer instance 176 """ 177 178 # The molecule name input. 179 self.mol_name = self.input_field(sizer, "Molecule name:", tooltip=self.uf._doc_args_dict['mol_name']) 180 181 # The type selection. 182 self.mol_type = self.combo_box(sizer, "Molecule type:", ALLOWED_MOL_TYPES, tooltip=self.uf._doc_args_dict['mol_type'])
183 184
185 - def on_execute(self):
186 """Execute the user function.""" 187 188 # Get the name and type. 189 mol_name = str(self.mol_name.GetValue()) 190 mol_type = str(self.mol_type.GetValue()) 191 192 # Set the name. 193 self.execute('molecule.create', mol_name=mol_name, mol_type=mol_type)
194 195 196
197 -class Delete_page(UF_page):
198 """The molecule.delete() user function page.""" 199 200 # Some class variables. 201 image_path = WIZARD_IMAGE_PATH + 'molecule.png' 202 uf_path = ['molecule', 'delete'] 203 204
205 - def add_contents(self, sizer):
206 """Add the molecule specific GUI elements. 207 208 @param sizer: A sizer object. 209 @type sizer: wx.Sizer instance 210 """ 211 212 # The molecule selection. 213 self.mol_id = self.combo_box(sizer, "Molecule ID:", [], tooltip=self.uf._doc_args_dict['mol_id'])
214 215
216 - def on_display(self):
217 """Clear and update the molecule list.""" 218 219 # Clear the previous data. 220 self.mol_id.Clear() 221 222 # The list of molecule names. 223 if cdp_name(): 224 for mol, mol_id in molecule_loop(return_id=True): 225 self.mol_id.Append(str_to_gui(mol_id))
226 227
228 - def on_execute(self):
229 """Execute the user function.""" 230 231 # Get the name. 232 mol_id = gui_to_str(self.mol_id.GetValue()) 233 234 # Delete the molecule. 235 self.execute('molecule.delete', mol_id=mol_id)
236