Пример #1
0
def loadPDBmacro( projects ):


    fp = open( projects.path('loadPDB.mcr' ), 'w')

    fprintf(fp, 'Console off\n')
    for p in projects.entries:
        #fprintf(fp, 'loadPDB %s\n', os.path.abspath(projects.path(p.name+'.pdb')))
        fprintf(fp, 'loadPDB %s,Center=No\n', projects.path(p.name+'.pdb'))
    #end for
    fprintf(fp, 'Style Ribbon\n')
    fprintf(fp, 'macro %s\n', projects.path('colorPDB.mcr'))
    fprintf(fp, 'Console on\n')
    fp.close()
Пример #2
0
def printRmsds( title, rmsds, stream=sys.stdout ):
    n = len(rmsds)
    printTitle(title, 20*(n+1), stream)
    fprintf( stream, '%-20s%s\n','', rmsds.zap('group').format('  %-16s  '))
    for row in rmsds:
        fprintf( stream, '%-20s%s\n',  row.group, row.format('%-18s  '))
    fprintf( stream, '%s\n', '_'*20*(n+1))
Пример #3
0
def obj2XML(obj, stream=None, path=None):
    """Convert an object to XML
       output to stream or path
       gwv 13 Jun08: return object or None on error
    """
    if obj is None:
        io.error("obj2XML: no object\n")
        return None
    if stream is None and path is None:
        io.error("obj2XML: no output defined\n")
        return None

    closeFile = 0
    if not stream:
        stream = open(path, 'w')
        closeFile = 1

    fprintf(stream, '<?xml version="1.0" encoding="ISO-8859-1"?>\n')
    nTtoXML(obj, depth=0, stream=stream, indent='    ')

    if closeFile:
        stream.close()

    return obj
Пример #4
0
def rogMacro( projects ):

    stream = open( projects.path('ROG.mcr' ), 'w')

    fprintf(stream, 'Console off\n')
    fprintf(stream, 'ColorRes  All, Gray\n')

    yasaraColorDict = dict(green = 240, orange = 150, red = 120)

    for p in projects:
        selectedResidues = p.molecule.setResiduesFromRanges(projects.ranges)
        for res in p.molecule.allResidues():
            if res in selectedResidues:
                pass
            else:
                fprintf(stream, 'ColorRes object %d residue %d, %s\n', p.id+1, res.resNum, yasaraColorDict[res.rogScore.colorLabel])
    #end for
    fprintf(stream, 'Console on\n')
Пример #5
0
def colorPDBmacro( projects ):


    fp = open( projects.path('colorPDB.mcr' ), 'w')

    fprintf(fp, 'Console off\n')
    for p in projects.entries:
        #fprintf(fp, 'loadPDB %s\n', os.path.abspath(projects.path(p.name+'.pdb')))
        selectedResidues = p.molecule.setResiduesFromRanges(projects.ranges)
        #print '>>', selectedResidues
        if p.has_key('color'):
            fprintf(fp, 'ColorObject %d, %d\n', p.id+1, p.color)
            for res in p.molecule.allResidues():
                #print res,
                if res in selectedResidues:
                    pass
                else:
                    fprintf(fp, 'ColorRes object %d residue %d, grey\n', p.id+1, res.resNum)
                #end if
            #end for
        #end if
    #end for
    fprintf(fp, 'Console on\n')
    fp.close()
Пример #6
0
def nTtoXML(obj, depth=0, stream=sys.stdout, indent='\t', lineEnd='\n'):
    """Generate XML:
       check for method toXML
       or
       standard types int, float, tuple, list, dict
    """
    if (obj == None):
        nTindent(depth, stream, indent)
        fprintf(stream, "<None/>")
        fprintf(stream, lineEnd)
    elif hasattr(obj, 'toXML'):
        obj.toXML(depth, stream, indent, lineEnd)
    elif (type(obj) == int):
        nTindent(depth, stream, indent)
        fprintf(stream, "<int>%s</int>", repr(obj))
        fprintf(stream, lineEnd)
    elif (type(obj) == bool):
        nTindent(depth, stream, indent)
        fprintf(stream, "<bool>%s</bool>", repr(obj))
        fprintf(stream, lineEnd)
    elif (type(obj) == float):
        nTindent(depth, stream, indent)
        fprintf(stream, "<float>%s</float>", repr(obj))
        fprintf(stream, lineEnd)
    elif (type(obj) == str):
        nTindent(depth, stream, indent)
