Exemple #1
0
def importFullStarProjects(starFileName, projectName, inputDir='.', outputDir='.', guiRoot=None, allowPopups=0,minimalPrompts=1,verbose=1):
    '''Returns a full CCPN project rooted in inputDir/projectName that will be created and saved.
    Input will be from inputDir/starFileName

    Returns False for error.
    '''

    if not os.path.exists(inputDir):
        nTerror("Failed to find inputDir: %s" % inputDir)
        return False
    starFileNameFull = os.path.join(inputDir, starFileName)
    if not os.path.exists(starFileNameFull):
        nTerror("Failed to find starFileNameFull: %s" % starFileNameFull)
        return False
    if not os.path.exists(outputDir):
        os.mkdir(outputDir)
    os.chdir(outputDir)

    ccpnProjectPath = os.path.join(outputDir, projectName)
    if os.path.exists(ccpnProjectPath):
        shutil.rmtree(ccpnProjectPath)

    ccpnProject = Implementation.MemopsRoot(name=projectName)

#    'linkAtoms':                (True,False,'If set to False (off), unrecognized coordinate atoms will not be linked.'),
    keywds = {'minimalPrompts': minimalPrompts, 'allowPopups': allowPopups, 'linkAtoms':0}
    formatNmrStarFormat = NmrStarFormat(ccpnProject, guiRoot, verbose=verbose, **keywds)
    formatNmrStarFormat.version = '3.1'
    entryTitle = 'Project from NMR-STAR for %s' % projectName
    entryDetails = "Created by Wim Vranken's FormatConverter embedded in CING"
    formatNmrStarFormat.getFullProject( starFileNameFull, title = entryTitle, details = entryDetails, **keywds)
#    nmrConstraintStore = shiftList.nmrConstraintStore
#    structureGeneration = nmrConstraintStore.findFirstStructureGeneration()
#    formatNmrStarFormat.linkResonances(
#                  forceDefaultChainMapping=1, # may be overwritten by using forceChainMappings.
#                  globalStereoAssign=1,
#                  setSingleProchiral=1,
#                  setSinglePossEquiv=1,
##                  strucGen=structureGeneration,
#                  allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **keywds)
    # Catch entries like mentioned in issue

    try:
        ccpnProject.checkAllValid()
    except ApiError:
        nTtracebackError()
        nTerror("Failed ccpnProject.checkAllValid")
        nTerror("See issue: %s%d" % (issueListUrl, 266))
        return False

    ccpnProject.saveModified()

    if not os.path.exists(ccpnProjectPath):
        nTerror("Failed to find new CCPN project directory: %s" % ccpnProjectPath)
        return False
    tgzFileName = projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)

    return ccpnProject
Exemple #2
0
 def _test_anneal(self):
     'Test the anneal'
     cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
     mkdirs(cingDirTmpTest)
     self.failIf(os.chdir(cingDirTmpTest),
                 msg="Failed to change to test directory for files: " +
                 cingDirTmpTest)
     inputArchiveDir = os.path.join(cingDirTestsData, "xplor")
     for _i, entryId in enumerate(AllChecks.entryList):
         nTmessage('Doing entry %s' % entryId)
         cingDirTmpTestEntry = entryId
         mkdirs(cingDirTmpTestEntry)
         self.failIf(
             os.chdir(cingDirTmpTestEntry),
             msg="Failed to change to test entry directory for files: " +
             cingDirTmpTestEntry)
         do_cmd("rm -f *_extended_*.pdb* >& /dev/null")
         inputDir = os.path.join(inputArchiveDir, entryId)
         self.failIf(not os.path.exists(inputDir),
                     "Missing input dir " + inputDir)
         nTmessage('Trying to copy input files')
         copydir(os.path.join(inputDir, '*'), '.')
         xplorExecutable = '/Users/jd/workspace/xplor-nih-2.27/bin/xplor'
         xplorScript = '$CINGROOT/python/xplorcing/anneal.py'
         cmd = 'env -i PATH=$PATH HOME=$HOME USER=$USER %s -py %s %s >& anneal.log' % (
             xplorExecutable,
             xplorScript,
             entryId,
             #                os.getcwd(), # inputDir
             #                os.getcwd(), # outputDir
         )
         if do_cmd(cmd):
             nTerror("Failed anneal")
         else:
             nTmessage("Succeeded anneal")
Exemple #3
0
def convert(projectName, rootDir):
    datasetDir = os.path.join(rootDir, projectName)
    nijmegenDir = os.path.join(datasetDir, "Nijmegen")
    authorDir = os.path.join(datasetDir, "Authors")
    os.chdir(nijmegenDir)

    projectPath = os.path.join(nijmegenDir, projectName)
    if os.path.exists(projectPath):
        shutil.rmtree(projectPath)

    project = Implementation.MemopsRoot(name = projectName)

    nmrProject = project.newNmrProject(name = project.name)
    structureGeneration = nmrProject.newStructureGeneration()
    guiRoot = Tkinter.Tk()
    format = PseudoPdbFormat(project, guiRoot, verbose = 1)

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

    project.saveModified()
    tgzFileName = "../"+projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)
Exemple #4
0
def convert(projectName, rootDir):
    datasetDir = os.path.join(rootDir, projectName)
    nijmegenDir = os.path.join(datasetDir, "Nijmegen")
    authorDir = os.path.join(datasetDir, "Authors")
    os.chdir(nijmegenDir)

    projectPath = os.path.join(nijmegenDir, projectName)
    if os.path.exists(projectPath):
        shutil.rmtree(projectPath)

    project = Implementation.MemopsRoot(name=projectName)

    nmrProject = project.newNmrProject(name=project.name)
    structureGeneration = nmrProject.newStructureGeneration()
    guiRoot = Tkinter.Tk()
    format = PseudoPdbFormat(project, guiRoot, verbose=1)

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

    project.saveModified()
    tgzFileName = "../" + projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)
