Beispiel #1
0
def calculatePairWisePhiPsiRmsd( mol1, mol2, ranges='auto' ):
    """
    Calculate a pairwise angular Phi,Psi rmsd between the models of mol1 and mol2
    return result NTlistOfLists, pairwise1, pairwise2, pairwise12 tuple
    """

    fitResidues1 = mol1.setResiduesFromRanges(ranges)
    models1 = PhiPsiLists( mol1, fitResidues1 )

    fitResidues2 = mol2.setResiduesFromRanges(ranges)
    models2 = PhiPsiLists( mol2, fitResidues2 )

    #print '>', ranges, models1, models2

    l1 = len(models1)
    l2 = len(models2)
    if l1 == 0 or len(models1[0]) == 0 or l2 == 0 or len(models2[0]) == 0:
        nTdebug(">calculatePairWisePhiPsiRmsd> returning None, %s %s %s", l1, l2, ranges)
        return None, None, None, None

    models = models1 + models2

    result = NTlistOfLists(len(models), len(models), 0.0)

    #nTmessage( '==> Calculating dihedral pairwise rmsds' )

    for i in range(len(models)):
        for j in range(i+1, len(models)):
            #print '>>', i,j
            r = models[i].calculateRMSD( models[j] )
            if r == None:
                nTdebug('calculatePairWisePhiPsiRmsd: error for %s and %s', models[i], models[j])
                return None, None, None, None
            else:
                result[i][j] = r
                result[j][i] = r
        #end for
    #end for

    pairwise1 = NTlist()
    for i in range(l1):
        for j in range(i+1, l1):
            pairwise1.append(result[i][j])
#            print '1>', i,j

    pairwise2 = NTlist()
    for i in range(l1, l1+l2):
        for j in range(i+1, l1+l2):
            pairwise2.append(result[i][j])
#            print '2>', i,j

    pairwise12 = NTlist()
    for i in range(l1):
        for j in range(l1, l1+l2):
            pairwise12.append(result[i][j])

#            print '12>', i,j
#    print len(pairwise1), len(pairwise2), len(pairwise12)
    return ( result, pairwise1.average2(fmt='%6.2f +- %5.2f'),pairwise2.average2(fmt='%6.2f +- %5.2f'),
        pairwise12.average2(fmt='%6.2f +- %5.2f') )
Beispiel #2
0
def restoreQueeny100( project, tmp=None ):
    """
    Restore queeny results from sml file.

    Return True on error
    """
    if project is None:
        nTmessage("restoreQueeny100: No project defined")
        return True

    if project.molecule is None:
        return False # Gracefully returns

    queenyDefs = project.getStatusDict(constants.QUEENY_KEY)

    if not queenyDefs.completed: # old definition
        nTdebug('restoreQueeny100: no queeny completed')
        return False # Return gracefully

    path = project.validationPath( 'Queeny')
    if not path.exists():
        ntu.nTwarning('restoreQueeny100: directory "%s" with prior queeny data not found', path)
    else:
        # delete the data and run again
        os.rename(path, project.path() / cdefs.directories.version1 / 'Queeny')
    #end if
    # regenerate the data
    project.runQueeny()
    nTmessage('restoreQueeny100: Re-generated Queeny results')
    return False
Beispiel #3
0
def smoothTriangle(data,degree=1,dropVals=False):
    cvWindowSize = 3
    n = len(data)
    nTdebug("data: %s" % str(data))
    w=ones(cvWindowSize,'d')
    windowAveraged=convolve(w/w.sum(),data,mode='same')
    windowAveraged[0] = data[0]
    windowAveraged[n-1] = data[n-1]
    return windowAveraged
Beispiel #4
0
def smoothTriangle(data, degree=1, dropVals=False):
    cvWindowSize = 3
    n = len(data)
    nTdebug("data: %s" % str(data))
    w = ones(cvWindowSize, 'd')
    windowAveraged = convolve(w / w.sum(), data, mode='same')
    windowAveraged[0] = data[0]
    windowAveraged[n - 1] = data[n - 1]
    return windowAveraged
Beispiel #5
0
def calculatePairWiseRmsd( mol1, mol2, ranges=None ):
    """Calculate pairwise rmsd between mol1 and mol2
       Optionally use ranges for the fitting
    """

    #Use ranges routines to define fitAtoms ed
    fitResidues1 = mol1.setResiduesFromRanges(ranges)
    mol1.selectFitAtoms( fitResidues1, backboneOnly=True, includeProtons = False )
    fitResidues2 = mol2.setResiduesFromRanges(ranges)
    mol2.selectFitAtoms( fitResidues2, backboneOnly=True, includeProtons = False )
#    mol2.superpose( ranges )

    l1 = len(mol1.ensemble)
    l2 = len(mol2.ensemble)

    if (   l1 == 0 or len(mol1.ensemble[0].fitCoordinates) == 0
        or l2 == 0 or len(mol2.ensemble[0].fitCoordinates) == 0
        or len(mol1.ensemble[0].fitCoordinates) != len(mol2.ensemble[0].fitCoordinates)
    ):
        nTdebug( ">calculatePairWiseRmsd> returning None, %s %s %s" , l1, l2, ranges)
        return None, None, None, None


    models = mol1.ensemble + mol2.ensemble

    result = NTlistOfLists(len(models), len(models), 0.0)

    nTmessage('==> Calculating pairwise rmsds %s %s', mol1, mol2)

    for i in range(len(models)):
        for j in range(i+1, len(models)):
            result[i][j] = models[i].superpose( models[j] )
            result[j][i] = result[i][j]
        #end for
    #end for

    pairwise1 = NTlist()
    for i in range(l1):
        for j in range(i+1, l1):
            pairwise1.append(result[i][j])
