Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove logging abstraction to facilitate debugging and reduce bloat. #109

Merged
merged 5 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions propka/bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
PROPKA representation of bonds.

"""
import logging
import math
import json
import pkg_resources
import propka.calculations
# TODO - replace the info/warning imports with logging functionality
from propka.lib import info


_LOGGER = logging.getLogger(__name__)


# TODO - should these constants be defined higher up in the module?
Expand All @@ -30,8 +32,8 @@ class BondMaker:
"""
def __init__(self):
# predefined bonding distances
self.distances = {'S-S' : DISULFIDE_DISTANCE,
'F-F' : FLUORIDE_DISTANCE}
self.distances = {'S-S': DISULFIDE_DISTANCE,
'F-F': FLUORIDE_DISTANCE}
self.distances_squared = {}
for key in self.distances:
self.distances_squared[key] = (
Expand All @@ -53,22 +55,22 @@ def __init__(self):
'C': ['CA', 'O'], 'O': ['C']}
self.num_pi_elec_bonds_backbone = {'C': 1, 'O': 1}
self.num_pi_elec_conj_bonds_backbone = {'N': 1}
self.num_pi_elec_bonds_sidechains = {'ARG-CZ' : 1, 'ARG-NH1': 1,
'ASN-OD1': 1, 'ASN-CG' : 1,
'ASP-OD1': 1, 'ASP-CG' : 1,
'GLU-OE1': 1, 'GLU-CD' : 1,
'GLN-OE1': 1, 'GLN-CD' : 1,
'HIS-CG' : 1, 'HIS-CD2': 1,
self.num_pi_elec_bonds_sidechains = {'ARG-CZ': 1, 'ARG-NH1': 1,
'ASN-OD1': 1, 'ASN-CG': 1,
'ASP-OD1': 1, 'ASP-CG': 1,
'GLU-OE1': 1, 'GLU-CD': 1,
'GLN-OE1': 1, 'GLN-CD': 1,
'HIS-CG': 1, 'HIS-CD2': 1,
'HIS-ND1': 1, 'HIS-CE1': 1,
'PHE-CG' : 1, 'PHE-CD1': 1,
'PHE-CE1': 1, 'PHE-CZ' : 1,
'PHE-CG': 1, 'PHE-CD1': 1,
'PHE-CE1': 1, 'PHE-CZ': 1,
'PHE-CE2': 1, 'PHE-CD2': 1,
'TRP-CG' : 1, 'TRP-CD1': 1,
'TRP-CG': 1, 'TRP-CD1': 1,
'TRP-CE2': 1, 'TRP-CD2': 1,
'TRP-CE3': 1, 'TRP-CZ3': 1,
'TRP-CH2': 1, 'TRP-CZ2': 1,
'TYR-CG' : 1, 'TYR-CD1': 1,
'TYR-CE1': 1, 'TYR-CZ' : 1,
'TYR-CG': 1, 'TYR-CD1': 1,
'TYR-CE1': 1, 'TYR-CZ': 1,
'TYR-CE2': 1, 'TYR-CD2': 1}
self.num_pi_elec_conj_bonds_sidechains = {'ARG-NE': 1, 'ARG-NH2': 1,
'ASN-ND2': 1, 'GLN-NE2': 1,
Expand All @@ -90,13 +92,13 @@ def find_bonds_for_protein(self, protein):
Args:
protein: the protein to search for bonds
"""
info('++++ Side chains ++++')
_LOGGER.info('++++ Side chains ++++')
# side chains
for chain in protein.chains:
for residue in chain.residues:
if residue.res_name.replace(' ', '') not in ['N+', 'C-']:
self.find_bonds_for_side_chain(residue.atoms)
info('++++ Backbones ++++')
_LOGGER.info('++++ Backbones ++++')
# backbone
last_residues = []
for chain in protein.chains:
Expand All @@ -108,11 +110,11 @@ def find_bonds_for_protein(self, protein):
self.connect_backbone(chain.residues[i-1],
chain.residues[i])
last_residues.append(chain.residues[i])
info('++++ terminal oxygen ++++')
_LOGGER.info('++++ terminal oxygen ++++')
# terminal OXT
for last_residue in last_residues:
self.find_bonds_for_terminal_oxygen(last_residue)
info('++++ cysteines ++++')
_LOGGER.info('++++ cysteines ++++')
# Cysteines
for chain in protein.chains:
for i in range(0, len(chain.residues)):
Expand Down Expand Up @@ -180,7 +182,7 @@ def find_bonds_for_residue_backbone(self, residue):
self.num_pi_elec_bonds_backbone[atom1.name])
if atom1.name in (
list(self.num_pi_elec_conj_bonds_backbone.keys())
and len(atom1.bonded_atoms) > 1): # avoid N-term
and len(atom1.bonded_atoms) > 1): # avoid N-term
atom1.num_pi_elec_conj_2_3_bonds = (
self.num_pi_elec_conj_bonds_backbone[atom1.name])

Expand All @@ -204,8 +206,8 @@ def find_bonds_for_side_chain(self, atoms):
if key in list(self.num_pi_elec_conj_bonds_sidechains.keys()):
atom1.num_pi_elec_conj_2_3_bonds = (
self.num_pi_elec_conj_bonds_sidechains[key])
if not atom1.name in self.backbone_atoms:
if not atom1.name in self.terminal_oxygen_names:
if atom1.name not in self.backbone_atoms:
if atom1.name not in self.terminal_oxygen_names:
for atom2 in atoms:
if atom2.name in (
self
Expand Down Expand Up @@ -266,7 +268,6 @@ def find_bonds_for_protein_by_distance(self, molecule):
Returns:
list of atoms
"""
#self.find_bonds_for_protein(molecule)
atoms = []
for chain in molecule.chains:
for residue in chain.residues:
Expand Down Expand Up @@ -424,9 +425,9 @@ def make_bond(atom1, atom2):
"""
if atom1 == atom2:
return
if not atom1 in atom2.bonded_atoms:
if atom1 not in atom2.bonded_atoms:
atom2.bonded_atoms.append(atom1)
if not atom2 in atom1.bonded_atoms:
if atom2 not in atom1.bonded_atoms:
atom1.bonded_atoms.append(atom2)

def generate_protein_bond_dictionary(self, atoms):
Expand All @@ -441,21 +442,21 @@ def generate_protein_bond_dictionary(self, atoms):
name_i = atom.name
resi_j = bonded_atom.res_name
name_j = bonded_atom.name
if not name_i in (
if name_i not in (
self.backbone_atoms
or not name_j in self.backbone_atoms):
if not name_i in (
or name_j not in self.backbone_atoms):
if name_i not in (
self.terminal_oxygen_names
and not name_j in self.terminal_oxygen_names):
if not resi_i in list(self.protein_bonds.keys()):
and name_j not in self.terminal_oxygen_names):
if resi_i not in list(self.protein_bonds.keys()):
self.protein_bonds[resi_i] = {}
if not name_i in self.protein_bonds[resi_i]:
if name_i not in self.protein_bonds[resi_i]:
self.protein_bonds[resi_i][name_i] = []
if not name_j in self.protein_bonds[resi_i][name_i]:
if name_j not in self.protein_bonds[resi_i][name_i]:
self.protein_bonds[resi_i][name_i].append(name_j)
if not resi_j in list(self.protein_bonds.keys()):
if resi_j not in list(self.protein_bonds.keys()):
self.protein_bonds[resi_j] = {}
if not name_j in self.protein_bonds[resi_j]:
if name_j not in self.protein_bonds[resi_j]:
self.protein_bonds[resi_j][name_j] = []
if not name_i in self.protein_bonds[resi_j][name_j]:
if name_i not in self.protein_bonds[resi_j][name_j]:
self.protein_bonds[resi_j][name_j].append(name_i)
34 changes: 20 additions & 14 deletions propka/conformation_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

Container data structure for molecular conformations.
"""
import logging
import functools
import propka.ligand
from propka.output import make_interaction_map
Expand All @@ -12,11 +13,14 @@
from propka.determinants import set_backbone_determinants, set_ion_determinants
from propka.determinants import set_determinants
from propka.group import Group, is_group
from propka.lib import info


_LOGGER = logging.getLogger(__name__)


#: A large number that gets multipled with the integer obtained from applying
#: :func:`ord` to the atom chain ID. Used in calculating atom keys for sorting.
#: :func:`ord` to the atom chain ID. Used in calculating atom keys for
#: sorting.
UNICODE_MULTIPLIER = 1e7

#: A number that gets mutiplied with an atom's residue number. Used in
Expand Down Expand Up @@ -60,7 +64,8 @@ def extract_groups(self):
else:
group = atom.group
# if the atom has been checked in a another conformation, check
# if it has a group that should be used in this conformation as well
# if it has a group that should be used in this conformation
# as well
if group:
self.setup_and_add_group(group)

Expand Down Expand Up @@ -101,15 +106,16 @@ def find_covalently_coupled_groups(self):
'Covalent coupling map for {0:s}'.format(str(self)),
self.get_covalently_coupled_groups(),
lambda g1, g2: g1 in g2.covalently_coupled_groups)
info(map_)
_LOGGER.info("Coupling map:\n%s", map_)

def find_non_covalently_coupled_groups(self, verbose=False):
"""Find non-covalently coupled groups and set common charge centres.

Args:
verbose: verbose output
"""
# check if non-covalent coupling has already been set up in an input file
# check if non-covalent coupling has already been set up in an input
# file
if len(list(filter(lambda g: len(g.non_covalently_coupled_groups) > 0,
self.get_titratable_groups()))) > 0:
self.non_covalently_coupled_groups = True
Expand Down Expand Up @@ -186,7 +192,7 @@ def calculate_pka(self, version, options):
version: version object
options: option object
"""
info('\nCalculating pKas for', self)
_LOGGER.info('Calculating pKas for %s', self)
# calculate desolvation
for group in self.get_titratable_groups() + self.get_ions():
version.calculate_desolvation(group)
Expand All @@ -208,7 +214,7 @@ def calculate_pka(self, version, options):
penalised_labels = self.coupling_effects()
if (self.parameters.remove_penalised_group
and len(penalised_labels) > 0):
info('Removing penalised groups!!!')
_LOGGER.info('Removing penalised groups!!!')
for group in self.get_titratable_groups():
group.remove_determinants(penalised_labels)
# re-calculating the total pKa values
Expand Down Expand Up @@ -250,7 +256,7 @@ def coupling_effects(self):
# group with the highest pKa is allowed to titrate...
continue
group.coupled_titrating_group = first_group
#... and the rest are penalised
# ... and the rest are penalised
penalised_labels.append(group.label)
return penalised_labels

Expand All @@ -275,7 +281,7 @@ def share_determinants(groups):
max_dets[det.group] = max(det.value,
max_dets[det.group],
key=lambda v: abs(v))
# overwrite/add maximum value for each determinant
# overwrite/add maximum value for each determinant
for det_group in max_dets:
new_determinant = Determinant(det_group, max_dets[det_group])
for group in groups:
Expand Down Expand Up @@ -426,9 +432,9 @@ def get_titratable_groups(self):
def get_groups_for_calculations(self):
"""Get a list of groups that should be included in results report.

If --titrate_only option is specified, only residues that are titratable
and are in that list are included; otherwise all titratable residues
and CYS residues are included.
If --titrate_only option is specified, only residues that are
titratable and are in that list are included; otherwise all titratable
residues and CYS residues are included.

Returns:
list of groups
Expand Down Expand Up @@ -518,7 +524,7 @@ def add_atom(self, atom):
if not atom.molecular_container:
atom.molecular_container = self.molecular_container
# store chain id for bookkeeping
if not atom.chain_id in self.chains:
if atom.chain_id not in self.chains:
self.chains.append(atom.chain_id)

def copy_atom(self, atom):
Expand Down Expand Up @@ -549,7 +555,7 @@ def top_up(self, other):
"""
my_residue_labels = {a.residue_label for a in self.atoms}
for atom in other.atoms:
if not atom.residue_label in my_residue_labels:
if atom.residue_label not in my_residue_labels:
self.copy_atom(atom)

def find_group(self, group):
Expand Down
Loading