Exemple #5
0
    def _test_anneal(self):
        'Test the anneal'
        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)
        inputArchiveDir = os.path.join(cingDirTestsData, "xplor")
        for _i,entryId in enumerate(AllChecks.entryList):
            nTmessage('Doing entry %s' % entryId)
            cingDirTmpTestEntry = entryId
            mkdirs( cingDirTmpTestEntry )
            self.failIf(os.chdir(cingDirTmpTestEntry), msg =
                "Failed to change to test entry directory for files: " + cingDirTmpTestEntry)
            do_cmd( "rm -f *_extended_*.pdb* >& /dev/null" )
            inputDir = os.path.join(inputArchiveDir, entryId )
            self.failIf( not os.path.exists(inputDir), "Missing input dir " + inputDir)
            nTmessage('Trying to copy input files' )
            copydir( os.path.join(inputDir, '*'), '.')
            xplorExecutable = '/Users/jd/workspace/xplor-nih-2.27/bin/xplor'
            xplorScript = '$CINGROOT/python/xplorcing/anneal.py'
            cmd = 'env -i PATH=$PATH HOME=$HOME USER=$USER %s -py %s %s >& anneal.log' % (
                xplorExecutable, xplorScript,
                entryId,
#                os.getcwd(), # inputDir
#                os.getcwd(), # outputDir
                )
            if do_cmd( cmd ):
                nTerror("Failed anneal")
            else:
                nTmessage("Succeeded anneal")
Exemple #6
0
def convertStar2Ccpn(projectName, rootDir, inputDir="XPLOR", outputDir="CCPN"):
    """The structure when done will be:

    rootDir -> -> inputDir -> xxxx.pdb etc.
               -> outputDir -> xxxx -> ccp etc.
               -> xxxx.tgz (the resulting CCPN data)

    E.g.
    taf3Piscataway -> Authors ->  all.pdb etc.
                   -> Nijmegen -> taf3Piscataway -> ccp etc.
                   -> taf3Piscataway.tgz

    Or in iCingSetup the rootDir is eg: /Library/WebServer/Documents/tmp/cing/ano/WjtXOz
    with project name gb1

    WjtXOz -> XPLOR  -> gb1.pdb etc.
           -> CCPN   -> gb1 -> ccpn etc.
           -> gb1.tgz


    The in and out paths are relative to the rootDir.
            """

    nTerror("This routine is untested and shouldn't be used without.")
    inputDir = os.path.join(rootDir, inputDir)
    outputDir = os.path.join(rootDir, outputDir)

    if not os.path.exists(inputDir):
        nTerror("Failed to find")
    if os.path.exists(outputDir):
        shutil.rmtree(outputDir)

    os.mkdir(outputDir)
    os.chdir(outputDir)

    ccpnProjectPath = os.path.join(outputDir, projectName)
    if os.path.exists(ccpnProjectPath):
        shutil.rmtree(ccpnProjectPath)

    project = Implementation.MemopsRoot(name=projectName)

    guiRoot = Tkinter.Tk()  #  headless possible?
    importStarChemicalShifts(project,
                             inputDir,
                             guiRoot,
                             allowPopups=0,
                             minimalPrompts=1,
                             verbose=0)
    project.saveModified()
    tgzFileName = "../" + projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)
    guiRoot.destroy()
Exemple #7
0
def convertStar2Ccpn(projectName, rootDir, inputDir="XPLOR", outputDir="CCPN"):
    """The structure when done will be:

    rootDir -> -> inputDir -> xxxx.pdb etc.
               -> outputDir -> xxxx -> ccp etc.
               -> xxxx.tgz (the resulting CCPN data)

    E.g.
    taf3Piscataway -> Authors ->  all.pdb etc.
                   -> Nijmegen -> taf3Piscataway -> ccp etc.
                   -> taf3Piscataway.tgz

    Or in iCingSetup the rootDir is eg: /Library/WebServer/Documents/tmp/cing/ano/WjtXOz
    with project name gb1

    WjtXOz -> XPLOR  -> gb1.pdb etc.
           -> CCPN   -> gb1 -> ccpn etc.
           -> gb1.tgz


    The in and out paths are relative to the rootDir.
            """

    nTerror("This routine is untested and shouldn't be used without.")
    inputDir = os.path.join(rootDir, inputDir)
    outputDir = os.path.join(rootDir, outputDir)

    if not os.path.exists(inputDir):
        nTerror("Failed to find")
    if os.path.exists(outputDir):
        shutil.rmtree(outputDir)

    os.mkdir(outputDir)
    os.chdir(outputDir)

    ccpnProjectPath = os.path.join(outputDir, projectName)
    if os.path.exists(ccpnProjectPath):
        shutil.rmtree(ccpnProjectPath)

    project = Implementation.MemopsRoot(name=projectName)

    guiRoot = Tkinter.Tk() #  headless possible?
    importStarChemicalShifts(project, inputDir, guiRoot, allowPopups=0, minimalPrompts=1, verbose=0)
    project.saveModified()
    tgzFileName = "../" + projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)
    guiRoot.destroy()
    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)
Exemple #9
0
def convertCyana2Ccpn(projectName, rootDir):
    guiRoot = Tkinter.Tk()
    datasetDir = os.path.join(rootDir, projectName)
    nijmegenDir = os.path.join(datasetDir, "Nijmegen")
    authorDir = os.path.join(datasetDir, "Authors")
    os.chdir(nijmegenDir)

    projectPath = os.path.join(nijmegenDir, projectName)
    if os.path.exists(projectPath):
        shutil.rmtree(projectPath)

    project = Implementation.MemopsRoot(name=projectName)

    importCyanaCoorAndRes(project, authorDir, guiRoot)
    project.saveModified()
    tgzFileName = "../" + projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)
    guiRoot.destroy()