#            print '1>', i,j

    pairwise2 = NTlist()
    for i in range(l1, l1+l2):
        for j in range(i+1, l1+l2):
            pairwise2.append(result[i][j])
#            print '2>', i,j

    pairwise12 = NTlist()
    for i in range(l1):
        for j in range(l1, l1+l2):
            pairwise12.append(result[i][j])

#            print '12>', i,j
#    print len(pairwise1), len(pairwise2), len(pairwise12)
    return ( result, pairwise1.average2(fmt='%6.2f +- %5.2f'),pairwise2.average2(fmt='%6.2f +- %5.2f'),
        pairwise12.average2(fmt='%6.2f +- %5.2f'))
Beispiel #6
0
def remove_pseudo_atoms(res_def, convention='STAP'):
    """Remove pseudo atoms from this convention in the residue definition.

    Return the corrected res_def.
    """
    nTdebug('Removing STAP pseudo atoms from %s', res_def)
    for pseudo_name in res_def.atomsWithProperties('pseudoatom'):
        nTdebug('Removing %s', pseudo_name)
        res_def[pseudo_name].nameDict['STAP'] = None
    return res_def
Beispiel #7
0
def correct_termini_stap(res_def):
    """Change nomenclature conventions for termini to STAP convention.

    For the N-terminal protons HT1/2/3 'H1', 'H2' and 'H3' are added.
    The C-terminal protons are: 'O,OT1' and 'OXT,OT2'.
    """
    nTdebug("Correcting terminal protons to STAP convention for %s", res_def)
    for name, repl in [("H1", "H1,HT1"), ("H2", "H2,HT2"), ("H3", "H3,HT3"), ("O", "O,OT1"), ("OXT", "OXT,OT2")]:
        if name in res_def:
            res_def[name].nameDict["STAP"] = repl
Beispiel #8
0
def remove_pseudo_atoms(res_def, convention='STAP'):
    """Remove pseudo atoms from this convention in the residue definition.

    Return the corrected res_def.
    """
    nTdebug('Removing STAP pseudo atoms from %s', res_def)
    for pseudo_name in res_def.atomsWithProperties('pseudoatom'):
        nTdebug('Removing %s', pseudo_name)
        res_def[pseudo_name].nameDict['STAP'] = None
    return res_def
Beispiel #9
0
def restoreShiftx100(project):
    """
    Restore shiftx results by parsing files.

    Return True on error
    """
    if project is None:
        nTdebug("restoreShiftx100: No project defined")
        return True

    if project.molecule == None:
        return True # Gracefully returns

    defs = project.getStatusDict(constants.SHIFTX_KEY)

    # Older versions; initialize the required keys of shiftx Status from xml file
    if project.version < 0.881:

        path = project.validationPath(cdefs.validationsDirectories.shiftx)
        if not path:
            nTerror('restoreShiftx100: directory "%s" with shiftx data not found', path)
            return True
        xmlFile = project.path() / 'content.xml'

        if not xmlFile.exists():
            nTerror('restoreShiftx100: Shiftx results xmlFile "%s" not found', xmlFile)
            return True
        #end if

        shiftxResult = xmlTools.xML2obj(xmlFile)
        if not shiftxResult:
            nTerror('restoreShiftx100: restoring Shiftx results from xmlFile "%s" failed', xmlFile)
            return None

        defs.update(shiftxResult)
        defs.completed = True
    #end if

    #update some of the settings
    if 'moleculeName' in defs:
        del defs['moleculeName']

    if 'path' in defs:
        defs.directory = disk.Path(defs.path)[-1:]
        del defs['path']
    else:
        defs.directory = constants.SHIFTX_KEY
    if 'contenFile' in defs:
        del defs['contentFile']

    if not defs.completed:
        nTdebug('restoreShiftx100: shiftx not completed')
        return True

    return project.parseShiftx()
Beispiel #10
0
def remove_non_stap_residues(res_def):
    """Set name to None for non-stap residue definitions.

    ARGx HH1 is not set to None.
    ASPH HD2 is None.
    GLUH HE2 is not set to None.
    """
    non_stap = ['ARGx', 'ASPH', 'GLUH', 'LYSx']
    for res in non_stap:
        nTdebug('Removing %s from STAP residue definitions', res)
        res_def[res].nameDict['STAP'] = None
Beispiel #11
0
def correct_termini_stap(res_def):
    """Change nomenclature conventions for termini to STAP convention.

    For the N-terminal protons HT1/2/3 'H1', 'H2' and 'H3' are added.
    The C-terminal protons are: 'O,OT1' and 'OXT,OT2'.
    """
    nTdebug('Correcting terminal protons to STAP convention for %s', res_def)
    for name, repl in [('H1', 'H1,HT1'), ('H2', 'H2,HT2'), ('H3', 'H3,HT3'),
                       ('O', 'O,OT1'), ('OXT', 'OXT,OT2')]:
        if name in res_def:
            res_def[name].nameDict['STAP'] = repl
