def downloadResults(self): if not self.run: msg = 'No current iCing run' showWarning('Failure', msg, parent=self) return credentials = self.serverCredentials if not credentials: msg = 'No current iCing server job' showWarning('Failure', msg, parent=self) return fileName = self.resultFileEntry.get() if not fileName: msg = 'No save file specified' showWarning('Failure', msg, parent=self) return if os.path.exists(fileName): msg = 'File %s already exists. Overwite?' % fileName if not showOkCancel('Query', msg, parent=self): return url = self.iCingBaseUrl iCingUrl = self.getServerUrl(url) logText = iCingRobot.iCingFetch(credentials, url, iCingUrl, fileName) print logText msg = 'Results saved to file %s\n' % fileName msg += 'Purge results from iCing server?' if showYesNo('Query',msg, parent=self): self.purgeCingServer()
def removeResonance(self): if self.resonance and self.spinSystem and (self.resonance in self.spinSystem.resonances): if showOkCancel('Confirm','Really remove resonance from spin system?', parent=self): self.spinSystem.codeScoreDict = {} deassignResonance(self.resonance, clearAssignNames=False) removeSpinSystemResonance(self.spinSystem, self.resonance)
def save(self): projName = self.proj_name_entry.get() directory = self.proj_dir_select.getDirectory() directory = joinPath(directory, projName) if self.isProjectDirectory(directory): if not showOkCancel('Overwrite directory', 'Overwrite existing project directory?', parent=self): return self.updateInfo() self.did_save = False changeDataLocations = self.dataCheckButton.isSelected() done = False try: done = Io.saveProject(self.project, newPath=directory, newProjectName=projName, createFallback=True, showYesNo=showYesNo, changeDataLocations=changeDataLocations, showWarning=showWarning) if done: showInfo('Project saved', 'Project saved successfully') self.did_save = True if self.callback: self.callback(self.project) elif self.modal: return # give another chance except Implementation.ApiError, e: showError('Save project', e.error_msg)
def deleteExpSeries(self, *event): if self.expSeries and (self.expSeries.className != 'Experiment'): if showOkCancel('Confirm','Really delete series?', parent=self): self.expSeries.delete() self.expSeries = None self.conditionPoint = None
def transferChainAssignments(chainA, chainB): """Transfer any atomic assignments from one chain to another where possible. .. describe:: Input MolSystem.Chain, MolSystem.Chain .. describe:: Output None """ mapping = getChainResidueMapping(chainA, chainB) for residueA, residueB in mapping: if residueB: resonancesB = getResidueResonances(residueB) if resonancesB: msg = 'Destination residue %s%d has assignments. Continue?.' data = (residueB.seqCode, residueB.ccpCode) if not showOkCancel('Warning', msg % data): return for residueA, residueB in mapping: if residueA: if residueB is None: msg = 'Residue %d%s has no equivalent in destination chain' data = (residueA.seqCode, residueA.ccpCode) showWarning('Warning', msg % data) else: transferResidueAssignments(residueA, residueB)
def setJCoupling(self, index=None): if not index: atomNames = self.atomNames index = couplingAtoms.index(atomNames) else: atomNames = couplingAtoms[index] value = self.jCouplingEntry.get() if self.residue and atomNames: coupling = self.jCouplings[index] if value is None: if coupling: if showOkCancel('Confirm', 'Really remove J coupling?', parent=self): coupling.delete() else: if not coupling: self.setResidueJCoupling(self.measureJCouplingList, self.residue, atomNames, value, isSimulated=False) else: coupling.setValue(value)
def propagatePath(self): dataStores = self.dataStoreTable.currentObjects if self.dataStore and len(dataStores) > 1: sourcePath = self.dataStore.dataUrl.url.dataLocation if os.path.exists(sourcePath): directory = sourcePath elif os.path.exists(os.path.dirname(sourcePath)): directory = os.path.dirname(sourcePath) else: directory = None if not directory: msg = 'Source directory does not exist' showWarning('Failure', msg, parent=self) return msg = 'Transfer path "%s" to selection?' % directory if showOkCancel('Confirm', msg, parent=self): for dataStore in dataStores: if dataStore is self.dataStore: continue if dataStore.dataUrl.url.dataLocation == directory: continue changeDataStoreUrl(dataStore, sourcePath)
def deleteConstraints(self): if self.constrList and showOkCancel( 'Confirm', 'Really delete constraint list?', parent=self): self.constrList.delete() self.constrList = None self.constrListButtons.buttons[0].disable() self.constrListButtons.buttons[2].disable()
def deleteViolations(self): if self.violList and showOkCancel( 'Confirm', 'Really delete violation list?', parent=self): self.violList.delete() self.violList = None self.violListButtons.buttons[0].disable() self.violListButtons.buttons[1].disable()
def deleteNodes(self): if self.selectedNodes: msg = 'Really delete %d selected nodes?' % len(self.selectedNodes) if showOkCancel('Confirm', msg, parent=self): for node in self.selectedNodes[:]: node.delete() self.selectedNodes = [] self.node = None
def deleteChild(self, table): object = table.currentObject if (object): if (showOkCancel( 'Delete object', 'Are you sure you want to delete selected object?', parent=self)): object.delete()
def deleteRun(self): if self.run: msg = 'Really delete calculation run %d?' % self.run.serial if showOkCancel('Query', msg, parent=self): self.run.delete() self.run = None self.updateAfter()
def deleteLinks(self): if self.selectedLinks: msg = 'Really delete %d selected links?' % len(self.selectedLinks) if showOkCancel('Confirm', msg, parent=self): for link in self.selectedLinks[:]: link.delete() self.selectedLinks = [] self.link = None
def setSpectrumMultiplet(self, spectrum, pattern): prevPattern = getSpectrumMultipletPattern(spectrum) if prevPattern and (prevPattern != pattern): if showOkCancel('Query', 'Really change multiplet pattern?', parent=self): setSpectrumMultipletPattern(spectrum, pattern)
def deleteStrucGen(self): if self.strucGen and showOkCancel( 'Confirm', 'Really delete structure generation run?', parent=self): self.strucGen.delete() self.strucGen = None self.constrList = None self.violist = None self.structGenButtons.buttons[0].disable() self.structGenButtons.buttons[1].disable()
def deleteRun(self): if self.dangleStore: msg = 'Really delete DANGLE run "%s"?' % self.dangleStore.name if showOkCancel('Confirm', msg, parent=self): self.dangleStore.delete() self.dangleStore = None self.dangleChain = None self.updatePredictionMatrix() self.updateDangleStorePulldown()
def deleteMeasurements(self): measurements = self.measurementsMatrix.currentObjects if measurements: className = self.measurementListB.className if className == 'ShiftList': msg = 'Really delete %s chemical shifts?' % len(measurements) if not showOkCancel('Confirm', msg, parent=self): return untouched = set() for shift in measurements: for peakDim in shift.peakDims: shiftList = peakDim.peak.peakList.dataSource.experiment.shiftList if shiftList is self.measurementListB: untouched.add(shift) break else: shift.delete() if untouched: if len(untouched) > 1: msg = 'Could not delete %d shifts because they are still assigned to peaks' % len( untouched) else: msg = 'Could not delete shift because it is still assigned to peaks' showWarning('Warning', msg, parent=self) else: msg = 'Really delete %d %s measurements?' % (len(measurements), className[:-4]) if not showOkCancel('Confirm', msg, parent=self): return for measurement in measurements: measurement.delete()
def deleteCloud(self): if self.constraintSet and self.cloud and showOkCancel( 'Confirm', 'Really delete resonance cloud?', parent=self): clouds = self.guiParent.application.getValues( self.constraintSet, 'clouds') if clouds: clouds.remove(self.cloud) self.cloud = None self.guiParent.application.setValues(self.constraintSet, 'clouds', values=clouds) self.updateAfter()
def deassignType(self): if self.spinSystem: residue = self.spinSystem.residue if residue: resText = '%d%s' % (residue.seqCode, residue.ccpCode) msg = 'Spin system assigned to %s. Continue and deassign residue?' if showOkCancel('Warning', msg % resText, parent=self): assignSpinSystemResidue(self.spinSystem, None) assignSpinSystemType(self.spinSystem, None) else: assignSpinSystemType(self.spinSystem,None)
def assign(self): if self.spinSystem and self.ccpCode: if self.spinSystem.residue and (self.spinSystem.residue.ccpCode != self.ccpCode): resText = '%d%s' % (self.spinSystem.residue.seqCode, self.spinSystem.residue.ccpCode) msg = 'Spin system is already assigned to %s. Continue?' if showOkCancel('Warning', msg % resText, parent=self): assignSpinSystemResidue(self.spinSystem,residue=None) else: return if self.spinSystem.ccpCode != self.ccpCode: assignSpinSystemType(self.spinSystem,self.ccpCode,'protein') self.update()
def deleteSelected(self, event=None): objs = self.selectedLinks + self.selectedNodes if objs: n1 = len(self.selectedNodes) n2 = len(self.selectedLinks) msg = 'Really delete %d selected objects?\n' % (n1 + n2) msg += '(%d nodes, %d links)' % (n1, n2) if showOkCancel('Confirm', msg, parent=self): for obj in objs: obj.delete() self.selectedLinks = [] self.link = None self.selectedNodes = [] self.node = None
def deleteClouds(self): if self.names and self.name and showOkCancel( 'Confirm', 'Really remove selected clouds?'): indices = [] for name in self.scrolledMatrix.currentObjects: i = self.names.index(name) indices.append(i) indices.sort() indices.reverse() for i in indices: self.clouds.pop(i) self.rmsds.pop(i) self.names.pop(i) self.name = None self.updateAfter()
def installUpdates(self): if self.isGraphical and not showOkCancel( 'Confirmation', 'Continue with file upgrade?'): return if not self.server: self.warningMessage('Warning', 'No accessible server') return if not self.installRoot: self.warningMessage('Warning', 'No installation path') return updates = self.server.getSelectedUpdates() if not updates: self.warningMessage('Warning', 'No selected updates to install') return needMake = False needMakeClean = False needMakeLinks = False for update in updates: update.setInstallFromCache() if update.fileName.endswith('.c'): needMake = True elif update.fileName.endswith('.h'): needMake = needMakeClean = True elif update.fileName == 'Makefile': needMake = needMakeClean = needMakeLinks = True #if not isWindowsOS(): if False: # 16 Nov 2010: do not even try to compile C code any more self.compileCode(needMakeClean=needMakeClean, needMake=needMake, needMakeLinks=needMakeLinks) if self.isGraphical and not self.isStandAlone: self.warningMessage( 'Notice', 'All updates complete. You must restart Analysis for changes to take effect.' )
def stripGroups(self): self.updateWindows() name = self.windowPulldown.getText() groups = self.scrolledMatrix.currentObjects if groups and name and (name != '<None>'): selected = self.windowPulldown.getText() windowPane, positions = self.orthogonalDict[selected] window = windowPane.spectrumWindow N = len(positions) msg = '%d positions selected. Really make %d strips in window %s' if N > 10 and not showOkCancel('Warning', msg % (N,N,window.name ), parent=self): return displayStrips(self.parent, positions, orthoPositions=None, spectrum=None, windowPane=windowPane) # often fails first time... self.update_idletasks() displayStrips(self.parent, positions, orthoPositions=None, spectrum=None, windowPane=windowPane)
def deleteConditionPoint(self, *event): if self.conditionPoint and (self.expSeries.className != 'Experiment'): if showOkCancel('Confirm','Really delete series point?', parent=self): conditionSet = self.conditionPoint.sampleConditionSet experiments = [e for e in conditionSet.experiments if e in self.expSeries.experiments] for experiment in experiments: self.expSeries.removeExperiment(experiment) for experiment in experiments: for expSeries in experiment.nmrExpSeries: if self.conditionPoint.condition in self.expSeries.conditionNames: break else: continue break else: self.conditionPoint.delete() self.conditionPoint = None
def deleteMeasurementList(self, *event): if self.measurementList: if (len(self.measurementList.experiments) > 0) and (self.measurementList.className == 'ShiftList'): showWarning( 'Warning', 'Deletion of shift lists with associated experiments prohibited', parent=self) return elif len(self.measurementList.measurements) > 0: if showOkCancel('Confirm', 'List is not empty. Really delete?', parent=self): self.measurementList.delete() self.measurementList = None else: return else: self.measurementList.delete() self.measurementList = None
def makeStructureEnsemble(strucDict, molSystem, modelNames=None, doWarnings=False, checkTruncation=True, fixAtomNames=True): """Makes structure ensemble from a structure dictionary [model][chainCode][resNum][atomName] = (x,y,z coords) in a mol system. Options to supress warnings and thus automatically link non-identical, but similar chains or make a new chain if none is found, NB chains and resides are those present in FIRST model atoms are taken from all models, and missing atoms are given x=y=z = 0.0; occupancy=0.0 .. describe:: Input Dictionary, MolSystem.MolSystem, Boolean .. describe:: Output MolStructures.StructureEnsemble """ # Rasmus Fogh 20/6/2011: Changed to new MolStructure model # Rasmus Fogh 4/5/2013:Added automatic name fixing: 2HB -> HB2 # # Set up, and create structure ensemble # ll = sorted(strucDict.keys()) firstModelId = ll[0] project = molSystem.root ensembles = molSystem.sortedStructureEnsembles() if ensembles: eId = ensembles[-1].ensembleId + 1 else: eId = 1 ensemble = project.newStructureEnsemble(molSystem=molSystem, ensembleId=eId) #models = [] #for m in strucDict.keys(): # models.append((m, ensemble.newModel())) # # record data list - for creating and processing records in reading order # recordDataList = [] recordDataDict = {} coordResidues = {} allMsResidues = {} usedChains = [] failedAtoms = [] msAtomDict = {} atomCheckDict = {} systemAtoms = set() chainsDict = strucDict[firstModelId] # match or make chains chCodes = list(chainsDict.keys()) chCodes.sort() nOrigChCodes = len(chCodes) for iChCode, chCode in enumerate(chCodes): resDict = chainsDict[chCode] seqIds = resDict.keys() seqIds.sort() chemComps = [] ccpCodes = [] seqIdsGood = [] # get list of good chemcomps molTypes = set() resNames = [] for seqId in seqIds: ll = resDict[seqId].keys() resName = resDict[seqId][ll[0]]['resName'] atomNames = [tt[0] for tt in ll] chemComp = DataConvertLib.getBestChemComp(project, resName, atomNames) resNames.append(resName) if chemComp: chemComps.append(chemComp) ccpCodes.append(chemComp.ccpCode) seqIdsGood.append(seqId) molTypes.add(chemComp.molType) if not seqIdsGood: msg = 'Could not find any matching CCPN ChemComps for sequence: ' msg += ' '.join(resNames) showWarning('Structure Creation Failed', msg) continue #get matching MolSystem chains seqIds = seqIdsGood msChains, mappings = findMatchingChains(molSystem, ccpCodes, excludeChains=usedChains, doWarning=doWarnings, molTypes=molTypes) nChains = len(msChains) if nChains == 1: msChain = msChains[0] mapping = mappings[0] elif nChains: from memops.gui.DataEntry import askString codes = [c.code for c in msChains] msg = 'Structure chain %s matches %d \nCCPN chains' % (chCode, nChains) msg += ' equally well: %s\n' % (' '.join(codes), ) msg += 'Which CCPN chain should be linked to?' if chCode in codes: default = chCode else: default = codes[0] choice = None while choice not in codes: choice = askString('Query', msg, default) or '' choice = choice.strip() index = codes.index(choice) msChain = msChains[index] mapping = mappings[index] else: msChain = None if nChains: nRes = len(mapping) startPair = 0 endPair = nRes - 1 for i in range(nRes): residueA, residueB = mapping[i] if residueA and residueB: startPair = i break for endTrunc in range(nRes): j = endPair - endTrunc residueA, residueB = mapping[j] if residueA and residueB: endPair = j break mismatch = [] for i in range(startPair, endPair + 1): if None in mapping[i]: mismatch.append(i) break if doWarnings: if checkTruncation and ((endTrunc > 10) or (startPair > 10)): msg = 'Structure truncated (Start:%s, End:%s) ' % ( startPair, endTrunc) msg += 'compared to existing chain. Really link to chain %s?' % msChain.code msg += ' (Otherwise a new chain will be made)' if not showYesNo('Query', msg): msChain = None if mismatch and msChain is not None: msg = 'Imperfect match: %s non-terminal mismatches, ' % len( mismatch) msg += 'compared to existing chain. Really link to chain %s?' % msChain.code msg += ' (Otherwise a new chain will be made)' if not showYesNo('Query', msg): msChain = None else: if checkTruncation and (startPair or endTrunc): print( 'WARNING, Structure truncated (Start:%s, End:%s) rel. to existing chain.' % (startPair, endTrunc)) if mismatch: print 'WARNING, Imperfect match: %s non-terminal mismatches' % len( mismatch) if not msChain: # no matching chain - make new one # use existing chain code from PDB file if possible sysChainCode = chCode.strip() if not sysChainCode or molSystem.findFirstChain(code=sysChainCode): sysChainCode = nextChainCode(molSystem) if molTypes == set(('DNA', )) and iChCode <= nOrigChCodes: # check for special case: # double stranded DNA with a single chain code oneLetterCodes = [cc.code1Letter for cc in chemComps] if None not in oneLetterCodes: # All ChemComps are (variants of) Std bases. # Not sure certain, but this should mostly work. nCodes = len(oneLetterCodes) halfway, remainder = divmod(nCodes, 2) if not remainder: # even number of codes resMap = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'} for ii in range(halfway): if oneLetterCodes[ii] != resMap[oneLetterCodes[ -1 - ii]]: break else: # the second half is the reverse complement of the first half. # treat as two separate DNA chains # Move second half to a new chain, and remove from this chain. newChCode = chCode while newChCode in chCodes: newChCode = chr(ord(newChCode) + 1) newResDict = chainsDict[newChCode] = {} for ii in range(halfway, nCodes): iix = seqIds[ii] newResDict[iix] = resDict[iix] del resDict[iix] # put both chains on end of list for later (re)processing chCodes.append(chCode) chCodes.append(newChCode) continue codes = (molSystem.code, sysChainCode) msg = 'Structure residue sequence (chain %s) not in molecular system. ' % chCode msg += 'Make new molecular system %s chain (%s) for this sequence?' % codes if not doWarnings or (not molSystem.chains) or ( doWarnings and showOkCancel('Confirm', msg)): atomNames = resDict[seqIds[0]].keys() molType = chemComps[0].molType ccpCodes0 = [] startNum = resDict[seqIds[0]][atomNames[0]]['seqCode'] project = molSystem.root molecule = makeMolecule(project, molType, []) for i in range(len(seqIds)): chemComp = chemComps[i] if (chemComp.molType != molType) or ( i and (seqIds[i] != seqIds[i - 1] + 1)): newMolResidues = addMolResidues(molecule, molType, ccpCodes0, startNum=startNum) # set seqCodes and seqInsertCodes xSeqIds = seqIds[i - len(newMolResidues):i] for j, x in enumerate(xSeqIds): rr = newMolResidues[j] for dummy in resDict[x]: # future-safe of getting a random atomDict for seqId x dd = resDict[x][dummy] break rr.seqCode = dd['seqCode'] rr.seqInsertCode = dd['insertCode'] ccpCodes0 = [ chemComp.ccpCode, ] molType = chemComp.molType startNum = seqIds[i] else: ccpCodes0.append(chemComp.ccpCode) if ccpCodes0: addMolResidues(molecule, molType, ccpCodes0, startNum=startNum) msChain = makeChain(molSystem, molecule, code=sysChainCode) resMapping = {} for i, residue in enumerate(msChain.sortedResidues()): resMapping[i] = residue # TBD deal with HETATMs, proper Molecule name, # store CCPN xml as non-standard naming system? else: continue else: # msChain is not None sysChainCode = msChain.code resMapping = {} for i, residue in mapping: resMapping[i] = residue usedChains.append(msChain) atomNamesList = [] msResidues = [] for j, seqId in enumerate(seqIds): atomNames = [tt[0] for tt in resDict[seqId].keys()] if fixAtomNames: # change names to get right naming system. for ii, name in enumerate(atomNames): if name[0] in '123': atomNames[ii] = name[1:] + name[0] atomNamesList.append(atomNames) msResidue = resMapping.get(j) msResidues.append(msResidue) namingSystem = DataConvertLib.getBestNamingSystem( msResidues, atomNamesList) coordChain = ensemble.newChain(code=sysChainCode) #ensemble.override = True # # Done making chain - start adding residues to chain # for j, seqId in enumerate(seqIds): msResidue = msResidues[j] if not msResidue: # Structure is bigger continue resName = ccpCodes[j] ccpCode = msResidue.ccpCode if doWarnings: if resName != ccpCode: msg = 'Residue names [%s,%s] don\'t match\nin' msg += ' loaded molecular system\nchain %s position %d' data = (resName, ccpCode, chCode, seqId) showWarning('Warning', msg % data) continue if msResidue is None: msg = 'No equivalent molecular system residue' msg += '\nfor PDB chain %s residue %d' showWarning('Warning', msg % (chCode, seqId)) continue coordResidue = coordChain.newResidue( seqCode=msResidue.seqCode, seqInsertCode=msResidue.seqInsertCode, seqId=msResidue.seqId) coordResidues[(chCode, seqId)] = coordResidue allMsResidues[(chCode, seqId)] = msResidue # # Now make atoms # for atomKey, coordDict in resDict[seqId].items(): atomName, altLoc = atomKey key = '%s:%s:%s' % (atomName, msResidue, namingSystem) if key in msAtomDict: systemAtom = msAtomDict.get(key) else: systemAtom = DataConvertLib.findMatchingMolSystemAtom( atomName, msResidue, namingSystem, systemAtoms, fixAtomNames=fixAtomNames) msAtomDict[key] = systemAtom if (systemAtom is None) or atomCheckDict.get( (systemAtom, altLoc)): #print '### failing', atomName failedAtoms.append( '%s %d %s %4s' % (chCode, seqId, msResidue.ccpCode, atomName)) continue systemAtoms.add(systemAtom) #print '### adding', atomName, systemAtom.name atomCheckDict[(systemAtom, altLoc)] = True tt = (coordDict.get('recordId'), (chCode, seqId, atomKey), coordResidue, systemAtom.name, coordDict) recordDataList.append(tt) recordDataDict[(chCode, seqId, atomKey)] = tt # # Finished getting data for reading order from first model # # Now loop over other models and add new atoms to existing residues # ignoring new residues and chains, to cater for varying atom presence # for modelInd, chainsDict in sorted(strucDict.items()[1:]): for chCode, resDict in sorted(chainsDict.items()): for seqId, atomDict in sorted(resDict.items()): coordResidue = coordResidues.get((chCode, seqId)) msResidue = allMsResidues.get((chCode, seqId)) if coordResidue is None or msResidue is None: continue for atomKey, coordDict in atomDict.items(): tt = recordDataDict.get((chCode, seqId, atomKey)) if tt is None: # new atom, make new record atomName, altLoc = atomKey key = '%s:%s:%s' % (atomName, msResidue, namingSystem) if key in msAtomDict: systemAtom = msAtomDict.get(key) else: systemAtom = DataConvertLib.findMatchingMolSystemAtom( atomName, msResidue, namingSystem, systemAtoms, fixAtomNames=fixAtomNames) msAtomDict[key] = systemAtom if (systemAtom is None) or atomCheckDict.get( (systemAtom, altLoc)): failedAtoms.append( '%s %d %s %4s' % (chCode, seqId, msResidue.ccpCode, atomName)) continue print '### NBNB add extra atom:', (chCode, seqId, atomKey) systemAtoms.add(systemAtom) atomCheckDict[(systemAtom, altLoc)] = True tt = (coordDict.get('recordId'), (chCode, seqId, atomKey), coordResidue, systemAtom.name, coordDict) recordDataList.append(tt) recordDataDict[(chCode, seqId, atomKey)] = tt # # Finished getting data for reading order # # sort by recordId. If not set - or if duplicate recordId # will sort by full key. recordDataList.sort() # nAtoms = len(recordDataList) # # Create atoms # for tt in recordDataList: recordId, fullKey, coordResidue, atomName, coordDict = tt # make coordAtom coordResidue.newAtom(name=atomName, altLocationCode=fullKey[2][1]) # # set data for all models # kk = 0 for modelInd, chainsDict in sorted(strucDict.items()): #create model model = ensemble.newModel() if modelNames: model.name = modelNames[kk] kk += 1 # set up for data reading coordinates = [0.0] * (3 * nAtoms ) # NB deliberate this is 0.0, not None # There might be atoms missing in other models occupancies = [1.0] * nAtoms bFactors = [0.0] * nAtoms ii = 0 jj = 0 hasOccupancies = False hasBFactors = False for tt in recordDataList: recordId, fullKey, coordResidue, atomName, coordDict = tt resDict = chainsDict.get(fullKey[0]) if resDict: atomDict = resDict.get(fullKey[1]) if atomDict: coordDict = atomDict.get(fullKey[2]) #try: # xxx = atomDict[fullKey[2]] # coordDict = xxx #except: # print '###', atomDict.keys(), tt if coordDict: # get data for model coordinates[jj] = coordDict['x'] jj += 1 coordinates[jj] = coordDict['y'] jj += 1 coordinates[jj] = coordDict['z'] jj += 1 occupancy = coordDict.get('occupancy', 1.0) if occupancy != 1.0: occupancies[ii] = occupancy hasOccupancies = True bFactor = coordDict.get('bFactor', 0.0) if bFactor != 0.0: bFactors[ii] = bFactor hasBFactors = True ii += 1 else: # This atom not found in this model # Just leave default values, set occupancy to 0 # and increment indices # NBNB this leaves coordinates as 0.0 NBNBNB occupancies[ii] = 0.0 hasOccupancies = True ii += 1 jj += 3 # fill data into model model.setSubmatrixData('coordinates', coordinates) if hasOccupancies: model.setSubmatrixData('occupancies', occupancies) if hasBFactors: model.setSubmatrixData('bFactors', bFactors) # final validity check try: ensemble.checkAllValid() except: ensemble.delete() return # reset switches #ensemble.override = False if failedAtoms: ll = sorted(set(failedAtoms)) ll = [x for x in ll if not ('Q' in x[-5:] or '*' in x[-5:])] #skipAtoms = (' HT1', ' HT2', ' HT3', ' 1HT', ' 2HT', ' 3HT', ' OXT', # ' OT1', ' OT2', ' 1H', ' 2H', ' 3H') #ll = [x for x in failedAtoms # if 'Q' not in x # and not [x.endswith(y) for y in skipAtoms]] if ll: print( '## WARNING %s failed atoms. Unique, non-pesudo atoms are:' % len(failedAtoms), ', '.join(ll)) if failedAtoms and doWarnings: msg = 'No equivalent molecular system atoms for PDB atoms: %s' showWarning('Warning', msg % (' '.join(failedAtoms))) if not ensemble.coordChains: ensemble.delete() ensemble = None return ensemble
def getLatestRelease(self): # assumes is in correct directory (so far) # fetches latest release # returns name of release file (not full path, just file name) ss = '' use_precompiled = False try: from ccpnmr.analysis.Version import platform, bits, arch, built_by if built_by == 'ccpn': if platform == 'linux': ss = '_%s%s' % (platform, bits) use_precompiled = True elif platform == 'darwin': if arch != 'ppc': arch = 'intel' ss = '_%s' % arch use_precompiled = True except: pass self.use_precompiled = use_precompiled if use_precompiled: extension = 'tgz' else: extension = 'tar.gz' fileName = 'analysis%s%s%s.%s' % ( self.server.version, self.server.minor_version, ss, extension) self.releaseFile = None addr = 'http://' + joinPath(self.httpServer, self.homeDir, self.httpDir, fileName) try: url = urllib.urlopen(addr) except: self.server.parent.warningMessage('Download failed', 'Could not connect to %s' % addr) return data = url.read() url.close() destFile = joinPath(self.baseDir, self.releaseDir, fileName) try: fp = open(destFile, 'wb') except: self.server.parent.warningMessage( 'Saving release failed', 'Could not save release to %s' % destFile) fp.write(data) fp.close() self.releaseFile = fileName if self.server.parent.isGraphical: if showOkCancel( 'Query', 'Can CCPN log your IP address for its statistics? No other information will be taken' ): self.logDownload() else: print 'CCPN is logging your IP address for its statistics. No other information will be taken' self.logDownload()
def installLatestRelease(self): if self.server: msg = 'Current version is %s - ' % self.version + \ 'You must upgrade to version %s to get updates. ' % self.server.version + \ 'Continue with automatic upgrade to the latest major release? ' + \ '(Old version will not be deleted from disk)' if self.isGraphical and not showOkCancel('Confirmation', msg): return if not self.server: self.warningMessage('Warning', 'No accessible server') return if not self.installRoot: self.warningMessage('Warning', 'No installation path') return releaseUpdate = ReleaseUpdate(self.server, self.installRoot, self.version) success = releaseUpdate.installRelease() if success: self.server.parent.version = self.server.version if success and self.isGraphical: self.server.getFileUpdates() if self.server.fileUpdates and showOkCancel( 'Confirmation', 'Also install any updates to new release?'): wasGraphical = self.isGraphical self.isGraphical = False self.installNewUpdates() for fileUpdate in self.server.getSelectedUpdates(): print 'Updated %s in %s' % (fileUpdate.fileName, fileUpdate.filePath) self.isGraphical = wasGraphical if hasattr(self, 'parent'): if not self.isStandAlone: self.warningMessage( 'Notice', 'Release update complete. Program will exit. Restart for changes to take effect.' ) parent = self.parent # parent.project does not exist in some contexts (e.g. updateCheck) if hasattr(parent, 'project') and parent.project: if not parent.checkSaving(): return parent.destroy() # Need the below code to fix the problem with Bash # where the commend line was getting screwed up on exit. if os.name == 'posix': os.system('stty sane') sys.exit(0) else: if not self.isStandAlone: self.warningMessage( 'Notice', 'Release update complete. You must restart for changes to take effect.' )
def runCingServer(self): if not self.project: return run = self.run if not run: msg = 'No CING run setup' showWarning('Failure', msg, parent=self) return structure = self.structure if not structure: msg = 'No structure ensemble selected' showWarning('Failure', msg, parent=self) return ensembleText = getModelsString(run) if not ensembleText: msg = 'No structural models selected from ensemble' showWarning('Failure', msg, parent=self) return residueText = getResiduesString(structure) if not residueText: msg = 'No active residues selected in structure' showWarning('Failure', msg, parent=self) return url = self.iCingBaseUrlPulldown.getObject() url.strip() if not url: msg = 'No iCing server URL specified' showWarning('Failure', msg, parent=self) self.iCingBaseUrl = None return msg = 'Submit job now? You will be informed when the job is done.' if not showOkCancel('Confirm', msg, parent=self): return self.iCingBaseUrl = url iCingUrl = self.getServerUrl(url) self.serverCredentials, results, tarFileName = iCingRobot.iCingSetup(self.project, userId='ccpnAp', url=iCingUrl) if not results: # Message already issued on failure self.serverCredentials = None self.resultsUrl = None self.update() return else: credentials = self.serverCredentials os.unlink(tarFileName) entryId = iCingRobot.iCingProjectName(credentials, iCingUrl).get(iCingRobot.RESPONSE_RESULT) baseUrl, htmlUrl, logUrl, zipUrl = iCingRobot.getResultUrls(credentials, entryId, url) self.resultsUrl = htmlUrl # Save server data in this run for persistence setRunParameter(run, iCingRobot.FORM_USER_ID, self.serverCredentials[0][1]) setRunParameter(run, iCingRobot.FORM_ACCESS_KEY, self.serverCredentials[1][1]) setRunParameter(run, ICING_BASE_URL, url) setRunParameter(run, HTML_RESULTS_URL, htmlUrl) self.update() run.inputStructures = structure.sortedModels() # select residues from the structure's chain #iCingRobot.iCingResidueSelection(credentials, iCingUrl, residueText) # Select models from ensemble #iCingRobot.iCingEnsembleSelection(credentials, iCingUrl, ensembleText) # Start the actual run self.serverDone = False iCingRobot.iCingRun(credentials, iCingUrl) # Fetch server progress occasionally, report when done # this function will call itself again and again self.after(CHECK_INTERVAL, self.timedCheckStatus) self.update()