Ejemplo n.º 1
0
def importCyanaCoorAndRes(ccpnProject, inputDir, guiRoot, replaceCoordinates=1, replaceRestraints=1, allowPopups=1, 
                          minimalPrompts=0, verbose=1, **presets):

    if replaceCoordinates:
        status = importPseudoPdb(ccpnProject, inputDir, guiRoot, allowPopups=allowPopups, 
                                 minimalPrompts=minimalPrompts, verbose=verbose, **presets)
        if status:
            nTerror("Failed importCyanaCoorAndRes")
            return True
    if not replaceRestraints:
        return

    formatCyana = CyanaFormat(ccpnProject, guiRoot, verbose=verbose, minimalPrompts=minimalPrompts, allowPopups=allowPopups)
    ccpnConstraintListOfList = []

    globPattern = inputDir + '/*.upl'
    fileList = glob(globPattern)
    nTdebug("From %s will read files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCyana.readDistanceConstraints(fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)


    globPattern = inputDir + '/*.aco'
    fileList = glob(globPattern)
    nTdebug("From %s will read in total files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCyana.readDihedralConstraints(fn, minimalPrompts=minimalPrompts,allowPopups=allowPopups,verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)


    ccpnConstraintList = getDeepByKeys(ccpnConstraintListOfList, 0) # no need to repeat
    nTdebug("ccpnConstraintList: %s" % ccpnConstraintList)
    if ccpnConstraintList:
        nmrConstraintStore = ccpnConstraintList.nmrConstraintStore
        structureGeneration = nmrConstraintStore.findFirstStructureGeneration()
        formatCyana.linkResonances(
                      forceDefaultChainMapping=1,
                      globalStereoAssign=1,
                      setSingleProchiral=1,
                      setSinglePossEquiv=1,
                      strucGen=structureGeneration,
                      allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose)
Ejemplo n.º 2
0
def importXplorCoorAndRes(ccpnProject, inputDir, guiRoot, replaceCoordinates=1, replaceRestraints=1, 
                          allowPopups=1, minimalPrompts=0, verbose=1, **presets):

    if replaceCoordinates:
        status = importPseudoPdb(ccpnProject, inputDir, guiRoot, allowPopups=allowPopups, minimalPrompts=minimalPrompts, 
                                 verbose=verbose, **presets)
        if status:
            nTerror("Failed importXplorCoorAndRes")
            return True

    if not replaceRestraints:
        return

    formatCns = CnsFormat(ccpnProject, guiRoot, verbose=verbose, minimalPrompts=minimalPrompts, allowPopups=allowPopups)
    ccpnConstraintListOfList = []

    # Will overwrite the settings given to formatCns.linkResonances(  below
    globPattern = inputDir + '/*_noe.tbl'
    fileList = glob(globPattern)
    nTdebug("From %s will read files: %s" % (globPattern, fileList))

#    for fn in fileList[0:1]: # TODO:
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCns.readDistanceConstraints(fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)
        if not ccpnConstraintList:
            nTerror("Failed to read")
            return True

#    globPattern = inputDir + '/*_hbond.tblXXXX' # TODO:
    globPattern = inputDir + '/*_hbond.tbl'
    fileList = glob(globPattern)
    nTdebug("From %s will read in files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCns.readDistanceConstraints(fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)

#    globPattern = inputDir + '/*_dihe.tblXXXX' # TODO:
    globPattern = inputDir + '/*_dihe.tbl'
    fileList = glob(globPattern)
    nTdebug("From %s will read in total files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCns.readDihedralConstraints(fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)

    keywds = getDeepByKeysOrDefault(presets, {}, LINK_RESONANCES, KEYWORDS)
    nTdebug("From getDeepByKeysOrDefault keywds: %s" % repr(keywds))

    ccpnConstraintList = getDeepByKeys(ccpnConstraintListOfList, 0) # no need to repeat
    nTdebug("First ccpnConstraintList: %s" % ccpnConstraintList)
    if ccpnConstraintList != None:
#    for i, ccpnConstraintList in enumerate(ccpnConstraintListOfList):
        keywds = getDeepByKeysOrDefault(presets, {}, LINK_RESONANCES, KEYWORDS)
        nTdebug("From getDeepByKeysOrDefault keywds: %s" % repr(keywds))
        nTdebug("ccpnConstraintList: %s" % ccpnConstraintList)
        nmrConstraintStore = ccpnConstraintList.nmrConstraintStore
        structureGeneration = nmrConstraintStore.findFirstStructureGeneration()
        formatCns.linkResonances(
                      forceDefaultChainMapping=1, # may be overwritten by using forceChainMappings.
                      globalStereoAssign=1,
                      setSingleProchiral=1,
                      setSinglePossEquiv=1,
                      strucGen=structureGeneration,
                      allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **keywds)
Ejemplo n.º 3
0
def annotateEntry(entryCodeNew, *extraArgList):
    nTmessage(header)
    nTmessage(getStartMessage())

    expectedArgumentList = []
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTerror("Got arguments: " + repr(extraArgList))
        nTerror("Failed to get expected number of arguments: %d got %d" % (
            expectedNumberOfArguments, len(extraArgList)))
        nTerror("Expected arguments: %s" % expectedArgumentList)
        return True
#    entryCode, city = entryCodePlusCity.split('_')

    # Adjust the parameters below
    isInteractive = False
    sourceIsOrgProject = True
    checkOrgProject = False
    replaceCoordinates = True # From all *.pdb files in inputDir.
    replaceRestraints = True
    doSwapCheck = True
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True

    if isInteractive:
        allowPopups = True
        minimalPrompts = False
#        verbose = True
    else:
        allowPopups = False
#        minimalPrompts = True
#        verbose = False

    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'sourceIsOrgProject                      (or new CCPN file)                                    ', sourceIsOrgProject
    print 'checkOrgProject                                                                               ', checkOrgProject
    print 'replaceCoordinates                                                                            ', replaceCoordinates
    print 'replaceRestraints                                                                             ', replaceRestraints
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

    guiRoot = None
    if allowPopups:
        guiRoot = Tkinter.Tk()

    entryCode,city = mapEntrycodeNew2EntrycodeAndCity[entryCodeNew]
    ch23 = entryCode[1:3]
    entryCodeOrg = entryCode + 'Org'
    dataOrgEntryDir = os.path.join(dataDir, ch23, entryCodeOrg)
    ccpnFile = os.path.join(dataOrgEntryDir, entryCodeOrg + ".tgz")
#    entryCodeNew = entryCode + city
    programId = getDeepByKeys(programHoH, entryCode, city)
    if not (city == 'Test' or programId):
#                nTdebug("Skipping %s" % entryCodeNew)
        nTerror("Neither City is 'Test' or programId given")
        return
    else:
        nTdebug("Looking at %s" % entryCodeNew)
#                continue # TODO disable premature stop.


    dataDividedXDir = os.path.join(dataDir, ch23)
    entryDir = os.path.join(dataDividedXDir, entryCodeNew)
    inputAuthorDir = os.path.join(entryDir, 'Author')
    outputNijmegenDir = os.path.join(entryDir, 'Nijmegen')

    if not os.path.exists(inputAuthorDir):
        mkdirs(inputAuthorDir)
    if not os.path.exists(outputNijmegenDir):
        mkdirs(outputNijmegenDir)

    os.chdir(outputNijmegenDir)

    presets = getDeepByKeysOrDefault(presetDict, {}, entryCodeNew)
    if presets:
        nTmessage("In annotateLoop using preset values...")
    # end if

    if sourceIsOrgProject:
        if os.path.exists(entryCodeOrg):
            nTmessage("Removing previous Org directory: %s" % entryCodeOrg)
            rmtree(entryCodeOrg)
        do_cmd("tar -xzf " + ccpnFile)
        if os.path.exists(entryCodeNew):
            nTmessage("Removing previous directory: %s" % entryCodeNew)
            rmtree(entryCodeNew)
        copytree(entryCodeOrg, entryCodeNew)

    if checkOrgProject:
        # By reading the ccpn tgz into cing it is also untarred/tested.
        project = Project.open(entryCodeOrg, status='new')
        if not project.initCcpn(ccpnFolder=ccpnFile, modelCount=1):
            nTerror("Failed check of original project")
            return
        project.removeFromDisk()
        project.close(save=False)

    ccpnProject = loadProject(entryCodeNew)
    if not ccpnProject:
        nTerror("Failed to read project: %s" % entryCodeNew)
        return

#            nmrProject = ccpnProject.currentNmrProject
#            ccpnMolSystem = ccpnProject.findFirstMolSystem()
#            nTmessage('found ccpnMolSystem: %s' % ccpnMolSystem)
#    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

    if replaceCoordinates or replaceRestraints:
        if programId == CYANA:
            importCyanaCoorAndRes(ccpnProject, inputAuthorDir, guiRoot,
                replaceCoordinates=replaceCoordinates, replaceRestraints=replaceRestraints, 
                allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **presets)
        elif programId == XPLOR:
            importXplorCoorAndRes(ccpnProject, inputAuthorDir, guiRoot,
                replaceCoordinates=replaceCoordinates, replaceRestraints=replaceRestraints, 
                allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **presets)
        elif programId == PDB:
            importPseudoPdb(ccpnProject, inputAuthorDir, guiRoot,
                allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **presets)
        else:
            nTerror("Failed to doImportCoordinatesAndRestraints because action for program Id not coded for: %s" % programId)
            nTerror("Skipping entry")
            return

    if doSwapCheck:
#        constraintsHandler = ConstraintsHandler()
        nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore()
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        numSwapCheckRuns = 3
        if nmrConstraintStore:
            if structureEnsemble:
                swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)
            else:
                nTmessage("Failed to find structureEnsemble; skipping swapCheck")
        else:
            nTmessage("Failed to find nmrConstraintStore; skipping swapCheck")
#        constraintsHandler.swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)

    if doSaveProject:
#        nTmessage('Checking validity and saving to new path')
        nTmessage('Saving to new path: %s' % entryCodeNew)
#        checkValid=True,
        saveProject(ccpnProject, newPath=entryCodeNew, removeExisting=True)
    if doExport:
        tarPath = os.path.join(entryDir, entryCodeNew + ".tgz")
        if os.path.exists(tarPath):
            nTmessage("Overwriting: " + tarPath)
        myTar = tarfile.open(tarPath, mode='w:gz') # overwrites
        myTar.add(entryCodeNew)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
Ejemplo n.º 4
0
def importCyanaCoorAndRes(ccpnProject,
                          inputDir,
                          guiRoot,
                          replaceCoordinates=1,
                          replaceRestraints=1,
                          allowPopups=1,
                          minimalPrompts=0,
                          verbose=1,
                          **presets):

    if replaceCoordinates:
        status = importPseudoPdb(ccpnProject,
                                 inputDir,
                                 guiRoot,
                                 allowPopups=allowPopups,
                                 minimalPrompts=minimalPrompts,
                                 verbose=verbose,
                                 **presets)
        if status:
            nTerror("Failed importCyanaCoorAndRes")
            return True
    if not replaceRestraints:
        return

    formatCyana = CyanaFormat(ccpnProject,
                              guiRoot,
                              verbose=verbose,
                              minimalPrompts=minimalPrompts,
                              allowPopups=allowPopups)
    ccpnConstraintListOfList = []

    globPattern = inputDir + '/*.upl'
    fileList = glob(globPattern)
    nTdebug("From %s will read files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCyana.readDistanceConstraints(
            fn, minimalPrompts=minimalPrompts, verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)

    globPattern = inputDir + '/*.aco'
    fileList = glob(globPattern)
    nTdebug("From %s will read in total files: %s" % (globPattern, fileList))
    for fn in fileList:
        fnBaseName = os.path.basename(fn).split('.')[0]
        ccpnConstraintList = formatCyana.readDihedralConstraints(
            fn,
            minimalPrompts=minimalPrompts,
            allowPopups=allowPopups,
            verbose=verbose)
        ccpnConstraintList.setName(fnBaseName)
        ccpnConstraintListOfList.append(ccpnConstraintList)

    ccpnConstraintList = getDeepByKeys(ccpnConstraintListOfList,
                                       0)  # no need to repeat
    nTdebug("ccpnConstraintList: %s" % ccpnConstraintList)
    if ccpnConstraintList:
        nmrConstraintStore = ccpnConstraintList.nmrConstraintStore
        structureGeneration = nmrConstraintStore.findFirstStructureGeneration()
        formatCyana.linkResonances(forceDefaultChainMapping=1,
                                   globalStereoAssign=1,
                                   setSingleProchiral=1,
                                   setSinglePossEquiv=1,
                                   strucGen=structureGeneration,
                                   allowPopups=allowPopups,
                                   minimalPrompts=minimalPrompts,
                                   verbose=verbose)