Beispiel #1
0
    def write_pdb_file(self,filename,options):
        """
        Writes a pdb file containing all valid atoms. The bfactor option
        may be set to 'packdens' - substitutes bfactor with packing density.
        'volume' - same with total atomic volume
        'minuspackdens' - same with 1-packing density
        'zscore' - z-score (normalized difference to reference value)
        """
        bfactor = options['bfactor']
        out = []
        # z-score calculation only needed when the b-factor is to
        # be replaced with the z-score
        # actually, the expensive part is not the ZScore initialization
        # but the AveragePacking initialization
        if bfactor == 'zscore':
            zsc = ZScore(AveragePacking(options))
        for i in range(len(self.atoms)):
            if not self.valid[i]:continue
            atom = self.get_atom(i)
            pl = atom['pdb_line']

            # now get the value to be inserted as bfactor
            #
            # For some programs they need to be normalized
            #
            # Hallo Fiete!
            #
            # unter 'packdens' kannst Du dich austoben.
            # Habe ein Beispiel reingeschrieben,
            # in Python sollte etwas Mathe nicht so schwer sein.
            # Aber frag mich trotzdem falls Du im Code versumpfst.
            # 11.7.06 KR
            #
            if bfactor == 'packdens':
                value = atom['packing_density']
                # normalize values from 0.4 to 0.9 to bfactors between 0.0 and 30.
                # 'packdens'
                vmin = 0.4
                vmax = 0.9
                bmin = 0.0
                bmax = 30.0
                value = ((value-vmin)/vmax) * (bmax-bmin) + bmin
                # 
            if bfactor == 'minuspackdens':
                value = 1-atom['packing_density']
                # normalize values from 0.4 to 0.9 to bfactors between 30.0 and 0.0
                # 'minuspackdens'
                vmin = 0.4
                vmax = 0.9
                bmin = 0.0
                bmax = 30.0
                value = ((value-vmin)/vmax) * (bmax-bmin) + bmin
                # 
            elif bfactor == 'volume':
                value = atom['total_volume']
                # nomalize
                # (insert code on demand)
            elif bfactor == 'zscore':
                value = zsc.get_z_score(atom,options)
                if not value: value=100.0
                # normalize
                # (insert code on demand)

            pl = pl[:60]+"%6.2f"%(value)+pl[66:]
            out.append(pl+'\n')
        open(filename,'w').writelines(out)
Beispiel #2
0
    def replace_bfactors(self,infile,outfile,options,check_valid=False):
        """
        Writes the .vol file 'infile' to 'outfile', but replaces the bfactor
        column with either packing density or volume.
        Also adds a short remark before the first atom.
        """
        extralines_pd="""REMARK 
REMARK   COLUMNS MODIFIED FROM ORIGINAL PDB FILE:
REMARK      PD     - LOCAL PACKING DENSITY
REMARK      VDWVOL - VOLUME INSIDE VAN-DER-WAALS SPHERE
REMARK      SEVOL  - VOLUME IN 1.4 ANGSTROM LAYER OUTSIDE VDW-SPHERE
REMARK      BUR    - INDICATES BURIED ATOMS (1=BURIED, 0=SURFACE)
REMARK  
REMARK  AT# ELEM RES C RES#       X       Y       Z     PD   PD    VDWVOL  SEVOL BUR
"""
        extralines_vol="""REMARK 
REMARK   COLUMNS MODIFIED FROM ORIGINAL PDB FILE:
REMARK      VOL    - TOTAL ATOMIC VOLUME
REMARK      VDWVOL - VOLUME INSIDE VAN-DER-WAALS SPHERE
REMARK      SEVOL  - VOLUME IN 1.4 ANGSTROM LAYER OUTSIDE VDW-SPHERE
REMARK      BUR    - INDICATES BURIED ATOMS (1=BURIED, 0=SURFACE)
REMARK  
REMARK  AT# ELEM RES C RES#       X       Y       Z     VOL  VOL   VDWVOL  SEVOL BUR
"""

        extralines_z="""REMARK 
REMARK   COLUMNS MODIFIED FROM ORIGINAL PDB FILE:
REMARK      Z      - Z-SCORE
REMARK      VDWVOL - VOLUME INSIDE VAN-DER-WAALS SPHERE
REMARK      SEVOL  - VOLUME IN 1.4 ANGSTROM LAYER OUTSIDE VDW-SPHERE
REMARK      BUR    - INDICATES BURIED ATOMS (1=BURIED, 0=SURFACE)
REMARK  
REMARK  AT# ELEM RES C RES#       X       Y       Z     Z    Z     VDWVOL  SEVOL BUR
"""

        f_atom = 0
        out = ""
        mode = options['bfactor']
        
        if mode == 'zscore':
            z = ZScore(AveragePacking(options))
            
        for l in open(infile).readlines():
            if re.search('(^ATOM)|(^HETATM)',l):
                if not f_atom:
                    f_atom = 1
                    if mode == 'packing_density': out += extralines_pd
                    elif mode == 'volume': out += extralines_vol
                    elif mode == 'zscore': out += extralines_z
                # extract volume data
                atom = self.parse_atom(l,options)
                if check_valid and not atom['valid']: continue
                if mode == 'packing_density': value =  atom['packing_density']
                elif mode == 'zscore':
                    value = z.get_z_score(atom,options)
                    if not value: value = -1
                else: value = atom['total_volume']
                newline = l[:55] + "%5.2f %5.2f"%(value,value) + l[67:]
                out += newline
            else:
                out += l

        open(outfile,'w').writelines(out+'\n')
