def from_dict(d, t=None): ''' Convert the dictionary to a crystal model Params: d The dictionary of parameters t The template dictionary to use Returns: The crystal model ''' # If None, return None if d == None: if t == None: return None else: return from_dict(t, None) elif t != None: d = dict(t.items() + d.items()) # Create the model from the dictionary if 'ML_half_mosaicity_deg' in d: assert 'ML_domain_size_ang' in d if d['ML_half_mosaicity_deg'] is None or d['ML_domain_size_ang'] is None: assert d['ML_half_mosaicity_deg'] is None and d['ML_domain_size_ang'] is None else: if 'mosaicity' in d and d['mosaicity'] > 0: print "Warning, two kinds of mosaicity found. Using Sauter2014 model" from dxtbx.model import MosaicCrystalSauter2014 return MosaicCrystalSauter2014.from_dict(d) if 'mosaicity' in d: from dxtbx.model import MosaicCrystalKabsch2010 return MosaicCrystalKabsch2010.from_dict(d) else: from dxtbx.model import Crystal return Crystal.from_dict(d)
def from_dict(d, t=None): """Convert the dictionary to a crystal model Params: d The dictionary of parameters t The template dictionary to use Returns: The crystal model """ if d is None and t is None: return None joint = t.copy() if t else {} joint.update(d) # Create the model from the dictionary if "ML_half_mosaicity_deg" in joint: assert "ML_domain_size_ang" in joint if (joint["ML_half_mosaicity_deg"] is None or joint["ML_domain_size_ang"] is None): assert (joint["ML_half_mosaicity_deg"] is None and joint["ML_domain_size_ang"] is None) else: if joint.get("mosaicity", 0) > 0: print( "Warning, two kinds of mosaicity found. Using Sauter2014 model" ) from dxtbx.model import MosaicCrystalSauter2014 return MosaicCrystalSauter2014.from_dict(joint) if "mosaicity" in joint: from dxtbx.model import MosaicCrystalKabsch2010 return MosaicCrystalKabsch2010.from_dict(joint) else: from dxtbx.model import Crystal return Crystal.from_dict(joint)