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 N0.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 N0.array(frameList).astype(N0.Float32)
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'] = N0.all(model[k] == sourceModel[k]) model.xyzChanged = (0 != N0.sum(N0.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 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'] = N0.all( model[k] == sourceModel[k] ) model.xyzChanged = ( 0 != N0.sum( N0.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 N0.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( N0.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 N0.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(N0.sum(resAcc[:, 0]), 2814.6903, 7)