cctbx_project
cctbx_project copied to clipboard
Deepcopy failure with mmtbx model.
Assertion error triggered on deepcopy of model.
~/miniconda3/envs/py39/lib/python3.9/site-packages/mmtbx/model/model.py in __init__(self, model_input, pdb_hierarchy, crystal_symmetry, restraint_objects, monomer_parameters, stop_for_unknowns, log, expand_with_mtrix, skip_ss_annotations)
202 if(pdb_hierarchy is not None):
203 assert model_input is None
--> 204 assert crystal_symmetry is not None
205 # Internals
206 self._processed = False
AssertionError:
See code below to reproduce:
from copy import deepcopy
from iotbx.data_manager import DataManager
filename = "test_pdb.pdb"
dm = DataManager(datatypes = ["model"])
dm.process_model_file(filename)
model = dm.get_model(model_filename[0])
cp_model = deepcopy(model)
cctbx install via conda on a ubuntu 18 PC
It looks like your model does not have a CRYST1
record. That defines the space group and unit cell which is the crystal_symmetry
object that is causing the error. If you add that record, the copy should work. We (@olegsobolev ) will look into handling this situation more gracefully.
Also, the mmtbx.model.model.manager
object has a deep_copy
function. Since that object has some C++ objects attached to it, the normal Python deepcopy
function may not do the right thing.
A way around it would be to call model.add_crystal_symmetry_if_necessary() before deep copying it. Basically, deep copy in the example tries to create mmtbx.model.manager using only pdb_hierarchy without crystal symmetry information which we are trying to forbid using the assertion. The explicit call to add crystal symmetry seems to be better than hiding it somewhere else to prevent the above behavior.