示例#1
0
def convert(projectName, inputDir, projectNameNew):
    "Testing doc strings"
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True # From all *.pdb files in inputDir.

    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

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

    if removeOriginalStructureEnsemble:
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        if structureEnsemble:
            nTmessage("Removing first found structureEnsemble -A-")
            structureEnsemble.delete()
        else:
            nTwarning("No structureEnsemble found; can't remove it.")

    if addStructureEnsemble:
        structureGeneration = ccpnProject.newStructureGeneration()
        guiRoot = Tkinter.Tk()
        format = PseudoPdbFormat(ccpnProject, guiRoot, verbose = 1)

        globPattern = inputDir + '/*.pdb'
        fileList = glob(globPattern)
        nTdebug("From %s will read files: %s" % (globPattern,fileList))
        format.readCoordinates(fileList, strucGen = structureGeneration, minimalPrompts = 1, linkAtoms = 0)

    nTmessage(  'saving to new path if all checks are valid' )
    # the newPath basename will be taken according to ccpn code doc.
    ccpnPathNew = os.path.join(inputDir, projectNameNew)
    saveProject(ccpnProject, checkValid=True, newPath=ccpnPathNew, removeExisting=True)
    def runSpecific(self):
        """ Returns True on error """
        entryCodeChar2and3 = self.idCode[1:3]
        projectDirectory = os.path.join(dir_S, entryCodeChar2and3, self.idCode)
        os.chdir(projectDirectory)
        curDir = os.getcwd() #@UnusedVariable
        nTdebug("curDir: %s" % curDir)
#        ccpnDir = self.baseName #@UnusedVariable

        # Read the existing CCPN project, set up format object dict
        self.loadProject()
        self.createFormatObjects()

        self.entry = self.ccpnProject.findFirstNmrEntryStore().findFirstEntry()
        self.molSystem = self.ccpnProject.findFirstMolSystem()
        self.nmrProject = self.ccpnProject.findFirstNmrProject()
        self.strucGen = self.nmrProject.findFirstStructureGeneration()

        bmrbCodesLength = len(self.bmrbCodes)
        if not bmrbCodesLength:
            nTerror("Not a single BMRB entry presented.")
            return
        if bmrbCodesLength > 1:
            nTwarning("Currently NRG-CING only loads a single BMRB entry's CS. Skipping others.")

        # Read the BMRB NMR-STAR file (only chem shift data)
#        for bmrbCode in self.bmrbCodes:
        bmrbFile = self.bmrbCodes[0]
        bmrbCode = bmrbFile.split('_')[0]
        self.initShiftPresets(bmrbCode)
    #          bmrbNmrStarFile = os.path.join(bmrbArchiveDataDir, self.bmrbFileFormat % bmrbCode)
#        bmrb_id = int(bmrbCode[3:])
#        digits12 = "%02d" % (bmrb_id % 100)
#        inputStarDir = os.path.join(bmrbDir, digits12)
#         inputStarDir = os.path.join(bmrbDir, bmrbCode)
#         if not os.path.exists(bmrbFile):
#             nTerror("Input star dir not found: %s" % bmrbFile)
#             return True
        inputStarFile = bmrbFile
        if not os.path.exists(inputStarFile):
            nTerror("inputStarFile not found: %s" % inputStarFile)
            return True
        nTdebug("Start readNmrStarFile")
        self.readNmrStarFile(inputStarFile, components=['measurements'])
        # Try to autoset mapping...
        nTdebug("Start setBmrbNmrStarMapping")
        self.setBmrbNmrStarMapping(inputStarFile)
        # Run linkResonances, using custom keywds set above
        nTdebug("Start runLinkResonances")
        self.runLinkResonances(resonanceType='nmr')
        # Save project in new location
        newPath = self.baseName
        nTmessage('Saving to new path: %s in cwd: %s' % (newPath, os.getcwd()))
        saveProject(self.ccpnProject, removeExisting=True, newPath=newPath, newProjectName=self.baseName)
        ccpnTgzFile = "%s.tgz" % self.idCode
        cmd = "tar -czf %s %s" % (ccpnTgzFile, newPath)
        if do_cmd(cmd):
            nTerror("Failed tar")
            return None
        nTmessage("Saved ccpn project to tgz: %s" % ccpnTgzFile)
示例#3
0
    def saveFile(self):

        if not self.project:
            return False

        try:
            saveProject(self.project, createFallback=True)

            print 'successfully saved project'
            return True
        except IOError, e:
            showError('Saving file', str(e), parent=self)
            return False
