Skip to content

Commit

Permalink
basic stats for collator and aligner
Browse files Browse the repository at this point in the history
  • Loading branch information
tdudgeon committed Nov 20, 2024
1 parent 3e5c244 commit 4f31250
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/xchemalign/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import traceback
import shutil
import time
from pathlib import Path

import yaml
Expand Down Expand Up @@ -207,6 +208,7 @@ def __init__(self, version_dir, metadata, assemblies, logger=None):
self.logger = logger
else:
self.logger = utils.Logger()
self.num_alignments = 0
self.errors = []
self.warnings = []

Expand Down Expand Up @@ -802,6 +804,7 @@ def _extract_components(self, crystals, aligner_meta):
self.logger.info('extracting components')

num_errors = 0
num_pdbs = 0
for k1, v1 in aligner_meta.get(Constants.META_XTALS, {}).items(): # k = xtal
if Constants.META_ALIGNED_FILES in v1:
self.logger.info('handling', k1)
Expand All @@ -811,7 +814,6 @@ def _extract_components(self, crystals, aligner_meta):
.get(Constants.META_XTAL_CIF, {})
.get(Constants.META_FILE)
)

for k2, v2 in v1[Constants.META_ALIGNED_FILES].items(): # chain
for k3, v3 in v2.items(): # ligand
for k4, v4 in v3.items(): # version
Expand All @@ -830,6 +832,7 @@ def _extract_components(self, crystals, aligner_meta):
self.logger.error("validation errors - can't extract components")
num_errors += 1
else:
num_pdbs += 1
pdbxtal.create_apo_file()
pdbxtal.create_apo_solv_desolv()

Expand Down Expand Up @@ -866,6 +869,7 @@ def _extract_components(self, crystals, aligner_meta):
)
traceback.print_exc()

self.num_alignments = num_pdbs
return num_errors


Expand Down Expand Up @@ -901,7 +905,10 @@ def main():
logger.error("There are errors, cannot continue")
exit(1)
else:
t0 = time.time()
a.run()
t1 = time.time()
logger.info("Handled {} alignments in {} secs".format(a.num_alignments, round(t1 - t0)))
# write a summary of errors and warnings
logger.report()
logger.close()
Expand Down
9 changes: 9 additions & 0 deletions src/xchemalign/collator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import shutil
import datetime
import re
import time
import traceback
from distutils import dir_util
import yaml
Expand Down Expand Up @@ -161,6 +162,7 @@ def __init__(self, config_file, log_file=None, log_level=0, include_git_info=Fal
self.new_or_updated_xtals = None
self.compound_codes = {}
self.compound_smiles = {}
self.num_crystals = 0
if not log_file:
log_file = self.output_path / 'collator.log'
self.logger = utils.Logger(logfile=log_file, level=log_level)
Expand Down Expand Up @@ -742,6 +744,7 @@ def _copy_files(self, meta):

event_tables = self._find_event_tables()
forbidden_unattested_ligand_events = {}
pdb_count = 0
for xtal_name, xtal in meta[Constants.META_XTALS].items():
dir = cryst_path / xtal_name

Expand Down Expand Up @@ -900,6 +903,7 @@ def _copy_files(self, meta):
"Failed to copy PDB file {} to {}".format(fdata[0], self.output_path / fdata[1])
)
else:
pdb_count += 1
data_to_add[Constants.META_XTAL_PDB] = {
Constants.META_FILE: str(fdata[1]),
Constants.META_SHA256: fdata[2],
Expand Down Expand Up @@ -1054,6 +1058,8 @@ def _copy_files(self, meta):
if ligand_binding_events:
data_to_add[Constants.META_BINDING_EVENT] = ligand_binding_events

self.num_crystals = pdb_count

new_xtal_data = {}
for k, v in historical_xtal_data.items():
new_xtal_data[k] = v
Expand Down Expand Up @@ -1305,8 +1311,11 @@ def main():
logger.close()
exit(1)
else:
t0 = time.time()
c.run(meta)
t1 = time.time()
# write a summary of errors and warnings
logger.info("Handled {} crystals in {} secs".format(c.num_crystals, round(t1 - t0)))
logger.report()
logger.close()
if logger.logfilename:
Expand Down

0 comments on commit 4f31250

Please sign in to comment.