Skip to content

Commit

Permalink
Remove checking of scatterer.label from adopt_xray_structure
Browse files Browse the repository at this point in the history
  • Loading branch information
olegsobolev committed Sep 21, 2023
1 parent e31f6f7 commit 74fb1e7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 32 deletions.
28 changes: 4 additions & 24 deletions iotbx/pdb/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from iotbx.pdb.modified_rna_dna_names import lookup as na_3_as_1_mod
from iotbx.pdb.utils import all_chain_ids, all_label_asym_ids
import iotbx.cif.model
from cctbx import crystal
from cctbx import crystal, adptbx
from cctbx.array_family import flex
import six
from six.moves import cStringIO as StringIO
Expand Down Expand Up @@ -808,20 +808,18 @@ def extract_xray_structure(self, crystal_symmetry=None,
else: # usual just use whatever is default in xray_structure_simple
return self.as_pdb_input(crystal_symmetry).xray_structure_simple()

def adopt_xray_structure(self, xray_structure, assert_identical_id_str=True):
def adopt_xray_structure(self, xray_structure):
"""
Apply the current (refined) atomic parameters from the cctbx.xray.structure
object to the atoms in the PDB hierarchy. This will fail if the labels of
the scatterers do not match the atom labels.
object to the atoms in the PDB hierarchy.
"""
from cctbx import adptbx
if(self.atoms_size() != xray_structure.scatterers().size()):
raise RuntimeError("Incompatible size of hierarchy and scatterers array.")
awl = self.atoms_with_labels()
scatterers = xray_structure.scatterers()
uc = xray_structure.unit_cell()
orth = uc.orthogonalize
def set_attr(sc, a):
for sc, a in zip(scatterers, awl):
a.set_xyz(new_xyz=orth(sc.site))
a.set_occ(new_occ=sc.occupancy)
a.set_b(new_b=adptbx.u_as_b(sc.u_iso_or_equiv(uc)))
Expand All @@ -835,24 +833,6 @@ def set_attr(sc, a):
element, charge = sc.element_and_charge_symbols()
a.set_element(element)
a.set_charge(charge)
def get_id(l):
# This function takes content between last 2 quotes and removes whitespaces.
# figure out positions of " (quotes)
r = [pos for pos, char in enumerate(l) if char == '"']
# do nothing if less than two quotes
if(len(r)<2): return None
# assign the last 2 to i,j... not clear when there will be more that 2 quotes in id_str or sc.label
i,j = r[-2:]
# drop the quotes and remove whitespaces while spoiling r.
r = "".join(l[i:j+1].replace('"',"").replace('"',"").split())
return r
for sc, a in zip(scatterers, awl):
if assert_identical_id_str:
l1 = get_id(sc.label)
l2 = get_id(a.id_str())
if(l1 != l2):
raise RuntimeError("Mismatch: \n %s \n %s \n"%(sc.label,a.id_str()))
set_attr(sc=sc, a=a)

def apply_rotation_translation(self, rot_matrices, trans_vectors):
"""
Expand Down
3 changes: 1 addition & 2 deletions iotbx/pdb/tst_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6435,8 +6435,7 @@ def exercise_adopt_xray_structure():
try: hierarchy.adopt_xray_structure(xray_structure=xrs)
except Exception as e: pass
else: raise Exception_expected
hierarchy.adopt_xray_structure(
xray_structure=xrs, assert_identical_id_str=False)
hierarchy.adopt_xray_structure(xray_structure=xrs)
xrs_new5 = hierarchy.extract_xray_structure(
crystal_symmetry=xrs.crystal_symmetry())
for s1,s2 in zip(xrs.scatterers(), xrs_new5.scatterers()):
Expand Down
8 changes: 2 additions & 6 deletions mmtbx/refinement/select_best_starting_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ def strip_model(
xray_structure = xray_structure.select(sele)
print(" removed %d waters" % n_wat, file=log)
pdb_hierarchy.atoms().reset_i_seq()
assert_identical_id_str = True
if (remove_alt_confs):
n_atoms_start = xray_structure.scatterers().size()
pdb_hierarchy.remove_alt_confs(always_keep_one_conformer=False)
Expand All @@ -390,7 +389,6 @@ def strip_model(
if (n_atoms_end != n_atoms_start):
print(" removed %d atoms in alternate conformations" % \
(n_atoms_end - n_atoms_start), file=log)
assert_identical_id_str = False
xray_structure = xray_structure.select(i_seqs)
pdb_hierarchy.atoms().reset_i_seq()
if (convert_semet_to_met):
Expand All @@ -400,14 +398,12 @@ def strip_model(
pdb_hierarchy.convert_semet_to_met()
if (convert_to_isotropic):
xray_structure.convert_to_isotropic()
pdb_hierarchy.adopt_xray_structure(xray_structure,
assert_identical_id_str=assert_identical_id_str)
pdb_hierarchy.adopt_xray_structure(xray_structure)
print(" converted all atoms to isotropic B-factors", file=log)
if (reset_occupancies):
assert (remove_alt_confs)
xray_structure.adjust_occupancy(occ_max=1.0, occ_min=1.0)
pdb_hierarchy.adopt_xray_structure(xray_structure,
assert_identical_id_str=assert_identical_id_str)
pdb_hierarchy.adopt_xray_structure(xray_structure)
print(" reset occupancy to 1.0 for all atoms", file=log)
if (reset_hetatm_flag):
for atom in pdb_hierarchy.atoms():
Expand Down

0 comments on commit 74fb1e7

Please sign in to comment.