示例#4
0
def _packageProject(memopsRoot):
    """Create a tar gzipped CCPN project from a MemopsRoot object"""    
    
    from memops.general.Io import saveProject, packageProject
    
    repository = memopsRoot.findFirstRepository(name='userData')
    if not repository:
        return
    
        
    projectPath = repository.url.path
    parentDir, projectDir = os.path.split(projectPath)

    
    writeable = os.access(parentDir, os.W_OK)
    if not writeable:
        msg = 'Directory %s does not have write access required to write temporary file.'
        showWarning('Warning', msg % parentDir)
        return
    
    currentProjName = memopsRoot.name
    newProjName = '__%s' % currentProjName
    newProjDir = os.path.join(parentDir, newProjName)
    
    while os.path.exists(newProjDir):
        msg = 'Filename %s exists. Overwrite?' % newProjDir
        if showYesNo('Query', msg): 
            break
        
        newProjName = '_' + newProjName
        newProjDir = os.path.join(parentDir, newProjName)
    
    try:
      saveProject(memopsRoot, newPath=newProjDir, removeExisting=True, revertToOriginal=True)
    
      packageProject(memopsRoot, filePrefix=newProjDir, userPath=newProjDir)
    finally:
      # reset project name
      # need to use override since name is frozen
      # wb104: 6 Feb 2014: should not need to do below any more because added revertToOriginal and userPath above
      #memopsRoot.override = True
      #memopsRoot.name = currentProjName
      #memopsRoot.override = False
      pass

    return newProjDir + '.tgz'
示例#5
0
def convert(projectName, inputDir, projectNameNew):
    "Testing doc strings"
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True  # From all *.pdb files in inputDir.

    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

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

    if removeOriginalStructureEnsemble:
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        if structureEnsemble:
            nTmessage("Removing first found structureEnsemble -A-")
            structureEnsemble.delete()
        else:
            nTwarning("No structureEnsemble found; can't remove it.")

    if addStructureEnsemble:
        structureGeneration = ccpnProject.newStructureGeneration()
        guiRoot = Tkinter.Tk()
        format = PseudoPdbFormat(ccpnProject, guiRoot, verbose=1)

        globPattern = inputDir + '/*.pdb'
        fileList = glob(globPattern)
        nTdebug("From %s will read files: %s" % (globPattern, fileList))
        format.readCoordinates(fileList,
                               strucGen=structureGeneration,
                               minimalPrompts=1,
                               linkAtoms=0)

    nTmessage('saving to new path if all checks are valid')
    # the newPath basename will be taken according to ccpn code doc.
    ccpnPathNew = os.path.join(inputDir, projectNameNew)
    saveProject(ccpnProject,
                checkValid=True,
                newPath=ccpnPathNew,
                removeExisting=True)
示例#6
0
def annotateEntry(entry_code, bmrb_id, *extraArgList):
    'Return True on error'
    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
#    entry_code, city = entryCodePlusCity.split('_')

# Adjust the parameters below
    isInteractive = False
    checkOrgProject = False
    doSwapCheck = False
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True
    allowPopups = False

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

    print 'entry_code                                                                                    ', entry_code
    print 'bmrb_id                                                                                       ', bmrb_id
    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'checkOrgProject                                                                               ', checkOrgProject
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

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

    ch23 = entry_code[1:3]
    dataOrgEntryDir = os.path.join(results_dir, 'recoordSync', entry_code)
    ccpnFile = os.path.join(dataOrgEntryDir, entry_code + ".tgz")
    if not os.path.exists(ccpnFile):
        nTerror("Input file not found: %s" % ccpnFile)
        return True
    nTdebug("Looking at %s" % entry_code)
    #                continue # TODO disable premature stop.

    bmrb_code = 'bmr' + bmrb_id

    digits12 = "%02d" % (bmrb_id % 100)
    inputStarDir = os.path.join(bmrbDir, digits12)
    if not os.path.exists(inputStarDir):
        nTerror("Input star dir not found: %s" % inputStarDir)
        return True
    inputStarFile = os.path.join(inputStarDir, '%s.str' % bmrb_code)
    if not os.path.exists(inputStarFile):
        nTerror("inputStarFile not found: %s" % inputStarFile)
        return True

    dataDividedXDir = os.path.join(nrgPlusDir, ch23)
    entryDir = os.path.join(dataDividedXDir, entry_code)
    outputNijmegenDir = os.path.join(entryDir, 'Nijmegen')
    if not os.path.exists(outputNijmegenDir):
        mkdirs(outputNijmegenDir)
    os.chdir(outputNijmegenDir)

    presets = getDeepByKeysOrDefault(presetDict, {}, bmrb_code)
    if presets:
        nTmessage("In annotateLoop using preset values...")
        nTdebug(str(presets))

    if os.path.exists(entry_code):
        nTmessage("Removing previous directory: %s" % entry_code)
        rmtree(entry_code)
    do_cmd("tar -xzf " + ccpnFile)
    if os.path.exists('linkNmrStarData'):
        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" %
                  entry_code)
        os.rename('linkNmrStarData', entry_code)

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

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

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

    importStarChemicalShifts(ccpnProject,
                             inputStarDir,
                             guiRoot,
                             allowPopups=allowPopups,
                             minimalPrompts=minimalPrompts,
                             verbose=verbose,
                             **presets)

    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')
        #        checkValid=True,
        saveProject(ccpnProject, newPath=entry_code, removeExisting=True)
    if doExport:
        tarPath = os.path.join(entryDir, entry_code + ".tgz")
        if os.path.exists(tarPath):
            nTmessage("Overwriting: " + tarPath)
        myTar = tarfile.open(tarPath, mode='w:gz')  # overwrites
        myTar.add(entry_code)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
