From 1d50cf4b0bcb8430bcd0e125c102da5cc7ea14d6 Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Wed, 13 Dec 2023 19:53:16 +0100 Subject: [PATCH] Typing: Atom members --- propka/atom.py | 89 ++++++++++++++++++++----------------- propka/group.py | 3 +- propka/ligand_pka_values.py | 9 +++- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/propka/atom.py b/propka/atom.py index fa80997..0cca0e1 100644 --- a/propka/atom.py +++ b/propka/atom.py @@ -43,6 +43,43 @@ class Atom: :meth:`make_input_line` and :meth:`get_input_parameters` have been removed as reading/writing PROPKA input is no longer supported. """ + group: Optional["Group"] = None + group_type: Optional[str] = None + cysteine_bridge: bool = False + residue: NoReturn = None # type: ignore[assignment] + conformation_container: Optional["ConformationContainer"] = None + molecular_container: Optional["MolecularContainer"] = None + is_protonated: bool = False + steric_num_lone_pairs_set: bool = False + terminal: Optional[str] = None + charge: float = 0.0 + charge_set: bool = False + steric_number: int = 0 + number_of_lone_pairs: int = 0 + number_of_protons_to_add: int = 0 + num_pi_elec_2_3_bonds: int = 0 + num_pi_elec_conj_2_3_bonds: int = 0 + groups_extracted: bool = False + + # PDB attributes + name: str = '' + numb: int = 0 + x: float = 0.0 + y: float = 0.0 + z: float = 0.0 + res_num: int = 0 + res_name: str = '' + chain_id: str = 'A' + type: str = '' + occ: str = '1.0' + beta: str = '0.0' + element: str = '' + icode: str = '' + + # ligand atom types + sybyl_type = '' + sybyl_assigned = False + marvin_pka = False def __init__(self, line: Optional[str] = None): """Initialize Atom object. @@ -51,53 +88,17 @@ class Atom: line: Line from a PDB file to set properties of atom. """ self.number_of_bonded_elements: NoReturn = cast(NoReturn, {}) # FIXME unused? - self.group: Optional[Group] = None - self.group_type: Optional[str] = None - self.cysteine_bridge: bool = False self.bonded_atoms: List[Atom] = [] - self.residue = None - self.conformation_container: Optional[ConformationContainer] = None - self.molecular_container: Optional[MolecularContainer] = None - self.is_protonated = False - self.steric_num_lone_pairs_set = False - self.terminal: Optional[str] = None - self.charge = 0.0 - self.charge_set = False - self.steric_number = 0 - self.number_of_lone_pairs = 0 - self.number_of_protons_to_add = 0 - self.num_pi_elec_2_3_bonds = 0 - self.num_pi_elec_conj_2_3_bonds = 0 - self.groups_extracted = 0 self.set_properties(line) fmt = "{r.name:3s}{r.res_num:>4d}{r.chain_id:>2s}" self.residue_label = fmt.format(r=self) - # ligand atom types - self.sybyl_type = '' - self.sybyl_assigned = False - self.marvin_pka = False - def set_properties(self, line: Optional[str]): """Line from PDB file to set properties of atom. Args: line: PDB file line """ - self.name = '' - self.numb = 0 - self.x = 0.0 - self.y = 0.0 - self.z = 0.0 - self.res_num = 0 - self.res_name = '' - self.chain_id = 'A' - self.type = '' - self.occ = '1.0' - self.beta = '0.0' - self.element = '' - self.icode = '' - if line: self.name = line[12:16].strip() self.numb = int(hybrid36.decode(line[6:11])) @@ -184,9 +185,17 @@ class Atom: return True return False - def set_property(self, numb=None, name=None, res_name=None, chain_id=None, - res_num=None, x=None, y=None, z=None, occ=None, - beta=None): + def set_property(self, + numb: Optional[int] = None, + name: Optional[str] = None, + res_name: Optional[str] = None, + chain_id: Optional[str] = None, + res_num: Optional[int] = None, + x: Optional[float] = None, + y: Optional[float] = None, + z: Optional[float] = None, + occ: Optional[str] = None, + beta: Optional[str] = None): """Set properties of the atom object. Args: @@ -345,7 +354,7 @@ class Atom: """Return an undefined-format string version of this atom.""" return STR_FMT.format(r=self) - def set_residue(self, residue): + def set_residue(self, residue: NoReturn): """ Makes a reference to the parent residue Args: diff --git a/propka/group.py b/propka/group.py index 66eacc3..4ff702c 100644 --- a/propka/group.py +++ b/propka/group.py @@ -1230,7 +1230,7 @@ def is_group(parameters: Parameters, atom: Atom) -> Optional[Group]: Returns: group for atom or None """ - atom.groups_extracted = 1 + atom.groups_extracted = True # check if this atom belongs to a protein group protein_group = is_protein_group(parameters, atom) if protein_group: @@ -1386,6 +1386,7 @@ def is_ligand_group_by_marvin_pkas(parameters: Parameters, atom: Atom) -> Option # calculate Marvin ligand pkas for this conformation container # if not already done # TODO - double-check testing coverage of these functions. + assert atom.molecular_container is not None assert atom.conformation_container is not None if not atom.conformation_container.marvin_pkas_calculated: lpka = LigandPkaValues(parameters) diff --git a/propka/ligand_pka_values.py b/propka/ligand_pka_values.py index ecbb50d..c36f4d2 100644 --- a/propka/ligand_pka_values.py +++ b/propka/ligand_pka_values.py @@ -15,10 +15,14 @@ import shutil import subprocess import sys import warnings +from typing import TYPE_CHECKING, NoReturn + from propka.output import write_mol2_for_atoms from propka.lib import split_atoms_into_molecules from propka.parameters import Parameters +if TYPE_CHECKING: + from propka.molecular_container import MolecularContainer _LOGGER = logging.getLogger(__name__) @@ -58,7 +62,8 @@ class LigandPkaValues: return loc def get_marvin_pkas_for_pdb_file( - self, molecule, parameters, num_pkas=10, min_ph=-10.0, max_ph=20.0): + self, molecule: "MolecularContainer", parameters: NoReturn, + num_pkas=10, min_ph=-10.0, max_ph=20.0): """Use Marvin executables to get pKas for a PDB file. Args: @@ -72,7 +77,7 @@ class LigandPkaValues: self.get_marvin_pkas_for_molecular_container( molecule, num_pkas=num_pkas, min_ph=min_ph, max_ph=max_ph) - def get_marvin_pkas_for_molecular_container(self, molecule, num_pkas=10, + def get_marvin_pkas_for_molecular_container(self, molecule: "MolecularContainer", num_pkas=10, min_ph=-10.0, max_ph=20.0): """Use Marvin executables to calculate pKas for a molecular container.