From 083816b5beec9ba1c06079fd5ebb11ef10de5ab4 Mon Sep 17 00:00:00 2001 From: Pavel Afonine Date: Tue, 17 Sep 2024 13:19:22 -0700 Subject: [PATCH] Bug fixes with a test --- iotbx/pdb/hierarchy.py | 6 +- mmtbx/model/model.py | 8 ++ mmtbx/regression/model/tst_model_2.py | 137 ++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 2 deletions(-) diff --git a/iotbx/pdb/hierarchy.py b/iotbx/pdb/hierarchy.py index 1aa0415cf5..131a5789eb 100644 --- a/iotbx/pdb/hierarchy.py +++ b/iotbx/pdb/hierarchy.py @@ -2562,10 +2562,12 @@ def exchangeable_hd_selections(self): for chain in model.chains(): for residue_group in chain.residue_groups(): for i_gr1, atom_group_1 in enumerate(residue_group.atom_groups()): - elements_group1 = atom_group_1.atoms().extract_element() + elements_group1 = [ + e.strip() for e in atom_group_1.atoms().extract_element()] non_H_atoms_group1 = list(set(elements_group1) - set(['H','D'])) for i_gr2, atom_group_2 in enumerate(residue_group.atom_groups()): - elements_group2 = atom_group_2.atoms().extract_element() + elements_group2 = [ + e.strip() for e in atom_group_2.atoms().extract_element()] non_H_atoms_group2 = list(set(elements_group2) - set(['H','D'])) if non_H_atoms_group1 and non_H_atoms_group2: continue if(atom_group_1.altloc != atom_group_2.altloc and i_gr2 > i_gr1): diff --git a/mmtbx/model/model.py b/mmtbx/model/model.py index e3d342652d..2bc1568727 100644 --- a/mmtbx/model/model.py +++ b/mmtbx/model/model.py @@ -1092,6 +1092,14 @@ def get_site_symmetry_table(self): def altlocs_present(self): return self.get_hierarchy().altlocs_present() + def altlocs_present_only_hd(self): + noh_selection = self.selection("not (element H or element D)") + hierarchy_no_hd = self.get_hierarchy().select(noh_selection) + altlocs = hierarchy_no_hd.altlocs_present() + hd = self.get_hierarchy().exchangeable_hd_selections() + if not altlocs and len(hd)>0: return True + return False + def aa_residues_with_bound_sidechains(self): """ Return array of i_seqs of residue side chain atoms that are involved into diff --git a/mmtbx/regression/model/tst_model_2.py b/mmtbx/regression/model/tst_model_2.py index 54381854bf..2a25893fe1 100644 --- a/mmtbx/regression/model/tst_model_2.py +++ b/mmtbx/regression/model/tst_model_2.py @@ -491,8 +491,145 @@ def exercise_model_filename(): m = mmtbx.model.manager(model_input=inp) assert m.get_source_filename() is None +def exercise_altlocs_present(): + pdb_str1=""" +CRYST1 13.135 16.057 12.855 90.00 90.00 90.00 P 1 +ATOM 1 N HIS A 3 8.135 7.414 7.855 1.00 22.05 N +ATOM 2 CA HIS A 3 7.032 6.873 7.032 1.00 18.37 C +ATOM 3 C HIS A 3 7.233 5.393 6.739 1.00 13.79 C +ATOM 4 O HIS A 3 8.085 5.000 5.991 1.00 12.07 O +ATOM 5 CB HIS A 3 6.816 7.572 5.708 1.00 21.10 C +ATOM 6 CG HIS A 3 6.273 8.956 5.759 1.00 24.64 C +ATOM 7 ND1 HIS A 3 5.237 9.382 6.577 1.00 21.60 N +ATOM 8 CD2 HIS A 3 6.625 10.039 5.000 1.00 33.23 C +ATOM 9 CE1 HIS A 3 5.000 10.626 6.356 1.00 23.45 C +ATOM 10 NE2 HIS A 3 5.834 11.057 5.402 1.00 24.68 N +ATOM 11 OXT HIS A 3 6.509 4.555 7.276 1.00 13.79 O +ATOM 12 H HIS A 3 7.879 8.235 8.404 1.00 22.05 H +ATOM 13 H2 HIS A 3 8.446 6.714 8.498 1.00 22.05 H +ATOM 14 H3 HIS A 3 8.894 7.681 7.262 1.00 22.05 H +ATOM 15 HA HIS A 3 6.135 7.043 7.628 1.00 18.37 H +ATOM 16 HB2 HIS A 3 7.776 7.626 5.195 1.00 21.10 H +ATOM 17 HB3 HIS A 3 6.114 6.977 5.123 1.00 21.10 H +ATOM 18 HD2 HIS A 3 7.384 10.073 4.233 1.00 33.23 H +ATOM 19 HE1 HIS A 3 4.253 11.224 6.857 1.00 23.45 H + +ATOM 20 HD1AHIS A 3 4.740 8.798 7.250 0.50 21.60 H +ATOM 21 HE2AHIS A 3 5.867 12.008 5.035 0.50 24.68 H + +ATOM 22 DD1BHIS A 3 4.740 8.798 7.250 0.50 21.60 D +ATOM 23 DE2BHIS A 3 5.867 12.008 5.035 0.50 24.68 D +TER +END + """ + pdb_str2=""" +CRYST1 13.135 16.057 12.855 90.00 90.00 90.00 P 1 +ATOM 1 N HIS A 3 8.135 7.414 7.855 1.00 22.05 N +ATOM 2 CA AHIS A 3 7.032 6.873 7.032 1.00 18.37 C +ATOM 2 CA BHIS A 3 7.032 6.873 7.032 1.00 18.37 C +ATOM 3 C HIS A 3 7.233 5.393 6.739 1.00 13.79 C +ATOM 4 O HIS A 3 8.085 5.000 5.991 1.00 12.07 O +ATOM 5 CB HIS A 3 6.816 7.572 5.708 1.00 21.10 C +ATOM 6 CG HIS A 3 6.273 8.956 5.759 1.00 24.64 C +ATOM 7 ND1 HIS A 3 5.237 9.382 6.577 1.00 21.60 N +ATOM 8 CD2 HIS A 3 6.625 10.039 5.000 1.00 33.23 C +ATOM 9 CE1 HIS A 3 5.000 10.626 6.356 1.00 23.45 C +ATOM 10 NE2 HIS A 3 5.834 11.057 5.402 1.00 24.68 N +ATOM 11 OXT HIS A 3 6.509 4.555 7.276 1.00 13.79 O +ATOM 12 H HIS A 3 7.879 8.235 8.404 1.00 22.05 H +ATOM 13 H2 HIS A 3 8.446 6.714 8.498 1.00 22.05 H +ATOM 14 H3 HIS A 3 8.894 7.681 7.262 1.00 22.05 H +ATOM 15 HA HIS A 3 6.135 7.043 7.628 1.00 18.37 H +ATOM 16 HB2 HIS A 3 7.776 7.626 5.195 1.00 21.10 H +ATOM 17 HB3 HIS A 3 6.114 6.977 5.123 1.00 21.10 H +ATOM 18 HD2 HIS A 3 7.384 10.073 4.233 1.00 33.23 H +ATOM 19 HE1 HIS A 3 4.253 11.224 6.857 1.00 23.45 H + +ATOM 20 HD1AHIS A 3 4.740 8.798 7.250 0.50 21.60 H +ATOM 21 HE2AHIS A 3 5.867 12.008 5.035 0.50 24.68 H + +ATOM 22 DD1BHIS A 3 4.740 8.798 7.250 0.50 21.60 D +ATOM 23 DE2BHIS A 3 5.867 12.008 5.035 0.50 24.68 D +TER +END + """ + pdb_str3=""" +CRYST1 13.135 16.057 12.855 90.00 90.00 90.00 P 1 +ATOM 1 N HIS A 3 8.135 7.414 7.855 1.00 22.05 N +ATOM 2 CA AHIS A 3 7.032 6.873 7.032 1.00 18.37 C +ATOM 2 CA BHIS A 3 7.032 6.873 7.032 1.00 18.37 C +ATOM 3 C HIS A 3 7.233 5.393 6.739 1.00 13.79 C +ATOM 4 O HIS A 3 8.085 5.000 5.991 1.00 12.07 O +ATOM 5 CB HIS A 3 6.816 7.572 5.708 1.00 21.10 C +ATOM 6 CG HIS A 3 6.273 8.956 5.759 1.00 24.64 C +ATOM 7 ND1 HIS A 3 5.237 9.382 6.577 1.00 21.60 N +ATOM 8 CD2 HIS A 3 6.625 10.039 5.000 1.00 33.23 C +ATOM 9 CE1 HIS A 3 5.000 10.626 6.356 1.00 23.45 C +ATOM 10 NE2 HIS A 3 5.834 11.057 5.402 1.00 24.68 N +ATOM 11 OXT HIS A 3 6.509 4.555 7.276 1.00 13.79 O +ATOM 12 H HIS A 3 7.879 8.235 8.404 1.00 22.05 H +ATOM 13 H2 HIS A 3 8.446 6.714 8.498 1.00 22.05 H +ATOM 14 H3 HIS A 3 8.894 7.681 7.262 1.00 22.05 H +ATOM 15 HA HIS A 3 6.135 7.043 7.628 1.00 18.37 H +ATOM 16 HB2 HIS A 3 7.776 7.626 5.195 1.00 21.10 H +ATOM 17 HB3 HIS A 3 6.114 6.977 5.123 1.00 21.10 H +ATOM 18 HD2 HIS A 3 7.384 10.073 4.233 1.00 33.23 H +ATOM 19 HE1 HIS A 3 4.253 11.224 6.857 1.00 23.45 H +TER +END + """ + pdb_str4=""" +CRYST1 13.135 16.057 12.855 90.00 90.00 90.00 P 1 +ATOM 1 N HIS A 3 8.135 7.414 7.855 1.00 22.05 N +ATOM 2 CA HIS A 3 7.032 6.873 7.032 1.00 18.37 C +ATOM 3 C HIS A 3 7.233 5.393 6.739 1.00 13.79 C +ATOM 4 O HIS A 3 8.085 5.000 5.991 1.00 12.07 O +ATOM 5 CB HIS A 3 6.816 7.572 5.708 1.00 21.10 C +ATOM 6 CG HIS A 3 6.273 8.956 5.759 1.00 24.64 C +ATOM 7 ND1 HIS A 3 5.237 9.382 6.577 1.00 21.60 N +ATOM 8 CD2 HIS A 3 6.625 10.039 5.000 1.00 33.23 C +ATOM 9 CE1 HIS A 3 5.000 10.626 6.356 1.00 23.45 C +ATOM 10 NE2 HIS A 3 5.834 11.057 5.402 1.00 24.68 N +ATOM 11 OXT HIS A 3 6.509 4.555 7.276 1.00 13.79 O +ATOM 12 H HIS A 3 7.879 8.235 8.404 1.00 22.05 H +ATOM 13 H2 HIS A 3 8.446 6.714 8.498 1.00 22.05 H +ATOM 14 H3 HIS A 3 8.894 7.681 7.262 1.00 22.05 H +ATOM 15 HA HIS A 3 6.135 7.043 7.628 1.00 18.37 H +ATOM 16 HB2 HIS A 3 7.776 7.626 5.195 1.00 21.10 H +ATOM 17 HB3 HIS A 3 6.114 6.977 5.123 1.00 21.10 H +ATOM 18 HD2 HIS A 3 7.384 10.073 4.233 1.00 33.23 H +ATOM 19 HE1 HIS A 3 4.253 11.224 6.857 1.00 23.45 H +TER +END + """ + pdb_inp1 = iotbx.pdb.input(source_info=None, lines=pdb_str1) + m1 = mmtbx.model.manager(model_input = pdb_inp1) + # + pdb_inp2 = iotbx.pdb.input(source_info=None, lines=pdb_str2) + m2 = mmtbx.model.manager(model_input = pdb_inp2) + # + pdb_inp3 = iotbx.pdb.input(source_info=None, lines=pdb_str3) + m3 = mmtbx.model.manager(model_input = pdb_inp3) + # + pdb_inp4 = iotbx.pdb.input(source_info=None, lines=pdb_str4) + m4 = mmtbx.model.manager(model_input = pdb_inp4) + # + assert m1.altlocs_present() + assert m1.altlocs_present_only_hd() + # + assert m2.altlocs_present() + assert not m2.altlocs_present_only_hd() + # + assert m3.altlocs_present() + assert not m3.altlocs_present_only_hd() + # + assert not m4.altlocs_present() + assert not m4.altlocs_present_only_hd() + + if (__name__ == "__main__"): t0 = time.time() + exercise_altlocs_present() exercise_macromolecule_plus_hetatms_by_chain_selections() exercise_ss_creation_crash() exercise_set_b_iso()