def chimera_color(rgba): if rgba is None: c = None else: from chimera import MaterialColor c = MaterialColor(*rgba) return c
def restoreColors(colors, materials): # restore materials first, since colors use them from chimera import MaterialColor, Material, Color # since colors use materials, restore materials first for name, matInfo in materials.items(): mat = Material.lookup(name) if mat is not None: mat.remove() mat = Material(name) specular, shininess = matInfo mat.specular = specular mat.shininess = shininess for name, colorInfo in colors.items(): rgb, a, matName = colorInfo mat = Material.lookup(matName) c = Color.lookup(name) if c is not None: c.remove() c = MaterialColor(rgb[0], rgb[1], rgb[2], a, material=mat) c.save(name)
def __getattr__(self, attrname): if attrname == 'customColors': vrgba = self.customRGBA if vrgba is None: return None from chimera import MaterialColor ccolors = [MaterialColor(*rgba) for rgba in vrgba] return ccolors elif attrname == 'customRGBA': p = self.surface_piece if p is None or p.__destroyed__: return None vcolors = p.vertexColors return vcolors elif attrname == 'drawMode': p = self.surface_piece if p is None or p.__destroyed__: return self.surface_piece_defaults[attrname] return { p.Solid: self.Filled, p.Mesh: self.Mesh, p.Dot: self.Dot }[p.displayStyle] elif attrname == 'lineWidth': p = self.surface_piece if p is None or p.__destroyed__: return self.surface_piece_defaults[attrname] return p.lineThickness elif attrname == 'pointSize': p = self.surface_piece if p is None or p.__destroyed__: return self.surface_piece_defaults[attrname] return p.dotSize elif attrname in ('useLighting', 'twoSidedLighting', 'smoothLines', 'transparencyBlendMode'): p = self.surface_piece if p is None or p.__destroyed__: return self.surface_piece_defaults[attrname] return getattr(p, attrname) elif attrname == 'atoms': return self.category_atoms(primary_atoms=False) elif attrname == 'bonds': return self.category_bonds(primary_atoms=False) elif attrname == 'vertexCount': if self.triData is None: return 0 return len(self.triData[0]) else: raise AttributeError, "MSMSModel has no attribute '%s'" % attrname
def restoreColors(colors, materials, colorUsage, vdwColors, labelColors, surfaceColors): # restore materials first, since colors use them from chimera import MaterialColor, Material, Color # since colors use materials, restore materials first for name, matInfo in materials.items(): mat = Material.lookup(name) if mat is not None: mat.remove() mat = Material(name) specular, shininess = matInfo mat.specular = specular mat.shininess = shininess for name, colorInfo in colors.items(): rgb, a, matName = colorInfo mat = Material.lookup(matName) c = Color.lookup(name) if c is not None: c.remove() c = MaterialColor(rgb[0], rgb[1], rgb[2], a, material=mat) c.save(name) for itemID, colorID in colorUsage.items(): item = idLookup(itemID) if isinstance(item, chimera.Residue): item.ribbonColor = getColor(colorID) else: item.color = getColor(colorID) for itemID, colorID in vdwColors.items(): idLookup(itemID).vdwColor = getColor(colorID) for itemID, colorID in labelColors.items(): idLookup(itemID).labelColor = getColor(colorID) for itemID, colorID in surfaceColors.items(): idLookup(itemID).surfaceColor = getColor(colorID)
def empty(self): for k,v in self.fields.items(): _data = v[0] _ui= v[1] _var = v[3] if isinstance(_ui,Entry): _var.set("") elif isinstance(_ui,ColorOption): _ui.set(MaterialColor(*[0.0,0.0,0.0,1.0])) elif isinstance(_ui,OptionMenu): _var.set("") elif isinstance(_ui,FileFrame): _ui.resetFileMenu([""],0) _data.empty()
def _colorCB(self): if self.treatmentColorModel == 0: # No action return idList = self._getSelected() from CGLtk.color import colorRange from chimera import MaterialColor colorList = [ MaterialColor(r, g, b, 1.0) for r, g, b in colorRange(len(idList)) ] lb = self.listbox.component("listbox") origColor = lb["fg"] origSelColor = lb["selectforeground"] for i, color in enumerate(colorList): id = idList[i] if self.treatmentColorModelOf == "representatives": # Color representative for m in self.clusterInfo[id][1]: m.color = m.preclusterColor self._resetColor(m) self.clusterInfo[id][0].color = color else: # Color cluster for m in self.clusterInfo[id][1]: m.color = color self._resetColor(m) r, g, b, a = color.rgba() tkColor = "#%02x%02x%02x" % (int(r * 255), int( g * 255), int(b * 255)) lb.itemconfigure(id, fg=tkColor, selectforeground=tkColor) for id in range(len(self.clusterInfo)): if id in idList: continue for m in self.clusterInfo[id][1]: m.color = m.preclusterColor self._resetColor(m) lb.itemconfigure(id, fg=origColor, selectforeground=origSelColor)
def refresh(self, selection=None, rebuild=False): if not self.tixTable: return # cull dead data liveData = [ d for d in self.data if not getattr(d, '__destroyed__', False) ] if len(liveData) != len(self.data): self.setData(liveData) return if selection is None: selection = self._selected() if rebuild: self._constructEmptyTable() else: self.tixTable.hlist.delete_all() for datum, column, widget in self._widgetData.values(): widget.destroy() self._widgetData.clear() hlist = self.tixTable.hlist for colNum, column in enumerate([c for c in self.columns if c.display]): hlist.header_create(colNum, itemtype='window', style=column.headerStyle, window=self._columnHeader(hlist, column)) # data in the sorting column may have changed... self._sortCache = None sortData = self._sortedData() for row, datum in enumerate(sortData): for col, column in enumerate( [c for c in self.columns if c.display]): contents = column.displayValue(datum) if col == 0: hlist.add(row) if type(contents) == bool: but = Tkinter.Checkbutton( hlist, command=lambda r=row, c=col: self._widgetCB(r, c), indicatoron=False, borderwidth=0, image=self._ckButImage(contents)) self._widgetData[(row, col)] = (datum, column, but) hlist.item_create(row, col, itemtype="window", window=but, style=column.checkButtonStyle) elif isinstance(contents, basestring): hlist.item_create(row, col, itemtype="text", style=column.textStyle, text=contents) else: color, noneOkay, alphaOkay = contents from color.ColorWell import ColorWell if hasattr(color, 'rgba') \ or color == None: from chimera \ import MaterialColor cval = color.rgba() cb = lambda clr, r=row, c=col:\ self._widgetCB(r, c, newVal=MaterialColor( *clr)) else: cval = color cb = lambda clr, r=row, c=col:\ self._widgetCB(r, c, newVal=clr) well = ColorWell(hlist, cval, callback=cb, width=18, height=18, noneOkay=noneOkay, wantAlpha=alphaOkay) self._widgetData[(row, col)] = (datum, column, well) hlist.item_create(row, col, itemtype="window", window=well, style=column.colorWellStyle) for s in selection: if s in sortData: hlist.selection_set(sortData.index(s))
def getAttribute(self, piece, name): from chimera import MaterialColor return MaterialColor(*piece.color)