示例#7
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()
示例#8
0
    def test_ccpn(self):
        #        cing.verbosity = verbosityDebug
        #        if you have a local copy you can use it; make sure to adjust the path setting below.
        fastestTest = True  # DEFAULT: True. Not passed to the validate routine in order to customize checks for speed.

        modelCount = 99  # DEFAULT: 99
        redoFromCingProject = False  # DEFAULT: False
        htmlOnly = False  # DEFAULT: False # default is False but enable it for faster runs without some actual data.
        doWhatif = True  # DEFAULT: True # disables whatif actual run
        doProcheck = True  # DEFAULT: True
        doWattos = True  # DEFAULT: True
        doQueeny = True  # DEFAULT: True
        doTalos = True  # DEFAULT: True
        filterVasco = True  # DEFAULT: True
        filterTopViolations = True  # DEFAULT: True
        useNrgArchive = False  # DEFAULT: False
        ranges = CV_STR  # DEFAULT: CV_STR
        #        ranges='173-177'
        #        ranges='6-13,29-45' # 1bus

        doSwapCheck = False
        doRestoreCheck = False
        doStoreCheck = False  # DEFAULT: False Requires sqlAlchemy
        doSave = not redoFromCingProject  # DEFAULT: False Requires sqlAlchemy

        if fastestTest:
            modelCount = 2  # DEFAULT 2
            #            redoFromCingProject = False
            htmlOnly = True  # DEFAULT: True
            doWhatif = False  # DEFAULT: False
            doProcheck = False  # DEFAULT: False
            doWattos = False  # DEFAULT: False
            doQueeny = False  # DEFAULT: False
            doTalos = False  # DEFAULT: False
            filterVasco = False  # DEFAULT: False
            doRestoreCheck = False  # DEFAULT: False
            doStoreCheck = False  # DEFAULT: False
        if redoFromCingProject:
            useNrgArchive = False
            doWhatif = False
            doProcheck = False
            doWattos = False
            doTalos = False
        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)
        for i, entryId in enumerate(AllChecks.entryList):

            if i:
                nTmessage('\n\n')
            if redoFromCingProject:
                project = Project.open(entryId, status='old')
            else:
                project = Project.open(entryId, status='new')
                self.assertTrue(project, 'Failed opening project: ' + entryId)

                if useNrgArchive:  # default is False
                    #                inputArchiveDir = os.path.join('/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    # Mounted from nmr.cmbi.ru.nl
                    #                inputArchiveDir = os.path.join('/Volumes/tria1/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    inputArchiveDir = os.path.join(
                        '/Users/jd/ccpn_tmp/data/recoord', entryId)
                else:
                    inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")

                ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
                if not os.path.exists(ccpnFile):
                    ccpnFile = os.path.join(inputArchiveDir,
                                            entryId + ".tar.gz")
                    if not os.path.exists(ccpnFile):
                        self.fail("Neither %s or the .tgz exist" % ccpnFile)

                if doSwapCheck:  # Need to start with ccpn without loading into CING api yet.
                    if os.path.exists(entryId):
                        nTmessage("Removing previous directory: %s" % entryId)
                        rmtree(entryId)
                    do_cmd("tar -xzf " +
                           ccpnFile)  # will extract to local dir.
                    if os.path.exists('linkNmrStarData'):
                        nTmessage(
                            "Renaming standard directory linkNmrStarData to entry: %s"
                            % entryId)
                        os.rename('linkNmrStarData', entryId)

                    ccpnProject = loadProject(entryId)
                    if not ccpnProject:
                        self.fail("Failed to read project: %s" % entryId)
            #        constraintsHandler = ConstraintsHandler()
                    nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore(
                    )
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble(
                    )
                    numSwapCheckRuns = 2
                    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)
                    nTmessage('Saving to new path')
                    #        checkValid=True,
                    saveProject(ccpnProject,
                                newPath=entryId,
                                removeExisting=True)
                    ccpnFile = entryId  # set to local dir now.
                # end if doSwapCheck
                self.assertTrue(
                    project.initCcpn(ccpnFolder=ccpnFile,
                                     modelCount=modelCount))
#                if doSave:
#                    self.assertTrue(project.save())

            if False:
                ranges = "173-183"
