Exemplo n.º 1
0
    def fillInUI(self, parent):

        self.toplevel_widget = parent.winfo_toplevel()
        self.toplevel_widget.withdraw()

        row = 0

        import Tkinter

        from chimera.widgets import MoleculeOptionMenu
        mm = MoleculeOptionMenu(parent, labelpos='w', label_text='Molecule ')
        mm.grid(row=row, column=0, sticky='w')
        self.molecule_menu = mm
        row = row + 1

        from VolumeViewer import Volume_Menu
        vm = Volume_Menu(parent, 'Volume data ', open_button=True)
        vm.frame.grid(row=row, column=0, sticky='w')
        self.volume_menu = vm
        row = row + 1

        #
        # Specify a label width so dialog is not resized for long messages.
        #
        msg = Tkinter.Label(parent, width=30, anchor='w', justify='left')
        msg.grid(row=row, column=0, sticky='ew')
        row = row + 1
        self.message_label = msg
Exemplo n.º 2
0
    def fillInUI(self, parent):
        import Pmw, Tkinter
        SaveModeless.fillInUI(self, parent)
        row = 0

        from chimera.widgets import MoleculeOptionMenu
        self.modelMenu = MoleculeOptionMenu(
            self.clientArea,
            labelpos='w',
            label_text="Save model:",
            command=lambda m: self.configure(self.modelMenu.getvalue(),
                                             refreshList=False))
        self.modelMenu.grid(row=row, column=0, sticky='w')
        row += 1

        from AddCharge import knownChargeModels, defaultChargeModel

        from chimera import dialogs
        self.parmsetOption = Pmw.OptionMenu(
            self.clientArea,
            labelpos='w',
            label_text="Select force field type: ",
            initialitem=defaultChargeModel,
            items=knownChargeModels)
        # not always shown; remember row number
        self._msmRow = row
        self.parmsetOption.grid(row=row, column=0, sticky='w')
        row += 1
Exemplo n.º 3
0
  def fillInUI(self, parent):

    self.toplevel_widget = parent.winfo_toplevel()
    self.toplevel_widget.withdraw()

    parent.columnconfigure(0, weight=1)
    row = 0

    import Tkinter
    from CGLtk import Hybrid

    from chimera.widgets import MoleculeOptionMenu
    mm = MoleculeOptionMenu(parent, labelpos = 'w', label_text = 'Molecule ')
    mm.grid(row = row, column = 0, sticky = 'w')
    self.molecule_menu = mm
    row = row + 1

    cd = Hybrid.Entry(parent, 'Contact distance', 5, '1.0')
    cd.frame.grid(row = row, column = 0, sticky = 'w')
    self.contact_distance = cd.variable
    cd.entry.bind('<KeyPress-Return>', self.show_contacts)
    row = row + 1

    mc = Hybrid.Checkbutton(parent, 'Create copies of contacting molecules.', False)
    mc.button.grid(row = row, column = 0, sticky = 'w')
    row += 1
    self.copy_molecule = mc.variable
    
    msg = Tkinter.Label(parent, anchor = 'w', justify = 'left')
    msg.grid(row = row, column = 0, sticky = 'ew')
    row = row + 1
    self.message_label = msg
Exemplo n.º 4
0
  def fillInUI(self, parent):
    self.toplevel_widget = parent.winfo_toplevel()
    self.toplevel_widget.withdraw()
	
    parent.columnconfigure(0, weight = 1)

    from CGLtk import Hybrid
    import Pmw, Tkinter
	
    from chimera.widgets import MoleculeOptionMenu
    self.molMenu = MoleculeOptionMenu(parent, labelpos="w",
						label_text="Select PDB:")
    self.molMenu.grid(row = 1, column = 0, sticky = 'w')

    from chimera.widgets import MoleculeChainOptionMenu 
    self.chainMenu = MoleculeChainOptionMenu(parent, labelpos="w",
	                    label_text="Select Chain:")
    self.chainMenu.grid(row = 2, column = 0, sticky = 'w')
	
	
    from chimera.widgets import ModelOptionMenu 
    self.modelMenu = ModelOptionMenu(parent, labelpos="w",
	                    label_text="Select MRC:")
    self.modelMenu.grid(row = 3, column = 0, sticky = 'w')
	
    import Pmw
    self.radius = Pmw.EntryField(parent, labelpos="w",
                        label_text="Radius:")
    self.radius.grid(row = 4, column = 0, sticky = 'w')
	
    self.resolution = Pmw.EntryField(parent, labelpos="w",
                        label_text="Resolution:")
    self.resolution.grid(row = 5, column = 0, sticky = 'w')
Exemplo n.º 5
0
  def fillInUI(self, parent):

    self.toplevel_widget = parent.winfo_toplevel()
    self.toplevel_widget.withdraw()
    
    row = 0

    import Tkinter

    from chimera.widgets import MoleculeOptionMenu
    mm = MoleculeOptionMenu(parent, labelpos = 'w', label_text = 'Molecule ')
    mm.grid(row = row, column = 0, sticky = 'w')
    self.molecule_menu = mm
    row = row + 1

    from VolumeViewer import Volume_Menu
    vm = Volume_Menu(parent, 'Volume data ', open_button = True)
    vm.frame.grid(row = row, column = 0, sticky = 'w')
    self.volume_menu = vm
    row = row + 1
    
    #
    # Specify a label width so dialog is not resized for long messages.
    #
    msg = Tkinter.Label(parent, width = 30, anchor = 'w', justify = 'left')
    msg.grid(row = row, column = 0, sticky = 'ew')
    row = row + 1
    self.message_label = msg