Exemple #10
0
def convertCyana2Ccpn(projectName, rootDir):
    guiRoot = Tkinter.Tk()
    datasetDir = os.path.join(rootDir, projectName)
    nijmegenDir = os.path.join(datasetDir, "Nijmegen")
    authorDir = os.path.join(datasetDir, "Authors")
    os.chdir(nijmegenDir)

    projectPath = os.path.join(nijmegenDir, projectName)
    if os.path.exists(projectPath):
        shutil.rmtree(projectPath)

    project = Implementation.MemopsRoot(name=projectName)

    importCyanaCoorAndRes(project, authorDir, guiRoot)
    project.saveModified()
    tgzFileName = "../" + projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)
    guiRoot.destroy()
Exemple #11
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())
Exemple #12
0
def importFullStarProjects(starFileName,
                           projectName,
                           inputDir='.',
                           outputDir='.',
                           guiRoot=None,
                           allowPopups=0,
                           minimalPrompts=1,
                           verbose=1):
    '''Returns a full CCPN project rooted in inputDir/projectName that will be created and saved.
    Input will be from inputDir/starFileName

    Returns False for error.
    '''

    if not os.path.exists(inputDir):
        nTerror("Failed to find inputDir: %s" % inputDir)
        return False
    starFileNameFull = os.path.join(inputDir, starFileName)
    if not os.path.exists(starFileNameFull):
        nTerror("Failed to find starFileNameFull: %s" % starFileNameFull)
        return False
    if not os.path.exists(outputDir):
        os.mkdir(outputDir)
    os.chdir(outputDir)

    ccpnProjectPath = os.path.join(outputDir, projectName)
    if os.path.exists(ccpnProjectPath):
        shutil.rmtree(ccpnProjectPath)

    ccpnProject = Implementation.MemopsRoot(name=projectName)

    #    'linkAtoms':                (True,False,'If set to False (off), unrecognized coordinate atoms will not be linked.'),
    keywds = {
        'minimalPrompts': minimalPrompts,
        'allowPopups': allowPopups,
        'linkAtoms': 0
    }
    formatNmrStarFormat = NmrStarFormat(ccpnProject,
                                        guiRoot,
                                        verbose=verbose,
                                        **keywds)
    formatNmrStarFormat.version = '3.1'
    entryTitle = 'Project from NMR-STAR for %s' % projectName
    entryDetails = "Created by Wim Vranken's FormatConverter embedded in CING"
    formatNmrStarFormat.getFullProject(starFileNameFull,
                                       title=entryTitle,
                                       details=entryDetails,
                                       **keywds)
    #    nmrConstraintStore = shiftList.nmrConstraintStore
    #    structureGeneration = nmrConstraintStore.findFirstStructureGeneration()
    #    formatNmrStarFormat.linkResonances(
    #                  forceDefaultChainMapping=1, # may be overwritten by using forceChainMappings.
    #                  globalStereoAssign=1,
    #                  setSingleProchiral=1,
    #                  setSinglePossEquiv=1,
    ##                  strucGen=structureGeneration,
    #                  allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **keywds)
    # Catch entries like mentioned in issue

    try:
        ccpnProject.checkAllValid()
    except ApiError:
        nTtracebackError()
        nTerror("Failed ccpnProject.checkAllValid")
        nTerror("See issue: %s%d" % (issueListUrl, 266))
        return False

    ccpnProject.saveModified()

    if not os.path.exists(ccpnProjectPath):
        nTerror("Failed to find new CCPN project directory: %s" %
                ccpnProjectPath)
        return False
    tgzFileName = projectName + ".tgz"
    cmd = "tar -czf %s %s" % (tgzFileName, projectName)
    do_cmd(cmd)

    return ccpnProject
Exemple #13
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())
    def _test_CombineRestraints(self):
        '''
        This unit test is by default disabled because we haven't figured out yet how to disable the output from
        Yasara yet.
        
        Input is a CING project from the test data.
        '''

        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)

        # Original project
        #        entryId = 'H2_2Ca_64_100'
        _basicStats = """
 pdb e.res_count b.deposition_date c.name r.number r.name a1.name a2.name 
                                                    csd   chi1_avg chi2_avg chi1_cv chi2_cv           
 1brv        32 1996-03-29      A 180 LEU  CD1  CD2  0.0  270.3    170.5    0.000   0.000 no SSA delta
 1brv        32 1996-03-29      A 183 LEU  CD1  CD2  2.3  285.2    180.6    0.000   0.000 no SSA delta
 1brv        32 1996-03-29      A 185 LEU  CD1  CD2  0.4  313.5    172.1    0.054   0.045 no SSA delta/beta

 2loj        63 2012-01-24      A  20 LEU  CD1  CD2  1.3  302.2    178.2    0.002   0.001
 2loj        63 2012-01-24      A  33 LEU  CD1  CD2  -1.5 72.0     168.8    0.001   0.002
 2loj        63 2012-01-24      A  34 LEU  CD1  CD2  3.0  295.7    176.1    0.001   0.001
 2loj <=     63 2012-01-24      A  50 LEU  CD1  CD2  -2.2 184.2    283.6    0.002   0.001 chi2 > 240
 2loj        63 2012-01-24      A  51 LEU  CD1  CD2  -1.3 181.5    59.6     0.001   0.001
 2loj        63 2012-01-24      A  59 LEU  CD1  CD2  2.2  286.8    174.6    0.001   0.001
 2loj        63 2012-01-24      A  60 LEU  CD1  CD2  -0.3 203.4    66.6     0.049   0.002
 2loj <=     63 2012-01-24      A  61 LEU  CD1  CD2  -1.6 197.5    289.6    0.001   0.001 chi2 > 240 no SSA beta

 2fwu       159 2006-02-03      A 526 LEU  CD1  CD2  2.2  297.3    306.8    0.003   0.001 chi2 > 240
 2fwu       159 2006-02-03      A 560 LEU  CD1  CD2  1.8  293.8    173.6    0.002   0.001 
 2fwu       159 2006-02-03      A 589 LEU  CD1  CD2  -1.1 205.0    301.3    0.001   0.000 chi2 > 240
 2fwu       159 2006-02-03      A 596 LEU  CD1  CD2  -0.5 220.3    318.1    0.002   0.002 chi2 > 240 
 2fwu       159 2006-02-03      A 642 LEU  CD1  CD2  -4.1 178.5    70.9     0.001   0.000
"""
        entryId = '2fwu'
        #        entryId = '1brv'
        #        entryId = '2loj'
        #        entryId = 'H2_2Ca_64_100'
        modelCount = 20  # DEFAULT: 20 Not valid for starting from CING project.
        doCcpn = True  # Test entry starting from CCPN project e.g. from NRG-CING.
        threshold = 0  # minimal violation, necessary to classify the restraints.
        deasHB = True  # first deassign all HBs in the specified leucines
        dihrCHI2 = True  # add a dihedral restraint on the leucines.
        useAll = False  # DEFAULT: False. use all leucines regardless of state
        useLeuList = False  # If useAll is False and useLeuList is False then the leucines will be automatically detected
        doPrepCingProject = False  # DEFAULT: True  # NB If False this script will prefer a restore from the virgin .tgz
        doRunRotateLeucines = False  # DEFAULT: True  # NB If False this script will prefer a restore from the virgin .tgz
        # No changes needed below. ################################################################################################
        if entryId == 'H2_2Ca_64_100' or entryId == '2fwu':
            useLeuList = (('A', 589), ('A', 596), ('A', 618))
