def __init__(self, miller_array,
                    xray_structure = None,
                    miller_array_twin = None,
                    mask_params = None,
                    compute_mask = True):
   adopt_init_args(self, locals())
   if(self.mask_params is not None): self.mask_params = mask_params
   else: self.mask_params = mask_master_params.extract()
   self.grid_step = self._get_grid_step()
   self.atom_radii = None
   self._f_mask = None
   self._f_mask_twin = None
   self.solvent_content_via_mask = None
   self.layer_volume_fractions = None
   self.sites_cart = None
   if(xray_structure is not None):
     self.atom_radii = vdw_radii_from_xray_structure(xray_structure =
      self.xray_structure)
     self.xray_structure = self.xray_structure.deep_copy_scatterers()
     self.sites_cart = self.xray_structure.sites_cart()
     twin=False
     if(self.miller_array_twin is not None): twin=True
     if(compute_mask): self.compute_f_mask()
   if( not (self._f_mask is None) ):
     assert self._f_mask[0].data().size() == self.miller_array.indices().size()
Beispiel #2
0
 def __init__(
       self,
       xray_structure,
       p1,
       for_structure_factors,
       n_real,
       solvent_radius=None,
       shrink_truncation_radius=None,
       in_asu=False):
   if([solvent_radius, shrink_truncation_radius].count(None)>0):
     mask_params = mask_master_params.extract()
     if(solvent_radius is None): solvent_radius = mask_params.solvent_radius
     if(shrink_truncation_radius is None):
       shrink_truncation_radius = mask_params.shrink_truncation_radius
   xrs = xray_structure
   sgt = xrs.space_group().type() # must be BEFORE going to P1, obviously!
   if(p1): xrs = xrs.expand_to_p1(sites_mod_positive=True)
   atom_radii = vdw_radii_from_xray_structure(xray_structure = xrs)
   self.asu_mask = mmtbx.masks.atom_mask(
     unit_cell                = xrs.unit_cell(),
     space_group              = xrs.space_group(),
     gridding_n_real          = n_real,
     solvent_radius           = solvent_radius,
     shrink_truncation_radius = shrink_truncation_radius)
   self.asu_mask.compute(xrs.sites_frac(), atom_radii)
   self.mask_data = self.asu_mask.mask_data_whole_uc()
   if(for_structure_factors):
     self.mask_data = self.mask_data / xrs.space_group().order_z()
   if(in_asu):
     assert p1
     asu_map_ = asu_map_ext.asymmetric_map(sgt, self.mask_data)
     self.mask_data = asu_map_.data()
Beispiel #3
0
 def __init__(self,
              miller_array,
              xray_structure=None,
              miller_array_twin=None,
              mask_params=None,
              compute_mask=True):
     adopt_init_args(self, locals())
     if (self.mask_params is not None): self.mask_params = mask_params
     else: self.mask_params = mask_master_params.extract()
     self.grid_step = self._get_grid_step()
     self.atom_radii = None
     self._f_mask = None
     self._f_mask_twin = None
     self.solvent_content_via_mask = None
     self.layer_volume_fractions = None
     self.sites_cart = None
     if (xray_structure is not None):
         self.atom_radii = vdw_radii_from_xray_structure(
             xray_structure=self.xray_structure)
         self.xray_structure = self.xray_structure.deep_copy_scatterers()
         self.sites_cart = self.xray_structure.sites_cart()
         twin = False
         if (self.miller_array_twin is not None): twin = True
         if (compute_mask): self.compute_f_mask()
     if (not (self._f_mask is None)):
         assert self._f_mask[0].data().size() == self.miller_array.indices(
         ).size()
Beispiel #4
0
 def __init__(self,
              miller_array,
              xray_structure=None,
              miller_array_twin=None,
              mask_params=None,
              compute_mask=True):
     adopt_init_args(self, locals())
     if (self.mask_params is not None): self.mask_params = mask_params
     else: self.mask_params = mask_master_params.extract()
     Fmask_res_high = self.mask_params.Fmask_res_high
     self.sel_Fmask_res = miller_array.d_spacings().data() >= Fmask_res_high
     self.sel_Fmask_res_twin = None
     if (miller_array_twin is not None):
         self.sel_Fmask_res_twin = miller_array_twin.d_spacings().data(
         ) >= Fmask_res_high
     self.xray_structure = self._load_xrs(xray_structure)
     self.atom_radii = None
     self._f_mask = None
     self._f_mask_twin = None
     self.solvent_content_via_mask = None
     self.layer_volume_fractions = None
     self.sites_cart = None
     if (self.xray_structure is not None):
         self.atom_radii = vdw_radii_from_xray_structure(
             xray_structure=self.xray_structure)
         self.sites_cart = self.xray_structure.sites_cart()
         twin = False
         if (self.miller_array_twin is not None): twin = True
         if (compute_mask): self.compute_f_mask()
     if (not (self._f_mask is None)):
         assert self._f_mask[0].data().size() == self.miller_array.indices(
         ).size()