Exemplo n.º 6
0
    def fill_in_ui(self, parent):
        self.canvas.columnconfigure(0, weight=1)
        row = 0
        self.ui_calculation = tk.LabelFrame(self.canvas,
                                            text='Perceive bond order')
        self.ui_molecule = MoleculeOptionMenu(self.ui_calculation,
                                              labelpos='w',
                                              label_text='Analyze')
        self.ui_methods = Pmw.OptionMenu(
            self.ui_calculation,
            label_text='with',
            labelpos='w',
            items=['RDKit', 'OpenBabel', 'Single'])
        self.ui_calculate_btn = tk.Button(self.ui_calculation,
                                          text='Go!',
                                          command=self._cmd_calculate_btn)
        self.ui_calculation.grid(row=row, padx=5, pady=5, sticky='we')
        self.ui_calculation.columnconfigure(0, weight=1)
        self.ui_molecule.grid(row=0, column=0, padx=5, pady=5, sticky='we')
        self.ui_methods.grid(row=0, column=1, padx=5, pady=5)
        self.ui_calculate_btn.grid(row=0, column=2, padx=5, pady=5)

        row += 1
        self.ui_edition = tk.LabelFrame(self.canvas, text='Manual edition')
        self.ui_fill_all_btn = tk.Button(self.ui_edition, text='Fill with all')
        self.ui_fill_selected_btn = tk.Button(self.ui_edition,
                                              text='Fill with selection')
        self.ui_fill_defined_btn = tk.Button(self.ui_edition,
                                             text='Fill with defined')
        self.ui_hilite_selected_btn = tk.Button(self.ui_edition,
                                                text='Highlight selected')
        buttons = (self.ui_fill_all_btn, self.ui_fill_selected_btn,
                   self.ui_fill_defined_btn, self.ui_hilite_selected_btn)
        self.auto_pack(self.ui_edition, buttons, padx=5, pady=5, side='left')
        self.ui_edition.grid(row=row,
                             columnspan=3,
                             padx=5,
                             pady=5,
                             sticky='we')

        row += 1
        self.ui_table = t = _SortableTableWithEntries(self.canvas)
        self.ui_table.grid(row=row, padx=5, pady=5, sticky='news')
        kw = dict(anchor='w', refresh=False)
        t.addColumn('Bond', 'bond', format=str, headerPadX=75, **kw)
        t.addColumn('Order',
                    'var_order',
                    format=lambda a: a,
                    headerPadX=5,
                    **kw)
        t.setData([
            _BondTableProxy(bond=b) for b in chimera.selection.currentBonds()
        ])
        t.grid(row=row, column=0, columnspan=3, padx=5, pady=5, sticky='news')
        self.canvas.rowconfigure(row, weight=1)
Exemplo n.º 7
0
class WritePrmtopDialog(SaveModeless):
	keepShown = SaveModeless.default
	name = "write prmtop"
	help = "UsersGuide/savemodel.html#prmtop"

	def __init__(self):
		SaveModeless.__init__(self, clientPos='s', clientSticky='ewns',
			filters=[("Prmtop", "*.prmtop", ".prmtop")])

	def configure(self, model=None, refreshList=True):
		if model:
			self._toplevel.title(
				"Save %s as prmtop File" % model.name)
			if refreshList:
				self.modelMenu.setvalue(model)

	def fillInUI(self, parent):
		import Pmw, Tkinter
		SaveModeless.fillInUI(self, parent)
		row = 0

		from chimera.widgets import MoleculeOptionMenu
		self.modelMenu = MoleculeOptionMenu(self.clientArea,
			labelpos='w', label_text="Save model:",
			command=lambda m: self.configure(
			self.modelMenu.getvalue(), refreshList=False))
		self.modelMenu.grid(row=row, column=0, sticky='w')
		row += 1

		from AddCharge import knownChargeModels, defaultChargeModel

		from chimera import dialogs
		self.parmsetOption = Pmw.OptionMenu(self.clientArea,
			labelpos='w', label_text="Select force field type: ",
			initialitem=defaultChargeModel, items=knownChargeModels)
		# not always shown; remember row number
		self._msmRow = row
		self.parmsetOption.grid(row=row, column=0, sticky='w')
		row += 1

	def Apply(self):
		paths = self.getPaths()
		path = paths[0]
		model = self.modelMenu.getvalue()
		if not model:
			self.enter()
			raise UserError("No model chosen to save.")
			
		from WritePrmtop import writePrmtop
		from AddCharge.gui import checkNoCharges
		chargeModel = self.parmsetOption.getvalue()
		checkNoCharges([model], lambda ur, ua, model=model,
			path=paths[0], parmset=chargeModel[6:]:
			writePrmtop(model, path, parmset, unchargedAtoms=ua),
			"prmtop output", chargeModel=chargeModel)
class Interface(ModelessDialog):

    title = "Fill Gaps with Modeller"

    def __init__(self, *args, **kw):
        ModelessDialog.__init__(self, *args, **kw)
        # TODO: initialize instance variables

    def fillInUI(self, parent):
        from chimera.widgets import MoleculeOptionMenu
        from chimera.tkoptions import IntOption, BooleanOption, \
          InputFileOption, StringOption
        import itertools
        info = Tk.Label(parent,
                        justify=Tk.LEFT,
                        wraplength=300,
                        text="Select a molecule with gaps")
        info.pack(ipadx=2, ipady=2)
        options = Tk.Frame(parent)
        options.columnconfigure(0, pad=2)
        options.columnconfigure(1, pad=2)
        row = itertools.count()
        molRow = row.next()
        text = Tk.Label(options, text="Restrict selections to molecule:")
        text.grid(row=molRow, column=0)
        self.molecules = MoleculeOptionMenu(options,
                                            command=self.updateMolecule)
        self.molecules.grid(row=molRow, column=1, sticky=Tk.W)
        self.turnsOnly = BooleanOption(options, row.next(),
                                       "Skip gaps at ends of chains", False,
                                       None)
        self.hetatms = BooleanOption(options, row.next(),
                                     "Include HETATM residues", False, None)
        #self.waters = BooleanOption(options, row.next(),
        #		"Include waters", False, None)
        self.nucleic = BooleanOption(options, row.next(),
                                     "Include nucleic acids", False, None)
        self.nucleic.disable()
        hr = Tk.Frame(options, relief=Tk.GROOVE, borderwidth=1, height=2)
        hr.grid(row=row.next(), columnspan=2, sticky='ew')
        # modeller location
        self.modeller = InputFileOption(options, row.next(),
                                        "Modeller location", "mod8v2", None)
        # temporary prefix -- TODO: add unique id
        #self.tempdir = StringOption(options, row.next(),
        #		"Temporary file prefix", "modtmp", None)
        options.pack()

    def updateMolecule(self, *args, **kw):
        print 'updateMolecule', args, kw
        # TODO: look for gaps

    def Apply(self):
        from chimera import selection
        molecule = [self.molecules.getvalue()]