Beispiel #12
0
def correct_termini_stap(res_def):
    """Change nomenclature conventions for termini to STAP convention.

    For the N-terminal protons HT1/2/3 'H1', 'H2' and 'H3' are added.
    The C-terminal protons are: 'O,OT1' and 'OXT,OT2'.
    """
    nTdebug('Correcting terminal protons to STAP convention for %s', res_def)
    for name, repl in [('H1', 'H1,HT1'), ('H2', 'H2,HT2'), ('H3', 'H3,HT3'),
                       ('O', 'O,OT1'), ('OXT', 'OXT,OT2')]:
        if name in res_def:
            res_def[name].nameDict['STAP'] = repl
Beispiel #13
0
def remove_non_stap_residues(res_def):
    """Set name to None for non-stap residue definitions.

    ARGx HH1 is not set to None.
    ASPH HD2 is None.
    GLUH HE2 is not set to None.
    """
    non_stap = ['ARGx', 'ASPH', 'GLUH', 'LYSx']
    for res in non_stap:
        nTdebug('Removing %s from STAP residue definitions', res)
        res_def[res].nameDict['STAP'] = None
Beispiel #14
0
def remove_non_stap_residues(res_def):
    """Set name to None for non-stap residue definitions.

    ARGx HH1 is not set to None.
    ASPH HD2 is None.
    GLUH HE2 is not set to None.
    """
    non_stap = ["ARGx", "ASPH", "GLUH", "LYSx"]
    for res in non_stap:
        nTdebug("Removing %s from STAP residue definitions", res)
        res_def[res].nameDict["STAP"] = None
Beispiel #15
0
def upgrade100(project, restore):
    """
    Do all things to upgrade project to current configuration
    All versions <= 1.00
    """
    nTmessage('*** upgrade100: upgrading %s from version %s ***', project, project.version)
    verbosity = cing.verbosity
    # make sure we get all if we heave debug on
    if cing.verbosity < cing.verbosityDebug:
        cing.verbosity = cing.verbosityWarning

    # Molecules
    for molName in project.moleculeNames:
        pathName = project.molecules.path(molName)
        mol = Molecule.open(pathName)
        if mol:
            mol.status = 'keep'
            project.appendMolecule(mol)
        #end if
        nTdebug('upgrade100: restored %s', mol)
    #end for

    # restore the lists
    for pl in [project.peaks, project.distances, project.dihedrals, project.rdcs, project.coplanars]:
        pl.restore()
    #end for

    # Now patch talos+
    nTmessage('==> upgrade100: talosPlus')
    if restoreTalosPlus100(project):
        io.error('upgrade100: restoring talosPlus data failed\n')

    # Now patch queeny
    # nTmessage('==> upgrade100: queeny')
    # if restoreQueeny100(project):
    #     nTerror('upgrade100: restoring queeny data failed')
    # project.saveQueeny()
    #
    # # Now patch shiftx
    # if restoreShiftx100(project):
    #     nTerror('upgrade100: restoring shiftx data failed')
    #     return None
    # project.saveShiftx()

    # Plugin registered functions
    nTdebug('upgrade100: calling plugins')
    project._callPluginRestores()

    # save to consolidate
    project.save()

    cing.verbosity = verbosity
    return Project.open(project.name, constants.PROJECT_OLD, restore=restore)
Beispiel #16
0
    def setUncertainty(self, key):
        """set the uncertainty for:
        - each atom[key] of molecule
        - each residue[key] of molecule
        """
#        nTdebug('Queeny.setUncertainty: starting')

        for dme in self.itervalues():
            if dme.upper > dme.lower:
                dme.uncertainty = max(DmElement.uncertaintyMinvalue, math.log(dme.upper-dme.lower))
            else:
                nTdebug('Queeny.setUncertainty: problem with %s', dme.format())
                dme.uncertainty = DmElement.uncertaintyMinvalue
        #end for

        atms = self.molecule.allAtoms()
        n = len(atms)

        for atm in atms:
            atm[key] = 0.0

        for i in range(n):
            atm1 = atms[i]
            for j in range(i+1,n):
                atm2 = atms[j]
                if self.has_key((atm1.atomIndex,atm2.atomIndex)):
                    dme = self[(atm1.atomIndex,atm2.atomIndex)]
                    atm1[key] += dme.uncertainty
                    atm2[key] += dme.uncertainty
                else:
                    atm1[key] += DmElement.uncertaintyDefault
                    atm2[key] += DmElement.uncertaintyDefault
                #end if
            #end for
        #end for
        fls = float(n-1)
        for atm in atms:
            atm[key] /= fls
        #end for

        # residues
        for res in self.molecule.allResidues():
            res[key] = 0.0
        for atm in atms:
            atm.residue[key] += atm[key]
        for res in self.molecule.allResidues():
            resAtomCount = len(res.atoms)
            if resAtomCount:
                res[key] /= resAtomCount
Beispiel #17
0
def copy_from_convention(from_convention, new_convention, protein_only=True):
    """Copy nomenclature convention from from_convention to new_convention.

    Only copy standard protein residues if protein_only (defaults to True).
    """
    residue_definitions = NTdb.residuesWithProperties("protein")
    if not protein_only:
        residue_definitions = NTdb.allResidueDefs()

    for res_def in residue_definitions:
        nTdebug("Copying %s nomenclature convention to %s for %s", from_convention, new_convention, res_def)
        res_def.nameDict[new_convention] = res_def.nameDict[from_convention]
        for atom_def in res_def:
            atom_def.nameDict[new_convention] = atom_def.nameDict[from_convention]
            atom_def.postProcess()
        res_def.postProcess()
