Esempio n. 1
0
 def __init__(self,
              fmodel,
              map_type_str,
              fo_scale,
              fc_scale,
              use_shelx_weight,
              shelx_weight_parameter,
              map_calculation_helper=None):
   self.mch = map_calculation_helper
   self.mnm = mmtbx.map_names(map_name_string = map_type_str)
   self.fmodel = fmodel
   self.fc_scale = fc_scale
   self.fo_scale = fo_scale
   self.f_obs = None
   self.f_model = None
   self.use_shelx_weight = use_shelx_weight
   self.shelx_weight_parameter = shelx_weight_parameter
   if(not self.mnm.ml_map):
     self.f_obs = self.fmodel.f_obs().data()*fo_scale
   else:
     if(self.mch is None): self.mch = self.fmodel.map_calculation_helper()
     if(self.fmodel.hl_coeffs() is None):
       self.f_obs = self.mch.f_obs.data()*fo_scale*self.mch.fom
     else:
       cp = fmodel.combine_phases(map_calculation_helper = self.mch)
       self.f_obs = self.mch.f_obs.data()*fo_scale*cp.f_obs_phase_and_fom_source()
Esempio n. 2
0
 def check_expected_error(s):
     cntr = 0
     try:
         r = mmtbx.map_names(map_name_string=s)
     except Sorry, e:
         assert str(e).count("Wrong map type requested: %s" % s) == 1
         cntr += 1
Esempio n. 3
0
 def __init__(self,
              fmodel,
              map_type_str,
              acentrics_scale = 2.0,
              centrics_scale = 1.0):
   """
   Compute x and y for x*Fobs-y*Fmodel given map type string
   """
   self.fmodel = fmodel
   mnm = mmtbx.map_names(map_name_string = map_type_str)
   # R.Read, SIGMAA: 2mFo-DFc (acentrics) & mFo (centrics)
   centric_flags  = self.fmodel.f_obs().centric_flags().data()
   acentric_flags = ~centric_flags
   if(mnm.k != 0):
     self.fo_scale = flex.double(self.fmodel.f_obs().size(), 1.0)
   else: self.fo_scale = flex.double(self.fmodel.f_obs().size(), 0.0)
   if(mnm.n != 0):
     self.fc_scale = flex.double(self.fmodel.f_obs().size(), 1.0)
   else: self.fc_scale = flex.double(self.fmodel.f_obs().size(), 0.0)
   abs_kn = abs(mnm.k*mnm.n)
   if(mnm.k != abs(mnm.n) and abs_kn > 1.e-6):
     self.fo_scale.set_selected(acentric_flags, mnm.k)
     self.fo_scale.set_selected( centric_flags, max(mnm.k-centrics_scale,0.))
     self.fc_scale.set_selected(acentric_flags, mnm.n)
     self.fc_scale.set_selected( centric_flags, max(mnm.n-centrics_scale,0.))
   elif(mnm.k == abs(mnm.n) and abs_kn > 1.e-6):
     fo_scale_k = self.fo_scale*mnm.k
     self.fc_scale_n = self.fc_scale*mnm.n
     self.fo_scale.set_selected(acentric_flags, fo_scale_k*acentrics_scale)
     self.fo_scale.set_selected( centric_flags, fo_scale_k)
     self.fc_scale.set_selected(acentric_flags, self.fc_scale_n*acentrics_scale)
     self.fc_scale.set_selected( centric_flags, self.fc_scale_n)
   else:
     self.fo_scale *= mnm.k
     self.fc_scale *= mnm.n