Exemplo n.º 9
0
	def fillInUI(self, parent):
		from chimera.widgets import MoleculeOptionMenu
		from chimera.tkoptions import IntOption, BooleanOption, \
				InputFileOption, StringOption, EnumOption
		import itertools
		info = Tk.Label(parent, justify=Tk.LEFT, wraplength=300, text=
				"Model alternate conformations of loops using "
				"Modeller from <http://salilab.org/>.\n"
				"First select the loops you wish to model."
				"  Then choose the number of models "
				"you wish to generate.")
		info.pack(ipadx=2, ipady=2)
		options = Tk.Frame(parent)
		options.columnconfigure(0, pad=2)
		options.columnconfigure(1, pad=2)
		row = itertools.count()
		molRow = row.next()
		text = Tk.Label(options,
				text="Restrict selections to molecule:")
		text.grid(row=molRow, column=0)
		self.molecules = MoleculeOptionMenu(options)
		self.molecules.grid(row=molRow, column=1, sticky=Tk.W)
		self.turnsOnly = BooleanOption(options, row.next(),
				"Restrict selections to turns", True, None)
		self.hetatms = BooleanOption(options, row.next(),
				"Include HETATM residues", False, None)
		self.waters = BooleanOption(options, row.next(),
				"Include waters", False, None)
		self.waters.disable()
		self.nucleic = BooleanOption(options, row.next(),
				"Include nucleic acids", False, None)
		self.nucleic.disable()
		self.count = IntOption(options, row.next(), "Number of models",
				10, None, min=1, sticky=Tk.W)
		#self.start = IntOption(options, row.next(),
		#		"Starting model number", 1, None, min=0)
		class Refinement(EnumOption):
			values = ('very fast', 'fast', 'slow', 'very slow',
				'slow large', 'none')
		self.refine = Refinement(options, row.next(), "Refinement",
								'fast', None)
		button = Tk.Button(options, text="Prune selection",
				command=self.prune)
		button.grid(row=row.next(), column=0, columnspan=2, pady=2)
		self.start = 1
		hr = Tk.Frame(options, relief=Tk.GROOVE, borderwidth=1, height=2)
		hr.grid(row=row.next(), columnspan=2, sticky='ew')
		# modeller location
		self.modeller = InputFileOption(options, row.next(),
				"Modeller location", "mod9v2", None)
		# temporary prefix -- TODO: add unique id
		#self.tempdir = StringOption(options, row.next(),
		#		"Temporary file prefix", "modtmp", None)
		options.pack()
Exemplo n.º 10
0
    def fillInUI(self, parent):

        self.toplevel_widget = parent.winfo_toplevel()
        self.toplevel_widget.withdraw()

        parent.columnconfigure(0, weight=1)  # Allow scalebar to expand.

        row = 0

        import Tkinter
        from CGLtk import Hybrid

        from chimera.widgets import MoleculeOptionMenu
        mm = MoleculeOptionMenu(parent,
                                labelpos='w',
                                label_text='Molecule ',
                                command=self.show_cumulative_transform)
        mm.grid(row=row, column=0, sticky='w')
        self.molecule_menu = mm
        row = row + 1

        ea = Hybrid.Entry(parent, 'Euler angles ', 25, '0 0 0')
        ea.frame.grid(row=row, column=0, sticky='e')
        row = row + 1
        self.euler_angles = ea.variable

        tr = Hybrid.Entry(parent, 'Shift ', 25, '0 0 0')
        tr.frame.grid(row=row, column=0, sticky='e')
        row = row + 1
        self.translation = tr.variable

        cas = Tkinter.Label(parent, text='', justify='left')
        cas.grid(row=row, column=0, sticky='w')
        self.cumulative = cas
        row = row + 1

        el = Tkinter.Label(
            parent,
            text=
            'Apply rotation and translation to atom coordinates\n using the molecule coordinate system.',
            justify='left')
        el.grid(row=row, column=0, sticky='w')
        row = row + 1

        self.show_cumulative_transform(None)
Exemplo n.º 11
0
	def fillInUI(self, parent):
		from chimera.widgets import MoleculeScrolledListBox
		self.molListBox = MoleculeScrolledListBox(parent,
			listbox_selectmode='extended', labelpos='w',
			label_text="Molecules to combine/copy:")
		if self.initModels:
			self.molListBox.setvalue(self.initModels)
		self.molListBox.grid(row=0, column=0, columnspan=2,
							sticky="nsew")
		parent.rowconfigure(0, weight=1)
		parent.columnconfigure(1, weight=1)
		from chimera.tkoptions import StringOption, IntOption
		self.molNameEntry = StringOption(parent, 1, "New model's"
						" name", "combination", None)

		curIDs = set([i1 for i1, i2 in openModels.listIds()])
		mid = 0
		while mid in curIDs:
			mid += 1
		self.modelID = IntOption(parent, 2, "New model's ID", mid, None)

		from chimera.widgets import MoleculeOptionMenu
		self.refMolMenu = MoleculeOptionMenu(parent, labelpos='w',
			label_text="Coordinate system of:",
			initialitem=self.initModels[0])
		self.refMolMenu.grid(row=3, column=0, columnspan=2, sticky='w')

		import Pmw
		chb = self.chainHandlingButtons = Pmw.RadioSelect(parent,
			buttontype="radiobutton", labelpos='w',
			label_text="If original molecules have duplicate\n"
			"single-letter chain IDs, then:", orient="vertical")
		self.buttonTexts = ["rename them uniquely",
				"retain them (residues may be renumbered)"]
		for bt in self.buttonTexts:
			chb.add(bt)
		chb.setvalue(self.buttonTexts[0])
		chb.grid(row=4, column=0, columnspan=2)

		import Tkinter
		self.closeModelsVar = Tkinter.IntVar(parent)
		self.closeModelsVar.set(False)
		Tkinter.Checkbutton(parent, text="Close source models",
					variable=self.closeModelsVar).grid(
					row=5, column=0, columnspan=2)
