Beispiel #1
0
    def add(self, str):
        """
        Add String str and line break to file.

        @param str: string to add to pml file
        @type  str: str        
        """
        try:
            self.fgenerate.write(str + '\n')
        except (IOError):
            T.errWriteln(
                "PymolInput.add(): Error adding string to pymol script file.")
            T.errWriteln( T.lastError() )
Beispiel #2
0
 def dump( self, o ):
     """
     Try to pickle an object to the currently valid path.
     
     :return: the absolute path to which o was pickled
     :rtype: str
     """
     try:
         f = self.local()
         T.dump( f, o )
         return f
     except:
         T.errWriteln("Couldn't dump to %s (constructed from %s)" %\
                      self.formatted(), self.local() )
         raise
Beispiel #3
0
 def dump(self, o):
     """
     Try to pickle an object to the currently valid path.
     
     :return: the absolute path to which o was pickled
     :rtype: str
     """
     try:
         f = self.local()
         T.dump(f, o)
         return f
     except:
         T.errWriteln("Couldn't dump to %s (constructed from %s)" %\
                      self.formatted(), self.local() )
         raise
Beispiel #4
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 #5
0
    def setResValues( self, model, values, key='temperature_factor',
                      lastOnly=0 ):
        """
        Add numeric value per residue to all atoms of all Structures
        or the last Structure in a model. 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{setAtomValues}.
        
        @param model: model name
        @type  model: str
        @param values: list of numbers, len( values ) == number of residues
        @type  values: [float]      
        @param key: key for Atom.properties dictionary
                    (default: temperature_factor)
        @type  key: occupancy|temperature_factor
        @param lastOnly: 0 - add to all in model OR
                         1 - add only to last Structure (default: 0)
        @type  lastOnly: 1|0
        """
        if lastOnly:
            self.dic[ model ][-1].addResProperty( values, key )

        else:
            for m in self.dic[ model ]:
                try:
                    m.addResProperty( values, key )
                except:
                    T.errWriteln( "Warning: error while adding properties.")
                    T.errWriteln( "Key: "+str( key )+" values: "+str( values ) )
                    T.errWriteln( T.lastError() )
Beispiel #6
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 #7
0
    def getFluct_local( self, mask=None, border_res=1,
                        left_atoms=['C'], right_atoms=['N'], verbose=1 ):
        """
        Get mean displacement of each atom from it's average position after
        fitting of each residue to the reference backbone coordinates of itself
        and selected atoms of neighboring residues to the right and left.

        :param mask: N_atoms x 1 array of 0||1, atoms for which fluctuation
                     should be calculated
        :type  mask: array
        :param border_res: number of neighboring residues to use for fitting
        :type  border_res: int
        :param left_atoms: atoms (names) to use from these neighbore residues
        :type  left_atoms: [str]
        :param right_atoms: atoms (names) to use from these neighbore residues
        :type  right_atoms: [str]

        :return: Numpy array ( N_unmasked x 1 ) of float
        :rtype: array
        """
        if mask is None:
            mask = N0.ones( len( self.frames[0] ), N0.Int32 )

        if verbose: T.errWrite( "rmsd fitting per residue..." )

        residues = N0.nonzero( self.ref.atom2resMask( mask ) )

        ## backbone atoms used for fit
        fit_atoms_right = N0.nonzero( self.ref.mask( right_atoms ) )
        fit_atoms_left  = N0.nonzero( self.ref.mask( left_atoms ) )
        ## chain index of each residue
        rchainMap = N0.take( self.ref.chainMap(), self.ref.resIndex() )

        result = []

        for res in residues:

            i_res, i_border = self.__resWindow(res, border_res, rchainMap,
                                               fit_atoms_left, fit_atoms_right)

            try:
                if not len( i_res ): raise PDBError('empty residue')

                t_res = self.takeAtoms( i_res + i_border )

                i_center = range( len( i_res ) )

                mask_BB = t_res.ref.maskBB() * t_res.ref.maskHeavy()

                ## fit with border atoms ..
                t_res.fit( ref=t_res.ref, mask=mask_BB, verbose=0 )
                ## .. but calculate only with center residue atoms
                frames = N0.take( t_res.frames, i_center, 1 )

                avg = N0.average( frames )

                rmsd = N0.average(N0.sqrt(N0.sum(N0.power(frames - avg, 2), 2) ))

                result.extend( rmsd )

                if verbose: T.errWrite('#')

            except ZeroDivisionError:
                result.extend( N0.zeros( len(i_res), N0.Float32 ) )
                T.errWrite('?' + str( res ))

        if verbose: T.errWriteln( "done" )

        return result