Esempio n. 4
0
def validate_map_params(params):
    from mmtbx import map_names
    labels = []
    for map_coeffs in params.map_coefficients:
        if (map_coeffs.map_type is not None):
            try:
                decode_map = map_names(map_coeffs.map_type)
            except RuntimeError as e:
                raise Sorry(str(e))
            f = map_coeffs.mtz_label_amplitudes
            phi = map_coeffs.mtz_label_phases
            if (f in labels) or (phi in labels):
                raise Sorry((
                    "The map coefficients with MTZ labels %s,%s duplicates at"
                    +
                    " least one previously defined label.  You may output multiple sets "
                    +
                    "of coefficients with the same map type, but the column labels must "
                    + "be unique.") % (f, phi))
            elif (None in [f, phi]):
                raise Sorry(
                    "Please specify both MTZ column labels for map_type '%s'."
                    % map_coeffs.map_type)
            labels.extend([f, phi])
    if (hasattr(params, "map")):
        for map in params.map:
            if (map.grid_resolution_factor > 0.5):
                # XXX can't we enforce this in phil?
                raise Sorry(
                    "The grid resolution factor for CCP4 and X-PLOR maps " +
                    "must be 0.5 or less.")
    return True
Esempio n. 5
0
 def __init__(self,
              fmodel,
              map_type_str,
              fo_scale,
              fc_scale,
              use_shelx_weight,
              shelx_weight_parameter,
              map_calculation_helper=None):
   self.mch = map_calculation_helper
   self.mnm = mmtbx.map_names(map_name_string = map_type_str)
   self.fmodel = fmodel
   self.fc_scale = fc_scale
   self.fo_scale = fo_scale
   self.f_obs = None
   self.f_model = None
   self.use_shelx_weight = use_shelx_weight
   self.shelx_weight_parameter = shelx_weight_parameter
   if(not self.mnm.ml_map):
     self.f_obs = self.fmodel.f_obs().data()*fo_scale
   else:
     if(self.mch is None): self.mch = self.fmodel.map_calculation_helper()
     if(self.fmodel.hl_coeffs() is None):
       self.f_obs = self.mch.f_obs.data()*fo_scale*self.mch.fom
     else:
       cp = fmodel.combine_phases(map_calculation_helper = self.mch)
       self.f_obs = self.mch.f_obs.data()*fo_scale*cp.f_obs_phase_and_fom_source()
Esempio n. 6
0
 def __init__(self,
              fmodel,
              map_type_str,
              acentrics_scale = 2.0,
              centrics_scale = 1.0):
   """
   Compute x and y for x*Fobs-y*Fmodel given map type string
   """
   self.fmodel = fmodel
   mnm = mmtbx.map_names(map_name_string = map_type_str)
   # R.Read, SIGMAA: 2mFo-DFc (acentrics) & mFo (centrics)
   centric_flags  = self.fmodel.f_obs().centric_flags().data()
   acentric_flags = ~centric_flags
   if(mnm.k != 0):
     self.fo_scale = flex.double(self.fmodel.f_obs().size(), 1.0)
   else: self.fo_scale = flex.double(self.fmodel.f_obs().size(), 0.0)
   if(mnm.n != 0):
     self.fc_scale = flex.double(self.fmodel.f_obs().size(), 1.0)
   else: self.fc_scale = flex.double(self.fmodel.f_obs().size(), 0.0)
   abs_kn = abs(mnm.k*mnm.n)
   if(mnm.k != abs(mnm.n) and abs_kn > 1.e-6):
     self.fo_scale.set_selected(acentric_flags, mnm.k)
     self.fo_scale.set_selected( centric_flags, max(mnm.k-centrics_scale,0.))
     self.fc_scale.set_selected(acentric_flags, mnm.n)
     self.fc_scale.set_selected( centric_flags, max(mnm.n-centrics_scale,0.))
   elif(mnm.k == abs(mnm.n) and abs_kn > 1.e-6):
     fo_scale_k = self.fo_scale*mnm.k
     self.fc_scale_n = self.fc_scale*mnm.n
     self.fo_scale.set_selected(acentric_flags, fo_scale_k*acentrics_scale)
     self.fo_scale.set_selected( centric_flags, fo_scale_k)
     self.fc_scale.set_selected(acentric_flags, self.fc_scale_n*acentrics_scale)
     self.fc_scale.set_selected( centric_flags, self.fc_scale_n)
   else:
     self.fo_scale *= mnm.k
     self.fc_scale *= mnm.n