Exemplo n.º 12
0
  def fillInUI(self, parent):

    self.toplevel_widget = parent.winfo_toplevel()
    self.toplevel_widget.withdraw()

    parent.columnconfigure(0, weight=1)         # Allow scalebar to expand.
    
    row = 0

    import Tkinter
    from CGLtk import Hybrid

    from chimera.widgets import MoleculeOptionMenu
    mm = MoleculeOptionMenu(parent, labelpos = 'w', label_text = 'Molecule ',
                            command = self.show_cumulative_transform)
    mm.grid(row = row, column = 0, sticky = 'w')
    self.molecule_menu = mm
    row = row + 1

    ea = Hybrid.Entry(parent, 'Euler angles ', 25, '0 0 0')
    ea.frame.grid(row = row, column = 0, sticky = 'e')
    row = row + 1
    self.euler_angles = ea.variable

    tr = Hybrid.Entry(parent, 'Shift ', 25, '0 0 0')
    tr.frame.grid(row = row, column = 0, sticky = 'e')
    row = row + 1
    self.translation = tr.variable

    cas = Tkinter.Label(parent, text = '', justify = 'left')
    cas.grid(row = row, column = 0, sticky = 'w')
    self.cumulative = cas
    row = row + 1

    el = Tkinter.Label(parent, text = 'Apply rotation and translation to atom coordinates\n using the molecule coordinate system.', justify = 'left')
    el.grid(row = row, column = 0, sticky = 'w')
    row = row + 1

    self.show_cumulative_transform(None)
Exemplo n.º 13
0
	def fillInUI(self, parent):
		import Pmw, Tkinter
		SaveModeless.fillInUI(self, parent)
		row = 0

		from chimera.widgets import MoleculeOptionMenu
		self.modelMenu = MoleculeOptionMenu(self.clientArea,
			labelpos='w', label_text="Save model:",
			command=lambda m: self.configure(
			self.modelMenu.getvalue(), refreshList=False))
		self.modelMenu.grid(row=row, column=0, sticky='w')
		row += 1

		from AddCharge import knownChargeModels, defaultChargeModel

		from chimera import dialogs
		self.parmsetOption = Pmw.OptionMenu(self.clientArea,
			labelpos='w', label_text="Select force field type: ",
			initialitem=defaultChargeModel, items=knownChargeModels)
		# not always shown; remember row number
		self._msmRow = row
		self.parmsetOption.grid(row=row, column=0, sticky='w')
		row += 1
Exemplo n.º 14
0
    def fill_in_ui(self, *args):
        self.canvas.columnconfigure(0, weight=1)

        row = 1
        self.ui_molecule = MoleculeOptionMenu(self.canvas,
                                              command=self.populate_table)
        self.ui_molecule.grid(row=row, padx=5, pady=5, sticky='we')
        row += 1
        self.ui_toolbar_frame = tk.LabelFrame(
            self.canvas, text='Configure selected entries')
        self.ui_toolbar_frame.grid(row=row, padx=5, pady=5, sticky='we')
        self.ui_select_all = tk.Button(self.canvas,
                                       text='All',
                                       command=self._cb_select_all)
        self.ui_select_none = tk.Button(self.canvas,
                                        text='None',
                                        command=self._cb_select_none)
        self.ui_select_invert = tk.Button(self.canvas,
                                          text='Invert',
                                          command=self._cb_select_invert)
        self.ui_select_selection = tk.Button(self.canvas,
                                             text='Current',
                                             command=self._cb_select_selection)
        self.ui_batch_layer_entry = Pmw.OptionMenu(self.canvas,
                                                   labelpos='w',
                                                   label_text='ONIOM Layer:',
                                                   items=['', 'H', 'M', 'L'])
        self.ui_batch_layer_btn = tk.Button(self.canvas,
                                            text='Set',
                                            command=self._cb_batch_layer_btn)
        self.ui_batch_frozen_entry = Pmw.OptionMenu(self.canvas,
                                                    labelpos='w',
                                                    label_text='Freeze state:',
                                                    items=['Yes', 'No'])
        self.ui_batch_frozen_btn = tk.Button(self.canvas,
                                             text='Set',
                                             command=self._cb_batch_freeze_btn)
        toolbar = [[
            self.ui_select_all, self.ui_select_none, self.ui_batch_layer_entry,
            self.ui_batch_layer_btn
        ],
                   [
                       self.ui_select_invert, self.ui_select_selection,
                       self.ui_batch_frozen_entry, self.ui_batch_frozen_btn
                   ]]
        self.auto_grid(self.ui_toolbar_frame,
                       toolbar,
                       padx=3,
                       pady=3,
                       sticky='we')

        row += 1
        self.canvas.rowconfigure(row, weight=1)
        self.ui_table = t = _SortableTableWithEntries(self.canvas)
        self.ui_table.grid(row=row, padx=5, pady=5, sticky='news')
        kw = dict(anchor='w', refresh=False)
        t.addColumn('#', 'serial', format="%d", headerPadX=5, **kw)
        t.addColumn('Atom', 'atom', format=str, headerPadX=50, **kw)
        t.addColumn('Element', 'element', headerPadX=5, **kw)
        t.addColumn('Type', 'idatmtype', format=str, headerPadX=5, **kw)
        t.addColumn('Layer',
                    'var_layer',
                    format=lambda a: a,
                    headerPadX=5,
                    **kw)
        t.addColumn('Freeze',
                    'var_frozen',
                    format=lambda a: a,
                    headerPadX=5,
                    **kw)
        if self.ui_molecule.getvalue():
            self.ui_molecule.invoke()
        else:
            t.setData([])
        t.launch()
