diff options
author | Mark Sims <mark@nanorex.com> | 2008-12-23 21:24:51 +0000 |
---|---|---|
committer | Mark Sims <mark@nanorex.com> | 2008-12-23 21:24:51 +0000 |
commit | 7704e22b57466a1f51294169bd5828457999ad7a (patch) | |
tree | aa8c0739777387bfebe62b69fdc417fc6a73e23b | |
parent | 798c3f541ec33c797c3cf80945b952f68af531ed (diff) | |
download | nanoengineer-theirix-7704e22b57466a1f51294169bd5828457999ad7a.tar.gz nanoengineer-theirix-7704e22b57466a1f51294169bd5828457999ad7a.zip |
Renamed class PeptideLineMode to PeptideLine_GraphicsMode. Cleaned up code docstrings and variable names. Also added more comments that were sorely needed.
-rw-r--r-- | cad/src/graphics/drawing/drawPeptideTrace.py | 58 | ||||
-rw-r--r-- | cad/src/protein/commands/InsertPeptide/InsertPeptide_EditCommand.py | 80 | ||||
-rwxr-xr-x | cad/src/protein/commands/InsertPeptide/PeptideGenerator.py | 21 | ||||
-rw-r--r-- | cad/src/protein/temporary_commands/PeptideLine_GraphicsMode.py (renamed from cad/src/protein/temporary_commands/PeptideLineMode.py) | 72 |
4 files changed, 128 insertions, 103 deletions
diff --git a/cad/src/graphics/drawing/drawPeptideTrace.py b/cad/src/graphics/drawing/drawPeptideTrace.py index 188f62f9e..d4718b97c 100644 --- a/cad/src/graphics/drawing/drawPeptideTrace.py +++ b/cad/src/graphics/drawing/drawPeptideTrace.py @@ -28,35 +28,49 @@ from utilities.constants import blue, gray from protein.commands.InsertPeptide.PeptideGenerator import get_unit_length -def drawPeptideTrace_new(mol): - - if mol and \ - mol.atoms: +def drawPeptideTrace(alphaCarbonProteinChunk): + """ + Draws a protein backbone trace using atoms stored in + I{alphaCarbonProteinChunk}. + + @param alphaCarbonProteinChunk: a special (temporary) chunk that contains + only the alpha carbon atoms in the peptide + backbone + @param alphaCarbonProteinChunk: Chunk + + @see PeptideLine_GraphicsMode.Draw(), PeptideGenerator.make_aligned() + """ + if alphaCarbonProteinChunk and alphaCarbonProteinChunk.atoms: last_pos = None - - atomitems = mol.atoms.items() - + atomitems = alphaCarbonProteinChunk.atoms.items() atomitems.sort() - atlist = [atom for (key, atom) in atomitems] + alphaCarbonAtomsList = [atom for (key, atom) in atomitems] - for atom in atlist: + for atom in alphaCarbonAtomsList: drawsphere(blue, atom.posn(), 0.2, 1) if last_pos: drawline(gray, last_pos, atom.posn(), width=2) last_pos = atom.posn() - -def drawPeptideTrace(endCenter1, - endCenter2, - phi, - psi, - glpaneScale, - lineOfSightVector, - beamThickness = 2.0, - beam1Color = None, - beam2Color = None, - stepColor = None - ): + pass + pass + return + +# drawPeptideTrace_orig is the original function for drawing a peptide +# trace. This function is deprecated and marked for removal. I'm keeping it +# here for reference for the time being. +# --Mark 2008-12-23 +def drawPeptideTrace_orig(endCenter1, + endCenter2, + phi, + psi, + glpaneScale, + lineOfSightVector, + beamThickness = 2.0, + beam1Color = None, + beam2Color = None, + stepColor = None + ): """ Draws the Peptide in a schematic display. @@ -88,6 +102,7 @@ def drawPeptideTrace(endCenter1, @see: B{DnaLineMode.Draw } (where it is used) for comments on color convention + @deprecated: Use drawPeptideTrace() instead. """ ladderWidth = 3.0 @@ -172,3 +187,4 @@ def drawPeptideTrace(endCenter1, glPopMatrix() glEnable(GL_LIGHTING) + return diff --git a/cad/src/protein/commands/InsertPeptide/InsertPeptide_EditCommand.py b/cad/src/protein/commands/InsertPeptide/InsertPeptide_EditCommand.py index 881e17e1a..cc93183f6 100644 --- a/cad/src/protein/commands/InsertPeptide/InsertPeptide_EditCommand.py +++ b/cad/src/protein/commands/InsertPeptide/InsertPeptide_EditCommand.py @@ -15,7 +15,7 @@ from command_support.EditCommand import EditCommand from protein.commands.InsertPeptide.PeptideGenerator import PeptideGenerator from utilities.constants import gensym from commands.SelectChunks.SelectChunks_GraphicsMode import SelectChunks_GraphicsMode -from protein.temporary_commands.PeptideLineMode import PeptideLine_GM +from protein.temporary_commands.PeptideLine_GraphicsMode import PeptideLine_GraphicsMode from utilities.debug import print_compact_stack, print_compact_traceback import foundation.env as env @@ -24,10 +24,8 @@ from utilities.prefs_constants import cursorTextColor_prefs_key from protein.commands.BuildProtein.BuildProtein_Command import BuildProtein_Command from protein.commands.InsertPeptide.InsertPeptide_PropertyManager import InsertPeptide_PropertyManager -#_superclass = BuildProtein_Command _superclass = EditCommand class InsertPeptide_EditCommand(EditCommand): -#class InsertPeptide_EditCommand(BuildProtein_Command): PM_class = InsertPeptide_PropertyManager @@ -43,10 +41,8 @@ class InsertPeptide_EditCommand(EditCommand): create_name_from_prefix = True - #GraphicsMode_class = SelectChunks_GraphicsMode - #Graphics Mode set to Peptide graphics mode - GraphicsMode_class = PeptideLine_GM - #required by NanotubeLine_GM + GraphicsMode_class = PeptideLine_GraphicsMode + #required by PeptideLine_GraphicsMode mouseClickPoints = [] structGenerator = PeptideGenerator() @@ -58,10 +54,10 @@ class InsertPeptide_EditCommand(EditCommand): """ Constructor for InsertPeptide_EditCommand """ - _superclass.__init__(self, commandSequencer) - #Maintain a list of peptide segments created while this command was running. - self._segmentList = [] + #Maintain a list of peptides created while this command is running. + self._peptideList = [] + return def command_entered(self): """ @@ -71,26 +67,27 @@ class InsertPeptide_EditCommand(EditCommand): _superclass.command_entered(self) #NOTE: Following code was copied from self.init_gui() that existed #in old command API -- Ninad 2008-09-18 - if isinstance(self.graphicsMode, PeptideLine_GM): + if isinstance(self.graphicsMode, PeptideLine_GraphicsMode): self._setParamsForPeptideLineGraphicsMode() self.mouseClickPoints = [] - #Clear the segmentList as it may still be maintaining a list of segments + #Clear the peptideList as it may still be maintaining a list of peptides #from the previous run of the command. - self._segmentList = [] + self._peptideList = [] ss_idx, self.phi, self.psi, aa_type = self._gatherParameters() + return def command_will_exit(self): """ Extends superclass method. @see: basecommand.command_will_exit() for documentation """ - if isinstance(self.graphicsMode, PeptideLine_GM): + if isinstance(self.graphicsMode, PeptideLine_GraphicsMode): self.mouseClickPoints = [] self.graphicsMode.resetVariables() - self._segmentList = [] + self._peptideList = [] _superclass.command_will_exit(self) - + return def _getFlyoutToolBarActionAndParentCommand(self): """ @@ -115,7 +112,6 @@ class InsertPeptide_EditCommand(EditCommand): bool_keep = _superclass.keep_empty_group(self, group) return bool_keep - def _gatherParameters(self): """ @@ -128,6 +124,7 @@ class InsertPeptide_EditCommand(EditCommand): Overrides EditCommand.runCommand """ self.struct = None + return def _createStructure(self): """ @@ -157,8 +154,12 @@ class InsertPeptide_EditCommand(EditCommand): -self.win.glpane.pov) """ from geometry.VQT import V - pos1 = V(self.mouseClickPoints[0][0], self.mouseClickPoints[0][1], self.mouseClickPoints[0][2]) - pos2 = V(self.mouseClickPoints[1][0], self.mouseClickPoints[1][1], self.mouseClickPoints[1][2]) + pos1 = V(self.mouseClickPoints[0][0], \ + self.mouseClickPoints[0][1], \ + self.mouseClickPoints[0][2]) + pos2 = V(self.mouseClickPoints[1][0], \ + self.mouseClickPoints[1][1], \ + self.mouseClickPoints[1][2]) struct = self.structGenerator.make_aligned(self.win.assy, name, aa_type, @@ -166,8 +167,8 @@ class InsertPeptide_EditCommand(EditCommand): self.psi, pos1, pos2, - fake_chain=False, - secondary=self.secondary) + fake_chain = False, + secondary = self.secondary) self.win.assy.part.topnode.addmember(struct) self.win.win_update() @@ -191,36 +192,35 @@ class InsertPeptide_EditCommand(EditCommand): self.previousParams = params self.struct = self._createStructure() - + return def cancelStructure(self): """ - Overrides Editcommand.cancelStructure ..calls _removeSegments which - deletes all the segments created while this command was running + Overrides Editcommand.cancelStructure. Calls _removePeptides which + deletes all the peptides created while this command was running. @see: B{EditCommand.cancelStructure} """ _superclass.cancelStructure(self) - self._removeSegments() + self._removePeptides() + return - def _removeSegments(self): + def _removePeptides(self): """ - Remove the segments created while in this command - - This deletes all the segments created while this command was running + Deletes all the peptides created while this command was running @see: L{self.cancelStructure} """ - segmentList = self._segmentList + peptideList = self._peptideList - #for segment in segmentList: - #can segment be None? Lets add this condition to be on the safer + #for peptide in peptideList: + #can peptide be None? Lets add this condition to be on the safer #side. - # if segment is not None: - # segment.kill_with_contents() + # if peptide is not None: + # peptide.kill_with_contents() # self._revertNumber() - - self._segmentList = [] - self.win.win_update() + self._peptideList = [] + self.win.win_update() + return def createStructure(self): """ @@ -240,8 +240,8 @@ class InsertPeptide_EditCommand(EditCommand): self.preview_or_finalize_structure(previewing = True) - #Now append this ntSegment to self._segmentList - self._segmentList.append(self.struct) + #Now append this peptide to self._peptideList + self._peptideList.append(self.struct) #clear the mouseClickPoints list self.mouseClickPoints = [] @@ -290,7 +290,7 @@ class InsertPeptide_EditCommand(EditCommand): def getCursorText(self, endPoint1, endPoint2): """ This is used as a callback method in PeptideLineLine mode - @see: PeptideLineMode.setParams, PeptideLineMode_GM.Draw + @see: PeptideLine_GraphicsMode.setParams, PeptideLine_GraphicsMode.Draw """ text = '' diff --git a/cad/src/protein/commands/InsertPeptide/PeptideGenerator.py b/cad/src/protein/commands/InsertPeptide/PeptideGenerator.py index def5bc767..00fd47dc8 100755 --- a/cad/src/protein/commands/InsertPeptide/PeptideGenerator.py +++ b/cad/src/protein/commands/InsertPeptide/PeptideGenerator.py @@ -615,7 +615,9 @@ class PeptideGenerator: # structure which is aligned along the Z axis. bLine = pt2 - pt1 bLength = vlen(bLine) - b = bLine/bLength + if bLength == 0: + return + b = bLine / bLength # <b> is the unit vector parallel to the line (i.e. pt1, pt2). axis = cross(a, b) # <axis> is the axis of rotation. @@ -639,7 +641,8 @@ class PeptideGenerator: # Bruce suggested I add this. It works here, but not if its # before move() and rot() above. Mark 2008-04-11 - chunk.full_inval_and_update() + chunk.full_inval_and_update() + return def get_number_of_res(self, pos1, pos2, phi, psi): """ @@ -654,9 +657,15 @@ class PeptideGenerator: """ return 1 + int(vlen(pos2 - pos1) / get_unit_length(phi, psi)) - def make_aligned(self, assy, name, aa_idx, phi, psi, - pos1, pos2, secondary=SS_COIL, - fake_chain=False, length=None): + def make_aligned(self, + assy, + name, + aa_idx, + phi, psi, + pos1, pos2, + secondary = SS_COIL, + fake_chain = False, + length = None): """ Build and return a chunk that is a homo-peptide aligned to a pos2-pos1 vector. @@ -679,7 +688,7 @@ class PeptideGenerator: @param fake_chain: if True, create only C-alpha atoms. used for drawing peptide trace image during interactive peptide placement (used by - PeptideLineMode.py) + PeptideLine_GraphicsMode.py) @type fake_chain: boolean @param length: optional peptide length (number of amino acids), if diff --git a/cad/src/protein/temporary_commands/PeptideLineMode.py b/cad/src/protein/temporary_commands/PeptideLine_GraphicsMode.py index 606ad747d..48bb1ade5 100644 --- a/cad/src/protein/temporary_commands/PeptideLineMode.py +++ b/cad/src/protein/temporary_commands/PeptideLine_GraphicsMode.py @@ -1,18 +1,15 @@ # Copyright 2007-2008 Nanorex, Inc. See LICENSE file for details. """ -@author: Urmi +@author: Urmi, Mark @copyright: 2008 Nanorex, Inc. See LICENSE file for details. @version: $Id$ @license: GPL - - """ - from temporary_commands.LineMode.Line_Command import Line_Command from temporary_commands.LineMode.Line_GraphicsMode import Line_GraphicsMode -from graphics.drawing.drawPeptideTrace import drawPeptideTrace, drawPeptideTrace_new +from graphics.drawing.drawPeptideTrace import drawPeptideTrace, drawPeptideTrace_orig from utilities.constants import gray, black, darkred, blue, white @@ -20,11 +17,11 @@ from protein.commands.InsertPeptide.PeptideGenerator import PeptideGenerator, ge # == GraphicsMode part -class PeptideLine_GM( Line_GraphicsMode ): +class PeptideLine_GraphicsMode( Line_GraphicsMode ): """ - Custom GraphicsMode for use as a component of PeptideLineMode. - @see: L{PeptideLineMode} for more comments. - @see: InsertPeptide_EditCommand where this is used as a GraphicsMode class. + Custom GraphicsMode used while interactively drawing a peptide chain for + the "Insert Peptide" command. + @see: InsertPeptide_EditCommand where this class is used. """ # The following valuse are used in drawing the 'sphere' that represent the @@ -39,7 +36,7 @@ class PeptideLine_GM( Line_GraphicsMode ): def leftUp(self, event): """ - Left up method + Left up method. """ if self.command.mouseClickLimit is None: if len(self.command.mouseClickPoints) == 2: @@ -47,7 +44,8 @@ class PeptideLine_GM( Line_GraphicsMode ): self.command.createStructure() self.glpane.gl_update() - return + pass + return def snapLineEndPoint(self): """ @@ -73,32 +71,34 @@ class PeptideLine_GM( Line_GraphicsMode ): """ Line_GraphicsMode.Draw(self) if self.endPoint2 is not None and \ - self.endPoint1 is not None: - #Urmi 20080804: In absence of a better representation, this is a - #placeholder for now. May be Piotr can implement a better representation - #for drawing protein secondary structure - # Draw the ladder. + self.endPoint1 is not None: - #print "command = ", self.command - #print "phi = ", self.command.phi + # Generate a special chunk that contains only alpha carbon atoms + # that will be used to draw the peptide backbone trace. + alphaCarbonProteinChunk = \ + self.structGenerator.make_aligned( + self.win.assy, "", 0, + self.command.phi, + self.command.psi, + self.endPoint1, + self.endPoint2, + fake_chain = True) - mol = self.structGenerator.make_aligned(self.win.assy, "", 0, - self.command.phi, - self.command.psi, - self.endPoint1, - self.endPoint2, - fake_chain=True) + drawPeptideTrace(alphaCarbonProteinChunk) - drawPeptideTrace_new(mol) - - """ - drawPeptideTrace(self.endPoint1, - self.endPoint2, - 135, - -135, - self.glpane.scale, - self.glpane.lineOfSight, - beamThickness = 4.0 - ) - """ + # The original way of drawing the peptide trace. + # This function is deprecated and marked for removal. + # --Mark 2008-12-23 + #drawPeptideTrace_orig(self.endPoint1, + #self.endPoint2, + #135, + #-135, + #self.glpane.scale, + #self.glpane.lineOfSight, + #beamThickness = 4.0 + #) + + pass + return + pass # end of class PeptideLine_GraphicsMode |