Esempio n. 7
0
def map_coefficients_from_fmodel(
      params,
      fmodel = None,
      map_calculation_server = None,
      post_processing_callback=None,
      pdb_hierarchy=None):
  assert [fmodel, map_calculation_server].count(None) == 1
  from mmtbx import map_tools
  import mmtbx
  from cctbx import miller
  mnm = mmtbx.map_names(map_name_string = params.map_type)
  if(mnm.k==0 and abs(mnm.n)==1):
    # FIXME Fcalc maps require that fmodel is not None!
    if (fmodel is None) :
      fmodel = map_calculation_server.fmodel
    return compute_f_calc(fmodel, params)
  if(fmodel is not None and
     fmodel.is_twin_fmodel_manager() and
     mnm.phaser_sad_llg):
    return None
  if(fmodel is not None):
    e_map_obj = fmodel.electron_density_map()
    xrs = fmodel.xray_structure
  else:
    e_map_obj = map_calculation_server
    xrs = map_calculation_server.fmodel.xray_structure
  coeffs = None
  coeffs = e_map_obj.map_coefficients(
    map_type           = params.map_type,
    acentrics_scale    = params.acentrics_scale,
    centrics_pre_scale = params.centrics_pre_scale,
    fill_missing       = params.fill_missing_f_obs,
    isotropize         = params.isotropize,
    exclude_free_r_reflections=params.exclude_free_r_reflections,
    ncs_average=getattr(params, "ncs_average", False),
    post_processing_callback=post_processing_callback,
    pdb_hierarchy=pdb_hierarchy,
    merge_anomalous=True)
  if (coeffs is None) : return None
  if(params.sharpening):
    from mmtbx import map_tools
    coeffs, b_sharp = map_tools.sharp_map(
      sites_frac = xrs.sites_frac(),
      map_coeffs = coeffs,
      b_sharp    = params.sharpening_b_factor)
  # XXX need to figure out why this happens
  if (coeffs is None) :
    raise RuntimeError(("Map coefficient generation failed (map_type=%s, "
      "sharpening=%s, isotropize=%s, anomalous=%s.") %
        (params.map_type, params.sharpening, params.isotropize,
         fmodel.f_obs().anomalous_flag()))
  if(coeffs.anomalous_flag()) :
    coeffs = coeffs.average_bijvoet_mates()
  return coeffs
Esempio n. 8
0
def validate_map_params(params):
    from mmtbx import map_names
    labels = []
    for map_coeffs in params.map_coefficients:
        if (map_coeffs.map_type is not None):
            try:
                decode_map = map_names(map_coeffs.map_type)
            except RuntimeError, e:
                raise Sorry(str(e))
            f = map_coeffs.mtz_label_amplitudes
            phi = map_coeffs.mtz_label_phases
            if (f in labels) or (phi in labels):
                raise Sorry((
                    "The map coefficients with MTZ labels %s,%s duplicates at"
                    +
                    " least one previously defined label.  You may output multiple sets "
                    +
                    "of coefficients with the same map type, but the column labels must "
                    + "be unique.") % (f, phi))
            elif (None in [f, phi]):
                raise Sorry(
                    "Please specify both MTZ column labels for map_type '%s'."
                    % map_coeffs.map_type)
            labels.extend([f, phi])
