Skip to content

Commit 64758b6

Browse files
committed
Fix process 21
1 parent bb18e07 commit 64758b6

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

libtbx/langchain/agent/best_files_tracker.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
from datetime import datetime
3333

3434
# Centralized pattern utilities - handle both PHENIX and standalone imports
35-
try:
36-
from libtbx.langchain.agent.pattern_manager import is_half_map
37-
except ImportError:
38-
from agent.pattern_manager import is_half_map
35+
# Override is_half_map with a stricter version that requires 'half' in name.
36+
# The pattern_manager version uses [_-]?[12]$ which false-positives on
37+
# sequentially numbered maps (map_1.ccp4, map_2.ccp4).
38+
def is_half_map(basename):
39+
"""Return True only if basename contains 'half' (strict version)."""
40+
return 'half' in basename.lower()
3941

4042

4143
# =============================================================================

libtbx/langchain/agent/workflow_state.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,37 @@ def _categorize_files(available_files, ligand_hints=None, files_local=True):
507507
if f not in files[lst_key]:
508508
files[lst_key].append(f)
509509

510+
# Post-processing: Validate half-map classification.
511+
#
512+
# Both the YAML and hardcoded categorizers can misclassify sequentially
513+
# numbered maps (map_1.ccp4, map_2.ccp4 from resolve_cryo_em segmentation)
514+
# as half-maps if broad patterns like *_[12].* are used.
515+
#
516+
# Half-maps from EMDB, RELION, CryoSPARC, and other cryo-EM software
517+
# always contain 'half' in their filename. Any file in half_map without
518+
# 'half' in the name is reclassified as full_map.
519+
if "half_map" in files and files["half_map"]:
520+
reclassified = []
521+
keep = []
522+
for f in files["half_map"]:
523+
if 'half' in os.path.basename(f).lower():
524+
keep.append(f)
525+
else:
526+
reclassified.append(f)
527+
if reclassified:
528+
files["half_map"] = keep
529+
if "full_map" not in files:
530+
files["full_map"] = []
531+
for f in reclassified:
532+
if f not in files["full_map"]:
533+
files["full_map"].append(f)
534+
# Also ensure reclassified files are in 'map' parent
535+
if "map" not in files:
536+
files["map"] = []
537+
for f in reclassified:
538+
if f not in files["map"]:
539+
files["map"].append(f)
540+
510541
# Post-processing: If we have exactly one half-map and no full maps,
511542
# treat it as a full map. Half-maps only make sense in pairs for FSC.
512543
# A user providing a single map (even if named like a half-map) wants to use it.

0 commit comments

Comments
 (0)