Beispiel #5
0
 def __init__(self,
              xray_structure,
              p1,
              for_structure_factors,
              n_real,
              solvent_radius=None,
              shrink_truncation_radius=None,
              in_asu=False):
     if ([solvent_radius, shrink_truncation_radius].count(None) > 0):
         mask_params = mask_master_params.extract()
         if (solvent_radius is None):
             solvent_radius = mask_params.solvent_radius
         if (shrink_truncation_radius is None):
             shrink_truncation_radius = mask_params.shrink_truncation_radius
     xrs = xray_structure
     sgt = xrs.space_group().type(
     )  # must be BEFORE going to P1, obviously!
     if (p1): xrs = xrs.expand_to_p1(sites_mod_positive=True)
     atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs)
     self.asu_mask = mmtbx.masks.atom_mask(
         unit_cell=xrs.unit_cell(),
         space_group=xrs.space_group(),
         gridding_n_real=n_real,
         solvent_radius=solvent_radius,
         shrink_truncation_radius=shrink_truncation_radius)
     self.asu_mask.compute(xrs.sites_frac(), atom_radii)
     self.mask_data = self.asu_mask.mask_data_whole_uc()
     if (for_structure_factors):
         self.mask_data = self.mask_data / xrs.space_group().order_z()
     if (in_asu):
         assert p1
         asu_map_ = asu_map_ext.asymmetric_map(sgt, self.mask_data)
         self.mask_data = asu_map_.data()
Beispiel #6
0
def mask(xray_structure, n_real, solvent_radius):
  xrs_p1 = xray_structure.expand_to_p1(sites_mod_positive=True)
  from cctbx.masks import vdw_radii_from_xray_structure
  radii = vdw_radii_from_xray_structure(xray_structure = xrs_p1)
  radii = radii + solvent_radius
  return ext.mask(
    sites_frac = xrs_p1.sites_frac(),
    unit_cell  = xrs_p1.unit_cell(),
    n_real     = n_real,
    radii      = radii)
Beispiel #7
0
 def __init__(self,
              xray_structure,
              d_min=None,
              n_real=None,
              mask_params=None,
              atom_radius=None):
     adopt_init_args(self, locals())
     assert [d_min, n_real].count(None) == 1
     if (self.mask_params is None):
         self.mask_params = mask_master_params.extract()
     if (atom_radius is None):
         self.atom_radii = vdw_radii_from_xray_structure(
             xray_structure=self.xray_structure)
     else:
         self.atom_radii = flex.double(
             self.xray_structure.scatterers().size(), atom_radius)
     if (d_min is not None):
         self.asu_mask = atom_mask(
             unit_cell=self.xray_structure.unit_cell(),
             group=self.xray_structure.space_group(),
             resolution=self.d_min,
             grid_step_factor=self.mask_params.grid_step_factor,
             solvent_radius=self.mask_params.solvent_radius,
             shrink_truncation_radius=self.mask_params.
             shrink_truncation_radius)
     else:
         self.asu_mask = atom_mask(
             unit_cell=self.xray_structure.unit_cell(),
             space_group=self.xray_structure.space_group(),
             gridding_n_real=self.n_real,
             solvent_radius=self.mask_params.solvent_radius,
             shrink_truncation_radius=self.mask_params.
             shrink_truncation_radius)
     selection = flex.bool(self.xray_structure.scatterers().size(), True)
     if (self.mask_params.ignore_zero_occupancy_atoms):
         selection &= self.xray_structure.scatterers().extract_occupancies(
         ) > 0
     if (self.mask_params.ignore_hydrogens):
         selection &= (~self.xray_structure.hd_selection())
     sites_frac = self.xray_structure.sites_frac()
     sites_frac = sites_frac.select(selection)
     atom_radii = self.atom_radii.select(selection)
     if (self.mask_params.n_radial_shells > 1):
         # number of shell radii is one less than number of shells
         # last shell is of unknown radius
         shell_rads = [self.mask_params.radial_shell_width] * \
           (self.mask_params.n_radial_shells-1)
         # TODO: Should first shell width be:
         shell_rads[0] -= self.mask_params.solvent_radius
         if (shell_rads[0] < 0.):
             shell_rads[0] = 0.
         self.asu_mask.compute(sites_frac, atom_radii, shell_rads)
     else:
         self.asu_mask.compute(sites_frac, atom_radii)
