Exemple #1
0
    def _testNmrStar(self):
        "Testing conversion from CCPN to NMR-STAR using Wim Vranken's FC. Disabled test because only JFD uses it."
        # failing entries: 1ai0, 1kr8 (same for 2hgh)
        entryList = "1a4d".split()
#        entryList = "1a4d 1a24 1afp 1ai0 1brv 1bus 1cjg 1hue 1ieh 1iv6 1kr8 2hgh 2k0e SRYBDNA Parvulustat".split()
#1iv6 needs better ccpn file from FC
#        if you have a local copy you can use it; make sure to adjust the path setting below.
        useNrgArchive = False # Default is 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 entryId in entryList:
            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)
            else:
                inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")

            ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
            self.assertTrue(project.initCcpn(ccpnFolder = ccpnFile))
            self.assertTrue(project.save())
            fileName = os.path.join( cingDirTmp, entryId + ".str")
            nmrStar = NmrStar(project)
            self.assertTrue( nmrStar )
            self.assertTrue( nmrStar.toNmrStarFile( fileName ))
            # 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))
Exemple #2
0
    def _testNmrStar(self):
        "Testing conversion from CCPN to NMR-STAR using Wim Vranken's FC. Disabled test because only JFD uses it."
        # failing entries: 1ai0, 1kr8 (same for 2hgh)
        entryList = "1a4d".split()
        #        entryList = "1a4d 1a24 1afp 1ai0 1brv 1bus 1cjg 1hue 1ieh 1iv6 1kr8 2hgh 2k0e SRYBDNA Parvulustat".split()
        #1iv6 needs better ccpn file from FC
        #        if you have a local copy you can use it; make sure to adjust the path setting below.
        useNrgArchive = False  # Default is 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 entryId in entryList:
            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)
            else:
                inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")

            ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
            self.assertTrue(project.initCcpn(ccpnFolder=ccpnFile))
            self.assertTrue(project.save())
            fileName = os.path.join(cingDirTmp, entryId + ".str")
            nmrStar = NmrStar(project)
            self.assertTrue(nmrStar)
            self.assertTrue(nmrStar.toNmrStarFile(fileName))
            # 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))