Esempio n. 9
0
 def map_coefficients(self,
                      map_type,
                      acentrics_scale = 2.0,
                      centrics_pre_scale = 1.0,
                      exclude_free_r_reflections=False,
                      fill_missing=False,
                      fill_missing_method="f_model",
                      isotropize=True,
                      sharp=False,
                      pdb_hierarchy=None, # XXX required for map_type=llg
                      merge_anomalous=None,
                      use_shelx_weight=False,
                      shelx_weight_parameter=1.5):
   map_name_manager = mmtbx.map_names(map_name_string = map_type)
   # Special case #1: anomalous map
   if(map_name_manager.anomalous):
     if(self.anom_diff is not None):
       # Formula from page 141 in "The Bijvoet-Difference Fourier Synthesis",
       # Jeffrey Roach, METHODS IN ENZYMOLOGY, VOL. 374
       return miller.array(miller_set = self.anom_diff,
                           data       = self.anom_diff.data()/(2j))
     else: return None
   # Special case #2: anomalous residual map
   elif (map_name_manager.anomalous_residual):
     if (self.anom_diff is not None):
       return anomalous_residual_map_coefficients(
         fmodel=self.fmodel,
         exclude_free_r_reflections=exclude_free_r_reflections)
     else : return None
   # Special case #3: Phaser SAD LLG map
   elif (map_name_manager.phaser_sad_llg):
     if (pdb_hierarchy is None):
       raise RuntimeError("pdb_hierarchy must not be None when a Phaser SAD "+
         "LLG map is requested.")
     if (self.anom_diff is not None):
       return get_phaser_sad_llg_map_coefficients(
         fmodel=self.fmodel,
         pdb_hierarchy=pdb_hierarchy)
     else :
       return None
   # Special case #4: Fcalc map
   mnm = mmtbx.map_names(map_name_string = map_type)
   if(mnm.k==0 and abs(mnm.n)==1):
     if(fill_missing):
       return self.fmodel.xray_structure.structure_factors(
         d_min = self.fmodel.f_obs().d_min()).f_calc()
     else:
       return self.fmodel.f_obs().structure_factors_from_scatterers(
         xray_structure = self.fmodel.xray_structure).f_calc()
   #
   if(self.mch is None):
     self.mch = self.fmodel.map_calculation_helper()
   ffs = fo_fc_scales(
     fmodel          = self.fmodel,
     map_type_str    = map_type,
     acentrics_scale = acentrics_scale,
     centrics_scale  = centrics_pre_scale)
   fo_scale, fc_scale = ffs.fo_scale, ffs.fc_scale
   coeffs = combine(
     fmodel                 = self.fmodel,
     map_type_str           = map_type,
     fo_scale               = fo_scale,
     fc_scale               = fc_scale,
     map_calculation_helper = self.mch,
     use_shelx_weight       = use_shelx_weight,
     shelx_weight_parameter = shelx_weight_parameter).map_coefficients()
   r_free_flags = None
   # XXX the default scale array (used for the isotropize option) needs to be
   # calculated and processed now to avoid array size errors
   scale_default = 1. / (self.fmodel.k_isotropic()*self.fmodel.k_anisotropic())
   scale_array = coeffs.customized_copy(data=scale_default)
   if (exclude_free_r_reflections):
     if (coeffs.anomalous_flag()):
       coeffs = coeffs.average_bijvoet_mates()
     r_free_flags = self.fmodel.r_free_flags()
     if (r_free_flags.anomalous_flag()):
       r_free_flags = r_free_flags.average_bijvoet_mates()
       scale_array = scale_array.average_bijvoet_mates()
     coeffs = coeffs.select(~r_free_flags.data())
     scale_array = scale_array.select(~r_free_flags.data())
   scale=None
   if(isotropize):
     if(scale is None):
       if (scale_array.anomalous_flag()) and (not coeffs.anomalous_flag()):
         scale_array = scale_array.average_bijvoet_mates()
       scale = scale_array.data()
     coeffs = coeffs.customized_copy(data = coeffs.data()*scale)
   if(fill_missing):
     if(coeffs.anomalous_flag()):
       coeffs = coeffs.average_bijvoet_mates()
     coeffs = fill_missing_f_obs(
       coeffs = coeffs,
       fmodel = self.fmodel,
       method = fill_missing_method)
   if(sharp):
     ss = 1./flex.pow2(coeffs.d_spacings().data()) / 4.
     from cctbx import adptbx
     b = flex.mean(self.fmodel.xray_structure.extract_u_iso_or_u_equiv() *
       adptbx.u_as_b(1))/2
     k_sharp = 1./flex.exp(-ss * b)
     coeffs = coeffs.customized_copy(data = coeffs.data()*k_sharp)
   if (merge_anomalous) and (coeffs.anomalous_flag()):
     return coeffs.average_bijvoet_mates()
   return coeffs
