def test_sequenceRepeats(self): """match2seq sequence repeat test""" seq1 = 'ABCDEFG~~~~~~~~~~~~~~~' seq2 = '~~~~~' mask1, mask2 = compareSequences( seq1, seq2 ) self.assert_( N.all( mask1 == N.zeros( len(seq1 ) )) ) self.assert_( N.all( mask2 == N.zeros( len(seq2 ) )) )
def test_sequenceRepeats(self): """match2seq sequence repeat test""" seq1 = 'ABCDEFG~~~~~~~~~~~~~~~' seq2 = '~~~~~' mask1, mask2 = compareSequences(seq1, seq2) self.assert_(N.all(mask1 == N.zeros(len(seq1)))) self.assert_(N.all(mask2 == N.zeros(len(seq2))))
def test_model(self): """PDBDope test final model""" from Biskit import PDBModel if self.local: print '\nData added to info record of model (key -- value):' for k in self.d.m.info.keys(): print '%s -- %s'%(k, self.d.m.info[k]) print '\nAdded atom profiles:' print self.M.atoms print '\nAdded residue profiles:' print self.M.residues ## check that nothing has changed print '\nChecking that models are unchanged by doping ...' m_ref = PDBModel( self.f ) m_ref = m_ref.compress( m_ref.maskProtein() ) for k in m_ref.atoms.keys(): #ref = [ m_ref.atoms[i][k] for i in m_ref.atomRange() ] #mod = [ self.M.atoms[i][k] for i in self.M.atomRange() ] self.assert_( N.all( m_ref[k] == self.M[k]) ) ## display in Pymol if self.local: print "Starting PyMol..." from Biskit.Pymoler import Pymoler pm = Pymoler() pm.addPdb( self.M, 'm' ) pm.colorAtoms( 'm', N.clip(self.M.profile('relAS'), 0.0, 100.0) ) pm.show()
def permutInverse(n): """Returns inverse permutation given integers in range(len(n)), such that permitInverse(permutInverse(range(4)))==range(4). """ n = Numeric.asarray(n) pInv = Numeric.argsort(n) assert Numeric.all(Numeric.equal(n, Numeric.argsort(pInv))), "Inverse not successful; input should be permutation of range(len(input))." return pInv
def __collectFrames( self, pdbs, castAll=0 ): """ Read coordinates from list of pdb files. @param pdbs: list of file names @type pdbs: [str] @param castAll: analyze atom content of each frame for casting (default: 0) @type castAll: 0|1 @return: frames x (N x 3) Numpy array (of float) @rtype: array """ frameList = [] i = 0 atomCast = None if self.verbose: T.errWrite('reading %i pdbs...' % len(pdbs) ) refNames = self.ref.atomNames() ## cache for atom checking for f in pdbs: ## Load m = PDBModel(f) ## compare atom order & content of first frame to reference pdb if castAll or i==0: atomCast, castRef = m.compareAtoms( self.ref ) if castRef != range( len( self.ref ) ): ## we can take away atoms from each frame but not from ref raise TrajError("Reference PDB doesn't match %s." %m.fileName) if N.all( atomCast == range( len( m ) ) ): atomCast = None ## no casting necessary else: if self.verbose: T.errWrite(' casting ') ## assert that frame fits reference if atomCast: m = m.take( atomCast ) ## additional check on each 100st frame if i%100 == 0 and m.atomNames() <> refNames: raise TrajError("%s doesn't match reference pdb."%m.fileName ) frameList.append( m.xyz ) i += 1 if i%10 == 0 and self.verbose: T.errWrite('#') if self.verbose: T.errWrite( 'done\n' ) ## convert to 3-D Numpy Array return N.array(frameList).astype(N.Float32)
def __collectFrames(self, pdbs, castAll=0): """ Read coordinates from list of pdb files. @param pdbs: list of file names @type pdbs: [str] @param castAll: analyze atom content of each frame for casting (default: 0) @type castAll: 0|1 @return: frames x (N x 3) Numpy array (of float) @rtype: array """ frameList = [] i = 0 atomCast = None if self.verbose: T.errWrite('reading %i pdbs...' % len(pdbs)) refNames = self.ref.atomNames() ## cache for atom checking for f in pdbs: ## Load m = PDBModel(f) ## compare atom order & content of first frame to reference pdb if castAll or i == 0: atomCast, castRef = m.compareAtoms(self.ref) if castRef != range(len(self.ref)): ## we can take away atoms from each frame but not from ref raise TrajError("Reference PDB doesn't match %s." % m.fileName) if N.all(atomCast == range(len(m))): atomCast = None ## no casting necessary else: if self.verbose: T.errWrite(' casting ') ## assert that frame fits reference if atomCast: m = m.take(atomCast) ## additional check on each 100st frame if i % 100 == 0 and m.atomNames() <> refNames: raise TrajError("%s doesn't match reference pdb." % m.fileName) frameList.append(m.xyz) i += 1 if i % 10 == 0 and self.verbose: T.errWrite('#') if self.verbose: T.errWrite('done\n') ## convert to 3-D Numpy Array return N.array(frameList).astype(N.Float32)
def test_match2seq(self): """match2seq test""" ## Reading pdb files lig_traj = T.load(T.testRoot() + '/lig_pcr_00/traj.dat')[:2] m = [m.compress(m.maskProtein()) for m in lig_traj] ## make the models different m[1].removeRes(['ALA']) mask1, mask2 = compareModels(m[0], m[1]) if self.local: print 'Reading and comparing two models' print '\nResidue masks to make the two maodels equal' print 'mask1\n', mask1 print 'mask2\n', mask2 globals().update(locals()) self.assert_(N.all(mask1 == self.EXPECT[0])) self.assert_(N.all(mask2 == self.EXPECT[1]))
def test_match2seq(self): """match2seq test""" ## Reading pdb files lig_traj = T.load( T.testRoot() + '/lig_pcr_00/traj.dat' )[:2] m = [ m.compress( m.maskProtein() ) for m in lig_traj ] ## make the models different m[1].removeRes(['ALA']) mask1, mask2 = compareModels( m[0], m[1] ) if self.local: print 'Reading and comparing two models' print '\nResidue masks to make the two maodels equal' print 'mask1\n', mask1 print 'mask2\n', mask2 globals().update( locals() ) self.assert_( N.all(mask1 == self.EXPECT[0] ) ) self.assert_( N.all(mask2 == self.EXPECT[1] ) )
def changeModel( inFile, prefix, sourceModel ): print '\nget ' + os.path.basename( inFile ) + '..', model = PDBModel( inFile ) model.update() model = model.sort() eq = model.equals( sourceModel ) if not eq[0] and eq[1]: raise ConvertError('source and other models are not equal: ' + str(eq)) # model.validSource() model.setSource( sourceModel.validSource() ) #model.atomsChanged = 0 for k in model.atoms: model.atoms[k,'changed'] = N.all( model[k] == sourceModel[k] ) model.xyzChanged = ( 0 != N.sum( N.ravel( model.xyz - sourceModel.xyz)) ) model.update( updateMissing=1 ) if model.xyzChanged: doper = PDBDope( model ) if 'MS' in sourceModel.atoms.keys(): doper.addSurfaceRacer( probe=1.4 ) if 'density' in sourceModel.atoms.keys(): doper.addDensity() if 'foldX' in sourceModel.info.keys(): doper.addFoldX() if 'delphi' in sourceModel.info.keys(): doper.addDelphi() outFile = os.path.dirname( inFile ) + '/' + prefix +\ T.stripFilename( inFile ) + '.model' T.dump( model, outFile ) print '-> ' + os.path.basename( outFile )
def test_Whatif(self): """Whatif test""" from Biskit import PDBModel ## Loading PDB... f = T.testRoot()+"/com/1BGS.pdb" m = PDBModel(f) m = m.compress( m.maskProtein() ) m = m.compress( m.maskHeavy() ) ## Starting WhatIf x = WhatIf( m, debug=0, verbose=0 ) ## Running atomAcc, resAcc, resMask = x.run() if self.local: ## check that model hasn't changed m_ref = PDBModel(f) m_ref = m.compress( m.maskProtein() ) for k in m_ref.atoms.keys(): if not N.all(m_ref[k] == m[k]): print 'Not equal ', k else: print 'Equal ', k ## display exposed residues in PyMol from Pymoler import Pymoler pm = Pymoler() model = pm.addPdb( m, '1' ) pm.colorRes( '1', resAcc[:,0] ) pm.show() print "\nResult for first 10 atoms/residues: " print '\nAccessability (A^2):\n', atomAcc[:10] print '\nResidue accessability (A^2)' print '[total, backbone, sidechain]:\n', resAcc[:10] print '\nExposed residue mask:\n',resMask[:10] print '\nTotal atom accessability (A^2): %.2f'%sum(atomAcc) print ' residue accessability (A^2): %.2f'%sum(resAcc)[0] self.assertAlmostEqual( N.sum(resAcc[:,0]), 2814.6903, 7 )
def test_Whatif(self): """Whatif test""" from Biskit import PDBModel ## Loading PDB... f = T.testRoot() + "/com/1BGS.pdb" m = PDBModel(f) m = m.compress(m.maskProtein()) m = m.compress(m.maskHeavy()) ## Starting WhatIf x = WhatIf(m, debug=0, verbose=0) ## Running atomAcc, resAcc, resMask = x.run() if self.local: ## check that model hasn't changed m_ref = PDBModel(f) m_ref = m.compress(m.maskProtein()) for k in m_ref.atoms.keys(): if not N.all(m_ref[k] == m[k]): print 'Not equal ', k else: print 'Equal ', k ## display exposed residues in PyMol from Pymoler import Pymoler pm = Pymoler() model = pm.addPdb(m, '1') pm.colorRes('1', resAcc[:, 0]) pm.show() print "\nResult for first 10 atoms/residues: " print '\nAccessability (A^2):\n', atomAcc[:10] print '\nResidue accessability (A^2)' print '[total, backbone, sidechain]:\n', resAcc[:10] print '\nExposed residue mask:\n', resMask[:10] print '\nTotal atom accessability (A^2): %.2f' % sum(atomAcc) print ' residue accessability (A^2): %.2f' % sum(resAcc)[0] self.assertAlmostEqual(N.sum(resAcc[:, 0]), 2814.6903, 7)
def test_SparseArray(self): """SparseArray test""" a = N.zeros((6, ), N.Float32) self.sa = SparseArray(a.shape) self.sa[3] = 1. self.sa[5] = 2. b = N.zeros((5, 6), N.Float32) b[0, 1] = 3. b[0, 2] = 4 b[4, 2] = 5 b[3, 0] = 6 self.sb = SparseArray(b) self.sb.append(self.sa) if self.local: print self.sa.toarray() self.assert_(N.all(self.sb.toarray() == self.EXPECTED))
def test_SparseArray(self): """SparseArray test""" a = N.zeros( (6,), N.Float32 ) self.sa = SparseArray( a.shape ) self.sa[3] = 1. self.sa[5] = 2. b = N.zeros( (5, 6), N.Float32 ) b[0,1] = 3. b[0,2] = 4 b[4,2] = 5 b[3,0] = 6 self.sb = SparseArray( b ) self.sb.append( self.sa ) if self.local: print self.sa.toarray() self.assert_( N.all( self.sb.toarray() == self.EXPECTED) )
def test_hist( self ): """hist test""" self.x = Numeric.arange( 4, 12, 1.2 ) self.data = density( self.x, 3, hist=1 ) self.assert_( Numeric.all( self.data == self.EXPECT) )
def test_hist(self): """hist test""" self.x = Numeric.arange(4, 12, 1.2) self.data = density(self.x, 3, hist=1) self.assert_(Numeric.all(self.data == self.EXPECT))