Exemplo n.º 1
0
    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((range(1093, 1191), range(0,
                                                     1093), 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)
Exemplo n.º 2
0
    def test_Analyzer( self):
        """Dock.Analyzer test """
        from Biskit import Trajectory
        from Biskit.Dock import ComplexList

        ## create a minimal 1-frame receptor trajectory from a pdb file
        self.t_rec = Trajectory( [t.testRoot()+'/rec/1A2P.pdb'],
                                 verbose=self.local)
        t.dump( self.t_rec, self.f_out )

        ## load a complex list
        cl = t.load( t.testRoot() + '/dock/hex/complexes.cl')

        self.a= Analyzer( rec = self.f_out,
                          lig = t.testRoot()+'/lig_pcr_00/traj.dat',
                          ref = t.testRoot()+'/com/ref.complex',
                          verbose = self.local)

        ## shuffle this list five times
        shuff_lst = self.a.shuffledLists( 5, range(8) )

        ## create two random contact matrices
        rand_mat = self.a.random_contacts( cl[0].atomContacts(), 2 )
        
        self.assertEqual( N0.shape(rand_mat[1]), (1075, 876) ) 
Exemplo n.º 3
0
    def test_ComplexRandomizer(self):
        """Dock.ComplexRandomizer test"""
        from Biskit import Trajectory

        if self.local:
            print "\nLoading Rec and Lig files ...",

        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 = PCRModel(rec_psf, rec_pdb)
        lig = PCRModel(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])

        if self.local:
            self.display(self.traj)
            globals().update(locals())

        self.assertEqual(len(self.traj), 3)
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    for i in range(nr):
        print '%5i' % (i + 1),
    for i in range(nr):
        print '\n%2i' % (i + 1),
        for k in range(i):
            print ' ' * 5,
        for j in range(i, nr):
            print '%5.2f' % matrix[i, j],


## get filenames of all models
models = glob.glob('%s/modeller/%s*.pdb' %
                   (outFolder, tools.stripFilename(f_target)))

## create a Trajectory object with the models
traj = Trajectory(pdbs=models)

## fit the models against the average structure iteratively
traj.blockFit2ref()

## calculate and print rmsd matrix
rmsHeavy = traj.pairwiseRmsd()
print '\nHEAVY ATOM RMSD BETWEEN MODELS::'
__printMatrix(rmsHeavy)

## same thing for backbone atoms
BBMask = traj[0].maskBB()
traj.blockFit2ref(mask=BBMask)
rmsBB = traj.pairwiseRmsd(aMask=BBMask)
print '\nBACKBONE RMSD BETWEEN MODELS:'
__printMatrix(rmsBB)
Exemplo n.º 7
0
dotPlotName = os.path.dirname(cFile) + '/' + cName + '_dot_plot.eps'
logPlotName = os.path.dirname(cFile) + '/' + cName + '_log_plot.eps'
diffPlotName = os.path.dirname(cFile) + '/' + cName + '_diff_plot.eps'
rankPlotName = os.path.dirname(cFile) + '/' + cName + '_rank_plot.eps'
contourPlotName = os.path.dirname(cFile) + '/' + cName + '_contour_plot.eps'
profilePlotName = os.path.dirname(cFile) + '/' + cName + '_plot_profile.eps'
outFile = os.path.dirname(cFile) + '/' + cName + '_best.txt'
dumpFile = os.path.dirname(cFile) + '/' + cName + '.dat'

#############################################################
## RMSD analysis

flushPrint('Performing RMSD analysis...\n')

## Load Trajectories - read and sort bound ligand and recepror trajectories
traj_rec = Trajectory(rec_pdbs)
traj_lig = Trajectory(lig_pdbs)

## reference (bound) rec and lig
ref = load(absfile(options['ref']))
ref.rec().remove(ref.rec().maskH())
ref.lig_model.remove(ref.lig().maskH())
ref.lig_transformed = None
ref.rec().writePdb(ref_rec_file)
ref.lig().writePdb(ref_lig_file)

## Load Trajectories - read and sort bound ligand and recepror trajectories
traj_rec_ref = Trajectory([ref_rec_file])
traj_lig_ref = Trajectory([ref_lig_file])

