Partial pylint de-linting of bonds.py.

This commit is contained in:
Nathan Baker
2020-05-16 21:11:09 -07:00
parent 22d83ae29e
commit 303aaae25a

View File

@@ -1,49 +1,51 @@
"""PROPKA representation of bonds."""
from __future__ import division # TODO - is pickle still used?
from __future__ import print_function import pickle
# TODO - eliminate use of sys
import pickle,sys,os,math,propka.calculations import sys
# TODO - eliminate use of os
import os
import math
import json import json
import pkg_resources import pkg_resources
import propka.calculations
# TODO - replace the info/warning imports with logging functionality
from propka.lib import info, warning from propka.lib import info, warning
# TODO - should these constants be defined higher up in the module?
# TODO - I don't know what some of these constants mean
DISULFIDE_DISTANCE = 2.5
FLUORIDE_DISTANCE = 1.7
HYDROGEN_DISTANCE = 1.5
DEFAULT_DISTANCE = 2.0
class bondmaker: class bondmaker:
"""Makes bonds?
TODO - the documentation for this class needs to be improved.
"""
def __init__(self): def __init__(self):
# predefined bonding distances # predefined bonding distances
self.distances = { self.distances = {'S-S' : DISULFIDE_DISTANCE, 'F-F' : FLUORIDE_DISTANCE}
'S-S':2.5,
'F-F':1.7}
self.distances_squared = {} self.distances_squared = {}
for k in self.distances.keys(): for k in self.distances.keys():
self.distances_squared[k] = self.distances[k] * self.distances[k] self.distances_squared[k] = self.distances[k] * self.distances[k]
self.H_dist = HYDROGEN_DISTANCE
self.H_dist = 1.5; self.default_dist = DEFAULT_DISTANCE
self.default_dist = 2.0;
self.H_dist_squared = self.H_dist * self.H_dist self.H_dist_squared = self.H_dist * self.H_dist
self.default_dist_squared = self.default_dist * self.default_dist self.default_dist_squared = self.default_dist * self.default_dist
distances = list(self.distances_squared.values()) + [self.default_dist_squared]
self.max_sq_distance = max(list(self.distances_squared.values())+[self.default_dist_squared]) self.max_sq_distance = max(distances)
# protein bonding data # protein bonding data
self.data_file_name = pkg_resources.resource_filename(__name__, 'protein_bonds.json') self.data_file_name = pkg_resources.resource_filename(__name__, 'protein_bonds.json')
with open(self.data_file_name, 'rt') as json_file: with open(self.data_file_name, 'rt') as json_file:
self.protein_bonds = json.load(json_file) self.protein_bonds = json.load(json_file)
self.intra_residue_backbone_bonds = {'N': ['CA'], 'CA': ['N', 'C'],
'C': ['CA', 'O'], 'O': ['C']}
self.intra_residue_backbone_bonds = {'N': ['CA'], self.number_of_pi_electrons_in_bonds_in_backbone = {'C': 1, 'O': 1}
'CA':['N','C'],
'C': ['CA','O'],
'O': ['C']}
self.number_of_pi_electrons_in_bonds_in_backbone = {'C':1,
'O':1}
self.number_of_pi_electrons_in_conjugate_bonds_in_backbone = {'N': 1} self.number_of_pi_electrons_in_conjugate_bonds_in_backbone = {'N': 1}
self.number_of_pi_electrons_in_bonds_in_sidechains = {'ARG-CZ' : 1, self.number_of_pi_electrons_in_bonds_in_sidechains = {'ARG-CZ' : 1,
'ARG-NH1': 1, 'ARG-NH1': 1,
'ASN-OD1': 1, 'ASN-OD1': 1,
@@ -78,46 +80,33 @@ class bondmaker:
'TYR-CZ' : 1, 'TYR-CZ' : 1,
'TYR-CE2': 1, 'TYR-CE2': 1,
'TYR-CD2': 1} 'TYR-CD2': 1}
self.number_of_pi_electrons_in_conjugate_bonds_in_sidechains = {'ARG-NE': 1, self.number_of_pi_electrons_in_conjugate_bonds_in_sidechains = {'ARG-NE': 1,
'ARG-NH2': 1, 'ARG-NH2': 1,
'ASN-ND2': 1, 'ASN-ND2': 1,
'GLN-NE2': 1, 'GLN-NE2': 1,
'HIS-NE2': 1, 'HIS-NE2': 1,
'TRP-NE1': 1} 'TRP-NE1': 1}
self.number_of_pi_electrons_in_bonds_ligands = {'C.ar': 1, 'N.pl3': 0,
self.number_of_pi_electrons_in_bonds_ligands = {'C.ar':1, 'C.2': 1, 'O.2': 1,
'N.pl3':0, 'O.co2': 1, 'N.ar': 1,
'C.2':1, 'C.1': 2, 'N.1': 2}
'O.2':1, self.number_of_pi_electrons_in_conjugate_bonds_in_ligands = {'N.am': 1,
'O.co2':1, 'N.pl3': 1}
'N.ar':1,
'C.1':2,
'N.1':2}
self.number_of_pi_electrons_in_conjugate_bonds_in_ligands = {'N.am':1,'N.pl3':1}
self.backbone_atoms = list(self.intra_residue_backbone_bonds.keys()) self.backbone_atoms = list(self.intra_residue_backbone_bonds.keys())
self.terminal_oxygen_names = ['OXT', 'O\'\''] self.terminal_oxygen_names = ['OXT', 'O\'\'']
return
def find_bonds_for_protein(self, protein): def find_bonds_for_protein(self, protein):
""" Finds bonds proteins based on the way atoms """Finds bonds proteins based on the way atoms normally bond in proteins.
normally bond in proteins"""
Args:
protein: the protein to search for bonds
"""
info('++++ Side chains ++++') info('++++ Side chains ++++')
# side chains # side chains
for chain in protein.chains: for chain in protein.chains:
for residue in chain.residues: for residue in chain.residues:
if residue.resName.replace(' ', '') not in ['N+', 'C-']: if residue.resName.replace(' ', '') not in ['N+', 'C-']:
self.find_bonds_for_side_chain(residue.atoms) self.find_bonds_for_side_chain(residue.atoms)
info('++++ Backbones ++++') info('++++ Backbones ++++')
# backbone # backbone
last_residues = [] last_residues = []
@@ -127,12 +116,10 @@ class bondmaker:
if chain.residues[i].resName.replace(' ', '') not in ['N+', 'C-']: if chain.residues[i].resName.replace(' ', '') not in ['N+', 'C-']:
self.connect_backbone(chain.residues[i-1], chain.residues[i]) self.connect_backbone(chain.residues[i-1], chain.residues[i])
last_residues.append(chain.residues[i]) last_residues.append(chain.residues[i])
info('++++ terminal oxygen ++++') info('++++ terminal oxygen ++++')
# terminal OXT # terminal OXT
for last_residue in last_residues: for last_residue in last_residues:
self.find_bonds_for_terminal_oxygen(last_residue) self.find_bonds_for_terminal_oxygen(last_residue)
info('++++ cysteines ++++') info('++++ cysteines ++++')
# Cysteines # Cysteines
for chain in protein.chains: for chain in protein.chains:
@@ -142,29 +129,36 @@ class bondmaker:
if chain.residues[j].resName == 'CYS' and j != i: if chain.residues[j].resName == 'CYS' and j != i:
self.check_for_cysteine_bonds(chain.residues[i], self.check_for_cysteine_bonds(chain.residues[i],
chain.residues[j]) chain.residues[j])
return
def check_for_cysteine_bonds(self, cys1, cys2): def check_for_cysteine_bonds(self, cys1, cys2):
"""Looks for potential bonds between two cysteines.
Args:
cys1: one of the cysteines to check
cys1: one of the cysteines to check
"""
for atom1 in cys1.atoms: for atom1 in cys1.atoms:
if atom1.name == 'SG': if atom1.name == 'SG':
for atom2 in cys2.atoms: for atom2 in cys2.atoms:
if atom2.name == 'SG': if atom2.name == 'SG':
if propka.calculations.squared_distance(atom1,atom2) < self.SS_dist_squared: dist = propka.calculations.squared_distance(atom1, atom2)
# TODO - is SS_dist_squared an attribute of this class?
if dist < self.SS_dist_squared:
self.make_bond(atom1, atom2) self.make_bond(atom1, atom2)
return
def find_bonds_for_terminal_oxygen(self, residue): def find_bonds_for_terminal_oxygen(self, residue):
"""Look for bonds for terminal oxygen.
Args:
residue - test residue
"""
for atom1 in residue.atoms: for atom1 in residue.atoms:
if atom1.name in self.terminal_oxygen_names: if atom1.name in self.terminal_oxygen_names:
for atom2 in residue.atoms: for atom2 in residue.atoms:
if atom2.name == 'C': if atom2.name == 'C':
self.make_bond(atom1, atom2) self.make_bond(atom1, atom2)
return # TODO - stopped here.
def connect_backbone(self, residue1, residue2): def connect_backbone(self, residue1, residue2):
""" Sets up bonds in the backbone """ """ Sets up bonds in the backbone """
# residue 1 # residue 1