#        elif entryId == '1brv':
#            useLeuList = (('A', 180),('A', 185),)
#        elif entryId == '2loj':            # Commented out will lead to automatic detection.
#            useLeuList = (('A', 50),('A', 61),)
# end if

        nTmessage("Starting %s" % getCallerName())
        nTmessage("entryId             %s" % entryId)
        nTmessage("modelCount          %s" % modelCount)
        nTmessage("doCcpn              %s" % doCcpn)
        nTmessage("threshold           %s" % threshold)
        nTmessage("deasHB              %s" % deasHB)
        nTmessage("dihrCHI2            %s" % dihrCHI2)
        nTmessage("useAll              %s" % useAll)
        nTmessage("useLeuList          %s" % str(useLeuList))
        nTmessage("doPrepCingProject   %s" % doPrepCingProject)
        nTmessage("doRunRotateLeucines %s" % doRunRotateLeucines)
        # project with rotated leucines (created with RotateLeucines).
        entry2Id = entryId + '_' + ROTL_STR
        # NO CHANGES NEEDED BELOW THIS LINE.
        if doCcpn:
            nTmessage("Creating project from CCPN first.")
            if doPrepCingProject:
                project = Project.open(entryId, status='new')
                inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")
                ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
                project.initCcpn(ccpnFolder=ccpnFile, modelCount=modelCount)
                project.close()
                del project
                do_cmd('tar -czf %s.cing.tgz %s.cing' % (entryId, entryId))
            # end if
            inputCingArchiveDir = cingDirTmpTest  # cwd.is input dir.
        else:
            inputCingArchiveDir = os.path.join(cingDirTestsData, "cing")
        # end if
        # Create a copy of the original cing project locally
        # Then duplicate the project to a cing project that has rotated leucines.
        # It will also close and GC the large objects for efficiency.
        if doRunRotateLeucines:
            status = runRotateLeucines(cingDirTmpTest,
                                       inputCingArchiveDir,
                                       entryId,
                                       useAll=useAll,
                                       useLeuList=useLeuList)
            self.assertFalse(status)
        # end if
        # Restore the 2 projects. The first project will be modified based on the info in the second project.
        proj1 = Project.open(
            entryId,
            status='old')  # NB Will prefer a restore from the virgin .tgz
        proj2 = Project.open(entry2Id, status='old')
        self.assertTrue(proj1 and proj2)
        project = proj1
        #### BLOCK BEGIN repeated in rotateLeucines
        if not useAll and useLeuList:
            leuList = project.decodeResidueList(useLeuList)
            if not leuList:
                nTerror('Failed to decodeResidueList')
                return True
            # end if
        else:
            leuList = selectBadLeucineList(project,
                                           CV_THRESHOLD_SELECTION,
                                           useAll=useAll)
        # end if
        if leuList == None:
            nTerror('Failed to selectBadLeucineList')
            return True
        # end if
        #### BLOCK BEGIN
        status = alterRestraintsForLeus(leuList, proj1, proj2, threshold,
                                        deasHB, dihrCHI2)
        self.assertTrue(status)
        proj1.save()
def mainCasd(entryId, *extraArgList):
    """inputDir may be a directory or a url. A url needs to start with http://.
    """

    fastestTest = False # default: False
#    ranges=AUTO_STR # default is None retrieved from DBMS csv files.
    htmlOnly = False # default: False but enable it for faster runs without some actual data.
    doWhatif = True # disables whatif actual run
    doProcheck = True
    doWattos = True
    doTalos = True
