# As usual, create the BMRB Entry object. entryStore = project.newNmrEntryStore(name=project.name) entry = entryStore.newEntry(name=project.name) # Get the molSystem object, and link to it. molSystem = project.sortedMolSystems()[0] entry.setMolSystem(molSystem) # Link the structureGeneration object so that the restraints # are part of the BMRB Entry object. entry.addStructureGeneration(strucGen) # Make a test NOESY experiment. refExpType = 'noesy_hsqc_HNH.hhn' refExp = getRefExpFromOldExpType(project, refExpType) nmrExp = createExperiment(project, 'noesyTest', refExp) nmrExp.addMolSystem(molSystem) # Link the experiment to the BMRB Entry. entry.addExperiment(nmrExp) # Save the project to XML files using a sub routine - see above. saveProject(project, name='testSave', subDir='../data/cnsOut') # Sub routine to print where data for the CCPN project is saved. printReposUrls(project) curDir = os.path.abspath('../data') nmrStarDir = os.path.join(curDir, 'nmrStar')
sequenceFile = os.path.join(dataDir,inputSequenceFileName) nmrViewFormat.readSequence(sequenceFile, minimalPrompts = 1) # # Read in the chemical shifts (set minimalPrompts = 0 for more user interaction during this process) # chemShiftFile = os.path.join(dataDir,inputChemShiftFileName) nmrViewFormat.readShifts(chemShiftFile, minimalPrompts = 1) # # Create an NMR experiment. This is based on the NmrExpPrototype setup. # refExp = getRefExpFromOldExpType(ccpnProject,expTypeName) nmrExp = createExperiment(ccpnProject,expName,refExp) nmrDataSource = createPpmFreqDataSource(nmrExp,'test','processed',nmrExp.numDim) # # Read in a peak list (connected to the experiment that was just created) # peakListFile = os.path.join(dataDir,inputPeakListFileName) nmrViewFormat.readPeaks(peakListFile, dataSource = nmrDataSource,minimalPrompts = 1) # # Run linkresonances... before running this there is on the one hand the NMR # information (peaks, shifts) linked to the 'Resonance' objects, and on the # other hand the sequence information (molecules, chains, residues, atoms), but # they are not linked to each other.
def readPeakList(self, fileName, refExperimentOldName, spectrumName, peakListDimOrder): if self.fileNameDict.has_key(fileName): self.peakList = self.fileNameDict[fileName] else: refExperiment = getRefExpFromOldExpType(self.ccpnProject, refExperimentOldName) self.experiment = self.ccpnProject.currentNmrProject.findFirstExperiment( name=spectrumName, refExperiment=refExperiment) if not self.experiment: self.experiment = createExperiment(self.ccpnProject, spectrumName, refExperiment) self.dataSource = self.experiment.findFirstDataSource( dataType='processed') if not self.dataSource: self.dataSource = createPpmFreqDataSource( self.experiment, spectrumName, 'processed', self.experiment.numDim) self.peakList = self.dataSource.findFirstPeakList( name=spectrumName) # # Determine the peak list relationship # In ccp data model setup assuming that: # - first dim is acquisition # - first hetero dim belongs to acquisition dim # protonDims = [] heteroDims = [] for dataDim in self.dataSource.sortedDataDims(): if '1H' in dataDim.findFirstDataDimRef( ).expDimRef.isotopeCodes: protonDims.append(dataDim.findFirstDataDimRef()) else: heteroDims.append(dataDim.findFirstDataDimRef()) dataDimRefs = self.experiment.numDim * [''] for dim in range(0, len(peakListDimOrder)): peakListDim = returnInt(peakListDimOrder[dim]) if peakListDim: if dim >= 2: dataDimRef = heteroDims[dim - 2] else: dataDimRef = protonDims[dim - 2] dataDimRefs[peakListDim - 1] = dataDimRef self.peakLists = self.format.readPeaks(fileName, dataSource=self.dataSource, dataDimRefs=dataDimRefs, specName=spectrumName, peakList=self.peakList, minimalPrompts=1) if self.experiment not in self.chemShiftList.experiments: self.chemShiftList.addExperiment(self.experiment) return self.peakLists
def ccpNmrConversion(self): ccpNmrConv = Tool() ccpNmrConv.setupProject(self.xmlFile.conversion.project.filename, self.xmlFile.conversion.project.name) ccpNmrConv.setupMolSystem( self.xmlFile.conversion.molecular_system.name) self.tagAriaInput(ccpNmrConv.molSystem) # # Molecules # molecules = self.xmlFile.conversion.molecular_system.molecule if type(molecules) != type([]): molecules = [molecules] for molecule in molecules: ccpNmrConv.setupFormat(molecule.sequence_format) if not hasattr(molecule, 'segID'): segID = defaultMolCode else: segID = molecule.segID ccpNmrConv.readSequence(molecule.sequence_filename, molecule.name, molecule.type, segID, molecule.first_residue_number) # # Spectra # spectra = self.xmlFile.conversion.spectrum if type(spectra) != type([]): spectra = [spectra] for spectrum in spectra: ccpNmrConv.setupFormat(spectrum.data_files_format) if spectrum.chemical_shifts.filename: shiftList = ccpNmrConv.readShifts( spectrum.chemical_shifts.filename, spectrum.name) else: shiftList = ccpNmrConv.createChemShiftsFromPeakList( spectrum.name) self.tagAriaInput(shiftList) peakListDimOrder = [ spectrum.cross_peaks.proton1, spectrum.cross_peaks.proton2, spectrum.cross_peaks.hetero1, spectrum.cross_peaks.hetero2 ] # TODO TODO Should the names not directly reflect the ones from the data model?!?! Better... # or have alternative system for this at least refExperiment = getRefExpFromOldExpType(ccpNmrConv.ccpnProject, spectrum.type) if not refExperiment: print " Error unknown experiment type %s... not created." % spectrum.type peakLists = ccpNmrConv.readPeakList(spectrum.cross_peaks.filename, refExperiment, spectrum.name, peakListDimOrder) self.tagAriaInput(peakLists[0]) if spectrum.cross_peaks_assignments.filename: ccpNmrConv.readPeakListAssignments( spectrum.cross_peaks_assignments.filename) # # Link resonances to atoms # ccpNmrConv.linkResonances( self.xmlFile.conversion.project.naming_system, setSinglePossEquiv=0, setSingleProchiral=0, useIupacMatching=1, minimalPrompts=1) self.ccpNmrConv = ccpNmrConv
def fcSetPeaksInformation(self, formatName, filePath, addKeywords): """ Handling of peak lists - can use specific addKeywords that make it easier to select reference experiments and set the peak list to reference experiment dimension mappings. """ from ccpnmr.format.general.Util import getRefExpFromOldExpType # # Step 1, preparse the file and get info out # (fileRead, fileInformation) = self.formatConversion.preparseFile( 'peaks', formatName, filePath, addKeywords=addKeywords) if not fileRead: raise self.FcWorkFlowError( "Could not read peak list file %s in format %s:\n%s" % (filePath, formatName, fileRead)) else: peakListNames = fileInformation.keys() if len(peakListNames) > 1: if not addKeywords.has_key("peakListName"): raise self.FcWorkFlowError( "Multiple peak lists in file %s, and no specific 'peakListName' defined in addKeywords." % (filePath)) else: peakListName = addKeywords['peakListName'] if peakListName not in peakListNames: raise self.FcWorkFlowError( "Multiple peak lists in file %s, and 'peakListName' %s not in list of peak list names from file." % (filePath, peakListName)) else: peakListName = peakListNames[0] peakPpmRanges = fileInformation[peakListName]['peakPpmRanges'] dimCodes = fileInformation[peakListName]['dimensionCodes'] # # Step 2, set the reference experiment. # if addKeywords.has_key('oldExpType'): refExperiment = getRefExpFromOldExpType( self.formatConversion.ccpnProject, addKeywords['oldExpType']) if not refExperiment: raise self.FcWorkFlowError( "Could not find reference experiment 'old' name %s." % (addKeywords['oldExpType'])) del (addKeywords['oldExpType']) elif addKeywords.has_key('expTypeInfo'): (expPrototypeName, refExpName) = addKeywords['expTypeInfo'] refExperiment = None expPrototype = project.findFirstNmrExpPrototype( name=expPrototypeName) if expPrototype: refExperiment = expPrototype.findFirstRefExperiment( name=refExpName) if not refExperiment: raise self.FcWorkFlowError( "Could not find reference experiment with (prototype,experiment) names %s." % (addKeywords['expTypeInfo'])) del (addKeywords['expTypeInfo']) else: raise self.FcWorkFlowError( "No reference experiment defined for %s:\nNeed to set an 'oldExpType' or 'expTypeInfo' variable in addKeywords in self.dataFiles." % (filePath)) addKeywords['refExperiment'] = refExperiment refExperimentInfo = self.formatConversion.getRefExperimentInfo( addKeywords['refExperiment']) # # Step 3 set the peak list to reference experiment dimension mapping, if necessary # # uniqueMatches gives the unique (shift matches) connection between the CCPN dimension (as number) and the peak dimension (as list index) # matches gives all possible shift matches # # Basically, web side has to allow all possibilities in 'matches', but should set the 'uniqueMatches' match as default. # # Only run this if not manually set! if not addKeywords.has_key( 'expDimToPeakDim') or not addKeywords['expDimToPeakDim']: (matches, uniqueMatches) = self.formatConversion.matchFormatAndCcpnPeakDims( peakPpmRanges, dimCodes, refExperimentInfo['ppmRange']) if uniqueMatches: addKeywords['expDimToPeakDim'] = uniqueMatches else: raise self.FcWorkFlowError( "No reference experiment dimension to peak list dimension mapping set or a unique match found. Possibilities are:\n%s\n\nReference experiment info is:\n%s\n\nPeak ppm ranges:\n%s\n" % (str(matches), refExperimentInfo, str(peakPpmRanges)))