Ejemplo n.º 1
0
 def box_iterator(self):
   b = maptbx.boxes(
     n_real   = self.atom_map_asu.focus(),
     fraction = self.box_size_as_fraction,
     max_boxes= self.max_boxes,
     log      = self.log)
   def get_wide_box(s,e): # define wide box: neutral + phased volumes
     if(self.neutral_volume_box_cushion_width>0):
       sh = self.neutral_volume_box_cushion_width
       ss = [max(s[i]-sh,0) for i in [0,1,2]]
       ee = [min(e[i]+sh,n_real_asu[i]) for i in [0,1,2]]
     else: ss,ee = s,e
     return ss,ee
   n_real_asu = b.n_real
   n_boxes = len(b.starts)
   i_box = 0
   for s,e in zip(b.starts, b.ends):
     i_box+=1
     sw,ew = get_wide_box(s=s,e=e)
     fmodel_omit = self.omit_box(start=sw, end=ew)
     r = fmodel_omit.r_work()
     self.r.append(r) # for tests only
     if(self.log):
       print >> self.log, "r(curr,min,max,mean)=%6.4f %6.4f %6.4f %6.4f"%(r,
         flex.min(self.r), flex.max(self.r), flex.mean(self.r)), i_box, n_boxes
     omit_map_data = self.asu_map_from_fmodel(
       fmodel=fmodel_omit, map_type=self.map_type)
     maptbx.copy_box(
       map_data_from = omit_map_data,
       map_data_to   = self.map_result_asu,
       start         = s,
       end           = e)
   self.map_result_asu.reshape(self.acc_asu)
Ejemplo n.º 2
0
    def __init__(self,
                 crystal_gridding,
                 fmodel,
                 map_type,
                 max_boxes,
                 box_size_as_fraction=None):
        sgt = fmodel.f_obs().space_group().type()
        assert sgt.number() == 1

        def get_map(fmodel, map_type, external_complete_set=None):
            f_map = fmodel.electron_density_map().map_coefficients(
                map_type=map_type, isotropize=True, fill_missing=False)
            fft_map = miller.fft_map(crystal_gridding=crystal_gridding,
                                     fourier_coefficients=f_map)
            return fft_map.real_map_unpadded()

        f_model = fmodel.f_model_scaled_with_k1()
        fft_map = miller.fft_map(crystal_gridding=crystal_gridding,
                                 fourier_coefficients=f_model)
        f_model_map_data = fft_map.real_map_unpadded()
        zero_complex_ma = f_model.customized_copy(
            data=flex.complex_double(f_model.data().size(), 0))
        b = maptbx.boxes(fraction=0.3,
                         n_real=f_model_map_data.focus(),
                         max_boxes=max_boxes,
                         log=sys.stdout)
        self.map_result = flex.double(flex.grid(b.n_real))
        self.r = flex.double()
        for s, e in zip(b.starts, b.ends):
            f_model_map_data_omit = maptbx.set_box_copy(
                value=0, map_data_to=f_model_map_data, start=s, end=e)
            f_model_omit = f_model.structure_factors_from_map(
                map=f_model_map_data_omit,
                use_scale=True,
                anomalous_flag=False,
                use_sg=False)
            fmodel_ = mmtbx.f_model.manager(f_obs=fmodel.f_obs(),
                                            r_free_flags=fmodel.r_free_flags(),
                                            f_calc=f_model_omit,
                                            f_mask=zero_complex_ma)
            self.r.append(fmodel_.r_work())
            f_map_data = get_map(fmodel=fmodel_, map_type=map_type)
            etmp = [e[0] - 1, e[1] - 1,
                    e[2] - 1]  # because .copy() includes right edge
            box = maptbx.copy(f_map_data, s, etmp)
            box.reshape(flex.grid(box.all()))
            maptbx.set_box(map_data_from=box,
                           map_data_to=self.map_result,
                           start=s,
                           end=e)
        sd = self.map_result.sample_standard_deviation()
        self.map_result = self.map_result / sd
        self.map_coefficients = fmodel.f_obs().structure_factors_from_map(
            map=self.map_result,
            use_scale=True,
            anomalous_flag=False,
            use_sg=False)