#    doStoreCheck = True # DEFAULT: True Requires sqlAlchemy
    doStoreCheck = False # DEFAULT: True Requires sqlAlchemy
    tgzCing = True # default: True # Create a tgz for the cing project. In case of a CING project input it will be overwritten.
    modelCount = None # default setting is None
    if fastestTest:
        modelCount = 3
        htmlOnly = True
        doWhatif = False
        doProcheck = False
        doWattos = False
        doTalos = False
    fORCE_REDO = True
    fORCE_RETRIEVE_INPUT = False


    nTmessage(header)
    nTmessage(getStartMessage())

    expectedArgumentList = [ 'inputDir', 'outputDir', 'pdbConvention', 'restraintsConvention', 'archiveType', 'projectType' ]
    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

    entryCodeChar2and3 = entryId[1:3]

    inputDir = extraArgList[0]
    outputDir = os.path.join(extraArgList[1], DATA_STR, entryCodeChar2and3, entryId)
    pdbConvention = extraArgList[2] #@UnusedVariable
    restraintsConvention = extraArgList[3]
    archiveType = extraArgList[4]
    projectType = extraArgList[5]

    if archiveType == ARCHIVE_TYPE_FLAT:
        pass
        # default
    elif archiveType == ARCHIVE_TYPE_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryId)
    elif archiveType == ARCHIVE_TYPE_BY_CH23:
        inputDir = os.path.join(inputDir, entryCodeChar2and3)
    elif archiveType == ARCHIVE_TYPE_BY_CH23_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryCodeChar2and3, entryId)
    
    ranges = CasdScripts.getRangesForEntry(entryId)

    nTdebug("Using:")
    nTdebug("inputDir:             %s" % inputDir)
    nTdebug("outputDir:            %s" % outputDir)
    nTdebug("pdbConvention:        %s" % pdbConvention)
    nTdebug("restraintsConvention: %s" % restraintsConvention)
    nTdebug("archiveType:          %s" % archiveType)
    nTdebug("projectType:          %s" % projectType)
    nTdebug("modelCount:           %s" % modelCount)
    nTdebug("ranges:               %s" % ranges)
    # presume the directory still needs to be created.
    cingEntryDir = entryId + ".cing"

    if os.path.isdir(cingEntryDir):
        if fORCE_REDO:
            nTmessage("Enforcing a redo")
            rmtree(cingEntryDir)
        else:
            mainIndexFile = os.path.join(cingEntryDir, "index.html")
            isDone = os.path.isfile(mainIndexFile)
            if isDone:
                nTmessage("SKIPPING ENTRY ALREADY DONE")
                return
            nTmessage("REDOING BECAUSE VALIDATION CONSIDERED NOT DONE.")
            rmtree(cingEntryDir)
        # end if.
    # end if.

    os.chdir(outputDir)

    project = Project(entryId)
    if project.removeFromDisk():
        nTerror("Failed to remove existing project (if present)")
        return True
    # end if.

#    extension = '.tgz'
    formatFileName = '%s.tgz'
#    fileNameTgz = entryId + '.tgz'
    if projectType == PROJECT_TYPE_CING:
#        fileNameTgz = entryId + '.cing.tgz'
        formatFileName = '%s.cing.tgz'
    elif projectType == PROJECT_TYPE_PDB:
        formatFileName = 'pdb%s.ent.gz'
    fileNameTgz = formatFileName % entryId

#    nTdebug("fileNameTgz: %s" % fileNameTgz)
    # if true will do retrieveTgzFromUrl.
    if inputDir.startswith("http") or inputDir.startswith("file"):
        stillToRetrieve = False
        if os.path.exists(fileNameTgz):
            if fORCE_RETRIEVE_INPUT:
                os.unlink(fileNameTgz)
                stillToRetrieve = True
            # end if
        else:
            stillToRetrieve = True
        # end if
        if stillToRetrieve:
            retrieveTgzFromUrl(entryId, inputDir, archiveType=archiveType, formatFileName=formatFileName)
        # end if
        if not os.path.exists(fileNameTgz):
            nTerror("Tgz should already have been present skipping entry")
            return
        # end if
    # end if.
#            retrieveTgzFromUrl(entryId, inputDir)

    if projectType == PROJECT_TYPE_CING:
        # Needs to be copied because the open method doesn't take a directory argument..
        fullFileNameTgz = os.path.join(inputDir, fileNameTgz)
        shutil.copy(fullFileNameTgz, '.')
        project = Project.open(entryId, status='old')
        if not project:
            nTerror("Failed to init old project")
            return True
    elif projectType == PROJECT_TYPE_CCPN:
        project = Project.open(entryId, status='new')
        if not project.initCcpn(ccpnFolder=fileNameTgz, modelCount=modelCount):
                                #nmrCalcName='CING'):
                                #nmrCalcName='CASD-NMR'):
            nTerror("Failed to init project from ccpn")
            return True
        
        # Temporary debug
#        project.saveCcpn(os.path.join('/home/rf118/tmpdata/',entryId))
    elif projectType == PROJECT_TYPE_PDB:
        project = Project.open(entryId, status='new')
#        pdbFileFormats = [ entryId + ".pdb", "pdb" + entryId + ".ent.gz" ]
#        for pdbFileName in pdbFileFormats:
#        pdbFileName = "pdb" + entryId + ".ent.gz"
#        #    pdbFilePath = os.path.join( inputDir, pdbFileName)
#            pdbFilePath = os.path.join(inputDir, pdbFileName)
#            if os.path.exists(pdbFilePath):
#                break
#        tmpPdbFile = None
#        if pdbFileName.endswith('.gz'):
        pdbFilePath = entryId + ".pdb"
#        tmpPdbFile = pdbFilePath
#        if os.path.exists(pdbFilePath):
#            os.unlink(pdbFilePath)
        gunzip(fileNameTgz, outputFileName=pdbFilePath, removeOriginal=True)
        project.initPDB(pdbFile=pdbFilePath, convention=IUPAC, nmodels=modelCount)
#        if tmpPdbFile:
        if True:
            nTdebug("Removing tmp: %s" % pdbFilePath)
            os.unlink(pdbFilePath)



#    if inputDirOrg == inputDirCASD_NMR:
#    if True: # Default is False for this is specific to CASD-NMR
#        nTmessage("Renaming molecule name to entry id: %s" % entryId)
#        project.molecule.name = entryId # insufficient since all data is already initialized to disk.
#        project.updateProject()
#        project.molecule.rename( entryId )

#    project.save()
#    project.molecule.ranges = ranges # JFD: this doesn't seem to be set there exactly.
    
#    nTdebug("mainCasd: Molecule starts with ranges %s" % project.molecule.ranges)
    project.molecule.superpose(ranges=ranges)
    if True:
        if project.validate(htmlOnly=htmlOnly, ranges=ranges, doProcheck=doProcheck, doWhatif=doWhatif,
                doWattos=doWattos, doTalos=doTalos):
            nTerror("Failed to validate project read")
            return True