Exemplo n.º 15
0
class CombineDialog(ModelessDialog):
	title = "Copy/Combine Molecular Models"
	help = "UsersGuide/modelpanel.html#combine"

	def __init__(self, models=None):
		self.initModels = models
		ModelessDialog.__init__(self)

	def fillInUI(self, parent):
		from chimera.widgets import MoleculeScrolledListBox
		self.molListBox = MoleculeScrolledListBox(parent,
			listbox_selectmode='extended', labelpos='w',
			label_text="Molecules to combine/copy:")
		if self.initModels:
			self.molListBox.setvalue(self.initModels)
		self.molListBox.grid(row=0, column=0, columnspan=2,
							sticky="nsew")
		parent.rowconfigure(0, weight=1)
		parent.columnconfigure(1, weight=1)
		from chimera.tkoptions import StringOption, IntOption
		self.molNameEntry = StringOption(parent, 1, "New model's"
						" name", "combination", None)

		curIDs = set([i1 for i1, i2 in openModels.listIds()])
		mid = 0
		while mid in curIDs:
			mid += 1
		self.modelID = IntOption(parent, 2, "New model's ID", mid, None)

		from chimera.widgets import MoleculeOptionMenu
		self.refMolMenu = MoleculeOptionMenu(parent, labelpos='w',
			label_text="Coordinate system of:",
			initialitem=self.initModels[0])
		self.refMolMenu.grid(row=3, column=0, columnspan=2, sticky='w')

		import Pmw
		chb = self.chainHandlingButtons = Pmw.RadioSelect(parent,
			buttontype="radiobutton", labelpos='w',
			label_text="If original molecules have duplicate\n"
			"single-letter chain IDs, then:", orient="vertical")
		self.buttonTexts = ["rename them uniquely",
				"retain them (residues may be renumbered)"]
		for bt in self.buttonTexts:
			chb.add(bt)
		chb.setvalue(self.buttonTexts[0])
		chb.grid(row=4, column=0, columnspan=2)

		import Tkinter
		self.closeModelsVar = Tkinter.IntVar(parent)
		self.closeModelsVar.set(False)
		Tkinter.Checkbutton(parent, text="Close source models",
					variable=self.closeModelsVar).grid(
					row=5, column=0, columnspan=2)
			

	def Apply(self):
		mols = self.molListBox.getvalue()
		from chimera import UserError
		if not mols:
			self.enter()
			raise UserError("Must specify at least one molecular"
				" model to combine/copy")
		from chimera import suppressNewMoleculeProcessing, \
						restoreNewMoleculeProcessing
		suppressNewMoleculeProcessing()
		newChainIDs = (self.chainHandlingButtons.getvalue()
						== self.buttonTexts[0])
		refMol = self.refMolMenu.getvalue()
		from Combine import combine, CombineError
		try:
			m = combine(mols, refMol,
					newChainIDs=newChainIDs, log=True)
		except CombineError, v:
			restoreNewMoleculeProcessing()
			self.enter()
			raise UserError(v)
		m.name = self.molNameEntry.get()
		openModels.add([m], baseId=self.modelID.get(), shareXform=False)
		m.openState.xform = refMol.openState.xform
		restoreNewMoleculeProcessing()

		if self.closeModelsVar.get():
			openModels.close(mols)
Exemplo n.º 16
0
class Vol_Cut_Dialog(ModelessDialog):

  title = 'Volume_Cut'
  name = 'Volume_Cut'
  buttons = ('Cut Volume', 'Close',)
  help = 'https://github.com/nissensonm/VolumeCut/'

    
# -----------------------------------------------------------------------------
#
  def fillInUI(self, parent):
    self.toplevel_widget = parent.winfo_toplevel()
    self.toplevel_widget.withdraw()
	
    parent.columnconfigure(0, weight = 1)

    from CGLtk import Hybrid
    import Pmw, Tkinter
	
    from chimera.widgets import MoleculeOptionMenu
    self.molMenu = MoleculeOptionMenu(parent, labelpos="w",
						label_text="Select PDB:")
    self.molMenu.grid(row = 1, column = 0, sticky = 'w')

    from chimera.widgets import MoleculeChainOptionMenu 
    self.chainMenu = MoleculeChainOptionMenu(parent, labelpos="w",
	                    label_text="Select Chain:")
    self.chainMenu.grid(row = 2, column = 0, sticky = 'w')
	
	
    from chimera.widgets import ModelOptionMenu 
    self.modelMenu = ModelOptionMenu(parent, labelpos="w",
	                    label_text="Select MRC:")
    self.modelMenu.grid(row = 3, column = 0, sticky = 'w')
	
    import Pmw
    self.radius = Pmw.EntryField(parent, labelpos="w",
                        label_text="Radius:")
    self.radius.grid(row = 4, column = 0, sticky = 'w')
	
    self.resolution = Pmw.EntryField(parent, labelpos="w",
                        label_text="Resolution:")
    self.resolution.grid(row = 5, column = 0, sticky = 'w')
	
# -----------------------------------------------------------------------------
#
  def CutVolume(self):
    #print ' mode: ' + str(self.mode.get()) 
    import VolCut as vc


    if self.molMenu.getvalue() is None or self.modelMenu.getvalue() is None \
                or self.chainMenu.getvalue() is None:
      warnings.warn('Must load valid PDB, MRC, or select a chain.')
      return
	  
    if type(self.modelMenu.getvalue()) is not VolumeViewer.volume.Volume:
      warnings.warn('Must select a valid MRC for the mrc')
      return
    
    try:
      float(self.radius.getvalue())
    except ValueError:
      warnings.warn('Radius must be a valid float value')
      return
	
    try:
      float(self.resolution.getvalue())
    except ValueError:
      warnings.warn('Resolution must be a valid float value')
      return
	
    vc.cutvol(self.molMenu.getvalue().id, self.modelMenu.getvalue().id, \
                float(self.radius.getvalue()), \
                float(self.resolution.getvalue()), \
                self.chainMenu.getvalue().chain)