Ejemplo n.º 3
0
def exercise_set_box():
  n_real = (60, 100, 160)
  n = n_real[0]*n_real[1]*n_real[2]
  cs=crystal.symmetry(
    unit_cell=(21,37,58,80,111,117),
    space_group_symbol="P1")
  be = maptbx.boxes(n_real = n_real, fraction=0.1)
  #
  m1 = flex.double([-1 for i in xrange(n)])
  m1.resize(flex.grid(n_real))
  m2 = flex.double([1 for i in xrange(n)])
  m2.resize(flex.grid(n_real))
  #
  for s,e in zip(be.starts, be.ends):
    box = maptbx.copy(m2, s, e)
    box.reshape(flex.grid(box.all()))
    maptbx.set_box(
      map_data_from = box,
      map_data_to   = m1,
      start         = s,
      end           = e)
  assert m2.as_1d().min_max_mean().as_tuple() == (1.,1.,1.)
Ejemplo n.º 4
0
    def __init__(self,
                 crystal_gridding,
                 fmodel,
                 map_type,
                 box_size_as_fraction=0.03,
                 max_boxes=100,
                 n_debias_cycles=2,
                 neutral_volume_box_cushion_width=1,
                 full_resolution_map=True,
                 log=sys.stdout):
        self.crystal_gridding = crystal_gridding
        # assert compatibility of symops with griding
        assert self.crystal_gridding._symmetry_flags is not None
        self.sgt = fmodel.f_obs().space_group().type()
        self.zero_cmpl_ma = fmodel.f_calc().customized_copy(
            data=flex.complex_double(fmodel.f_calc().size(), 0))

        # embedded utility functions
        def get_map(fmodel, map_type, crystal_gridding, asu=True):
            f_map = fmodel.electron_density_map().map_coefficients(
                map_type=map_type,
                isotropize=True,
                exclude_free_r_reflections=True,
                fill_missing=False)
            fft_map = cctbx.miller.fft_map(crystal_gridding=crystal_gridding,
                                           fourier_coefficients=f_map)
            if (asu):
                return asu_map_ext.asymmetric_map(
                    self.sgt, fft_map.real_map_unpadded()).data()
            else:
                return fft_map.real_map_unpadded()

        # f_model map
        f_model_map_data = fmodel.f_model_scaled_with_k1().fft_map(
            symmetry_flags=maptbx.use_space_group_symmetry,
            crystal_gridding=self.crystal_gridding).real_map_unpadded()
        self.n_real = f_model_map_data.focus()
        # extract asu map from full P1
        f_model_map_data_asu = asu_map_ext.asymmetric_map(
            self.sgt, f_model_map_data).data()
        self.acc = f_model_map_data_asu.accessor()
        f_model_map_data_asu = f_model_map_data_asu.shift_origin()
        # set up boxes
        b = maptbx.boxes(n_real=f_model_map_data_asu.focus(),
                         fraction=box_size_as_fraction,
                         max_boxes=max_boxes,
                         log=log)
        self.map_result_asu = flex.double(flex.grid(b.n_real))
        assert f_model_map_data_asu.focus() == b.n_real
        assert b.n_real == self.map_result_asu.focus()
        n_real_asu = b.n_real
        self.r = flex.double()  # for regression test only
        n_boxes = len(b.starts)
        i_box = 0
        for s, e in zip(b.starts, b.ends):
            i_box += 1
            # define wide box: neutral + phased volumes
            if (neutral_volume_box_cushion_width > 0):
                sh = neutral_volume_box_cushion_width
                ss = [max(s[i] - sh, 0) for i in [0, 1, 2]]
                ee = [min(e[i] + sh, n_real_asu[i]) for i in [0, 1, 2]]
            else:
                ss, ee = s, e
            # omit wide box from f_model map, repeat n_debias_cycles times
            f_model_map_data_asu_ = f_model_map_data_asu.deep_copy()
            for i in range(n_debias_cycles):
                f_model_omit, f_model_map_data_asu_ = self.omit_box(
                    s=ss, e=ee, md_asu=f_model_map_data_asu_)
            # get fmodel for omit map calculation
            fmodel_ = mmtbx.f_model.manager(f_obs=fmodel.f_obs(),
                                            r_free_flags=fmodel.r_free_flags(),
                                            f_calc=f_model_omit,
                                            f_mask=self.zero_cmpl_ma)
            rw = fmodel_.r_work()
            self.r.append(rw)  # for regression test only
            f_map_data_asu = get_map(fmodel=fmodel_,
                                     map_type=map_type,
                                     crystal_gridding=self.crystal_gridding)
            f_map_data_asu = f_map_data_asu.shift_origin()
            if (log):
                print("box %2d of %2d:" % (i_box, n_boxes),
                      s,
                      e,
                      "%6.4f" % rw,
                      file=log)
            assert f_map_data_asu.focus() == self.map_result_asu.focus()
            maptbx.copy_box(map_data_from=f_map_data_asu,
                            map_data_to=self.map_result_asu,
                            start=s,
                            end=e)
        # result
        self.map_result_asu.reshape(self.acc)
        self.asu_map_omit = asu_map_ext.asymmetric_map(self.sgt,
                                                       self.map_result_asu,
                                                       self.n_real)
        self.map_coefficients = self.zero_cmpl_ma.customized_copy(
            indices=self.zero_cmpl_ma.indices(),
            data=self.asu_map_omit.structure_factors(
                self.zero_cmpl_ma.indices()))
        # full resolution map (reflections in sphere, not in box!)
        if (full_resolution_map):
            cs = self.zero_cmpl_ma.complete_set(
                d_min=self.zero_cmpl_ma.d_min())
            asu_map_omit = asu_map_ext.asymmetric_map(self.sgt,
                                                      self.map_result_asu,
                                                      self.n_real)
            fill = self.zero_cmpl_ma.customized_copy(
                indices=cs.indices(),
                data=asu_map_omit.structure_factors(cs.indices()))
            self.map_coefficients = self.map_coefficients.complete_with(
                other=fill, scale=True)