#    if True:
#        project.runRpf(
#           doAlised=DEFAULT_CONSIDER_ALIASED_POSITIONS,
#           distThreshold=DEFAULT_DISTANCE_THRESHOLD,
#           prochiralExclusion=DEFAULT_PROCHIRAL_EXCLUSION_SHIFT,
#           diagonalExclusion=DEFAULT_DIAGONAL_EXCLUSION_SHIFT
#    )

    if doStoreCheck:
        if doStoreCING2db( entryId, ARCHIVE_CASD_ID, project=project):
            nTerror("Failed to store CING project's data to DB but continuing.")

    project.save()
    if projectType == PROJECT_TYPE_CCPN:
#        fileNameTgz = entryId + '.tgz'
#        os.unlink(fileNameTgz) # temporary ccpn tgz
#        pass
        rmdir(entryId) # temporary ccpn dir

    if tgzCing:
        directoryNameCing = entryId + ".cing"
        tgzFileNameCing = directoryNameCing + ".tgz"
        if os.path.exists(tgzFileNameCing):
            nTwarning("Overwriting: " + tgzFileNameCing)
        cmd = "tar -czf %s %s" % (tgzFileNameCing, directoryNameCing)
        do_cmd(cmd)
Exemple #16
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()
def mainCasd(entryId, *extraArgList):
    """inputDir may be a directory or a url. A url needs to start with http://.
    """

    fastestTest = False  # default: False
    #    ranges=AUTO_STR # default is None retrieved from DBMS csv files.
    htmlOnly = False  # default: False but enable it for faster runs without some actual data.
    doWhatif = True  # disables whatif actual run
    doProcheck = True
    doWattos = True
    doTalos = True
    #    doStoreCheck = True # DEFAULT: True Requires sqlAlchemy
    doStoreCheck = False  # DEFAULT: True Requires sqlAlchemy
    tgzCing = True  # default: True # Create a tgz for the cing project. In case of a CING project input it will be overwritten.
    modelCount = None  # default setting is None
    if fastestTest:
        modelCount = 3
        htmlOnly = True
        doWhatif = False
        doProcheck = False
        doWattos = False
        doTalos = False
    fORCE_REDO = True
    fORCE_RETRIEVE_INPUT = False

    nTmessage(header)
    nTmessage(getStartMessage())

    expectedArgumentList = [
        'inputDir', 'outputDir', 'pdbConvention', 'restraintsConvention',
        'archiveType', 'projectType'
    ]
    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

    entryCodeChar2and3 = entryId[1:3]

    inputDir = extraArgList[0]
    outputDir = os.path.join(extraArgList[1], DATA_STR, entryCodeChar2and3,
                             entryId)
    pdbConvention = extraArgList[2]  #@UnusedVariable
    restraintsConvention = extraArgList[3]
    archiveType = extraArgList[4]
    projectType = extraArgList[5]

    if archiveType == ARCHIVE_TYPE_FLAT:
        pass
        # default
    elif archiveType == ARCHIVE_TYPE_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryId)
    elif archiveType == ARCHIVE_TYPE_BY_CH23:
        inputDir = os.path.join(inputDir, entryCodeChar2and3)
    elif archiveType == ARCHIVE_TYPE_BY_CH23_BY_ENTRY:
        inputDir = os.path.join(inputDir, entryCodeChar2and3, entryId)

    ranges = CasdScripts.getRangesForEntry(entryId)

    nTdebug("Using:")
    nTdebug("inputDir:             %s" % inputDir)
    nTdebug("outputDir:            %s" % outputDir)
    nTdebug("pdbConvention:        %s" % pdbConvention)
    nTdebug("restraintsConvention: %s" % restraintsConvention)
    nTdebug("archiveType:          %s" % archiveType)
    nTdebug("projectType:          %s" % projectType)
    nTdebug("modelCount:           %s" % modelCount)
    nTdebug("ranges:               %s" % ranges)
    # presume the directory still needs to be created.
    cingEntryDir = entryId + ".cing"

    if os.path.isdir(cingEntryDir):
        if fORCE_REDO:
            nTmessage("Enforcing a redo")
            rmtree(cingEntryDir)
        else:
            mainIndexFile = os.path.join(cingEntryDir, "index.html")
            isDone = os.path.isfile(mainIndexFile)
            if isDone:
                nTmessage("SKIPPING ENTRY ALREADY DONE")
                return
            nTmessage("REDOING BECAUSE VALIDATION CONSIDERED NOT DONE.")
            rmtree(cingEntryDir)
        # end if.
    # end if.

    os.chdir(outputDir)

    project = Project(entryId)
    if project.removeFromDisk():
        nTerror("Failed to remove existing project (if present)")
        return True
    # end if.

#    extension = '.tgz'
    formatFileName = '%s.tgz'
    #    fileNameTgz = entryId + '.tgz'
    if projectType == PROJECT_TYPE_CING:
        #        fileNameTgz = entryId + '.cing.tgz'
        formatFileName = '%s.cing.tgz'
    elif projectType == PROJECT_TYPE_PDB:
        formatFileName = 'pdb%s.ent.gz'
    fileNameTgz = formatFileName % entryId

    #    nTdebug("fileNameTgz: %s" % fileNameTgz)
    # if true will do retrieveTgzFromUrl.
    if inputDir.startswith("http") or inputDir.startswith("file"):
        stillToRetrieve = False
        if os.path.exists(fileNameTgz):
            if fORCE_RETRIEVE_INPUT:
                os.unlink(fileNameTgz)
                stillToRetrieve = True
            # end if
        else:
            stillToRetrieve = True
        # end if
        if stillToRetrieve:
            retrieveTgzFromUrl(entryId,
                               inputDir,
                               archiveType=archiveType,
                               formatFileName=formatFileName)
        # end if
        if not os.path.exists(fileNameTgz):
            nTerror("Tgz should already have been present skipping entry")
            return
        # end if
    # end if.
#            retrieveTgzFromUrl(entryId, inputDir)

    if projectType == PROJECT_TYPE_CING:
        # Needs to be copied because the open method doesn't take a directory argument..
        fullFileNameTgz = os.path.join(inputDir, fileNameTgz)
        shutil.copy(fullFileNameTgz, '.')
        project = Project.open(entryId, status='old')
        if not project:
            nTerror("Failed to init old project")
            return True
    elif projectType == PROJECT_TYPE_CCPN:
        project = Project.open(entryId, status='new')
        if not project.initCcpn(ccpnFolder=fileNameTgz, modelCount=modelCount):
            #nmrCalcName='CING'):
            #nmrCalcName='CASD-NMR'):
            nTerror("Failed to init project from ccpn")
            return True

        # Temporary debug
