Beispiel #1
0
    def get_s(self, pdb_file=None):
        if self._pdb_file is not None:
            pdb = self._pdb_file
        else:
            pdb = iotbx.pdb.input(file_name=pdb_file)
        
        s = 0
        tot = 0
    
        for a in pdb.atoms_with_labels():
            if a.resname in ['DOD', 'HOH']:
                if a.name.strip() == 'O':
                    s += a.occ
            tot += a.occ

        return s/tot
Beispiel #2
0
    def get_rmm(self, pdb_file=None):
        if self._pdb_file is not None:
            pdb = self._pdb_file
        else:
            pdb = iotbx.pdb.input(file_name=file)
        
        rmm = 0

        for a in pdb.atoms_with_labels():
            if a.resname in ['ASP', 'ALA', 'HIS', 'ARG', 'LYS', 'GLN', 'GLU',
                             'TYR', 'PRO', 'LEU', 'ILE', 'MET', 'VAL', 'SER',
                             'ASN', 'CYS', 'GLY', 'TRP', 'PHE', 'THR', 'LYS']:
                
                rmm += self._weights[a.name.strip()[0]] * a.occ

        return rmm
Beispiel #3
0
    def get_chains(self, pdb_file):
        residues = []
        pdb = iotbx.pdb.input(file_name=pdb_file)
        for a in pdb.atoms_with_labels():
            rid = int(a.resid())
            if rid not in residues:
                residues.append(rid)

        cid = 'A'
        res_lookup = {}
        _last = 0
        for r in sorted(residues):
            if r - _last > 21:
                cid = chr(ord(cid)+1)
            
            res_lookup[r] = cid
            
            _last = r
        
        return res_lookup
Beispiel #4
0
    def get_bond_lengths(self, pdb_file):
        self._omitted = {'asp': [], 'glu': [], 'his': [], 'arg': []}
        self._residues = {'asp': {}, 'glu': {}, 'his': {}, 'arg': {}}
        
        b_avg_array = [[],[],[]]
        rlist = {'asp': {}, 'glu': {}, 'his': {}, 'arg': {}}
        t = {'ASP': [' CG ', ' OD1', ' OD2'], 'GLU': [' CD ', ' OE1', ' OE2']} 
        pdb = iotbx.pdb.input(file_name=pdb_file)
        for a in pdb.atoms_with_labels():
            b_avg_array[2].append(a.b)
                    
            if a.resname in ['HOH', 'DOD']:
                b_avg_array[1].append(a.b)
            
            if a.resname in ['ASP', 'ALA', 'HIS', 'ARG', 'LYS', 'GLN', 'GLU', 
                             'TYR', 'PRO', 'LEU', 'ILE', 'MET', 'VAL', 'SER',
                             'ASN', 'CYS', 'GLY', 'TRP', 'PHE', 'THR', 'LYS']:
                b_avg_array[0].append(a.b)
        
            rid = int(a.resid())
            if a.resname in t.keys():
                n = t[a.resname]
                rn = a.resname.lower()
                
                if a.occ < 1:
                    if rid not in self._omitted[rn]:
                        self._omitted[rn].append(rid)
                    
                else:
                    if a.name in n:
                        id = n.index(a.name)
                        if rid in rlist[rn].keys():
                            rlist[rn][rid][id] = a
                        else:
                            rlist[rn][rid] = {id:a}
                             
            # his CG CD2 NE2, ND1 CE1 NE2
            elif a.resname == 'HIS':
                if a.occ < 1:
                    if rid not in self._omitted['his']:
                        self._omitted['his'].append(rid)
                    
                else:
                    atoms = [' CG ', ' CD2', ' NE2', ' ND1', ' CE1']
                    if a.name in atoms:
                        id = atoms.index(a.name)
                        if rid in rlist['his'].keys():
                            rlist['his'][rid][id] = a
                        else:
                            rlist['his'][rid] = {id:a}
            
            # arg CZ NH2, CZ NE, CZ NH1, CD NE?
            elif a.resname == 'ARG':
                if a.occ < 1:
                    if rid not in self._omitted['arg']:
                        self._omitted['arg'].append(rid)
                    
                else:
                    atoms = [' CZ ', ' NH2', ' NE ', ' NH1']
                    if a.name in atoms:           
                        id = atoms.index(a.name)
                        if rid in rlist['arg'].keys():
                            rlist['arg'][rid][id] = a
                        else:
                            rlist['arg'][rid] = {id:a}

        for t in rlist.keys():
            for rid,res in rlist[t].iteritems():
                if t == 'asp' or t == 'glu':
                    if len(res) == 3:
                        self._residues[t][rid] = {1: [res[0].distance(res[1]), res[1].occ, res[1].b], 2: [res[0].distance(res[2]), res[2].occ, res[2].b]}

                elif t == 'his':
                    if len(res) == 5:
                        #for i,a in res.iteritems():
                        #    print i,a.name

                        self._residues[t][rid] = {  1: [res[1].angle(res[0], res[2], True), res[1].occ, res[1].b], 
                                                    2: [res[4].angle(res[3], res[2], True), res[4].occ, res[4].b],
                                                    3: [res[2].angle(res[1], res[4], True), res[2].occ, res[2].b],
                                                    4: [res[3].angle(res[0], res[4], True), res[3].occ, res[3].b],
                                                    5: [res[0].angle(res[3], res[1], True), res[0].occ, res[0].b],
                                                    }

                elif t == 'arg':
                    if len(res) == 4:
                        self._residues[t][rid] = {1: [res[0].distance(res[1]), res[1].occ, res[1].b], 2: [res[0].distance(res[2]), res[2].occ, res[2].b], 3: [res[0].distance(res[3]), res[3].occ, res[3].b]}

        self._residues['avg'] = {}
        for i,k in enumerate(['pro', 'sol', 'all']):
            if len(b_avg_array[i]) > 0:
                val = sum(b_avg_array[i])/len(b_avg_array[i])
            else:
                val = 0;
            self._residues['avg'][k] = val

        #self._residues['avg'] = {'b': (sum(b_avg_array)/len(b_avg_array))}
        
        return self._omitted, self._residues
