From 2ce3ebb232ce6c2fd4bcf4771bcd7bf2494c4a97 Mon Sep 17 00:00:00 2001 From: "Nigel W. Moriarty" Date: Thu, 18 Sep 2025 10:28:19 -0700 Subject: [PATCH] start of ION select --- iotbx/pdb/atom_selection.py | 18 ++++++++++++ mmtbx/monomer_library/linking_setup.py | 39 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/iotbx/pdb/atom_selection.py b/iotbx/pdb/atom_selection.py index 653aebbfd14..790833ea639 100644 --- a/iotbx/pdb/atom_selection.py +++ b/iotbx/pdb/atom_selection.py @@ -192,6 +192,7 @@ class cache(slots_getstate_setstate): "nucleotide", "single_atom_residue", "water", + 'ion', "hetero", "backbone", "sidechain", @@ -207,6 +208,7 @@ def __init__(self, root, wildcard_escape_char='\\', self.protein = None self.nucleotide = None self.water = None + self.ion = None self.hetero = None self.backbone = None self.sidechain = None @@ -340,6 +342,17 @@ def get_water(self): self.water = (atoms.extract_tmp_as_size_t() == 1).iselection() return [self.water] + def get_ion(self): + from mmtbx.monomer_library.linking_setup import ad_hoc_single_metal_residue_element_types + if self.ion is None: + atoms = self.root.atoms() + atoms.set_chemical_element_simple_if_necessary() + for atom in atoms: + if atom.element.upper() in ad_hoc_single_metal_residue_element_types: + atom.tmp=1 + self.ion = (atoms.extract_tmp_as_size_t() == 1).iselection() + return [self.ion] + def get_protein(self): if self.protein is None: import iotbx.pdb @@ -524,6 +537,9 @@ def sel_nucleotide(self): def sel_water(self): return self.union(iselections=self.get_water()) + def sel_ion(self): + return self.union(iselections=self.get_ion()) + def sel_hetero(self): return self.union(iselections=self.get_hetero()) @@ -711,6 +727,8 @@ def try_compose_sequence(): result_stack.append(self.sel_single_atom_residue()) elif (lword == "water"): result_stack.append(self.sel_water()) + elif (lword == "ion"): + result_stack.append(self.sel_ion()) elif (lword == "hetero") or (lword == "hetatm"): result_stack.append(self.sel_hetero()) elif (lword == "bfactor") or (lword == "occupancy"): diff --git a/mmtbx/monomer_library/linking_setup.py b/mmtbx/monomer_library/linking_setup.py index 2fc0aa0845c..cba981714f2 100644 --- a/mmtbx/monomer_library/linking_setup.py +++ b/mmtbx/monomer_library/linking_setup.py @@ -1,6 +1,25 @@ # see iotbx/pdb/common_residue_names.h; additionally here only: U I from __future__ import absolute_import, division, print_function +ad_hoc_single_metal_residue_element_types_more_complete = """\ +LI BE +NA MG +AL +K CA +SC TI V CR MN FE CO NI CU ZN +GA GE AS SE +RB SR +Y ZR NB MO TC RU RH PD AG CD +IN SN SB TE I +CS BA +LA HF TA W RE OS IR PT AU HG +TL PB BI PO AT +FR RA +AC +CE PR ND PM SM EU GD TB DY HO ER TM YB LU +TB PA U NP PU AM CM BK CF ES FM MD NO LW +""".split() + ad_hoc_single_metal_residue_element_types = """\ ZN CA MG NA MN K FE CU CD HG NI CO SR CS PT BA TL PB SM AU RB YB LI MO LU CR OS GD TB LA AG HO GA CE W RU RE PR IR EU AL V PD U @@ -148,5 +167,25 @@ def skip_if_non_linking(lookup, atom1, atom2): assert 0 if __name__=="__main__": + from libtbx import easy_run print(skip_if_both) print(skip_if_longer) + from mmtbx.monomer_library.pdb_interpretation import ad_hoc_single_atom_residue_element_types + s1 = set(ad_hoc_single_metal_residue_element_types_more_complete) + s1 = set(ad_hoc_single_atom_residue_element_types) + s2 = set(ad_hoc_single_metal_residue_element_types) + print(s1) + print(s2) + print('-'*80) + print(s1.difference(s2)) + print('-'*80) + print(s2.difference(s1)) + print('-'*80) + # for e in ad_hoc_single_metal_residue_element_types_more_complete: + # cmd='mmtbx.where_is_that_cif_file %s source=ccd' % e + # print(cmd) + # rc=easy_run.go(cmd) + # print(dir(rc)) + # for line in rc.stdout_lines: + # print(line) + # # assert 0