def test_AddResidue_Standard(self): entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') mol = Molecule('test') project.appendMolecule(mol) c = mol.addChain('A') r1 = c.addResidue('ALA', 1, Nterminal=True) if r1: r1.addAllAtoms() r2 = c.addResidue('VAL', 2) if r2: r2.addAllAtoms() r2 = c.addResidue('PHE', 3) if r2: r2.addAllAtoms() r2 = c.addResidue('ARG', 4) if r2: r2.addAllAtoms() r3 = c.addResidue('GLU', 5, Cterminal=True) if r3: r3.addAllAtoms() mol.updateAll() nTmessage(mol.format())
def test_AddResidue_Standard(self): entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') mol = Molecule('test') project.appendMolecule(mol) c = mol.addChain('A') r1 = c.addResidue('ALA', 1, Nterminal = True) if r1: r1.addAllAtoms() r2 = c.addResidue('VAL', 2) if r2: r2.addAllAtoms() r2 = c.addResidue('PHE', 3) if r2: r2.addAllAtoms() r2 = c.addResidue('ARG', 4) if r2: r2.addAllAtoms() r3 = c.addResidue('GLU', 5, Cterminal = True) if r3: r3.addAllAtoms() mol.updateAll() nTmessage( mol.format() )
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 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 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 test_GetNextAvailableChainId(self): entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') project.appendMolecule(molecule) # Needed for html. chainId = molecule.getNextAvailableChainId() self.assertEquals( chainId, Chain.defaultChainId) n = 26 * 2 + 10 + 1 # alpha numeric including an extra and lower cased. for _c in range(n): chainId = molecule.getNextAvailableChainId() self.assertTrue( molecule.addChain(chainId)) nTdebug("Added %d chains to: %s" % (n, molecule.format())) self.assertEqual( len(molecule.allChains()), n)
def test_GetNextAvailableChainId(self): entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') molecule = Molecule(name='moleculeName') project.appendMolecule(molecule) # Needed for html. chainId = molecule.getNextAvailableChainId() self.assertEquals(chainId, Chain.defaultChainId) n = 26 * 2 + 10 + 1 # alpha numeric including an extra and lower cased. for _c in range(n): chainId = molecule.getNextAvailableChainId() self.assertTrue(molecule.addChain(chainId)) nTdebug("Added %d chains to: %s" % (n, format(molecule))) self.assertEqual(len(molecule.allChains()), n)
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 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 test_RangeSelection(self): cing.verbosity = verbosityDebug entryId = 'testEntry' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') mol = Molecule('testMol') project.appendMolecule(mol) offset1 = -10 # h**o dimer chainList = ( 'A', 'B' ) sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' seqL = len(sequence) lastResidueI = seqL - 1 for cId in chainList: c = mol.addChain(cId) for i, rName in enumerate(sequence): rNumber = i+offset1 Nterminal = False # pylint: disable=C0103 Cterminal = False # pylint: disable=C0103 if i == 0: Nterminal = True # pylint: disable=C0103 if i == lastResidueI: Cterminal = True # pylint: disable=C0103 r = c.addResidue(rName, rNumber, Nterminal = Nterminal, Cterminal = Cterminal) if r: # nTdebug("Adding atoms to residue: %s" % r) r.addAllAtoms() for atom in r.allAtoms(): atom.addCoordinate(0.0, 1.0, 2.0, 40.0) # else: # nTdebug("Skipping atoms for residue: %s" % r) # end if # end for # end for chain # another h**o dimer with renumbering. chainList = ( 'C', 'D' ) offset2 = 100 for cId in chainList: c = mol.addChain(cId) for i, rName in enumerate(sequence): rNumber = i+offset2 Nterminal = False # pylint: disable=C0103 Cterminal = False # pylint: disable=C0103 if i == 0: Nterminal = True # pylint: disable=C0103 if i == lastResidueI: Cterminal = True # pylint: disable=C0103 r = c.addResidue(rName, rNumber, Nterminal = Nterminal, Cterminal = Cterminal) if r: # nTdebug("Adding atoms to residue: %s" % r) r.addAllAtoms() # else: # nTdebug("Skipping atoms for residue: %s" % r) # end if # end for # end for chain nTdebug("Done creating simple fake molecule") self.assertFalse( mol.updateAll() ) nTmessage( mol.format() ) # Nada selectedResidueList = mol.ranges2list('') self.assertEquals( len(selectedResidueList), 2*len(chainList)*seqL) # Single residue selectedResidueList = mol.ranges2list('A.'+str(offset1)) self.assertEquals( len(selectedResidueList), 1) nTdebug("Selected residues: %s" % str(selectedResidueList)) # Two residues selectedResidueList = mol.ranges2list(str(offset1)) self.assertEquals( len(selectedResidueList), 2) nTdebug("Selected residues: %s" % str(selectedResidueList)) # Four residues in ranges selectedResidueList = mol.ranges2list('1-2') self.assertEquals( len(selectedResidueList), 4) nTdebug("Selected residues: %s" % str(selectedResidueList)) # Eight residues in negative crossing ranges selectedResidueList = mol.ranges2list('-1-2') self.assertEquals( len(selectedResidueList), 8) nTdebug("Selected residues: %s" % str(selectedResidueList)) selectedResidueList = mol.ranges2list('A.-5--2') self.assertEquals( len(selectedResidueList), 4) nTdebug("Selected residues: %s" % str(selectedResidueList)) selectedResidueList = mol.ranges2list('-999-999') nTdebug("Selected residues: %s" % str(selectedResidueList)) self.assertEquals( len(selectedResidueList), 2*len(chainList)*seqL) residueList2StartStopList = mol.ranges2StartStopList('-999-999') nTdebug('residueList2StartStopList: %s' % str(residueList2StartStopList)) self.assertEquals( len(residueList2StartStopList), 8 ) # """ # Possible 5 situations: # a # 1 # positive int # -a # 2 # single int # -a-b # 3 # # -a--b # 4 # # a-b # 5 # most common # """ inputList = """ A.1 A.1-3 A.-2--1 A.-2-1 A.-3 """.split() for i, ranges in enumerate(inputList): nTdebug("test_RangeSelection: %d %s" % (i, ranges)) residueList = mol.setResiduesFromRanges(ranges) # nTdebug('residueList: [%s]' % residueList) rangesRecycled = mol.residueList2Ranges(residueList) # nTdebug('rangesRecycled: [%s]' % rangesRecycled) self.assertEquals( ranges, rangesRecycled ) res1, res2 = mol.ranges2list('A.1,A.3') self.assertEquals( 2, residueNumberDifference(res1, res2)) res3, res4 = mol.ranges2list('A.5,A.8') self.assertEquals( 3, residueNumberDifference(res3, res4)) res5, res6 = mol.ranges2list('B.9,B.10') self.assertEquals( 1, residueNumberDifference(res5, res6)) ranges = mol.startStopList2ranges([res1, res2]) self.assertEquals( 'A.1-3', ranges) ranges = mol.startStopList2ranges([res1, res2, res3, res4]) self.assertEquals( 'A.1-3,A.5-8', ranges) ranges = mol.startStopList2ranges([res1, res2, res5, res6]) self.assertEquals( 'A.1-3,B.9-10', ranges) # Check other routine chain0 = mol.allChains()[0] chain1 = mol.allChains()[1] atomList = chain0.getRepresentingAtomListsPerResidue(chain1) nTdebug("atomList: %s" % str(atomList)) self.assertEquals( len(atomList[0]), 5)
def test_GetMolTypeCountList(self): cing.verbosity = verbosityDebug entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') mol = Molecule('test') project.appendMolecule(mol) c = mol.addChain('A') c.addResidue('ALA', 1, Nterminal = True) c.addResidue('VAL', 2) c.addResidue('PHE', 3) c.addResidue('ARG', 4) c.addResidue('GLU', 5, Cterminal = True) c = mol.addChain('B') c.addResidue('DG', 1, Nterminal = True) c.addResidue('DA', 2) c.addResidue('DT', 3) c.addResidue('DC', 4, Cterminal = True) c = mol.addChain('C') c.addResidue('RGUA', 1, convention=INTERNAL_0, Nterminal = True) c.addResidue('RADE', 2, convention=INTERNAL_0, ) c.addResidue('URA', 3, convention=INTERNAL_0, ) # not RTHY normally of course. c.addResidue('RTHY', 4, convention=INTERNAL_0, ) c.addResidue('RCYT', 5, convention=INTERNAL_0, Cterminal = True) c = mol.addChain('D') for i in range(1,11): c.addResidue('HOH', i ) # end for c = mol.addChain('E') # Unknown residue to CING c.addResidue('ACE', 1 ) c = mol.addChain('F') # Ions are also other c.addResidue('CA2P', 1 ) for residue in mol.allResidues(): residue.addAllAtoms() # end for mol.updateAll() nTmessage( mol.format() ) for c in mol.allChains(): nTmessage( c.format() ) nTmessage( "idxMolType: %s" % (c.getIdxMolType())) # end for nTmessage("Count the molecule types") molTypeCountList = mol.getMolTypeCountList() p_protein_count = molTypeCountList[ mapMoltypeToInt[PROTEIN_STR] ] p_dna_count = molTypeCountList[ mapMoltypeToInt[DNA_STR] ] p_rna_count = molTypeCountList[ mapMoltypeToInt[RNA_STR] ] p_water_count = molTypeCountList[ mapMoltypeToInt[WATER_STR] ] p_other_count = molTypeCountList[ mapMoltypeToInt[OTHER_STR] ] self.assertEqual(1, p_protein_count) self.assertEqual(1, p_dna_count ) self.assertEqual(1, p_rna_count ) self.assertEqual(1, p_water_count) self.assertEqual(2, p_other_count) nTmessage("Count the residue types") molTypeResidueCountList = mol.getMolTypeResidueCountList() p_res_protein_count = molTypeResidueCountList[ mapMoltypeToInt[PROTEIN_STR] ] p_res_dna_count = molTypeResidueCountList[ mapMoltypeToInt[DNA_STR] ] p_res_rna_count = molTypeResidueCountList[ mapMoltypeToInt[RNA_STR] ] p_res_water_count = molTypeResidueCountList[ mapMoltypeToInt[WATER_STR] ] p_res_other_count = molTypeResidueCountList[ mapMoltypeToInt[OTHER_STR] ] self.assertEqual(5, p_res_protein_count) self.assertEqual(4, p_res_dna_count ) self.assertEqual(5, p_res_rna_count ) self.assertEqual(10, p_res_water_count) self.assertEqual(2, p_res_other_count) nTmessage("Select a list of residues.") inputResList = (('A', 5),('B', 2),('A', 6),('X', 1)) # The last 2 are non-existing residues # should give two warnings for a non-existing residue resList = project.decodeResidueList( inputResList ) self.assertEqual(2, len(resList) )
def test_RangeSelection(self): cing.verbosity = verbosityDebug entryId = 'testEntry' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') mol = Molecule('testMol') project.appendMolecule(mol) offset1 = -10 # h**o dimer chainList = ('A', 'B') sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' seqL = len(sequence) lastResidueI = seqL - 1 for cId in chainList: c = mol.addChain(cId) for i, rName in enumerate(sequence): rNumber = i + offset1 Nterminal = False # pylint: disable=C0103 Cterminal = False # pylint: disable=C0103 if i == 0: Nterminal = True # pylint: disable=C0103 if i == lastResidueI: Cterminal = True # pylint: disable=C0103 r = c.addResidue(rName, rNumber, Nterminal=Nterminal, Cterminal=Cterminal) if r: # nTdebug("Adding atoms to residue: %s" % r) r.addAllAtoms() for atom in r.allAtoms(): atom.addCoordinate(0.0, 1.0, 2.0, 40.0) # else: # nTdebug("Skipping atoms for residue: %s" % r) # end if # end for # end for chain # another h**o dimer with renumbering. chainList = ('C', 'D') offset2 = 100 for cId in chainList: c = mol.addChain(cId) for i, rName in enumerate(sequence): rNumber = i + offset2 Nterminal = False # pylint: disable=C0103 Cterminal = False # pylint: disable=C0103 if i == 0: Nterminal = True # pylint: disable=C0103 if i == lastResidueI: Cterminal = True # pylint: disable=C0103 r = c.addResidue(rName, rNumber, Nterminal=Nterminal, Cterminal=Cterminal) if r: # nTdebug("Adding atoms to residue: %s" % r) r.addAllAtoms() # else: # nTdebug("Skipping atoms for residue: %s" % r) # end if # end for # end for chain nTdebug("Done creating simple fake molecule") self.assertFalse(mol.updateAll()) nTmessage(mol.format()) # Nada selectedResidueList = mol.ranges2list('') self.assertEquals(len(selectedResidueList), 2 * len(chainList) * seqL) # Single residue selectedResidueList = mol.ranges2list('A.' + str(offset1)) self.assertEquals(len(selectedResidueList), 1) nTdebug("Selected residues: %s" % str(selectedResidueList)) # Two residues selectedResidueList = mol.ranges2list(str(offset1)) self.assertEquals(len(selectedResidueList), 2) nTdebug("Selected residues: %s" % str(selectedResidueList)) # Four residues in ranges selectedResidueList = mol.ranges2list('1-2') self.assertEquals(len(selectedResidueList), 4) nTdebug("Selected residues: %s" % str(selectedResidueList)) # Eight residues in negative crossing ranges selectedResidueList = mol.ranges2list('-1-2') self.assertEquals(len(selectedResidueList), 8) nTdebug("Selected residues: %s" % str(selectedResidueList)) selectedResidueList = mol.ranges2list('A.-5--2') self.assertEquals(len(selectedResidueList), 4) nTdebug("Selected residues: %s" % str(selectedResidueList)) selectedResidueList = mol.ranges2list('-999-999') nTdebug("Selected residues: %s" % str(selectedResidueList)) self.assertEquals(len(selectedResidueList), 2 * len(chainList) * seqL) residueList2StartStopList = mol.ranges2StartStopList('-999-999') nTdebug('residueList2StartStopList: %s' % str(residueList2StartStopList)) self.assertEquals(len(residueList2StartStopList), 8) # """ # Possible 5 situations: # a # 1 # positive int # -a # 2 # single int # -a-b # 3 # # -a--b # 4 # # a-b # 5 # most common # """ inputList = """ A.1 A.1-3 A.-2--1 A.-2-1 A.-3 """.split() for i, ranges in enumerate(inputList): nTdebug("test_RangeSelection: %d %s" % (i, ranges)) residueList = mol.setResiduesFromRanges(ranges) # nTdebug('residueList: [%s]' % residueList) rangesRecycled = mol.residueList2Ranges(residueList) # nTdebug('rangesRecycled: [%s]' % rangesRecycled) self.assertEquals(ranges, rangesRecycled) res1, res2 = mol.ranges2list('A.1,A.3') self.assertEquals(2, residueNumberDifference(res1, res2)) res3, res4 = mol.ranges2list('A.5,A.8') self.assertEquals(3, residueNumberDifference(res3, res4)) res5, res6 = mol.ranges2list('B.9,B.10') self.assertEquals(1, residueNumberDifference(res5, res6)) ranges = mol.startStopList2ranges([res1, res2]) self.assertEquals('A.1-3', ranges) ranges = mol.startStopList2ranges([res1, res2, res3, res4]) self.assertEquals('A.1-3,A.5-8', ranges) ranges = mol.startStopList2ranges([res1, res2, res5, res6]) self.assertEquals('A.1-3,B.9-10', ranges) # Check other routine chain0 = mol.allChains()[0] chain1 = mol.allChains()[1] atomList = chain0.getRepresentingAtomListsPerResidue(chain1) nTdebug("atomList: %s" % str(atomList)) self.assertEquals(len(atomList[0]), 5)
def test_GetMolTypeCountList(self): cing.verbosity = verbosityDebug entryId = 'test' project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') mol = Molecule('test') project.appendMolecule(mol) c = mol.addChain('A') c.addResidue('ALA', 1, Nterminal=True) c.addResidue('VAL', 2) c.addResidue('PHE', 3) c.addResidue('ARG', 4) c.addResidue('GLU', 5, Cterminal=True) c = mol.addChain('B') c.addResidue('DG', 1, Nterminal=True) c.addResidue('DA', 2) c.addResidue('DT', 3) c.addResidue('DC', 4, Cterminal=True) c = mol.addChain('C') c.addResidue('RGUA', 1, convention=INTERNAL_0, Nterminal=True) c.addResidue( 'RADE', 2, convention=INTERNAL_0, ) c.addResidue( 'URA', 3, convention=INTERNAL_0, ) # not RTHY normally of course. c.addResidue( 'RTHY', 4, convention=INTERNAL_0, ) c.addResidue('RCYT', 5, convention=INTERNAL_0, Cterminal=True) c = mol.addChain('D') for i in range(1, 11): c.addResidue('HOH', i) # end for c = mol.addChain('E') # Unknown residue to CING c.addResidue('ACE', 1) c = mol.addChain('F') # Ions are also other c.addResidue('CA2P', 1) for residue in mol.allResidues(): residue.addAllAtoms() # end for mol.updateAll() nTmessage(mol.format()) for c in mol.allChains(): nTmessage(c.format()) nTmessage("idxMolType: %s" % (c.getIdxMolType())) # end for nTmessage("Count the molecule types") molTypeCountList = mol.getMolTypeCountList() p_protein_count = molTypeCountList[mapMoltypeToInt[PROTEIN_STR]] p_dna_count = molTypeCountList[mapMoltypeToInt[DNA_STR]] p_rna_count = molTypeCountList[mapMoltypeToInt[RNA_STR]] p_water_count = molTypeCountList[mapMoltypeToInt[WATER_STR]] p_other_count = molTypeCountList[mapMoltypeToInt[OTHER_STR]] self.assertEqual(1, p_protein_count) self.assertEqual(1, p_dna_count) self.assertEqual(1, p_rna_count) self.assertEqual(1, p_water_count) self.assertEqual(2, p_other_count) nTmessage("Count the residue types") molTypeResidueCountList = mol.getMolTypeResidueCountList() p_res_protein_count = molTypeResidueCountList[ mapMoltypeToInt[PROTEIN_STR]] p_res_dna_count = molTypeResidueCountList[mapMoltypeToInt[DNA_STR]] p_res_rna_count = molTypeResidueCountList[mapMoltypeToInt[RNA_STR]] p_res_water_count = molTypeResidueCountList[mapMoltypeToInt[WATER_STR]] p_res_other_count = molTypeResidueCountList[mapMoltypeToInt[OTHER_STR]] self.assertEqual(5, p_res_protein_count) self.assertEqual(4, p_res_dna_count) self.assertEqual(5, p_res_rna_count) self.assertEqual(10, p_res_water_count) self.assertEqual(2, p_res_other_count) nTmessage("Select a list of residues.") inputResList = (('A', 5), ('B', 2), ('A', 6), ('X', 1) ) # The last 2 are non-existing residues # should give two warnings for a non-existing residue resList = project.decodeResidueList(inputResList) self.assertEqual(2, len(resList))
class AllChecks(TestCase): 'Test case' cingDirTmpTest = os.path.join( cingDirTmp, 'test_classes2' ) mkdirs( cingDirTmpTest ) os.chdir(cingDirTmpTest) def __init__(self, *args, **kwds): TestCase.__init__(self, *args, **kwds) self.project = None self.r1 = None self.r2 = None self.r3 = None self.r4 = None self.r5 = None self.r6 = None self.r7 = None self.r8 = None 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() # nTmessage( mol.format() ) def test_simplifyForFcFeature(self): 'test simplify Specifically For Fc Feature' self.createSimpleFastProject() _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist() r1 = self.r1 r2 = self.r2 # r3 = self.r3 atomPairs.append((r1.MG1, r2.MG1)) atomPairs.append((r1.MG2, r2.MG1)) atomPairs.append((r1.MG1, r2.MG2)) atomPairs.append((r1.MG2, r2.MG2)) # atomPairs.append((r2.HN, r2.MG1)) # atomPairs.append((r2.HN, r2.MG2)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) if distanceRestraint.isValid: _distanceRestraintList.append(distanceRestraint) else: nTerror('Failed to initialize DR with %s' % atomPairs) # nTdebug("dr before: %s" % formatall(distanceRestraint)) # Takes 4 simplification iterations. self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 1: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 2: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 3: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("dr after 4: %s" % formatall(distanceRestraint)) # don't print as it contains error token. _x = "dr after 4: %s" % formatall(distanceRestraint) def test_simplifyForFcFeature_2(self): 'test simplify Specifically For Fc Feature 2' # disfunctional as of yet self.createSimpleFastProject() _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist() # r1 = self.r1 r2 = self.r2 # r3 = self.r3 atomPairs.append((r2.HN, r2.MG1)) atomPairs.append((r2.MG2, r2.HN)) # atomPairs.append((r2.HN, r2.MG1)) # atomPairs.append((r2.HN, r2.MG2)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) _distanceRestraintList.append(distanceRestraint) # nTdebug("dr before: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 1: %s" % formatall(distanceRestraint)) def test_CombinationToPseudo(self): ' test combination to Pseudo' self.createSimpleFastProject() r1 = self.r1 r2 = self.r2 r3 = self.r3 atomLoL = [[r2.HN], [r3.HB2, r3.HB3], [r3.HB2], [r1.HG11, r1.HG12, r1.HG13], [r1.HG12, r1.HG11, r1.HG13], [r1.HG11, r1.HG12, r1.HG13, r1.HG21, r1.HG22, r1.HG23], # unrepresented by below method. ] pseudoListResultExpected = [ None, r3.QB, None, r1.MG1, # TODO: update these to MD1 when CING has IUPAC internally. r1.MG1, None, ] i = -1 for atomList in atomLoL: i += 1 firstAtom = atomList[0] self.assertEqual( firstAtom.getRepresentativePseudoAtom(atomList), pseudoListResultExpected[i]) def test_CombinationToPseudoDouble(self): ' test combination to Pseudo Double' # 'Simulate 1a24 1254.00 A 3 TYR QD A 8 GLN QG' self.createSimpleFastProject() e = self.r3 # GLN y = self.r4 # TYR _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist((e.HG2, y.HB2), (e.HG3, y.HB2), (e.HG2, y.HB3), (e.HG3, y.HB3)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_CombiToPseudoDouble_2(self): 'test_CombiToPseudoDouble_2' # 'Simulate 1a24 1254.00 A 3 TYR QD A 8 GLN QB' self.createSimpleFastProject() # e = self.r3 # GLN y = self.r4 # TYR _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist((y.HE1, y.HB2), (y.HE2, y.HB2), (y.HE1, y.HB3), (y.HE2, y.HB3)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_CombiToPseudoQuadruple(self): ' test combination to Pseudo 4 some.' # 'Simulate 1a24 1254.00 A 3 TYR QR A 8 GLN QB' self.createSimpleFastProject() y = self.r5 # PHE _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist((y.QE, y.H), (y.QD, y.H) ) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_Simplify(self): 'test Simplify' self.createSimpleFastProject() y = self.r5 # PHE _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist((y.QE, y.H), (y.QE, y.H) ) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_Simplify2(self): 'test Simplify2' _help = """ For 1a24 783.00 A 20 PRO QB A 23 LEU MD1 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 783.01 A 20 PRO QB A 23 LEU QD 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 """ self.createSimpleFastProject() y = self.r5 # PHE _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist((y.QE, y.H), (y.QE, y.H) ) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_Simplify3(self): 'test simplify 3' _help = """ For 1a24 783.00 A 20 PRO QB A 23 LEU MD1 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 783.01 A 20 PRO QB A 23 LEU QD 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 """ self.createSimpleFastProject() y = self.r8 # LEU _distanceRestraintList = self.project.distances.new(DR_LEVEL, status = 'keep') atomPairs = NTlist((y.QD, y.H), (y.MD1, y.H) ) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.removeDuplicateAtomPairs2(), DistanceRestraint.STATUS_REMOVED_DUPLICATE)
class AllChecks(TestCase): 'Test case' cingDirTmpTest = os.path.join(cingDirTmp, 'test_classes2') mkdirs(cingDirTmpTest) os.chdir(cingDirTmpTest) def __init__(self, *args, **kwds): TestCase.__init__(self, *args, **kwds) self.project = None self.r1 = None self.r2 = None self.r3 = None self.r4 = None self.r5 = None self.r6 = None self.r7 = None self.r8 = None 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() # nTmessage( mol.format() ) def test_simplifyForFcFeature(self): 'test simplify Specifically For Fc Feature' self.createSimpleFastProject() _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist() r1 = self.r1 r2 = self.r2 # r3 = self.r3 atomPairs.append((r1.MG1, r2.MG1)) atomPairs.append((r1.MG2, r2.MG1)) atomPairs.append((r1.MG1, r2.MG2)) atomPairs.append((r1.MG2, r2.MG2)) # atomPairs.append((r2.HN, r2.MG1)) # atomPairs.append((r2.HN, r2.MG2)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) if distanceRestraint.isValid: _distanceRestraintList.append(distanceRestraint) else: nTerror('Failed to initialize DR with %s' % atomPairs) # nTdebug("dr before: %s" % formatall(distanceRestraint)) # Takes 4 simplification iterations. self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 1: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 2: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 3: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplifyForFc(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("dr after 4: %s" % formatall(distanceRestraint)) # don't print as it contains error token. _x = "dr after 4: %s" % formatall(distanceRestraint) def test_simplifyForFcFeature_2(self): 'test simplify Specifically For Fc Feature 2' # disfunctional as of yet self.createSimpleFastProject() _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist() # r1 = self.r1 r2 = self.r2 # r3 = self.r3 atomPairs.append((r2.HN, r2.MG1)) atomPairs.append((r2.MG2, r2.HN)) # atomPairs.append((r2.HN, r2.MG1)) # atomPairs.append((r2.HN, r2.MG2)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) _distanceRestraintList.append(distanceRestraint) # nTdebug("dr before: %s" % formatall(distanceRestraint)) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("dr after 1: %s" % formatall(distanceRestraint)) def test_CombinationToPseudo(self): ' test combination to Pseudo' self.createSimpleFastProject() r1 = self.r1 r2 = self.r2 r3 = self.r3 atomLoL = [ [r2.HN], [r3.HB2, r3.HB3], [r3.HB2], [r1.HG11, r1.HG12, r1.HG13], [r1.HG12, r1.HG11, r1.HG13], [r1.HG11, r1.HG12, r1.HG13, r1.HG21, r1.HG22, r1.HG23], # unrepresented by below method. ] pseudoListResultExpected = [ None, r3.QB, None, r1. MG1, # TODO: update these to MD1 when CING has IUPAC internally. r1.MG1, None, ] i = -1 for atomList in atomLoL: i += 1 firstAtom = atomList[0] self.assertEqual(firstAtom.getRepresentativePseudoAtom(atomList), pseudoListResultExpected[i]) def test_CombinationToPseudoDouble(self): ' test combination to Pseudo Double' # 'Simulate 1a24 1254.00 A 3 TYR QD A 8 GLN QG' self.createSimpleFastProject() e = self.r3 # GLN y = self.r4 # TYR _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist((e.HG2, y.HB2), (e.HG3, y.HB2), (e.HG2, y.HB3), (e.HG3, y.HB3)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_CombiToPseudoDouble_2(self): 'test_CombiToPseudoDouble_2' # 'Simulate 1a24 1254.00 A 3 TYR QD A 8 GLN QB' self.createSimpleFastProject() # e = self.r3 # GLN y = self.r4 # TYR _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist((y.HE1, y.HB2), (y.HE2, y.HB2), (y.HE1, y.HB3), (y.HE2, y.HB3)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_CombiToPseudoQuadruple(self): ' test combination to Pseudo 4 some.' # 'Simulate 1a24 1254.00 A 3 TYR QR A 8 GLN QB' self.createSimpleFastProject() y = self.r5 # PHE _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist((y.QE, y.H), (y.QD, y.H)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_Simplify(self): 'test Simplify' self.createSimpleFastProject() y = self.r5 # PHE _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist((y.QE, y.H), (y.QE, y.H)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_Simplify2(self): 'test Simplify2' _help = """ For 1a24 783.00 A 20 PRO QB A 23 LEU MD1 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 783.01 A 20 PRO QB A 23 LEU QD 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 """ self.createSimpleFastProject() y = self.r5 # PHE _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist((y.QE, y.H), (y.QE, y.H)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.simplify(), DistanceRestraint.STATUS_NOT_SIMPLIFIED) # nTdebug("after: %r" % distanceRestraint ) def test_Simplify3(self): 'test simplify 3' _help = """ For 1a24 783.00 A 20 PRO QB A 23 LEU MD1 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 783.01 A 20 PRO QB A 23 LEU QD 3.20 7.90 2.96 0.56 2.56 3.35 0.32 0.45 0.64 0 0 0 """ self.createSimpleFastProject() y = self.r8 # LEU _distanceRestraintList = self.project.distances.new(DR_LEVEL, status='keep') atomPairs = NTlist((y.QD, y.H), (y.MD1, y.H)) distanceRestraint = DistanceRestraint(atomPairs, 0.0, 5.0) # nTdebug("before: %r" % distanceRestraint ) self.assertEqual(distanceRestraint.removeDuplicateAtomPairs2(), DistanceRestraint.STATUS_REMOVED_DUPLICATE)