Ejemplo n.º 5
0
def exercise_boxing():
  n_real = (60, 100, 160)
  cs=crystal.symmetry(
    unit_cell=(21,37,58,80,111,117),
    space_group_symbol="P1")
  maptbx.boxes(n_real = n_real, fraction=0.1)
 def __init__(
       self,
       crystal_gridding,
       fmodel,
       map_type,
       box_size_as_fraction=0.03,
       max_boxes=100,
       n_debias_cycles=2,
       neutral_volume_box_cushion_width=1,
       full_resolution_map=True,
       log=sys.stdout):
   self.crystal_gridding = crystal_gridding
   # assert compatibility of symops with griding
   assert self.crystal_gridding._symmetry_flags is not None
   self.sgt = fmodel.f_obs().space_group().type()
   self.zero_cmpl_ma = fmodel.f_calc().customized_copy(
     data = flex.complex_double(fmodel.f_calc().size(), 0))
   # embedded utility functions
   def get_map(fmodel, map_type, crystal_gridding, asu=True):
     f_map = fmodel.electron_density_map().map_coefficients(
       map_type                   = map_type,
       isotropize                 = True,
       exclude_free_r_reflections = True,
       fill_missing               = False)
     fft_map = cctbx.miller.fft_map(
       crystal_gridding     = crystal_gridding,
       fourier_coefficients = f_map)
     if(asu): return asu_map_ext.asymmetric_map(self.sgt,
       fft_map.real_map_unpadded()).data()
     else:
       return fft_map.real_map_unpadded()
   # f_model map
   f_model_map_data = fmodel.f_model_scaled_with_k1().fft_map(
     symmetry_flags   = maptbx.use_space_group_symmetry,
     crystal_gridding = self.crystal_gridding).real_map_unpadded()
   self.n_real = f_model_map_data.focus()
   # extract asu map from full P1
   f_model_map_data_asu=asu_map_ext.asymmetric_map(
     self.sgt, f_model_map_data).data()
   self.acc = f_model_map_data_asu.accessor()
   f_model_map_data_asu = f_model_map_data_asu.shift_origin()
   # set up boxes
   b = maptbx.boxes(
     n_real   = f_model_map_data_asu.focus(),
     fraction = box_size_as_fraction,
     max_boxes= max_boxes,
     log      = log)
   self.map_result_asu = flex.double(flex.grid(b.n_real))
   assert f_model_map_data_asu.focus()==b.n_real
   assert b.n_real==self.map_result_asu.focus()
   n_real_asu = b.n_real
   self.r = flex.double() # for regression test only
   n_boxes = len(b.starts)
   i_box = 0
   for s,e in zip(b.starts, b.ends):
     i_box+=1
     # define wide box: neutral + phased volumes
     if(neutral_volume_box_cushion_width>0):
       sh = neutral_volume_box_cushion_width
       ss = [max(s[i]-sh,0) for i in [0,1,2]]
       ee = [min(e[i]+sh,n_real_asu[i]) for i in [0,1,2]]
     else: ss,ee = s,e
     # omit wide box from f_model map, repeat n_debias_cycles times
     f_model_map_data_asu_ = f_model_map_data_asu.deep_copy()
     for i in xrange(n_debias_cycles):
       f_model_omit, f_model_map_data_asu_ = self.omit_box(s=ss, e=ee,
         md_asu=f_model_map_data_asu_)
     # get fmodel for omit map calculation
     fmodel_ = mmtbx.f_model.manager(
       f_obs        = fmodel.f_obs(),
       r_free_flags = fmodel.r_free_flags(),
       f_calc       = f_model_omit,
       f_mask       = self.zero_cmpl_ma)
     rw = fmodel_.r_work()
     self.r.append(rw) # for regression test only
     f_map_data_asu = get_map(fmodel=fmodel_, map_type=map_type,
       crystal_gridding=self.crystal_gridding)
     f_map_data_asu = f_map_data_asu.shift_origin()
     if(log):
       print >> log, "box %2d of %2d:"%(i_box, n_boxes), s, e, "%6.4f"%rw
     assert f_map_data_asu.focus() == self.map_result_asu.focus()
     maptbx.copy_box(
       map_data_from = f_map_data_asu,
       map_data_to   = self.map_result_asu,
       start         = s,
       end           = e)
   # result
   self.map_result_asu.reshape(self.acc)
   self.asu_map_omit = asu_map_ext.asymmetric_map(
     self.sgt, self.map_result_asu, self.n_real)
   self.map_coefficients = self.zero_cmpl_ma.customized_copy(
     indices = self.zero_cmpl_ma.indices(),
     data    = self.asu_map_omit.structure_factors(self.zero_cmpl_ma.indices()))
   # full resolution map (reflections in sphere, not in box!)
   if(full_resolution_map):
     cs = self.zero_cmpl_ma.complete_set(d_min=self.zero_cmpl_ma.d_min())
     asu_map_omit = asu_map_ext.asymmetric_map(
       self.sgt,self.map_result_asu,self.n_real)
     fill = self.zero_cmpl_ma.customized_copy(
       indices = cs.indices(),
       data    = asu_map_omit.structure_factors(cs.indices()))
     self.map_coefficients = self.map_coefficients.complete_with(
       other=fill, scale=True)
 def __init__(
       self,
       crystal_gridding,
       fmodel,
       map_type,
       max_boxes,
       box_size_as_fraction=None):
   sgt = fmodel.f_obs().space_group().type()
   assert sgt.number() == 1
   def get_map(fmodel, map_type, external_complete_set=None):
     f_map = fmodel.electron_density_map().map_coefficients(
         map_type     = map_type,
         isotropize   = True,
         fill_missing = False)
     fft_map = miller.fft_map(
       crystal_gridding     = crystal_gridding,
       fourier_coefficients = f_map)
     return fft_map.real_map_unpadded()
   f_model = fmodel.f_model_scaled_with_k1()
   fft_map = miller.fft_map(
     crystal_gridding     = crystal_gridding,
     fourier_coefficients = f_model)
   f_model_map_data = fft_map.real_map_unpadded()
   zero_complex_ma = f_model.customized_copy(
     data = flex.complex_double(f_model.data().size(), 0))
   b = maptbx.boxes(
     fraction = 0.3,
     n_real   = f_model_map_data.focus(),
     max_boxes=max_boxes,
     log=sys.stdout)
   self.map_result = flex.double(flex.grid(b.n_real))
   self.r = flex.double()
   for s,e in zip(b.starts, b.ends):
     f_model_map_data_omit = maptbx.set_box_copy(
       value         = 0,
       map_data_to   = f_model_map_data,
       start         = s,
       end           = e)
     f_model_omit = f_model.structure_factors_from_map(
       map            = f_model_map_data_omit,
       use_scale      = True,
       anomalous_flag = False,
       use_sg         = False)
     fmodel_ = mmtbx.f_model.manager(
       f_obs        = fmodel.f_obs(),
       r_free_flags = fmodel.r_free_flags(),
       f_calc       = f_model_omit,
       f_mask       = zero_complex_ma)
     self.r.append(fmodel_.r_work())
     f_map_data = get_map(fmodel=fmodel_, map_type=map_type)
     etmp = [e[0]-1, e[1]-1, e[2]-1] # because .copy() includes right edge
     box = maptbx.copy(f_map_data, s, etmp)
     box.reshape(flex.grid(box.all()))
     maptbx.set_box(
       map_data_from = box,
       map_data_to   = self.map_result,
       start         = s,
       end           = e)
   sd = self.map_result.sample_standard_deviation()
   self.map_result = self.map_result/sd
   self.map_coefficients = fmodel.f_obs().structure_factors_from_map(
     map            = self.map_result,
     use_scale      = True,
     anomalous_flag = False,
     use_sg         = False)