def getCosmosData(nmrCalcRun): """ Make data{} and options{} dictionaries for COSMOS input """ # get options - use all input options that have a 'code' attribute options = {} for runParameter in nmrCalcRun.findAllRunParameters(ioRole='input'): code = runParameter.code if code is not None: options[code] = intUtil.getParameterValue(runParameter) # get data data = {} # get coordinates coordinates = data['COO'] = [] ll = nmrCalcRun.findAllData(className='StructureEnsembleData', ioRole='input') if len(ll) == 1: ensemble = ll.pop().structureEnsemble atomNames, elementNumbers, atomIdMap = getAtomData(ensemble) # list of name,elemNumber tuples atomData = zip(atomNames, elementNumbers) for model in ensemble.sortedModels(): # Split into x,y,z triplets coordTriplets = zip(*[iter(model.coordinates)] * 3) coordinates.append([ list(atomData[ii] + xyz) for ii, xyz in enumerate(coordTriplets) ]) else: raise Exception( "Run must have exactly one input structure ensemble, %s found" % len(ll)) # get bond data data['BONDS'] = getBondData(ensemble.molSystem, atomIdMap) # get experiment data data['EXP'] = expdict = {} for label, name, code, numResonances in interfaceData: constraintData = nmrCalcRun.findFirstData(code=code) if constraintData is not None: # There should be exactly one constraintList constraintList = constraintData.findFirstConstraintList() expdict[code] = makeAtomInput(constraintList, atomIdMap) return data, options
def run(nmrCalcRun): """ Run Program Input: nmrCalcRun: NmrCalc.Run NBNB TBD change dictionary keys for data to use COSMOS names. """ COSMOS_LIB = os.path.join(os.path.expandvars('${COSMOS_HOME}'), 'lib') if COSMOS_LIB not in sys.path: sys.path.append(COSMOS_LIB) from PyCOSMOS import runCOSMOS # check we are not overriding an old run if not intUtil.runIsWritable(nmrCalcRun): raise Exception("Cannot read into %s - has already been used" % nmrCalcRun) data, options = cosmosIo.getCosmosData(nmrCalcRun) fp = open('/home/rhf22/CosmosTestData.txt', 'w') fp.write(json.dumps(data, sort_keys=2, indent=2)) fp = open('/home/rhf22/CosmosTestOpts.txt', 'w') fp.write(json.dumps(options, sort_keys=2, indent=2)) fp.close() # determine and create absolute outputdir outputdir = options.get('OUTPUT_DIR') if outputdir: # converts relative to absoulte directories outputdir = os.path.join(os.getcwd(), outputdir) else: outputdir = os.getcwd() options['OUTPUT_DIR'] = outputdir if not os.path.exists(outputdir): os.makedirs(outputdir) nmrCalcRun.status = 'active' output = runCOSMOS(data, options) # put output into NmrCalc instance cosmosIo.mergeCosmosData(nmrCalcRun, output)
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)
from memops.general import Io as genIo from ccpnmr.integrator.core import Util as intUtil if __name__ == '__main__': """ Make NmrCalc.Run from json file. """ # get input arguments if len(sys.argv) == 3: projectDir, jsonFile = sys.argv[1:3] nmrProjectName = None else: raise Exception("Usage: projectToJson projectDir jsonFilePath") try: memopsRoot = genIo.loadProject(projectDir, suppressGeneralDataDir=True) jsonObject = json.load(open(jsonFile)) tmpFile = jsonFile + '_tmp' json.dump(jsonObject, open(tmpFile, 'w'), sort_keys=True, indent=2) nmrCalcId = intUtil.makeNmrCalc(memopsRoot, jsonObject) memopsRoot.saveModified() jsonObject['CCPN.nmrCalcId'] = nmrCalcId fp = open(jsonFile, 'w') json.dump(jsonObject, fp, sort_keys=True, indent=2) fp.close() except: traceback.print_exc() raise
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")
def importFromCyana(nmrCalcRun, targetDir): c = cp.CyanaParser() rootProject = nmrCalcRun.root os.chdir(targetDir) peakFiles = [] uplFiles = [] acoFiles = [] rdcFiles = [] cyaFiles = [] noaFiles = [] txtFiles = [] dataSources = [] ccpnConfigFile = open("Properties.ccpn.json") ccpnConfig = json.load(ccpnConfigFile) configFile = open("cyana2ccpn.json") config = json.load(configFile) runId = ccpnConfig['CCPN.nmrCalcId'].split('+')[1] for peakList in ccpnConfig['PeakListData']: peakListName = peakList['fileName'].split( '.peaks')[0] + '-cycle7.peaks' peakFiles.append(peakListName) for distanceRestraintList in config["distanceRestraints"]: uplFiles.append(distanceRestraintList) for dihedralRestraintList in config["dihedralRestraints"]: acoFiles.append(dihedralRestraintList) for rdcRestraintList in config["rdcRestraints"]: rdcFiles.append(rdcRestraintList) for cyaFile in config["cyaFiles"]: cyaFiles.append(cyaFile) for noaFile in config["noaFiles"]: noaFiles.append(noaFile) seqFile = ccpnConfig['RunParameter']['fileNameSequence'] originalProtFile = ccpnConfig['MeasurementListData'][0]['fileName'] finalProtFile = originalProtFile.split(".prot")[0] + "-final.prot" c.parse(seqFile=seqFile, originalProtFile=originalProtFile, finalProtFile=finalProtFile, peakFiles=peakFiles, rdcFiles=rdcFiles, acoFiles=acoFiles, cyaFiles=cyaFiles, noaFiles=noaFiles) nmrProject = rootProject.currentNmrProject nmrConstraintStore = rootProject.newNmrConstraintStore( nmrProject=nmrProject) if rootProject.currentAnalysisProject is not None: AnalysisProject = rootProject.currentAnalysisProject else: AnalysisProject = rootProject.newAnalysisProject( name="analysisProject", nmrProject=nmrProject) shiftListName = c.finalProtFile molSystem = rootProject.findFirstMolSystem() newShiftList = nmrProject.newShiftList(name=shiftListName) atomToResonanceMap = createAtomtoResonanceMap(nmrProject) resonanceDictionaries = assignResonances(c.resonances, atomToResonanceMap, molSystem, newShiftList, AnalysisProject, nmrConstraintStore) loadPdb(config['pdbFile'], molSystem) # newPeakLists = [] for peakList in ccpnConfig['PeakListData']: peakListName = peakList['fileName'].split('.peaks')[0] experimentSerial = int(peakList['fileName'].split('_')[1]) ccpnExperiment = nmrProject.findFirstExperiment( serial=experimentSerial) cloneName = ccpnExperiment.name + '_run' + str(runId) clonedExperiment = cloneExperiment(ccpnExperiment, cloneName) spectrum = clonedExperiment.findFirstDataSource() dataSources.append(spectrum) setExperimentShiftList(clonedExperiment, newShiftList) peakList = spectrum.newPeakList() spectrum.activePeakList = peakList for cingPeakList in c.peakLists: if cingPeakList.name.split('-')[0] == peakListName: peakList.name = cingPeakList.name pickPeaksFromCing(cingPeakList, peakList, resonanceDictionaries['resonanceDict']) nmrCalcRun.newPeakListData(name=cingPeakList.name, ioRole='output', peakList=peakList) # newPeakLists.append(peakList) # for newPeakList in newPeakLists: assignedPeakList = spectrum.newPeakList() unassignedPeakList = spectrum.newPeakList() assignedPeakList.details = 'assigned' unassignedPeakList.details = 'unassigned' splitAssignedUnassigned(peakList, assignedPeakList, unassignedPeakList) loadChemShiftRestraints(c.chemicalShiftRestraints, originalProtFile, nmrConstraintStore, atomToResonanceMap, resonanceDictionaries['fixedResonanceDict'], molSystem) if len(c.distanceRestraintLists) != 0: loadDistanceRestraints(c.distanceRestraintLists, nmrProject, nmrCalcRun, nmrConstraintStore, resonanceDictionaries['fixedResonanceDict'], resonanceDictionaries['cingFixedResonanceDict'], molSystem, AnalysisProject) if len(c.violationLists) != 0: violatedPeaks = loadViolatedDistanceRestraints( c.violationLists, nmrProject, nmrCalcRun, nmrConstraintStore, resonanceDictionaries['fixedResonanceDict'], resonanceDictionaries['cingFixedResonanceDict'], molSystem, AnalysisProject) for peakList, peaks in violatedPeaks.iteritems(): spectrum = peakList.getDataSource() newPeakList = spectrum.newPeakList() newPeakList.details = 'violated' copyPeakList(peakList, newPeakList, peaks=peaks) if len(c.dihedralRestraintLists) != 0: loadDihedralRestraints(c.dihedralRestraintLists, nmrConstraintStore, nmrCalcRun, resonanceDictionaries['cingFixedResonanceDict'], molSystem) if len(c.rdcRestraintLists) != 0: loadRdcRestraints(c.rdcRestraintLists, nmrConstraintStore, resonanceDictionaries['cingFixedResonanceDict'], molSystem) pluginModule = intUtil.getIntegratorPlugin( ccpnConfig["CCPN.Run.wmsProtocolName"]) pluginModule.read.read(nmrCalcRun, targetDir) print "Import Complete" return dataSources
def read(nmrCalcRun, dataDir): """ Read Output files for Rosetta run Input: nmrCalcRun: NmrCalc.Run dataDir: directory directly containing program output. """ # set up files = {} data = {} fileNames = stdFileNames.copy() #fileNames['properties'] = intIo.propFileName # check presence of files: if not os.path.isdir(dataDir): raise IOError("Data directory %s not found" % dataDir) for tag in ( 'scores', 'rms', 'rawRms', ): ss = uniIo.joinPath(dataDir, fileNames[tag]) files[tag] = ss if not os.path.isfile(ss): raise IOError("%s file %s not found in directory %s" % (tag, ss, dataDir)) # check NmrCalcRun: if not intUtil.runIsWritable(nmrCalcRun): raise Exception("Cannot read into %s - has already been used" % nmrCalcRun) # get simple data records #ss = fileNames.get('input') #if ss: # path = uniIo.joinPath(dataDir, ss) # if os.path.isfile(path): # data = open(path).read() # nmrCalcRun.newRunParameter(name='inputUsed', code=stdFileNames['input'], # ioRole='output', textValue=data, # ) #details='Input data, as used by Rosetta') #NBNB TBD remove. Not there. Properties is an input thing. #ss = fileNames.get('properties') #if ss: # path = uniIo.joinPath(dataDir, ss) # if os.path.isfile(path): # data = open(ss).read() # nmrCalcRun.newRunParameter(name='propertiesUsed', # code=stdFileNames['properties'], # ioRole='output', textValue=data, # details='Properties file, as used by Rosetta') # read data arrays and sort by Rosetta score scoreFile = open(files['scores']) rmsFile = open(files['rms']) rawRmsFile = open(files['rawRms']) data = [] for ss in scoreFile: rms = float(rmsFile.next().split()[1]) rawRms = float(rawRmsFile.next().split(None, 1)[0]) tt = ss.split() # Order is: score, rawscore shiftChi2, rms, rawrms, name data.append( (float(tt[3]), float(tt[1]), float(tt[2]), rms, rawRms, tt[0])) data.sort() scores, rawScores, shiftChi2, rms, rawRms, names = zip(*data) # Set scores data in NmrCalc matrices docTemplate = ( "Rosetta %s for all calculated structures, sorted by corrected score") ss = 'corrected scores' nmrCalcRun.newFloatMatrixData(code='scores', name=ss, ioRole='output', shape=(0, ), data=scores, details=docTemplate % ss) ss = 'raw scores' nmrCalcRun.newFloatMatrixData(code='rawScores', name=ss, ioRole='output', shape=(0, ), data=rawScores, details=docTemplate % ss) ss = 'shift chi2 scores' nmrCalcRun.newFloatMatrixData(code='shiftChi2', name=ss, ioRole='output', shape=(0, ), data=shiftChi2, details=docTemplate % 'Chemical' + ss) ss = 'RMS to best struct' nmrCalcRun.newFloatMatrixData(code='rms', name=ss, ioRole='output', shape=(0, ), data=rms, details=docTemplate % 'RMS to structure with best corrected score') ss = 'RMS to best raw struct' nmrCalcRun.newFloatMatrixData(code='rawRms', name=ss, ioRole='output', shape=(0, ), data=rawRms, details=docTemplate % 'RMS to structure with best raw score') # Get MolSystem molResidueData = nmrCalcRun.findFirstData(className='MolResidueData', ioRole='input') molSystem = molResidueData.molSystem # read structures in order of lowest corrected score paths = [] for modelNum, fileName in enumerate(names): path = uniIo.joinPath(dataDir, fileName + '.pdb') if os.path.isfile(path): paths.append(path) else: break ensemble = StructureIo.getStructureFromFiles(molSystem, paths, fileType='rough') ss = "Rosetta calculated structures, sorted by corrected score" nmrCalcRun.newStructureEnsembleData(name='result', ioRole='output', structureEnsemble=ensemble, details=docTemplate % ss) # Make Nmr.StructureCalculation nmrProject = nmrCalcRun.nmrCalcStore.nmrProject nmrCalcRun.structureGeneration = nmrProject.newStructureGeneration( generationType='denovo', name='CSRosetta', structureEnsemble=ensemble)
from ccpnmr.integrator.core import Util as intUtil if __name__ == '__main__': """ Create project summary JSON file """ # get input arguments if len(sys.argv) == 3: projectDir, jsonFile = sys.argv[1:3] nmrProjectName = None elif len(sys.argv) == 4: projectDir, jsonFile, nmrProjectName = sys.argv[1:4] else: raise Exception( "Usage: projectToJson projectDir jsonFilePath [nmrProjectName optional]" ) memopsRoot = genIo.loadProject(projectDir, suppressGeneralDataDir=True) jsonObject = intUtil.wmsProjectSummary(memopsRoot, nmrProjectName=nmrProjectName) # If jsonFile is relative this puts it relative to project repository # If it is absoolute it goes where it should jsonFile = os.path.join( memopsRoot.findFirstActiveRepository().url.dataLocation, jsonFile) fp = open(jsonFile, 'w') json.dump(jsonObject, fp, sort_keys=True, indent=2) fp.close()
def cyanaNmrCalcRun(nmrCalcRun): """ Modify nmrCalcRun from generic MultiStructure form to CANDID-specific Input: nmrCalcRun: NmrCalc.Run """ print ('### Cyana adaptNmrCalcRun') ###Reset calcMode values valueMap = { 'none':'default', 'assignedPeaks':'pks', 'unassignedPeaks':'upks', } runParam = nmrCalcRun.findFirstRunParameter(name='calcMode') val = valueMap.get(runParam.textValue) print val if val is None: raise ValueError("Cyana calculation mode %s must be one of %s" % (runParam.textValue, tuple(valueMap.keys()))) else: runParam.textValue = val # Sequence. Set RMSDresidues seqDataObj = nmrCalcRun.findFirstData(name='definedResidues') #seqIds = seqDataObj.residueSeqIds # will not work - seqIds is empty when takingwhole chain seqIds = [x.seqId for x in seqDataObj.sortedResidues()] ss = intUtil.integerListExpression(seqIds,fieldSep='..') nmrCalcRun.newRunParameter(name='definedResidueString', code='rmsdrange', textValue=ss) # first and last residue numbers, for one-chain web version nmrCalcRun.newRunParameter(name='firstSeqId', code='firstSeqId', intValue= min(seqIds)) nmrCalcRun.newRunParameter(name='lastSeqId', code='lastSeqId', intValue= max(seqIds)) # Spectrum tolerance defaultTolPoints = 1.0 runParam = nmrCalcRun.findFirstRunParameter(name='defaultTolPoints') if runParam: val = runParam.floatValue if val: defaultTolPoints = val minTol = 0.02 runParam = nmrCalcRun.findFirstRunParameter(name='minTolPpm') if runParam: val = runParam.floatValue if val: minTol = val # random number seed nmrCalcRun.newRunParameter(name='ranseed', code='seed', intValue= random.randint(1,10000000)) #set 'peaks' and 'tolerance' parameters # First get data peakFiles = [] dataSources = [] peakListObjs = [x for x in nmrCalcRun.sortedData() if x.className == 'PeakListData'] if peakListObjs: for peakListData in peakListObjs: runParameter = peakListData.findFirstRunParameter(name='fileName') peakFiles.append(runParameter.textValue) dataSources.append(peakListData.peakList.dataSource) # set 'peaks' parameter nmrCalcRun.newRunParameter(name='peakFileNames', code='peaks', textValue=','.join(peakFiles)) customTolerances = nmrCalcRun.findFirstRunParameter(name='assignmentTolerances') if customTolerances is None: tolValues = intUtil.getAmalgamatedTolerances(dataSources, defaultTolPoints, minTol, tagOrder=('hx2', 'hx1', 'x1', 'x2')) nmrCalcRun.newRunParameter(name='toleranceString', code='tolerance', textValue=','.join(str(x) for x in tolValues)) else: tolValues = str(customTolerances.textValue) print('tolvalues',tolValues) nmrCalcRun.newRunParameter(name='toleranceString', code='tolerance', textValue=tolValues) # Check number of shift lists shiftListObjs = [x for x in nmrCalcRun.sortedData() if x.className == 'MeasurementListData' and x.measurementList.className == 'ShiftList'] if len(shiftListObjs) == 1: shiftListObj = shiftListObjs[0] fileNameObj = shiftListObj.findFirstRunParameter(name='fileName') nmrCalcRun.newRunParameter(name='shiftFileName', code='prot', textValue=fileNameObj.textValue, data=shiftListObj) else: # raise Exception("Required 1 shiftList, %s found" % len(shiftListObjs)) pass
def mergeCosmosData(nmrCalcRun, cosmosOutput): """ Merge Cosmos output data back into NmrCalcRun """ summaryLog = cosmosOutput[0] modelData = cosmosOutput[1:] nmrCalcRun.newRunParameter(name='summaryLog', code='SUMMARY_LOG', ioRole='output', textValue=summaryLog) if modelData: inputEnsembleData = nmrCalcRun.findFirstData(ioRole='input', name='structureEnsemble') if inputEnsembleData is None: raise KeyError( "NmrCalc.run has no structureEnsemble input Data object") newEnsemble = makeEmptyEnsembleCopy( inputEnsembleData.structureEnsemble) nmrCalcRun.newStructureEnsembleData(ioRole='output', code='COO', name='structureEnsemble', structureEnsemble=newEnsemble) nAtoms = newEnsemble.nAtoms constraintStore = None for modelDict in modelData: # Models and coordinates # NBNB problem matching output to input models. NB lacks information. model = newEnsemble.newModel() # NBNB TBD some better model identifier would be useful modelSerial = model.serial newData = nmrCalcRun.newStructureEnsembleData( ioRole='output', #groupId=modelSerial, models=(model,), models=(model, ), name='model%s' % modelSerial) # COSMOS log modelLog = modelDict.get('LOG') if modelLog is not None: nmrCalcRun.newRunParameter(name='log%s' % modelSerial, code='LOG', ioRole='output', textValue=modelLog, data=newData) #textValue=modelLog, groupId=modelSerial) coords = modelDict.get('COO') if coords: # NB assumes that atoms are in same order as input # and that coordinates are always present. coordinates = [None] * (nAtoms * 3) offset = 0 for tt in coords: coordinates[offset] = tt[2] offset += 1 coordinates[offset] = tt[3] offset += 1 coordinates[offset] = tt[4] offset += 1 model.setSubmatrixData('coordinates', coordinates) inputModelData = None parameterGroup = None # generate output data as ConstraintLists newConstraintLists = {} for label, name, code, numResonances in interfaceData: data = modelDict.get(code) if data is not None: if parameterGroup is None: parameterGroup = nmrCalcRun.newParameterGroup( name=newData.name, ioRole='output', data=(newData, )) if constraintStore is None: # Initialise ConstraintStore constraintStore = nmrCalcRun.root.newNmrConstraintStore( nmrProject=nmrCalcRun.nmrCalcStore.nmrProject) if inputModelData is None: # Make input model record, to group of input and utput models inputModel = inputEnsembleData.structureEnsemble.findFirstModel( serial=modelSerial) inputModelData = nmrCalcRun.newStructureEnsembleData( ioRole='input', models=(inputModel, ), parameterGroup=parameterGroup, name=parameterGroup.name) constraintList = intUtil.constraintListFromData( nmrCalcRun, constraintStore, data, name, code, numResonances, parameterGroup) if constraintList: ll = newConstraintLists.get(name) if ll is None: ll = newConstraintLists[name] = [] ll.append(constraintList) # NBNB REWORK! in standard operation you should generate only ONE # measurementlist from ALL models (average with std dev.) for name, constraintLists in newConstraintLists: intUtil.measurementListFromConstraints(nmrCalcRun, name, constraintLists) nmrCalcRun.status = 'completed' else: nmrCalcRun.status = 'failed'
""" if len(sys.argv) >= 4: # # set up input junk, projectDir, nmrCalcRunId, protocolName = sys.argv[:4] print '### input : ', projectDir, nmrCalcRunId, protocolName masterRun = intIo.getNmrCalcRun(projectDir, nmrCalcRunId) print '### masterRun', masterRun if masterRun is None: raise Exception("No NmrCalcRun found for %s, %s" % (projectDir, nmrCalcRunId)) nmrCalcRun = intUtil.makeDerivedRun(masterRun) print '### nmrCalcRun', nmrCalcRun try: pluginModule = intUtil.getIntegratorPlugin(protocolName) intUtil.setRunParametersFromConfig(nmrCalcRun, pluginModule.Util.defaultConfiguration) except: print 'WARNING, no python plugin found for %s' % protocolName nmrCalcRun.wmsProtocolName = protocolName intIo.doPrepareStdWmsRun(nmrCalcRun, pluginModule) nmrCalcRun.root.saveModified()