#        project.saveCcpn(os.path.join('/home/rf118/tmpdata/',entryId))
    elif projectType == PROJECT_TYPE_PDB:
        project = Project.open(entryId, status='new')
        #        pdbFileFormats = [ entryId + ".pdb", "pdb" + entryId + ".ent.gz" ]
        #        for pdbFileName in pdbFileFormats:
        #        pdbFileName = "pdb" + entryId + ".ent.gz"
        #        #    pdbFilePath = os.path.join( inputDir, pdbFileName)
        #            pdbFilePath = os.path.join(inputDir, pdbFileName)
        #            if os.path.exists(pdbFilePath):
        #                break
        #        tmpPdbFile = None
        #        if pdbFileName.endswith('.gz'):
        pdbFilePath = entryId + ".pdb"
        #        tmpPdbFile = pdbFilePath
        #        if os.path.exists(pdbFilePath):
        #            os.unlink(pdbFilePath)
        gunzip(fileNameTgz, outputFileName=pdbFilePath, removeOriginal=True)
        project.initPDB(pdbFile=pdbFilePath,
                        convention=IUPAC,
                        nmodels=modelCount)
        #        if tmpPdbFile:
        if True:
            nTdebug("Removing tmp: %s" % pdbFilePath)
            os.unlink(pdbFilePath)

#    if inputDirOrg == inputDirCASD_NMR:
#    if True: # Default is False for this is specific to CASD-NMR
#        nTmessage("Renaming molecule name to entry id: %s" % entryId)
#        project.molecule.name = entryId # insufficient since all data is already initialized to disk.
#        project.updateProject()
#        project.molecule.rename( entryId )

#    project.save()
#    project.molecule.ranges = ranges # JFD: this doesn't seem to be set there exactly.

#    nTdebug("mainCasd: Molecule starts with ranges %s" % project.molecule.ranges)
    project.molecule.superpose(ranges=ranges)
    if True:
        if project.validate(htmlOnly=htmlOnly,
                            ranges=ranges,
                            doProcheck=doProcheck,
                            doWhatif=doWhatif,
                            doWattos=doWattos,
                            doTalos=doTalos):
            nTerror("Failed to validate project read")
            return True


#    if True:
#        project.runRpf(
#           doAlised=DEFAULT_CONSIDER_ALIASED_POSITIONS,
#           distThreshold=DEFAULT_DISTANCE_THRESHOLD,
#           prochiralExclusion=DEFAULT_PROCHIRAL_EXCLUSION_SHIFT,
#           diagonalExclusion=DEFAULT_DIAGONAL_EXCLUSION_SHIFT
#    )

    if doStoreCheck:
        if doStoreCING2db(entryId, ARCHIVE_CASD_ID, project=project):
            nTerror(
                "Failed to store CING project's data to DB but continuing.")

    project.save()
    if projectType == PROJECT_TYPE_CCPN:
        #        fileNameTgz = entryId + '.tgz'
        #        os.unlink(fileNameTgz) # temporary ccpn tgz
        #        pass
        rmdir(entryId)  # temporary ccpn dir

    if tgzCing:
        directoryNameCing = entryId + ".cing"
        tgzFileNameCing = directoryNameCing + ".tgz"
        if os.path.exists(tgzFileNameCing):
            nTwarning("Overwriting: " + tgzFileNameCing)
        cmd = "tar -czf %s %s" % (tgzFileNameCing, directoryNameCing)
        do_cmd(cmd)
Exemple #18
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()
Exemple #19
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()
    def _test_CombineRestraints(self):
        '''
        This unit test is by default disabled because we haven't figured out yet how to disable the output from
        Yasara yet.
        
        Input is a CING project from the test data.
        '''

        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest), msg=
            "Failed to change to test directory for files: " + cingDirTmpTest)

        # Original project
#        entryId = 'H2_2Ca_64_100'
        _basicStats = """
 pdb e.res_count b.deposition_date c.name r.number r.name a1.name a2.name 
                                                    csd   chi1_avg chi2_avg chi1_cv chi2_cv           
 1brv        32 1996-03-29      A 180 LEU  CD1  CD2  0.0  270.3    170.5    0.000   0.000 no SSA delta
 1brv        32 1996-03-29      A 183 LEU  CD1  CD2  2.3  285.2    180.6    0.000   0.000 no SSA delta
 1brv        32 1996-03-29      A 185 LEU  CD1  CD2  0.4  313.5    172.1    0.054   0.045 no SSA delta/beta

 2loj        63 2012-01-24      A  20 LEU  CD1  CD2  1.3  302.2    178.2    0.002   0.001
 2loj        63 2012-01-24      A  33 LEU  CD1  CD2  -1.5 72.0     168.8    0.001   0.002
 2loj        63 2012-01-24      A  34 LEU  CD1  CD2  3.0  295.7    176.1    0.001   0.001
 2loj <=     63 2012-01-24      A  50 LEU  CD1  CD2  -2.2 184.2    283.6    0.002   0.001 chi2 > 240
 2loj        63 2012-01-24      A  51 LEU  CD1  CD2  -1.3 181.5    59.6     0.001   0.001
 2loj        63 2012-01-24      A  59 LEU  CD1  CD2  2.2  286.8    174.6    0.001   0.001
 2loj        63 2012-01-24      A  60 LEU  CD1  CD2  -0.3 203.4    66.6     0.049   0.002
 2loj <=     63 2012-01-24      A  61 LEU  CD1  CD2  -1.6 197.5    289.6    0.001   0.001 chi2 > 240 no SSA beta

 2fwu       159 2006-02-03      A 526 LEU  CD1  CD2  2.2  297.3    306.8    0.003   0.001 chi2 > 240
 2fwu       159 2006-02-03      A 560 LEU  CD1  CD2  1.8  293.8    173.6    0.002   0.001 
 2fwu       159 2006-02-03      A 589 LEU  CD1  CD2  -1.1 205.0    301.3    0.001   0.000 chi2 > 240
 2fwu       159 2006-02-03      A 596 LEU  CD1  CD2  -0.5 220.3    318.1    0.002   0.002 chi2 > 240 
 2fwu       159 2006-02-03      A 642 LEU  CD1  CD2  -4.1 178.5    70.9     0.001   0.000
"""
        entryId = '2fwu'