Beispiel #18
0
def copy_from_convention(from_convention, new_convention, protein_only=True):
    """Copy nomenclature convention from from_convention to new_convention.

    Only copy standard protein residues if protein_only (defaults to True).
    """
    residue_definitions = NTdb.residuesWithProperties('protein')
    if not protein_only:
        residue_definitions = NTdb.allResidueDefs()

    for res_def in residue_definitions:
        nTdebug("Copying %s nomenclature convention to %s for %s",
                from_convention, new_convention, res_def)
        res_def.nameDict[new_convention] = res_def.nameDict[from_convention]
        for atom_def in res_def:
            atom_def.nameDict[new_convention] = atom_def.nameDict[
                from_convention]
            atom_def.postProcess()
        res_def.postProcess()
Beispiel #19
0
def getArchiveIdFromDirectoryName(dirName):
    ''' 
    From input such as:
    Return a valid id such as:
    or None on error.
    '''
    nTdebug("In `getArchiveIdFromDirectoryName`, with %s as dirName" % dirName)
    if not dirName:
        nTerror("Failed to map dirName [%s] because baseName evaluates to False." % dirName)
        return None
    # end if
    baseName = None
    for baseTry in results_baseList:
        nTdebug("baseTry: %s" % baseTry)
        if baseTry in dirName:
            baseName = baseTry
            break
        # end if
    # end def
    nTdebug("Returning %s as archiveID" % mapBase2Archive[baseName])
    if not baseName in mapBase2Archive.keys():
        nTwarning("Failed to map dirName [%s] with baseName [%s] because baseName is an unenumerated baseName." % (dirName, baseName))
        return None
    # end if
    return mapBase2Archive[baseName]
Beispiel #20
0
def getArchiveIdFromDirectoryName(dirName):
    ''' 
    From input such as:
    Return a valid id such as:
    or None on error.
    '''
    nTdebug("In `getArchiveIdFromDirectoryName`, with %s as dirName" % dirName)
    if not dirName:
        nTerror(
            "Failed to map dirName [%s] because baseName evaluates to False." %
            dirName)
        return None
    # end if
    baseName = None
    for baseTry in results_baseList:
        nTdebug("baseTry: %s" % baseTry)
        if baseTry in dirName:
            baseName = baseTry
            break
        # end if
    # end def
    nTdebug("Returning %s as archiveID" % mapBase2Archive[baseName])
    if not baseName in mapBase2Archive.keys():
        nTwarning(
            "Failed to map dirName [%s] with baseName [%s] because baseName is an unenumerated baseName."
            % (dirName, baseName))
        return None
    # end if
    return mapBase2Archive[baseName]
Beispiel #21
0
def smoothTriangleOld(data, degree, dropVals=False):
    """performs moving triangle smoothing with a variable degree."""
    """note that if dropVals is False, output length will be identical
        to input length, but with copies of data at the flanking regions"""
    triangle = numpy.array(range(degree) + [degree] + range(degree)[::-1]) + 1
    nTdebug("triangle: %s" % triangle)
    smoothed = []
    for i in range(degree, len(data) - degree * 2):
        point = data[i:i + len(triangle)] * triangle
        smoothed.append(sum(point) / sum(triangle))
    if dropVals:
        return smoothed
    nTdebug("data: %s" % str(data))
    nTdebug("smoothed[0]: %s" % smoothed[0])
    nTdebug("smoothed: %s" % str(smoothed))

    smoothedStart = [smoothed[0]] * (degree + degree / 2)
    nTdebug("smoothedStart: %s" % str(smoothedStart))

    smoothed = smoothedStart + smoothed
    while len(smoothed) < len(data):
        smoothed.append(smoothed[-1])
    return smoothed
Beispiel #22
0
def smoothTriangleOld(data,degree,dropVals=False):
        """performs moving triangle smoothing with a variable degree."""
        """note that if dropVals is False, output length will be identical
        to input length, but with copies of data at the flanking regions"""
        triangle=numpy.array(range(degree)+[degree]+range(degree)[::-1])+1
        nTdebug("triangle: %s" % triangle)
        smoothed=[]
        for i in range(degree,len(data)-degree*2):
                point=data[i:i+len(triangle)]*triangle
                smoothed.append(sum(point)/sum(triangle))
        if dropVals:
            return smoothed
        nTdebug("data: %s" % str(data))
        nTdebug("smoothed[0]: %s" % smoothed[0])
        nTdebug("smoothed: %s" % str(smoothed))

        smoothedStart=[smoothed[0]]*(degree+degree/2)
        nTdebug("smoothedStart: %s" % str(smoothedStart))

        smoothed = smoothedStart + smoothed
        while len(smoothed) < len(data):
            smoothed.append(smoothed[-1])
        return smoothed
Beispiel #23
0
def correct_hg_stap(res_def):
    """Correct cysteine and serine HG for STAP."""
    nTdebug('Applying %s HG STAP naming conventions', res_def)
    res_def['HG'].nameDict['STAP'] = 'HG1'
Beispiel #24
0
def correct_hg_stap(res_def):
    """Correct cysteine and serine HG for STAP."""
    nTdebug("Applying %s HG STAP naming conventions", res_def)
    res_def["HG"].nameDict["STAP"] = "HG1"
