def __init__(self): NTdict.__init__(self, __CLASS__ = 'ROGscore', __FORMAT__ = "ROGscore '%(colorLabel)s' %(colorCommentList)s" ) # Explicitly showing instance attributes here in init. self.colorLabel = constants.COLOR_GREEN # Elements in this list are tuples of (color, comment). self.colorCommentList = NTlist()
def __init__( self, table, id, **kwds ): NTdict.__init__( self, __CLASS__ = 'NmrPipeTabRow', table = table, id = id, name = 'row'+str(id), __FORMAT__ = '%(name)s', **kwds ) # set defaults to None for c in self.keys(): self.setdefault( c, None )
def __init__(self, checkID, level, modelCount ): NTdict.__init__( self, __CLASS__ = 'CingResult', checkID = checkID, alternate = None, level = level, # comment = Whatif.explain(checkID), ) # # Initialize the lists # if Whatif.cingNameDict.has_key(checkID): # self.alternate = Whatif.cingNameDict[checkID] # for c in [ VALUE_LIST_STR, QUAL_LIST_STR]: for c in [ constants.VALUE_LIST_STR ]: self[c] = nTfill( None, modelCount)
def __init__( self, tabFile=None, **kwds ): NTdict.__init__( self, __CLASS__ = 'nmrPipeTab', **kwds ) self.setdefault('noneIndicator', '-') # character to identify the None value self.columnDefs = NTlist() # list of column definitions, implemented # as NTdict self.rows = NTlist() self.nrows = 0 self.remarks = NTlist() self.data = NTdict() self.tabFile = tabFile if tabFile: self.readFile( tabFile )
def __init__(self, name, status = 'keep'): NTlist.__init__(self) ProjectListMember.__init__(self) # Initialized objectPath self.__CLASS__ = 'ResonanceList' self.name = name # Name of the list self.status = status # Status of the list; 'keep' indicates storage required self.currentId = 0 # Id for each element of list self._idDict = {} # dictionary to look up id in case the list is sorted differently self._byItem = None # if not None: list was sorted _byItem. self.vascoResults = NTdict() # See applyVascoChemicalShiftCorrections # NB match with VASCO_RESULTS_STR self.vascoApplied = False # VASCO_APPLIED_STR self.bmrb_id = None # Will be derived from name when calling rename. self.rogScore = ROGscore() self.SMLhandler.SML_SAVE_ATTRIBUTE_LIST = self.SML_SAVE_ATTRIBUTE_LIST self.rename(name) # Triggers setting self.bmrb_id
# (RES_LEVEL, 'PDBLST', None, 'List of residues', 'List of residues'), # (RES_LEVEL, 'PL3CHK', None, 'Side chain planarity with hydrogens attached', 'NA planarity'), # (RES_LEVEL, 'PLNCHK', 'planarities', 'Protein side chain planarities', 'Protein SC planarity'), # (RES_LEVEL, 'PRECHK', None, 'Missing backbone atoms.', 'Missing backbone atoms.'), # (RES_LEVEL, 'PUCCHK', None, 'Ring puckering in Prolines', 'Ring puckering in Prolines'), # (RES_LEVEL, 'QUACHK', 'packingQuality1','Directional Atomic Contact Analysis, aka 1st generation packing quality', 'Packing quality'), # (RES_LEVEL, 'RAMCHK', 'ramachandran', 'Ramachandran Z-score', 'Ramachandr.' ), # (RES_LEVEL, 'ROTCHK', 'rotamer', 'Rotamers', 'Rotamer normality'), # (RES_LEVEL, 'SCOLST', None, 'List of symmetry contacts', 'List of symmetry contacts'), # (RES_LEVEL, 'TO2CHK', None, 'Missing C-terminal groups', 'Missing C-terminal groups'), # (RES_LEVEL, 'TOPPOS', None, 'Ligand without know topology', 'Ligand without know topology'), # (RES_LEVEL, 'TORCHK', None, 'Unknown check', 'Unknown check'), # (RES_LEVEL, 'WIOPAC', None, 'Water packing', 'Water packing') ] cingNameDict = NTdict( zip( nTzap(nameDefs,1), nTzap(nameDefs,2)) ) nameDict = NTdict( zip( nTzap(nameDefs,1), nTzap(nameDefs,3)) ) shortNameDict = NTdict( zip( nTzap(nameDefs,1), nTzap(nameDefs,4)) ) cingNameDict.keysformat() nameDict.keysformat() shortNameDict.keysformat() wiPlotList = [] # GV: moved to outer level to not always call createHtmlWhatif wiPlotList.append( ('_01_backbone_chi','QUA/RAM/BBC/C12') ) wiPlotList.append( ('_02_bond_angle','BND/ANG/NQA/PLNCHK') ) wiPlotList.append( ('_03_steric_acc_flip','BMP/ACC/FLP/CHI') ) # Whatif id's for summary; will be keys in molecule[WHATIF_STR] dict # Make them available to 'outside world through the Whatif class
def __init__(self): NTdict.__init__(self) self[ ERROR_ID ] = NTlist() self[ WARNING_ID ] = NTlist() self[ MESSAGE_ID ] = NTlist() self[ DEBUG_ID ] = NTlist()
"C": 1, "N": 1, "H": 1, "HN": 1, "H1": 1, "H2": 1, "H3": 1, "CA": 1, "HA": 1, "HA1": 1, "HA2": 1, "HA3": 1, } backBoneNucleicAtomDict = {"P": 1, "O3'": 1, "C3'": 1, "C4'": 1, "C5'": 1, "O5'": 1} # skipping 'backbone protons' NterminalProteinAtomDict = NTdict() NterminalProteinAtomDict.appendFromList("H1 H2 H3 H' H''".split()) # watch out; H1 does occur in nucleic acid bases. NterminalNucleicAtomDict = NTdict() NterminalNucleicAtomDict.appendFromList("HOP2 HOP3".split()) def isNterminalAtom(atmDef): """ Return True if atom belongs to N-terminal category. Needs to be called by valid atmDef or 0 will be returned. """ if atmDef is None or atmDef.residueDef is None: # Fixes 2ksi # nTdebug("%s called without atom/residue definition." % getCallerName()) return 0 if atmDef.residueDef.hasProperties("protein"):
def __init__(self): NTdict.__init__(self) self[ERROR_ID] = NTlist() self[WARNING_ID] = NTlist() self[MESSAGE_ID] = NTlist() self[DEBUG_ID] = NTlist()
directories = cdefs.directories moleculeDirectories = cdefs.validationDirectories validationDirectories = cdefs.validationDirectories htmlDirectories = cdefs.htmlDirectories cingPaths = cdefs.cingPaths outlierColor = '#CC66FF' # iWeb lavender plotParameters = NTdict( #default dihedralDefault = NTdict( min = 0.0, max = 360.0, mticksize= 10, ticksize = 60, # color = 'green', color = '#990099', # iWeb plum outlier = outlierColor, average = 'blue', lower = 'orange', upper = 'orange' ), ) plotParameters.PHI = plotParameters.dihedralDefault.copy() plotParameters.PHI.min = -180 plotParameters.PHI.max = 180 plotParameters.PHI.xlabelLat = '$\phi 1$' # Latex plotParameters.PSI = plotParameters.PHI.copy() plotParameters.PHI.xlabelLat = '$\psi 1$' # Latex
config = NTdict( XPLOR = xplorPath, # (waterrefine) xplor stuff, directories, etc. refinePath = refinePath, topparPath = os.path.join(refinePath,'toppar'), protocolsPath = os.path.join(refinePath,'explicit_solvent'), parameterFiles = [ 'parallhdg5.3-merge.pro', 'parallhdg5.3.sol', 'par_axis_aria.pro', 'ion.param', ], topologyFiles = [ 'topallhdg5.3-merge.pro', 'topallhdg5.3.sol', 'top_axis_aria.pro', 'ion.top', ], directories = NTdict( converted = 'Converted', analyzed = 'Analyzed', # analyzed from refine annealed = 'Annealed', # annealed from template template = 'Template', # extended structure at random refined = 'Refined', # from analyzed tables = 'Tables', jobs = 'Jobs', psf = 'PSF', toppar = 'Toppar' ) )
class NmrPipeTable( NTdict ): """ NmrPipeTable class implemented as NTdict of NTdict's, i.e. element (row-0, INDEX) indexed as tab[0].INDEX or tab[0]['INDEX'] tab = NmrPipeTable() # Empty table tab = NmrPipeTable( 'tabFile' ) # table from tabFile METHODS: addColumn( name, fmt = "%s", default=None ): Add column 'name' to table; set values to 'default' hideColumn( *cNames ) Hide column(s) cNames showColumn( *cNames ) Show columns cNames addRow( **kwds ): Add row to table, optional kwds can be used to set values readFile( tabFile ): Read table from tabFile write( stream=sys.stdout ): Write table to stream writeFile( tabFile) : Open tabFile, write table and close tabFile """ def __init__( self, tabFile=None, **kwds ): NTdict.__init__( self, __CLASS__ = 'nmrPipeTab', **kwds ) self.setdefault('noneIndicator', '-') # character to identify the None value self.columnDefs = NTlist() # list of column definitions, implemented # as NTdict self.rows = NTlist() self.nrows = 0 self.remarks = NTlist() self.data = NTdict() self.tabFile = tabFile if tabFile: self.readFile( tabFile ) #end if #end def def format(self): # pylint: disable=W0221 return sprintf( '''=== NmrPipeTable "%s" === columns: %s nrows: %d''', self.tabFile, self.columnDefs.zap('name'), self.nrows ) def addRow( self, **kwds ): """ Add row to table, optional kwds can be used to set values """ row = NmrPipeTabRow( table=self, id=self.nrows, **kwds ) self[ self.nrows ] = row self.rows.append( row ) self.nrows += 1 return row #end def def addColumn( self, name, fmt = "%s", default=None ): """ Add column 'name' to table; set values to 'default' return columnDef, or None on error """ if name in self: nTerror('NmrPipeTable.addColumn: column "%s" already exists\n', name ) return None #end if col = NTdict( name=name, fmt=fmt, id=len(self.columnDefs), hide=False, __FORMAT__ = '%(name)s' ) self.columnDefs.append( col ) self[name] = col for row in self: row[name] = default #end for return col #end def def column( self, cName ): """Return list of values of column cName or None on error """ if cName not in self: return None col = NTlist() for row in self: col.append( row[cName] ) #end for return col #end def def hideColumn( self, *cNames ): """ Hide column(s) cNames """ for c in cNames: if not c in self: nTerror('NmrPipeTable.hideColumn: column "%s" not defined\n', c) else: self[c].hide = True #end if #end for #end def def showColumn( self, *cNames ): """ Show column(s) cNames """ for c in cNames: if not c in self: nTerror('NmrPipeTable.showColumn: column "%s" not defined\n', c) else: self[c].hide = False #end if #end for #end def def readFile( self, tabFile ): """ Read table from tabFile """ # nTmessage('Reading nmrPipe table file %s', tabFile ) #end if for line in AwkLike( tabFile, minNF = 1, commentString = '#' ): if ( line.dollar[1] == 'REMARK' and line.NF > 1 ): self.remarks.append( line.dollar[2:] ) elif ( line.dollar[1] == 'VARS' ): for v in line.dollar[2:]: self.addColumn( name=v ) #end for elif ( line.dollar[1] == 'FORMAT' ): i = 0 for f in line.dollar[2:]: self.columnDefs[i].fmt=f i += 1 #end for elif ( line.dollar[1] == 'DATA' and line.NF > 3 ): self.data[line.dollar[2]] = line.dollar[3:] elif ( line.NF == len( self.columnDefs ) ): row = self.addRow() for i in range( 0, line.NF ): col = self.columnDefs[i] if (line.dollar[i+1] == self.noneIndicator): row[col.name] = None else: # derive conversion function from fmt field if (col.fmt[-1:] in ['f','e','E','g','G']): func = float elif (col.fmt[-1:] in ['d','o','x','X']): func = int else: func = str #end if row[ col.name ] = func( line.dollar[i+1] ) #endif #end for else: pass #end if #end for self.tabFile = tabFile #end def 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 ) #end for #end def def writeFile( self, tabFile) : """ Write table to tabFile. Return True on error """ fp = open( tabFile, 'w' ) if fp is None: nTerror('NmrPipeTable.writeFile: error opening "%s"', tabFile) return True self.write( fp ) fp.close() # nTdebug('==> Written nmrPipe table file "%s"', tabFile ) return False #end def #iteration overrides: loop over row indices or rows def keys( self ): return range( 0, self.nrows ) #end def def __iter__( self ): for row in self.rows: yield row
class ResonanceList(NTlist, ProjectListMember): """ Contains ResonanceList meta data. NB the name is not necessarily unique within even the molecule. I.e. for PDB entry 1cjg and from NMR-STAR entry 4813 will get the resonance list name bmr4813_21.str twice from CCPN. """ SML_SAVE_ATTRIBUTE_LIST = 'name status bmrb_id vascoApplied vascoResults'.split() # Used in cing.core.sml.SMLNTListWithAttrHandler # use the same spelling through out. # NB the unusual init. Differs in that arguments aren't added to the list. def __init__(self, name, status = 'keep'): NTlist.__init__(self) ProjectListMember.__init__(self) # Initialized objectPath self.__CLASS__ = 'ResonanceList' self.name = name # Name of the list self.status = status # Status of the list; 'keep' indicates storage required self.currentId = 0 # Id for each element of list self._idDict = {} # dictionary to look up id in case the list is sorted differently self._byItem = None # if not None: list was sorted _byItem. self.vascoResults = NTdict() # See applyVascoChemicalShiftCorrections # NB match with VASCO_RESULTS_STR self.vascoApplied = False # VASCO_APPLIED_STR self.bmrb_id = None # Will be derived from name when calling rename. self.rogScore = ROGscore() self.SMLhandler.SML_SAVE_ATTRIBUTE_LIST = self.SML_SAVE_ATTRIBUTE_LIST self.rename(name) # Triggers setting self.bmrb_id #end def def decriticize(self): # nTdebug("Now in ResonanceList#decriticize") # Restraints lists self.rogScore.reset() for dr in self: dr.rogScore.reset() # end for #end def def hasVascoCorrectionsApplied(self): """A little bit more sophisticated routine to report no corrections of zero.""" return self.vascoApplied and self.hasVascoCorrectionsApplicable() #end def def hasVascoCorrectionsApplicable(self): """A little bit more sophisticated routine to report no corrections of zero.""" for atomId in self.vascoResults.keys(): ntvalue = self.vascoResults[ atomId ] rerefValue = ntvalue.value rerefError = ntvalue.error useCorrection = math.fabs(rerefValue) >= VASCO_CERTAINTY_FACTOR_CUTOFF * rerefError # sync with molecule code. if useCorrection: return True # end if # end for return False #end def def __str__(self): return io.sprintf('<%s "%s">' % (self.__CLASS__, self.name)) # return self.toVascoHtmlList() # modify when needed. def toVascoHtmlList(self, showHeader = False): 'If showIndividualApplication the output will be multiple lines.' s = '' if showHeader: s += '<h3>' s += self.name if self.vascoApplied: s += ' (applied)' else: s += ' (ignored)' s += '</h3>\n' s += '<ul>\n' for atomId in self.vascoResults.keys(): ntvalue = self.vascoResults[ atomId ] s += '<li>' atomClassId = getDeepByKeys(vascoMapAtomIdToHuman, atomId) if atomClassId == None: atomClassId = atomId s += '%s: %s' % ( atomClassId, ntvalue) rerefValue = ntvalue.value rerefError = ntvalue.error useCorrection = math.fabs(rerefValue) >= VASCO_CERTAINTY_FACTOR_CUTOFF * rerefError if useCorrection: s += ' applied' else: s += ' not applied' # end if s += '</li>\n' # end for s += '</ul>\n' return s #end def def __repr__(self): return self.__str__() #end def def rename(self, newName): 'Please use this rename instead of directly renaming so BMRB ID detection can kick in.' self.name = newName # Detect the id from strings like: bmr4020_21.str pattern = re.compile( '^.*(bmr\d+).*$' ) match = pattern.match( self.name ) if match: bmrb_idStr = match.group(1)[3:] self.bmrb_id = int(bmrb_idStr) if is_bmrb_code(self.bmrb_id): # nTdebug("-0- Autodetected BMRB ID %s from new name: %s" % (self.bmrb_id, self.name)) return self # end if nTerror("Did not detect valid BMRB ID from new name: %s." % self.name) return self # end if # nTdebug("-2- No BMRB ID was matched from new name: %s" % self.name) # return self.projectList.rename(self.name, newName) return self #end def def append(self, item): # pylint: disable=W0221 'Append' # if not hasattr(self, 'currentId'): # for deepcopy # self.currentId = 0 item.id = self.currentId item.parent = self # being able to go from restraint to restraint list is important. NTlist.append(self, item) self._idDict[item.id] = item self.currentId += 1 #end def def save(self, path = None): """ Create a SML file Return self or None on error Sort the list on id before saving, to preserve (original) order from save to restore. """ # sort the list on id number NTsort( self, byItem='id', inplace=True) if not path: path = self.objectPath if self.SMLhandler.toFile(self, path) != self: nTerror('%s.save: failed creating "%s"' % (self.__CLASS__, path)) return None #end if # restore original sorting if self._byItem: NTsort( self, byItem=self._byItem, inplace=True) nTdetail('==> Saved %s to "%s"', self, path) return self #end def def sort(self, byItem='id' ): "Sort the list byItem; store the byItem " NTsort( self, byItem, inplace=True) self._byItem = byItem return self #end def def getId(self, id): """Return restraint instance with id Returns None on error """ if not self._idDict.has_key(id): nTerror('ResonanceList.getId: invalid id (%d)', id) return None #end if return self._idDict[id] #end def def format(self, showAll = False): if not showAll: return rTxtList = [] for r in self: rTxtList.append( r.format() ) msg = '\n' msg += '\n'.join(rTxtList) return msg