def testNTtreeIndex(self): mol = Molecule('mol') mol.addChain('top') top = mol.allChains()[0] # Disable warnings temporarily v = cing.verbosity cing.verbosity = verbosityNothing for i in range( 1*10): res = top.addResidue( repr(random()),i ) for j in range( 5): atom = res.addAtom( repr(random()),j ) cing.verbosity = v resList = top.allResidues() middleValue = resList[len(resList)/2] for _i in range( 1*10): # _x = middleValue.sibling(0) # getting myself back should not take time. _x = middleValue.sibling(1) # this tends to be very expensive newMol = atom.getParent(level = 3) self.assertEqual(mol,newMol) newMol = atom.getMolecule() self.assertEqual(mol,newMol) res.removeAtom(atom.name) newMol = atom.getMolecule() self.assertEqual(newMol, mol)
def _test_HTMLfile(self): """ Create two html files (project and molecule) that have relative links to each other. Exercising the machinery in HTMLfile class. """ entryId = "test_HTMLfile" project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') project.appendMolecule(molecule) # initialize project html page # per item always set 2 top level attributes: project.htmlLocation = (project.path('index.html'), None) project.html = HTMLfile(project.htmlLocation[0], project, title='Project') nTdebug("project.htmlLocation[0]: %s" % project.htmlLocation[0]) #create new folders for Molecule/HTML htmlPath = project.htmlPath() if os.path.exists(htmlPath): removedir(htmlPath) os.makedirs(htmlPath) nTdebug("htmlPath: %s" % htmlPath) # initialize molecule html page for subdir in htmlDirectories.values(): project.mkdir(project.molecule.name, moleculeDirectories.html, subdir) # NB project.htmlPath is different from project.path molecule.htmlLocation = (project.htmlPath('indexMolecule.html'), None) nTdebug("molecule.htmlLocation[0]: %s" % molecule.htmlLocation[0]) molecule.html = HTMLfile(molecule.htmlLocation[0], project, title='Molecule ' + molecule.name) # nb: destination is a destination obj (eg molecule object) that is to # have a html attribute that points to an HTMLfile instance. # In the validate.py code, the source argument is the 'main' section in # project.html. JFD doesn't understand why. project.html.insertHtmlLinkInTag('li', section=project.html.main, source=project, destination=molecule, text='mol ref', id=None) # rerun for testing. _link = project.html.findHtmlLocation(project, molecule, id=None) # self.assertEquals('moleculeName/HTML/indexMolecule.html#_top', link) project.html.main('ul', openTag=False) for htmlObj in [project.html, molecule.html]: self.assertFalse(htmlObj.render())
def _test_HTMLfile(self): """ Create two html files (project and molecule) that have relative links to each other. Exercising the machinery in HTMLfile class. """ entryId = "test_HTMLfile" project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') project.appendMolecule(molecule) # initialize project html page # per item always set 2 top level attributes: project.htmlLocation = (project.path('index.html'), None) project.html = HTMLfile(project.htmlLocation[0], project, title = 'Project') nTdebug("project.htmlLocation[0]: %s" % project.htmlLocation[0]) #create new folders for Molecule/HTML htmlPath = project.htmlPath() if os.path.exists(htmlPath): removedir(htmlPath) os.makedirs(htmlPath) nTdebug("htmlPath: %s" % htmlPath) # initialize molecule html page for subdir in htmlDirectories.values(): project.mkdir(project.molecule.name, moleculeDirectories.html, subdir) # NB project.htmlPath is different from project.path molecule.htmlLocation = (project.htmlPath('indexMolecule.html'), None) nTdebug("molecule.htmlLocation[0]: %s" % molecule.htmlLocation[0]) molecule.html = HTMLfile(molecule.htmlLocation[0], project, title = 'Molecule ' + molecule.name) # nb: destination is a destination obj (eg molecule object) that is to # have a html attribute that points to an HTMLfile instance. # In the validate.py code, the source argument is the 'main' section in # project.html. JFD doesn't understand why. project.html.insertHtmlLinkInTag('li', section=project.html.main, source=project, destination=molecule, text='mol ref', id=None) # rerun for testing. _link = project.html.findHtmlLocation(project, molecule, id=None) # self.assertEquals('moleculeName/HTML/indexMolecule.html#_top', link) project.html.main('ul', openTag=False) for htmlObj in [ project.html, molecule.html ]: self.assertFalse(htmlObj.render())
def setupSimplestProject(self): entryId = 'setupSimplestProject' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') molecule.ensemble = Ensemble(molecule) # Needed for html. project.appendMolecule(molecule) # Needed for html. c = molecule.addChain('A') r1 = c.addResidue('ALA', 1, Nterminal = True) if r1: r1.addAllAtoms() molecule.updateAll() project.setupHtml() # Needed for creating the sub dirs. return project
def run(): relationName = 'nrgcing_ranges' fn = os.path.join( '/Users/jd/CMBI/Papers/CING/Data', relationName + '.csv') nentries = 0 nchains = 0 nsegments = 0 nresidues = 0 nresiduesMin = 999 nresiduesMinEntry = None r = getRelationFromCsvFile(fn) columnIdxId = 0 columnIdxRange = 1 for rowIdx in range(r.sizeRows()): if rowIdx >= 200000: print "Stopping early." break # end if nentries += 1 pdb_id = r.getValue( rowIdx, columnIdxId) rangeStr = r.getValue( rowIdx, columnIdxRange) chain_id = None # nTdebug( 'pdb_id: %s' % pdb_id) # nTdebug( 'rangeStr: %s' % rangeStr) startStopLoL = Molecule.ranges2StartStopLoLStatic(rangeStr) # nTdebug( 'startStopLoL: %s' % str(startStopLoL) ) nsegments += len(startStopLoL) for startStopList in startStopLoL: residueCount = startStopList[2] - startStopList[1] + 1 nresidues += residueCount if residueCount < nresiduesMin: nresiduesMin = residueCount nresiduesMinEntry = pdb_id # end for if residueCount < 5: nTdebug( 'residueCount for %s with range %s and segment %s is %s' % ( pdb_id, rangeStr, str(startStopList), residueCount)) # end for segmentChainId = startStopList[0] if segmentChainId != chain_id: chain_id = segmentChainId nchains += 1 # end if # end for # end for print "nentries: %s" % nentries print "nchains: %s" % nchains print "nsegments: %s" % nsegments print "nresidues: %s" % nresidues print "chainsPerEntry: %s" % (nsegments / float(nchains)) print "segmentsPerEntry: %s" % (nsegments / float(nentries)) print "segmentsPerChain: %s" % (nsegments / float(nchains)) print "residuesPerEntry: %s" % (nresidues / float(nentries)) print "residuesPerChain: %s" % (nresidues / float(nchains)) print "residuesPerSegments: %s" % (nresidues / float(nsegments)) print "residuesMin: %s" % nresiduesMin print "residuesMinEntry: %s" % nresiduesMinEntry
def testROGscore(self): entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') molecule.ensemble = Ensemble(molecule) # Needed for html. project.appendMolecule(molecule) # Needed for html. # Add some crud to prevent warnings/errors later. molecule.addChain('top') top = molecule.allChains()[0] # Disable warnings temporarily v = cing.verbosity cing.verbosity = verbosityNothing for i in range(1 * 10): res = top.addResidue(repr(random()), i) for j in range(5): _atom = res.addAtom(repr(random()), j) cing.verbosity = v molecule.updateAll() project.setupHtml() # Needed for creating the sub dirs. a = Atom(resName='ALA', atomName='HN') a.criticize() self.assertTrue(a) self.assertEquals(a.rogScore.colorLabel, COLOR_ORANGE) self.assertEquals(a.rogScore.colorCommentList[0][0], COLOR_ORANGE) self.assertEquals(a.rogScore.colorCommentList[0][1], ROGscore.ROG_COMMENT_NO_COOR) lotr_remark = 'One ring to rule them all' preserved_remark = 'Preserved' nowHasEffect_remark = 'Now has effect' nowHasEffectToo_remark = 'Now has effect too' # Next line will have to wipe out the orange comments. a.rogScore.setMaxColor(COLOR_RED, lotr_remark) a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffect_remark) a.rogScore.setMaxColor(COLOR_RED, preserved_remark) a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffectToo_remark) self.assertEquals(len(a.rogScore.colorCommentList), 5) self.assertEquals(a.rogScore.colorCommentList[0][1], ROGscore.ROG_COMMENT_NO_COOR) self.assertEquals(a.rogScore.colorCommentList[1][1], nowHasEffect_remark) myhtml = HTMLfile('testROGscore.html', project, 'A Test') myhtml.main("a main") a.rogScore.createHtmlForComments(myhtml.main) kw = {} a.rogScore.addHTMLkeywords(kw) myhtml.main("a", 'or by popup', **kw) myhtml.render()
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)
def initBMRB( project, bmrbFile, moleculeName = None ): """ Initialize from edited BMRB file Return molecule instance """ mol = Molecule( name=moleculeName ) project.appendMolecule( mol ) error = False record = None for record in AwkLike( bmrbFile, minNF = 8, commentString = '#' ): resName = record.dollar[3] resNum = record.int(2) atomName = record.dollar[4] # shift = record.float(6) # serror = record.float(7) # ambig = record.int(8) res = mol.addResidue( Chain.defaultChainId, resName, resNum, IUPAC ) if (not res): nTerror( 'Error initBMRB: invalid residue %s %s line %d (%s)\n', resName, atomName, record.NR, record.dollar[0] ) error = True #end if #end for error = error or (project.importBMRB( bmrbFile) == None) if error: nTmessage( '==> initBMRB: completed with error(s)' ) else: nTmessage( '==> initBMRB: successfully parsed %d lines from %s', record.NR, record.FILENAME ) #end if nTmessage("%s", mol.format() ) if error: return None return mol
def initBMRB(project, bmrbFile, moleculeName=None): """ Initialize from edited BMRB file Return molecule instance """ mol = Molecule(name=moleculeName) project.appendMolecule(mol) error = False record = None for record in AwkLike(bmrbFile, minNF=8, commentString='#'): resName = record.dollar[3] resNum = record.int(2) atomName = record.dollar[4] # shift = record.float(6) # serror = record.float(7) # ambig = record.int(8) res = mol.addResidue(Chain.defaultChainId, resName, resNum, IUPAC) if (not res): nTerror('Error initBMRB: invalid residue %s %s line %d (%s)\n', resName, atomName, record.NR, record.dollar[0]) error = True #end if #end for error = error or (project.importBMRB(bmrbFile) == None) if error: nTmessage('==> initBMRB: completed with error(s)') else: nTmessage('==> initBMRB: successfully parsed %d lines from %s', record.NR, record.FILENAME) #end if nTmessage("%s", mol.format()) if error: return None return mol
def initMolecule(self, moleculeName): """Initialize new Molecule instance from the tree. Return Molecule on None on error. """ mol = Molecule(name = moleculeName) # The self.tree contains a tree-like representation of the pdb-records for ch in self.tree: chain = mol.addChain(name = ch.name) for res in ch: # print '>', ch, res, res.skip, res.db if not res.skip and res.db != None: residue = chain.addResidue(res.db.name, res.resNum) if residue == None: nTerror("Not adding residue: %s" % res) continue residue.addAllAtoms() #end if #end for #end for # nTdebug('pdbParser.initMolecule: %s', mol) self.map2molecule(mol) return mol
def createSimpleFastProject(self): 'create simple fast project' entryId = 'test' self.project = Project( entryId ) self.project.removeFromDisk() self.project = Project.open( entryId, status='new' ) mol = Molecule('test') self.project.appendMolecule(mol) c = mol.addChain('A') self.r1 = c.addResidue('VAL', 1, Nterminal = True) self.r2 = c.addResidue('VAL', 2) self.r3 = c.addResidue('GLU', 3) self.r4 = c.addResidue('TYR', 4) self.r5 = c.addResidue('PHE', 5) self.r6 = c.addResidue('GLY', 6) self.r7 = c.addResidue('ARG', 7) self.r8 = c.addResidue('LEU', 8, Cterminal = True) for r in mol.allResidues(): r.addAllAtoms() mol.updateAll()
def initMolecule(self, moleculeName): """Initialize new Molecule instance from the tree. Return Molecule on None on error. """ mol = Molecule(name=moleculeName) # The self.tree contains a tree-like representation of the pdb-records for ch in self.tree: chain = mol.addChain(name=ch.name) for res in ch: # print '>', ch, res, res.skip, res.db if not res.skip and res.db != None: residue = chain.addResidue(res.db.name, res.resNum) if residue == None: nTerror("Not adding residue: %s" % res) continue residue.addAllAtoms() #end if #end for #end for # nTdebug('pdbParser.initMolecule: %s', mol) self.map2molecule(mol) return mol
def testROGscore(self): entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') molecule.ensemble = Ensemble(molecule) # Needed for html. project.appendMolecule(molecule) # Needed for html. # Add some crud to prevent warnings/errors later. molecule.addChain('top') top = molecule.allChains()[0] # Disable warnings temporarily v = cing.verbosity cing.verbosity = verbosityNothing for i in range( 1*10): res = top.addResidue( repr(random()),i ) for j in range( 5): _atom = res.addAtom( repr(random()),j ) cing.verbosity = v molecule.updateAll() project.setupHtml() # Needed for creating the sub dirs. a = Atom(resName='ALA', atomName='HN') a.criticize() self.assertTrue(a) self.assertEquals(a.rogScore.colorLabel, COLOR_ORANGE) self.assertEquals(a.rogScore.colorCommentList[0][0], COLOR_ORANGE) self.assertEquals(a.rogScore.colorCommentList[0][1], ROGscore.ROG_COMMENT_NO_COOR) lotr_remark = 'One ring to rule them all' preserved_remark = 'Preserved' nowHasEffect_remark = 'Now has effect' nowHasEffectToo_remark = 'Now has effect too' # Next line will have to wipe out the orange comments. a.rogScore.setMaxColor(COLOR_RED, lotr_remark) a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffect_remark ) a.rogScore.setMaxColor(COLOR_RED, preserved_remark) a.rogScore.setMaxColor(COLOR_ORANGE, nowHasEffectToo_remark) self.assertEquals(len(a.rogScore.colorCommentList), 5) self.assertEquals(a.rogScore.colorCommentList[0][1], ROGscore.ROG_COMMENT_NO_COOR) self.assertEquals(a.rogScore.colorCommentList[1][1], nowHasEffect_remark) myhtml = HTMLfile('testROGscore.html', project, 'A Test') myhtml.main("a main") a.rogScore.createHtmlForComments(myhtml.main) kw = {} a.rogScore.addHTMLkeywords(kw) myhtml.main("a", 'or by popup', **kw) myhtml.render()
def setupSimplestProject(self): entryId = 'setupSimplestProject' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') molecule.ensemble = Ensemble(molecule) # Needed for html. project.appendMolecule(molecule) # Needed for html. c = molecule.addChain('A') r1 = c.addResidue('ALA', 1, Nterminal=True) if r1: r1.addAllAtoms() molecule.updateAll() project.setupHtml() # Needed for creating the sub dirs. return project
def createSimpleFastProject(self): 'create simple fast project' entryId = 'test' self.project = Project(entryId) self.project.removeFromDisk() self.project = Project.open(entryId, status='new') mol = Molecule('test') self.project.appendMolecule(mol) c = mol.addChain('A') self.r1 = c.addResidue('VAL', 1, Nterminal=True) self.r2 = c.addResidue('VAL', 2) self.r3 = c.addResidue('GLU', 3) self.r4 = c.addResidue('TYR', 4) self.r5 = c.addResidue('PHE', 5) self.r6 = c.addResidue('GLY', 6) self.r7 = c.addResidue('ARG', 7) self.r8 = c.addResidue('LEU', 8, Cterminal=True) for r in mol.allResidues(): r.addAllAtoms() mol.updateAll()
def run(): relationName = 'nrgcing_ranges' fn = os.path.join('/Users/jd/CMBI/Papers/CING/Data', relationName + '.csv') nentries = 0 nchains = 0 nsegments = 0 nresidues = 0 nresiduesMin = 999 nresiduesMinEntry = None r = getRelationFromCsvFile(fn) columnIdxId = 0 columnIdxRange = 1 for rowIdx in range(r.sizeRows()): if rowIdx >= 200000: print "Stopping early." break # end if nentries += 1 pdb_id = r.getValue(rowIdx, columnIdxId) rangeStr = r.getValue(rowIdx, columnIdxRange) chain_id = None # nTdebug( 'pdb_id: %s' % pdb_id) # nTdebug( 'rangeStr: %s' % rangeStr) startStopLoL = Molecule.ranges2StartStopLoLStatic(rangeStr) # nTdebug( 'startStopLoL: %s' % str(startStopLoL) ) nsegments += len(startStopLoL) for startStopList in startStopLoL: residueCount = startStopList[2] - startStopList[1] + 1 nresidues += residueCount if residueCount < nresiduesMin: nresiduesMin = residueCount nresiduesMinEntry = pdb_id # end for if residueCount < 5: nTdebug( 'residueCount for %s with range %s and segment %s is %s' % (pdb_id, rangeStr, str(startStopList), residueCount)) # end for segmentChainId = startStopList[0] if segmentChainId != chain_id: chain_id = segmentChainId nchains += 1 # end if # end for # end for print "nentries: %s" % nentries print "nchains: %s" % nchains print "nsegments: %s" % nsegments print "nresidues: %s" % nresidues print "chainsPerEntry: %s" % (nsegments / float(nchains)) print "segmentsPerEntry: %s" % (nsegments / float(nentries)) print "segmentsPerChain: %s" % (nsegments / float(nchains)) print "residuesPerEntry: %s" % (nresidues / float(nentries)) print "residuesPerChain: %s" % (nresidues / float(nchains)) print "residuesPerSegments: %s" % (nresidues / float(nsegments)) print "residuesMin: %s" % nresiduesMin print "residuesMinEntry: %s" % nresiduesMinEntry