예제 #1
0
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)
예제 #2
0
파일: read.py 프로젝트: fenglb/ccpnmr2.4
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)