def candidNmrCalcRun(nmrCalcRun): """ Modify nmrCalcRun from generic MultiStructure form to CANDID-specific Input: nmrCalcRun: NmrCalc.Run """ xx = nmrCalcRun.findFirstRunParameter(name='shiftFormat') if xx is None: raise Exception("shiftFormat must be set for UNIO_CANDID protocols") else: shiftFormat = xx.textValue xx = nmrCalcRun.findFirstRunParameter(name='peakFormat') if xx is None: raise Exception("peakFormat must be set for UNIO_CANDID protocols") else: peakFormat = xx.textValue shiftFileSuffix = intUtil.getFileFormatData(shiftFormat, 'shift')['shiftExt'] peakFileSuffix = intUtil.getFileFormatData(peakFormat, 'peak')['peakExt'] # name : code dictionary for resetting code values codeRemapping = { 'solvent': 'SolventType', 'spectrumType': 'PeakType', 'spectrumKind': 'PeakKind', 'numDataSets': 'NoPeakList', } # set proper codes for existing data parameters for runParameter in nmrCalcRun.sortedRunParameters(): newCode = codeRemapping.get(runParameter.name) if newCode is not None: runParameter.code = newCode # Reset spectrumType strings for runParameter in nmrCalcRun.findAllRunParameters(name='spectrumType'): ss = runParameter.textValue if ss in spectrumTypes: # Spectrum type should be remapped runParameter.textValue = spectrumTypes[ss] # get data sets peakListObjs = [ x for x in nmrCalcRun.sortedData() if x.className == 'PeakListData' ] shiftListObjs = {} for datum in nmrCalcRun.findAllData(className='MeasurementListData'): measurementList = datum.measurementList if measurementList.className == 'ShiftList': shiftListObjs[measurementList] = datum # create data set files and parameters numDataSets = 0 usePeakListObjs = [] for peakListData in peakListObjs: numDataSets += 1 # check and set spectrum kind dataSource = peakListData.dataSource spectrumKind = getSpectrumKind(dataSource) if spectrumKind is None: print 'WARNING, incorrect spectrum type. Removing %s' % peakListData for runParameter in peakListData.runParameters: runParameter.delete() peakListData.delete() numDataSets -= 1 continue # note in order to select shiftlist later usePeakListObjs.append(peakListData) # Reset connected parameters #for runParameter in peakListData.runParameters: # code = runParameter.code # if code: # runParameter.code = code + '[%s]' % numDataSets nmrCalcRun.newRunParameter( name='spectrumKind', data=peakListData, code=codeRemapping['spectrumKind'], # + '[%s]' % numDataSets), textValue=spectrumKind) # check and set shiftlist and related parameters experiment = dataSource.experiment shiftList = experiment.shiftList shiftListData = shiftListObjs.get(shiftList) if shiftListData is None: shiftListData = nmrCalcRun.newMeasurementListData( name='shiftList', measurementList=shiftList) shiftListObjs[shiftList] = shiftListData shiftFile = intUtil.objectFileName(shiftList, suffix=shiftFileSuffix, compact=True) nmrCalcRun.newRunParameter(name='fileName', textValue=shiftFile, data=shiftListData) nmrCalcRun.newRunParameter(name='fileFormat', textValue=shiftFormat, data=shiftListData) useFormat = shiftFormat else: shiftFile = shiftListData.findFirstRunParameter( name='fileName').textValue useFormat = shiftListData.findFirstRunParameter( name='fileFormat').textValue nmrCalcRun.newRunParameter(name='fileNameShift', textValue=shiftFile, code='fileNameShift', data=peakListData) nmrCalcRun.newRunParameter(name='fileFormatShift', textValue=shiftFormat, code='fileFormatShift', data=peakListData) fileNamePeakList = intUtil.objectFileName(peakListData.peakList, suffix=peakFileSuffix, compact=True) nmrCalcRun.newRunParameter(name='fileName', textValue=fileNamePeakList, code='fileNamePeak', data=peakListData) nmrCalcRun.newRunParameter(name='fileFormat', textValue=peakFormat, code='fileFormatPeak', data=peakListData) # number of data sets nmrCalcRun.newRunParameter(name='numDataSets', code=codeRemapping['numDataSets'], intValue=numDataSets) # choose shift list for backbone if shiftListObjs: if len(shiftListObjs) == 1: shiftData = list(shiftListObjs.items())[0][1] fileName = shiftData.findFirstRunParameter( name='fileName').textValue fileFormat = shiftData.findFirstRunParameter( name='fileFormat').textValue else: shiftListScore = 0 for peakListData in usePeakListObjs: # check preferred shiftlist spectrumKind = peakListData.findFirstRunParameter( name='spectrumKind').textValue spectrumType = peakListData.findFirstRunParameter( name='spectrumType').textValue shiftFileWeight = (preferredShiftWeights.get(spectrumKind, 0) + preferredShiftWeights.get(spectrumType, 0)) if shiftFileWeight > shiftListScore: shiftListScore = shiftFileWeight fileName = peakListData.findFirstRunParameter( name='fileNameShift').textValue fileFormat = peakListData.findFirstRunParameter( name='fileFormatShift').textValue # main shift list nmrCalcRun.newRunParameter(name='fileNameShift', code='fileNameCaCbShift', textValue=fileName) nmrCalcRun.newRunParameter(name='fileFormatShift', code='fileFormatCaCbShift', textValue=fileFormat)
def asdpNmrCalcRun(nmrCalcRun): """ Modify nmrCalcRun from generic MultiStructure form to ASDP-specific Input: nmrCalcRun: NmrCalc.Run """ # CCPN params xx = nmrCalcRun.findFirstRunParameter(name='shiftFormat') if xx is None: raise Exception("shiftFormat must be set for ASDP protocols") else: shiftFormat = xx.textValue xx = nmrCalcRun.findFirstRunParameter(name='peakFormat') if xx is None: raise Exception("peakFormat must be set for ASDP protocols") else: peakFormat = xx.textValue shiftFileSuffix = intUtil.getFileFormatData(shiftFormat, 'shift')['shiftExt'] peakFileSuffix = intUtil.getFileFormatData(peakFormat, 'peak')['peakExt'] # name : code dictionary for resetting code values codeRemapping = { #'spectrumType':'x1.type', 'jobName': 'proteinName', #'numDataSets':None, } # set proper codes for existing data parameters for runParameter in nmrCalcRun.sortedRunParameters(): name = runParameter.name if name in codeRemapping: runParameter.code = codeRemapping[name] # get data sets peakListObjs = [ x for x in nmrCalcRun.sortedData() if x.className == 'PeakListData' ] shiftListObjs = {} for datum in nmrCalcRun.findAllData(className='MeasurementListData'): measurementList = datum.measurementList if measurementList.className == 'ShiftList': shiftListObjs[measurementList] = datum defaultTol = 1.0 runParam = nmrCalcRun.findFirstRunParameter(name='defaultTolPoints') if runParam: val = runParam.floatValue if val: defaultTol = val minTol = 0.02 runParam = nmrCalcRun.findFirstRunParameter(name='minTolPpm') if runParam: val = runParam.floatValue if val: minTol = val # create data set files and parameters for peakListData in peakListObjs: dataSource = peakListData.dataSource experiment = dataSource.experiment dimCodes = getDimCodes(dataSource) if (None in dimCodes or not experiment.findFirstExpTransfer( transferType='through-space')): print("Removed spectrum %s: not recognised as 2D-4D NOESY" % dataSource) for runParameter in peakListData.runParameters: runParameter.delete() peakListData.delete() continue # peak file name fileNamePeakList = intUtil.objectFileName(peakListData.peakList, suffix=peakFileSuffix, compact=True) nmrCalcRun.newRunParameter(name='fileName', textValue=fileNamePeakList, code='fileNamePeak', data=peakListData) nmrCalcRun.newRunParameter(name='fileFormat', textValue=peakFormat, data=peakListData) nmrCalcRun.newRunParameter(name='numDim', code='dimension', intValue=dataSource.numDim, data=peakListData) # interchain NOEs not supported nmrCalcRun.newRunParameter(name='haveInterChain', code='haveIC', intValue=0, data=peakListData) nmrCalcRun.newRunParameter(name='interChain', code='IC', intValue=0, data=peakListData) # Solvent runParameter = peakListData.findFirstRunParameter(name='solvent') if runParameter.textValue == 'h2o': val = 1 else: val = 0 nmrCalcRun.newRunParameter(name='solventH2O', code='waterFlag', intValue=val, data=peakListData) runParameter.delete() # column data nmrCalcRun.newRunParameter(name='intensityColumn', code='col.intensity', intValue=dataSource.numDim + 4, data=peakListData) isotopeCodes = getIsotopeCodesList(dataSource) tolerances = AssignmentBasic.estimateAssignmentTolerances( dataSource, defPoints=defaultTol, minTol=minTol) # Dimension parameters: for ii, dataDim in enumerate(dataSource.sortedDataDims()): dimCode = dimCodes[ii] # Peak position column column tag = 'col.%s' % dimCode nmrCalcRun.newRunParameter(name='PositionColumn', code=tag, intValue=ii + 2, data=peakListData) # Shift correction (set to default) tag = '%s.shift' % dimCode nmrCalcRun.newRunParameter(name='ShiftCorrection', code=tag, floatValue=0.0, data=peakListData) # sign (meaning ???) (set to default) tag = '%s.sign' % dimCode nmrCalcRun.newRunParameter(name=tag, code=tag, intValue=0, data=peakListData) # Assignment tolerance tag = '%s.tol' % dimCode nmrCalcRun.newRunParameter(name='AssignTolerance', code=tag, floatValue=tolerances[ii], data=peakListData) # sw in ppm tag = '%s.sw' % dimCode swOrig = 1000.0 # NBNB program probably assumes that all shifts are within SW. # As long as peak positions are correct, swOrig is not useful. # Leave at default #for dataDimRef in dataDim.sortedDataDimRefs(): # if dataDimRef.expDimRef.measurementType in ('shift','Shift'): # swOrig = dataDimRef.spectralWidthOrig nmrCalcRun.newRunParameter(name='swPpm', code=tag, floatValue=swOrig, data=peakListData) # dimension type isotopeCode = isotopeCodes[ii] if isotopeCode == '1H': dimType = 'H' elif isotopeCode == '13C': dimType = 'C13' specTypeObj = peakListData.findFirstRunParameter( name='spectrumType') if specTypeObj: dimType = spectrumTypes.get( specTypeObj.textValue) or dimType else: ii = 0 while isotopeCode[ii] in '0123456789': ii += 1 dimType = isotopeCode[ii:] + isotopeCode[:ii] tag = '%s.type' % dimCode nmrCalcRun.newRunParameter(name='dimensionType', code=tag, textValue=dimType, data=peakListData) # check and set shiftlist and related parameters shiftList = experiment.shiftList shiftListData = shiftListObjs.get(shiftList) if shiftListData is None: shiftListData = nmrCalcRun.newMeasurementListData( name='shiftList', measurementList=shiftList) shiftListObjs[shiftList] = shiftListData shiftFile = intUtil.objectFileName(shiftList, suffix=shiftFileSuffix, compact=True) nmrCalcRun.newRunParameter(name='fileName', textValue=shiftFile, data=shiftListData) nmrCalcRun.newRunParameter(name='fileFormat', textValue=shiftFormat, data=shiftListData) useFormat = shiftFormat # main shift list if shiftListObjs: if len(shiftListObjs) == 1: shiftData = list(shiftListObjs.items())[0][1] fileName = shiftData.findFirstRunParameter( name='fileName').textValue fileFormat = shiftData.findFirstRunParameter( name='fileFormat').textValue nmrCalcRun.newRunParameter(name='fileNameShift', code='chemicalShiftFile', textValue=fileName, data=shiftData) nmrCalcRun.newRunParameter(name='fileFormatShift', code='fileFormatShift', textValue=fileFormat, data=shiftData) else: raise Exception("All spectra must use same shift list for ASDP")