def __init__(self, command): """ Constructor for the Nanotube property manager. """ self.endPoint1 = None self.endPoint2 = None self.nanotube = NanotubeParameters() # A 5x5 CNT. _superclass.__init__(self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_CANCEL_BUTTON | \ PM_WHATS_THIS_BUTTON)
def setProps(self, props): """ Sets some properties. These will be used while editing the structure. (but if the structure is read from an mmp file, this won't work. As a fall back, it returns some constant values) @see: InsertNanotube_EditCommand.createStructure which calls this method. @see: self.getProps, EditNanotube_EditCommand.editStructure """ (_n, _m), _type, _endings, (_endPoint1, _endPoint2) = props from cnt.model.NanotubeParameters import NanotubeParameters self.nanotube = NanotubeParameters() self.nanotube.setChirality(_n, _m) self.nanotube.setType(_type) self.nanotube.setEndings(_endings) self.nanotube.setEndPoints(_endPoint1, _endPoint2)
def _createStructure(self): """ Returns the current NanotubeSegment being edited with a new nanotube chunk. @return : Nanotube segment that include the new nanotube chunk. @rtype: L{NanotubeSegment} """ try: # Create a new nanotube chunk using new params. n, m, type, endings, endPoint1, endPoint2 = self._gatherParameters() from cnt.model.NanotubeParameters import NanotubeParameters self.nanotube = NanotubeParameters() nanotube = self.nanotube nanotube.setChirality(n, m) nanotube.setType(type) nanotube.setEndings(endings) nanotube.setEndPoints(endPoint1, endPoint2) position = V(0.0, 0.0, 0.0) ntChunk = nanotube.build(self.struct.name, self.win.assy, position) nanotube.computeEndPointsFromChunk(ntChunk) # Needed. self.struct.addchild(ntChunk) #WARNING 2008-03-05: #When we actually permit modifying a nanotube without recreating it, #then the following properties must be set in self._modifyStructure #as well. Needs more thought. props =(nanotube.getChirality(), nanotube.getType(), nanotube.getEndings(), nanotube.getEndPoints()) self.struct.setProps(props) return self.struct except (PluginBug, UserError): self.struct.kill() raise PluginBug("Internal error while trying to recreate a NanotubeSegment.") return None
def readmmp_info_opengroup_setitem(self, key, val, interp): """ [extends superclass method] """ #bruce 080507 refactoring (split this out of the superclass method) if key == ['nanotube-parameters']: # val includes all the parameters, separated by commas. n, m, type, endings = val.split(",") self.n = int(n) self.m = int(m) self.type = type.lstrip() self.endings = endings.lstrip() # Create the nanotube. from cnt.model.NanotubeParameters import NanotubeParameters self.nanotube = NanotubeParameters() # Returns a 5x5 CNT. self.nanotube.setChirality(self.n, self.m) self.nanotube.setType(self.type) self.nanotube.setEndings(self.endings) # The endpoints are recomputed every time it is edited. else: _superclass.readmmp_info_opengroup_setitem(self, key, val, interp) return
def modifyStructure_NEW_SEGMENT_RESIZE(self): #@ NOT FIXED """ Called when a resize handle is dragged to change the length of the segment. (Called upon leftUp) . This method assigns the new parameters for the segment after it is resized and calls preview_or_finalize_structure which does the rest of the job. Note that Client should call this public method and should never call the private method self._modifyStructure. self._modifyStructure is called only by self.preview_or_finalize_structure @see: B{EditNanotube_ResizeHandle.on_release} (the caller) @see: B{SelectChunks_GraphicsMode.leftUp} (which calls the the relevent method in DragHandler API. ) @see: B{exprs.DraggableHandle_AlongLine}, B{exprs.DragBehavior} @see: B{self.preview_or_finalize_structure } @see: B{self._modifyStructure} As of 2008-02-01 it recreates the structure @see: a note in self._createStructure() about use of ntSegment.setProps """ #TODO: need to cleanup this and may be use use something like #self.previousParams = params in the end -- 2008-03-24 (midnight) #@TODO: - rename this method from modifyStructure_NEW_SEGMENT_RESIZE #to self.modifyStructure, after more testing #This method is used for debug prefence: #'Nanotube Segment: resize without recreating whole duplex' #see also self._modifyStructure_NEW_SEGMENT_RESIZE if self.grabbedHandle is None: return self.propMgr.endPoint1 = self.grabbedHandle.fixedEndOfStructure self.propMgr.endPoint2 = self.grabbedHandle.currentPosition DEBUG_DO_EVERYTHING_INSIDE_MODIFYSTRUCTURE_METHOD = False if DEBUG_DO_EVERYTHING_INSIDE_MODIFYSTRUCTURE_METHOD: # TO DO: this entire block of code. --Mark 2008-04-03 print_compact_stack("modifyStructure_NEW_SEGMENT_RESIZE(): NOT FIXED") length = vlen(self.grabbedHandle.fixedEndOfStructure - \ self.grabbedHandle.currentPosition ) endAtom1, endAtom2 = self.struct.getAxisEndAtoms() #@ for atm in (endAtom1, endAtom2): if not same_vals(self.grabbedHandle.fixedEndOfStructure, atm.posn()): ladderEndAxisAtom = atm break endPoint1, endPoint2 = self.struct.nanotube.getEndPoints() old_dulex_length = vlen(endPoint1 - endPoint2) nanotubeRise = self.struct.getProps() #@ params_to_set_in_propMgr = ( self.grabbedHandle.origin, self.grabbedHandle.currentPosition, ) ##self._modifyStructure(params) ############################################ self.nanotube = NanotubeParameters() #@ Creates 5x5 CNT. Missing PM params. length_diff = self._determine_how_to_change_length() ladderEndAxisAtom = self.get_axisEndAtom_at_resize_end() #@ #@ Nanotube class needs modify() method. self.nanotube.modify(self.struct, length_diff, ladderEndAxisAtom.posn(), self.grabbedHandle.currentPosition) #TODO: Important note: How does NE1 know that structure is modified? #Because number of base pairs parameter in the PropMgr changes as you #drag the handle . This is done in self.getCursorText() ... not the #right place to do it. OR that method needs to be renamed to reflect #this as suggested in that method -- Ninad 2008-03-25 self.preview_or_finalize_structure(previewing = True) ##self.previousParams = params_to_set_in_propMgr self.glpane.gl_update() return