def exercise():
  r = mmtbx.map_names(map_name_string = "anom")
  assert r.format() == "anomalous_difference", r.format()
  r = mmtbx.map_names(map_name_string = "anomalous")
  assert r.format() == "anomalous_difference", r.format()
  r = mmtbx.map_names(map_name_string = " Anomal-diff  ")
  assert r.format() == "anomalous_difference", r.format()
  r = mmtbx.map_names(map_name_string = "LLG")
  assert r.format() == "phaser_sad_llg"
  r = mmtbx.map_names(map_name_string = " SAD")
  assert r.format() == "phaser_sad_llg"
  #
  r = mmtbx.map_names(map_name_string = "3.mFo-2DFc ")
  assert r.format() == "3mFobs-2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "mFo-DFc ")
  assert r.format() == "mFobs-DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "mFo-1.DFc ")
  assert r.format() == "mFobs-DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "+3.mFo+2DFc ")
  assert r.format() == "3mFobs+2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-3.mFo+2DFc")
  assert r.format() == "-3mFobs+2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-2DFc+3.mFo")
  assert r.format() == "3mFobs-2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "- 2 D F c + 3 . m F o ")
  assert r.format() == "3mFobs-2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-  D F ca lc 2.0 +  m F oBS 3 .0")
  assert r.format() == "3mFobs-2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-2DFc-3.mFo")
  assert r.format() == "-3mFobs-2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "+2DFc+3.mFo")
  assert r.format() == "3mFobs+2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-3.mF_OBS-2D_F_cAlC")
  assert r.format() == "-3mFobs-2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "+3.mF_o+2 . D F_MODEL")
  assert r.format() == "3mFobs+2DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "0.75mFobs-1.37DFmodel")
  assert r.format() == "0.75mFobs-1.37DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "0.99999mFobs-1.00001DFmodel")
  assert r.format() == "0.99999mFobs-1.00001DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "0mFobs-0DFmodel")
  assert r.format() == "0mFobs-0DFmodel", r.format()
  #
  r = mmtbx.map_names(map_name_string = "3.Fo-2Fc ")
  assert r.format() == "3Fobs-2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "Fo-Fc ")
  assert r.format() == "Fobs-Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "Fo-1.Fc ")
  assert r.format() == "Fobs-Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "+3.Fo+2Fc ")
  assert r.format() == "3Fobs+2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-3.Fo+2Fc")
  assert r.format() == "-3Fobs+2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-2Fc+3.Fo")
  assert r.format() == "3Fobs-2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "- 2  F c + 3 .  F o ")
  assert r.format() == "3Fobs-2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-   F ca lc 2.0 +   F oBS 3 .0")
  assert r.format() == "3Fobs-2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-2Fc-3.Fo")
  assert r.format() == "-3Fobs-2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "+2Fc+3.Fo")
  assert r.format() == "3Fobs+2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "-3.F_OBS-2_F_cAlC")
  assert r.format() == "-3Fobs-2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "+3.F_o+2 .  F_MODEL")
  assert r.format() == "3Fobs+2Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "0.75Fobs-1.37Fmodel")
  assert r.format() == "0.75Fobs-1.37Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "0.99999Fobs-1.00001Fmodel")
  assert r.format() == "0.99999Fobs-1.00001Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "0Fobs-0Fmodel")
  assert r.format() == "0Fobs-0Fmodel", r.format()
  #
  r = mmtbx.map_names(map_name_string = "fc")
  assert r.format() == "0Fobs+Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "FMODEL")
  assert r.format() == "0Fobs+Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "dfc")
  assert r.format() == "0mFobs+DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "dFMODEL")
  assert r.format() == "0mFobs+DFmodel", r.format()
  #
  r = mmtbx.map_names(map_name_string = "fo")
  assert r.format() == "Fobs-0Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "FoBS")
  assert r.format() == "Fobs-0Fmodel", r.format()
  r = mmtbx.map_names(map_name_string = "mfo")
  assert r.format() == "mFobs-0DFmodel", r.format()
  r = mmtbx.map_names(map_name_string = "MFOBS")
  assert r.format() == "mFobs-0DFmodel", r.format()
  #
  r = mmtbx.map_names(map_name_string = "3.mFo-2DFc__filled")
  assert r.format() == "3mFobs-2DFmodel_filled", r.format()
  r = mmtbx.map_names(map_name_string = "3.Fo-2Fc+filled")
  assert r.format() == "3Fobs-2Fmodel_filled", r.format()
  #
  def check_expected_error(s):
    cntr = 0
    try: r = mmtbx.map_names(map_name_string = s)
    except Sorry, e:
      assert str(e).count("Wrong map type requested: %s"%s)==1
      cntr += 1
    assert cntr == 1
 def check_expected_error(s):
   cntr = 0
   try: r = mmtbx.map_names(map_name_string = s)
   except Sorry, e:
     assert str(e).count("Wrong map type requested: %s"%s)==1
     cntr += 1