Exemple #3
0
def _runWattos(project, ranges=None, tmp=None, parseOnly=False):
    """
        Run and import the wattos results per model.
        All models in the ensemble of the molecule will be checked.
        Set wattos references for Molecule, Chain, Residue and Atom instances
        or None if no wattos results exist
        returns 1 on success or None on any failure.
    """

    if not project.molecule:
        nTerror("runWattos: no molecule defined")
        return True

    mol = project.molecule
    if not mol:
        nTerror("No project molecule in runWattos")
        return None
    if mol.modelCount == 0:
        nTwarning('runWattos: no models for "%s"', mol)
        return

    path = project.path(mol.name, project.moleculeDirectories.wattos)
    if not os.path.exists(path):
        mol.wattos = None
        for chain in mol.allChains():
            chain.wattos = None
        for res in mol.allResidues():
            res.wattos = None
        for atm in mol.allAtoms():
            atm.wattos = None
        return None

    if ranges == None:
        ranges = mol.ranges
    wattos = Wattos(rootPath=path, molecule=mol, ranges=ranges)
    del ranges  # only use wattos.ranges now.
    useRanges = mol.useRanges(wattos.ranges)
    if mol == None:
        nTerror('runWattos: no mol defined')
        return None

    if mol.modelCount == 0:
        nTwarning('runWattos: no models for "%s"', mol)
        return None

    wattosDir = project.mkdir(mol.name, project.moleculeDirectories.wattos)

    wattosStatus = project.wattosStatus

    if not parseOnly:
        wattosStatus.completed = False
        wattosStatus.parsed = False
        wattosStatus.time = None
        wattosStatus.exitCode = None

        fileName = 'project.str'
        fullname = os.path.join(os.path.curdir, wattosDir, fileName)
        fullname = os.path.abspath(fullname)

        if os.path.exists(fullname):
            if not os.unlink(fullname):
                nTmessage("Removing existing file: %s" % fullname)
            else:
                nTerror("Failed to remove existing file: %s" % fullname)
                return None

        nmrStar = NmrStar(project)
        if not nmrStar:
            nTerror("Failed to create NmrStar(project)")
            return None

        if not nmrStar.toNmrStarFile(fullname):
            nTmessage(
                "Failed to nmrStar.toNmrStarFile (fine if there wasn't a CCPN project to start with)"
            )
            return None

        if not os.path.exists(fullname):
            nTerror("Failed to create file [%s] in nmrStar.toNmrStarFile" %
                    fullname)
            return None

        scriptComplete = wattos.scriptTemplate
        scriptComplete = scriptComplete.replace("INPUT_STR_FILE", fileName)
        scriptComplete = scriptComplete.replace("VERBOSITY",
                                                repr(cing.verbosity))
        rangesTxt = wattos.ranges
        if not useRanges:  # Wattos can't handle a None this way.
            rangesTxt = ALL_RANGES_STR
        rangesTxtWattos = project.molecule.rangesToMmCifRanges(rangesTxt)
        if rangesTxtWattos == None:
            rangesTxtWattos = ALL_RANGES_STR
        if rangesTxt != rangesTxtWattos:
            nTmessage(
                "==> Translating ranges %s to mmCIF numbering scheme: %s" %
                (rangesTxt, rangesTxtWattos))
        scriptComplete = scriptComplete.replace("RANGES", rangesTxtWattos)
        # Let's ask the user to be nice and not kill us
        # estimate to do **0.5 residues per minutes as with entry 1bus on dual core intel Mac.
        timeRunEstimatedInSeconds = 0.025 * mol.modelCount * len(
            mol.allResidues())
        timeRunEstimatedList = timedelta2Hms(timeRunEstimatedInSeconds)
        msg = '==> Running Wattos for an estimated (5,000 atoms/s): %s hours, %s minutes and %s seconds; please wait' % timeRunEstimatedList
        nTmessage(msg)
        scriptFileName = "wattos.script"
        scriptFullFileName = os.path.join(wattosDir, scriptFileName)
        open(scriptFullFileName, "w").write(scriptComplete)
        wattosPath = "%s Wattos.CloneWars.UserInterface -at" % JVM_CMD_STD
        logFileName = "wattos_compl.log"
        wattosProgram = ExecuteProgram(wattosPath,
                                       rootPath=wattosDir,
                                       redirectOutputToFile=logFileName,
                                       redirectInputFromFile=scriptFileName)
        # The last argument becomes a necessary redirection into fouling Wattos into
        # thinking it's running interactively.
        now = time.time()
        wattosExitCode = wattosProgram()

        #        nTdebug("Took number of seconds: " + sprintf("%8.1f", time.time() - now))

        wattosStatus.exitCode = wattosExitCode
        wattosStatus.time = sprintf("%.1f", time.time() - now)
        wattosStatus.keysformat()

        if wattosExitCode:
            nTerror("Failed wattos checks with exit code: " +
                    repr(wattosExitCode))
            return None
        wattosStatus.completed = True
    # end if not parseOnly

    if not project.hasDistanceRestraints():
        return wattos

    fullname = os.path.join(wattosDir, wattos.completeness_check_file_name)
    if not os.path.exists(fullname):
        nTwarning("Failed to find wattos completeness check result file: %s" %
                  fullname)
        return None
#    nTmessage('==> Parsing checks')

    if wattos._processComplCheck(fullname):
        nTerror("\nrunWattos Failed to parse check %s", fullname)
        return None

    pathOutSurplus = os.path.join(
        path, wattos.surplus_check_file_name_base + '_summary.txt')
    if not os.path.exists(
            pathOutSurplus
    ):  # Happened for 1ao2 on production machine; not on development...
        nTerror("Path does not exist: %s" % (pathOutSurplus))
        return True
#    nTdebug('> parsing ' + pathOutSurplus)
    fullTextSurplus = open(pathOutSurplus, 'r').read()
    if not fullTextSurplus:
        nTerror('Failed to parse Wattos surplus summary file')
        return True

    startString = 'SUMMARY:'
    surplusSummary = getTextBetween(fullTextSurplus,
                                    startString,
                                    endString=None,
                                    startIncl=False,
                                    endIncl=False)
    if not surplusSummary:
        nTerror("Failed to find surplusSummary in surplusSummary[:80]: [%s]" %
                surplusSummary[:80])
        return True
    surplusSummary = "Wattos Surplus Analysis Summary\n\n" + surplusSummary.strip(
    )

    #    nTdebug('got surplusSummary: \n' + surplusSummary)

    #    pathOutCompleteness = os.path.join(path, 'wattos_completeness_chk.str')
    #    if not os.path.exists(pathOutCompleteness): # Happened for 1ao2 on production machine; not on development...
    #        nTerror("Path does not exist: %s" % (pathOutCompleteness))
    #        return True
    #    nTdebug('> parsing ' + pathOutCompleteness)
    #    fullTextCompleteness = open(pathOutCompleteness, 'r').read()
    #    if not fullTextCompleteness:
    #        nTerror('Failed to parse Wattos completeness summary file')
    #        return True
    #
    #    startString = '_NOE_completeness_shell.Type'
    #    endString = 'stop_'
    #    completenessSummary = getTextBetween(fullTextCompleteness, startString, endString, endIncl = False)
    #    if not completenessSummary:
    #        nTerror("Failed to find completenessSummary in fullText[:80]: [%s]" % fullTextCompleteness[:80])
    #        return True
    #    completenessSummary = '\n'.join([HTML_TAG_PRE,
    #                                completenessSummary.strip(),
    #                                '---------------------------------------------',
    #                                HTML_TAG_PRE2])
    #
    #    nTdebug('got completenessSummary: \n' + completenessSummary)

    #    intro = '----------- Wattos summary -----------'
    completenessMolStr = NaNstring
    completenessMol = mol.getDeepByKeys(WATTOS_STR, COMPLCHK_STR,
                                        VALUE_LIST_STR)
    if completenessMol:
        completenessMolStr = val2Str(completenessMol, "%.2f")
    complStatement = 'Overall NOE completeness is %s percent\n' % completenessMolStr

    summary = '\n\n'.join([surplusSummary, complStatement])
    if setDeepByKeys(mol, summary, WATTOS_SUMMARY_STR):
        nTerror('Failed to set Wattos summary')
        return True

    wattosStatus.parsed = True
    #    nTdebug("In runWattos: project.wattosStatus.completed: %s" % project.wattosStatus.completed)

    return wattos  # Success