Exemplo n.º 17
0
class WritePrmtopDialog(SaveModeless):
    keepShown = SaveModeless.default
    name = "write prmtop"
    help = "UsersGuide/savemodel.html#prmtop"

    def __init__(self):
        SaveModeless.__init__(self,
                              clientPos='s',
                              clientSticky='ewns',
                              filters=[("Prmtop", "*.prmtop", ".prmtop")])

    def configure(self, model=None, refreshList=True):
        if model:
            self._toplevel.title("Save %s as prmtop File" % model.name)
            if refreshList:
                self.modelMenu.setvalue(model)

    def fillInUI(self, parent):
        import Pmw, Tkinter
        SaveModeless.fillInUI(self, parent)
        row = 0

        from chimera.widgets import MoleculeOptionMenu
        self.modelMenu = MoleculeOptionMenu(
            self.clientArea,
            labelpos='w',
            label_text="Save model:",
            command=lambda m: self.configure(self.modelMenu.getvalue(),
                                             refreshList=False))
        self.modelMenu.grid(row=row, column=0, sticky='w')
        row += 1

        from AddCharge import knownChargeModels, defaultChargeModel

        from chimera import dialogs
        self.parmsetOption = Pmw.OptionMenu(
            self.clientArea,
            labelpos='w',
            label_text="Select force field type: ",
            initialitem=defaultChargeModel,
            items=knownChargeModels)
        # not always shown; remember row number
        self._msmRow = row
        self.parmsetOption.grid(row=row, column=0, sticky='w')
        row += 1

    def Apply(self):
        paths = self.getPaths()
        path = paths[0]
        model = self.modelMenu.getvalue()
        if not model:
            self.enter()
            raise UserError("No model chosen to save.")

        from WritePrmtop import writePrmtop
        from AddCharge.gui import checkNoCharges
        chargeModel = self.parmsetOption.getvalue()
        checkNoCharges(
            [model],
            lambda ur, ua, model=model, path=paths[0], parmset=chargeModel[
                6:]: writePrmtop(model, path, parmset, unchargedAtoms=ua),
            "prmtop output",
            chargeModel=chargeModel)
Exemplo n.º 18
0
class Interface(ModelessDialog):

	title = "Model Loops with Modeller"
	buttons = ("OK", "Cancel")
	help = "ContributedSoftware/model/model.html"

	def __init__(self, *args, **kw):
		ModelessDialog.__init__(self, *args, **kw)
		# TODO: initialize instance variables

	def fillInUI(self, parent):
		from chimera.widgets import MoleculeOptionMenu
		from chimera.tkoptions import IntOption, BooleanOption, \
				InputFileOption, StringOption, EnumOption
		import itertools
		info = Tk.Label(parent, justify=Tk.LEFT, wraplength=300, text=
				"Model alternate conformations of loops using "
				"Modeller from <http://salilab.org/>.\n"
				"First select the loops you wish to model."
				"  Then choose the number of models "
				"you wish to generate.")
		info.pack(ipadx=2, ipady=2)
		options = Tk.Frame(parent)
		options.columnconfigure(0, pad=2)
		options.columnconfigure(1, pad=2)
		row = itertools.count()
		molRow = row.next()
		text = Tk.Label(options,
				text="Restrict selections to molecule:")
		text.grid(row=molRow, column=0)
		self.molecules = MoleculeOptionMenu(options)
		self.molecules.grid(row=molRow, column=1, sticky=Tk.W)
		self.turnsOnly = BooleanOption(options, row.next(),
				"Restrict selections to turns", True, None)
		self.hetatms = BooleanOption(options, row.next(),
				"Include HETATM residues", False, None)
		self.waters = BooleanOption(options, row.next(),
				"Include waters", False, None)
		self.waters.disable()
		self.nucleic = BooleanOption(options, row.next(),
				"Include nucleic acids", False, None)
		self.nucleic.disable()
		self.count = IntOption(options, row.next(), "Number of models",
				10, None, min=1, sticky=Tk.W)
		#self.start = IntOption(options, row.next(),
		#		"Starting model number", 1, None, min=0)
		class Refinement(EnumOption):
			values = ('very fast', 'fast', 'slow', 'very slow',
				'slow large', 'none')
		self.refine = Refinement(options, row.next(), "Refinement",
								'fast', None)
		button = Tk.Button(options, text="Prune selection",
				command=self.prune)
		button.grid(row=row.next(), column=0, columnspan=2, pady=2)
		self.start = 1
		hr = Tk.Frame(options, relief=Tk.GROOVE, borderwidth=1, height=2)
		hr.grid(row=row.next(), columnspan=2, sticky='ew')
		# modeller location
		self.modeller = InputFileOption(options, row.next(),
				"Modeller location", "mod9v2", None)
		# temporary prefix -- TODO: add unique id
		#self.tempdir = StringOption(options, row.next(),
		#		"Temporary file prefix", "modtmp", None)
		options.pack()

	def prune(self):
		from chimera import selection
		molecule = self.molecules.getvalue()
		import ModUtil
		pairs, residues = ModUtil.convertSelection(
				selection._currentSelection,
				minLen=4, molecule=molecule,
				keepHet=self.hetatms.get(),
				keepNA=self.nucleic.get(),
				turnsOnly=self.turnsOnly.get())
		sel = selection.ItemizedSelection()
		sel.add(residues)
		sel.addImplied()
		selection.mergeCurrent(selection.INTERSECT, sel)
		return pairs, residues

	def Apply(self):
		pairs, residues = self.prune()
		if not pairs:
			from chimera import replyobj
			replyobj.status("no residues meet loop modelling criteria")
			return

		# create a temporary directory to work in
		import tempfile
		tempdir = tempfile.mkdtemp(prefix="modeller")
		print 'Modeller temporary directory:', tempdir

		# write PDB file with original coordinates
		import os
		fname = os.path.join(tempdir, 'original.pdb')
		molecule = self.molecules.getvalue()
		xform = molecule.openState.xform
		xform.invert()	# want original coordinates
		chimera.viewer.pdbWrite([molecule], xform, fname)
		# write out Modeller input file
		count = self.count.get()
		refine = self.refine.get()
		fname = os.path.join(tempdir, "loopopt.py")
		f = file(fname, 'w')
		writeModeller(f, 'original.pdb', 'loop', pairs, count, refine)
		f.close()

		#  run Modeller -- put up progress dialog
		import ModUtil
		def cb(process, dirname=tempdir, count=count):
			return loopFileCount(dirname, count)
		try:
			prog = self.modeller.get()
			p = ModUtil.run([prog, "loopopt.py"], cb, cwd=tempdir)
		except OSError, e:
			from chimera import replyobj
			replyobj.error("Unable to run modeller: %s\n" % e)
			return

		# Do concurrent work here

		# find atoms that are connected to the residues we will model
		atoms = set()
		for r in residues:
			for a in r.atoms:
				atoms.add(a)
		outsideAtoms = set()
		for a in atoms:
			for b in a.bonds:
				oa = b.otherAtom(a)
				if oa.residue not in residues:
					outsideAtoms.add(oa)
		outsideAtoms = [(a.residue.id, a.name) for a in outsideAtoms]

		residueIds = set([r.id for r in residues])

		# TODO: use triggers to monitor process
		# and then startup dock interface
		# For now, we just wait
		returncode = p.wait()
		if returncode != 0:
			from chimera import replyobj
			replyobj.error("Modeller failed\n")
			return

		# create ViewDock input file from output files
		path = makedock(tempdir, residueIds, outsideAtoms)
		if not path:
			from chimera import replyobj
			replyobj.error("No models were generated\n")
			return

		# undisplay selected residues
		for r in residues:
			for a in r.atoms:
				a.display = False

		# startup dock
		import ViewDock
		v = ViewDock.ViewDock(path, 'Modeller')

		# remove long bonds since makedock can't put TERs
		# from both the model and the "longbond" PseudoBondGroup
		models = [c.chimeraModel for c in v.results.compoundList]
		length = 3
		sqLen = length * length
		for m in models:
			for b in m.bonds:
				if b.sqlength() >= sqLen:
					# get rid of longbond PseudoBonds
					a0, a1 = b.atoms
					pbs = a0.associations(
						chimera.LONGBOND_PBG_NAME, a1)
					for pb in pbs:
						pb.pseudoBondGroup.deletePseudoBond(pb)
					# get rid of bond
					m.deleteBond(b)