Beispiel #25
0
def runShiftx(project, parseOnly=False, model=None):
    """
    Use shiftx program to predict chemical shifts
    Works only for protein residues.

    Adds ShiftxResult instance to validation container of atoms
    LEGACY:
    Adds a NTlist object with predicted values for each model as shiftx attribute
    to each atom for which there are predictions, or empty list otherwise.

    Throws warnings for non-protein residues.
    Returns True on error.

    Shiftx works on pdb files, uses only one model (first), so we have to write the files separately and analyze them
    one at the time.
    """

    # LEGACY:
    if parseOnly:
        return parseShiftx(project)

    if cdefs.cingPaths.shiftx is None:
        nTmessage("runShiftx: no shiftx executable, skipping")
        return False  # Gracefully return

    if project.molecule is None:
        nTerror("runShiftx: no molecule defined")
        return True

    if project.molecule.modelCount == 0:
        nTwarning('runShiftx: no models for "%s"', project.molecule)
        return True

    if model is not None and model >= project.molecule.modelCount:
        nTerror('runShiftx: invalid model (%d) for "%s"', model, project.molecule)
        return True

    if not project.molecule.hasAminoAcid():
        nTmessage("==> Skipping runShiftx because no amino acids are present.")
        return False

    nTmessage("==> Running shiftx")

    skippedAtoms = []  # Keep a list of skipped atoms for later
    skippedResidues = []  # Only used for presenting to end user not actually used for skipping.
    skippedChains = []

    for chain in project.molecule.allChains():
        skippChain = True
        for res in chain.allResidues():
            if not res.hasProperties("protein"):
                if not res.hasProperties("HOH"):  # don't report waters
                    skippedResidues.append(res)
                for atm in res.allAtoms():
                    atm.pdbSkipRecord = True
                    skippedAtoms.append(atm)
                # end for
            else:
                skippChain = False
            # end if
            if skippChain:
                skippedChains.append(chain)
        # end for
    # end for
    if skippedResidues:
        nTmessage("==> runShiftx: %s non-protein residues will be skipped." % len(skippedResidues))

    defs = project.getStatusDict(constants.SHIFTX_KEY, **shiftxStatus())
    if model is not None:
        defs.models = NTlist(model)
    else:
        defs.models = NTlist(*range(project.molecule.modelCount))
    defs.baseName = "model_%03d"
    defs.completed = False
    defs.parsed = False
    defs.chains = []

    # initialize the shiftx attributes
    _resetShiftx(project)

    path = project.validationPath(defs.directory)
    if not path:
        return True
    if path.exists():
        nTdebug("runShiftx: removing %s with prior data", path)
        path.rmdir()
    path.makedirs()

    doShiftx = ExecuteProgram(pathToProgram=cdefs.cingPaths.shiftx, rootPath=path, redirectOutput=False)
    startTime = io.now()

    for model in defs.models:
        # set filenames
        rootname = defs.baseName % model
        nTdebug("runShiftx: doing model %s, path %s, rootname %s", model, path, rootname)

        # generate a pdbfile
        pdbFile = project.molecule.toPDB(model=model, convention=constants.IUPAC)
        if not pdbFile:
            nTerror("runShiftx: Failed to generate a pdb file for model: %s", model)
            return True
        pdbFile.save(path / rootname + ".pdb")
        del pdbFile

        for chain in project.molecule.allChains():
            if chain not in skippedChains:
                # nTdebug('Doing chain code [%s]' % (chain.name))
                # quotes needed because by default the chain id is a space now.
                # chainId =  "'" + chain.name + "'"
                # According to the readme in shiftx with the source this is the way to call it.
                chainId = "1" + chain.name
                outputFile = rootname + "_" + chain.name + ".out"
                defs.chains.append((chain.name, outputFile))
                doShiftx(chainId, rootname + ".pdb", outputFile)
            # end if
        # end for
    # end for

    # cleanup
    for pdbfile in path.glob("*.pdb"):
        pdbfile.remove()

    # Restore the 'default' state
    for atm in skippedAtoms:
        atm.pdbSkipRecord = False

    defs.completed = True
    # parse the results
    if parseShiftx(project):
        return True

    defs.date = io.now()
    defs.version = __version__
    defs.molecule = project.molecule.asPid
    defs.remark = "Shiftx on %s completed in %.1f seconds on %s; data in %s" % (
        project.molecule,
        defs.date - startTime,
        defs.date,
        path,
    )
    project.history(defs.remark)
    nTmessage("==> %s", defs.remark)
    return False