#                residueOfInterest = range(171,174)
#                for residue in project.molecule.A.allResidues():
#                    if residue.resNum not in residueOfInterest:
#    #                    nTmessage("Removing residue of no interest")
#                        project.molecule.A.removeResidue(residue)
            if False:
                ccpnProject = project.ccpn
                printSequenceFromCcpnProject(ccpnProject)

            if True:
                self.assertFalse(project.molecule.setRanges(ranges))
                nTdebug('In test_ccpn.py: ranges: %s' %
                        str(project.molecule.ranges))
                project.molecule.rangesToMmCifRanges(ranges)

            if True:
                self.assertFalse(
                    project.validate(
                        htmlOnly=htmlOnly,
                        ranges=ranges,
                        #                                              fastestTest=fastestTest, # disabled
                        doProcheck=doProcheck,
                        doWhatif=doWhatif,
                        doWattos=doWattos,
                        doQueeny=doQueeny,
                        doTalos=doTalos,
                        filterVasco=filterVasco,
                        filterTopViolations=filterTopViolations))
                if doWattos and False:
                    mol = project.molecule
                    completenessMol = mol.getDeepByKeys(
                        WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                    nTdebug("completenessMol: %s" % completenessMol)
                    for res in mol.allResidues():
                        completenessRes = res.getDeepByKeys(
                            WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                        nTdebug("%s: %s" % (res, completenessRes))
                    # end for
                # end if
                color = project.molecule.getRogColor()
                nTdebug("The color of this molecule is: %s" % color)
                self.assertFalse(color == COLOR_RED)  # ;-)
            # end if
#            self.assertTrue(project.exportValidation2ccpn())
#            self.assertFalse(project.removeCcpnReferences())
# Do not leave the old CCPN directory laying around since it might get added to by another test.
#            if os.path.exists(entryId):
#                self.assertFalse(shutil.rmtree(entryId))

            if False:
                self.assertTrue(project.save())
                self.assertTrue(project.saveCcpn(entryId))

            if doRestoreCheck:
                del project
                project = Project.open(entryId, status='old')
                self.assertTrue(project,
                                'Failed reopening project: ' + entryId)
            if doStoreCheck:
                #                # Does require below import which is used here to trigger import warning in case it's not installed.
                # pylint: disable=W0612
                from cing.PluginCode.sqlAlchemy import CsqlAlchemy  #@UnusedImport # pylint: disable=W0404
                if doStoreCING2db(entryId, ARCHIVE_NRG_ID, project=project):
                    nTerror(
                        "Failed to store CING project's data to DB but continuing."
                    )
            if doSave:
                self.assertTrue(project.save())
示例#9
0
    def makeCcpnProjectTgz(self, baseNameSuffix="", outputDir=None):

        #
        # Set up
        #

        userData = self.ccpnProject.findFirstRepository(name='userData')
        ccpnProjectDir = userData.url.path
        if not outputDir:
            outputDir = ccpnProjectDir

        tarFileBaseName = os.path.join(outputDir + baseNameSuffix)

        tarFileName = "%s.tar" % tarFileBaseName
        tgzFileName = "%s.tgz" % tarFileBaseName

        #
        # Re-save before tarring, in case of changes
        #

        if baseNameSuffix:
            saveProject(self.ccpnProject,
                        newPath=tarFileBaseName,
                        removeExisting=True)
            ccpnProjectDir = userData.url.path

        else:
            self.ccpnProject.saveModified()

        # TJS: Use Wayne's packageProject, which only packages uses .xml files

        packageProject(self.ccpnProject, tarFileBaseName)
        """
    #
    # Now go to directory containing CCPN project to make .tar file, do not want full path for project!
    #
    
    curDir = os.getcwd()
    (mainCcpnDir,projectNameDir) = os.path.split(ccpnProjectDir)
    os.chdir(mainCcpnDir)

    tar = tarfile.open(tarFileName, "w")
    tar.add(projectNameDir)
    tar.close()
    
    os.chdir(curDir)
    
    #
    # Now make .tgz, remove .tar file
    #

    inFile = open(tarFileName,'rb')
    outFile = gzip.open(tgzFileName,'wb')
    outFile.writelines(inFile)
    outFile.close()
    inFile.close()
    
    os.remove(tarFileName)
    """

        print "  Created .tgz archive %s for CCPN project %s." % (
            tgzFileName, self.ccpnProject.name)

        return tgzFileName
示例#10
0
def fcProcessEntry( entry_code, ccpnTgzFile, outputCcpnTgzFile, functionToRun='swapCheck'):
    """
    E.g.

    entry_code          1brv
    ccpnTgzFile         /NRG-CING/prep/S/br/1brv/1brv.tgz Full path
    outputCcpnTgzFile   1brv_assign.tgz but inside the project will still be keyed and named 1brv.

    Return True on error
    Can be extended later on to run a different function.
    Will run in cwd.
    """

    # Adjust the parameters below
    isInteractive = False
    doSwapCheck = True
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True
    allowPopups = False

    if isInteractive:
        allowPopups = True
        minimalPrompts = False

    print 'entry_code                                                                                    ', entry_code
#    print 'bmrb_id                                                                                       ', bmrb_id
    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

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

    if not os.path.exists(ccpnTgzFile):
        nTerror("Input file not found: %s" % ccpnTgzFile)
        return True
    nTdebug("Looking at %s" % entry_code)

    if os.path.exists(entry_code):
        nTmessage("Removing previous directory: %s" % entry_code)
        rmtree(entry_code)
    do_cmd("tar -xzf " + ccpnTgzFile) # will unpack to cwd.
    if os.path.exists('linkNmrStarData'):
        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" % entry_code)
        os.rename('linkNmrStarData', entry_code)

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

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

    if doSaveProject:
        nTmessage('Saving to new path: %s' % entry_code)
        saveProject(ccpnProject, newPath=entry_code, removeExisting=True)
    if doExport:
        if os.path.exists(outputCcpnTgzFile):
            nTmessage("Overwriting: " + outputCcpnTgzFile)
        myTar = tarfile.open(outputCcpnTgzFile, mode='w:gz') # overwrites
        myTar.add(entry_code)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
示例#11
0
    def runSpecific(self):
        """ Returns True on error """

        # Read the existing CCPN project, set up format object dict
        self.loadProject()
        self.createFormatObjects()

        self.entry = self.ccpnProject.findFirstNmrEntryStore().findFirstEntry()
        self.molSystem = self.ccpnProject.findFirstMolSystem()
        self.nmrProject = self.ccpnProject.findFirstNmrProject()
        self.strucGen = self.nmrProject.findFirstStructureGeneration()

        bmrbCodesLength = len(self.bmrbCodes)
        if not bmrbCodesLength:
            print("Not a single BMRB entry presented.")
            return
        if bmrbCodesLength > 1:
            print(
                "Currently NRG-CING only loads a single BMRB entry's CS. Skipping others."
            )

        # Read the BMRB NMR-STAR file (only chem shift data)
        bmrbCode = self.bmrbCodes[0]
        self.initShiftPresets(bmrbCode)

        inputStarDir = os.path.join(self.bmrbDir, bmrbCode)
        if not os.path.exists(inputStarDir):
            print("Input star dir not found: %s" % inputStarDir)
            return True

        inputStarFile = os.path.join(inputStarDir,
                                     self.bmrbFileFormat % bmrbCode[3:])
        if not os.path.exists(inputStarFile):
            print("inputStarFile not found: %s" % inputStarFile)
            return True
        print("Start readNmrStarFile")
        self.readNmrStarFile(inputStarFile, components=['measurements'])
        # Try to autoset mapping...
        print("Start setBmrbNmrStarMapping")
        self.setBmrbNmrStarMapping(inputStarFile)
        # Run linkResonances, using custom keywds set above
        print("Start runLinkResonances")
        self.runLinkResonances(resonanceType='nmr')
        # Save project in new location

        finalProjectDirectory = os.path.join(self.finalProjectMainDir,
                                             self.idCode)
        if not os.path.exists(finalProjectDirectory):
            os.mkdir(finalProjectDirectory)

        print('Saving to new path: %s in cwd: %s' %
              (finalProjectDirectory, os.getcwd()))
        saveProject(self.ccpnProject,
                    removeExisting=True,
                    newPath=finalProjectDirectory,
                    newProjectName=self.baseName)

        # Create .tgz of new project - can do this a bit nicer, quick hack
        curDir = os.getcwd()
        os.chdir(self.finalProjectMainDir)
        tar = tarfile.open("{}.tgz".format(self.baseName), 'w:gz')
        print self.baseName
        tar.add(self.baseName)
        tar.close()
        os.chdir(curDir)

        # Clean up non-archived CCPN projects to save disk space
        shutil.rmtree(self.ccpnProjectDir)
        shutil.rmtree(finalProjectDirectory)
示例#12
0
def replaceCoordinates():

    cityList = [ 'Cheshire', 'Frankfurt', 'Lyon', 'Paris', 'Piscataway', 'Seattle', 'Utrecht' ]
    maxCities = 1
    maxEntries = 1
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True # From all *.pdb files in inputDir.

    dataOrgDir = os.path.join(baseDir,DATA_STR)
    dataDividedDir = os.path.join(baseDir,DATA_STR)
    #        _scriptName = sys.argv[0]
    # parameters for doScriptOnEntryList
    startDir = '/Library/WebServer/Documents/' + CASD_NMR_BASE_NAME
    entryListFileName = os.path.join(startDir, 'list', 'entry_list_todo.csv')
    entryList = readLinesFromFile(entryListFileName) #@UnusedVariable
    entryList = ['ET109Aox']

    for entryCode in entryList[0:maxEntries]:
        ch23 = entryCode[1:3]
        dataOrgEntryDir = os.path.join( dataOrgDir, entryCode )
        ccpnFile = os.path.join(dataOrgEntryDir, entryCode+".tgz")
        for city in cityList[0:maxCities]:
            entryCodeNew = entryCode + city
            dataDividedXDir = os.path.join(dataDividedDir, ch23)
            inputAuthorDir = os.path.join(dataDividedXDir, entryCodeNew, 'Author')
            outputNijmegenDir = os.path.join(dataDividedXDir, entryCodeNew, 'Nijmegen')

            globPattern = inputAuthorDir + '/*.pdb'
            pdbFileList = glob(globPattern)
            if not pdbFileList:
                nTmessage("Skipping because there is no PDB file in: " + os.getcwd())
                continue

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

            os.chdir(outputNijmegenDir)
            if False:
                # By reading the ccpn tgz into cing it is also untarred/tested.
                project = Project.open(entryCode, status = 'new')
                project.initCcpn(ccpnFolder = ccpnFile, modelCount=1)
                project.removeFromDisk()
                project.close(save=False)

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

                if removeOriginalStructureEnsemble:
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble()
                    if structureEnsemble:
                        nTmessage("Removing first found structureEnsemble")
                        structureEnsemble.delete()
                    else:
                        nTwarning("No structureEnsemble found; can't remove it.")

                if addStructureEnsemble:
                    structureGeneration = nmrProject.newStructureGeneration()
                    fileList = None
                    nTdebug("From %s will read files: %s" % (globPattern,fileList))
                    guiRoot = Tkinter.Tk()
                    format = PseudoPdbFormat(ccpnProject, guiRoot, verbose = 1)
                    format.readCoordinates(fileList, strucGen = structureGeneration, minimalPrompts = 1, linkAtoms = 0)

                nTmessage(  'saving to new path if all checks are valid' )
                # the newPath basename will be taken according to ccpn code doc.
                saveProject(ccpnProject, checkValid=True, newPath=entryCodeNew, removeExisting=True)
示例#13
0
def annotateEntry(entry_code, bmrb_id, *extraArgList):
    'Return True on error'
    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
#    entry_code, city = entryCodePlusCity.split('_')

    # Adjust the parameters below
    isInteractive = False
    checkOrgProject = False
    doSwapCheck = False
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True
    allowPopups = False

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

    print 'entry_code                                                                                    ', entry_code
    print 'bmrb_id                                                                                       ', bmrb_id
    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'checkOrgProject                                                                               ', checkOrgProject
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

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

    ch23 = entry_code[1:3]
    dataOrgEntryDir = os.path.join(results_dir, 'recoordSync', entry_code)
    ccpnFile = os.path.join(dataOrgEntryDir, entry_code + ".tgz")
    if not os.path.exists(ccpnFile):
        nTerror("Input file not found: %s" % ccpnFile)
        return True
    nTdebug("Looking at %s" % entry_code)
#                continue # TODO disable premature stop.

    bmrb_code = 'bmr'+bmrb_id

    digits12 ="%02d" % ( bmrb_id % 100 )
    inputStarDir = os.path.join(bmrbDir, digits12)
    if not os.path.exists(inputStarDir):
        nTerror("Input star dir not found: %s" % inputStarDir)
        return True
    inputStarFile = os.path.join(inputStarDir, '%s.str'%bmrb_code)
    if not os.path.exists(inputStarFile):
        nTerror("inputStarFile not found: %s" % inputStarFile)
        return True

    dataDividedXDir = os.path.join(nrgPlusDir, ch23)
    entryDir = os.path.join(dataDividedXDir, entry_code)
    outputNijmegenDir = os.path.join(entryDir, 'Nijmegen')
    if not os.path.exists(outputNijmegenDir):
        mkdirs(outputNijmegenDir)
    os.chdir(outputNijmegenDir)

    presets = getDeepByKeysOrDefault(presetDict, {}, bmrb_code)
    if presets:
        nTmessage("In annotateLoop using preset values...")
        nTdebug(str(presets))

    if os.path.exists(entry_code):
        nTmessage("Removing previous directory: %s" % entry_code)
        rmtree(entry_code)
    do_cmd("tar -xzf " + ccpnFile)
    if os.path.exists('linkNmrStarData'):
        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" % entry_code)
        os.rename('linkNmrStarData', entry_code)

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

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

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

    importStarChemicalShifts(ccpnProject, inputStarDir, guiRoot, allowPopups=allowPopups, minimalPrompts=minimalPrompts, 
                             verbose=verbose, **presets)

    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')
#        checkValid=True,
        saveProject(ccpnProject, newPath=entry_code, removeExisting=True)
    if doExport:
        tarPath = os.path.join(entryDir, entry_code + ".tgz")
        if os.path.exists(tarPath):
            nTmessage("Overwriting: " + tarPath)
        myTar = tarfile.open(tarPath, mode='w:gz') # overwrites
        myTar.add(entry_code)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
示例#14
0
def replaceCoordinates():

    cityList = [
        'Cheshire', 'Frankfurt', 'Lyon', 'Paris', 'Piscataway', 'Seattle',
        'Utrecht'
    ]
    maxCities = 1
    maxEntries = 1
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True  # From all *.pdb files in inputDir.

    dataOrgDir = os.path.join(baseDir, DATA_STR)
    dataDividedDir = os.path.join(baseDir, DATA_STR)
    #        _scriptName = sys.argv[0]
    # parameters for doScriptOnEntryList
    startDir = '/Library/WebServer/Documents/' + CASD_NMR_BASE_NAME
    entryListFileName = os.path.join(startDir, 'list', 'entry_list_todo.csv')
    entryList = readLinesFromFile(entryListFileName)  #@UnusedVariable
    entryList = ['ET109Aox']

    for entryCode in entryList[0:maxEntries]:
        ch23 = entryCode[1:3]
        dataOrgEntryDir = os.path.join(dataOrgDir, entryCode)
        ccpnFile = os.path.join(dataOrgEntryDir, entryCode + ".tgz")
        for city in cityList[0:maxCities]:
            entryCodeNew = entryCode + city
            dataDividedXDir = os.path.join(dataDividedDir, ch23)
            inputAuthorDir = os.path.join(dataDividedXDir, entryCodeNew,
                                          'Author')
            outputNijmegenDir = os.path.join(dataDividedXDir, entryCodeNew,
                                             'Nijmegen')

            globPattern = inputAuthorDir + '/*.pdb'
            pdbFileList = glob(globPattern)
            if not pdbFileList:
                nTmessage("Skipping because there is no PDB file in: " +
                          os.getcwd())
                continue

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

            os.chdir(outputNijmegenDir)
            if False:
                # By reading the ccpn tgz into cing it is also untarred/tested.
                project = Project.open(entryCode, status='new')
                project.initCcpn(ccpnFolder=ccpnFile, modelCount=1)
                project.removeFromDisk()
                project.close(save=False)

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

                if removeOriginalStructureEnsemble:
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble(
                    )
                    if structureEnsemble:
                        nTmessage("Removing first found structureEnsemble")
                        structureEnsemble.delete()
                    else:
                        nTwarning(
                            "No structureEnsemble found; can't remove it.")

                if addStructureEnsemble:
                    structureGeneration = nmrProject.newStructureGeneration()
                    fileList = None
                    nTdebug("From %s will read files: %s" %
                            (globPattern, fileList))
                    guiRoot = Tkinter.Tk()
                    format = PseudoPdbFormat(ccpnProject, guiRoot, verbose=1)
                    format.readCoordinates(fileList,
                                           strucGen=structureGeneration,
                                           minimalPrompts=1,
                                           linkAtoms=0)

                nTmessage('saving to new path if all checks are valid')
                # the newPath basename will be taken according to ccpn code doc.
                saveProject(ccpnProject,
                            checkValid=True,
                            newPath=entryCodeNew,
                            removeExisting=True)
示例#15
0
    def runSpecific(self):
        """ Returns True on error """

        # Read the existing CCPN project, set up format object dict
        self.loadProject()
        self.createFormatObjects()

        self.entry = self.ccpnProject.findFirstNmrEntryStore().findFirstEntry()
        self.molSystem = self.ccpnProject.findFirstMolSystem()
        self.nmrProject = self.ccpnProject.findFirstNmrProject()
        self.strucGen = self.nmrProject.findFirstStructureGeneration()

        bmrbCodesLength = len(self.bmrbCodes)
        if not bmrbCodesLength:
            print("Not a single BMRB entry presented.")
            return
        if bmrbCodesLength > 1:
            print("Currently NRG-CING only loads a single BMRB entry's CS. Skipping others.")

        # Read the BMRB NMR-STAR file (only chem shift data)
        bmrbCode = self.bmrbCodes[0]
        self.initShiftPresets(bmrbCode)

        inputStarDir = os.path.join(self.bmrbDir, bmrbCode)
        if not os.path.exists(inputStarDir):
            print("Input star dir not found: %s" % inputStarDir)
            return True
            
        inputStarFile = os.path.join(inputStarDir, self.bmrbFileFormat % bmrbCode[3:])
        if not os.path.exists(inputStarFile):
            print("inputStarFile not found: %s" % inputStarFile)
            return True
        print("Start readNmrStarFile")
        self.readNmrStarFile(inputStarFile, components=['measurements'])
        # Try to autoset mapping...
        print("Start setBmrbNmrStarMapping")
        self.setBmrbNmrStarMapping(inputStarFile)
        # Run linkResonances, using custom keywds set above
        print("Start runLinkResonances")
        self.runLinkResonances(resonanceType='nmr')
        # Save project in new location
        
        
        finalProjectDirectory = os.path.join(self.finalProjectMainDir,self.idCode)
        if not os.path.exists(finalProjectDirectory):
          os.mkdir(finalProjectDirectory)

        print('Saving to new path: %s in cwd: %s' % (finalProjectDirectory, os.getcwd()))
        saveProject(self.ccpnProject, removeExisting=True, newPath=finalProjectDirectory, newProjectName=self.baseName)
                
        # Create .tgz of new project - can do this a bit nicer, quick hack
        curDir = os.getcwd()
        os.chdir(self.finalProjectMainDir)
        tar = tarfile.open("{}.tgz".format(self.baseName),'w:gz')
        print self.baseName
        tar.add(self.baseName)
        tar.close()
        os.chdir(curDir)
        
        # Clean up non-archived CCPN projects to save disk space        
        shutil.rmtree(self.ccpnProjectDir)
        shutil.rmtree(finalProjectDirectory)
示例#16
0
    def test_ccpn(self):
#        cing.verbosity = verbosityDebug
#        if you have a local copy you can use it; make sure to adjust the path setting below.
        fastestTest = True             # DEFAULT: True. Not passed to the validate routine in order to customize checks for speed.

        modelCount=99                  # DEFAULT: 99 
        redoFromCingProject = False    # DEFAULT: False 
        htmlOnly = False               # DEFAULT: False # default is False but enable it for faster runs without some actual data.
        doWhatif = True                # DEFAULT: True # disables whatif actual run
        doProcheck = True              # DEFAULT: True 
        doWattos = True                # DEFAULT: True 
        doQueeny = True                # DEFAULT: True 
        doTalos = True                 # DEFAULT: True 
        filterVasco = True             # DEFAULT: True 
        filterTopViolations = True     # DEFAULT: True 
        useNrgArchive = False          # DEFAULT: False 
        ranges = CV_STR                # DEFAULT: CV_STR 
#        ranges='173-177'
#        ranges='6-13,29-45' # 1bus

        doSwapCheck = False
        doRestoreCheck = False
        doStoreCheck = False # DEFAULT: False Requires sqlAlchemy
        doSave = not redoFromCingProject  # DEFAULT: False Requires sqlAlchemy

        if fastestTest:
            modelCount=2 # DEFAULT 2
#            redoFromCingProject = False
            htmlOnly = True            # DEFAULT: True
            doWhatif = False           # DEFAULT: False
            doProcheck = False         # DEFAULT: False
            doWattos = False           # DEFAULT: False
            doQueeny = False           # DEFAULT: False
            doTalos = False            # DEFAULT: False
            filterVasco = False        # DEFAULT: False
            doRestoreCheck = False     # DEFAULT: False
            doStoreCheck = False       # DEFAULT: False
        if redoFromCingProject:
            useNrgArchive = False
            doWhatif = False
            doProcheck = False
            doWattos = False
            doTalos = False
        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)
        for i,entryId in enumerate(AllChecks.entryList):

            if i:
                nTmessage('\n\n')
            if redoFromCingProject:
                project = Project.open(entryId, status = 'old')
            else:
                project = Project.open(entryId, status = 'new')
                self.assertTrue(project, 'Failed opening project: ' + entryId)

                if useNrgArchive: # default is False
    #                inputArchiveDir = os.path.join('/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    # Mounted from nmr.cmbi.ru.nl
    #                inputArchiveDir = os.path.join('/Volumes/tria1/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    inputArchiveDir = os.path.join('/Users/jd/ccpn_tmp/data/recoord', entryId)
                else:
                    inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")

                ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
                if not os.path.exists(ccpnFile):
                    ccpnFile = os.path.join(inputArchiveDir, entryId + ".tar.gz")
                    if not os.path.exists(ccpnFile):
                        self.fail("Neither %s or the .tgz exist" % ccpnFile)

                if doSwapCheck: # Need to start with ccpn without loading into CING api yet.
                    if os.path.exists(entryId):
                        nTmessage("Removing previous directory: %s" % entryId)
                        rmtree(entryId)
                    do_cmd("tar -xzf " + ccpnFile) # will extract to local dir.
                    if os.path.exists('linkNmrStarData'):
                        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" % entryId)
                        os.rename('linkNmrStarData', entryId)

                    ccpnProject = loadProject(entryId)
                    if not ccpnProject:
                        self.fail("Failed to read project: %s" % entryId)
            #        constraintsHandler = ConstraintsHandler()
                    nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore()
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble()
                    numSwapCheckRuns = 2
                    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)
                    nTmessage('Saving to new path')
            #        checkValid=True,
                    saveProject(ccpnProject, newPath=entryId, removeExisting=True)
                    ccpnFile = entryId # set to local dir now.
                # end if doSwapCheck
                self.assertTrue(project.initCcpn(ccpnFolder = ccpnFile, modelCount=modelCount))
