-
Notifications
You must be signed in to change notification settings - Fork 8
fix(evals): cif patching regression to allow protenix outputs to run on all evals, and remove hydrogens in RSCC parsing #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,6 @@ release_data/ | |
| *.pt | ||
| *.tar.gz | ||
| *.tgz | ||
| *.tar | ||
| output/ | ||
| .jj/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| from biotite.structure.io.pdbx import CIFColumn, CIFFile, set_structure | ||
| from loguru import logger | ||
| from sampleworks.utils.atom_array_utils import remove_atoms_with_any_nan_coords | ||
| from sampleworks.utils.cif_utils import add_category_to_cif | ||
| from sampleworks.utils.cif_utils import add_category_to_cif, resolve_mixed_hetatm_atom_altlocs | ||
|
|
||
|
|
||
| SAMPLEWORKS_CACHE = Path("~/.sampleworks/rcsb").expanduser() | ||
|
|
@@ -245,7 +245,14 @@ def patch_individual_cif_file( | |
| # fetch only downloads the file if it isn't already present. | ||
| rcsb_path = fetch(rcsb_id, format="cif", target_path=str(SAMPLEWORKS_CACHE)) | ||
|
|
||
| reference = load_any(reference_path) | ||
| # Mirror the fix from guidance_script_utils - strip mixed ATOM/HETATM altlocs | ||
| # at the same residue position (e.g. 6NI5/6 CYS/CSO) so the reference matches | ||
| # what is generated by guidance. Returns the original path if nothing to fix. | ||
| safe_reference_path = resolve_mixed_hetatm_atom_altlocs(reference_path) | ||
| reference = load_any(safe_reference_path) | ||
| if safe_reference_path != reference_path: | ||
| safe_reference_path.unlink() | ||
|
|
||
| asym_unit = load_any(cif_file) | ||
| asym_unit = ensure_atom_array_stack(asym_unit) | ||
|
Comment on lines
+248
to
257
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will address separately as there are multiple places this comes up. #339 |
||
| except Exception: | ||
|
|
@@ -269,20 +276,34 @@ def patch_individual_cif_file( | |
| logger.error(msg) | ||
| return msg | ||
|
|
||
| # patch the residue numbers to match the original pdb | ||
| mapping = {} | ||
| for cif_key, ref_key in zip(cif_keys, ref_keys, strict=True): | ||
| if cif_key[0] != ref_key[0]: | ||
| msg = f"Chain mismatch while remapping residues for {cif_path} vs {reference_path}" | ||
| logger.error(msg) | ||
| # return msg | ||
| # TODO: fix chain mismatches upstream (protenix json creation needs update) | ||
| # this breaks multi-chain stuff for now | ||
| # TODO: uncomment below region after fixing chain mismatches upstream | ||
| # (protenix json creation needs update) | ||
| # which breaks the commented multi-chain handling below | ||
|
|
||
| mapping[cif_key] = ref_key[1] | ||
| # patch the residue numbers to match the original pdb | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @k-chrispens did you apply this to all the generated CIF files? If so, I'm fine with it. We're probably going to be able to get rid of this script soon anyway.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I did! |
||
| # mapping = {} | ||
| # for cif_key, ref_key in zip(cif_keys, ref_keys, strict=True): | ||
| # if cif_key[0] != ref_key[0]: | ||
| # msg = f"Chain mismatch while remapping residues for {cif_path} vs {reference_path}" | ||
| # logger.error(msg) | ||
| # # return msg | ||
| # # TODO: fix chain mismatches upstream (protenix json creation needs update) | ||
| # # this breaks multi-chain stuff for now | ||
|
|
||
| # mapping[cif_key] = ref_key[1] | ||
|
|
||
| # TODO: delete the line below after uncommenting the mapping above | ||
| # Some models currently relabel chains and/or renumber residues, so we | ||
| # remap both per atom. ``mapping`` is keyed by the predicted (chain, res) and | ||
| # returns the reference (chain, res) at the same position | ||
| mapping = dict(zip(cif_keys, ref_keys, strict=True)) | ||
|
|
||
| atom_keys = list(zip(asym_unit.chain_id.tolist(), asym_unit.res_id.tolist())) | ||
| asym_unit.res_id = np.array([mapping[k] for k in atom_keys], dtype=asym_unit.res_id.dtype) | ||
| # TODO: uncomment after fixing chain mismatches upstream | ||
| # asym_unit.res_id = np.array([mapping[k] for k in atom_keys], dtype=asym_unit.res_id.dtype) | ||
| # TODO: delete these two lines after fixing chain mismatches upstream | ||
| asym_unit.chain_id = np.array([mapping[k][0] for k in atom_keys]) | ||
| asym_unit.res_id = np.array([mapping[k][1] for k in atom_keys], dtype=asym_unit.res_id.dtype) | ||
|
|
||
| # load the actual PDB, we'll copy the new coordinates and metadata into it. | ||
| template = CIFFile.read(rcsb_path) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you really want to remove hydrogens, add
hydrogen_policy="remove"