Beispiel #26
0
def _parseShiftxOutput(fileName, project, chainId):
    """
    Parse shiftx generated output (gv_version!).
    Store result in shiftx attribute (which is a NTlist type) of each atom

format file:

# Entries marked with a * may have inaccurate shift predictions.
# Entries marked with a value < -600 should be ignored
  501   H  N      116.3173
  501   H  CA      55.4902
  501   H  CB      29.9950
  501   H  C      169.8446
  501   H  H        8.4401
  or in 1y4o:
  1     G  N      109.7404
  1     G  CA      45.2787
  or in 1afp
  10    K  HZ3      3.7795 # A HZ3 that might not be present.


    Return True on error; eg. when the file is absent.
    """
    if not os.path.exists(fileName):
        nTerror("_parseShiftxOutput: Failed to find %s" % fileName)
        return True

    if project is None:
        nTerror("_parseShiftxOutput: no project defined")
        return True

    molecule = project.molecule

    nTdebug("_parseShiftxOutput: parsing %s", fileName)

    atomDict = molecule.getAtomDict(constants.IUPAC, chainId)

    for line in AwkLike(fileName, commentString="#", minNF=4):
        shift = line.float(4)
        if shift != -666.000:
            lineCol1 = int(line.dollar[1].strip("*"))
            atmName = line.dollar[3]
            if chainId is not None:
                atm = molecule.decodeNameTuple((constants.IUPAC, chainId, lineCol1, atmName))
                # happens for all N-terminal H because the Nterminal residue has H1/2/3
                # fix:
                if atm is None and atmName == "H":
                    atm = molecule.decodeNameTuple((constants.IUPAC, chainId, lineCol1, "H1"))
            else:
                atm = None
                if atomDict.has_key((lineCol1, atmName)):
                    atm = atomDict[(lineCol1, atmName)]
            # end if
            # print '>>', atm
            if not atm:
                pass
                nTdebug("parseShiftxOutput: chainId [%s] line %d (%s)", chainId, line.NR, line.dollar[0])
                # happens for all LYS without HZ3.
            else:
                result = project.validationData.getResult(atm, constants.SHIFTX_KEY, ShiftxResult())
                if result is None:
                    io.error("_parseShiftxOutput: retrieving ShiftxResult for atom {0}\n", atm)
                else:
                    result.DATA.append(shift)
                    # LEGACY:
                    atm.shiftx.append(shift)
Beispiel #27
0
# -2- results base is tmpNRG-CING
# -3- db schema is tmpnrgcing

#: override for development in localConstants.py @UnusedVariable Disables some operations for need for speed.
isProduction = 1  # DEFAULT: 1  @UnusedVariable
#: when assumed all are done. Disables some messaging in case not all are done.
assumeAllAreDone = 1  # DEFAULT: 1  @UnusedVariable

UJ = '/Users/i'
WS = os.path.join(UJ, 'workspace')
dDir = '/mnt/data/D'  # Web dir.
VCsecret = 'a/b/c'  # Overriden locally. @UnusedVariable Only used in publishVC.py

try:
    from cing.NRG.localConstants import *  #@UnusedWildImport # pylint: disable=E0611
    nTdebug("Loaded NRG localConstants.py.")
except:
    nTdebug(
        "Consider creating a localConstants.py file with a different 'user' location."
    )

platform_dir = os.path.join(
    UJ, 'wattosTestingPlatform'
)  # For BMRB, and PDB and mmCIF formatted entries data. @UnusedVariable
pdbbase_dir = os.path.join(
    platform_dir,
    'pdb')  # For PDB and mmCIF formatted entries data. @UnusedVariable
baseDir = os.path.join(UJ, 'CASD-NMR-CING')  #@UnusedVariable
baseCaspDir = os.path.join(UJ, 'CASP-NMR-CING')  #@UnusedVariable
nrg_project = 'nmrrestrntsgrid'
nrg_dir = os.path.join(WS, nrg_project)  # For NRG project code.
Beispiel #28
0
def correct_his_stap(mol_def):
    """Correct histidine residue definitions for STAP."""
    nTdebug("Applying histidine STAP naming conventions")
    mol_def["HIS"].nameDict["STAP"] = "HSD"
    mol_def["HISE"].nameDict["STAP"] = "HSE"
    mol_def["HISH"].nameDict["STAP"] = "HSP"
Beispiel #29
0
def correct_ile_d_stap(res_def):
    """Correct cysteine delta for STAP."""
    nTdebug("Applying isoleucine CD1/HD123 STAP naming conventions")
    res_def["CD1"].nameDict["STAP"] = "CD"
    for name, repl in [("HD11", "HD1"), ("HD12", "HD2"), ("HD13", "HD3")]:
        res_def[name].nameDict["STAP"] = repl
Beispiel #30
0
def smoothTriangleOther(data,degree=1,dropVals=False):
    nTdebug("data: %s" % str(data))
    degree = 1 # 1 point on each side except for end points that will be 2:1
    beginAverage = [ 2/3., 1/3. ]
    endAverage = [ 1/3., 2/3. ]
    n =  len(data)
    triangle=numpy.array(range(degree)+[degree]+range(degree)[::-1])+1
    sumTriangle = sum(triangle)
    nTdebug("triangle: %s" % triangle)
    smoothed=[]
    startIdx = degree
    endIdx = n-degree*2
    nTdebug("n, degree, startIdx, endIdx: %s,%s,%s,%s" % (n, degree, startIdx,endIdx))
    for i in range(startIdx,endIdx):
        section = data[i:i+len(triangle)]
        point=section*triangle
        smValue = sum(point)/sumTriangle
        nTdebug("Looking at section i %s: %s smoothed to: %s" % (i,str(section),smValue))
        smoothed.append(smValue)
    if dropVals:
        return smoothed
    nTdebug("smoothed[0]: %s" % smoothed[0])
    nTdebug("smoothed: %s" % str(smoothed))
    smoothedStart = (data[0] * beginAverage[0] + data[1] * beginAverage[1])
    smoothedEnd = (data[n-2] * endAverage[0] + data[n-1] * endAverage[1])
    nTdebug("smoothedStart: %s" % str(smoothedStart))
    nTdebug("smoothedEnd: %s" % str(smoothedEnd))

    smoothed = [smoothedStart] + smoothed + [smoothedEnd]
    while len(smoothed) < n:
        smoothed.append(smoothed[-1])
    return smoothed
