def _draw_jig(self, glpane, color, highlighted=False): """ Draw a linear motor as a long box along the axis, with a thin cylinder (spoke) to each atom. """ glPushMatrix() try: glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) drawbrick(color, orig_center, self.axis, self.length, self.width, self.width, opacity = self.opacity) drawLinearSign((0,0,0), orig_center, self.axis, self.length, self.width, self.width) # (note: drawLinearSign uses a small depth offset so that arrows are slightly in front of brick) # [bruce comment 060302, a guess from skimming drawLinearSign's code] for a in self.atoms[:]: drawcylinder(color, orig_center, a.posn()-self.center, self.sradius, opacity = self.opacity) except: #bruce 060208 protect OpenGL stack from exception analogous to that seen for RotaryMotor in bug 1445 print_compact_traceback("exception in LinearMotor._draw, continuing: ") glPopMatrix()
def _draw_jig(self, glpane, color, highlighted=False): """ [overrides superclass method] """ del color self._update_props() if not self._should_draw(): return drawrad = 0.1 posns = [a.posn() for a in self.atoms] normcolor = self._drawing_color() # russ 080530: Support for patterned highlighting drawing modes. selected = self.picked patterned = isPatternedDrawing(select=selected, highlight=highlighted) if patterned: # Patterned selection drawing needs the normal drawing first. drawcylinder(normcolor, posns[0], posns[1], drawrad) startPatternedDrawing(select=selected, highlight=highlighted) pass # Draw solid color, or overlay pattern in highlight or selection color. drawcylinder( (highlighted and env.prefs[hoverHighlightingColor_prefs_key] or selected and env.prefs[selectionColor_prefs_key] or normcolor), posns[0], posns[1], drawrad) if patterned: # Reset from patterned drawing mode. endPatternedDrawing(select=selected, highlight=highlighted) pass return
def Draw(self): # TODO: also super draw, for model, axes, etc? color = self.command.cylinderColor length = cylinder_height() ## if self.command.cylinderVertical: ## direction = DY ## else: ## direction = DX direction = self.command.direction end1 = ORIGIN - direction * length/2.0 end2 = ORIGIN + direction * length/2.0 radius = self.command.cylinderWidth / 2.0 capped = True drawcylinder(color, end1, end2, radius, capped) if cylinder_round_caps(): detailLevel = 2 drawsphere( color, end1, radius, detailLevel) drawsphere( color, end2, radius, detailLevel) if self.command.widthHandleEnabled: self.command.widthHandle.draw() super(_test_connectWithState_GM, self).Draw() # added this, bruce 071022 return
def drawchunk(self, glpane, chunk, memo, highlighted): """ Draw chunk in glpane in the whole-chunk display mode represented by this ChunkDisplayMode subclass. Assume we're already in chunk's local coordinate system (i.e. do all drawing using atom coordinates in chunk.basepos, not chunk.atpos). If highlighted is true, draw it in hover-highlighted form (but note that it may have already been drawn in unhighlighted form in the same frame, so normally the highlighted form should augment or obscure the unhighlighted form). Draw it as unselected, whether or not chunk.picked is true. See also self.drawchunk_selection_frame. (The reason that's a separate method is to permit future drawing optimizations when a chunk is selected or deselected but does not otherwise change in appearance or position.) If this drawing requires info about chunk which it is useful to precompute (as an optimization), that info should be computed by our compute_memo method and will be passed as the memo argument (whose format and content is whatever self.compute_memo returns). That info must not depend on the highlighted variable or on whether the chunk is selected. """ if not chunk.atoms: return end1, end2, radius, color = memo if highlighted: color = ave_colors(0.5, color, env.prefs[chunkHighlightColor_prefs_key] ) #e should the caller compute this somehow? drawcylinder(color, end1, end2, radius, capped=True) return
def _draw_jig(self, glpane, color, highlighted = False): """ [overrides superclass method] """ del color self._update_props() if not self._should_draw(): return drawrad = 0.1 posns = [a.posn() for a in self.atoms] normcolor = self._drawing_color() # russ 080530: Support for patterned highlighting drawing modes. selected = self.picked patterned = isPatternedDrawing(select = selected, highlight = highlighted) if patterned: # Patterned selection drawing needs the normal drawing first. drawcylinder( normcolor, posns[0], posns[1], drawrad) startPatternedDrawing(select = selected, highlight = highlighted) pass # Draw solid color, or overlay pattern in highlight or selection color. drawcylinder( (highlighted and env.prefs[hoverHighlightingColor_prefs_key] or selected and env.prefs[selectionColor_prefs_key] or normcolor), posns[0], posns[1], drawrad) if patterned: # Reset from patterned drawing mode. endPatternedDrawing(select = selected, highlight = highlighted) pass return
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a Rotary Motor jig as a cylinder along the axis, with a thin cylinder (spoke) to each atom. If <highlighted> is True, the Rotary Motor is draw slightly larger. """ ## print "RMotor _draw_jig",env.redraw_counter # This confirms that Jigs are drawn more times than they ought to need to be, # possibly due to badly organized Jig hit-testing code -- 4 times on mouseenter that highlights them in Build mode # (even after I fixed a bug today in which it redrew the entire model twice each frame); # but it's hard to find something to compare it to for an objective test of whether being a Jig matters, # since atoms, bonds, and chunks all have special behavior of their own. BTW, the suspected bad Jig code might redraw # everything (not only Jigs) this often, even though all it cares about is seeing Jigs in glRenderMode output. # BTW2, on opening a file containing one jig, it was drawn something like 20 times. # [bruce 060724 comments] if highlighted: inc = 0.01 # tested. Fixes bug 1681. mark 060314. else: inc = 0.0 glPushMatrix() try: glTranslatef(self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef(q.angle * 180.0 / pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) bCenter = orig_center - (self.length / 2.0 + inc) * self.axis tCenter = orig_center + (self.length / 2.0 + inc) * self.axis drawcylinder(color, bCenter, tCenter, self.radius + inc, capped=1, opacity=self.opacity) for a in self.atoms: drawcylinder(color, orig_center, a.posn() - self.center, self.sradius + inc, opacity=self.opacity) rotby = self.getrotation() #bruce 050518 # if exception in getrotation, just don't draw the rotation sign # (safest now that people might believe what it shows about amount of rotation) drawRotateSign((0, 0, 0), bCenter, tCenter, self.radius, rotation=rotby) except: #bruce 060208 protect OpenGL stack from exception seen in bug 1445 print_compact_traceback( "exception in RotaryMotor._draw, continuing: ") print " some info that might be related to that exception: natoms = %d" % len( self.atoms) ###@@@ might not keep this glPopMatrix() return
def _DEBUG_drawPlaneNormals(self): ends = self._crossoverSite_marker.get_plane_normals_ends_for_drawing() for end1, end2 in ends: drawcylinder(banana, end1, end2, CYL_RADIUS, capped=True, opacity=CYL_OPACITY)
def _DEBUG_drawPlaneNormals(self): ends = self._crossoverSite_marker.get_plane_normals_ends_for_drawing() for end1, end2 in ends: drawcylinder(banana, end1, end2, CYL_RADIUS, capped = True, opacity = CYL_OPACITY )
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a Rotary Motor jig as a cylinder along the axis, with a thin cylinder (spoke) to each atom. If <highlighted> is True, the Rotary Motor is draw slightly larger. """ ## print "RMotor _draw_jig",env.redraw_counter # This confirms that Jigs are drawn more times than they ought to need to be, # possibly due to badly organized Jig hit-testing code -- 4 times on mouseenter that highlights them in Build mode # (even after I fixed a bug today in which it redrew the entire model twice each frame); # but it's hard to find something to compare it to for an objective test of whether being a Jig matters, # since atoms, bonds, and chunks all have special behavior of their own. BTW, the suspected bad Jig code might redraw # everything (not only Jigs) this often, even though all it cares about is seeing Jigs in glRenderMode output. # BTW2, on opening a file containing one jig, it was drawn something like 20 times. # [bruce 060724 comments] if highlighted: inc = 0.01 # tested. Fixes bug 1681. mark 060314. else: inc = 0.0 glPushMatrix() try: glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) bCenter = orig_center - (self.length / 2.0 + inc) * self.axis tCenter = orig_center + (self.length / 2.0 + inc) * self.axis drawcylinder(color, bCenter, tCenter, self.radius + inc, capped = 1, opacity = self.opacity ) for a in self.atoms: drawcylinder(color, orig_center, a.posn()-self.center, self.sradius + inc, opacity = self.opacity) rotby = self.getrotation() #bruce 050518 # if exception in getrotation, just don't draw the rotation sign # (safest now that people might believe what it shows about amount of rotation) drawRotateSign((0,0,0), bCenter, tCenter, self.radius, rotation = rotby) except: #bruce 060208 protect OpenGL stack from exception seen in bug 1445 print_compact_traceback("exception in RotaryMotor._draw, continuing: ") print " some info that might be related to that exception: natoms = %d" % len(self.atoms) ###@@@ might not keep this glPopMatrix() return
def _bondDraw(self, color, p0, p1, carbonAt): if self.dispMode == 'Tubes': drawcylinder(color, p0, p1, 0.2) else: if carbonAt < 0: drawsphere(color, p0, 0.5, 1) drawsphere(color, p1, 0.5, 1) elif carbonAt == 0: drawsphere(color, p0, 0.5, 1) drawsphere(color, p1, 0.2, 1) elif carbonAt == 1: drawsphere(color, p0, 0.2, 1) drawsphere(color, p1, 0.5, 1) drawline(white, p0, p1)
def _bondDraw(self, color, p0, p1, carbonAt): if self.dispMode == "Tubes": drawcylinder(color, p0, p1, 0.2) else: if carbonAt < 0: drawsphere(color, p0, 0.5, 1) drawsphere(color, p1, 0.5, 1) elif carbonAt == 0: drawsphere(color, p0, 0.5, 1) drawsphere(color, p1, 0.2, 1) elif carbonAt == 1: drawsphere(color, p0, 0.2, 1) drawsphere(color, p1, 0.5, 1) drawline(white, p0, p1)
def primCSDL(centers, radii, colors): if not doTransforms: csdl = ColorSortedDisplayList() # Transformless. else: # Test pattern for TransformControl usage - vertical columns # of TC domains, separated by X coord of first center point. # Chunking will be visible when transforms are changed. xCoord = centers[0][0] - start_pos[ 0] # Negate centering X. xPercent = ( xCoord / (nSpheres + nSpheres / 10 + nSpheres / 100 - 1 + (nSpheres <= 1))) xTenth = int(xPercent * 10 + .5) csdl = ColorSortedDisplayList(TCs[xTenth % numTCs]) pass # Test selection using the CSDL glname. ColorSorter.pushName(csdl.glname) ColorSorter.start(glpane, csdl) for (color, center, radius) in zip(colors, centers, radii): if not doCylinders: # Through ColorSorter to the sphere primitive buffer... drawsphere(color, center, radius, DRAWSPHERE_DETAIL_LEVEL) else: # Through ColorSorter to cylinder primitive buffer... if not drawing_globals.cylinderShader_available(): print "warning: not cylinderShader_available(), error is likely:" if (True and # Whether to do tapered shader-cylinders. # Display List cylinders don't support taper. glpane.glprefs.cylinderShader_desired()): ###cylRad = (radius/2.0, (.75-radius)/2.0) cylRad = (radius / 1.5 - .167, .3 - radius / 1.5) else: cylRad = radius / 2.0 pass endPt2 = center + V(0.5, 0.0, 0.0) # 0.5, -0.5) drawcylinder(color, center, endPt2, cylRad) global test_endpoints test_endpoints += [(center, endPt2)] pass continue ColorSorter.popName() ColorSorter.finish(draw_now=True) test_DrawingSet.addCSDL(csdl) return csdl
def _cellDraw(self, color, p0, p1): hasSinglet = False if type(p1) == type((1,)): v1 = p1[0] hasSinglet = True else: v1 = p1 if self.dispMode == "Tubes": drawcylinder(color, p0, v1, 0.2) else: drawsphere(color, p0, 0.5, 1) if hasSinglet: drawsphere(color, v1, 0.2, 1) else: drawsphere(color, v1, 0.5, 1) drawline(white, p0, v1)
def drawchunk_realtime(self, glpane, chunk, highlighted=False): if chunk.protein: for aa in chunk.protein.get_amino_acids(): if chunk.protein.is_expanded(aa): for atom in aa.get_atom_list(): pos1 = chunk.abs_to_base(atom.posn()) color = atom.drawing_color() drawsphere(color, pos1, 0.25, 1) for bond in atom.bonds: if atom == bond.atom1: pos2 = chunk.abs_to_base(bond.atom2.posn()) drawcylinder(color, pos1, pos1 + 0.5*(pos2 - pos1), 0.2, 1) else: pos2 = chunk.abs_to_base(bond.atom1.posn()) drawcylinder(color, pos1 + 0.5*(pos2 - pos1), pos1, 0.2, 1) return
def _cellDraw(self, color, p0, p1): hasSinglet = False if type(p1) == type((1,)): v1 = p1[0] hasSinglet = True else: v1 = p1 if self.dispMode == 'Tubes': drawcylinder(color, p0, v1, 0.2) else: drawsphere(color, p0, 0.5, 1) if hasSinglet: drawsphere(color, v1, 0.2, 1) else: drawsphere(color, v1, 0.5, 1) drawline(white, p0, v1)
def primCSDL(centers, radii, colors): if not doTransforms: csdl = ColorSortedDisplayList() # Transformless. else: # Test pattern for TransformControl usage - vertical columns # of TC domains, separated by X coord of first center point. # Chunking will be visible when transforms are changed. xCoord = centers[0][0] - start_pos[0] # Negate centering X. xPercent = (xCoord / (nSpheres + nSpheres/10 + nSpheres/100 - 1 + (nSpheres <= 1))) xTenth = int(xPercent * 10 + .5) csdl = ColorSortedDisplayList(TCs[xTenth % numTCs]) pass # Test selection using the CSDL glname. ColorSorter.pushName(csdl.glname) ColorSorter.start(glpane, csdl) for (color, center, radius) in zip(colors, centers, radii): if not doCylinders: # Through ColorSorter to the sphere primitive buffer... drawsphere(color, center, radius, DRAWSPHERE_DETAIL_LEVEL) else: # Through ColorSorter to cylinder primitive buffer... if not drawing_globals.cylinderShader_available(): print "warning: not cylinderShader_available(), error is likely:" if (True and # Whether to do tapered shader-cylinders. # Display List cylinders don't support taper. glpane.glprefs.cylinderShader_desired()): ###cylRad = (radius/2.0, (.75-radius)/2.0) cylRad = (radius/1.5 - .167, .3 - radius/1.5) else: cylRad = radius/2.0 pass endPt2 = center + V(0.5, 0.0, 0.0) # 0.5, -0.5) drawcylinder(color, center, endPt2, cylRad) global test_endpoints test_endpoints += [(center, endPt2)] pass continue ColorSorter.popName() ColorSorter.finish(draw_now = True) test_DrawingSet.addCSDL(csdl) return csdl
def _drawSpecialIndicators(self): """ Overrides superclass method. This draws a transparent cylinder around the segments being resized, to easily distinguish them from other model. @see: basicGraphicsmode._drawSpecialIndicators() """ if self.command: segmentList = self.command.getResizeSegmentList() for segment in segmentList: end1, end2 = segment.getAxisEndPoints() if end1 is not None and end2 is not None: drawcylinder(banana, end1, end2, CYL_RADIUS, capped=True, opacity=CYL_OPACITY)
def _drawSpecialIndicators(self): """ Overrides superclass method. This draws a transparent cylinder around the segments being resized, to easily distinguish them from other model. @see: basicGraphicsmode._drawSpecialIndicators() """ if self.command: segmentList = self.command.getResizeSegmentList() for segment in segmentList: end1, end2 = segment.getAxisEndPoints() if end1 is not None and end2 is not None: drawcylinder(banana, end1, end2, CYL_RADIUS, capped = True, opacity = CYL_OPACITY )
def drawchunk(self, glpane, chunk, memo, highlighted): """ Draw chunk in glpane in the whole-chunk display mode represented by this ChunkDisplayMode subclass. Assume we're already in chunk's local coordinate system (i.e. do all drawing using atom coordinates in chunk.basepos, not chunk.atpos). If highlighted is true, draw it in hover-highlighted form (but note that it may have already been drawn in unhighlighted form in the same frame, so normally the highlighted form should augment or obscure the unhighlighted form). Draw it as unselected, whether or not chunk.picked is true. See also self.drawchunk_selection_frame. (The reason that's a separate method is to permit future drawing optimizations when a chunk is selected or deselected but does not otherwise change in appearance or position.) If this drawing requires info about chunk which it is useful to precompute (as an optimization), that info should be computed by our compute_memo method and will be passed as the memo argument (whose format and content is whatever self.compute_memo returns). That info must not depend on the highlighted variable or on whether the chunk is selected. """ if not chunk.atoms: return end1, end2, radius, color = memo if highlighted: color = ave_colors(0.5, color, env.prefs[chunkHighlightColor_prefs_key]) #e should the caller compute this somehow? drawcylinder(color, end1, end2, radius, capped = True) return
def drawchunk(self, glpane, chunk, memo, highlighted): """ Draws reduced representation of a protein chunk. """ structure, total_length, ca_list, n_sec = memo style = self.proteinStyle scaleFactor = self.proteinStyleScaleFactor resolution = self.proteinStyleQuality scaling = self.proteinStyleScaling smooth = self.proteinStyleSmooth gleSetJoinStyle(TUBE_JN_ANGLE | TUBE_NORM_PATH_EDGE | TUBE_JN_CAP | TUBE_CONTOUR_CLOSED ) current_sec = 0 for sec, secondary in structure: # Number of atoms in SS element including dummy atoms. n_atoms = len(sec) # The length should be at least 3. if n_atoms >= 3: # Alpha carbon trace styles. Simple but fast. if style == PROTEIN_STYLE_CA_WIRE or \ style == PROTEIN_STYLE_CA_CYLINDER or \ style == PROTEIN_STYLE_CA_BALL_STICK: for n in range( 1, n_atoms-2 ): pos0, ss0, aa0, idx0, dpos0, cbpos0 = sec[n - 1] pos1, ss1, aa1, idx1, dpos1, cbpos1 = sec[n] pos2, ss2, aa2, idx2, dpos2, cbpos2 = sec[n + 1] color = self._get_aa_color(chunk, idx1, total_length, ss1, aa1, current_sec, n_sec) if style == PROTEIN_STYLE_CA_WIRE: if pos0: drawline(color, pos1 + 0.5 * (pos0 - pos1), pos1, width=5, isSmooth=True) if pos2: drawline(color, pos1, pos1 + 0.5 * (pos2 - pos1), width=5, isSmooth=True) else: if pos0: drawcylinder(color, pos1 + 0.5 * (pos0 - pos1), pos1, 0.25 * scaleFactor, capped=1) if style == PROTEIN_STYLE_CA_BALL_STICK: drawsphere(color, pos1, 0.5 * scaleFactor, 2) else: drawsphere(color, pos1, 0.25 * scaleFactor, 2) if pos2: drawcylinder(color, pos1, pos1 + 0.5 * (pos2 - pos1), 0.25 * scaleFactor, capped=1) elif style == PROTEIN_STYLE_PEPTIDE_TILES: for n in range( 1, n_atoms-2 ): pos0, ss0, aa0, idx0, dpos0, cbpos0 = sec[n - 1] pos1, ss1, aa1, idx1, dpos1, cbpos1 = sec[n] color = self._get_aa_color(chunk, idx1, total_length, ss1, aa1, current_sec, n_sec) tri = [] nor = [] col = [] elif style == PROTEIN_STYLE_TUBE or \ style == PROTEIN_STYLE_LADDER or \ style == PROTEIN_STYLE_ZIGZAG or \ style == PROTEIN_STYLE_FLAT_RIBBON or \ style == PROTEIN_STYLE_SOLID_RIBBON or \ style == PROTEIN_STYLE_SIMPLE_CARTOONS or \ style == PROTEIN_STYLE_FANCY_CARTOONS: tube_pos = [] tube_col = [] tube_rad = [] tube_dpos = [] for n in range( 2, n_atoms-2 ): pos00, ss00, a00, idx00, dpos00, cbpos00 = sec[n - 2] pos0, ss0, aa0, idx0, dpos0, cbpos0 = sec[n - 1] pos1, ss1, aa1, idx1, dpos1, cbpos1 = sec[n] pos2, ss2, aa2, idx2, dpos2, cbpos2 = sec[n + 1] pos22, ss22, aa22, idx22, dpos22, cbpos22 = sec[n + 2] color = self._get_aa_color(chunk, idx1, total_length, ss1, aa1, current_sec, n_sec) rad = 0.25 * scaleFactor if style == PROTEIN_STYLE_TUBE and \ scaling == 1: if secondary > 0: rad *= 2.0 if n == 2: if pos0: tube_pos.append(pos00) tube_col.append(V(color)) tube_rad.append(rad) tube_dpos.append(dpos1) tube_pos.append(pos0) tube_col.append(V(color)) tube_rad.append(rad) tube_dpos.append(dpos1) if style == PROTEIN_STYLE_LADDER: drawcylinder(color, pos1, cbpos1, rad * 0.75) drawsphere(color, cbpos1, rad * 1.5, 2) if pos1: tube_pos.append(pos1) tube_col.append(V(color)) tube_rad.append(rad) tube_dpos.append(dpos1) if n == n_atoms - 3: if pos2: tube_pos.append(pos2) tube_col.append(V(color)) tube_rad.append(rad) tube_dpos.append(dpos1) tube_pos.append(pos22) tube_col.append(V(color)) tube_rad.append(rad) tube_dpos.append(dpos1) # For smoothed helices we need to add virtual atoms # located approximately at the centers of peptide bonds # but slightly moved away from the helix axis. new_tube_pos = [] new_tube_col = [] new_tube_rad = [] new_tube_dpos = [] if smooth and \ secondary == 1: for p in range(len(tube_pos)): new_tube_pos.append(tube_pos[p]) new_tube_col.append(tube_col[p]) new_tube_rad.append(tube_rad[p]) new_tube_dpos.append(tube_dpos[p]) if p > 1 and p < len(tube_pos) - 3: pv = tube_pos[p-1] - tube_pos[p] nv = tube_pos[p+2] - tube_pos[p+1] mi = 0.5 * (tube_pos[p+1] + tube_pos[p]) # The coefficient below was handpicked to make # the helices approximately round. mi -= 0.75 * norm(nv+pv) new_tube_pos.append(mi) new_tube_col.append(0.5*(tube_col[p]+tube_col[p+1])) new_tube_rad.append(0.5*(tube_rad[p]+tube_rad[p+1])) new_tube_dpos.append(0.5*(tube_dpos[p]+tube_dpos[p+1])) tube_pos = new_tube_pos tube_col = new_tube_col tube_rad = new_tube_rad tube_dpos = new_tube_dpos if secondary != 1 or \ style != PROTEIN_STYLE_SIMPLE_CARTOONS: tube_pos, tube_col, tube_rad, tube_dpos = make_tube( tube_pos, tube_col, tube_rad, tube_dpos, resolution=resolution) if style == PROTEIN_STYLE_ZIGZAG or \ style == PROTEIN_STYLE_FLAT_RIBBON or \ style == PROTEIN_STYLE_SOLID_RIBBON or \ style == PROTEIN_STYLE_SIMPLE_CARTOONS or \ style == PROTEIN_STYLE_FANCY_CARTOONS: last_pos = None last_width = 1.0 reset = False # Find SS element widths and determine width increment. if secondary == 0: # Coils have a constant width. width = scaleFactor * 0.1 dw = 0.0 elif secondary == 1: # Helices expand and shrink at the ends. width = scaleFactor * 0.1 dw = (1.0 * scaleFactor) / (resolution - 3) else: # Strands just shrink at the C-terminal end. width = scaleFactor * 1.0 dw = (1.6 * scaleFactor) / (1.5 * resolution - 3) if style == PROTEIN_STYLE_FLAT_RIBBON or \ style == PROTEIN_STYLE_SOLID_RIBBON or \ style == PROTEIN_STYLE_SIMPLE_CARTOONS or \ style == PROTEIN_STYLE_FANCY_CARTOONS: tri_arr0 = [] nor_arr0 = [] col_arr0 = [] if style == PROTEIN_STYLE_SOLID_RIBBON or \ style == PROTEIN_STYLE_SIMPLE_CARTOONS or \ style == PROTEIN_STYLE_FANCY_CARTOONS: tri_arr1 = [] nor_arr1 = [] col_arr1 = [] tri_arr2 = [] nor_arr2 = [] col_arr2 = [] tri_arr3 = [] nor_arr3 = [] col_arr3 = [] from copy import copy new_tube_dpos = copy(tube_dpos) for n in range(1, len(tube_pos)-1): pos = tube_pos[n] col = tube_col[n][0] col2 = tube_col[n+1][0] if last_pos: next_pos = tube_pos[n+1] dpos1 = last_width * tube_dpos[n-1] dpos2 = width * tube_dpos[n] ddpos = dpos1-dpos2 if reset: dpos1 = dpos2 reset = False if self.proteinStyle == PROTEIN_STYLE_ZIGZAG: drawline(col, last_pos-dpos1, pos-dpos2, width=3) drawline(col, last_pos+dpos1, pos+dpos2, width=3) drawline(col, last_pos-dpos1, pos+dpos2, width=1) drawline(col, pos-dpos2, pos+dpos2, width=1) drawline(col, last_pos-dpos1, last_pos+dpos1, width=1) if self.proteinStyle == PROTEIN_STYLE_FLAT_RIBBON: if pos != last_pos: nvec1 = norm(cross(dpos1, pos-last_pos)) if next_pos != pos: nvec2 = norm(cross(dpos2, next_pos-pos)) else: nvec2 = nvec1 nor_arr0.append(nvec1) nor_arr0.append(nvec1) nor_arr0.append(nvec2) nor_arr0.append(nvec2) tri_arr0.append(last_pos-dpos1) tri_arr0.append(last_pos+dpos1) tri_arr0.append(pos-dpos2) tri_arr0.append(pos+dpos2) col_arr0.append(col) col_arr0.append(col) col_arr0.append(col2) col_arr0.append(col2) if self.proteinStyle == PROTEIN_STYLE_SOLID_RIBBON or \ self.proteinStyle == PROTEIN_STYLE_SIMPLE_CARTOONS or \ self.proteinStyle == PROTEIN_STYLE_FANCY_CARTOONS: if secondary > 0: col3 = col4 = V(gray) if pos != last_pos: nvec1 = norm(cross(dpos1, pos-last_pos)) if next_pos != pos: nvec2 = norm(cross(dpos2, next_pos-pos)) else: nvec2 = nvec1 nor_arr0.append(nvec1) nor_arr0.append(nvec1) nor_arr0.append(nvec2) nor_arr0.append(nvec2) if self.proteinStyle == PROTEIN_STYLE_FANCY_CARTOONS: dn1 = 0.15 * nvec1 * scaleFactor dn2 = 0.15 * nvec2 * scaleFactor else: dn1 = 0.15 * nvec1 * scaleFactor dn2 = 0.15 * nvec2 * scaleFactor tri_arr0.append(last_pos - dpos1 - dn1) tri_arr0.append(last_pos + dpos1 - dn1) tri_arr0.append(pos - dpos2 - dn2) tri_arr0.append(pos + dpos2 - dn2) col_arr0.append(col) col_arr0.append(col) col_arr0.append(col2) col_arr0.append(col2) nor_arr1.append(nvec1) nor_arr1.append(nvec1) nor_arr1.append(nvec2) nor_arr1.append(nvec2) tri_arr1.append(last_pos - dpos1 + dn1) tri_arr1.append(last_pos + dpos1 + dn1) tri_arr1.append(pos - dpos2 + dn2) tri_arr1.append(pos + dpos2 + dn2) if secondary == 1: col_arr1.append(0.5 * col + 0.5 * V(white)) col_arr1.append(0.5 * col + 0.5 * V(white)) col_arr1.append(0.5 * col2 + 0.5 * V(white)) col_arr1.append(0.5 * col2 + 0.5 * V(white)) else: col_arr1.append(col) col_arr1.append(col) col_arr1.append(col2) col_arr1.append(col2) nor_arr2.append(-dpos1) nor_arr2.append(-dpos1) nor_arr2.append(-dpos2) nor_arr2.append(-dpos2) tri_arr2.append(last_pos - dpos1 - dn1) tri_arr2.append(last_pos - dpos1 + dn1) tri_arr2.append(pos - dpos2 - dn2) tri_arr2.append(pos - dpos2 + dn2) col_arr2.append(col3) col_arr2.append(col3) col_arr2.append(col4) col_arr2.append(col4) nor_arr3.append(-dpos1) nor_arr3.append(-dpos1) nor_arr3.append(-dpos2) nor_arr3.append(-dpos2) tri_arr3.append(last_pos + dpos1 - dn1) tri_arr3.append(last_pos + dpos1 + dn1) tri_arr3.append(pos + dpos2 - dn2) tri_arr3.append(pos + dpos2 + dn2) col_arr3.append(col3) col_arr3.append(col3) col_arr3.append(col4) col_arr3.append(col4) last_pos = pos last_width = width if secondary == 1: if n > len(tube_pos) - resolution: width -= dw elif width < 1.0 * scaleFactor: width += dw if secondary == 2: if n == len(tube_pos) - 1.5 * resolution: width = scaleFactor * 1.6 reset = True if n > len(tube_pos) - 1.5 * resolution: width -= dw new_tube_dpos[n] = width * tube_dpos[n] ###drawcylinder(white, tube_pos[0], tube_pos[10], 1.0) if self.proteinStyle == PROTEIN_STYLE_FLAT_RIBBON: drawtriangle_strip([1.0,1.0,0.0,-2.0], tri_arr0, nor_arr0, col_arr0) if self.proteinStyle == PROTEIN_STYLE_SOLID_RIBBON or \ self.proteinStyle == PROTEIN_STYLE_SIMPLE_CARTOONS or \ self.proteinStyle == PROTEIN_STYLE_FANCY_CARTOONS: if secondary == 0: drawpolycone_multicolor([0,0,0,-2], tube_pos, tube_col, tube_rad) else: if (secondary == 1 and self.proteinStyle == PROTEIN_STYLE_SOLID_RIBBON) or \ secondary == 2: drawtriangle_strip([1.0,1.0,0.0,-2.0], tri_arr0, nor_arr0, col_arr0) drawtriangle_strip([1.0,1.0,0.0,-2.0], tri_arr1, nor_arr1, col_arr1) drawtriangle_strip([1.0,1.0,0.0,-2.0], tri_arr2, nor_arr2, col_arr2) drawtriangle_strip([1.0,1.0,0.0,-2.0], tri_arr3, nor_arr3, col_arr3) # Fill in the strand N-terminal end. quad_tri = [] quad_nor = [] quad_col = [] quad_tri.append(tri_arr2[0]) quad_tri.append(tri_arr3[0]) quad_tri.append(tri_arr2[1]) quad_tri.append(tri_arr3[1]) quad_nor.append(nor_arr2[0]) quad_nor.append(nor_arr3[0]) quad_nor.append(nor_arr2[1]) quad_nor.append(nor_arr3[1]) quad_col.append(col_arr2[0]) quad_col.append(col_arr3[0]) quad_col.append(col_arr2[1]) quad_col.append(col_arr3[1]) drawtriangle_strip([1.0,1.0,1.0,-2.0],quad_tri,quad_nor,quad_col) if (secondary == 1 and self.proteinStyle == PROTEIN_STYLE_FANCY_CARTOONS): drawtriangle_strip([1.0,1.0,0.0,-2.0], tri_arr0, nor_arr0, col_arr0) drawtriangle_strip([1.0,1.0,0.0,-2.0], tri_arr1, nor_arr1, col_arr1) tube_pos_left = [] tube_pos_right = [] new_tube_dpos[0] *= 0.1 new_tube_dpos[1] *= 0.2 new_tube_dpos[-1] *= 0.1 new_tube_dpos[-2] *= 0.2 for p in range(len(tube_pos)): tube_pos_left.append(tube_pos[p] - new_tube_dpos[p]) tube_pos_right.append(tube_pos[p] + new_tube_dpos[p]) tube_rad[p] *= 0.75 drawpolycone_multicolor([0,0,0,-2], tube_pos_left, tube_col, tube_rad) drawpolycone_multicolor([0,0,0,-2], tube_pos_right, tube_col, tube_rad) # else: if (secondary == 1 and style == PROTEIN_STYLE_SIMPLE_CARTOONS): drawcylinder(tube_col[0][0], tube_pos[1], tube_pos[-3], 2.5, capped=1) #print "hopsa" if style == PROTEIN_STYLE_LADDER or \ style == PROTEIN_STYLE_TUBE: # Draw tube. drawpolycone_multicolor([0,0,0,-2], tube_pos, tube_col, tube_rad) # increase Sec. Str. element counter current_sec += 1
def _drawSpecialIndicators(self): """ Overrides superclass method. This draws a transparent cylinder around the segments being resized, to easily distinguish them from other model. @see: basicGraphicsmode._drawSpecialIndicators() """ if self.command: if DEBUG_DRAW_SPHERES_AROUND_ATOMS_AT_BREAK_SITES: breakSitesDict = self._breakSite_marker.getBreakSitesDict() atmList = breakSitesDict.values() for atm in atmList: sphere_radius = max(1.2 * atm.drawing_radius(), SPHERE_RADIUS) drawsphere(darkgreen, atm.posn(), sphere_radius, SPHERE_DRAWLEVEL, opacity=SPHERE_OPACITY) breakSites_atomPairs_dict = self._breakSite_marker.getBreakSites_atomPairsDict( ) for aDict in breakSites_atomPairs_dict.values(): #DEBUG======== for atm1, atm2 in aDict.values(): #Its okay to do this check for only atm1 (for speed reason) #lets assume that atm2 drawing radius will be the same (it won't #be the same in very rare cases....) cyl_radius = max(1.3 * atm1.drawing_radius(), CYL_RADIUS) drawcylinder(red, atm1.posn(), atm2.posn(), cyl_radius, capped=True, opacity=CYL_OPACITY) startAtomsDict = self._breakSite_marker.getStartAtomsDict() for atm in startAtomsDict.values(): sphere_radius = max(1.2 * atm.drawing_radius(), SPHERE_RADIUS_2) color = atm.molecule.color if color is None: color = banana atom_radius = atm.drawing_radius() cyl_radius = 0.5 * atom_radius cyl_height = 2.5 * atom_radius axis_atm = atm.axis_neighbor() direction = None if axis_atm: #Direction will be opposite of direction = norm(atm.posn() - axis_atm.posn()) draw3DFlag(self.glpane, color, atm.posn(), cyl_radius, cyl_height, direction=direction, opacity=0.8)
def _drawSpecialIndicators(self): """ Overrides superclass method. This draws a transparent cylinder around the segments being resized, to easily distinguish them from other model. @see: basicGraphicsmode._drawSpecialIndicators() """ if self.command: if DEBUG_DRAW_SPHERES_AROUND_ATOMS_AT_BREAK_SITES: breakSitesDict = self._breakSite_marker.getBreakSitesDict() atmList = breakSitesDict.values() for atm in atmList: sphere_radius = max(1.2*atm.drawing_radius(), SPHERE_RADIUS) drawsphere(darkgreen, atm.posn(), sphere_radius, SPHERE_DRAWLEVEL, opacity = SPHERE_OPACITY) breakSites_atomPairs_dict = self._breakSite_marker.getBreakSites_atomPairsDict() for aDict in breakSites_atomPairs_dict.values(): #DEBUG======== for atm1, atm2 in aDict.values(): #Its okay to do this check for only atm1 (for speed reason) #lets assume that atm2 drawing radius will be the same (it won't #be the same in very rare cases....) cyl_radius = max(1.3*atm1.drawing_radius(), CYL_RADIUS) drawcylinder(red, atm1.posn(), atm2.posn(), cyl_radius, capped = True, opacity = CYL_OPACITY ) startAtomsDict = self._breakSite_marker.getStartAtomsDict() for atm in startAtomsDict.values(): sphere_radius = max(1.2*atm.drawing_radius(), SPHERE_RADIUS_2) color = atm.molecule.color if color is None: color = banana atom_radius = atm.drawing_radius() cyl_radius = 0.5*atom_radius cyl_height = 2.5*atom_radius axis_atm = atm.axis_neighbor() direction = None if axis_atm: #Direction will be opposite of direction = norm( atm.posn() - axis_atm.posn()) draw3DFlag(self.glpane, color, atm.posn(), cyl_radius, cyl_height, direction = direction, opacity = 0.8)