traj_rec, traj_rec_ref = castTraj(traj_rec, traj_rec_ref)
Exemplo n.º 8
0
cl = contact(cl, ref, fout + 'cont.cl', add_hosts=add_hosts)

cl = filter_zero_contacts(cl)  ## happened in one case

## cl = cl.filter( 'fnac_10', (0., 0.) )
cl = cl.filter('fnarc_10', (0., 0.))
flushPrint('%i orientations removed because of fnarc > 0.0\n' %
           (n_cl - len(cl)))

cg = group(cl, 0.001, 0.0001)

dump(cg, fout + 'grouped.cg')

## final selection
nr_cl = selectClusters(cg, 10)
flushPrint(
    'dumping %i non-redundant, non-overlapping, non-native complexes\n'\
        % len( nr_cl ) )
dump(nr_cl, fout + 'nr.cl')

flushPrint('Dumping random complexes.')
saveComplexes(nr_cl, com_out)

## for visualisation
flushPrint('\nPreparing trajectory...')

t = Trajectory([c.model() for c in nr_cl])
t.ref.addChainId()
t.ref.writePdb(fout + 'nr_traj_ref.pdb', ter=2)
t.writeCrd(fout + 'nr_traj.crd')
Exemplo n.º 9
0
    nr = len( matrix )
    for i in range(nr): print '%5i'%(i+1),
    for i in range(nr):
        print '\n%2i'%(i+1),
        for k in range(i):
            print ' '*5,
        for j in range(i, nr):
            print '%5.2f'%matrix[i,j],
            
    
## get filenames of all models 
models = glob.glob( '%s/modeller/%s*.pdb'%(outFolder,
                                           tools.stripFilename(f_target)) )

## create a Trajectory object with the models
traj = Trajectory( pdbs=models )

## fit the models against the average structure iteratively
traj.blockFit2ref()

## calculate and print rmsd matrix
rmsHeavy = traj.pairwiseRmsd()
print '\nHEAVY ATOM RMSD BETWEEN MODELS::'
__printMatrix( rmsHeavy )

## same thing for backbone atoms
BBMask = traj[0].maskBB()
traj.blockFit2ref( mask = BBMask )
rmsBB = traj.pairwiseRmsd( aMask = BBMask  )
print '\nBACKBONE RMSD BETWEEN MODELS:'
__printMatrix( rmsBB )
Exemplo n.º 10
0
    result_ref = result_ref or ref or t.ref

    if t.ref.equals(result_ref) != [1, 1]:
        raise Exception('Incompatible reference structure.')

    for xyz in t.frames:
        result_xyz.append(xyz.astype('f'))

    for fname in t.frameNames:
        result_frameNames.append(fname)

    T.flushPrint('#')

print " Done"

result = Trajectory()

result.ref = result_ref
result.ref.disconnect()

if 'pdb' in o:
    result.ref.pdbCode = o['pdb']

result.frames = N.array(result_xyz, 'f')
result.frameNames = result_frameNames

del result_xyz
## too much memory required for this
## result = trajLst[0].concat( *trajLst[1:] )

T.flushPrint("Converting to EnsembleTraj...")
Exemplo n.º 11
0
    lo = absfile(options['lo'])
    out = absfile(options['o'])
    n = int(options['n'])
    traj = absfile(options.get('traj', None))
    finp = absfile(options.get('debug', None))
    debug = (finp is not None)
except:
    print "Missing or wrong option:"
    print lastError()
    _use()

cr = ComplexRandomizer(rec, lig, ro, lo, debug=debug)
result = ComplexList()

flushPrint('generating...')
for i in range(n):
    result.append(cr.random_complex(inp_mirror=finp))

    flushPrint('#')

flushPrint('\nDumping result...')
dump(result, out)

if traj:
    flushPrint('\nWriting trajectory...')
    t = Trajectory([c.model() for c in result])
    t.ref.writePdb(traj + '.pdb')
    t.writeCrd(traj + '.crd')