Beispiel #31
0
def correct_hg_stap(res_def):
    """Correct cysteine and serine HG for STAP."""
    nTdebug('Applying %s HG STAP naming conventions', res_def)
    res_def['HG'].nameDict['STAP'] = 'HG1'
Beispiel #32
0
# -3- db schema is tmpnrgcing

#: override for development in localConstants.py @UnusedVariable Disables some operations for need for speed.
isProduction = 1  # DEFAULT: 1  @UnusedVariable
#: when assumed all are done. Disables some messaging in case not all are done.
assumeAllAreDone = 1  # DEFAULT: 1  @UnusedVariable

UJ = "/Users/i"
WS = os.path.join(UJ, "workspace")
dDir = "/mnt/data/D"  # Web dir.
VCsecret = "a/b/c"  # Overriden locally. @UnusedVariable Only used in publishVC.py

try:
    from cing.NRG.localConstants import *  # @UnusedWildImport # pylint: disable=E0611

    nTdebug("Loaded NRG localConstants.py.")
except:
    nTdebug("Consider creating a localConstants.py file with a different 'user' location.")

platform_dir = os.path.join(
    UJ, "wattosTestingPlatform"
)  # For BMRB, and PDB and mmCIF formatted entries data. @UnusedVariable
pdbbase_dir = os.path.join(platform_dir, "pdb")  # For PDB and mmCIF formatted entries data. @UnusedVariable
baseDir = os.path.join(UJ, "CASD-NMR-CING")  # @UnusedVariable
baseCaspDir = os.path.join(UJ, "CASP-NMR-CING")  # @UnusedVariable
nrg_project = "nmrrestrntsgrid"
nrg_dir = os.path.join(WS, nrg_project)  # For NRG project code.

scripts_dir = os.path.join(nrg_dir, "scripts")
wcf_dir = os.path.join(scripts_dir, "wcf")  # @UnusedVariable
divDir = os.path.join(pdbbase_dir, "data/structures/divided")
Beispiel #33
0
def correct_his_stap(mol_def):
    """Correct histidine residue definitions for STAP."""
    nTdebug('Applying histidine STAP naming conventions')
    mol_def['HIS'].nameDict['STAP'] = 'HSD'
    mol_def['HISE'].nameDict['STAP'] = 'HSE'
    mol_def['HISH'].nameDict['STAP'] = 'HSP'
Beispiel #34
0
def correct_ile_d_stap(res_def):
    """Correct cysteine delta for STAP."""
    nTdebug('Applying isoleucine CD1/HD123 STAP naming conventions')
    res_def['CD1'].nameDict['STAP'] = 'CD'
    for name, repl in [('HD11', 'HD1'), ('HD12', 'HD2'), ('HD13', 'HD3')]:
        res_def[name].nameDict['STAP'] = repl
Beispiel #35
0
def correct_ile_d_stap(res_def):
    """Correct cysteine delta for STAP."""
    nTdebug('Applying isoleucine CD1/HD123 STAP naming conventions')
    res_def['CD1'].nameDict['STAP'] = 'CD'
    for name, repl in [('HD11', 'HD1'), ('HD12', 'HD2'), ('HD13', 'HD3')]:
        res_def[name].nameDict['STAP'] = repl
Beispiel #36
0
def runTalosPlus(project, tmp=None, parseOnly=False):
    """Perform a talos+ analysis; parses the results; put into new CING dihedral restraint list
    Returns True on error.
    Returns False when talos is absent or when all is fine.
    """
    #LEGACY:
    if parseOnly:
        return parseTalosPlus(project)

    if project is None:
        nTerror("runTalosPlus: No project defined")
        return True

    # check executable
    if cdefs.cingPaths.talos is None:
        nTmessage('runTalosPlus: no talosPlus executable defined, skipping')
        return False # Gracefully return
    status, output = getOsResult('which '+ cdefs.cingPaths.talos )
    if len(output) == 0:
        nTmessage('runTalosPlus: invalid talosPlus executable defined (%s), skipping', cdefs.cingPaths.talos)
        return False # Gracefully return

    if project.molecule is None:
        nTmessage("runTalosPlus: No molecule defined")
        return True

    residues = project.molecule.residuesWithProperties('protein')
    if not residues:
        nTmessage('runTalosPlus: no amino acids defined')
        return False

    if len( project.molecule.resonanceSources ) == 0:
        nTmessage("==> runTalosPlus: No resonances defined so no sense in running.")
        # JFD: This doesn't catch all cases.
        return False

    talosDefs = project.getStatusDict(constants.TALOSPLUS_KEY, **talosDefaults)

    talosDefs.molecule = project.molecule.asPid
    talosDefs.directory = constants.TALOSPLUS_KEY

    path = project.validationPath( talosDefs.directory )
    if not path:
        return True
    if path.exists():
        nTdebug('runTalosPlus: removing %s with prior data', path)
        path.rmdir()
    path.makedirs()

    startTime = io.now()

    talosDefs.completed = False
    talosDefs.parsed = False
    _resetTalosPlus(project)

    # Exporting the shifts
    fileName = path / talosDefs.tableFile
    if exportShifts2TalosPlus(project, fileName=fileName):
        nTwarning("runTalosPlus: Failed to exportShifts2TalosPlus; this is normal for empty CS list.")
        return False

    # running TalosPlus
    talosProgram = ExecuteProgram(cdefs.cingPaths.talos, rootPath=path, redirectOutput=True)
    nTmessageNoEOL('==> Running talos+ ... ')
    talosProgram( '-in ' + talosDefs.tableFile + ' -sum ' + talosDefs.predFile )
    nTmessage('Done!')

    if _findTalosOutputFiles(path, talosDefs):
        return True

    talosDefs.date = io.now()
    talosDefs.completed=True
    talosDefs.version = __version__
    talosDefs.molecule = project.molecule.asPid
    talosDefs.remark = 'TalosPlus on %s completed in %.1f seconds on %s; data in %s' % \
                       (project.molecule, talosDefs.date-startTime, talosDefs.date, path)

    # Importing the results
    if parseTalosPlus(project):
        nTerror("runTalosPlus: Failed parseTalosPlus")
        return True

    project.history(talosDefs.remark)
    nTmessage('==> %s', talosDefs.remark)
    return False