Exemplo n.º 19
0
class BondOrderDialog(TangramBaseDialog):

    buttons = ('Draw', 'Close')
    default = None
    help = "https://github.com/insilichem/tangram_bondorder"
    VERSION = '0.0.1'
    VERSION_URL = "https://api.github.com/repos/insilichem/tangram_bondorder/releases/latest"

    def __init__(self, *args, **kwargs):
        # GUI init
        self.title = 'Tangram BondOrder'
        self.controller = None

        # Fire up
        super(BondOrderDialog, self).__init__(resizable=False, *args, **kwargs)

        # Triggers
        chimera.triggers.addHandler('selection changed',
                                    self._cmd_hilite_selected, None)

    def fill_in_ui(self, parent):
        self.canvas.columnconfigure(0, weight=1)
        row = 0
        self.ui_calculation = tk.LabelFrame(self.canvas,
                                            text='Perceive bond order')
        self.ui_molecule = MoleculeOptionMenu(self.ui_calculation,
                                              labelpos='w',
                                              label_text='Analyze')
        self.ui_methods = Pmw.OptionMenu(
            self.ui_calculation,
            label_text='with',
            labelpos='w',
            items=['RDKit', 'OpenBabel', 'Single'])
        self.ui_calculate_btn = tk.Button(self.ui_calculation,
                                          text='Go!',
                                          command=self._cmd_calculate_btn)
        self.ui_calculation.grid(row=row, padx=5, pady=5, sticky='we')
        self.ui_calculation.columnconfigure(0, weight=1)
        self.ui_molecule.grid(row=0, column=0, padx=5, pady=5, sticky='we')
        self.ui_methods.grid(row=0, column=1, padx=5, pady=5)
        self.ui_calculate_btn.grid(row=0, column=2, padx=5, pady=5)

        row += 1
        self.ui_edition = tk.LabelFrame(self.canvas, text='Manual edition')
        self.ui_fill_all_btn = tk.Button(self.ui_edition, text='Fill with all')
        self.ui_fill_selected_btn = tk.Button(self.ui_edition,
                                              text='Fill with selection')
        self.ui_fill_defined_btn = tk.Button(self.ui_edition,
                                             text='Fill with defined')
        self.ui_hilite_selected_btn = tk.Button(self.ui_edition,
                                                text='Highlight selected')
        buttons = (self.ui_fill_all_btn, self.ui_fill_selected_btn,
                   self.ui_fill_defined_btn, self.ui_hilite_selected_btn)
        self.auto_pack(self.ui_edition, buttons, padx=5, pady=5, side='left')
        self.ui_edition.grid(row=row,
                             columnspan=3,
                             padx=5,
                             pady=5,
                             sticky='we')

        row += 1
        self.ui_table = t = _SortableTableWithEntries(self.canvas)
        self.ui_table.grid(row=row, padx=5, pady=5, sticky='news')
        kw = dict(anchor='w', refresh=False)
        t.addColumn('Bond', 'bond', format=str, headerPadX=75, **kw)
        t.addColumn('Order',
                    'var_order',
                    format=lambda a: a,
                    headerPadX=5,
                    **kw)
        t.setData([
            _BondTableProxy(bond=b) for b in chimera.selection.currentBonds()
        ])
        t.grid(row=row, column=0, columnspan=3, padx=5, pady=5, sticky='news')
        self.canvas.rowconfigure(row, weight=1)

    def Draw(self):
        m = self.ui_molecule.getvalue()
        draw_bond_orders(m)

    def Close(self):  # Singleton mode
        global ui
        ui = None
        super(BondOrderDialog, self).Close()

    def _cmd_calculate_btn(self, *args):
        molecule = self.ui_molecule.getvalue()
        engine = self.ui_methods.getvalue()
        try:
            assign_bond_orders(molecule, engine=engine.lower())
        except Exception as e:
            self.status('Could not compute automatically!',
                        color='red',
                        blankAfter=4)
        else:
            self.Draw()

    def _cmd_fill_all(self, *args):
        pass

    def _cmd_fill_selected(self, *args):
        pass

    def _cmd_fill_defined(self, *args):
        pass

    def _cmd_hilite_selected(self, *args):
        pass
