def createShift(self, resonance, chemShift): keywds = {} # # Also set ambiguity code if listed # if chemShift.ambCode != None: setUniqueAppData('AppDataInt', resonance, self.format, 'ambiguityCode', chemShift.ambCode) # # Shift error could be missing... # if hasattr(chemShift, 'error'): keywds['error'] = chemShift.error # # Create shift linked to resonance # self.convertCount[self.mainCode][1][self.valueCode] += 1 return Nmr.Shift(self.measurementList, value=chemShift.value, resonance=resonance, **keywds)
def createShift(self,resonance,chemShift): # # Also set ambiguity code if listed # if chemShift.ambCode != None: setUniqueAppData('AppDataInt',resonance,self.format,'ambiguityCode',chemShift.ambCode) # # Create shift linked to resonance # return Nmr.Shift(self.measurementList, value = chemShift.value, resonance = resonance)
def createShift(self,resonance,chemShift): # # For xeasy also use chemShift to create atomSerial application data. # # Warning: if there is already an atomSerial available for this resonance # it will be overwritten!! # applData = resonance.findFirstApplicationData(application = self.format, keyword = self.atomSerialKeyword) if applData: resonance.removeApplicationData(applData) resonance.addApplicationData(Implementation.AppDataInt(application = self.format, keyword = self.atomSerialKeyword, value = chemShift.atomSerial)) # # Create shift linked to resonance # return Nmr.Shift(self.measurementList, value = chemShift.value, error = chemShift.valueError, resonance = resonance)
def createChemShifts(peakLists, guiParent=None, messageReporter=None, multiDialog=None, shiftList=None, useAllContribs=1, defaultShiftError=None, shiftListName='None'): # # Set up GUI or non-GuI user interaction if not passed in # if not messageReporter: messageReporter = setupMessageReporter(guiParent) if not multiDialog: multiDialog = setupMultiDialog(guiParent) # # Initial checks # if not peakLists: messageReporter.showError("Error", "No peaklist(s) provided.") return False for peakList in peakLists: if not isinstance(peakList, Nmr.PeakList): messageReporter.showError("Error", "Invalid peaklist provided.") return False # # Initialize some stuff # if not defaultShiftError: defaultShiftError = {} for (nucl, defValue) in (('1H', 0.002), ('13C', 0.1), ('15N', 0.1)): if not defaultShiftError.has_key(nucl): defaultShiftError[nucl] = defValue proj = peakLists[0].root resonanceChemShifts = {} experiments = [] # # Read the chemshifts and link them to the relevant resonances # for peakList in peakLists: if peakList.dataSource.experiment not in experiments: experiments.append(peakList.dataSource.experiment) for peak in peakList.sortedPeaks(): for peakDim in peak.sortedPeakDims(): chemShift = peakDim.value peakDimContribs = tuple(peakDim.peakDimContribs) if useAllContribs == 0 and len(peakDimContribs) > 1: # # First check if resonances for contribs connected through one resonanceSet # If so, then set values anyway. # resonanceSet = peakDimContribs[0].resonance.resonanceSet sameShiftGroup = 1 if resonanceSet: resonanceSetResonances = resonanceSet.sortedResonances( ) for peakDimContrib in peakDimContribs[1:]: if peakDimContrib.resonance not in resonanceSetResonances: sameShiftGroup = 0 break if not sameShiftGroup: # # Ignore this peakDim - many contribs possible and not wanted (?) # print " Warning: ignoring peakDim %d for peak %d... more than one resonance contribution" % ( peakDim.dim, peak.serial) continue for peakDimContrib in peakDimContribs: resonance = peakDimContrib.resonance if not resonanceChemShifts.has_key(resonance): resonanceChemShifts[resonance] = [] resonanceChemShifts[resonance].append(chemShift) # # Make a new chemical shift list if none passed in # if shiftList == None: shiftList = Nmr.ShiftList(proj.currentNmrProject, name=shiftListName, unit='ppm', experiments=experiments) # # Get the average (and standard dev) of the chemical shift for each resonance # Create the chemical shifts # for resonance in resonanceChemShifts.keys(): chemShiftTotal = 0.0 for chemShift in resonanceChemShifts[resonance]: chemShiftTotal += chemShift chemShiftAverage = chemShiftTotal / len(resonanceChemShifts[resonance]) standardDev = getStandardDev(resonanceChemShifts[resonance], chemShiftTotal) if standardDev == None: if defaultShiftError.has_key(resonance.isotopeCode): shiftError = defaultShiftError[resonance.isotopeCode] else: shiftError = 0.1 else: shiftError = standardDev * 2 # # Set the chemical shift value # shift = shiftList.findFirstMeasurement(resonance=resonance) if not shift: Nmr.Shift(shiftList, value=chemShiftAverage, error=shiftError, resonance=resonance) else: allowedErrorMargin = shiftError / 10 if shift.value + allowedErrorMargin < chemShiftAverage or chemShiftAverage < shift.value - allowedErrorMargin: resName = getResNameText(resonance) multiDialog.MeasurementSelect(guiParent, resName, resonance, chemShiftAverage, shiftList, 'Shift') return shiftList