Beispiel #37
0
def smoothTriangleOther(data, degree=1, dropVals=False):
    nTdebug("data: %s" % str(data))
    degree = 1  # 1 point on each side except for end points that will be 2:1
    beginAverage = [2 / 3., 1 / 3.]
    endAverage = [1 / 3., 2 / 3.]
    n = len(data)
    triangle = numpy.array(range(degree) + [degree] + range(degree)[::-1]) + 1
    sumTriangle = sum(triangle)
    nTdebug("triangle: %s" % triangle)
    smoothed = []
    startIdx = degree
    endIdx = n - degree * 2
    nTdebug("n, degree, startIdx, endIdx: %s,%s,%s,%s" %
            (n, degree, startIdx, endIdx))
    for i in range(startIdx, endIdx):
        section = data[i:i + len(triangle)]
        point = section * triangle
        smValue = sum(point) / sumTriangle
        nTdebug("Looking at section i %s: %s smoothed to: %s" %
                (i, str(section), smValue))
        smoothed.append(smValue)
    if dropVals:
        return smoothed
    nTdebug("smoothed[0]: %s" % smoothed[0])
    nTdebug("smoothed: %s" % str(smoothed))
    smoothedStart = (data[0] * beginAverage[0] + data[1] * beginAverage[1])
    smoothedEnd = (data[n - 2] * endAverage[0] + data[n - 1] * endAverage[1])
    nTdebug("smoothedStart: %s" % str(smoothedStart))
    nTdebug("smoothedEnd: %s" % str(smoothedEnd))

    smoothed = [smoothedStart] + smoothed + [smoothedEnd]
    while len(smoothed) < n:
        smoothed.append(smoothed[-1])
    return smoothed
Beispiel #38
0
def correct_his_stap(mol_def):
    """Correct histidine residue definitions for STAP."""
    nTdebug('Applying histidine STAP naming conventions')
    mol_def['HIS'].nameDict['STAP'] = 'HSD'
    mol_def['HISE'].nameDict['STAP'] = 'HSE'
    mol_def['HISH'].nameDict['STAP'] = 'HSP'
Beispiel #39
0
def _importTalosPlus( project, predFile, ssFile=None ):
    """
    Helper code: Import TalosPlus results from pred.tab and pred.ss.tab
    """

    if not project:
        return True
    #end if

    nTdebug('_importTalosPlus: files %s and %s', predFile, ssFile)

    if not project.molecule:
        nTerror('importTalosPlus: no molecule defined')
        return True
    molecule = project.molecule

    table = _importTableFile( predFile, molecule )

    for row in table:

        #print '>', row, row.residue
        talosPlus = TalosPlusResult()
        talosPlus.phi = NTvalue( row.PHI, row.DPHI, '%6.1f +- %4.1f')
        talosPlus.psi = NTvalue( row.PSI, row.DPSI, '%6.1f +- %4.1f')
        talosPlus.S2  = row.S2
        talosPlus.count = row.COUNT
        talosPlus.classification = row.CLASS

        if talosPlus.classification is 'None' or \
           talosPlus.phi.value == 9999.00 or \
           talosPlus.psi.value == 9999.00:
            talosPlus.phi.value = NaN
            talosPlus.phi.error = NaN
            talosPlus.psi.value = NaN
            talosPlus.psi.error = NaN
            talosPlus.S2 = NaN # pylint: disable=C0103
        #end if

        project.validationData.setResult(row.residue, constants.TALOSPLUS_KEY, talosPlus)
        #LEGACY:
        #talosPlus.residue = row.residue: implemented through "property"
        row.residue.talosPlus = talosPlus
    #end for

    # do the second ss file
    ssdict = dict( H = 'Helix', E='Extended', L='Coil' ) # X is translated to None
    if ssFile:
        table = _importTableFile( ssFile, molecule )
        #print '>>', table
        for row in table:
            #print '>>', row

            if ('residue' in row and row.residue is not None):
                tPlus = project.validationData.getResult(row.residue, constants.TALOSPLUS_KEY)
                if tPlus is not None:
                    tPlus.Q_H = row.Q_H    # Helix
                    tPlus.Q_E = row.Q_E    # Extended
                    tPlus.Q_L = row.Q_L    # Loop
                    if row.SS_CLASS in ssdict:
                        tPlus.ss_class = ssdict[row.SS_CLASS]
                    else:
                        tPlus.ss_class = None
                    tPlus.ss_confidence = row.CONFIDENCE
                else:
                    nTerror('_importTalosPlus: %s: row: %s', ssFile, row)