def test_ComplexTraj(self): """Dock.ComplexTraj test""" import biskit.tools as T ## there is no complex trajectory in the test folder so will have ## to create a fake trajectory with a complex f = [ T.testRoot()+ '/com/1BGS.pdb' ] * 5 t = Trajectory( f, verbose=self.local ) t = ComplexTraj( t, recChains=[0] ) #if self.local: #print 'plotting contact density...' #t.plotContactDensity( step=2 ) ## create a fake second chain in the ligand for i in range( 1093+98, 1968 ): t.ref.atoms['chain_id'][i] = 'B' t.ref.chainIndex( force=1, cache=1 ) t.cl = [1,2] r = N0.concatenate((list(range(1093,1191)), list(range(0,1093)), list(range(1191,1968)))) tt = t.takeAtoms( r ) contactMat = tt.atomContacts( 1 ) if self.local: print('Receptor chains: %s Ligand chains: %s'%(t.cr, t.cl)) self.assertEqual( N0.sum(N0.ravel(contactMat)), 308 )
def test_ComplexTraj(self): """Dock.ComplexTraj test""" import biskit.tools as T ## there is no complex trajectory in the test folder so will have ## to create a fake trajectory with a complex f = [T.testRoot() + '/com/1BGS.pdb'] * 5 t = Trajectory(f, verbose=self.local) t = ComplexTraj(t, recChains=[0]) #if self.local: #print 'plotting contact density...' #t.plotContactDensity( step=2 ) ## create a fake second chain in the ligand for i in range(1093 + 98, 1968): t.ref.atoms['chain_id'][i] = 'B' t.ref.chainIndex(force=1, cache=1) t.cl = [1, 2] r = N0.concatenate( (list(range(1093, 1191)), list(range(0, 1093)), list(range(1191, 1968)))) tt = t.takeAtoms(r) contactMat = tt.atomContacts(1) if self.local: print('Receptor chains: %s Ligand chains: %s' % (t.cr, t.cl)) self.assertEqual(N0.sum(N0.ravel(contactMat)), 308)
def test_ComplexRandomizer(self): """Dock.ComplexRandomizer test""" from biskit.md import Trajectory if self.local: print("\nLoading Rec and Lig files ...", end=' ') rec_pdb = t.testRoot() + '/rec/1A2P.pdb' lig_pdb = t.testRoot() + '/lig/1A19.pdb' rec_psf = t.testRoot() + '/rec/1A2P.psf' lig_psf = t.testRoot() + '/lig/1A19.psf' rec = XplorModel( rec_psf, rec_pdb ) lig = XplorModel( lig_psf, lig_pdb ) if self.local: print("Initializing Randomizer...") self.cr = ComplexRandomizer( rec, lig, debug=self.DEBUG ) if self.local: print("Creating 3 random complexes...") cs = [ self.cr.random_complex() for i in range(3) ] self.traj = Trajectory( [ c.model() for c in cs ], verbose=self.local ) if self.local: self.display( self.traj ) globals().update( locals() ) self.assertEqual( len(self.traj), 3 )
def replaceContent( self, traj ): """ Replace content of this trajectory by content of given traj. No deep-copying, only references are taken. @param traj: Trajectory @type traj: Trajectory @raise ComplexTrajError: if given traj is no ComplexTraj. """ if not isinstance( traj, ComplexTraj ): raise ComplexTrajError( "Cannot replace ComplexTraj by normal Trajectory.") Trajectory.replaceContent( self, traj ) self.cr = traj.cr self.cl = traj.cl
def replaceContent(self, traj): """ Replace content of this trajectory by content of given traj. No deep-copying, only references are taken. @param traj: Trajectory @type traj: Trajectory @raise ComplexTrajError: if given traj is no ComplexTraj. """ if not isinstance(traj, ComplexTraj): raise ComplexTrajError( "Cannot replace ComplexTraj by normal Trajectory.") Trajectory.replaceContent(self, traj) self.cr = traj.cr self.cl = traj.cl
def takeAtoms( self, indices, returnClass=None ): """ takeAtoms( indices, [returnClass] ) -> ComplexTraj @param indices: atoms to extract @type indices: [int] @param returnClass: return type (default: current class) @type returnClass: class @return: ComplexTraj @rtype: ComplexTraj @raise ComplexTrajError: if (parts of) chains are inserted into each other """ r = Trajectory.takeAtoms( self, indices, returnClass ) oldToNew = self.__translateChainIndices( indices, r.ref.chainMap() ) r.cr = [ oldToNew[ c ] for c in self.cr if c in oldToNew ] r.cl = [ oldToNew[ c ] for c in self.cl if c in oldToNew ] return r
def takeAtoms(self, indices, returnClass=None): """ takeAtoms( indices, [returnClass] ) -> ComplexTraj @param indices: atoms to extract @type indices: [int] @param returnClass: return type (default: current class) @type returnClass: class @return: ComplexTraj @rtype: ComplexTraj @raise ComplexTrajError: if (parts of) chains are inserted into each other """ r = Trajectory.takeAtoms(self, indices, returnClass) oldToNew = self.__translateChainIndices(indices, r.ref.chainMap()) r.cr = [oldToNew[c] for c in self.cr if c in oldToNew] r.cl = [oldToNew[c] for c in self.cl if c in oldToNew] return r
#!/usr/bin/env python ## re-generate binary test data in this folder import biskit as B import biskit.tools as T from biskit.md import Trajectory, EnsembleTraj, traj2ensemble ## create standard trajectory object t = Trajectory('raw/traj.crd', 'raw/traj_ref.pdb' ) t.frameNames = T.load('raw/traj_framenames.list') te = traj2ensemble(t, members=10) te.fit(fit=0) ## re-calculate profile 'rms' (all-atom fit to average structure) T.dump(te, 'traj.dat')
if len( sys.argv ) < 2: _use() o = cmdDict( {'o':'traj.dat', 'i':'sim.crd'} ) fcrd = o['i'] fpdb = o['r'] fout = o['o'] box = 'b' in o wat = 'wat' in o hyd = 'hyd' in o rnres = 'rnres' in o code = o.get('code', None) step = int(o.get('step', 1)) t = Trajectory( fcrd, fpdb, hasbox=box, rmwat=wat, verbose=True) if code: t.ref.pdbCode = code if hyd: t.ref.addChainId( keep_old=1 ) ## preserve chain-delimiters t.removeAtoms( lambda a: a['element'] == 'H' ) if step != 1: t = t.takeFrames( N.arange(0,len(t),step) ) print("Dumping result to ", fout) dump( t, absfile(fout) ) print("Done")
import numpy as N import biskit.tools as T import biskit as B from biskit.md import Trajectory, EnsembleTraj, traj2ensemble com = Trajectory('rpa_com.crd', '0_com.pdb', hasbox=1 ) ##com = T.load( 'com.traj' ) # re-order frames into 4 parallel trajectories frames = N.zeros( len(com), int ) for i in range( 11 ): N.put( frames, range(i*4,i*4+4), N.arange(i,44,11) ) etraj = EnsembleTraj( n_members=4 ) etraj.frames = com.takeFrames( frames ).frames etraj.ref = com.ref etraj.resetFrameNames() etraj.ref.disconnect() # separate protein and DNA into two chains etraj.ref.chainIndex(breaks=True, force=True, cache=True) etraj.ref.addChainId() ## extract only some residues for speed t1 = etraj.takeAtoms( etraj.ref.res2atomIndices(range(10)) ) t2 = etraj.takeChains( [1] )