Beispiel #3
0
    def html_report(self,options):
        report = """

<h1>Packing report</h1>
"""
        total_atoms = len(self.atoms)        
        calc_atoms  = 0
        sum_pd      = 0.0
        for i in range(len(self.atoms)):
                       if self.valid[i]:
                           calc_atoms += 1
                           sum_pd += self.get_atom(i)['packing_density']

        if calc_atoms > 0:
            avg_pd = sum_pd / calc_atoms
        else:
            avg_pd = 0
            
        n_cavi      = len(self.cavities)

        # calculate z-score-rms
        avg_pack = AveragePacking(options)
        z = ZScore(avg_pack)
        z_score = z.compare_molecule(self,options)


        report += """
<h2>1.SUMMARY</h2>

<table cellspacing=0 cellpadding=4 border=1>
<tr><td width='25%%'><b>structure file               </b></td><td width='75%%'>%s</td></tr>
<tr><td><b>reference file               </b></td><td>%s</td></tr>
<tr><td></td></tr>
<tr><td><b>total atoms in structure     </b></td><td>%5i</td></tr>
<tr><td><b>atoms used for calculation   </b></td><td>%5i</td></tr>
<tr><td><b>average packing density      </b></td><td>%5.3f</td></tr>
<tr><td><b>number of cavities           </b></td><td>%5i</td></tr>
<tr><td><b>z-score-rms                  </b></td><td>%5.2f</td></tr>
</table>
"""%(self.vol_file,options['reference_file'],total_atoms,calc_atoms,avg_pd,n_cavi,z_score)

        report += """

&nbsp;
<h2>2.ABBREVIATIONS USED</h2>

<table cellspacing=0 cellpadding=4 border=1>
<tr><td width='25%'><b>   chain         </b></td><td width='75%'> chain ID (one letter, e.g. H)</td></tr>
<tr><td><b>   resi_no       </b></td><td> residue number (integer, e.g. 131)</td></tr>
<tr><td><b>   resi_type     </b></td><td> residue type (e.g. TYR, HOH)</td></tr>
<tr><td><b>   n_atoms_total </b></td><td> number of atoms in the structure</td></tr>
<tr><td><b>   n_atoms       </b></td><td> number of atoms used in the calculation</td></tr>
<tr><td><b>   atom_no       </b></td><td> atom number in PDB and .vol file.</td></tr>
<tr><td><b>   atom_name     </b></td><td> atom name (three-letter, from PDB file, e.g. CA, CD2)</td></tr>
<tr><td><b>   atom_type     </b></td><td> classes by which average packing is calculated.<br>
This is either 'residuename_atomname' e.g. 'TYR_CA', or one of 18 concise ProtOr atom types, e.g. 'C4H3u' for methyl groups.</td></tr>
<tr><td><b>   &lt;VdW&gt;         </b></td><td> average Van-der-Waals volume in cubic Angstroms</td></tr>
<tr><td><b>   &lt;SolvExc&gt;     </b></td><td> average Solvent Excluded volume in cubic Angstroms</td></tr>
<tr><td><b>   &lt;totVol&gt;      </b></td><td> average total volume (VdW + SolvExc) in cubic Angstroms</td></tr>
<tr><td><b>   &lt;PD&gt;          </b></td><td> average packing density (VdW/totVol)</td></tr>
<tr><td><b>   SD            </b></td><td> standard deviation</td></tr>
<tr><td><b>   [&Aring;<sup>3</sup>]         </b></td><td> cubic Angstroms</td></tr>
</table>

&nbsp;
<h2>3.ATOM NUMBERS AND PACKING</h2>

<table cellspacing=0 cellpadding=4 border=1>
<tr><th width='20%'>atomic subset</th><th width='5%'>n_atoms</th><th width='10%'>&lt;VdW&gt; [&Aring;<sup>3</sup>]</th><th width='10%%'>&lt;SolvExc&gt; [&Aring;<sup>3</sup>]</th><th width='10%'>&lt;totVol&gt; [&Aring;<sup>3</sup>]</th><th width='10%'>SD(&lt;totVol&gt;) [&Aring;<sup>3</sup>]</th><th width='10%'>&lt;PD&gt;</th><th width='10%'>SD(&lt;PD&gt;)</th></tr>
"""
        subsets = ["total atoms in structure           ",
                   "   peptidic atoms                  ",
                   "      buried                       ",
                   "         buried cavity neighbors   ",
                   "         other buried atoms        ",
                   "      surface                      ",
                   "         surface cavity neighbors  ",
                   "         other surface atoms       ",
                   "   hetero atoms                    ",
                   "      water molecules              ",
                   "      other hetero atoms           "]
        avg_pack = AveragePacking(options)
        for s in subsets:            
            rec = avg_pack.count_subset(self,re.sub('(^\s+)|(\s+\Z)','',s))            
            line = '<tr align="right"><td align="left">%s</td><td>%i</td><td>%5.2f</td><td>%5.2f</td><td>%5.2f</td><td>%5.2f</td><td>%5.3f</td><td>%5.3f</td></tr>\n'%(s,rec[0],rec[1],rec[2],rec[3],rec[4],rec[5],rec[6])
            report += line
            
        report += """</table>

&nbsp; 
<h2>4.CAVITIES</h2>

<table cellspacing=0 cellpadding=4 border=1>
<tr><th width='15%'>cavity_no</th><th width='10%'>n_neighbors</th><th width='10%'>&lt;dist&gt; [&Aring;]</th><th width='10%'>%surface</th><th width='30%'>atom_types</th><th width='20%'>atom_indices</th></tr>
"""
        for i in range(len(self.cavities)):
            cav = self.cavities[i]
            nsurf = 0
            for c in cav:
                if self.get_atom(c)['surface']: nsurf +=1
            atypes = string.join([avg_pack.get_atomtype(self.get_atom(ai)) for ai in cav],', ') 
            anums = string.join([str(num) for num in cav],', ')
            eu_med = self.cav_dist[i]
            report += '<tr align="right"><td>%3i</td><td>%3i</td><td>%5.2f</td><td>%4.1f</td><td align="left">%s</td><td align="left">%s</td></tr>\n'%(i,len(cav),eu_med,nsurf*100.0/len(cav),atypes,anums)
            
        
        report += """</table>

&nbsp;
<h2>5.PACKING PER RESIDUE</h2>

<table cellspacing=0 cellpadding=4 border=1>
<tr><th width='5%'>chain</th><th width='10%'>resi_no</th><th width='10%'>resi_type</th><th width='5%'>n_atoms</th><th width='10%'>sum(VdW) [&Aring;<sup>3</sup>]</th><th width='10%'>sum(SolvExc) [&Aring;<sup>3</sup>]</th><th width='10%'>sum(totVol) [&Aring;<sup>3</sup>]</th><th width='10%'>&lt;PD&gt;</th><th width='10%'>SD(&lt;PD&gt;)</th></tr>
"""
        avg_pack = AveragePacking(options)
        for i in range(len(self.atoms)):
            if self.valid[i]:
                atom = self.get_atom(i)
                avg_pack.count_residue(atom)        
        for r in avg_pack.get_residue_results():
                report += '<tr align="right"><td>%s</td><td>%s</td><td>%s</td><td>%i</td><td>%5.2f</td><td>%5.2f</td><td>%5.2f</td><td>%5.2f</td><td>%5.3f</td></tr>\n'%r

        report += """</table>

&nbsp;  
<h2>6.PACKING PER ATOM</h2>

<table cellspacing=0 cellpadding=4 border=1>
<tr><th width='10%'>atom_no</th><th width='5%'>chain</th><th width='10%'>resi_no</th><th width='10%'>residue_name</th><th width='10%'>atom_name</th><th width='10%'>atom_type</th><th width='10%'>VdWVol [&Aring;<sup>3</sup>]</th><th width='10%'>SolvExcVol [&Aring;<sup>3</sup>]</th><th width='10%'>totVol [&Aring;<sup>3</sup>]</th><th width='10%'>PD</th></tr>
"""
        for i in range(len(self.atoms)):
            if self.valid[i]:
                atom = self.get_atom(i)
                atomtype = avg_pack.get_atomtype(atom)
                report += '<tr align="right"><td>%i</td><td>%s</td><td>%i</td><td>%s</td><td>%s</td><td>%s</td><td>%5.2f</td><td>%5.2f</td><td>%5.2f</td><td>%5.3f</td></tr>\n'%(atom['index'],atom['chain_id'],atom['residue_number'],atom['residue_type'],atom['atom_type'],atomtype,atom['vdw_volume'],atom['solv_ex_volume'],atom['total_volume'],atom['packing_density'])

        report += """</table>"""
        return report