def select_zone(): from chimera import dialogs, ZoneDialog, tkgui d = dialogs.find(ZoneDialog.ZoneDialog.name) if d == None: d = dialogs.find(ZoneDialog.ZoneDialog.name, create=True) d.Close() tkgui.finishZone(d)
def restore2DLabelDialog(info): from chimera.dialogs import find from Ilabel.gui import IlabelDialog dlg = find(IlabelDialog.name) if dlg is not None: dlg.destroy() dlg = find(IlabelDialog.name, create=True) dlg._restoreSession(info)
def clip_dialog(): from chimera import dialogs import ModelClip cd = dialogs.find(ModelClip.ClipDialog.name) if cd is None: cd = dialogs.find(ModelClip.ClipDialog.name, create=True) cd.Close() return cd
def clip_selected_models(): 'Toggle per-model clipping for selected models' from chimera import selection, openModels mlist = [m for m in selection.currentGraphs() if m.display] if len(mlist) == 0: mlist = [m for m in openModels.list() if m.display and m.useClipPlane] if len(mlist) == 0: mlist = [m for m in openModels.list() if m.display] if len(mlist) == 0: return from chimera import tkgui for m in mlist: if m.useClipPlane: m.useClipPlane = False elif m.bbox()[0]: tkgui.setClipModel(m) # Set initial clip plane placement. # Turn off clip adjust mouse mode. cm = tkgui.getClipModel() if cm is None or not cm.useClipPlane: from chimera import dialogs import ModelClip cd = dialogs.find(ModelClip.ClipDialog.name) if cd: cd.stopMouseClip()
def show_side_view(): 'Show side view dialog' from chimera import dialogs from chimera import viewing dialogs.display(viewing.ViewerDialog.name) d = dialogs.find(viewing.ViewerDialog.name, create=1) d.nb.raise_page('pSideView')
def initiateAddHyd(models, cancelCB=None, okCB=None, hisScheme=None, addFunc=AddH.hbondAddHydrogens): """Request the addition of hydrogens to the given models. If all atoms in the models have known hydrogen-adding geometries, the hydrogens are added immediately. Otherwise, a dialog is started to request the missing information from the user. Once the user 'Ok's the information-gathering dialog, the hydrogens are added. The dialog can instead be cancelled, in which case no hydrogens are added. This function may be called from the user interface or from other functions. If the latter, then typically the cancelCB and okCB callback functions are provided so that the calling function can ascertain whether hydrogens were in fact added to the models. """ unks = AddH.gatherUnknowns(models) if unks: dialogs.display(addHinfoDialog.name) dialog = dialogs.find(addHinfoDialog.name) dialog.setAtoms(unks) dialog.models = models dialog.cancelCB = cancelCB dialog.okCB = okCB dialog.hisScheme = hisScheme dialog.addFunc = addFunc else: addFunc(models, hisScheme=hisScheme) if okCB: okCB()
def track_xform_dialog(create=0): """track_xform_dialog(create=0) - look for Track Transform dialog. If create = 1, then creates a new dialog if dialog does not exist. """ from chimera import dialogs return dialogs.find(TrackXformDialog.name, create=create)
def seg_mask_dialog(create=0): """seg_mask_dialog(create=0) - look for Segment Mask dialog. If create = 1, then creates a new dialog if dialog does not exist. """ from chimera import dialogs return dialogs.find(Segment_Mask.name, create=create)
def airs_dialog(create=0): """airs_dialog(create=0) - look for AIRS dialog. If create = 1, then creates a new dialog if dialog does not exist. """ from chimera import dialogs return dialogs.find(AIRS_Dialog.name, create=create)
def displayDialog(wait=False): if dialogs.find(BugReportGUI.name): replyobj.status("Bug report already in progress!", color="red", blankAfter=15) return None else: br_gui = dialogs.display(BugReportGUI.name, wait) return br_gui
def color_secondary_structure(): 'Color secondary structure using ColorSS extension' import ColorSS from chimera import dialogs d = dialogs.find(ColorSS.ColorSSDialog.name, create=False) if d == None: d = dialogs.display(ColorSS.ColorSSDialog.name) d.Close() d.Apply()
def seg_marker_dialog(create=0): """Looks for Segment Marker dialog. seg_marker_dialog(create=0) If create = 1, then creates a new dialog if dialog does not exist. """ from chimera import dialogs return dialogs.find(Segment_Marker.name, create=create)
def showImage(image, title='', new_window=False, resize_window=False, fit_to_window=False): if new_window: v = ImageViewer() resize_window = True else: from chimera import dialogs v = dialogs.find(ImageViewer.name, create=False) if v is None: v = dialogs.find(ImageViewer.name, create=True) resize_window = True v.set_image(image, resize_window, fit_to_window) if title: v.set_title(title) v.enter()
def vol_morph_dialog(create=0): """Looks for Volume Morph dialog. vol_morph_dialog(create=0) If create = 1, then creates a new dialog if dialog does not exist. """ from chimera import dialogs return dialogs.find(Volume_Morph.name, create=create)
def simple_distance_dialog(create=0): """Looks for Measure Stick dialog. simple_distance_dialog(create=0) If create = 1, then creates a new dialog if dialog does not exist. """ from chimera import dialogs return dialogs.find(Measure_Stick.name, create=create)
def addRotation(bond): d = dialogs.find(StructMeasure.name) import types br = bondRotMgr.rotationForBond(bond, create=False) if br == None: br = bondRotMgr.rotationForBond(bond) else: d.enter() d.setCategoryMenu(BONDROTS) return br
def _showBondRotUI(trigger, myData, br): if chimera.nogui: return if trigger == bondRotMgr.CREATED: # some window managers are slow to raise windows # only auto-raise the dialog if a new rotation is created dialogs.display(StructMeasure.name) d = dialogs.find(StructMeasure.name) d.setCategoryMenu(BONDROTS) d.rotChange(trigger, br)
def show_dialog(closeOld=True): from chimera import dialogs d = dialogs.find(ISeg_Dialog.name, create=False) if d: if closeOld: d.toplevel_widget.update_idletasks() d.Close() d.toplevel_widget.update_idletasks() else: return d dialogs.register(ISeg_Dialog.name, ISeg_Dialog, replace=True) d = dialogs.find(ISeg_Dialog.name, create=True) # Avoid transient dialog resizing when created and mapped for first time. d.toplevel_widget.update_idletasks() d.enter() return d
def Apply(self): from ModelPanel import ModelPanel from chimera import dialogs mp = dialogs.find(ModelPanel.name, create=1) sels = mp.selected() if len(sels) != 1: replyobj.error("Must choose exactly one model" " in model panel.\n") return refXform = sels[0].openState.xform for model in self.models: model.openState.xform = refXform
def read_reply_log(): """ Reads the Chimera reply log Arguments: None Requires: There must be a Chimera reply log open. This means that Chimera needs to be running in GUI mode, e.g. Chimera needs to be opened with the command `chimera --start "Reply Log" ...` Returns: r (Chimera dialog object): The reply log object r_text (str): The current reply log text Effect: None """ r = dialogs.find("reply") r_text = r.text.get("1.0", "end") return (r, r_text)
def get_cutoff(self): # validate if the map is loaded/choosed bmap = self.map_menu.data_region() if bmap is None: self.message('Choose map.') return # Import the native dialog Volume Viewer from Chimera from chimera import dialogs vdlg = dialogs.find("volume viewer") # Get the cut-off level from the Volume Viewer dialog cutoff_panel = vdlg.thresholds_panel.threshold.get() # Set the cut-off value in FitOpt with the previous value self.cutoff.set(cutoff_panel) self.message("")
def surface_volume_dialog(create = 0): from chimera import dialogs return dialogs.find(Surface_Volume_Dialog.name, create=create)
def morph_map_dialog(create=False): from chimera import dialogs return dialogs.find(Morph_Map_Dialog.name, create=create)
def surface_zone_dialog(create=0): from chimera import dialogs return dialogs.find(Surface_Zone_Dialog.name, create=create)
def scale_bar_dialog(create = 0): from chimera import dialogs return dialogs.find(Scalebar_Dialog.name, create=create)
def saxs_dialog(create=False): from chimera import dialogs return dialogs.find(SAXS_Dialog.name, create=create)
def fit_map_dialog(create = False): from chimera import dialogs return dialogs.find(Fit_Map_Dialog.name, create=create)
def icosahedron_dialog(create = 0): from chimera import dialogs return dialogs.find(Icosahedron_Dialog.name, create=create)
def color_zone_dialog(create = 0): from chimera import dialogs return dialogs.find(Color_Zone_Dialog.name, create=create)
def volume_series_dialog(create = False): from chimera import dialogs return dialogs.find(Volume_Series_Dialog.name, create=create)
def fit_map_dialog(create=False): from chimera import dialogs return dialogs.find(Fit_Map_Dialog.name, create=create)
def real_scale_dialog(create = 0): from chimera import dialogs return dialogs.find(Realscale_Dialog.name, create=create)
def flatten_icosahedron_dialog(create = False): from chimera import dialogs return dialogs.find(Flatten_Icosahedron_Dialog.name, create=create)
def surface_color_dialog(create = False): from chimera import dialogs return dialogs.find(Surface_Color_Dialog.name, create=create)
def readFiles(fileNames, clear=True): if not _ilabelModel: IlabelModel() if clear: for label in _ilabelModel.labels[:]: _ilabelModel.removeLabel(label) _ilabelModel.setMajorChange() from chimera import UserError for fileName in fileNames: from OpenSave import osOpen f = osOpen(fileName) label = labelID = text = None for ln, line in enumerate(f): lineNum = ln + 1 if not line.strip() or line.strip().startswith('#'): # skip blank lines / comments continue if line.lower().startswith("label"): labelID = line[5:].strip() continue if line[0] != '\t': f.close() raise UserError("%s, line %d: line must start with 'Label'" " or tab" % (fileName, lineNum)) try: semi = line.index(':') except ValueError: f.close() raise UserError("%s, line %d: line must have semi-colon" % (fileName, lineNum)) name = line[1:semi].lower() if not label and name != "(x,y)": f.close() raise UserError("%s, line %d: xy position must immediately" " follow 'Label' line" % (fileName, lineNum)) if label and text is None and name != "text": f.close() raise UserError("%s, line %d: text must immediately" " follow xy position" % (fileName, lineNum)) value = line[semi + 1:].strip() if name == "(x,y)": text = None try: pos = eval(value) except: f.close() raise UserError("%s, line %d: could not parse xy value" % (fileName, lineNum)) if labelID: label = _ilabelModel.newLabel(pos) else: label = _ilabelModel.newLabel(pos, labelID=labelID) elif name == "text": try: text = eval(value) except: f.close() _ilabelModel.removeLabel(label) raise UserError( "%s, line %d: could not parse 'text' value" % (fileName, lineNum)) label.set(text) elif name == "shown": if name == "shown": try: label.shown = eval(value.capitalize()) except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse 'shown'" " value" % (fileName, lineNum)) else: chars = [] for l in label.lines: chars.extend(l) if '),' in value: values = value.split('),') for i, v in enumerate(values[:-1]): values[i] = v + ')' elif ',' in value and not value.strip().startswith('('): values = value.split(',') else: values = [value] * len(chars) if len(values) != len(chars): f.close() raise UserError( "%s, line %d: number of values not equal" " to numbers of characters in text (and not a single" " value)" % (fileName, lineNum)) if name.startswith("font size"): try: values = [eval(v) for v in values] except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'font size' value(s)" % (fileName, lineNum)) for c, v in zip(chars, values): c.size = v elif name.startswith("font style"): for c, v in zip(chars, values): try: c.style = styleLookup(v.strip().lower()) except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'font style' value(s)" % (fileName, lineNum)) elif name.startswith("font typeface"): for c, v in zip(chars, values): try: c.fontName = typefaceLookup(v.strip().lower()) except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'font typeface' value(s)" % (fileName, lineNum)) elif name.startswith("color"): try: values = [eval(v) for v in values] except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'color' value(s)" % (fileName, lineNum)) for c, v in zip(chars, values): c.rgba = v else: _ilabelModel.removeLabel(label) raise UserError( "%s, line %d: unknown label attribute '%s'" % (fileName, lineNum, name)) f.close() if chimera.nogui: dlg = None else: from gui import IlabelDialog from chimera import dialogs dlg = dialogs.find(IlabelDialog.name) if dlg: dlg.updateGUI("file")
def capper_dialog(create=0): from chimera import dialogs return dialogs.find(Capper_Dialog.name, create=create)
def readFiles(fileNames, clear=True): if not _ilabelModel: IlabelModel() if clear: for label in _ilabelModel.labels[:]: _ilabelModel.removeLabel(label) _ilabelModel.setMajorChange() from chimera import UserError for fileName in fileNames: from OpenSave import osOpen f = osOpen(fileName) label = labelID = text = None for ln, line in enumerate(f): lineNum = ln + 1 if not line.strip() or line.strip().startswith('#'): # skip blank lines / comments continue if line.lower().startswith("label"): labelID = line[5:].strip() continue if line[0] != '\t': f.close() raise UserError("%s, line %d: line must start with 'Label'" " or tab" % (fileName, lineNum)) try: semi = line.index(':') except ValueError: f.close() raise UserError("%s, line %d: line must have semi-colon" % (fileName, lineNum)) name = line[1:semi].lower() if not label and name != "(x,y)": f.close() raise UserError("%s, line %d: xy position must immediately" " follow 'Label' line" % (fileName, lineNum)) if label and text is None and name != "text": f.close() raise UserError("%s, line %d: text must immediately" " follow xy position" % (fileName, lineNum)) value = line[semi+1:].strip() if name == "(x,y)": text = None try: pos = eval(value) except: f.close() raise UserError("%s, line %d: could not parse xy value" % (fileName, lineNum)) if labelID: label = _ilabelModel.newLabel(pos) else: label = _ilabelModel.newLabel(pos, labelID=labelID) elif name == "text": try: text = eval(value) except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse 'text' value" % (fileName, lineNum)) label.set(text) elif name == "shown": if name == "shown": try: label.shown = eval(value.capitalize()) except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse 'shown'" " value" % (fileName, lineNum)) else: chars = [] for l in label.lines: chars.extend(l) if '),' in value: values = value.split('),') for i, v in enumerate(values[:-1]): values[i] = v + ')' elif ',' in value and not value.strip().startswith('('): values = value.split(',') else: values = [value] * len(chars) if len(values) != len(chars): f.close() raise UserError("%s, line %d: number of values not equal" " to numbers of characters in text (and not a single" " value)" % (fileName, lineNum)) if name.startswith("font size"): try: values = [eval(v) for v in values] except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'font size' value(s)" % (fileName, lineNum)) for c, v in zip(chars, values): c.size = v elif name.startswith("font style"): for c, v in zip(chars, values): try: c.style = styleLookup(v.strip().lower()) except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'font style' value(s)" % (fileName, lineNum)) elif name.startswith("font typeface"): for c, v in zip(chars, values): try: c.fontName = typefaceLookup(v.strip().lower()) except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'font typeface' value(s)" % (fileName, lineNum)) elif name.startswith("color"): try: values = [eval(v) for v in values] except: f.close() _ilabelModel.removeLabel(label) raise UserError("%s, line %d: could not parse" " 'color' value(s)" % (fileName, lineNum)) for c, v in zip(chars, values): c.rgba = v else: _ilabelModel.removeLabel(label) raise UserError("%s, line %d: unknown label attribute '%s'" % (fileName, lineNum, name)) f.close() if chimera.nogui: dlg = None else: from gui import IlabelDialog from chimera import dialogs dlg = dialogs.find(IlabelDialog.name) if dlg: dlg.updateGUI("file")
def dust_dialog(create = False): from chimera import dialogs return dialogs.find(Dust_Dialog.name, create=create)
def morph_map_dialog(create = False): from chimera import dialogs return dialogs.find(Morph_Map_Dialog.name, create=create)
def blob_picker_dialog(create=False): from chimera import dialogs return dialogs.find(Blob_Picker_Dialog.name, create=create)
def constrained_move_dialog(create=0): from chimera import dialogs return dialogs.find(Constrained_Move_Dialog.name, create=create)
def size_callback(self): if self.reply_dialog: x = "-1-1" d = dialogs.find(tkgui._ReplyDialog.name) d.uiMaster().winfo_toplevel().wm_geometry(x)
def accelerator_dialog(create = False): from gui import Accelerator_Browser from chimera import dialogs return dialogs.find(Accelerator_Browser.name, create=create)
label = model.labelMap[labelID] model.removeLabel(label) elif action == "read": readFiles([labelID]) elif action == "write": writeFile(labelID) else: raise MidasError, "Unknown 2dlabels action '%s'" % action model.setMajorChange() from gui import IlabelDialog from chimera import dialogs dlg = dialogs.find(IlabelDialog.name) if dlg: dlg.updateGUI("command") def changeLabelAttrs(label, size=None, color=None, style=None, typeface=None, opacity=None): chars = [] [chars.extend(line) for line in label.lines] for c in chars: if color != None: c.rgba = color.rgba()[0:3] + (c.rgba[3],) if size != None: c.size = size if style != None:
def molecule_transform_dialog(create = False): from chimera import dialogs return dialogs.find(Molecule_Transform_Dialog.name, create=create)
def saxs_dialog(create = False): from chimera import dialogs return dialogs.find(SAXS_Dialog.name, create=create)
label = model.labelMap[labelID] model.removeLabel(label) elif action == "read": readFiles([labelID]) elif action == "write": writeFile(labelID) else: raise MidasError, "Unknown 2dlabels action '%s'" % action model.setMajorChange() from gui import IlabelDialog from chimera import dialogs dlg = dialogs.find(IlabelDialog.name) if dlg: dlg.updateGUI("command") def changeLabelAttrs(label, size=None, color=None, style=None, typeface=None, opacity=None): chars = [] [chars.extend(line) for line in label.lines] for c in chars:
def atom_density_dialog(create=0): from chimera import dialogs return dialogs.find(Atom_Density_Dialog.name, create=create)
def movement_mode_dialog(create = 0): from chimera import dialogs return dialogs.find(Movement_Mouse_Mode_Dialog.name, create=create)
areaSASDict[string] = areaSAS helixDict[string] = resHelix sheetDict[string] = resSheet hydroDict[string] = resHydro atomsList.append(string) atomsList = sorted(atomsList) # COMPUTE DEPTH OF EACH ATOM (i.e. minimum distance to surface) depthDict = dict({}) minDepth = 1000000 rc("select #0") rc("~select #0:@") # rc("measure distance :arg@cd|:lys@ce|:pro@cd|:thr@cb|:trp@cd1 selection multiple true show true") rc("measure distance :arg@cd|:lys@ce|:pro@cd|:thr@cb selection multiple true show true" ) r = dialogs.find('reply') text = r.text.get('1.0', 'end') f_temp = open('./chimeraVOiD_temp.txt', 'w') f_temp.write(text) f_temp.close() ### EXAMPLE OF OPENING A TEXT FILE, ITERATING THROUGH THE LINES, AND SOME REGULAR EXPRESSION OPERATIONS. with open('./chimeraVOiD_temp.txt', 'r') as f_temp: for line in f_temp: line = line.rstrip() if line[:21] == 'minimum distance from': line = line.replace('minimum distance from ', '') line = re.sub(r" to #0:\? = ", "\t", line) resNum = line resNum = re.sub(r"#.+:", "", resNum) resNum = re.sub(r"@.+", "", resNum)
def capper_dialog(create = 0): from chimera import dialogs return dialogs.find(Capper_Dialog.name, create=create)
def crystal_contacts_dialog(create = False): from chimera import dialogs return dialogs.find(Crystal_Contacts_Dialog.name, create=create)
def movement_mode_dialog(create=0): from chimera import dialogs return dialogs.find(Movement_Mouse_Mode_Dialog.name, create=create)
def volume_eraser_dialog(create = False): from chimera import dialogs return dialogs.find(Volume_Eraser_Dialog.name, create=create)
def atom_density_dialog(create = 0): from chimera import dialogs return dialogs.find(Atom_Density_Dialog.name, create=create)