Skip to content

Commit

Permalink
Clarify map_manager.is_compatible_model(model) means this model can b…
Browse files Browse the repository at this point in the history
…e used with this map manager
  • Loading branch information
terwill committed Dec 14, 2024
1 parent b1d31f6 commit c312cdb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
6 changes: 4 additions & 2 deletions cctbx/maptbx/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def __init__(self,
assert self._map_manager.map_data().accessor().origin() == (0, 0, 0)
if model is not None:
assert isinstance(model, mmtbx.model.manager)
assert map_manager.is_compatible_model(model)
assert map_manager.is_compatible_model(model,
require_match_unit_cell_crystal_symmetry=True)

self._force_wrapping = wrapping
if wrapping is None:
Expand Down Expand Up @@ -629,7 +630,8 @@ def __init__(self, map_manager,
assert resolution is not None
if model is not None:
assert isinstance(model, mmtbx.model.manager)
assert map_manager.is_compatible_model(model)
assert map_manager.is_compatible_model(model,
require_match_unit_cell_crystal_symmetry=True)
if self.map_manager().wrapping(): # map must be entire unit cell
assert map_manager.unit_cell_grid == map_manager.map_data().all()

Expand Down
33 changes: 22 additions & 11 deletions iotbx/map_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ def is_compatible_ncs_object(self, ncs_object, tol = 0.001):
return ok

def is_compatible_model(self, model,
require_match_unit_cell_crystal_symmetry=True,
require_match_unit_cell_crystal_symmetry = False,
absolute_angle_tolerance = 0.01,
absolute_length_tolerance = 0.01,
shift_tol = 0.001):
Expand All @@ -1940,13 +1940,12 @@ def is_compatible_model(self, model,
2. model current symmetry does not match map original or current
3. model has a shift_cart (shift applied) different than map shift_cart
NOTE: a True result does not mean that the model crystal_symmetry matches
the map crystal_symmetry. It does mean that it is reasonable to set the
model crystal_symmetry to match the map ones.
If require_match_unit_cell_crystal_symmetry is True, then they are
different if anything is different. If it is False, allow original
symmetries do not have to match
incompatible if anything is different.
If require_match_unit_cell_crystal_symmetry is False, original
symmetries do not have to match. Model crystal_symmetry can match
the unit_cell_crystal_symmetry or crystal_symmetry of the map.
'''

ok=None
Expand Down Expand Up @@ -1983,6 +1982,8 @@ def is_compatible_model(self, model,
text_map_uc=str(map_uc).replace("\n"," ")
text_map=str(map_sym).replace("\n"," ")

assert map_sym # map_sym should always should be there. model_sym could be missing

if require_match_unit_cell_crystal_symmetry and map_uc and (
not model_uc) and (
not map_sym.is_similar_symmetry(map_uc,
Expand All @@ -1998,7 +1999,7 @@ def is_compatible_model(self, model,
"\n%s\n. Current map symmetry is: \n%s\n " %(
text_map_uc,text_map)

elif model_uc and map_uc and (
elif model_sym and model_uc and map_uc and (
(not map_uc.is_similar_symmetry(map_sym,
absolute_angle_tolerance = absolute_angle_tolerance,
absolute_length_tolerance = absolute_length_tolerance,))
Expand All @@ -2014,31 +2015,41 @@ def is_compatible_model(self, model,
absolute_angle_tolerance = absolute_angle_tolerance,
absolute_length_tolerance = absolute_length_tolerance,
) ) ):
ok=False# model and map_manager symmetries present and do not match
ok=False # model and map_manager uc present and some symmetries do not match
text="Model original symmetry: \n%s\n and current symmetry :\n%s\n" %(
text_model_uc,text_model)+\
"do not match map unit_cell symmetry:"+\
" \n%s\n and map current symmetry: \n%s\n symmetry" %(
text_map_uc,text_map)
elif model_sym and map_uc and (not model_sym.is_similar_symmetry(map_uc,
elif map_uc and model_sym and (not model_sym.is_similar_symmetry(map_uc,
absolute_angle_tolerance = absolute_angle_tolerance,
absolute_length_tolerance = absolute_length_tolerance,
)) and (not
model_sym.is_similar_symmetry(map_sym,
absolute_angle_tolerance = absolute_angle_tolerance,
absolute_length_tolerance = absolute_length_tolerance,
)):
ok=False# model does not match either map symmetry
ok=False # model does not match either map symmetry
text="Model current symmetry: \n%s\n" %(
text_model)+\
" does not match map unit_cell symmetry:"+\
" \n%s\n or map current symmetry: \n%s\n" %(
text_map_uc,text_map)
elif model_sym and (not model_uc) and (not map_uc) and (
not model_sym.is_similar_symmetry(map_sym,
absolute_angle_tolerance = absolute_angle_tolerance,
absolute_length_tolerance = absolute_length_tolerance,
)):
ok=False # model has no uc and model symmetry does not match map symmetry
text="Model current symmetry: \n%s\n" %(
text_model)+\
" does not match map symmetry: \n%s\n" %( text_map)

elif require_match_unit_cell_crystal_symmetry and (
not model_sym) and (not model_uc):
ok=False # model does not have any symmetry so it does not match
text="Model has no symmetry and cannot match any map"

elif (not model_sym) and (not model_uc):
ok=True # model does not have any symmetry so anything is ok
text="Model has no symmetry and can match any map symmetry"
Expand Down
12 changes: 8 additions & 4 deletions iotbx/map_model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ def add_model_by_id(self, model, model_id,

if model and \
self.map_manager() and (
not self.map_manager().is_compatible_model(model)):
not self.map_manager().is_compatible_model(model,
require_match_unit_cell_crystal_symmetry=True)):
# needs shifting
self.shift_any_model_to_match(model,
set_unit_cell_crystal_symmetry = True)
Expand Down Expand Up @@ -7894,7 +7895,8 @@ def density_at_model_sites(self,
"There is no map with id='%s' available for density_at_model_sites" %(
map_id))

assert self.map_manager().is_compatible_model(model) # model must match
assert self.map_manager().is_compatible_model(model,
require_match_unit_cell_crystal_symmetry=True) # model must match

if selection_string:
sel = model.selection(selection_string)
Expand Down Expand Up @@ -7938,7 +7940,8 @@ def map_model_cc(self,
map_id))


if not self.map_manager().is_compatible_model(model): # model must match
if not self.map_manager().is_compatible_model(model,
require_match_unit_cell_crystal_symmetry=True): # model must match
print("Setting model crystal symmetry to match map", file = self.log)
model = model.deep_copy()
model.set_crystal_symmetry(self.map_manager().crystal_symmetry())
Expand Down Expand Up @@ -8632,7 +8635,8 @@ def generate_map(self,
log = null_out())

if have_map_manager: # make sure model matches
if not self.map_manager().is_compatible_model(model):
if not self.map_manager().is_compatible_model(model,
require_match_unit_cell_crystal_symmetry=True):
self.shift_any_model_to_match(model,
set_unit_cell_crystal_symmetry = True)

Expand Down

0 comments on commit c312cdb

Please sign in to comment.