#        fprintf( stream, "<string>%s</string>",  saxutils.escape( obj )  )
        fprintf(stream, "<string>%s</string>", unicode(saxutils.escape(obj)))
        fprintf(stream, lineEnd)
    elif (type(obj) == unicode):
        nTindent(depth, stream, indent)
        fprintf(stream, "<unicode>%s</unicode>", unicode(saxutils.escape(obj)))
        fprintf(stream, lineEnd)
    elif (type(obj) == list):
        nTindent(depth, stream, indent)
        fprintf(stream, "<list>")
        fprintf(stream, lineEnd)
        for a in obj:
            nTtoXML(a, depth+1, stream, indent, lineEnd)
        #end for
        nTindent(depth, stream, indent)
        fprintf(stream, "</list>")
        fprintf(stream, lineEnd)
    elif (type(obj) == tuple):
        nTindent(depth, stream, indent)
        fprintf(stream, "<tuple>")
        fprintf(stream, lineEnd)
        for a in list(obj):
            nTtoXML(a, depth+1, stream, indent, lineEnd)
        #end for
        nTindent(depth, stream, indent)
        fprintf(stream, "</tuple>")
        fprintf(stream, lineEnd)
    elif (type(obj) == dict):
        nTindent(depth, stream, indent)
        fprintf(stream, "<dict>")
        fprintf(stream, lineEnd)
        for key, value in obj.iteritems():
            nTindent(depth+1, stream, indent)
            fprintf(stream, "<key name=%s>", quote(key))
            fprintf(stream, lineEnd)
            nTtoXML(value, depth+2, stream, indent, lineEnd)
            nTindent(depth+1, stream, indent)
            fprintf(stream, "</key>")
            fprintf(stream, lineEnd)
        #end for
        nTindent(depth, stream, indent)
        fprintf(stream, "</dict>")
        fprintf(stream, lineEnd)
    else:
        pass
        io.error('nTtoXML: undefined object "{0}": cannot generate XML\n', obj) # reenable when done testing.
Пример #7
0
def nTindent(depth, stream, indent):
    """
    Indent stream to depth; to pretty format XML
    """
    for dummy in range(depth):
        fprintf(stream, indent)
Пример #8
0
 def exportDef(self, stream=sys.stdout, convention=constants.INTERNAL):
     """export name definitions to stream"""
     io.fprintf(stream, "convention = %r\n", convention)
     for residue in self:
         residue.exportDef(stream=stream, convention=convention)
Пример #9
0
    def write( self, stream=sys.stdout):
        """
        Write tab to stream
        """
        for r in self.remarks:
            fprintf( stream, 'REMARK %s\n', r )
        #end for
        fprintf( stream, '\n' )

        for d,v in self.data.iteritems():
            fprintf( stream, 'DATA %s %s\n', d, v ) # Note: only ONE space between DATA and identifier!!!
        #end for
        fprintf( stream, '\n' )

        fprintf(     stream, 'VARS    ' )
        for c in self.columnDefs:
            if not c.hide:
                fprintf( stream, '%s ', c.name )
        #end for
        fprintf( stream, '\n' )

        fprintf(     stream, 'FORMAT  ' )
        for c in self.columnDefs:
            if not c.hide:
                fprintf( stream, '%s ', c.fmt )
        #end for
        fprintf( stream, '\n' )

        fprintf( stream, '\n' )
        for row in self:
            fprintf( stream, '%s\n', row )
Пример #10
0
def mkYasaraByResidueMacro(projects, keys,
                            minValue = 0.0, maxValue = 1.0, reverseColorScheme = False,
                            path = None
                           ):

#    nTdebug('mkYasaraByResidueMacro: keys: %s, minValue: %s maxValue: %s', keys, minValue, maxValue)

    if path==None:
        stream = sys.stdout
    else:
        stream = open( path, 'w')
    #end if

    fprintf(stream, 'Console off\n')
    fprintf(stream, 'ColorRes All, Gray\n')
    fprintf(stream, 'PropRes All, -999\n')
    if reverseColorScheme:
        fprintf(stream, 'ColorPar Property Min,red,%f\n', minValue)
        fprintf(stream, 'ColorPar Property Max,blue,%f\n', maxValue)
    else:
        fprintf(stream, 'ColorPar Property Min,blue,%f\n', minValue)
        fprintf(stream, 'ColorPar Property Max,red,%f\n', maxValue)

    for p in projects:
        for res in p.molecule.allResidues():
            value = getDeepByKeysOrAttributes(res, *keys)
    #        if res.has_key(property) and res[property] != None and not isNaN(res[property]):
            if value != None and not isNaN(value):
                fprintf(stream, 'PropRes object %d Residue %d, %.4f\n', p.id+1, res.resNum, value)
        #end for

    fprintf(stream, 'ColorAll Property\n')
    fprintf(stream, 'Console on\n')

    if path:
        stream.close()
Пример #11
0
def colorPhiPsiMacro( projects, minValue=2.0, maxValue=4.0 ):

    fp = open( projects.path('phipsi.mcr' ), 'w')

    fprintf(fp, 'Console off\n')
    fprintf(fp, 'ColorPar Property Min,blue, %7.3f\n', minValue)
    fprintf(fp, 'ColorPar Property Max,red,  %7.3f\n', maxValue)
    for p in projects.entries[1:]:
        fprintf(fp, 'ColorRes object %d, Gray\n', p.id+1)
        fprintf(fp, 'PropRes object %d, -999\n', p.id+1)
        for res in p.molecule.allResidues():
            if res.has_key('phipsiRmsds'):
                if not isNaN(res.phipsiRmsds[0][p.id].value):
                    fprintf( fp, 'PropRes object %d residue %d, %7.3f\n', p.id+1, res.resNum, res.phipsiRmsds[0][p.id].value)
            #end if
        #end for
        fprintf(fp, 'ColorObject %d, property\n', p.id+1)

    #end for
    fprintf(fp, 'Console off\n')
    fp.close()
