Beispiel #1
0
    def generic_test(self, pdb, expected=None, proteinonly=False):
        """generic DSSP test"""

        from biskit import PDBModel

        if self.local: print('Loading PDB...')
        self.m = PDBModel(pdb)
        
        if proteinonly:
            self.m = self.m.compress( self.m.maskProtein() )

        if self.local:  print('Starting DSSP')
        self.dssp = Dssp( self.m, verbose=self.local, debug=self.DEBUG )

        if self.local: print('Running DSSP')

        self.result = self.dssp.run()  ## returns modified PDBModel
        self.result = self.result.compress( self.result.maskProtein() )
        self.result = ''.join(self.result['dssp'])

        if self.local:
            print("Sequence :", self.m.sequence())
            print("Secondary:", self.result)            
        
        if expected:
            self.assertEqual( self.result, expected)        
Beispiel #2
0
    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 list(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 list(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.assertTrue(N.all(m_ref[k] == self.M[k]))

        ## display in Pymol
        if self.local:
            print("Starting PyMol...")
            from biskit.exe.pymoler import Pymoler

            pm = Pymoler()
            pm.addPdb(self.M, 'm')
            pm.colorAtoms('m', N0.clip(self.M.profile('relAS'), 0.0, 100.0))
            pm.show()
Beispiel #3
0
class Test(BT.BiskitTest):
    """Test"""

    TAGS = [ BT.EXE, BT.OLD ]

    def test_Prosa2003(self):
        """Prosa2003 test"""
        from biskit import PDBModel
        
        ## Loading PDB...
        self.ml = PDBModel( T.testRoot()+'/lig/1A19.pdb' )
        self.ml = self.ml.compress( self.ml.maskProtein() )

        self.mr = PDBModel( T.testRoot()+'/rec/1A2P.pdb' )
        self.mr = self.mr.compress( self.mr.maskProtein() )

        ## Starting Prosa2003
        self.prosa = Prosa2003( [self.ml, self.mr], debug=0, verbose=0 )

        ## Running
        self.ene = self.prosa.run()

        self.result = self.prosa.prosaEnergy()

        if self.local:
            print("Result: ", self.result)

        self.assertTrue( N0.sum(self.result - [ -94.568,  -64.903, -159.463 ] ) \
                      < 0.0000001 )
Beispiel #4
0
    def test_hexTools(self):
        """Dock.hexTools test"""
        from biskit import PDBModel
        self.m = PDBModel(t.testRoot() + '/com/1BGS.pdb')
        dist = centerSurfDist(self.m, self.m.maskCA())

        self.assertAlmostEqual(dist[0], 26.880979538, 7)
Beispiel #5
0
    def reduceToModel( self, xyz=None, reduce_profiles=1  ):
        """
        Create a reduced PDBModel from coordinates. Atom profiles the source
        PDBModel are reduced by averaging over the grouped atoms.
        
        @param xyz: coordinte array (N_atoms x 3) or
                    None (->use reference coordinates)
        @type  xyz: array OR None
        
        @return: PDBModel with reduced atom set and profile 'mass'
        @rtype: PDBModel
        """

        mass = self.m.atoms.get('mass')
        if xyz is None: xyz = self.m.getXyz()

        mProf = [ N0.sum( N0.take( mass, group ) ) for group in self.groups ]
        xyz = self.reduceXyz( xyz )

        result = PDBModel()

        for k in self.atoms.keys():
            result.atoms.set( k, self.atoms.valuesOf(k) )

##         result.setAtoms( self.atoms )

        result.setXyz( xyz )
        result.atoms.set( 'mass', mProf )

        if reduce_profiles:
            self.reduceAtomProfiles( self.m, result )

            result.residues = self.m.residues

        return result
Beispiel #6
0
class Test(BT.BiskitTest):
    """Test class"""

    TAGS = [ BT.EXE, BT.LONG ]
    
    def test_bindingE( self ):
        """bindingEnergyDelphi test (Barnase:Barstar)"""
        self.com = T.load( T.testRoot() + '/com/ref.complex' )
        self.dG = DelphiBindingEnergy( self.com, log=self.log, scale=1.2,
                                       verbose=self.local )
        self.r = self.dG.run()

##        self.assertAlmostEqual( self.r['dG_kt'], 21., 0 )
        self.assertTrue( abs(self.r['dG_kt'] - 24.6) < 4 )

        if self.local:
            self.log.add(
                '\nFinal result: dG = %3.2f kcal/mol'%self.r['dG_kcal'])
            
    def test_errorcase1( self ):
        """bindinEnergyDelphi test (error case 01)"""
        self.m = PDBModel( T.testRoot() + '/delphi/case01.pdb' )
        rec = self.m.takeChains( [0,1] )
        lig = self.m.takeChains( [2] )
        self.com = Complex( rec, lig )
        
        self.dG = DelphiBindingEnergy( self.com, log = self.log, scale=0.5,
                                       verbose=self.local )
        self.r = self.dG.run()

        if self.local:
            self.log.add(
                '\nFinal result: dG = %3.2f kcal/mol'%self.r['dG_kcal'])
Beispiel #7
0
    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 list(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 list(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.assertTrue( N.all( m_ref[k] == self.M[k]) )

        ## display in Pymol
        if self.local:
            print("Starting PyMol...")
            from biskit.exe.pymoler import Pymoler

            pm = Pymoler()
            pm.addPdb( self.M, 'm' )
            pm.colorAtoms( 'm', N0.clip(self.M.profile('relAS'), 0.0, 100.0) )
            pm.show()
Beispiel #8
0
    def test_tmalign(self):
        """TMAlign test"""
        from biskit import PDBModel

        if self.local: print('Loading PDB...')

        self.m1 = PDBModel(T.testRoot('tmalign/1huy_citrine.model'))
        self.m2 = PDBModel(T.testRoot('tmalign/1zgp_dsred_dimer.model'))

        if self.local: print('Starting TMAlign')
        self.x = TMAlign(self.m1,
                         self.m2,
                         debug=self.DEBUG,
                         verbose=self.local)

        if self.local:
            print('Running')

        self.r = self.x.run()

        if self.local:
            print("Result: ")
            for key, value in self.r.items():
                print('\t', key, ':\t', value)

        self.assertEqual(self.r['rmsd'], 1.76)
Beispiel #9
0
    def test_atomcharger( self ):
        """AtomCharger test"""
        import biskit.tools as T

        if self.local: self.log.add('\nLoading PDB...')

        self.m1 = PDBModel( T.testRoot('delphi/1A19_reduced.model'))
        self.m2 = PDBModel( T.testRoot('delphi/complex_reduced.model'))

        if self.local:
            self.log.add('\nSetup Residue Library\n')

        ac = AtomCharger(log=self.log, verbose=self.local)

        if self.local:
            self.log.add('match residues to Amber topology')

        ac.charge( self.m1 )
        ac.charge( self.m2 )

        self.assertAlmostEqual( N.sum(self.m1['partial_charge']), -6, 2 )
        self.assertAlmostEqual( N.sum(self.m2['partial_charge']), -4, 2 )
        self.assertTrue(N.all(self.m1['partial_charge'] != 0),'unmatched atoms 1')
        self.assertTrue(N.all(self.m2['partial_charge'] != 0),'unmatched atoms 2')

        if self.local:
            self.log.add('\nNow test handling of atom miss-matches:\n')

        self.m3 = PDBModel(self.m1.clone())
        self.m3.remove( [0,3,100,101,102,200] )
        ac.charge( self.m3 )

        self.assertAlmostEqual( N.sum(self.m3['partial_charge']),-8.21, 2)
Beispiel #10
0
    def test_Capping(self):
        """PDBCleaner.capTerminals test"""
        ## Loading PDB...
        self.model = PDBModel(t.testRoot() + '/rec/1A2P_rec_original.pdb')

        self.c = PDBCleaner(self.model, log=self.log, verbose=self.local)
        self.m2 = self.c.capTerminals(breaks=True)
        self.assertTrue(self.m2.atomNames() == self.model.atomNames())

        self.m3 = self.model.clone()
        self.m3.removeRes([10, 11, 12, 13, 14, 15])
        self.m4 = self.m3.clone()

        self.c = PDBCleaner(self.m3, log=self.log, verbose=self.local)
        self.m3 = self.c.capTerminals(breaks=True, capC=[0], capN=[0, 1])
        self.assertEqual(
            self.m3.takeChains([0]).sequence()[:18], 'XVINTFDGVADXXKLPDN')

        if self.local:
            self.log.add('\nTesting automatic chain capping...\n')

        self.c = PDBCleaner(self.m4, log=self.log, verbose=self.local)
        self.m4 = self.c.capTerminals(auto=True)
        self.assertEqual(
            self.m4.takeChains([0]).sequence()[:18], 'XVINTFDGVADXXKLPDN')
Beispiel #11
0
    def test_atomcharger(self):
        """AtomCharger test"""
        import biskit.tools as T

        if self.local: self.log.add('\nLoading PDB...')

        self.m1 = PDBModel(T.testRoot('delphi/1A19_reduced.model'))
        self.m2 = PDBModel(T.testRoot('delphi/complex_reduced.model'))

        if self.local:
            self.log.add('\nSetup Residue Library\n')

        ac = AtomCharger(log=self.log, verbose=self.local)

        if self.local:
            self.log.add('match residues to Amber topology')

        ac.charge(self.m1)
        ac.charge(self.m2)

        self.assertAlmostEqual(N.sum(self.m1['partial_charge']), -6, 2)
        self.assertAlmostEqual(N.sum(self.m2['partial_charge']), -4, 2)
        self.assertTrue(N.all(self.m1['partial_charge'] != 0),
                        'unmatched atoms 1')
        self.assertTrue(N.all(self.m2['partial_charge'] != 0),
                        'unmatched atoms 2')

        if self.local:
            self.log.add('\nNow test handling of atom miss-matches:\n')

        self.m3 = PDBModel(self.m1.clone())
        self.m3.remove([0, 3, 100, 101, 102, 200])
        ac.charge(self.m3)

        self.assertAlmostEqual(N.sum(self.m3['partial_charge']), -8.21, 2)
Beispiel #12
0
    def test_addSecondaryNonFiltered(self):
        from biskit import PDBModel
        m = PDBModel('1R4Q')
        d = PDBDope(m)
        d.addSecondaryStructure()

        r = m.compress(m.maskProtein())['secondary']
        self.assertEqual(''.join(r), self.EXPECT_1RQ4)
Beispiel #13
0
    def prepare(self):
        from biskit import PDBModel
        self.f = T.testRoot() + '/com/1BGS.pdb'

        self.M = PDBModel(self.f)
        self.M = self.M.compress(self.M.maskProtein())

        self.d = PDBDope(self.M)
Beispiel #14
0
 def test_addSecondaryNonFiltered(self):
     from biskit import PDBModel
     m = PDBModel('1R4Q')
     d = PDBDope(m)
     d.addSecondaryStructure()
     
     r = m.compress(m.maskProtein())['secondary']
     self.assertEqual(''.join(r), self.EXPECT_1RQ4 )
Beispiel #15
0
    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 != list(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 == list(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)
Beispiel #16
0
    def test_capping_extra(self):
        """PDBCleaner.capTerminals extra challenge"""
        self.m2 = PDBModel(t.testRoot() + '/pdbclean/foldx_citche.pdb')
        self.c = PDBCleaner(self.m2, verbose=self.local, log=self.log)
        self.assertRaises(CappingError, self.c.capTerminals, auto=True)
        if self.local:
            self.log.add('OK: CappingError has been raised indicating clash.')

        self.assertEqual(len(self.m2.takeChains([1]).chainBreaks()), 1)
Beispiel #17
0
    def test_capping_internal(self):
        self.m3 = PDBModel(t.testRoot('pdbclean/foldx_citche.pdb'))
        self.m3 = self.m3.takeChains([1])  # pick second chain; has chain break
        self.c3 = PDBCleaner(self.m3, verbose=self.local, log=self.log)

        m = self.c3.capACE(self.m3, 1, checkgap=False)

        self.assertEqual(
            m.lenChains(breaks=True) - 1, self.m3.lenChains(breaks=True))
Beispiel #18
0
 def __init__(self, fpdb, log=None, verbose=True):
     """
     :param fpdb: pdb file OR PDBModel instance
     :type  fpdb: str OR Biskit.PDBModel
     :param log: biskit.LogFile object (default: STDOUT)
     :type  log: biskit.LogFile
     :param verbose: log warnings and infos (default: True)
     :type  verbose: bool
     """
     self.model = PDBModel(fpdb)
     self.log = log or StdLog()
     self.verbose = verbose
Beispiel #19
0
    def prepare(self):
        root = T.testRoot('amber/leap/')
        self.ref = PDBModel( T.testRoot('amber/leap/1HPT_solvated.pdb'))
        self.refdry = root + '1HPT_dry.pdb'

        self.dryparm = tempfile.mktemp('.parm', 'dry_')
        self.drycrd  = tempfile.mktemp('.crd', 'dry_')
        self.drypdb  = tempfile.mktemp('.pdb', 'dry_')
        self.wetparm = tempfile.mktemp('.parm', 'wet_')
        self.wetcrd  = tempfile.mktemp('.crd', 'wet_')
        self.wetpdb  = tempfile.mktemp('.pdb', 'wet_')
        self.leapout = tempfile.mktemp('.out', 'leap_')
Beispiel #20
0
class LongTest( BT.BiskitTest ):

    TAGS = [ BT.EXE, BT.LONG ]


    def prepare(self):
        from biskit import PDBModel
        self.f = T.testRoot() + '/com/1BGS.pdb'

        self.M = PDBModel( self.f )
        self.M = self.M.compress( self.M.maskProtein() )

        self.d = PDBDope( self.M )

    ## test de-activated as we don't have a running Hmmer module any longer
    def __test_conservation(self):
        """PDBDope.addConservation (Hmmer) test"""
        if self.local: print("Adding conservation data...", end=' ')
        self.d.addConservation()
        if self.local: print('Done.')

        ## display in Pymol
        if self.local:
            print("Starting PyMol...")
            from biskit.exe.pymoler import Pymoler

            pm = Pymoler()
            pm.addPdb( self.M, 'm' )
            pm.colorAtoms( 'm', N0.clip(self.M.profile('cons_ent'), 0.0, 100.0) )
            pm.show()

    def test_delphi(self):
        """PDBDope.addDelphi test"""
        if self.local:
            self.log.add( 'Calculating Delphi electrostatic potential' )
            self.log.add( '' )

        self.d.addDelphi( scale=1.2 )
        
        self.assertAlmostEqual( self.M['delphi']['scharge'], 0.95, 1 )
                

    ## EXPECT_1RQ4 = '.EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEE.SS.EEEEE..SS...EEEEEEE.SSTTT.....EEEEEESSS..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS.SSHHHHHHHHTS.STT.EE.HHHHHHHHHHHHT..SS...HHHHHHHHHHHHHTHHHHH.HHHHHHHHGGGT.TT...EE..HHHHHHHTTHHHHHHHGGG.SS.SEEEETTEEESSHHHHHTT..EE.......SS.SSSS..EEEETTEEEEHHHHHHH.....EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEEETTEEEEEE...S...EEEEEEE.SSSSS.....EEEEEETTT..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS..SHHHHHHHS...TTT.EE.TTHHHHHHHHHHT..SS...HHHHHHHHHHHHHHHHHHH.HHHHHHHGGGSS.TT...EE..HHHHHHHHTHHHHHHHGGG.SS.SEEEETTEEE.SHHHHHTT..EE........S.STTSS.EEESSSEEEEHHHHHHH.......EEEEE.EEEEEE.TTS.EEEEESS.EEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE...EEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHHT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..HHHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.TTS.EEEEETTB..EE..TTHHHHHHHHHHHT..EEEE.SS.STT.B..EEEE.....EEE.EEEEEE.TTS.EEEEETTEEEEE..THHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..TTHHHHHHHHHTTT..EEEE.S..STT.B..EEEE.'
    EXPECT_1RQ4 = '.EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEE.SS.EEEEE..SS...EEEEEEE.SSTTT.....EEEEEESSS..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS.SSHHHHHHHHTS.STT.EE.HHHHHHHHHHHHT..SS...HHHHHHHHHHHIIIIIHHH.HHHHHHHHGGGT.TT...EE..HHHHHHHTTHHHHHHHGGG.SS.SEEEETTEEESSHHHHHTT..EE.......SS.SSSS..EEEETTEEEEHHHHHHH.....EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEEETTEEEEEE...S...EEEEEEE.SSSSS.....EEEEEETTT..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS..SHHHHHHHS...TTT.EE.TTHHHHHHHHHHT..SS...HHHHHHHHHHHIIIIIHHH.HHHHHHHGGGSS.TT...EE..HHHHHHHHTHHHHHHHGGG.SS.SEEEETTEEE.SHHHHHTT..EE........S.STTSS.EEESSSEEEEHHHHHHH.......EEEEE.EEEEEE.TTS.EEEEESS.EEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE...EEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHHT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..HHHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.TTS.EEEEETTB..EE..TTHHHHHHHHHHHT..EEEE.SS.STT.B..EEEE.....EEE.EEEEEE.TTS.EEEEETTEEEEE..THHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..TTHHHHHHHHHTTT..EEEE.S..STT.B..EEEE.'
    def test_addSecondaryNonFiltered(self):
        from biskit import PDBModel
        m = PDBModel('1R4Q')
        d = PDBDope(m)
        d.addSecondaryStructure()
        
        r = m.compress(m.maskProtein())['secondary']
        self.assertEqual(''.join(r), self.EXPECT_1RQ4 )
Beispiel #21
0
    def getPDBModel( self, index ):
        """
        Get PDBModel object for a particular frame of the trajectory.

        :param index: frame index
        :type  index: int

        :return: model
        :rtype: PDBModel
        """
        s = PDBModel( self.ref, noxyz=1 )
        s.setXyz( self.frames[ index ] )
        return s
Beispiel #22
0
    def avgModel( self ):
        """
        Returna a PDBModel with coordinates that are the average of
        all frames.

        :return: PDBModel with average structure of trajectory (no fitting!) 
                 this trajectory's ref is the source of result model
        :rtype: PDBModel
        """
        result = PDBModel( self.getRef(), noxyz=1 )
        result.setXyz( N0.average( self.frames ) )

        return result
Beispiel #23
0
class LongTest(BT.BiskitTest):

    TAGS = [BT.EXE, BT.LONG]

    def prepare(self):
        from biskit import PDBModel
        self.f = T.testRoot() + '/com/1BGS.pdb'

        self.M = PDBModel(self.f)
        self.M = self.M.compress(self.M.maskProtein())

        self.d = PDBDope(self.M)

    ## test de-activated as we don't have a running Hmmer module any longer
    def __test_conservation(self):
        """PDBDope.addConservation (Hmmer) test"""
        if self.local: print("Adding conservation data...", end=' ')
        self.d.addConservation()
        if self.local: print('Done.')

        ## display in Pymol
        if self.local:
            print("Starting PyMol...")
            from biskit.exe.pymoler import Pymoler

            pm = Pymoler()
            pm.addPdb(self.M, 'm')
            pm.colorAtoms('m', N0.clip(self.M.profile('cons_ent'), 0.0, 100.0))
            pm.show()

    def test_delphi(self):
        """PDBDope.addDelphi test"""
        if self.local:
            self.log.add('Calculating Delphi electrostatic potential')
            self.log.add('')

        self.d.addDelphi(scale=1.2)

        self.assertAlmostEqual(self.M['delphi']['scharge'], 0.95, 1)

    ## EXPECT_1RQ4 = '.EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEE.SS.EEEEE..SS...EEEEEEE.SSTTT.....EEEEEESSS..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS.SSHHHHHHHHTS.STT.EE.HHHHHHHHHHHHT..SS...HHHHHHHHHHHHHTHHHHH.HHHHHHHHGGGT.TT...EE..HHHHHHHTTHHHHHHHGGG.SS.SEEEETTEEESSHHHHHTT..EE.......SS.SSSS..EEEETTEEEEHHHHHHH.....EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEEETTEEEEEE...S...EEEEEEE.SSSSS.....EEEEEETTT..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS..SHHHHHHHS...TTT.EE.TTHHHHHHHHHHT..SS...HHHHHHHHHHHHHHHHHHH.HHHHHHHGGGSS.TT...EE..HHHHHHHHTHHHHHHHGGG.SS.SEEEETTEEE.SHHHHHTT..EE........S.STTSS.EEESSSEEEEHHHHHHH.......EEEEE.EEEEEE.TTS.EEEEESS.EEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE...EEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHHT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..HHHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.TTS.EEEEETTB..EE..TTHHHHHHHHHHHT..EEEE.SS.STT.B..EEEE.....EEE.EEEEEE.TTS.EEEEETTEEEEE..THHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..TTHHHHHHHHHTTT..EEEE.S..STT.B..EEEE.'
    EXPECT_1RQ4 = '.EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEE.SS.EEEEE..SS...EEEEEEE.SSTTT.....EEEEEESSS..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS.SSHHHHHHHHTS.STT.EE.HHHHHHHHHHHHT..SS...HHHHHHHHHHHIIIIIHHH.HHHHHHHHGGGT.TT...EE..HHHHHHHTTHHHHHHHGGG.SS.SEEEETTEEESSHHHHHTT..EE.......SS.SSSS..EEEETTEEEEHHHHHHH.....EEEEE.SSHHHHHHHHHHHHHHHEEEEEEEEETTEEEEEE...S...EEEEEEE.SSSSS.....EEEEEETTT..EEEEEETTTTEEEE.GGGTT...TT.EEEE.SS..SHHHHHHHS...TTT.EE.TTHHHHHHHHHHT..SS...HHHHHHHHHHHIIIIIHHH.HHHHHHHGGGSS.TT...EE..HHHHHHHHTHHHHHHHGGG.SS.SEEEETTEEE.SHHHHHTT..EE........S.STTSS.EEESSSEEEEHHHHHHH.......EEEEE.EEEEEE.TTS.EEEEESS.EEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE...EEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHHT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..HHHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..HHHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEEEEEEEEE.TTS.EEEEETTEEEEE..TTHHHHHHHHHHTT.EEEEE.S..STT.B..EEEE...EEEEE.EEEEEE.TTS.EEEEETTB..EE..TTHHHHHHHHHHHT..EEEE.SS.STT.B..EEEE.....EEE.EEEEEE.TTS.EEEEETTEEEEE..THHHHHHHHHHHHT..EEEE.S..STT.B..EEEE...EEEEE.EEEEEE.SSS.EEEEETTEEEEE..TTHHHHHHHHHTTT..EEEE.S..STT.B..EEEE.'

    def test_addSecondaryNonFiltered(self):
        from biskit import PDBModel
        m = PDBModel('1R4Q')
        d = PDBDope(m)
        d.addSecondaryStructure()

        r = m.compress(m.maskProtein())['secondary']
        self.assertEqual(''.join(r), self.EXPECT_1RQ4)
Beispiel #24
0
    def __init__(self,
                 fcrd,
                 fref,
                 box=0,
                 rnAmber=0,
                 pdbCode=None,
                 log=StdLog(),
                 verbose=0):
        """
        :param fcrd: path to input coordinate file
        :type  fcrd: str
        :param fref: PDB or pickled PDBModel with same atom content and order
        :type  fref: str
        :param box: expect line with box info at the end of each frame
                    (default: 0)
        :type  box: 1|0
        :param rnAmber: rename amber style residues into standard (default: 0)
        :type  rnAmber: 1|0
        :param pdbCode: pdb code to be put into the model (default: None)
        :type  pdbCode: str
        :param log: LogFile instance [Biskit.StdLog]
        :type  log: biskit.LogFile
        :param verbose: print progress to log [0]
        :type  verbose: int
        """
        self.fcrd = T.absfile(fcrd)
        self.crd = T.gzopen(self.fcrd)

        self.ref = PDBModel(T.absfile(fref), pdbCode=pdbCode)
        self.box = box

        self.n = self.ref.lenAtoms()

        self.log = log
        self.verbose = verbose

        if rnAmber:
            self.ref.renameAmberRes()

        ## pre-compile pattern for line2numbers
        xnumber = "-*\d+\.\d+"  # optionally negtive number
        xspace = ' *'  # one or more space char
        self.xnumbers = re.compile('(' + xspace + xnumber + ')')

        ## pre-compute lines expected per frame
        self.lines_per_frame = self.n * 3 // 10

        if self.n % 10 != 0: self.lines_per_frame += 1
        if self.box: self.lines_per_frame += 1
Beispiel #25
0
    def __create( self, pdbs, refpdb, rmwat=0, castAll=0 ):
        """
        Initiate and create necessary variables.

        :param pdbs: file names of all conformations OR PDBModels
        :type  pdbs: [ str ] OR [ PDBModel ]
        :param refpdb: file name of reference pdb
        :type  refpdb: str
        :param rmwat: skip all TIP3, HOH, Cl-, Na+ from all files (default: 1)
        :type  rmwat: 0|1
        :param castAll: re-analyze atom content of each frame (default: 0)
        :type  castAll: 0|1
        """

        ## get Structure object for reference
        self.setRef( PDBModel( refpdb ) )

        ## Remove waters from ref (which will also remove it from each frame)
        if rmwat:
            wat = ['TIP3', 'HOH', 'WAT', 'Na+', 'Cl-' ]
            self.ref.remove( lambda a, wat=wat: a['residue_name'] in wat )

        ## frames x (N x 3) Array with coordinates
        self.frames = self.__collectFrames( pdbs, castAll )
        pass  ## self.frames.savespace()

        ## [00011111111222233..] (continuous) residue number for each atom
        self.resIndex = self.ref.resMap()

        ## keep list of loaded files
        if type( pdbs[0] ) is str:
            self.frameNames = pdbs
        self.frameNames = [ str( i ) for i in range(len(pdbs)) ]
Beispiel #26
0
    def test_DSSP_alltroublemakers(self):
        from biskit import PDBModel
        lst = '''1c48.pdb  3rlg.pdb  4gv5.pdb  4tsp.pdb
1p9g.pdb  3v03.pdb  4i0n.pdb  4tsq.pdb
1rd9.pdb  3v09.pdb  4idj.pdb  4wdc.pdb
1rdp.pdb  3vwi.pdb  4iw1.pdb  4whn.pdb
2anv.pdb  3w9p.pdb  4iya.pdb  4wvp.pdb
2anx.pdb  3weu.pdb  4j0l.pdb  4wx3.pdb
2f9r.pdb  3wev.pdb  4j2v.pdb  4wx5.pdb
2j8f.pdb  3wmu.pdb  4jk4.pdb  4zbq.pdb
2wc8.pdb  3wmv.pdb  4nzl.pdb  4zbr.pdb
2wcb.pdb  4bct.pdb  4ot2.pdb  5abw.pdb
2wce.pdb  4e99.pdb  4pho.pdb  5bpg.pdb
2xrs.pdb  4emx.pdb  4phq.pdb  5cr6.pdb
2xsc.pdb  4f5s.pdb  4po0.pdb  5dby.pdb
3a57.pdb  4f5t.pdb  4q7g.pdb  5elc.pdb
3hdf.pdb  4f5u.pdb  4rw3.pdb  5ele.pdb
3kve.pdb  4f5v.pdb  4rw5.pdb  5elf.pdb
3lu6.pdb  4fba.pdb  4tsl.pdb  5id7.pdb
3lu8.pdb  4fzm.pdb  4tsn.pdb  5id9.pdb
3mxg.pdb  4fzn.pdb  4tso.pdb'''.split()

        for s in lst:
            dssp = Dssp(PDBModel(s[:4]))
            r = dssp.run()

            if self.local:
                print(s, ':')
                print(r.sequence())
                print(''.join( r.compress(r.maskProtein())['dssp'] ))
                print()
Beispiel #27
0
    def test_errorcase1(self):
        """bindinEnergyDelphi test (error case 01)"""
        self.m = PDBModel(T.testRoot() + '/delphi/case01.pdb')
        rec = self.m.takeChains([0, 1])
        lig = self.m.takeChains([2])
        self.com = Complex(rec, lig)

        self.dG = DelphiBindingEnergy(self.com,
                                      log=self.log,
                                      scale=0.5,
                                      verbose=self.local)
        self.r = self.dG.run()

        if self.local:
            self.log.add('\nFinal result: dG = %3.2f kcal/mol' %
                         self.r['dG_kcal'])
Beispiel #28
0
    def test_reduce(self):
        """Reduce test"""
        if self.local: self.log.add('Loading PDB...')

        self.m1 = PDBModel(T.testRoot('lig/1A19_dry.model'))

        rec = T.load(T.testRoot('com/rec.model'))
        lig = T.load(T.testRoot('com/lig.model'))

        self.m2 = rec.concat(lig)

        if self.local: self.log.add('Starting Reduce')
        self.x = Reduce(self.m1, debug=self.DEBUG, verbose=self.local)
        if self.local:
            self.log.add('Running')
        self.r = self.x.run()

        if self.local:
            self.log.add("Result: ")
            self.log.add(self.r.report(prnt=False))

        if self.local:
            self.log.add('Reduce protein complex')
        self.x = Reduce(self.m2,
                        debug=self.DEBUG,
                        verbose=self.local,
                        autocap=True)
        self.r2 = self.x.run()
Beispiel #29
0
    def test_delphiCharges2(self):
        """
        PDB2DelphiCharges test
        """
        if self.local:
            T.errWrite('loading PDB...')

        self.m1 = self.MODEL or PDBModel(T.testRoot('lig/1A19_dry.model'))
        Test.MODEL = self.m1
        if self.local:
            T.errWriteln('Done.')

        if self.local:
            T.errWrite('Adding hydrogens to model (reduce)...')

        self.rmodel = Reduce(self.m1, verbose=self.local).run()
        self.rmodel.xplor2amber()
        if self.local:
            T.errWriteln('Done.')

        ac = AtomCharger()
        ac.charge(self.rmodel)
        self.rmodel.addChainFromSegid()

        self.dc = PDB2DelphiCharges(self.rmodel)
        self.dc.prepare()

        self.assertEqual(len(self.dc.resmap['LYS']), 2)  # normal and N'
        self.assertEqual(len(self.dc.resmap['SER']), 2)  # normal and C'

        if self.local:
            T.errWriteln('writing delphi charge file to %s' % self.fcrg)
        self.dc.tofile(self.fcrg)

        self.assertTrue(os.path.exists(self.fcrg))
Beispiel #30
0
    def parseReference(self, fpdb, dry_out=None):
        flushPrint("parsing " + fpdb + "...")
        m = PDBModel(fpdb)

        solute_res = m.atom2resMask(N.logical_not(m.maskSolvent()))

        self.lenres = self.lenres or N.sum(solute_res)
        assert isinstance(self.lenres, N.integer)

        self.lenatoms = len(m) - N.sum(m.maskH2O())
        assert isinstance(self.lenatoms, N.integer)

        if dry_out:
            m.remove(m.maskH2O())
            m.writePdb(dry_out)
        flushPrint('done.\n')
Beispiel #31
0
    def test_Capping( self ):
        """PDBCleaner.capTerminals test"""
        ## Loading PDB...
        self.model = PDBModel(t.testRoot() + '/rec/1A2P_rec_original.pdb')

        self.c = PDBCleaner( self.model, log=self.log, verbose=self.local )       
        self.m2 = self.c.capTerminals( breaks=True )
        self.assertTrue( self.m2.atomNames() == self.model.atomNames() )
        
        self.m3 = self.model.clone()
        self.m3.removeRes( [10,11,12,13,14,15] )
        self.m4 = self.m3.clone()
        
        self.c = PDBCleaner( self.m3, log=self.log, verbose=self.local )
        self.m3 = self.c.capTerminals( breaks=True, capC=[0], capN=[0,1])
        self.assertEqual( self.m3.takeChains([0]).sequence()[:18], 
                          'XVINTFDGVADXXKLPDN' )
        
        if self.local:
            self.log.add( '\nTesting automatic chain capping...\n' )
        
        self.c = PDBCleaner( self.m4, log=self.log, verbose=self.local )
        self.m4 = self.c.capTerminals( auto=True )
        self.assertEqual( self.m4.takeChains([0]).sequence()[:18], 
                          'XVINTFDGVADXXKLPDN' )
Beispiel #32
0
 def test_surfaceRacerBug(self):
     """PDBDope.addSurfaceRacer mask handling bugfix"""
     import os
     from biskit import PDBModel
     m = PDBModel(os.path.join(T.testRoot(), 'lig/1A19.pdb'))
     d = PDBDope(m)
     d.addSurfaceRacer()
Beispiel #33
0
    def test_ReduceCoordinates(self):
        """ReduceCoordinates test"""

        self.m = PDBModel( T.testRoot()+'/com/1BGS.pdb' )
        self.m = self.m.compress( N0.logical_not( self.m.maskH2O() ) )

        self.m.atoms.set('test', list(range(len(self.m))))

        self.red = ReduceCoordinates( self.m, 4 )

        self.mred = self.red.reduceToModel()
        
        if self.local:
            print('\nAtoms before reduction %i'% self.m.lenAtoms())
            print('Atoms After reduction %i'% self.mred.lenAtoms())

        self.assertEqual( self.mred.lenAtoms(), 445 )
Beispiel #34
0
    def prepare(self):
        from biskit import PDBModel
        self.f = T.testRoot() + '/com/1BGS.pdb'

        self.M = PDBModel( self.f )
        self.M = self.M.compress( self.M.maskProtein() )

        self.d = PDBDope( self.M )
Beispiel #35
0
    def test_capIrregular(self):
        """AmberParmBuilder.capNME & capACE test"""
        gfp = PDBModel('1GFL')
        normal = gfp.takeResidues([10, 11])
        chromo = gfp.takeResidues([64, 65])

        self.a = AmberParmBuilder(normal, verbose=self.local)
        self.m4 = self.a.capACE(normal, 0)

        self.assertEqual(len(self.m4), 17)

        ##        del chromo.residues['biomol']

        self.m5 = self.a.capACE(chromo, 0)
        self.m5 = self.a.capNME(self.m5, 0)

        self.assertEqual(self.m5.sequence(), 'XSYX')
Beispiel #36
0
    def test_capIrregular( self ):
        """AmberParmBuilder.capNME & capACE test"""
        gfp = PDBModel('1GFL')
        normal = gfp.takeResidues([10,11])
        chromo = gfp.takeResidues([64,65])

        self.a = AmberParmBuilder( normal,
                                   verbose=self.local)
        self.m4 = self.a.capACE( normal, 0 )

        self.assertEqual( len(self.m4), 17 )
        
##        del chromo.residues['biomol']

        self.m5 = self.a.capACE( chromo, 0 )
        self.m5 = self.a.capNME( self.m5, 0 )
        
        self.assertEqual( self.m5.sequence(), 'XSYX' )
Beispiel #37
0
 def test_capping_extra( self ):
     """PDBCleaner.capTerminals extra challenge"""
     self.m2 = PDBModel( t.testRoot() + '/pdbclean/foldx_citche.pdb' )
     self.c = PDBCleaner( self.m2, verbose=self.local, log=self.log)
     self.assertRaises(CappingError, self.c.capTerminals, auto=True)
     if self.local:
         self.log.add('OK: CappingError has been raised indicating clash.' )
     
     self.assertEqual( len(self.m2.takeChains([1]).chainBreaks()), 1 )
Beispiel #38
0
 def test_capping_internal(self):
     self.m3 = PDBModel(t.testRoot('pdbclean/foldx_citche.pdb'))
     self.m3 = self.m3.takeChains([1])  # pick second chain; has chain break
     self.c3 = PDBCleaner(self.m3, verbose=self.local, log=self.log) 
     
     m = self.c3.capACE(self.m3, 1, checkgap=False)
     
     self.assertEqual(m.lenChains(breaks=True) -1, 
                      self.m3.lenChains(breaks=True))
Beispiel #39
0
    def __init__(self,
                 model,
                 leap_template=F_leap_in,
                 leaprc=None,
                 leap_out=None,
                 leap_in=None,
                 leap_pdb=None,
                 log=None,
                 debug=0,
                 verbose=0,
                 **kw):
        """
        :param model: model
        :type  model: PDBModel or str
        :param leap_template: path to template file for leap input
        :type  leap_template: str
        :param leaprc: forcefield parameter file or code (e.g. ff99)
        :type  leaprc: str
        :param leap_out: target file for leap.log (default: discard)
        :type  leap_out: str
        :param leap_in: target file for leap.in script (default: discard)
        :type  leap_in: str
        :param kw: kw=value pairs for additional options in the leap_template
        :type  kw: key=value
        """
        self.m = PDBModel(model)

        self.leap_template = leap_template
        self.leaprc = leaprc

        self.leap_pdb = leap_pdb or tempfile.mktemp('_leap_pdb')
        self.keep_leap_pdb = leap_pdb is not None

        self.leap_in = leap_in
        self.leap_out = leap_out

        self.log = log or StdLog()

        self.output = None  # last output of leap

        self.debug = debug
        self.verbose = verbose

        self.__dict__.update(kw)
Beispiel #40
0
    def test_surfaceRacerTools(self):
        """surfaceRacerTools test"""
        from biskit import PDBModel
        import biskit.tools as T

        ## load a structure
        self.m = PDBModel(T.testRoot() + '/lig/1A19.pdb')
        self.m = self.m.compress(self.m.maskProtein())
        self.m = self.m.compress(self.m.maskHeavy())

        ## some fake surface data
        surf = N0.ones(self.m.lenAtoms()) * 10.0

        relExp = relExposure(self.m, surf)

        ##         if self.local:
        ##             globals().update( locals() )

        self.assertAlmostEqual(N0.sum(relExp), 44276.86085222386, 8)
Beispiel #41
0
    def parseReference(self, fpdb, dry_out=None ):
        flushPrint("parsing "+fpdb+"...")
        m = PDBModel( fpdb )
        
        solute_res = m.atom2resMask( N.logical_not( m.maskSolvent() )  )
        
        self.lenres = self.lenres or N.sum( solute_res)
        assert isinstance( self.lenres, N.integer )
        
        self.lenatoms = len( m ) - N.sum( m.maskH2O() )
        assert isinstance( self.lenatoms, N.integer)

        if dry_out:
            m.remove( m.maskH2O() )
            m.writePdb( dry_out )
        flushPrint('done.\n')
Beispiel #42
0
class Test(BT.BiskitTest):
    """Test"""

    def test_ReduceCoordinates(self):
        """ReduceCoordinates test"""

        self.m = PDBModel( T.testRoot()+'/com/1BGS.pdb' )
        self.m = self.m.compress( N0.logical_not( self.m.maskH2O() ) )

        self.m.atoms.set('test', list(range(len(self.m))))

        self.red = ReduceCoordinates( self.m, 4 )

        self.mred = self.red.reduceToModel()
        
        if self.local:
            print('\nAtoms before reduction %i'% self.m.lenAtoms())
            print('Atoms After reduction %i'% self.mred.lenAtoms())

        self.assertEqual( self.mred.lenAtoms(), 445 )
Beispiel #43
0
    def test_AmberParmMirror(self):
        """AmberParmBuilder.parmMirror test"""
        ref = self.ref
        mask = N0.logical_not( ref.maskH2O() ) ## keep protein and Na+ ion
        self.mdry = ref.compress( mask )

        self.a = AmberParmBuilder( self.mdry, verbose=self.local,
                                   leap_out=self.leapout,
                                   debug=self.DEBUG )

        self.a.parmMirror(f_out=self.dryparm,
                          f_out_crd=self.drycrd )

        self.a.parm2pdb( self.dryparm, self.drycrd, self.drypdb )

        self.m1 = PDBModel(self.drypdb)
        self.m2 = PDBModel(self.refdry)

        eq = N0.array( self.m1.xyz == self.m2.xyz )
        self.assertTrue( eq.all() )
Beispiel #44
0
 def __init__( self, fpdb, log=None, verbose=True ):
     """
     :param fpdb: pdb file OR PDBModel instance
     :type  fpdb: str OR Biskit.PDBModel
     :param log: biskit.LogFile object (default: STDOUT)
     :type  log: biskit.LogFile
     :param verbose: log warnings and infos (default: True)
     :type  verbose: bool
     """
     self.model = PDBModel( fpdb )
     self.log = log or StdLog()
     self.verbose = verbose
Beispiel #45
0
    def prepare(self):
        root = T.testRoot('amber/leap/')
        self.ref = PDBModel( T.testRoot('amber/leap/1HPT_solvated.pdb'))
        self.refdry = root + '1HPT_dry.pdb'

        self.dryparm = tempfile.mktemp('.parm', 'dry_')
        self.drycrd  = tempfile.mktemp('.crd', 'dry_')
        self.drypdb  = tempfile.mktemp('.pdb', 'dry_')
        self.wetparm = tempfile.mktemp('.parm', 'wet_')
        self.wetcrd  = tempfile.mktemp('.crd', 'wet_')
        self.wetpdb  = tempfile.mktemp('.pdb', 'wet_')
        self.leapout = tempfile.mktemp('.out', 'leap_')
Beispiel #46
0
class Test(BT.BiskitTest):
    """Test case"""

    def test_surfaceRacerTools(self):
        """surfaceRacerTools test"""
        from biskit import PDBModel
        import biskit.tools as T
        
        ## load a structure
        self.m = PDBModel( T.testRoot()+'/lig/1A19.pdb' )
        self.m = self.m.compress( self.m.maskProtein() )
        self.m = self.m.compress( self.m.maskHeavy() )
        
        ## some fake surface data
        surf = N0.ones( self.m.lenAtoms()) * 10.0

        relExp = relExposure( self.m, surf )
        
##         if self.local:
##             globals().update( locals() )
            
        self.assertAlmostEqual( N0.sum(relExp), 44276.86085222386, 8 )
Beispiel #47
0
    def test_errorcase1( self ):
        """bindinEnergyDelphi test (error case 01)"""
        self.m = PDBModel( T.testRoot() + '/delphi/case01.pdb' )
        rec = self.m.takeChains( [0,1] )
        lig = self.m.takeChains( [2] )
        self.com = Complex( rec, lig )
        
        self.dG = DelphiBindingEnergy( self.com, log = self.log, scale=0.5,
                                       verbose=self.local )
        self.r = self.dG.run()

        if self.local:
            self.log.add(
                '\nFinal result: dG = %3.2f kcal/mol'%self.r['dG_kcal'])
Beispiel #48
0
    def test_SurfaceRacer(self):
        """SurfaceRacer test"""

        from biskit import PDBModel
        import biskit.mathUtils as MA
        import numpy as N

        if self.local: print('Loading PDB...')
        f = T.testRoot('/lig/1A19.pdb')
        m = PDBModel(f)
        m = m.compress( m.maskProtein() )

        if self.local: print('Starting SurfaceRacer')

        self.x = SurfaceRacer( m, 1.4, vdw_set=1, debug=self.DEBUG, verbose=0 )

        if self.local:
            print('Running ...')

        self.r = self.x.run()

        c= self.r['curvature']
        ms= self.r['MS']

        if self.local:
            print("Curvature: weighted mean %.6f and standard deviation %.3f"\
                  %(MA.wMean(c,ms), MA.wSD(c,ms)))

            print('Relative MS of atoms 10 to 20:',self.r['relMS'][10:20])

            print('Relative AS of atoms 10 to 20:',self.r['relAS'][10:20])

        self.e = ( N0.sum(self.r['relMS'][10:20]), N0.sum(self.r['relAS'][10:20]),
              N0.sum(self.r['curvature'][10:20]) )

        delta = N.sum(N.abs(N.array(self.e) - N.array(self.EXPECT)))
        self.assertAlmostEqual( delta, 0.0, 5 )
Beispiel #49
0
    def __init__( self, fcrd, fref, box=0, rnAmber=0, pdbCode=None,
                  log=StdLog(), verbose=0 ):
        """
        :param fcrd: path to input coordinate file
        :type  fcrd: str
        :param fref: PDB or pickled PDBModel with same atom content and order
        :type  fref: str
        :param box: expect line with box info at the end of each frame
                    (default: 0)
        :type  box: 1|0
        :param rnAmber: rename amber style residues into standard (default: 0)
        :type  rnAmber: 1|0
        :param pdbCode: pdb code to be put into the model (default: None)
        :type  pdbCode: str
        :param log: LogFile instance [Biskit.StdLog]
        :type  log: biskit.LogFile
        :param verbose: print progress to log [0]
        :type  verbose: int
        """
        self.fcrd = T.absfile( fcrd )
        self.crd  = T.gzopen( self.fcrd )

        self.ref  = PDBModel( T.absfile(fref), pdbCode=pdbCode )
        self.box  = box

        self.n = self.ref.lenAtoms()

        self.log = log
        self.verbose = verbose

        if rnAmber:
            self.ref.renameAmberRes()

        ## pre-compile pattern for line2numbers
        xnumber = "-*\d+\.\d+"              # optionally negtive number
        xspace  = ' *'                      # one or more space char
        self.xnumbers = re.compile('('+xspace+xnumber+')')

        ## pre-compute lines expected per frame
        self.lines_per_frame = self.n * 3 // 10

        if self.n % 10 != 0:  self.lines_per_frame += 1
        if self.box:          self.lines_per_frame += 1
Beispiel #50
0
    def __init__( self, model,
                  leap_template=F_leap_in,
                  leaprc=None,
                  leap_out=None, leap_in=None,
                  leap_pdb=None,
                  log=None,
                  debug=0,
                  verbose=0,
                  **kw ):
        """
        :param model: model
        :type  model: PDBModel or str
        :param leap_template: path to template file for leap input
        :type  leap_template: str
        :param leaprc: forcefield parameter file or code (e.g. ff99)
        :type  leaprc: str
        :param leap_out: target file for leap.log (default: discard)
        :type  leap_out: str
        :param leap_in: target file for leap.in script (default: discard)
        :type  leap_in: str
        :param kw: kw=value pairs for additional options in the leap_template
        :type  kw: key=value
        """
        self.m = PDBModel( model )

        self.leap_template = leap_template
        self.leaprc  = leaprc

        self.leap_pdb = leap_pdb or tempfile.mktemp( '_leap_pdb' )
        self.keep_leap_pdb = leap_pdb is not None

        self.leap_in = leap_in
        self.leap_out= leap_out

        self.log = log or StdLog()
        
        self.output = None   # last output of leap

        self.debug = debug
        self.verbose = verbose

        self.__dict__.update( kw )
Beispiel #51
0
    def addProperty( self, values, key='temperature_factor' ):
        """
        Add extra value to each atom in Structure. The values
        will be written to either the B- (temperature_factor)
        or Q-factor 'occupancy' column in the temporary pdb-file.
        These values can then be used to display properties in PyMol
        via commands like 'color_b' and 'color_q'. See also
        L{addResProperty}.

        @param values: list of numbers, len( values ) == number of atoms
        @type  values: [float]      
        @param key: key for Atom.properties dictionary
                    ('occupancy' OR 'temperature_factor')
        @type  key: occupancy|temperature_factor
        """
        if self.struct is None:
            self.struct = PDBModel( self.fname )
            self.temporary = 1

        self.struct[ key ] = values
Beispiel #52
0
    def test_AmberParmSolvated( self ):
        """AmberParmBuilder.parmSolvated test"""
        ## remove waters and hydrogens
        self.mdry = self.ref.compress( self.ref.maskProtein() )
        self.mdry = self.mdry.compress( self.mdry.maskHeavy() )

        self.a = AmberParmBuilder( self.mdry,
                                   leap_out=self.leapout,
                                   verbose=self.local, debug=self.DEBUG)

        self.a.parmSolvated( self.wetparm, f_out_crd=self.wetcrd,
                             f_out_pdb=self.wetpdb,
                             box=2.5 )

        self.m3 = PDBModel( self.wetpdb )

        m3prot = self.m3.compress( self.m3.maskProtein() )
        refprot= self.ref.compress( self.ref.maskProtein() )
        refprot.xplor2amber()
        
        self.assertEqual( self.ref.lenChains(), self.m3.lenChains() )
        self.assertEqual( refprot.atomNames(), m3prot.atomNames() )
Beispiel #53
0
    def addResProperty( self, values, key='temperature_factor'):
        """
        Does the same thing as L{addProperty} but on the residue level,
        i.e adds extra value to each residue in Structure.
        (The same value is added to all atoms of a residue.)
        These values can then be used to display properties in PyMol
        via commands like 'color_b' and 'color_q'.
        
        @param values: list of numbers, len( values ) == number of residues
        @type  values: [float]      
        @param key: key for Atom.properties dictionary
                    ('occupancy' OR 'temperature_factor')
        @type  key: occupancy|temperature_factor
        """
        try:
            if self.struct is None:
                self.struct = PDBModel( self.fname )
                self.temporary = 1

            self.struct[ key ] = self.struct.res2atomProfile( values )
        except:
            print(T.lastError())
Beispiel #54
0
class Test(BT.BiskitTest):
    """Test class """

    def prepare(self):
        from biskit import LogFile
        import tempfile


    def test_PDBCleaner( self ):
        """PDBCleaner general test"""
        
        ## Loading PDB...
        self.c = PDBCleaner( t.testRoot() + '/rec/1A2P_rec_original.pdb',
                             log=self.log,
                             verbose=self.local)
        
        self.m = self.c.process()

        self.assertAlmostEqual( self.m.mass(), 34029.0115499993, 7 )
        
    def test_DNACleaning( self ):
        """PDBCleaner DNA test"""
        ## Loading PDB...
        self.c = PDBCleaner( t.testRoot() + 'amber/entropy/0_com.pdb',
                             log=self.log, verbose=self.local )
        
        self.dna = self.c.process(amber=True)

        self.assertAlmostEqual( self.dna.mass(), 26953.26, 1 )
        
        
    def test_Capping( self ):
        """PDBCleaner.capTerminals test"""
        ## Loading PDB...
        self.model = PDBModel(t.testRoot() + '/rec/1A2P_rec_original.pdb')

        self.c = PDBCleaner( self.model, log=self.log, verbose=self.local )       
        self.m2 = self.c.capTerminals( breaks=True )
        self.assertTrue( self.m2.atomNames() == self.model.atomNames() )
        
        self.m3 = self.model.clone()
        self.m3.removeRes( [10,11,12,13,14,15] )
        self.m4 = self.m3.clone()
        
        self.c = PDBCleaner( self.m3, log=self.log, verbose=self.local )
        self.m3 = self.c.capTerminals( breaks=True, capC=[0], capN=[0,1])
        self.assertEqual( self.m3.takeChains([0]).sequence()[:18], 
                          'XVINTFDGVADXXKLPDN' )
        
        if self.local:
            self.log.add( '\nTesting automatic chain capping...\n' )
        
        self.c = PDBCleaner( self.m4, log=self.log, verbose=self.local )
        self.m4 = self.c.capTerminals( auto=True )
        self.assertEqual( self.m4.takeChains([0]).sequence()[:18], 
                          'XVINTFDGVADXXKLPDN' )
        
        
    def test_capping_internal(self):
        self.m3 = PDBModel(t.testRoot('pdbclean/foldx_citche.pdb'))
        self.m3 = self.m3.takeChains([1])  # pick second chain; has chain break
        self.c3 = PDBCleaner(self.m3, verbose=self.local, log=self.log) 
        
        m = self.c3.capACE(self.m3, 1, checkgap=False)
        
        self.assertEqual(m.lenChains(breaks=True) -1, 
                         self.m3.lenChains(breaks=True))
Beispiel #55
0
    def capACE( self, model, chain, breaks=True, checkgap=True ):
        """
        Cap N-terminal of given chain.

        Note: In order to allow the capping of chain breaks,
        the chain index is, by default, based on model.chainIndex(breaks=True), 
        that means with chain break detection activated! This is not the 
        default behaviour of PDBModel.chainIndex or takeChains or chainLength. 
        Please use the wrapping method capTerminals() for more convenient 
        handling of the index.

        :param model: model
        :type  model: PDBMode
        :param chain: index of chain to be capped
        :type  chain: int
        :param breaks: consider chain breaks when identifying chain boundaries
        :type  breaks: bool
        
        :return: model with added NME capping
        :rtype : PDBModel
        """
        if self.verbose:
            self.logWrite('Capping N-terminal of chain %i with ACE' % chain )

        c_start = model.chainIndex( breaks=breaks )
        c_end = model.chainEndIndex( breaks=breaks)
        Nterm_is_break = False
        Cterm_is_break = False
        
        if breaks:
            Nterm_is_break = c_start[chain] not in model.chainIndex()
            Cterm_is_break = c_end[chain] not in model.chainEndIndex()
            
        m_ace = PDBModel( self.F_ace_cap )

        chains_before = model.takeChains( range(chain), breaks=breaks )
        m_chain       = model.takeChains( [chain], breaks=breaks )
        chains_after  = model.takeChains( range(chain+1, len(c_start)),
                                          breaks=breaks )

        m_term  = m_chain.resModels()[0]

        ## we need 3 atoms for superposition, CB might mess things up but
        ## could help if there is no HN
        ##        if 'HN' in m_term.atomNames():
        m_ace.remove( ['CB'] )  ## use backbone 'C' rather than CB for fitting 

        ## rename overhanging residue in cap PDB
        for a in m_ace:
            if a['residue_name'] != 'ACE':
                a['residue_name'] = m_term.atoms['residue_name'][0]
            else:
                a['residue_number'] = m_term.atoms['residue_number'][0]-1
                a['chain_id']       = m_term.atoms['chain_id'][0]
                a['segment_id']     = m_term.atoms['segment_id'][0]

        ## fit cap onto first residue of chain
        m_ace = m_ace.magicFit( m_term )

        cap = m_ace.resModels()[0]
        serial = m_term['serial_number'][0] - len(cap)
        cap['serial_number'] = list(range( serial, serial + len(cap)))

        ## concat cap on chain
        m_chain = cap.concat( m_chain, newChain=False )

        ## re-assemble whole model
        r = chains_before.concat( m_chain, newChain=not Nterm_is_break)
            
        r = r.concat( chains_after, newChain=not Cterm_is_break)
        
        if checkgap and len(c_start) != r.lenChains( breaks=breaks ):
            raise CappingError('Capping ACE would mask a chain break. '+\
                  'This typically indicates a tight gap with high risk of '+\
                  'clashes and other issues.')

        return r
Beispiel #56
0
class PDBCleaner:
    """
    PDBCleaner performs the following tasks:
    
      * remove HETAtoms from PDB
      * replace non-standard AA by its closest standard AA
      * remove non-standard atoms from standard AA residues
      * delete atoms that follow missing atoms (in a chain)
      * remove multiple occupancy atoms (except the one with highest occupancy)
      * add ACE and NME capping residues to C- and N-terminals or chain breaks
        (see capTerminals(), this is NOT done automatically in process())

    Usage:
    =======

      >>> c = PDBCleaner( model )
      >>> c.process()
      >>> c.capTerminals( auto=True )

    This will modify the model in-place and report changes to STDOUT.
    Alternatively, you can specify a log file instance for the output.
    PDBCleaner.process accepts several options to modify the processing.
    
    Capping
    =======
    
    Capping will add N-methyl groups to free C-terminal carboxy ends
    or Acetyl groups to free N-terminal Amines and will thus 'simulate' the
    continuation of the protein chain -- a common practice in order to 
    prevent fake terminal charges. The automatic discovery of missing residues
    is guess work at best. The more conservative approach is to use,
    for example:
    
      >>> c.capTerminals( breaks=1, capC=[0], capN=[2] )
      
    In this case, only the chain break detection is used for automatic capping
    -- the last residue before a chain break is capped with NME and the first
    residue after the chain break is capped with ACE. Chain break detection
    relies on PDBModel.chainBreaks() (via PDBModel.chainIndex( breaks=1 )).
    The normal terminals to be capped are now specified explicitely. The first
    chain (not counting chain breaks) will receive a NME C-terminal cap and the
    third chain of the PDB will receive a N-terminal ACE cap. 
    
    Note: Dictionaries with standard residues and atom content are defined
          in Biskit.molUtils. This is a duplicate effort with the new strategy
          to parse Amber prep files for very similar information
          (AmberResidueType, AmberResidueLibrary) and should change once we 
          implement a real framework for better residue handling. 
    """
    
    #: these atoms always occur at the tip of of a chain or within a ring
    #: and, if missing, will not trigger the removal of other atoms
    TOLERATE_MISSING = ['O', 'CG2', 'CD1', 'CD2', 'OG1', 'OE1', 'NH1',
                        'OD1', 'OE1',
                        'H5T',"O5'", ]

    ## PDB with ACE capping residue
    F_ace_cap = t.dataRoot() + '/amber/leap/ace_cap.pdb'
    ## PDB with NME capping residue
    F_nme_cap = t.dataRoot() + '/amber/leap/nme_cap.pdb'

    def __init__( self, fpdb, log=None, verbose=True ):
        """
        :param fpdb: pdb file OR PDBModel instance
        :type  fpdb: str OR Biskit.PDBModel
        :param log: biskit.LogFile object (default: STDOUT)
        :type  log: biskit.LogFile
        :param verbose: log warnings and infos (default: True)
        :type  verbose: bool
        """
        self.model = PDBModel( fpdb )
        self.log = log or StdLog()
        self.verbose = verbose


    def logWrite( self, msg, force=1 ):
        if self.log:
            self.log.add( msg )
        else:
            if force:
                print(msg)

    def remove_multi_occupancies( self ):
        """
        Keep only atoms with alternate A field (well, or no alternate).
        """
        if self.verbose:
            self.logWrite( self.model.pdbCode +
                           ': Removing multiple occupancies of atoms ...')

        i = 0
        to_be_removed = []

        for a in self.model:

            if a['alternate']:
                try:
                    str_id = "%i %s %s %i" % (a['serial_number'], a['name'],
                                              a['residue_name'],
                                              a['residue_number'])

                    if a['alternate'].upper() in ['A', '1']:
                        a['alternate'] = ''

                    else:
                        if float( a['occupancy'] ) < 1.0:
                            to_be_removed += [ i ]
                            if self.verbose:
                                self.logWrite(
                                    'removing %s (%s %s)' %
                                    (str_id,a['alternate'], a['occupancy']))
                        else:
                            if self.verbose:
                                self.logWrite(
                                 ('keeping non-A duplicate %s because of 1.0 '+
                                  'occupancy') % str_id )

                except:
                    self.logWrite("Error removing duplicate: "+t.lastError() )
            i+=1

        try:
            self.model.remove( to_be_removed )
            if self.verbose:
                self.logWrite('Removed %i atoms' % len( to_be_removed ) )

        except:
            if self.verbose:
                self.logWrite('No atoms with multiple occupancies to remove' )


    def replace_non_standard_AA( self, amber=0, keep=[] ):
        """
        Replace amino acids with none standard names with standard
        amino acids according to :class:`MU.nonStandardAA`
        
        :param amber: don't rename HID, HIE, HIP, CYX, NME, ACE [0]
        :type  amber: 1||0
        :param keep: names of additional residues to keep
        :type keep:  [ str ]
        """
        standard = list(MU.atomDic.keys()) + keep

        if amber:
            standard.extend( ['HID', 'HIE', 'HIP', 'CYX', 'NME', 'ACE'] )

        replaced = 0

        if self.verbose:
            self.logWrite(self.model.pdbCode +
                          ': Looking for non-standard residue names...')

        resnames = self.model['residue_name']
        for i in self.model.atomRange():

            resname = resnames[i].upper()

            if resname not in standard:
                if resname in MU.nonStandardAA:
                    resnames[i] = MU.nonStandardAA[ resname ]

                    if self.verbose:
                        self.logWrite('renamed %s %i to %s' % \
                                     (resname, i, MU.nonStandardAA[ resname ]))
                else:
                    resnames[i] = 'ALA'

                    self.logWrite('Warning: unknown residue name %s %i: ' \
                                  % (resname, i ) )
                    if self.verbose:
                        self.logWrite('\t->renamed to ALA.')

                replaced += 1

        if self.verbose:
            self.logWrite('Found %i atoms with non-standard residue names.'% \
                          replaced )


    def __standard_res( self, resname, amber=0 ):
        """
        Check if resname is a standard residue (according to :class:`MU.atomDic`)
        if not return the closest standard residue (according to
        :class:`MU.nonStandardAA`).
        
        :param resname: 3-letter residue name
        :type  resname: str
        
        :return: name of closest standard residue or resname itself
        :rtype: str
        """
        if resname in MU.atomDic:
            return resname

        if resname in MU.nonStandardAA:
            return MU.nonStandardAA[ resname ]

        return resname


    def remove_non_standard_atoms( self ):
        """
        First missing standard atom triggers removal of standard atoms that
        follow in the standard order. All non-standard atoms are removed too.
        Data about standard atoms are taken from :class:`MU.atomDic` and symomym
        atom name is defined in :class:`MU.atomSynonyms`.
        
        :return: number of atoms removed
        :rtype: int
        """
        mask = []
        
        if self.verbose:
            self.logWrite("Checking content of standard amino-acids...")

        for res in self.model.resList():

            resname  = self.__standard_res( res[0]['residue_name'] ).upper()
            if resname == 'DC5':
                pass
            
            ## bugfix: ignore non-standard residues that have no matching 
            ## standard residue
            if resname in MU.atomDic:
                
                standard = copy.copy( MU.atomDic[ resname ] )
    
                ## replace known synonyms by standard atom name
                for a in res:
                    n = a['name']
                    if not n in standard and MU.atomSynonyms.get(n,0) in standard:
                        a['name'] = MU.atomSynonyms[n]
                        if self.verbose:
                            self.logWrite('%s: renaming %s to %s in %s %i' %\
                                          ( self.model.pdbCode, n, a['name'],
                                           a['residue_name'], a['residue_number']))
    
                anames   = [ a['name'] for a in res ]
                keep = 1
    
                ## kick out all standard atoms that follow a missing one
                rm = []
                for n in standard:
                    if (not n in anames) and not (n in self.TOLERATE_MISSING):
                        keep = 0
    
                    if not keep:
                        rm += [ n ]
    
                for n in rm:
                    standard.remove( n )
    
                ## keep only atoms that are standard (and not kicked out above)
                for a in res:
    
                    if a['name'] not in standard:
                        mask += [1]
                        if self.verbose:
                            self.logWrite('%s: removing atom %s in %s %i '%\
                                          ( self.model.pdbCode, a['name'],
                                           a['residue_name'], a['residue_number']))
                    else:
                        mask += [0]

        self.model.remove( mask )
        
        if self.verbose:
            self.logWrite('Removed ' + str(N0.sum(mask)) +
                          ' atoms because they were non-standard' +
                          ' or followed a missing atom.' )

        return N0.sum( mask )

    def capACE( self, model, chain, breaks=True, checkgap=True ):
        """
        Cap N-terminal of given chain.

        Note: In order to allow the capping of chain breaks,
        the chain index is, by default, based on model.chainIndex(breaks=True), 
        that means with chain break detection activated! This is not the 
        default behaviour of PDBModel.chainIndex or takeChains or chainLength. 
        Please use the wrapping method capTerminals() for more convenient 
        handling of the index.

        :param model: model
        :type  model: PDBMode
        :param chain: index of chain to be capped
        :type  chain: int
        :param breaks: consider chain breaks when identifying chain boundaries
        :type  breaks: bool
        
        :return: model with added NME capping
        :rtype : PDBModel
        """
        if self.verbose:
            self.logWrite('Capping N-terminal of chain %i with ACE' % chain )

        c_start = model.chainIndex( breaks=breaks )
        c_end = model.chainEndIndex( breaks=breaks)
        Nterm_is_break = False
        Cterm_is_break = False
        
        if breaks:
            Nterm_is_break = c_start[chain] not in model.chainIndex()
            Cterm_is_break = c_end[chain] not in model.chainEndIndex()
            
        m_ace = PDBModel( self.F_ace_cap )

        chains_before = model.takeChains( range(chain), breaks=breaks )
        m_chain       = model.takeChains( [chain], breaks=breaks )
        chains_after  = model.takeChains( range(chain+1, len(c_start)),
                                          breaks=breaks )

        m_term  = m_chain.resModels()[0]

        ## we need 3 atoms for superposition, CB might mess things up but
        ## could help if there is no HN
        ##        if 'HN' in m_term.atomNames():
        m_ace.remove( ['CB'] )  ## use backbone 'C' rather than CB for fitting 

        ## rename overhanging residue in cap PDB
        for a in m_ace:
            if a['residue_name'] != 'ACE':
                a['residue_name'] = m_term.atoms['residue_name'][0]
            else:
                a['residue_number'] = m_term.atoms['residue_number'][0]-1
                a['chain_id']       = m_term.atoms['chain_id'][0]
                a['segment_id']     = m_term.atoms['segment_id'][0]

        ## fit cap onto first residue of chain
        m_ace = m_ace.magicFit( m_term )

        cap = m_ace.resModels()[0]
        serial = m_term['serial_number'][0] - len(cap)
        cap['serial_number'] = list(range( serial, serial + len(cap)))

        ## concat cap on chain
        m_chain = cap.concat( m_chain, newChain=False )

        ## re-assemble whole model
        r = chains_before.concat( m_chain, newChain=not Nterm_is_break)
            
        r = r.concat( chains_after, newChain=not Cterm_is_break)
        
        if checkgap and len(c_start) != r.lenChains( breaks=breaks ):
            raise CappingError('Capping ACE would mask a chain break. '+\
                  'This typically indicates a tight gap with high risk of '+\
                  'clashes and other issues.')

        return r


    def capNME( self, model, chain, breaks=True, checkgap=True ):
        """
        Cap C-terminal of given chain. 

        Note: In order to allow the capping of chain breaks,
        the chain index is, by default, based on model.chainIndex(breaks=True), 
        that means with chain break detection activated! This is not the 
        default behaviour of PDBModel.chainIndex or takeChains or chainLength.
        Please use the wrapping method capTerminals() for more convenient 
        handling of the index.

        :param model: model
        :type  model: PDBMode
        :param chain: index of chain to be capped
        :type  chain: int
        :param breaks: consider chain breaks when identifying chain boundaries
        :type  breaks: bool
        
        :return: model with added NME capping residue
        :rtype : PDBModel
        """
        if self.verbose:
            self.logWrite('Capping C-terminal of chain %i with NME.' % chain )
        m_nme   = PDBModel( self.F_nme_cap )

        c_start = model.chainIndex( breaks=breaks )
        c_end = model.chainEndIndex( breaks=breaks)

        Nterm_is_break = False
        Cterm_is_break = False
        if breaks:
            Nterm_is_break = c_start[chain] not in model.chainIndex()
            Cterm_is_break = c_end[chain] not in model.chainEndIndex()
         
        chains_before = model.takeChains( range(chain), breaks=breaks )
        m_chain       = model.takeChains( [chain], breaks=breaks )
        chains_after  = model.takeChains( range(chain+1, len(c_start)),
                                          breaks=breaks )

        m_term  = m_chain.resModels()[-1]

        ## rename overhanging residue in cap PDB, renumber cap residue
        for a in m_nme:
            if a['residue_name'] != 'NME':
                a['residue_name'] = m_term.atoms['residue_name'][0]
            else:
                a['residue_number'] = m_term.atoms['residue_number'][0]+1
                a['chain_id']       = m_term.atoms['chain_id'][0]
                a['segment_id']     = m_term.atoms['segment_id'][0]

        ## chain should not have any terminal O after capping
        m_chain.remove( ['OXT'] )            

        ## fit cap onto last residue of chain
        m_nme = m_nme.magicFit( m_term )
        
        cap = m_nme.resModels()[-1]
        serial = m_term['serial_number'][-1]+1
        cap['serial_number'] = list(range( serial, serial + len(cap)))

        ## concat cap on chain
        m_chain = m_chain.concat( cap, newChain=False )

        ## should be obsolete now
        if getattr( m_chain, '_PDBModel__terAtoms', []) != []:
            m_chain._PDBModel__terAtoms = [ len( m_chain ) - 1 ]
        assert m_chain.lenChains() == 1

        ## re-assemble whole model
        r = chains_before.concat( m_chain, newChain=not Nterm_is_break)
        r = r.concat( chains_after, newChain=not Cterm_is_break)

        if checkgap and len(c_start) != r.lenChains( breaks=breaks ):
            raise CappingError('Capping NME would mask a chain break. '+\
                  'This typically indicates a tight gap with high risk of '+\
                  'clashes and other issues.')
        
        return r


    def convertChainIdsNter( self, model, chains ):
        """
        Convert normal chain ids to chain ids considering chain breaks.
        """
        if len(chains) == 0: 
            return chains
        i = N0.take( model.chainIndex(), chains ) 
        ## convert back to chain indices but this time including chain breaks
        return model.atom2chainIndices( i, breaks=1 )
        
    def convertChainIdsCter( self, model, chains ):
        """
        Convert normal chain ids to chain ids considering chain breaks.
        """
        if len(chains) == 0: 
            return chains
        ## fetch last atom of given chains
        index = N0.concatenate( (model.chainIndex(), [len(model)]) )
        i = N0.take( index, N0.array( chains ) + 1 ) - 1
        ## convert back to chain indices but this time including chain breaks
        return model.atom2chainIndices( i, breaks=1 )
    

    def unresolvedTerminals( self, model ):
        """
        Autodetect (aka "guess") which N- and C-terminals are most likely not
        the real end of each chain. This guess work is based on residue 
        numbering:
        
        * unresolved N-terminal: a protein residue with a residue number > 1

        * unresolved C-terminal: a protein residue that does not contain either
                               OXT or OT or OT1 or OT2 atoms
                               
        :param model: PDBModel
        
        :return: chains with unresolved N-term, with unresolved C-term
        :rtype : ([int], [int])
        """
        c_first = model.chainIndex()
        c_last  = model.chainEndIndex()
        
        capN = [ i for (i,pos) in enumerate(c_first)\
                 if model['residue_number'][pos] > 1 ]
        
        capN = [i for i in capN if model['residue_name'][c_first[i]] != 'ACE']
        
        capN = self.filterProteinChains( model, capN, c_first )
        
        capC = []
        for (i,pos) in enumerate(c_last):
            atoms = model.takeResidues(model.atom2resIndices([pos])).atomNames()
            
            if not( 'OXT' in atoms or 'OT' in atoms or 'OT1' in atoms or \
                    'OT2' in atoms ):
                capC += [ i ]

        capC = self.filterProteinChains( model, capC, c_last )
                  
        return capN, capC
    
    #@todo filter for protein positions in breaks=1

    def filterProteinChains( self, model, chains, chainindex ):
        maskProtein = model.maskProtein()
        chains = [ i for i in chains if maskProtein[ chainindex[i] ] ]
        return chains

    def capTerminals( self, auto=False, breaks=False, capN=[], capC=[],
                      checkgap=True):
        """
        Add NME and ACE capping residues to chain breaks or normal N- and 
        C-terminals. Note: these capping residues contain hydrogen atoms.
        
        Chain indices for capN and capC arguments can be interpreted either
        with or without chain break detection enabled. For example, let's
        assume we have a two-chain protein with some missing residues (chain
        break) in the first chain:
        
        A:   MGSKVSK---FLNAGSK
        B:   FGHLAKSDAK

        Then:
          capTerminals( breaks=False, capN=[1], capC=[1]) will add N-and 
          C-terminal caps to chain B.
        However:
          capTerminals( breaks=True, capN=[1], capC=[1]) will add N- and 
          C-terminal caps to the second fragment of chain A.
          
        
        Note: this operation *replaces* the internal model.
        
        :param auto: put ACE and NME capping residue on chain breaks
                     and on suspected false N- and C-termini (default: False)
        :type  auto: bool
        :param breaks: switch on chain break detection before interpreting
                       capN and capC
        :type  breaks: False
        :param capN: indices of chains that should get ACE cap (default: [])
        :type  capN: [int]
        :param capC: indices of chains that should get NME cap (default: [])
        :type  capC: [int]
        """
        m = self.model
        c_len = m.lenChains()
        i_breaks = m.chainBreaks()
            
        if auto:
            if not breaks:
                capN = self.convertChainIdsNter( m, capN )
                capC = self.convertChainIdsCter( m, capC )

            breaks=True
            capN, capC = self.unresolvedTerminals( m )
        
            end_broken = m.atom2chainIndices( m.chainBreaks(), breaks=1 )
            
            capC = M.union( capC, end_broken )
            capN = M.union( capN, N0.array( end_broken ) + 1 )
            
        capN = self.filterProteinChains(m, capN, m.chainIndex(breaks=breaks))
        capC = self.filterProteinChains(m, capC, m.chainEndIndex(breaks=breaks))

        for i in capN:
            m = self.capACE( m, i, breaks=breaks, checkgap=checkgap )
            assert m.lenChains() == c_len, '%i != %i' % \
                   (m.lenChains(), c_len)
            assert len(m.chainBreaks(force=True)) == len(i_breaks)
            assert m['serial_number'].dtype == N0.Int32, 'serial_number not int'

        for i in capC:
            m = self.capNME( m, i, breaks=breaks, checkgap=checkgap )
            assert m.lenChains() == c_len
            assert len(m.chainBreaks(force=True)) == len(i_breaks)
        
        self.model = m
        return self.model

    
    
    def process( self, keep_hetatoms=0, amber=0, keep_xaa=[] ):
        """
        Remove Hetatoms, waters. Replace non-standard names.
        Remove non-standard atoms.
        
        :param keep_hetatoms: option
        :type  keep_hetatoms: 0||1
        :param amber: don't rename amber residue names (HIE, HID, CYX,..)
        :type  amber: 0||1
        :param keep_xaa: names of non-standard residues to be kept
        :type  keep_xaa: [ str ]
        
        :return: PDBModel (reference to internal)
        :rtype: PDBModel
        
        :raise CleanerError: if something doesn't go as expected ...
        """
        try:
            if not keep_hetatoms:
                self.model.remove( self.model.maskHetatm() )

            self.model.remove( self.model.maskH2O() )

            self.model.remove( self.model.maskH() )

            self.remove_multi_occupancies()

            self.replace_non_standard_AA( amber=amber, keep=keep_xaa )

            self.remove_non_standard_atoms()


        except KeyboardInterrupt as why:
            raise KeyboardInterrupt( why )
        except Exception as why:
            self.logWrite('Error: '+t.lastErrorTrace())
            raise CleanerError( 'Error cleaning model: %r' % why )

        return self.model
Beispiel #57
0
class PymolModel:

    def __init__( self, model, modName ):
        """
        @param model: model to view
        @type  model: PDBModel
        @param modName: model name, will show up in PyMol
        @type  modName: str
        """
        self.fname = ''
        self.temporary = 0
        self.struct = None

        if type( model ) is str:
            self.fname = model
        else:
            self.struct = model.clone() ## clone atom dicts
            self.temporary = 1

        self.modName = modName

        if self.fname == '':
            self.fname = tempfile.mktemp( 'model')


    def addProperty( self, values, key='temperature_factor' ):
        """
        Add extra value to each atom in Structure. The values
        will be written to either the B- (temperature_factor)
        or Q-factor 'occupancy' column in the temporary pdb-file.
        These values can then be used to display properties in PyMol
        via commands like 'color_b' and 'color_q'. See also
        L{addResProperty}.

        @param values: list of numbers, len( values ) == number of atoms
        @type  values: [float]      
        @param key: key for Atom.properties dictionary
                    ('occupancy' OR 'temperature_factor')
        @type  key: occupancy|temperature_factor
        """
        if self.struct is None:
            self.struct = PDBModel( self.fname )
            self.temporary = 1

        self.struct[ key ] = values


    def addResProperty( self, values, key='temperature_factor'):
        """
        Does the same thing as L{addProperty} but on the residue level,
        i.e adds extra value to each residue in Structure.
        (The same value is added to all atoms of a residue.)
        These values can then be used to display properties in PyMol
        via commands like 'color_b' and 'color_q'.
        
        @param values: list of numbers, len( values ) == number of residues
        @type  values: [float]      
        @param key: key for Atom.properties dictionary
                    ('occupancy' OR 'temperature_factor')
        @type  key: occupancy|temperature_factor
        """
        try:
            if self.struct is None:
                self.struct = PDBModel( self.fname )
                self.temporary = 1

            self.struct[ key ] = self.struct.res2atomProfile( values )
        except:
            print(T.lastError())


    def writeIfNeeded( self ):
        """
        Create pdb on disc if it's not already there or if it
        has to be changed.
        
        @return: filename of new or existing pdb
        @rtype: str
        """
        if self.temporary:
            self.struct.writePdb( self.fname, 2 )
        return self.fname
Beispiel #58
0
    def capNME( self, model, chain, breaks=True, checkgap=True ):
        """
        Cap C-terminal of given chain. 

        Note: In order to allow the capping of chain breaks,
        the chain index is, by default, based on model.chainIndex(breaks=True), 
        that means with chain break detection activated! This is not the 
        default behaviour of PDBModel.chainIndex or takeChains or chainLength.
        Please use the wrapping method capTerminals() for more convenient 
        handling of the index.

        :param model: model
        :type  model: PDBMode
        :param chain: index of chain to be capped
        :type  chain: int
        :param breaks: consider chain breaks when identifying chain boundaries
        :type  breaks: bool
        
        :return: model with added NME capping residue
        :rtype : PDBModel
        """
        if self.verbose:
            self.logWrite('Capping C-terminal of chain %i with NME.' % chain )
        m_nme   = PDBModel( self.F_nme_cap )

        c_start = model.chainIndex( breaks=breaks )
        c_end = model.chainEndIndex( breaks=breaks)

        Nterm_is_break = False
        Cterm_is_break = False
        if breaks:
            Nterm_is_break = c_start[chain] not in model.chainIndex()
            Cterm_is_break = c_end[chain] not in model.chainEndIndex()
         
        chains_before = model.takeChains( range(chain), breaks=breaks )
        m_chain       = model.takeChains( [chain], breaks=breaks )
        chains_after  = model.takeChains( range(chain+1, len(c_start)),
                                          breaks=breaks )

        m_term  = m_chain.resModels()[-1]

        ## rename overhanging residue in cap PDB, renumber cap residue
        for a in m_nme:
            if a['residue_name'] != 'NME':
                a['residue_name'] = m_term.atoms['residue_name'][0]
            else:
                a['residue_number'] = m_term.atoms['residue_number'][0]+1
                a['chain_id']       = m_term.atoms['chain_id'][0]
                a['segment_id']     = m_term.atoms['segment_id'][0]

        ## chain should not have any terminal O after capping
        m_chain.remove( ['OXT'] )            

        ## fit cap onto last residue of chain
        m_nme = m_nme.magicFit( m_term )
        
        cap = m_nme.resModels()[-1]
        serial = m_term['serial_number'][-1]+1
        cap['serial_number'] = list(range( serial, serial + len(cap)))

        ## concat cap on chain
        m_chain = m_chain.concat( cap, newChain=False )

        ## should be obsolete now
        if getattr( m_chain, '_PDBModel__terAtoms', []) != []:
            m_chain._PDBModel__terAtoms = [ len( m_chain ) - 1 ]
        assert m_chain.lenChains() == 1

        ## re-assemble whole model
        r = chains_before.concat( m_chain, newChain=not Nterm_is_break)
        r = r.concat( chains_after, newChain=not Cterm_is_break)

        if checkgap and len(c_start) != r.lenChains( breaks=breaks ):
            raise CappingError('Capping NME would mask a chain break. '+\
                  'This typically indicates a tight gap with high risk of '+\
                  'clashes and other issues.')
        
        return r