Exemple #4
0
def _runWattos(project, ranges=None, tmp = None, parseOnly=False):
    """
        Run and import the wattos results per model.
        All models in the ensemble of the molecule will be checked.
        Set wattos references for Molecule, Chain, Residue and Atom instances
        or None if no wattos results exist
        returns 1 on success or None on any failure.
    """

    if not project.molecule:
        nTerror("runWattos: no molecule defined")
        return True

    mol = project.molecule
    if not mol:
        nTerror("No project molecule in runWattos")
        return None
    if mol.modelCount == 0:
        nTwarning('runWattos: no models for "%s"', mol)
        return



    path = project.path(mol.name, project.moleculeDirectories.wattos)
    if not os.path.exists(path):
        mol.wattos = None
        for chain in mol.allChains():
            chain.wattos = None
        for res in mol.allResidues():
            res.wattos = None
        for atm in mol.allAtoms():
            atm.wattos = None
        return None

    if ranges == None:
        ranges = mol.ranges
    wattos = Wattos(rootPath = path, molecule = mol, ranges = ranges)
    del ranges # only use wattos.ranges now.
    useRanges = mol.useRanges(wattos.ranges)
    if mol == None:
        nTerror('runWattos: no mol defined')
        return None

    if mol.modelCount == 0:
        nTwarning('runWattos: no models for "%s"', mol)
        return None

    wattosDir = project.mkdir(mol.name, project.moleculeDirectories.wattos)

    wattosStatus = project.wattosStatus

    if not parseOnly:
        wattosStatus.completed           = False
        wattosStatus.parsed              = False
        wattosStatus.time                = None
        wattosStatus.exitCode            = None

        fileName = 'project.str'
        fullname = os.path.join(os.path.curdir, wattosDir, fileName)
        fullname = os.path.abspath(fullname)

        if os.path.exists(fullname):
            if not os.unlink(fullname):
                nTmessage("Removing existing file: %s" % fullname)
            else:
                nTerror("Failed to remove existing file: %s" % fullname)
                return None

        nmrStar = NmrStar(project)
        if not nmrStar:
            nTerror("Failed to create NmrStar(project)")
            return None

        if not nmrStar.toNmrStarFile(fullname):
            nTmessage("Failed to nmrStar.toNmrStarFile (fine if there wasn't a CCPN project to start with)")
            return None

        if not os.path.exists(fullname):
            nTerror("Failed to create file [%s] in nmrStar.toNmrStarFile" % fullname)
            return None

        scriptComplete = wattos.scriptTemplate
        scriptComplete = scriptComplete.replace("INPUT_STR_FILE", fileName)
        scriptComplete = scriptComplete.replace("VERBOSITY", repr(cing.verbosity))
        rangesTxt = wattos.ranges
        if not useRanges: # Wattos can't handle a None this way.
            rangesTxt = ALL_RANGES_STR
        rangesTxtWattos = project.molecule.rangesToMmCifRanges(rangesTxt)
        if rangesTxtWattos == None:
            rangesTxtWattos = ALL_RANGES_STR
        if rangesTxt != rangesTxtWattos:
            nTmessage("==> Translating ranges %s to mmCIF numbering scheme: %s" % (rangesTxt, rangesTxtWattos ))
        scriptComplete = scriptComplete.replace("RANGES", rangesTxtWattos)
        # Let's ask the user to be nice and not kill us
        # estimate to do **0.5 residues per minutes as with entry 1bus on dual core intel Mac.
        timeRunEstimatedInSeconds = 0.025 * mol.modelCount * len(mol.allResidues())
        timeRunEstimatedInSeconds *= 60
        timeRunEstimatedList = timedelta2Hms(timeRunEstimatedInSeconds)
        msg = '==> Running Wattos for an estimated (5,000 atoms/s): %s hours, %s minutes and %s seconds; please wait' % timeRunEstimatedList
        nTmessage(msg)
        scriptFileName = "wattos.script"
        scriptFullFileName = os.path.join(wattosDir, scriptFileName)
        open(scriptFullFileName, "w").write(scriptComplete)
        wattosPath = "%s Wattos.CloneWars.UserInterface -at" % JVM_CMD_STD
        logFileName = "wattos_compl.log"
        wattosProgram = ExecuteProgram(wattosPath, rootPath = wattosDir,
                                 redirectOutputToFile = logFileName,
                                 redirectInputFromFile = scriptFileName)
        # The last argument becomes a necessary redirection into fouling Wattos into
        # thinking it's running interactively.
        now = time.time()
        wattosExitCode = wattosProgram()

