From 2b3caecda8f56e39934f15957cb11e4bd247cf8d Mon Sep 17 00:00:00 2001 From: Kevin Battaile Date: Fri, 12 Jun 2026 14:22:41 -0400 Subject: [PATCH 1/2] Fix: Prevent AlphaFold 1x1x1 dummy cell crashes using Gemmi to sync MTZ unit cell --- main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.py b/main.py index 3fc5a7a..a4ce3a4 100755 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ import os import sys import argparse +import gemmi if __name__ == '__main__' and __package__ is None: sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__ )))) @@ -47,6 +48,31 @@ GOOD_FINAL_RFREE = 0.4 def dimple(wf, opt): + + # --- START ALPHAFOLD PRE-PROCESSOR FIX --- + + if getattr(opt, 'pdbs', None): + for i, pdb_path in enumerate(opt.pdbs): + _st = gemmi.read_structure(pdb_path) + + # If we detect an AlphaFold dummy cell (a-axis <2) + if _st.cell.a < 2.0: + # Assign a save, massive dummy cell + # Volume = 1,000,000 A^3. rwcontents won't crash + # It will NOT match the MTZ, forcing dimple to use the phaser-mr path + _st.cell = gemmi.UnitCell(100.0, 100.0, 100.0, 90.0, 90.0, 90.0) + _st.spacegroup_hm = 'P 1' + + # Write to the absolute path of the output directory + new_filename = "fixed_AF_" + os.path.basename(pdb_path) + absolute_out_dir = os.path.abspath(opt.output_dir) + fixed_path = os.path.join(absolute_out_dir, new_filename) + _st.write_pdb(fixed_path) + opt.pdbs[i] = fixed_path + + # --- END ALPHAFOLD PRE-PROCESSOR FIX --- + + comment(' ### Dimple v%s. Problems and suggestions:' ' ccp4.github.io/dimple ###' % __version__) mtz_meta = wf.read_mtz_metadata(opt.mtz) From 14e4d7858ee0abb6edb83d29ac6d669f179c79f5 Mon Sep 17 00:00:00 2001 From: Kevin Battaile Date: Sat, 13 Jun 2026 12:31:35 -0400 Subject: [PATCH 2/2] Fix: Update pre-processor to handle list of inputs and ignore web downloads --- main.py | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index a4ce3a4..a6db2aa 100755 --- a/main.py +++ b/main.py @@ -50,26 +50,31 @@ def dimple(wf, opt): # --- START ALPHAFOLD PRE-PROCESSOR FIX --- - - if getattr(opt, 'pdbs', None): - for i, pdb_path in enumerate(opt.pdbs): - _st = gemmi.read_structure(pdb_path) - - # If we detect an AlphaFold dummy cell (a-axis <2) - if _st.cell.a < 2.0: - # Assign a save, massive dummy cell - # Volume = 1,000,000 A^3. rwcontents won't crash - # It will NOT match the MTZ, forcing dimple to use the phaser-mr path - _st.cell = gemmi.UnitCell(100.0, 100.0, 100.0, 90.0, 90.0, 90.0) - _st.spacegroup_hm = 'P 1' - - # Write to the absolute path of the output directory - new_filename = "fixed_AF_" + os.path.basename(pdb_path) - absolute_out_dir = os.path.abspath(opt.output_dir) - fixed_path = os.path.join(absolute_out_dir, new_filename) - _st.write_pdb(fixed_path) - opt.pdbs[i] = fixed_path - + for i, pdb_path in enumerate(opt.pdbs): + if os.path.isfile(pdb_path): + try: + pdb_st = gemmi.read_structure(pdb_path) + + # Check for the AlphaFold dummy cell (a-axis <2) + if pdb_st.cell.a < 2.0: + # Assign a safe, massive dummy cell + # Volume = 1,000,000 A^3. rwcontents won't crash + # It will NOT match the MTZ, forcing dimple to use the phaser-mr path + pdb_st.cell = gemmi.UnitCell(100.0, 100.0, 100.0, 90.0, 90.0, 90.0) + pdb_st.spacegroup_hm = 'P 1' + + # Write to the absolute path of the output directory + new_filename = "fixed_AF_" + os.path.basename(pdb_path) + absolute_out_dir = os.path.abspath(opt.output_dir) + fixed_path = os.path.join(absolute_out_dir, new_filename) + pdb_st.write_pdb(fixed_path) + + # Update Dimple's internal list to use the new patched file + opt.pdbs[i] = fixed_path + + except Exception as e: + # If gemmi fails for any reason, print a warning but don't crash + print(f"[*] Pre-processor warning: Could not read PDB with Gemmi ({e}). Proceeding...") # --- END ALPHAFOLD PRE-PROCESSOR FIX ---