#                if doSave:
#                    self.assertTrue(project.save())

            if False:
                ranges = "173-183"
#                residueOfInterest = range(171,174)
#                for residue in project.molecule.A.allResidues():
#                    if residue.resNum not in residueOfInterest:
#    #                    nTmessage("Removing residue of no interest")
#                        project.molecule.A.removeResidue(residue)
            if False:
                ccpnProject = project.ccpn
                printSequenceFromCcpnProject(ccpnProject)

            if True:
                self.assertFalse(project.molecule.setRanges(ranges))
                nTdebug('In test_ccpn.py: ranges: %s' % str(project.molecule.ranges))
                project.molecule.rangesToMmCifRanges(ranges)

            if True:
                self.assertFalse(project.validate(htmlOnly = htmlOnly,
                                              ranges=ranges,
#                                              fastestTest=fastestTest, # disabled
                                              doProcheck = doProcheck,
                                              doWhatif = doWhatif,
                                              doWattos=doWattos,
                                              doQueeny = doQueeny,
                                              doTalos=doTalos,
                                              filterVasco=filterVasco,
                                              filterTopViolations = filterTopViolations
                                               ))
                if doWattos and False:
                    mol = project.molecule
                    completenessMol = mol.getDeepByKeys( WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                    nTdebug("completenessMol: %s" % completenessMol)
                    for res in mol.allResidues():
                        completenessRes = res.getDeepByKeys( WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                        nTdebug("%s: %s" % (res, completenessRes))
                    # end for
                # end if
                color = project.molecule.getRogColor()
                nTdebug("The color of this molecule is: %s" % color)
                self.assertFalse( color == COLOR_RED ) # ;-)
            # end if
#            self.assertTrue(project.exportValidation2ccpn())
#            self.assertFalse(project.removeCcpnReferences())
            # Do not leave the old CCPN directory laying around since it might get added to by another test.
#            if os.path.exists(entryId):
#                self.assertFalse(shutil.rmtree(entryId))

            if False:
                self.assertTrue(project.save())
                self.assertTrue(project.saveCcpn(entryId))

            if doRestoreCheck:
                del project
                project = Project.open(entryId, status = 'old')
                self.assertTrue(project, 'Failed reopening project: ' + entryId)
            if doStoreCheck:
#                # Does require below import which is used here to trigger import warning in case it's not installed.
                # pylint: disable=W0612
                from cing.PluginCode.sqlAlchemy import CsqlAlchemy #@UnusedImport # pylint: disable=W0404
                if doStoreCING2db( entryId, ARCHIVE_NRG_ID, project=project):
                    nTerror("Failed to store CING project's data to DB but continuing.")
            if doSave:
                self.assertTrue(project.save())