flushPrint('done')
Exemplo n.º 12
0
logPlotName = os.path.dirname(cFile) + '/' + cName + '_log_plot.eps'
diffPlotName = os.path.dirname(cFile) + '/' + cName + '_diff_plot.eps'
rankPlotName = os.path.dirname(cFile) + '/' + cName + '_rank_plot.eps'
contourPlotName = os.path.dirname(cFile) + '/' + cName + '_contour_plot.eps'
profilePlotName = os.path.dirname(cFile) + '/' + cName + '_plot_profile.eps'
outFile = os.path.dirname(cFile) + '/' + cName + '_best.txt'
dumpFile = os.path.dirname(cFile) + '/' + cName + '.dat'


#############################################################
## RMSD analysis

flushPrint('Performing RMSD analysis...\n')

## Load Trajectories - read and sort bound ligand and recepror trajectories
traj_rec = Trajectory( rec_pdbs )
traj_lig = Trajectory( lig_pdbs )

## reference (bound) rec and lig
ref = load( absfile( options['ref'] ) )
ref.rec().remove( ref.rec().maskH() )
ref.lig_model.remove( ref.lig().maskH() )
ref.lig_transformed = None
ref.rec().writePdb( ref_rec_file )
ref.lig().writePdb( ref_lig_file )

## Load Trajectories - read and sort bound ligand and recepror trajectories
traj_rec_ref = Trajectory( [ ref_rec_file ] )
traj_lig_ref = Trajectory( [ ref_lig_file ] )

traj_rec, traj_rec_ref = castTraj( traj_rec, traj_rec_ref )
Exemplo n.º 13
0
    result_ref = result_ref or ref or t.ref

    if t.ref.equals( result_ref ) != [1,1]:
        raise Exception( 'Incompatible reference structure.' )
    
    for xyz in t.frames:
        result_xyz.append( xyz.astype('f') )

    for fname in t.frameNames:
        result_frameNames.append( fname )
    
    T.flushPrint('#')
    
print " Done"

result = Trajectory()

result.ref = result_ref
result.ref.disconnect()

if 'pdb' in o:
    result.ref.pdbCode = o['pdb']

result.frames      = N0.array( result_xyz, 'f' )
result.frameNames  = result_frameNames

del result_xyz
## too much memory required for this
## result = trajLst[0].concat( *trajLst[1:] )

T.flushPrint("Converting to EnsembleTraj...")
Exemplo n.º 14
0
    out = absfile( options['o'] )
    n   = int( options['n'] )
    traj= absfile( options.get('traj', None) )
    finp= absfile( options.get('debug', None))
    debug = ( finp is not None )
except:
    print "Missing or wrong option:"
    print lastError()
    _use()
    
cr = ComplexRandomizer( rec, lig, ro, lo, debug=debug )
result = ComplexList()

flushPrint('generating...')
for i in range( n ):
    result.append( cr.random_complex( inp_mirror=finp ) )

    flushPrint('#')

flushPrint('\nDumping result...')
dump( result, out )


if traj:
    flushPrint('\nWriting trajectory...')
    t = Trajectory( [ c.model() for c in result ] )
    t.ref.writePdb( traj + '.pdb' )
    t.writeCrd( traj + '.crd' )

flushPrint('done')
Exemplo n.º 15
0
cl = contact( cl, ref, fout + 'cont.cl', add_hosts=add_hosts )

cl = filter_zero_contacts( cl )  ## happened in one case

## cl = cl.filter( 'fnac_10', (0., 0.) )
cl = cl.filter( 'fnarc_10', (0., 0.) )
flushPrint('%i orientations removed because of fnarc > 0.0\n' % (n_cl-len(cl)))

cg = group( cl, 0.001, 0.0001 )

dump( cg, fout+'grouped.cg' )

## final selection
nr_cl = selectClusters( cg, 10 )
flushPrint(
    'dumping %i non-redundant, non-overlapping, non-native complexes\n'\
        % len( nr_cl ) )
dump( nr_cl, fout+'nr.cl')

flushPrint('Dumping random complexes.')
saveComplexes( nr_cl, com_out )

## for visualisation
flushPrint('\nPreparing trajectory...')

t = Trajectory( [ c.model() for c in nr_cl ] )
t.ref.addChainId()
t.ref.writePdb( fout+'nr_traj_ref.pdb', ter=2 )
t.writeCrd( fout+'nr_traj.crd')