Esempio n. 12
0
def exercise():
    r = mmtbx.map_names(map_name_string="anom")
    assert r.format() == "anomalous_difference", r.format()
    r = mmtbx.map_names(map_name_string="anomalous")
    assert r.format() == "anomalous_difference", r.format()
    r = mmtbx.map_names(map_name_string=" Anomal-diff  ")
    assert r.format() == "anomalous_difference", r.format()
    r = mmtbx.map_names(map_name_string="LLG")
    assert r.format() == "phaser_sad_llg"
    r = mmtbx.map_names(map_name_string=" SAD")
    assert r.format() == "phaser_sad_llg"
    #
    r = mmtbx.map_names(map_name_string="3.mFo-2DFc ")
    assert r.format() == "3mFobs-2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="mFo-DFc ")
    assert r.format() == "mFobs-DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="mFo-1.DFc ")
    assert r.format() == "mFobs-DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="+3.mFo+2DFc ")
    assert r.format() == "3mFobs+2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="-3.mFo+2DFc")
    assert r.format() == "-3mFobs+2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="-2DFc+3.mFo")
    assert r.format() == "3mFobs-2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="- 2 D F c + 3 . m F o ")
    assert r.format() == "3mFobs-2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="-  D F ca lc 2.0 +  m F oBS 3 .0")
    assert r.format() == "3mFobs-2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="-2DFc-3.mFo")
    assert r.format() == "-3mFobs-2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="+2DFc+3.mFo")
    assert r.format() == "3mFobs+2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="-3.mF_OBS-2D_F_cAlC")
    assert r.format() == "-3mFobs-2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="+3.mF_o+2 . D F_MODEL")
    assert r.format() == "3mFobs+2DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="0.75mFobs-1.37DFmodel")
    assert r.format() == "0.75mFobs-1.37DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="0.99999mFobs-1.00001DFmodel")
    assert r.format() == "0.99999mFobs-1.00001DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="0mFobs-0DFmodel")
    assert r.format() == "0mFobs-0DFmodel", r.format()
    #
    r = mmtbx.map_names(map_name_string="3.Fo-2Fc ")
    assert r.format() == "3Fobs-2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="Fo-Fc ")
    assert r.format() == "Fobs-Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="Fo-1.Fc ")
    assert r.format() == "Fobs-Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="+3.Fo+2Fc ")
    assert r.format() == "3Fobs+2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="-3.Fo+2Fc")
    assert r.format() == "-3Fobs+2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="-2Fc+3.Fo")
    assert r.format() == "3Fobs-2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="- 2  F c + 3 .  F o ")
    assert r.format() == "3Fobs-2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="-   F ca lc 2.0 +   F oBS 3 .0")
    assert r.format() == "3Fobs-2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="-2Fc-3.Fo")
    assert r.format() == "-3Fobs-2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="+2Fc+3.Fo")
    assert r.format() == "3Fobs+2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="-3.F_OBS-2_F_cAlC")
    assert r.format() == "-3Fobs-2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="+3.F_o+2 .  F_MODEL")
    assert r.format() == "3Fobs+2Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="0.75Fobs-1.37Fmodel")
    assert r.format() == "0.75Fobs-1.37Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="0.99999Fobs-1.00001Fmodel")
    assert r.format() == "0.99999Fobs-1.00001Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="0Fobs-0Fmodel")
    assert r.format() == "0Fobs-0Fmodel", r.format()
    #
    r = mmtbx.map_names(map_name_string="fc")
    assert r.format() == "0Fobs+Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="FMODEL")
    assert r.format() == "0Fobs+Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="dfc")
    assert r.format() == "0mFobs+DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="dFMODEL")
    assert r.format() == "0mFobs+DFmodel", r.format()
    #
    r = mmtbx.map_names(map_name_string="fo")
    assert r.format() == "Fobs-0Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="FoBS")
    assert r.format() == "Fobs-0Fmodel", r.format()
    r = mmtbx.map_names(map_name_string="mfo")
    assert r.format() == "mFobs-0DFmodel", r.format()
    r = mmtbx.map_names(map_name_string="MFOBS")
    assert r.format() == "mFobs-0DFmodel", r.format()
    #
    r = mmtbx.map_names(map_name_string="3.mFo-2DFc__filled")
    assert r.format() == "3mFobs-2DFmodel_filled", r.format()
    r = mmtbx.map_names(map_name_string="3.Fo-2Fc+filled")
    assert r.format() == "3Fobs-2Fmodel_filled", r.format()

    #
    def check_expected_error(s):
        cntr = 0
        try:
            r = mmtbx.map_names(map_name_string=s)
        except Sorry, e:
            assert str(e).count("Wrong map type requested: %s" % s) == 1
            cntr += 1
        assert cntr == 1