#        nTdebug("Took number of seconds: " + sprintf("%8.1f", time.time() - now))

        wattosStatus.exitCode  = wattosExitCode
        wattosStatus.time      = sprintf("%.1f", time.time() - now)
        wattosStatus.keysformat()

        if wattosExitCode:
            nTerror("Failed wattos checks with exit code: " + repr(wattosExitCode))
            return None
        wattosStatus.completed = True
    # end if not parseOnly

    if not project.hasDistanceRestraints():
        return wattos

    fullname = os.path.join(wattosDir, wattos.completeness_check_file_name)
    if not os.path.exists(fullname):
        nTwarning("Failed to find wattos completeness check result file: %s" % fullname)
        return None
#    nTmessage('==> Parsing checks')

    if wattos._processComplCheck(fullname):
        nTerror("\nrunWattos Failed to parse check %s", fullname)
        return None


    pathOutSurplus = os.path.join(path, wattos.surplus_check_file_name_base + '_summary.txt')
    if not os.path.exists(pathOutSurplus): # Happened for 1ao2 on production machine; not on development...
        nTerror("Path does not exist: %s" % (pathOutSurplus))
        return True
#    nTdebug('> parsing ' + pathOutSurplus)
    fullTextSurplus = open(pathOutSurplus, 'r').read()
    if not fullTextSurplus:
        nTerror('Failed to parse Wattos surplus summary file')
        return True


    startString = 'SUMMARY:'
    surplusSummary = getTextBetween(fullTextSurplus, startString, endString = None, startIncl = False, endIncl = False)
    if not surplusSummary:
        nTerror("Failed to find surplusSummary in surplusSummary[:80]: [%s]" % surplusSummary[:80])
        return True
    surplusSummary = "Wattos Surplus Analysis Summary\n\n" + surplusSummary.strip()

#    nTdebug('got surplusSummary: \n' + surplusSummary)

#    pathOutCompleteness = os.path.join(path, 'wattos_completeness_chk.str')
#    if not os.path.exists(pathOutCompleteness): # Happened for 1ao2 on production machine; not on development...
#        nTerror("Path does not exist: %s" % (pathOutCompleteness))
#        return True
#    nTdebug('> parsing ' + pathOutCompleteness)
#    fullTextCompleteness = open(pathOutCompleteness, 'r').read()
#    if not fullTextCompleteness:
#        nTerror('Failed to parse Wattos completeness summary file')
#        return True
#
#    startString = '_NOE_completeness_shell.Type'
#    endString = 'stop_'
#    completenessSummary = getTextBetween(fullTextCompleteness, startString, endString, endIncl = False)
#    if not completenessSummary:
#        nTerror("Failed to find completenessSummary in fullText[:80]: [%s]" % fullTextCompleteness[:80])
#        return True
#    completenessSummary = '\n'.join([HTML_TAG_PRE,
#                                completenessSummary.strip(),
#                                '---------------------------------------------',
#                                HTML_TAG_PRE2])
#
#    nTdebug('got completenessSummary: \n' + completenessSummary)

#    intro = '----------- Wattos summary -----------'
    completenessMolStr = NaNstring
    completenessMol = mol.getDeepByKeys( WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
    if completenessMol:
        completenessMolStr = val2Str(completenessMol, "%.2f")
    complStatement = 'Overall NOE completeness is %s percent\n' % completenessMolStr

    summary = '\n\n'.join([surplusSummary, complStatement])
    if setDeepByKeys(mol, summary, WATTOS_SUMMARY_STR):
        nTerror('Failed to set Wattos summary')
        return True

    wattosStatus.parsed = True
#    nTdebug("In runWattos: project.wattosStatus.completed: %s" % project.wattosStatus.completed)

    return wattos # Success