def partChanged(self, selectedItem): """ Method called when user changed the partlib browser tree. @param selectedItem: Item currently selected in the L{self.partLib} @type selectedItem: L{self.partLib.FileItem} @attention: This is called in the L{PM_TreeView.mouseReleaseEvent}. The 'selectionChanged' signal for self.partLib apparently was not emitted so that code has been removed. """ #Copying some old code from deprecated MMKit.py -- ninad 2007-09-06 item = selectedItem self.newModel = None if isinstance(item, self.partLib.FileItem): mmpFile = str(item.getFileObj()) if os.path.isfile(mmpFile): self.newModel = \ Assembly(self.w, os.path.normpath(mmpFile), run_updaters = True # desirable for PartLib [bruce 080403] ) self.newModel.set_glpane( self.elementViewer) # sets its .o and .glpane readmmp(self.newModel, mmpFile) self.newModel.update_parts( ) #k not sure if needed after readmmp self.newModel.checkparts() if self.newModel.shelf.members: for m in self.newModel.shelf.members[:]: m.kill() #k guess about a correct way to handle them self.newModel.update_parts() #k probably not needed self.newModel.checkparts() #k probably not needed self._updateElementViewer(self.newModel)
def partChanged(self, selectedItem): """ Method called when user changed the partlib browser tree. @param selectedItem: Item currently selected in the L{self.partLib} @type selectedItem: L{self.partLib.FileItem} @attention: This is called in the L{PM_TreeView.mouseReleaseEvent}. The 'selectionChanged' signal for self.partLib apparently was not emitted so that code has been removed. """ #Copying some old code from deprecated MMKit.py -- ninad 2007-09-06 item = selectedItem self.newModel = None if isinstance(item, self.partLib.FileItem): mmpFile = str(item.getFileObj()) if os.path.isfile(mmpFile): self.newModel = \ Assembly(self.w, os.path.normpath(mmpFile), run_updaters = True # desirable for PartLib [bruce 080403] ) self.newModel.set_glpane(self.elementViewer) # sets its .o and .glpane readmmp(self.newModel, mmpFile) self.newModel.update_parts() #k not sure if needed after readmmp self.newModel.checkparts() if self.newModel.shelf.members: for m in self.newModel.shelf.members[:]: m.kill() #k guess about a correct way to handle them self.newModel.update_parts() #k probably not needed self.newModel.checkparts() #k probably not needed self._updateElementViewer(self.newModel)
def _libPageView(self, isFile = False): item = self.dirView.selectedItem() if not isFile and not isinstance(item, self.FileItem): self.newModel = None self.elemGLPane.updateModel(self.newModel) return mmpfile = str(item.getFileObj()) if os.path.isfile(mmpfile): #self.newModel = Assembly(self.w, "Assembly 1") self.newModel = Assembly(self.w, os.path.normpath(mmpfile)) #ninad060924 to fix bug 1164 self.newModel.o = self.elemGLPane ## Make it looks "Assembly" used by glpane. readmmp(self.newModel, mmpfile) # What we did in Qt 3: ## #self.newModel = Assembly(self.w, "Assembly 1") ## self.newModel = Assembly(self.w, os.path.normpath(mmpfile)) #ninad060924 to fix bug 1164 ## self.newModel.o = self.elemGLPane ## Make it looks "Assembly" used by glpane. ## readmmp(self.newModel, mmpfile) ## # The following is absolute nonsense, and is part of what's breaking the fix of bug 2028, ## # so it needs to be revised, to give this assy a standard structure. ## # We'll have to find some other way to draw the hotspot singlet ## # (e.g. a reasonable, straightforward way). So we did -- MMKitView.always_draw_hotspot is True. ## # [bruce 060627] ## ## # Move all stuff under assembly.tree into assy.shelf. This is needed to draw hotspot singlet ## ## def addChild(child): ## ## self.newModel.shelf.addchild(child) ## ## ## ## # Remove existing clipboard items from the libary part before adopting childern from 'tree'. ## ## self.newModel.shelf.members = [] ## ## self.newModel.tree.apply2all(addChild) ## ## ## ## self.newModel.shelf.prior_part = None ## ## self.newModel.part = Part(self.newModel, self.newModel.shelf) ## if 1: #bruce 060627 self.newModel.update_parts() #k not sure if needed after readmmp) self.newModel.checkparts() if self.newModel.shelf.members: if debug_flags.atom_debug: print "debug warning: library part %r contains clipboard items" % mmpfile # we'll see if this is common # happens for e.g. nanokids/nanoKid-C39H42O2.mmp for m in self.newModel.shelf.members[:]: m.kill() #k guess about a correct way to handle them self.newModel.update_parts() #k probably not needed self.newModel.checkparts() #k probably not needed else: self.newModel = None self.elemGLPane.updateModel(self.newModel)
def insertBaseFromMmp(filename, subgroup, tfm, position = position): """ Insert the atoms for a nucleic acid base from an MMP file into a single chunk. - If atomistic, the atoms for each base are in a separate chunk. - If PAM5, the pseudo atoms for each base-pair are together in a chunk. @param filename: The mmp filename containing the base (or base-pair). @type filename: str @param subgroup: The part group to add the atoms to. @type subgroup: L{Group} @param tfm: Transform applied to all new base atoms. @type tfm: V @param position: The origin in space of the DNA duplex, where the 3' end of strand A is 0, 0, 0. @type position: L{V} """ try: ok, grouplist = readmmp(assy, filename, isInsert = True) except IOError: raise PluginBug("Cannot read file: " + filename) if not grouplist: raise PluginBug("No atoms in DNA base? " + filename) viewdata, mainpart, shelf = grouplist for member in mainpart.members: # 'member' is a chunk containing a set of base-pair atoms. for atm in member.atoms.values(): atm._posn = tfm(atm._posn) + position if atm.element.symbol in ('Se3', 'Ss3', 'Ss5'): if atm.getDnaBaseName() == "a": baseLetter = currentBaseLetter else: try: baseLetter = \ basesDict[currentBaseLetter]['Complement'] except: # If complement not found, just assign same # letter. baseLetter = currentBaseLetter if 0: print "Ss(%r) being set to %r." \ % (atm.getDnaBaseName(), baseLetter) atm.setDnaBaseName(baseLetter) member.name = currentBaseLetter subgroup.addchild(member) baseList.append(member) # Clean up. del viewdata shelf.kill()
def insertBaseFromMmp(filename, subgroup, tfm, position=position): """ Insert the atoms for a nucleic acid base from an MMP file into a single chunk. - If atomistic, the atoms for each base are in a separate chunk. - If PAM5, the pseudo atoms for each base-pair are together in a chunk. @param filename: The mmp filename containing the base (or base-pair). @type filename: str @param subgroup: The part group to add the atoms to. @type subgroup: L{Group} @param tfm: Transform applied to all new base atoms. @type tfm: V @param position: The origin in space of the DNA duplex, where the 3' end of strand A is 0, 0, 0. @type position: L{V} """ try: ok, grouplist = readmmp(assy, filename, isInsert=True) except IOError: raise PluginBug("Cannot read file: " + filename) if not grouplist: raise PluginBug("No atoms in DNA base? " + filename) viewdata, mainpart, shelf = grouplist for member in mainpart.members: # 'member' is a chunk containing a set of base-pair atoms. for atm in member.atoms.values(): atm._posn = tfm(atm._posn) + position if atm.element.symbol in ('Se3', 'Ss3', 'Ss5'): if atm.getDnaBaseName() == "a": baseLetter = currentBaseLetter else: try: baseLetter = \ basesDict[currentBaseLetter]['Complement'] except: # If complement not found, just assign same # letter. baseLetter = currentBaseLetter if 0: print "Ss(%r) being set to %r." \ % (atm.getDnaBaseName(), baseLetter) atm.setDnaBaseName(baseLetter) member.name = currentBaseLetter subgroup.addchild(member) baseList.append(member) # Clean up. del viewdata shelf.kill()
def read_mmp_single_part(assy, filename): from files.mmp.files_mmp import readmmp # start incredible kluge block history = env.history #bruce 050901 revised this. # It depends on there being only one active history object at a time. # (Before 050913, that object was stored as both env.history and win.history.) oldmessage = history.message from utilities.constants import noop history.message = noop # don't bother user with this file being nonstd (bad, should pass a flag, so other errors seen) try: ok, grouplist = readmmp(assy, filename, isInsert = True) finally: history.message = oldmessage if grouplist: viewdata, mainpart, shelf = grouplist return mainpart.steal_members() # a python list of whatever toplevel stuff was in the mmp file return None
def insert_output(self, outfiles, params, name): ## return self.create_methane_test(params, name) if debug_run(): print "inserting output from", outfiles ###@@@ # modified from dna generator's local function insertmmp(filename, tfm) assert len(outfiles) == 1 # for now filename = outfiles[0] assert filename.endswith( '.mmp' ) # for now; in future, also permit .pdb or anything else we know how to read assy = self.win.assy #k from files.mmp.files_mmp import readmmp ok_junk, grouplist = readmmp(assy, filename, isInsert=True) # WARNING: ok_junk is not a boolean; see readmmp doc for details if not grouplist: raise Exception( "Trouble with output file: " + filename ) ###@@@ predict NameError: Exception (good enough for now) viewdata, mainpart, shelf = grouplist if len(mainpart.members) == 1: thing = mainpart.members[0] else: thing = mainpart # won't happen for now del viewdata #k or kill? thing.name = name shelf.kill() # wware 060704 - fix valence problems on the ends while True: found_one = False for atm in thing.atoms.values(): if atm.element.symbol == 'C' and len(atm.realNeighbors()) == 1: atm.kill() found_one = True if not found_one: break for atm in thing.atoms.values(): if atm.element.symbol == 'C' and len(atm.realNeighbors()) == 2: atm.set_atomtype('sp2', always_remake_bondpoints=True) # problem: for some kinds of errors, the only indication is that we're inserting a 0-atom mol, not a many-atom mol. hmm. ####@@@@ return thing # doesn't actually insert it, GBC does that
def insert_output(self, outfiles, params, name): ## return self.create_methane_test(params, name) if debug_run(): print "inserting output from",outfiles ###@@@ # modified from dna generator's local function insertmmp(filename, tfm) assert len(outfiles) == 1 # for now filename = outfiles[0] assert filename.endswith('.mmp') # for now; in future, also permit .pdb or anything else we know how to read assy = self.win.assy #k from files.mmp.files_mmp import readmmp ok_junk, grouplist = readmmp(assy, filename, isInsert = True) # WARNING: ok_junk is not a boolean; see readmmp doc for details if not grouplist: raise Exception("Trouble with output file: " + filename)###@@@ predict NameError: Exception (good enough for now) viewdata, mainpart, shelf = grouplist if len(mainpart.members) == 1: thing = mainpart.members[0] else: thing = mainpart # won't happen for now del viewdata #k or kill? thing.name = name shelf.kill() # wware 060704 - fix valence problems on the ends while True: found_one = False for atm in thing.atoms.values(): if atm.element.symbol == 'C' and len(atm.realNeighbors()) == 1: atm.kill() found_one = True if not found_one: break for atm in thing.atoms.values(): if atm.element.symbol == 'C' and len(atm.realNeighbors()) == 2: atm.set_atomtype('sp2', always_remake_bondpoints = True) # problem: for some kinds of errors, the only indication is that we're inserting a 0-atom mol, not a many-atom mol. hmm. ####@@@@ return thing # doesn't actually insert it, GBC does that