Skip to content

Commit

Permalink
Feature: Logs are broken down per pair
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniekmateusz committed Feb 14, 2025
1 parent 82b6328 commit a5472cd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ties/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
logging.basicConfig(encoding='utf-8', level=logging.INFO)

from pathlib import Path

from . import cli
Expand All @@ -12,5 +14,3 @@
from ._version import __version__

__all__ = [Ligand, Protein, Pair, Config, LigandMap, Protein, __version__]

logging.basicConfig(encoding='utf-8', level=logging.INFO)
4 changes: 3 additions & 1 deletion ties/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def command_line_script():
help='Align the coordinates in the "END" ligand to the "INITIAL" ligand using '
'the generated maximum common substructure (MCS).')
parser.add_argument("-v", "--logging-level", metavar="str or bool", dest="logging_level",
type=ArgparseChecker.logging_lvl, required=False, default="WARNING",
type=ArgparseChecker.logging_lvl, required=False, default="INFO",
help="Logging level. Can be a boolean value "
"(False disables logging by setting it to ERROR). "
"A string should specify a logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL). ")
Expand Down Expand Up @@ -152,6 +152,8 @@ def command_line_script():
# initialise the config class
args = parser.parse_args()

# set the root logger
logging.getLogger().setLevel(args.logging_level)
logger.setLevel(args.logging_level)
for handler in logger.handlers:
handler.setLevel(args.logging_level)
Expand Down
8 changes: 8 additions & 0 deletions ties/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def __init__(self, **kwargs):
# assign all the initial configuration values
self.set_configs(**kwargs)

# logging
self.logging_breakdown = True
self.logging_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
self.logging_level = logging.INFO

@property
def workdir(self):
"""
Expand Down Expand Up @@ -900,6 +905,9 @@ def get_serializable(self):
if k in host_specific:
continue

if type(v) is logging.Formatter:
continue

if type(v) is pathlib.PosixPath:
v = str(v)

Expand Down
3 changes: 3 additions & 0 deletions ties/pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def superimpose(self, **kwargs):
if starting_node_pairs:
logger.debug(f'Starting nodes will be used: {starting_node_pairs}')

logging_key = str(self)

# fixme - simplify to only take the ParmEd as input
suptop = superimpose_topologies(ligand1_nodes.values(), ligand2_nodes.values(),
disjoint_components=self.config.allow_disjoint_components,
Expand All @@ -178,6 +180,7 @@ def superimpose(self, **kwargs):
starting_node_pairs=starting_node_pairs,
parmed_ligA=parmed_ligA, parmed_ligZ=parmed_ligZ,
starting_pair_seed=self.config.superimposition_starting_pair,
logging_key=logging_key,
config=self.config)

self.set_suptop(suptop, parmed_ligA, parmed_ligZ)
Expand Down
10 changes: 10 additions & 0 deletions ties/topology_superimposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3166,6 +3166,7 @@ def superimpose_topologies(top1_nodes,
check_atom_names_unique=True,
starting_pairs_heuristics=True,
starting_pair_seed=None,
logging_key=None,
config=None):
"""
The main function that manages the entire process.
Expand All @@ -3174,6 +3175,12 @@ def superimpose_topologies(top1_nodes,
- check if each molecule topology is connected
"""

if config.logging_breakdown:
file_log_handler = logging.FileHandler(config.workdir / f'{logging_key}.log')
file_log_handler.setLevel(config.logging_level)
file_log_handler.setFormatter(config.logging_formatter)
logger.addHandler(file_log_handler)

if not ignore_charges_completely:
whole_charge = SuperimposedTopology.validate_charges(top1_nodes, top2_nodes)

Expand Down Expand Up @@ -3382,6 +3389,9 @@ def take_largest(x, y):
logger.info(f'Disappearing atoms: { (len(top1_nodes) - len(suptop.matched_pairs)) / len(top1_nodes) * 100:.1f}%')
logger.info(f'Appearing atoms: { (len(top2_nodes) - len(suptop.matched_pairs)) / len(top2_nodes) * 100:.1f}%')

if config.logging_breakdown:
logger.removeHandler(file_log_handler)

return suptop


Expand Down

0 comments on commit a5472cd

Please # to comment.