Пример #12
0
def printRestraintScores( projects, stream=sys.stdout ):

    n = len(projects)
    if n == 0:
        return

#    print constants.dots20*(n+1)
#    print ' Restraints target', projects[0].target
#    print constants.dots20*(n+1)
#    print

    hlen=40

    printTitle('Restraint scores target '+projects.name, 110, stream)

    for p in projects:
        header = sprintf('%s project %-20s %s', '-'*hlen, p.name, '-'*hlen)
        fprintf( stream,'%s\n', header)

        if len(p.dihedrals)+len(p.distances) == 0:
            fprintf( stream,'%s\n%s\n\n',   "  No restraints",'-'*len(header))
            continue


        if len( p.distances ) > 0:
            fprintf( stream,    '%-25s %5s %5s %5s %5s %5s %5s   %-7s  %4s %4s %4s %4s    rmsd\n',
                   'DistanceRestraintLists', 'count', 'intra', 'seq', 'med', 'long', 'amb', 'ROG','low','>0.1','>0.3','>0.5'
                   )

            for r in p.distances:
                fprintf( stream,'  %-23s %5d %5d %5d %5d %5d %5d   %-7s  %4d %4d %4d %4d    %5.3f +- %5.3f\n',
                        r.name,
                        len(r), len(r.intraResidual), len(r.sequential), len(r.mediumRange), len(r.longRange), len(r.ambiguous),
                        r.rogScore,
                        r.violCountLower, r.violCount1, r.violCount3, r.violCount5,
                        r.rmsdAv, r.rmsdSd
                       )
            fprintf(stream, "\n")
        #end if
        if len(p.dihedrals) > 0:
            fprintf( stream,    '%-25s %5s %5s %5s %5s %5s %5s   %-7s  %4s %4s %4s %4s    rmsd\n',
                   'DihedralRestraintsLists', 'count', '','','','','', 'ROG','','>1','>3','>5',
                   )
            for r in p.dihedrals:
                fprintf( stream,'  %-23s %5s %5s %5s %5s %5s %5s   %-7s  %4s %4d %4d %4d    %5.3f +- %5.3f\n',
                        r.name,
                        len(r), '.', '.', '.', '.', '.',
                        r.rogScore, '.',
                        r.violCount1, r.violCount3, r.violCount5,
                        r.rmsdAv, r.rmsdSd
                       )
        #end if
        fprintf( stream,'%s\n\n',  '-'*len(header))
Пример #13
0
def printOverallScores( projects, stream = sys.stdout ):
    # Overall scores

    n = len(projects)
    if n == 0:
        return

    printTitle('Overall scores target '+projects.name, 20*(n+1), stream)
#    line = constants.dots20*(n+1)
#   fprintf( stream, '%s\n    Overall scores %s\n%s\n\n', line, projects.name, line )
    fprintf( stream, '%-20s%s\n\n', 'Parameter', projects.entries.zap('group').format('%-20s'))

    # rmsds
    fprintf( stream, '%-20s%s\n','rmsdToMean', projects.entries.zap('summaryDict','rmsdToMean_backboneAverage').format('  %-18s') )
    fprintf( stream, '%-20s%s\n','pairwiseRmsd', projects.entries.zap('summaryDict','pairwiseRmsd').format('%-16s    ') )
    fprintf( stream, '%-20s%s\n\n','pairwiseRmsdTo_'+projects.entries[0].group, projects.entries.zap(
        'summaryDict','pairwiseRmsdToFirst').format('%-18s  ') )

    # CING scores
    for key in ['CING_red', 'CING_orange', 'CING_green']:
        fprintf( stream, '%-20s%s\n',key, projects.entries.zap('summaryDict',key).format('%-18s  ') )
    fprintf( stream, '\n')

    # Procheck scores
    for key in ['PC_core','PC_allowed','PC_generous','PC_disallowed','PC_gf']:
        fprintf( stream, '%-20s%s\n',key, projects.entries.zap('summaryDict',key).format('%-18s  ') )
    fprintf( stream, '\n')

    # Whatif scores
    for checkId in projects[0].molecule.runWhatif.summaryCheckIdList:
        key = 'WI_'+projects[0].molecule.runWhatif.cingCheckId(checkId)
        fprintf( stream, '%-20s%s\n',key, projects.entries.zap('summaryDict',key).format('%-18s  ') )
    fprintf( stream, '\n')
Пример #14
0
def printTitle(title, length, stream=sys.stdout ):
    line = '-'*length
    fprintf( stream, '%s\n  %s\n%s\n', line, title, line )