Esempio n. 13
0
 def map_coefficients(self,
                      map_type,
                      acentrics_scale = 2.0,
                      centrics_pre_scale = 1.0,
                      exclude_free_r_reflections=False,
                      fill_missing=False,
                      fill_missing_method="f_model",
                      ncs_average=False,
                      isotropize=True,
                      sharp=False,
                      post_processing_callback=None,
                      pdb_hierarchy=None, # XXX required for map_type=llg
                      merge_anomalous=None,
                      use_shelx_weight=False,
                      shelx_weight_parameter=1.5) :
   map_name_manager = mmtbx.map_names(map_name_string = map_type)
   # Special case #1: anomalous map
   if(map_name_manager.anomalous):
     if(self.anom_diff is not None):
       # Formula from page 141 in "The Bijvoet-Difference Fourier Synthesis",
       # Jeffrey Roach, METHODS IN ENZYMOLOGY, VOL. 374
       return miller.array(miller_set = self.anom_diff,
                           data       = self.anom_diff.data()/(2j))
     else: return None
   # Special case #2: anomalous residual map
   elif (map_name_manager.anomalous_residual) :
     if (self.anom_diff is not None) :
       return anomalous_residual_map_coefficients(
         fmodel=self.fmodel,
         exclude_free_r_reflections=exclude_free_r_reflections)
     else : return None
   # Special case #3: Phaser SAD LLG map
   elif (map_name_manager.phaser_sad_llg) :
     if (pdb_hierarchy is None) :
       raise RuntimeError("pdb_hierarchy must not be None when a Phaser SAD "+
         "LLG map is requested.")
     if (self.anom_diff is not None) :
       return get_phaser_sad_llg_map_coefficients(
         fmodel=self.fmodel,
         pdb_hierarchy=pdb_hierarchy)
     else :
       return None
   # Special case #4: Fcalc map
   mnm = mmtbx.map_names(map_name_string = map_type)
   if(mnm.k==0 and abs(mnm.n)==1):
     if(fill_missing):
       return self.fmodel.xray_structure.structure_factors(
         d_min = self.fmodel.f_obs().d_min()).f_calc()
     else:
       return self.fmodel.f_obs().structure_factors_from_scatterers(
         xray_structure = self.fmodel.xray_structure).f_calc()
   #
   if(self.mch is None):
     self.mch = self.fmodel.map_calculation_helper()
   ffs = fo_fc_scales(
     fmodel          = self.fmodel,
     map_type_str    = map_type,
     acentrics_scale = acentrics_scale,
     centrics_scale  = centrics_pre_scale)
   fo_scale, fc_scale = ffs.fo_scale, ffs.fc_scale
   coeffs = combine(
     fmodel                 = self.fmodel,
     map_type_str           = map_type,
     fo_scale               = fo_scale,
     fc_scale               = fc_scale,
     map_calculation_helper = self.mch,
     use_shelx_weight       = use_shelx_weight,
     shelx_weight_parameter = shelx_weight_parameter).map_coefficients()
   r_free_flags = None
   # XXX the default scale array (used for the isotropize option) needs to be
   # calculated and processed now to avoid array size errors
   scale_default = 1. / (self.fmodel.k_isotropic()*self.fmodel.k_anisotropic())
   scale_array = coeffs.customized_copy(data=scale_default)
   if (exclude_free_r_reflections) :
     if (coeffs.anomalous_flag()) :
       coeffs = coeffs.average_bijvoet_mates()
     r_free_flags = self.fmodel.r_free_flags()
     if (r_free_flags.anomalous_flag()) :
       r_free_flags = r_free_flags.average_bijvoet_mates()
       scale_array = scale_array.average_bijvoet_mates()
     coeffs = coeffs.select(~r_free_flags.data())
     scale_array = scale_array.select(~r_free_flags.data())
   scale=None
   if (ncs_average) and (post_processing_callback is not None) :
     # XXX NCS averaging done here
     assert hasattr(post_processing_callback, "__call__")
     coeffs = post_processing_callback(
       map_coeffs=coeffs,
       fmodel=self.fmodel,
       map_type=map_type)
   if(isotropize):
     if(scale is None):
       if (scale_array.anomalous_flag()) and (not coeffs.anomalous_flag()) :
         scale_array = scale_array.average_bijvoet_mates()
       scale = scale_array.data()
     coeffs = coeffs.customized_copy(data = coeffs.data()*scale)
   if(fill_missing):
     if(coeffs.anomalous_flag()):
       coeffs = coeffs.average_bijvoet_mates()
     coeffs = fill_missing_f_obs(
       coeffs = coeffs,
       fmodel = self.fmodel,
       method = fill_missing_method)
   if(sharp):
     ss = 1./flex.pow2(coeffs.d_spacings().data()) / 4.
     from cctbx import adptbx
     b = flex.mean(self.fmodel.xray_structure.extract_u_iso_or_u_equiv() *
       adptbx.u_as_b(1))/2
     k_sharp = 1./flex.exp(-ss * b)
     coeffs = coeffs.customized_copy(data = coeffs.data()*k_sharp)
   if (merge_anomalous) and (coeffs.anomalous_flag()) :
     return coeffs.average_bijvoet_mates()
   return coeffs