# Copyright (C) 2002, Thomas Hamelryck (thamelry@binf.ku.dk) # This code is part of the Biopython distribution and governed by its # license. Please see the LICENSE file that should have been included # as part of this package. """Half-sphere exposure and coordination number calculation.""" import warnings from math import pi from Bio.PDB.AbstractPropertyMap import AbstractPropertyMap from Bio.PDB.PDBParser import PDBParser from Bio.PDB.Polypeptide import CaPPBuilder, is_aa from Bio.PDB.Vector import rotaxis class _AbstractHSExposure(AbstractPropertyMap): """ Abstract class to calculate Half-Sphere Exposure (HSE). The HSE can be calculated based on the CA-CB vector, or the pseudo CB-CA vector based on three consecutive CA atoms. This is done by two separate subclasses. """ def __init__(self, model, radius, offset, hse_up_key, hse_down_key, angle_key=None): """ @param model: model @type model: L{Model} @param radius: HSE radius @type radius: float @param offset: number of flanking residues that are ignored in the calculation of the number of neighbors @type offset: int @param hse_up_key: key used to store HSEup in the entity.xtra attribute @type hse_up_key: string @param hse_down_key: key used to store HSEdown in the entity.xtra attribute @type hse_down_key: string @param angle_key: key used to store the angle between CA-CB and CA-pCB in the entity.xtra attribute @type angle_key: string """ assert(offset>=0) # For PyMOL visualization self.ca_cb_list=[] ppb=CaPPBuilder() ppl=ppb.build_peptides(model) hse_map={} hse_list=[] hse_keys=[] for pp1 in ppl: for i in range(0, len(pp1)): if i==0: r1=None else: r1=pp1[i-1] r2=pp1[i] if i==len(pp1)-1: r3=None else: r3=pp1[i+1] # This method is provided by the subclasses to calculate HSE result=self._get_cb(r1, r2, r3) if result is None: # Missing atoms, or i==0, or i==len(pp1)-1 continue pcb, angle=result hse_u=0 hse_d=0 ca2=r2['CA'].get_vector() for pp2 in ppl: for j in range(0, len(pp2)): if pp1 is pp2 and abs(i-j)<=offset: # neighboring residues in the chain are ignored continue ro=pp2[j] if not is_aa(ro) or not ro.has_id('CA'): continue cao=ro['CA'].get_vector() d=(cao-ca2) if d.norm()=0) ppb=CaPPBuilder() ppl=ppb.build_peptides(model) fs_map={} fs_list=[] fs_keys=[] for pp1 in ppl: for i in range(0, len(pp1)): fs=0 r1=pp1[i] if not is_aa(r1) or not r1.has_id('CA'): continue ca1=r1['CA'] for pp2 in ppl: for j in range(0, len(pp2)): if pp1 is pp2 and abs(i-j)<=offset: continue r2=pp2[j] if not is_aa(r2) or not r2.has_id('CA'): continue ca2=r2['CA'] d=(ca2-ca1) if d