Exemplo n.º 20
0
class ONIOMLayersDialog(TangramBaseDialog):
    """
    Define ONIOM Layers on a per-atom basis
    """

    buttons = ('OK', 'Close')

    def __init__(self, saved_layers=None, *args, **kwargs):
        # Fire up
        self.title = 'Define ONIOM layers'
        self.atoms2rows = {}
        self.layers = saved_layers
        super(ONIOMLayersDialog, self).__init__(with_logo=False,
                                                *args,
                                                **kwargs)
        if saved_layers:
            self.restore_dialog(saved_layers['molecule'],
                                saved_layers['atoms'])

    def fill_in_ui(self, *args):
        self.canvas.columnconfigure(0, weight=1)

        row = 1
        self.ui_molecule = MoleculeOptionMenu(self.canvas,
                                              command=self.populate_table)
        self.ui_molecule.grid(row=row, padx=5, pady=5, sticky='we')
        row += 1
        self.ui_toolbar_frame = tk.LabelFrame(
            self.canvas, text='Configure selected entries')
        self.ui_toolbar_frame.grid(row=row, padx=5, pady=5, sticky='we')
        self.ui_select_all = tk.Button(self.canvas,
                                       text='All',
                                       command=self._cb_select_all)
        self.ui_select_none = tk.Button(self.canvas,
                                        text='None',
                                        command=self._cb_select_none)
        self.ui_select_invert = tk.Button(self.canvas,
                                          text='Invert',
                                          command=self._cb_select_invert)
        self.ui_select_selection = tk.Button(self.canvas,
                                             text='Current',
                                             command=self._cb_select_selection)
        self.ui_batch_layer_entry = Pmw.OptionMenu(self.canvas,
                                                   labelpos='w',
                                                   label_text='ONIOM Layer:',
                                                   items=['', 'H', 'M', 'L'])
        self.ui_batch_layer_btn = tk.Button(self.canvas,
                                            text='Set',
                                            command=self._cb_batch_layer_btn)
        self.ui_batch_frozen_entry = Pmw.OptionMenu(self.canvas,
                                                    labelpos='w',
                                                    label_text='Freeze state:',
                                                    items=['Yes', 'No'])
        self.ui_batch_frozen_btn = tk.Button(self.canvas,
                                             text='Set',
                                             command=self._cb_batch_freeze_btn)
        toolbar = [[
            self.ui_select_all, self.ui_select_none, self.ui_batch_layer_entry,
            self.ui_batch_layer_btn
        ],
                   [
                       self.ui_select_invert, self.ui_select_selection,
                       self.ui_batch_frozen_entry, self.ui_batch_frozen_btn
                   ]]
        self.auto_grid(self.ui_toolbar_frame,
                       toolbar,
                       padx=3,
                       pady=3,
                       sticky='we')

        row += 1
        self.canvas.rowconfigure(row, weight=1)
        self.ui_table = t = _SortableTableWithEntries(self.canvas)
        self.ui_table.grid(row=row, padx=5, pady=5, sticky='news')
        kw = dict(anchor='w', refresh=False)
        t.addColumn('#', 'serial', format="%d", headerPadX=5, **kw)
        t.addColumn('Atom', 'atom', format=str, headerPadX=50, **kw)
        t.addColumn('Element', 'element', headerPadX=5, **kw)
        t.addColumn('Type', 'idatmtype', format=str, headerPadX=5, **kw)
        t.addColumn('Layer',
                    'var_layer',
                    format=lambda a: a,
                    headerPadX=5,
                    **kw)
        t.addColumn('Freeze',
                    'var_frozen',
                    format=lambda a: a,
                    headerPadX=5,
                    **kw)
        if self.ui_molecule.getvalue():
            self.ui_molecule.invoke()
        else:
            t.setData([])
        t.launch()

    def populate_table(self, molecule):
        atoms = molecule.atoms
        data = []
        mapping = self.atoms2rows[molecule] = {}
        for atom in atoms:
            kwargs = dict(atom=atom,
                          element=atom.element.name,
                          idatmtype=atom.idatmType,
                          serial=atom.serialNumber)
            mapping[atom] = row = _AtomTableProxy(**kwargs)
            data.append(row)
        self.ui_table.setData(data)
        self.canvas.after(100, self.ui_table.requestFullWidth)

    def restore_dialog(self, molecule, rows):
        self.ui_molecule_dropdown.set(molecule)
        for atom, layer in rows:
            row = self.atoms2rows[atom]
            row.layer = layer
        self.ui_table.refresh()

    def export_dialog(self):
        molecule = self.ui_molecule.getvalue()
        rows = [(row.atom, (row.layer, row.frozen))
                for row in self.ui_table.data]
        return molecule, rows

    def _cb_batch_layer_btn(self, *args, **kwargs):
        layer = self.ui_batch_layer_entry.getvalue()
        selected = self.ui_table.selected()
        for row in selected:
            row.layer = layer
        self.status('Applied layer {} to {} rows'.format(layer, len(selected)),
                    color='blue',
                    blankAfter=3)

    def _cb_batch_freeze_btn(self, *args, **kwargs):
        frozen = self.ui_batch_frozen_entry.getvalue()
        selected = self.ui_table.selected()
        for row in selected:
            row.frozen = frozen
        self.status('Applied freeze code {} to {} rows'.format(
            frozen, len(selected)),
                    color='blue',
                    blankAfter=3)

    def _cb_select_all(self, *args, **kwargs):
        hlist = self.ui_table.tixTable.hlist
        nrows = int(hlist.info_children()[-1])
        for row in xrange(nrows + 1):
            hlist.selection_set(row)

    def _cb_select_none(self, *args, **kwargs):
        self.ui_table.tixTable.hlist.selection_clear()

    def _cb_select_invert(self, *args, **kwargs):
        hlist = self.ui_table.tixTable.hlist
        selected = set(hlist.info_selection())
        all_entries = set(hlist.info_children())
        self._cb_select_none()
        for row in selected ^ all_entries:
            hlist.selection_set(row)

    def _cb_select_selection(self, *args, **kwargs):
        self._cb_select_none()
        rows = [
            self.atoms2rows.get(atom.molecule, {}).get(atom)
            for atom in chimera.selection.currentAtoms()
        ]
        self.ui_table.select(rows)

    def OK(self, *args, **kwargs):
        self.layers.clear()
        molecule, rows = self.export_dialog()
        for i, (atom, (layer, frozen)) in enumerate(rows):
            if not layer:
                not_filledin = len([1 for row in rows[i + 1:] if not row[1]])
                raise UserError('Atom {} {} no layer defined!'.format(
                    atom, 'and {} atoms more have'.format(not_filledin)
                    if not_filledin else 'has'))
            self.layers[atom] = (layer, frozen)
        self.Close()