Beispiel #8
0
def exercise_mask_data_2(space_group_info,
                         n_sites=100,
                         d_min=2.0,
                         resolution_factor=1. / 4):
    from cctbx import maptbx
    from cctbx.masks import vdw_radii_from_xray_structure
    for yn2 in [0, 1]:
        for yn in [0, 1]:
            xrs = random_structure.xray_structure(
                space_group_info=space_group_info,
                elements=(("O", "N", "C") * (n_sites // 3 + 1))[:n_sites],
                volume_per_atom=50,
                min_distance=1.5)
            xrs.shake_sites_in_place(mean_distance=10)
            if (yn2): xrs = xrs.expand_to_p1(sites_mod_positive=True)
            atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs)
            asu_mask = masks.atom_mask(unit_cell=xrs.unit_cell(),
                                       group=xrs.space_group(),
                                       resolution=d_min,
                                       grid_step_factor=resolution_factor,
                                       solvent_radius=1.0,
                                       shrink_truncation_radius=1.0)
            asu_mask.compute(xrs.sites_frac(), atom_radii)
            mask_data = asu_mask.mask_data_whole_uc()
            #
            xrs_p1 = xrs.expand_to_p1(sites_mod_positive=True)
            for site_frac in xrs_p1.sites_frac():
                mv = mask_data.value_at_closest_grid_point(site_frac)
                assert mv == 0
            #
            mask_data = mask_data / xrs.space_group().order_z()
            if (yn == 1):
                mask_data = maptbx.copy(mask_data,
                                        flex.grid(mask_data.focus()))
            #
            for site_frac in xrs_p1.sites_frac():
                mv = mask_data.value_at_closest_grid_point(site_frac)
                assert mv == 0
            #
            fc = xrs.structure_factors(d_min=d_min).f_calc()
            f_mask_1 = fc.set().array(
                data=asu_mask.structure_factors(fc.indices()))
            f_mask_2 = f_mask_1.structure_factors_from_map(
                map=mask_data,
                use_scale=True,
                anomalous_flag=False,
                use_sg=True)
            fm1 = abs(f_mask_1).data()
            fm2 = abs(f_mask_2).data()
            r = flex.sum(flex.abs(fm1 - fm2)) / flex.sum(fm1 + fm2)
            assert approx_equal(r, 0.0)
Beispiel #9
0
def exercise_mask_data_1(space_group_info, n_sites=100):
    from cctbx import maptbx
    from cctbx.masks import vdw_radii_from_xray_structure
    for d_min in [1, 1.5, 2.1]:
        for resolution_factor in [1. / 2, 1. / 3, 1. / 4, 1. / 5]:
            xrs = random_structure.xray_structure(
                space_group_info=space_group_info,
                elements=(("O", "N", "C") * (n_sites // 3 + 1))[:n_sites],
                volume_per_atom=30,
                min_distance=1)
            atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs)
            asu_mask = masks.atom_mask(unit_cell=xrs.unit_cell(),
                                       group=xrs.space_group(),
                                       resolution=d_min,
                                       grid_step_factor=resolution_factor,
                                       solvent_radius=1.0,
                                       shrink_truncation_radius=1.0)
            asu_mask.compute(xrs.sites_frac(), atom_radii)
            mask_data = asu_mask.mask_data_whole_uc()
            assert flex.min(mask_data) == 0.0
            # It's not just 0 and 1 ...
            assert flex.max(mask_data) == xrs.space_group().order_z()
            # In fact, it is a mixture ...
            if 0:  # XXX this will rightfully crash
                mask_data_ = mask_data / xrs.space_group().order_z()
                s0 = mask_data_ < 0.5
                s1 = mask_data_ > 0.5
                if (mask_data_.size() != s0.count(True) + s1.count(True)):
                    for d in mask_data_:
                        if (d != 0 and d != 1):
                            print(d, xrs.space_group().order_z())
                    assert mask_data_.size(
                    ) == s0.count(True) + s1.count(True), [
                        mask_data_.size() - (s0.count(True) + s1.count(True))
                    ]
            if (
                    0
            ):  # XXX This would crash with the message: "... The grid is not ..."
                cr_gr = maptbx.crystal_gridding(
                    unit_cell=xrs.unit_cell(),
                    d_min=d_min,
                    resolution_factor=resolution_factor)
                asu_mask = masks.atom_mask(unit_cell=xrs.unit_cell(),
                                           space_group=xrs.space_group(),
                                           gridding_n_real=cr_gr.n_real(),
                                           solvent_radius=1.0,
                                           shrink_truncation_radius=1.0)
                asu_mask.compute(xrs.sites_frac(), atom_radii)
Beispiel #10
0
 def __init__(self, xray_structure, d_min=None, n_real=None, mask_params = None,
              atom_radius = None):
   adopt_init_args(self, locals())
   assert [d_min, n_real].count(None) == 1
   if(self.mask_params is None):
     self.mask_params = mask_master_params.extract()
   if(atom_radius is None):
     self.atom_radii = vdw_radii_from_xray_structure(xray_structure =
       self.xray_structure)
   else:
     self.atom_radii = flex.double(self.xray_structure.scatterers().size(),
       atom_radius)
   if(d_min is not None):
     self.asu_mask = atom_mask(
       unit_cell                = self.xray_structure.unit_cell(),
       group                    = self.xray_structure.space_group(),
       resolution               = self.d_min,
       grid_step_factor         = self.mask_params.grid_step_factor,
       solvent_radius           = self.mask_params.solvent_radius,
       shrink_truncation_radius = self.mask_params.shrink_truncation_radius)
   else:
     self.asu_mask = atom_mask(
       unit_cell                = self.xray_structure.unit_cell(),
       space_group              = self.xray_structure.space_group(),
       gridding_n_real          = self.n_real,
       solvent_radius           = self.mask_params.solvent_radius,
       shrink_truncation_radius = self.mask_params.shrink_truncation_radius)
   selection = flex.bool(self.xray_structure.scatterers().size(), True)
   if(self.mask_params.ignore_zero_occupancy_atoms):
     selection &= self.xray_structure.scatterers().extract_occupancies() > 0
   if(self.mask_params.ignore_hydrogens):
     selection &= (~self.xray_structure.hd_selection())
   sites_frac = self.xray_structure.sites_frac()
   sites_frac = sites_frac.select(selection)
   atom_radii = self.atom_radii.select(selection)
   if(self.mask_params.n_radial_shells > 1):
     # number of shell radii is one less than number of shells
     # last shell is of unknown radius
     shell_rads = [self.mask_params.radial_shell_width] * \
       (self.mask_params.n_radial_shells-1)
     # TODO: Should first shell width be:
     shell_rads[0] -= self.mask_params.solvent_radius
     if( shell_rads[0]<0. ):
       shell_rads[0] = 0.
     self.asu_mask.compute(sites_frac, atom_radii, shell_rads)
   else:
     self.asu_mask.compute(sites_frac, atom_radii)
Beispiel #11
0
def exercise_mask_data_2(space_group_info, n_sites=100, d_min=2.0,
                         resolution_factor=1./4):
  from cctbx import maptbx
  from cctbx.masks import vdw_radii_from_xray_structure
  for yn2 in [0,1]:
    for yn in [0,1]:
      xrs = random_structure.xray_structure(
        space_group_info=space_group_info,
        elements=(("O","N","C")*(n_sites//3+1))[:n_sites],
        volume_per_atom=50,
        min_distance=1.5)
      xrs.shake_sites_in_place(mean_distance=10)
      if(yn2): xrs = xrs.expand_to_p1(sites_mod_positive=True)
      atom_radii = vdw_radii_from_xray_structure(xray_structure = xrs)
      asu_mask = masks.atom_mask(
        unit_cell                = xrs.unit_cell(),
        group                    = xrs.space_group(),
        resolution               = d_min,
        grid_step_factor         = resolution_factor,
        solvent_radius           = 1.0,
        shrink_truncation_radius = 1.0)
      asu_mask.compute(xrs.sites_frac(), atom_radii)
      mask_data = asu_mask.mask_data_whole_uc()
      #
      xrs_p1 = xrs.expand_to_p1(sites_mod_positive=True)
      for site_frac in xrs_p1.sites_frac():
        mv = mask_data.value_at_closest_grid_point(site_frac)
        assert mv == 0
      #
      mask_data = mask_data / xrs.space_group().order_z()
      if(yn == 1):
        mask_data = maptbx.copy(mask_data, flex.grid(mask_data.focus()))
      #
      for site_frac in xrs_p1.sites_frac():
        mv = mask_data.value_at_closest_grid_point(site_frac)
        assert mv == 0
      #
      fc = xrs.structure_factors(d_min = d_min).f_calc()
      f_mask_1 = fc.set().array(data = asu_mask.structure_factors(fc.indices()))
      f_mask_2 = f_mask_1.structure_factors_from_map(map=mask_data,
        use_scale = True, anomalous_flag = False, use_sg = True)
      fm1 = abs(f_mask_1).data()
      fm2 = abs(f_mask_2).data()
      r = flex.sum( flex.abs( fm1 - fm2 ) ) / flex.sum( fm1 + fm2 )
      assert approx_equal(r, 0.0)
Beispiel #12
0
def exercise_mask_data_1(space_group_info, n_sites=100):
  from cctbx import maptbx
  from cctbx.masks import vdw_radii_from_xray_structure
  for d_min in [1, 1.5, 2.1]:
    for resolution_factor in [1./2, 1./3, 1./4, 1./5]:
      xrs = random_structure.xray_structure(
        space_group_info=space_group_info,
        elements=(("O","N","C")*(n_sites//3+1))[:n_sites],
        volume_per_atom=30,
        min_distance=1)
      atom_radii = vdw_radii_from_xray_structure(xray_structure = xrs)
      asu_mask = masks.atom_mask(
        unit_cell                = xrs.unit_cell(),
        group                    = xrs.space_group(),
        resolution               = d_min,
        grid_step_factor         = resolution_factor,
        solvent_radius           = 1.0,
        shrink_truncation_radius = 1.0)
      asu_mask.compute(xrs.sites_frac(), atom_radii)
      mask_data = asu_mask.mask_data_whole_uc()
      assert flex.min(mask_data) == 0.0
      # It's not just 0 and 1 ...
      assert flex.max(mask_data) == xrs.space_group().order_z()
      # In fact, it is a mixture ...
      if 0: # XXX this will rightfully crash
        mask_data_ = mask_data / xrs.space_group().order_z()
        s0 = mask_data_ < 0.5
        s1 = mask_data_ > 0.5
        if(mask_data_.size() != s0.count(True)+s1.count(True)):
          for d in mask_data_:
            if(d != 0 and d != 1): print d, xrs.space_group().order_z()
          assert mask_data_.size() == s0.count(True)+s1.count(True), [
            mask_data_.size()-(s0.count(True)+s1.count(True))]
      if(0): # XXX This would crash with the message: "... The grid is not ..."
        cr_gr = maptbx.crystal_gridding(
          unit_cell         = xrs.unit_cell(),
          d_min             = d_min,
          resolution_factor = resolution_factor)
        asu_mask = masks.atom_mask(
          unit_cell                = xrs.unit_cell(),
          space_group              = xrs.space_group(),
          gridding_n_real          = cr_gr.n_real(),
          solvent_radius           = 1.0,
          shrink_truncation_radius = 1.0)
        asu_mask.compute(xrs.sites_frac(), atom_radii)
Beispiel #13
0
def mask(xray_structure,
         n_real,
         mask_value_inside_molecule=0,
         mask_value_outside_molecule=1,
         solvent_radius=0,
         atom_radius=None):
    xrs_p1 = xray_structure.expand_to_p1(sites_mod_positive=True)
    if (atom_radius is None):
        from cctbx.masks import vdw_radii_from_xray_structure
        atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs_p1)
    else:
        atom_radii = flex.double(xrs_p1.scatterers().size(), atom_radius)
    return ext.mask(sites_frac=xrs_p1.sites_frac(),
                    unit_cell=xrs_p1.unit_cell(),
                    n_real=n_real,
                    mask_value_inside_molecule=mask_value_inside_molecule,
                    mask_value_outside_molecule=mask_value_outside_molecule,
                    radii=atom_radii + solvent_radius)
 def __init__(
       self,
       xray_structure,
       p1,
       solvent_radius,
       shrink_truncation_radius,
       for_structure_factors,
       n_real):
   xrs = xray_structure
   if(p1): xrs = xrs.expand_to_p1(sites_mod_positive=True)
   atom_radii = vdw_radii_from_xray_structure(xray_structure = xrs)
   self.asu_mask = mmtbx.masks.atom_mask(
     unit_cell                = xrs.unit_cell(),
     space_group              = xrs.space_group(),
     gridding_n_real          = n_real,
     solvent_radius           = solvent_radius,
     shrink_truncation_radius = shrink_truncation_radius)
   self.asu_mask.compute(xrs.sites_frac(), atom_radii)
   self.mask_data = self.asu_mask.mask_data_whole_uc()
   if(for_structure_factors):
     self.mask_data = self.mask_data / xrs.space_group().order_z()
Beispiel #15
0
 def __init__(self,
              xray_structure,
              ignore_zero_occupancy_atoms,
              solvent_radius,
              shrink_truncation_radius,
              ignore_hydrogen_atoms=True,
              gridding_n_real=None,
              grid_step=None,
              atom_radii=None):
     global number_of_mask_calculations
     number_of_mask_calculations += 1
     assert [gridding_n_real, grid_step].count(None) == 1
     self.xray_structure = xray_structure
     if (gridding_n_real is None):
         gridding_n_real = maptbx.crystal_gridding(
             unit_cell=xray_structure.unit_cell(), step=grid_step).n_real()
     if (atom_radii is None):
         atom_radii = vdw_radii_from_xray_structure(
             xray_structure=self.xray_structure)
     sites_frac = xray_structure.sites_frac()
     self.n_atoms_excluded = 0
     selection = flex.bool(xray_structure.scatterers().size(), True)
     if (ignore_zero_occupancy_atoms):
         selection &= xray_structure.scatterers().extract_occupancies() > 0
     if (ignore_hydrogen_atoms):
         selection &= (~xray_structure.hd_selection())
     sites_frac = sites_frac.select(selection)
     atom_radii = atom_radii.select(selection)
     self.n_atoms_excluded = selection.count(False)
     around_atoms.__init__(
         self,
         unit_cell=xray_structure.unit_cell(),
         space_group_order_z=xray_structure.space_group().order_z(),
         sites_frac=sites_frac,
         atom_radii=atom_radii,
         gridding_n_real=gridding_n_real,
         solvent_radius=solvent_radius,
         shrink_truncation_radius=shrink_truncation_radius)
     introspection.virtual_memory_info().update_max()
 def __init__(self,
       xray_structure,
       ignore_zero_occupancy_atoms,
       solvent_radius,
       shrink_truncation_radius,
       ignore_hydrogen_atoms=True,
       gridding_n_real=None,
       grid_step=None,
       atom_radii=None):
    global number_of_mask_calculations
    number_of_mask_calculations += 1
    assert [gridding_n_real, grid_step].count(None) == 1
    self.xray_structure = xray_structure
    if (gridding_n_real is None):
      gridding_n_real = maptbx.crystal_gridding(
        unit_cell=xray_structure.unit_cell(),
        step=grid_step).n_real()
    if(atom_radii is None):
      atom_radii = vdw_radii_from_xray_structure(xray_structure =
        self.xray_structure)
    sites_frac = xray_structure.sites_frac()
    self.n_atoms_excluded = 0
    selection = flex.bool(xray_structure.scatterers().size(), True)
    if(ignore_zero_occupancy_atoms):
      selection &= xray_structure.scatterers().extract_occupancies() > 0
    if(ignore_hydrogen_atoms):
      selection &= (~xray_structure.hd_selection())
    sites_frac = sites_frac.select(selection)
    atom_radii = atom_radii.select(selection)
    self.n_atoms_excluded = selection.count(False)
    around_atoms.__init__(self,
      unit_cell           = xray_structure.unit_cell(),
      space_group_order_z = xray_structure.space_group().order_z(),
      sites_frac          = sites_frac,
      atom_radii          = atom_radii,
      gridding_n_real     = gridding_n_real,
      solvent_radius      = solvent_radius,
      shrink_truncation_radius = shrink_truncation_radius)
    introspection.virtual_memory_info().update_max()
Beispiel #17
0
def get_f_mask(xrs, ma, step, option=2, r_shrink=None, r_sol=None):
    #
    result = ma.deep_copy()
    sel = ma.d_spacings().data() >= 3
    ma = ma.select(sel)
    #
    crystal_gridding = maptbx.crystal_gridding(
        unit_cell=xrs.unit_cell(),
        space_group_info=xrs.space_group_info(),
        symmetry_flags=maptbx.use_space_group_symmetry,
        step=step)
    n_real = crystal_gridding.n_real()
    atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs)
    mask_params = masks.mask_master_params.extract()
    grid_step_factor = ma.d_min() / step
    if (r_shrink is not None): mask_params.shrink_truncation_radius = r_shrink
    if (r_sol is not None): mask_params.solvent_radius = r_sol
    mask_params.grid_step_factor = grid_step_factor
    # 1
    if (option == 1):
        asu_mask = ext.atom_mask(
            unit_cell=xrs.unit_cell(),
            group=xrs.space_group(),
            resolution=ma.d_min(),
            grid_step_factor=grid_step_factor,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius)
        asu_mask.compute(xrs.sites_frac(), atom_radii)
        fm_asu = asu_mask.structure_factors(ma.indices())
        f_mask = ma.set().array(data=fm_asu)
    # 2
    elif (option == 2):
        asu_mask = ext.atom_mask(
            unit_cell=xrs.unit_cell(),
            space_group=xrs.space_group(),
            gridding_n_real=n_real,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius)
        asu_mask.compute(xrs.sites_frac(), atom_radii)
        fm_asu = asu_mask.structure_factors(ma.indices())
        f_mask = ma.set().array(data=fm_asu)
    # 3
    elif (option == 3):
        mask_p1 = mmtbx.masks.mask_from_xray_structure(
            xray_structure=xrs,
            p1=True,
            for_structure_factors=True,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius,
            n_real=n_real,
            in_asu=False).mask_data
        maptbx.unpad_in_place(map=mask_p1)
        mask = asu_map_ext.asymmetric_map(
            xrs.crystal_symmetry().space_group().type(), mask_p1).data()
        f_mask = ma.structure_factors_from_asu_map(asu_map_data=mask,
                                                   n_real=n_real)
    # 4
    elif (option == 4):
        f_mask = masks.bulk_solvent(
            xray_structure=xrs,
            ignore_zero_occupancy_atoms=False,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius,
            ignore_hydrogen_atoms=False,
            grid_step=step,
            atom_radii=atom_radii).structure_factors(miller_set=ma)
    elif (option == 5):
        o = mmtbx.masks.bulk_solvent(
            xray_structure=xrs,
            ignore_zero_occupancy_atoms=False,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius,
            ignore_hydrogen_atoms=False,
            gridding_n_real=n_real,
            atom_radii=atom_radii)
        assert approx_equal(n_real, o.data.accessor().all())
        f_mask = o.structure_factors(ma)
    elif (option == 6):
        # XXX No control over n_real, so results with others don't match
        mask_manager = masks.manager(miller_array=ma,
                                     miller_array_twin=None,
                                     mask_params=mask_params)
        f_mask = mask_manager.shell_f_masks(xray_structure=xrs,
                                            force_update=True)[0]
    else:
        assert 0
    #
    data = flex.complex_double(result.indices().size(), 0)
    data = data.set_selected(sel, f_mask.data())
    result = result.array(data=data)
    return result
Beispiel #18
0
 def __init__(self,
              xray_structure,
              mask_params=None,
              d_min=None,
              atom_radius=None):
     """
 If d_min is not None then it defines the gridding. Otherwise mask_params is
 used for that.
 """
     adopt_init_args(self, locals())
     if (mask_params is None):
         mask_params = mmtbx.masks.mask_master_params.extract()
         self.mask_params = mask_params
     if (d_min is not None):
         assert mask_params.grid_step_factor is not None
     assert [mask_params.step, mask_params.n_real].count(None) in [1, 2]
     assert mask_params.step is not None or mask_params.n_real is not None or \
            [d_min, mask_params.grid_step_factor].count(None)==0
     if (atom_radius is None):
         self.atom_radii = vdw_radii_from_xray_structure(
             xray_structure=self.xray_structure)
     else:
         self.atom_radii = flex.double(
             self.xray_structure.scatterers().size(), atom_radius)
     if (mask_params.step is not None):
         crystal_gridding = maptbx.crystal_gridding(
             unit_cell=self.xray_structure.unit_cell(),
             space_group_info=self.xray_structure.space_group_info(),
             symmetry_flags=maptbx.use_space_group_symmetry,
             step=mask_params.step)
         self.n_real = crystal_gridding.n_real()
     else:
         self.n_real = mask_params.n_real
     if (d_min is not None):
         self.asu_mask = atom_mask(
             unit_cell=self.xray_structure.unit_cell(),
             group=self.xray_structure.space_group(),
             resolution=self.d_min,
             grid_step_factor=self.mask_params.grid_step_factor,
             solvent_radius=self.mask_params.solvent_radius,
             shrink_truncation_radius=self.mask_params.
             shrink_truncation_radius)
     else:
         self.asu_mask = atom_mask(
             unit_cell=self.xray_structure.unit_cell(),
             space_group=self.xray_structure.space_group(),
             gridding_n_real=self.n_real,
             solvent_radius=self.mask_params.solvent_radius,
             shrink_truncation_radius=self.mask_params.
             shrink_truncation_radius)
     sites_frac = self.xray_structure.sites_frac()
     if (self.mask_params.n_radial_shells > 1):
         # number of shell radii is one less than number of shells
         # last shell is of unknown radius
         shell_rads = [self.mask_params.radial_shell_width] * \
           (self.mask_params.n_radial_shells-1)
         # TODO: Should first shell width be:
         shell_rads[0] -= self.mask_params.solvent_radius
         if (shell_rads[0] < 0.):
             shell_rads[0] = 0.
         self.asu_mask.compute(sites_frac, self.atom_radii, shell_rads)
     else:
         self.asu_mask.compute(sites_frac, self.atom_radii)
Beispiel #19
0
def get_f_mask(xrs, ma, step, option=2):
    crystal_gridding = maptbx.crystal_gridding(
        unit_cell=xrs.unit_cell(),
        space_group_info=xrs.space_group_info(),
        symmetry_flags=maptbx.use_space_group_symmetry,
        step=step)
    n_real = crystal_gridding.n_real()
    atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs)
    mask_params = masks.mask_master_params.extract()
    grid_step_factor = ma.d_min() / step
    # 1
    if (option == 1):
        asu_mask = ext.atom_mask(
            unit_cell=xrs.unit_cell(),
            group=xrs.space_group(),
            resolution=ma.d_min(),
            grid_step_factor=grid_step_factor,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius)
        asu_mask.compute(xrs.sites_frac(), atom_radii)
        fm_asu = asu_mask.structure_factors(ma.indices())
        f_mask = ma.set().array(data=fm_asu)
    # 2
    elif (option == 2):
        asu_mask = ext.atom_mask(
            unit_cell=xrs.unit_cell(),
            space_group=xrs.space_group(),
            gridding_n_real=n_real,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius)
        asu_mask.compute(xrs.sites_frac(), atom_radii)
        fm_asu = asu_mask.structure_factors(ma.indices())
        f_mask = ma.set().array(data=fm_asu)
    # 3
    elif (option == 3):
        mask_params.grid_step_factor = grid_step_factor
        mask_manager = masks.manager(miller_array=ma,
                                     miller_array_twin=None,
                                     mask_params=mask_params)
        f_mask = mask_manager.shell_f_masks(xray_structure=xrs,
                                            force_update=True)[0]
    # 4
    elif (option == 4):
        mask_p1 = mmtbx.masks.mask_from_xray_structure(
            xray_structure=xrs,
            p1=True,
            for_structure_factors=True,
            n_real=n_real,
            in_asu=False).mask_data
        maptbx.unpad_in_place(map=mask_p1)
        mask = asu_map_ext.asymmetric_map(
            xrs.crystal_symmetry().space_group().type(), mask_p1).data()
        f_mask = ma.structure_factors_from_asu_map(asu_map_data=mask,
                                                   n_real=n_real)
    elif (option == 5):
        o = mmtbx.masks.bulk_solvent(
            xray_structure=xrs,
            ignore_zero_occupancy_atoms=False,
            solvent_radius=mask_params.solvent_radius,
            shrink_truncation_radius=mask_params.shrink_truncation_radius,
            ignore_hydrogen_atoms=False,
            gridding_n_real=n_real,
            atom_radii=atom_radii)
        f_mask = o.structure_factors(ma)
    else:
        assert 0
    #
    return f_mask