diff --git a/main.py b/main.py index 3fc5a7a..a6db2aa 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,36 @@ GOOD_FINAL_RFREE = 0.4 def dimple(wf, opt): + + # --- START ALPHAFOLD PRE-PROCESSOR FIX --- + 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 --- + + comment(' ### Dimple v%s. Problems and suggestions:' ' ccp4.github.io/dimple ###' % __version__) mtz_meta = wf.read_mtz_metadata(opt.mtz)