Beispiel #5
0
    def analyse(self):
        self._omitted = {'asp': [], 'glu': [], 'his': [], 'arg': []}
        self._residues = {'asp': {}, 'glu': {}, 'his': {}, 'arg': {}}

        self._highlight = -1

        b_avg_array = []
        rlist = {'asp': {}, 'glu': {}, 'his': {}, 'arg': {}}
        t = {'ASP': [' CG ', ' OD1', ' OD2'], 'GLU': [' CD ', ' OE1', ' OE2']} 
        pdb = iotbx.pdb.input(file_name=self._bond_lengths)
        for a in pdb.atoms_with_labels():
            if a.resname in ['ASP', 'ALA', 'HIS', 'ARG', 'LYS', 'GLN', 'GLU', 
                            'TYR', 'PRO', 'LEU', 'ILE', 'MET', 'VAL', 'SER',
                            'ASN', 'CYS', 'GLY', 'TRP', 'PHE', 'THR', 'LYS']:
                b_avg_array.append(a.b)
        
            rid = int(a.resid())
            if a.resname in t.keys():
                n = t[a.resname]
                rn = a.resname.lower()
                
                if a.occ < 1:
                    if rid not in self._omitted[rn]:
                        self._omitted[rn].append(rid)
                    
                else:
                    if a.name in n:
                        id = n.index(a.name)
                        if rid in rlist[rn].keys():
                            rlist[rn][rid][id] = a
                        else:
                            rlist[rn][rid] = {id:a}
                             
            # his CG CD2 NE2, ND1 CE1 NE2
            elif a.resname == 'HIS':
                if a.occ < 1:
                    if rid not in self._omitted['his']:
                        self._omitted['his'].append(rid)
                    
                else:
                    atoms = [' CG ', ' CD2', ' NE2', ' ND1', ' CE1']
                    if a.name in atoms:
                        id = atoms.index(a.name)
                        if rid in rlist['his'].keys():
                            rlist['his'][rid][id] = a
                        else:
                            rlist['his'][rid] = {id:a}
            
            # arg CZ NH2, CZ NE, CZ NH1, CD NE?
            elif a.resname == 'ARG':
                if a.occ < 1:
                    if rid not in self._omitted['arg']:
                        self._omitted['arg'].append(rid)
                    
                else:
                    atoms = [' CZ ', ' NH2', ' NE ', ' NH1']
                    if a.name in atoms:           
                        id = atoms.index(a.name)
                        if rid in rlist['arg'].keys():
                            rlist['arg'][rid][id] = a
                        else:
                            rlist['arg'][rid] = {id:a}

        for t in rlist.keys():
            for rid,res in rlist[t].iteritems():
                if t == 'asp' or t == 'glu':
                    if len(res) == 3:
                        self._residues[t][rid] = {1: [res[0].distance(res[1]), res[1].occ, res[1].b], 2: [res[0].distance(res[2]), res[2].occ, res[2].b]}

                elif t == 'his':
                    if len(res) == 5:
                        self._residues[t][rid] = {1: [res[1].angle(res[0], res[2], True), res[0].occ, res[0].b], 2: [res[4].angle(res[3], res[2], True), res[3].occ, res[3].b]}

                elif t == 'arg':
                    if len(res) == 4:
                        self._residues[t][rid] = {1: [res[0].distance(res[1]), res[1].occ, res[1].b], 2: [res[0].distance(res[2]), res[2].occ, res[2].b], 3: [res[0].distance(res[3]), res[3].occ, res[3].b]}

        self._residues['avg'] = {'b': (sum(b_avg_array)/len(b_avg_array))}

        if os.path.exists(self._std_devs):
            devs = open(self._std_devs)
            asp_re = re.compile(r'CG_(\d+) OD(1|2)_\1 (\d+\.\d+)\((\d+)\)')
            glu_re = re.compile(r'CD_(\d+) OE(1|2)_\1 (\d+\.\d+)\((\d+)\)')
        
            his_re = [re.compile(r'CG_(\d+) CD2_\1 NE2_\1 (\d+)\((\d+)\)'),
                      re.compile(r'ND1_(\d+) CE1_\1 NE2_\1 (\d+)\((\d+)\)'),
                      re.compile(r'NE2_(\d+) CD2_\1 CG_\1 (\d+)\((\d+)\)'),
                      re.compile(r'NE2_(\d+) CE1_\1 ND1_\1 (\d+)\((\d+)\)'),
                      ]
                      
            arg_re = [re.compile(r'CZ_(\d+) NH2_\1 (\d+\.\d+)\((\d+)\)'),
                      re.compile(r'CZ_(\d+) NE_\1 (\d+\.\d+)\((\d+)\)'),
                      re.compile(r'CZ_(\d+) NH1_\1 (\d+\.\d+)\((\d+)\)'),
                      re.compile(r'NH2_(\d+) CZ_\1 (\d+\.\d+)\((\d+)\)'),
                      re.compile(r'NE_(\d+) CZ_\1 (\d+\.\d+)\((\d+)\)'),
                      re.compile(r'NH1_(\d+) CZ_\1 (\d+\.\d+)\((\d+)\)')
                     ]
            for s in devs:
                for t,rex in {'asp': asp_re, 'glu': glu_re}.items():
                    a = rex.match(s)
                    
                    if a:
                        if int(a.group(1)) in self._residues[t]:
                            if len(self._residues[t][int(a.group(1))][int(a.group(2))]) < 4:
                                d = pow(10, len((a.group(3).split('.'))[1]))
                                self._residues[t][int(a.group(1))][int(a.group(2))].append(float(a.group(4))/d)
                                
                for id,rex in enumerate(his_re):
                    a = rex.match(s)
                    
                    if a:
                        if int(a.group(1)) in self._residues['his']:
                            self._residues['his'][int(a.group(1))][(id%2)+1].append(float(a.group(3)))
                            
                for id,rex in enumerate(arg_re):
                    a = rex.match(s)
                    if a:
                        if int(a.group(1)) in self._residues['arg']:
                            d = pow(10, len((a.group(2).split('.'))[1]))
                            self._residues['arg'][int(a.group(1))][(id%3)+1].append(float(a.group(3))/d)
            
            devs.close()
            
        for type in self._residues.keys():
            std_arr = []
            for res in self._residues[type]:
                if type == 'asp'or type == 'glu' or type == 'his':
                    r = self._residues[type][res]
                                        
                    if len(r[1]) == 4 and len(r[2]) == 4:
                        std_arr.append(r[1][3])
                        std_arr.append(r[2][3])
                    
                        delta = abs(r[1][0] - r[2][0])
                        sigdel = math.sqrt(pow(r[1][3],2)+pow(r[2][3],2))
                        siglev = delta/sigdel
                        bavg = (r[1][2]+r[2][2])/2
                        
                        self._residues[type][res]['r'] = [delta, sigdel, siglev, r[1][1], bavg]
            
            if len(std_arr) > 0:
                self._residues['avg'][type] = sum(std_arr)/len(std_arr)
        
        self._update_lists()
        self._show_residue()