#        entryId = '1brv'
#        entryId = '2loj'
#        entryId = 'H2_2Ca_64_100'
        modelCount = 20            # DEFAULT: 20 Not valid for starting from CING project.
        doCcpn = True              # Test entry starting from CCPN project e.g. from NRG-CING.
        threshold = 0              # minimal violation, necessary to classify the restraints.
        deasHB = True              # first deassign all HBs in the specified leucines
        dihrCHI2 = True            # add a dihedral restraint on the leucines.
        useAll = False             # DEFAULT: False. use all leucines regardless of state        
        useLeuList = False         # If useAll is False and useLeuList is False then the leucines will be automatically detected
        doPrepCingProject = False   # DEFAULT: True  # NB If False this script will prefer a restore from the virgin .tgz
        doRunRotateLeucines = False # DEFAULT: True  # NB If False this script will prefer a restore from the virgin .tgz
        # No changes needed below. ################################################################################################
        if entryId == 'H2_2Ca_64_100' or entryId == '2fwu':
            useLeuList = (('A', 589), ('A', 596), ('A', 618))
#        elif entryId == '1brv':
#            useLeuList = (('A', 180),('A', 185),)
#        elif entryId == '2loj':            # Commented out will lead to automatic detection.
#            useLeuList = (('A', 50),('A', 61),)
        # end if
        
        nTmessage("Starting %s" % getCallerName())
        nTmessage("entryId             %s" % entryId            )
        nTmessage("modelCount          %s" % modelCount         )
        nTmessage("doCcpn              %s" % doCcpn             )
        nTmessage("threshold           %s" % threshold          )
        nTmessage("deasHB              %s" % deasHB             )
        nTmessage("dihrCHI2            %s" % dihrCHI2           )
        nTmessage("useAll              %s" % useAll             )
        nTmessage("useLeuList          %s" % str(useLeuList))
        nTmessage("doPrepCingProject   %s" % doPrepCingProject  )
        nTmessage("doRunRotateLeucines %s" % doRunRotateLeucines)
        # project with rotated leucines (created with RotateLeucines).
        entry2Id = entryId + '_' + ROTL_STR
        # NO CHANGES NEEDED BELOW THIS LINE.
        if doCcpn:
            nTmessage("Creating project from CCPN first.")
            if doPrepCingProject:
                project = Project.open(entryId, status='new')
                inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")
                ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
                project.initCcpn(ccpnFolder=ccpnFile, modelCount=modelCount)
                project.close()
                del project
                do_cmd('tar -czf %s.cing.tgz %s.cing' % (entryId, entryId))
            # end if
            inputCingArchiveDir = cingDirTmpTest # cwd.is input dir.
        else:
            inputCingArchiveDir = os.path.join(cingDirTestsData, "cing")
        # end if
        # Create a copy of the original cing project locally
        # Then duplicate the project to a cing project that has rotated leucines.
        # It will also close and GC the large objects for efficiency.
        if doRunRotateLeucines:
            status = runRotateLeucines(cingDirTmpTest, inputCingArchiveDir, entryId, useAll=useAll, useLeuList=useLeuList)
            self.assertFalse(status)
        # end if
        # Restore the 2 projects. The first project will be modified based on the info in the second project.
        proj1 = Project.open(entryId, status='old') # NB Will prefer a restore from the virgin .tgz 
        proj2 = Project.open(entry2Id, status='old')
        self.assertTrue(proj1 and proj2)            
        project = proj1
        #### BLOCK BEGIN repeated in rotateLeucines
        if not useAll and useLeuList:
            leuList = project.decodeResidueList(useLeuList)
            if not leuList:
                nTerror('Failed to decodeResidueList')
                return True
            # end if            
        else:
            leuList = selectBadLeucineList(project, CV_THRESHOLD_SELECTION, useAll=useAll)
        # end if
        if leuList == None:
            nTerror('Failed to selectBadLeucineList')
            return True
        # end if
        #### BLOCK BEGIN                
        status = alterRestraintsForLeus(leuList, proj1, proj2, threshold, deasHB, dihrCHI2)
        self.assertTrue(status)
        proj1.save()
Exemple #21
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()
Exemple #22
0
            nTmessage("Removing existing file.")
        else:
            nTerror("Failed because found remote file: %s" % remoteFile)
            sys.exit(1)

    tarring = ExecuteProgram('tar', rootPath=localDir, redirectOutputToFile = remoteFile)
    tar_cmd = '-cpBf - %s.vmwarevm | gzip --fast' % vmName
    nTmessage("Running tar with options: %s" % tar_cmd)
    if tarring( tar_cmd ):
        nTerror("Failed to run tar with options: " + tar_cmd)
        sys.exit(1)

if doLink:
    local_cmd = "'cd %s/%s; ln -f %s %s'" % ( dDir, VCsecret, fileName, dstFile )
    if workLocally:
        if do_cmd(local_cmd):
            nTerror("Failed to link locally: " + local_cmd)
            sys.exit(1)
    else:
        sshing = ExecuteProgram('ssh', redirectOutput = False)
        ssh_cmd = ' [email protected] %s' % local_cmd
        nTmessage("Running ssh with options: %s" % ssh_cmd)
        if sshing( ssh_cmd ):
            nTerror("Failed to run ssh with options: " + ssh_cmd)
            sys.exit(1)
else:
    nTmessage("No linking done yet, do manually.")