Пример #1
0
bool Skeleton_basic::operator() ( clipper::Xmap<int>& xskl, const clipper::Xmap<float>& xmap ) const
{
  std::vector<int> index;
  clipper::Xmap<float>::Map_reference_index ix;
  
  /* now get the map in sorted order.
     We only sort those points which are to be considered, i.e. non-zero */
  for ( ix = xmap.first(); !ix.last(); ix.next() )
    if ( xskl[ix] > 0 )
      index.push_back( ix.index() );
  Map_index_sort::sort_increasing( xmap, index );

  /* make neighbours
     The neighbours of a point are the other grid points which are
     'near' it.  The exact choice depends on the grid geometry. The
     cutoff is chosen to give 18-20 neighbours. For a cubic grid,
     these are a 3x3x3 cube without the vertices, for a hex grid they
     are a hexagonal cylinder. */
  Skeleton_basic::Neighbours neigh( xmap );

  /* make the skeleton map. This will contain:
      0 for non-skeleton grids (inter ridge spaces)
      1 for untested grids
      1 for skeleton grids (ridges)
     (The untested and skeleton grids can have the same value,
     because the untested ones are still in the index).
     We loop through point in order, starting with the lowest
     and decide whether each one is part of the skeleton. */
  for ( int i = 0; i < index.size(); i++ )
    if ( !isInSkel( xskl, xskl.coord_of(index[i]), neigh, box_ ) )
      xskl.set_data( index[ i ], 0 );

  return true;
}
Пример #2
0
void SSfind::prep_xmap( const clipper::Xmap<float>& xmap, const double radius )
{
  // make a 1-d array of gridded density values covering ASU+border
  grid = xmap.grid_sampling();
  grrot = xmap.operator_orth_grid().rot();
  clipper::Grid_range gr0 = xmap.grid_asu();
  clipper::Grid_range gr1( xmap.cell(), xmap.grid_sampling(), radius );
  mxgr = clipper::Grid_range( gr0.min()+gr1.min(), gr0.max()+gr1.max() );
  mapbox = std::vector<float>( mxgr.size(), 0.0 );

  // make 1d list of densities
  clipper::Xmap<float>::Map_reference_index ix( xmap );
  for ( int i = 0; i < mapbox.size(); i++ ) {
    ix.set_coord( mxgr.deindex( i ) );
    mapbox[i] = xmap[ix];
  }
}
Пример #3
0
void SSfind::prep_search( const clipper::Xmap<float>& xmap )
{
  // make list of results
  typedef clipper::Xmap<float>::Map_reference_index MRI;
  srctrn.clear();
  for ( MRI ix = xmap.first(); !ix.last(); ix.next() )
    srctrn.push_back( grid.index( ix.coord() ) );
}
Пример #4
0
template<class T1, class T2> bool Skeleton_fast<T1,T2>::isInSkel( const clipper::Xmap<T1>& xskl, const clipper::Coord_grid& c ) const
{
  int dx, dy, dz;

  /* Fill the cube with flags Each non-rejected grid point is given
     its own number. We will the reduce these to 'region numbers', so
     that each connected region takes the value of one of its
     neighbours. (A performace benefit is gaine from allocating these
     in decreasing order). */
  clipper::Xmap_base::Map_reference_index ix( xskl, c );
  for ( dz = 0; dz < 3; dz++ )
    for ( dy = 0; dy < 3; dy++ )
      for ( dx = 0; dx < 3; dx++ )
	cube[dx][dy][dz] = xskl.get_data( ix.index_offset( dx-1, dy-1, dz-1 ) );
  // the centre cannot be  a link - set to zero
  cube[1][1][1] = 0;

  /* The following is a simple optimisation which could be omitted.
     We count the number of neightbours or the centre point which are
     not yet eliminated from the skeleton. If this is more than 14 or
     less than 1, then this pint cannot be part of the skeleton. */
  int nneigh = 0;
  for ( int i = 0; i < neigh.size(); i++ ) {
    dx = neigh[i].u()+1;
    dy = neigh[i].v()+1;
    dz = neigh[i].w()+1;
    if ( cube[dx][dy][dz] > 0 ) nneigh++;
  }
  if ( nneigh > 14 ) return false;
  if ( nneigh < 1 ) return false;

  /* Now alter flags for one connected region. If all flags are
     altered, then this point is not part of the skeleton. */
  for ( int i = 0; i < neigh.size(); i++ ) {
    dx = neigh[i].u()+1;
    dy = neigh[i].v()+1;
    dz = neigh[i].w()+1;
    if ( cube[dx][dy][dz] > 0 ) break;
  }
  flood_cube( dx, dy, dz );
  bool res2 = false;
  for ( int i = 0; i < neigh.size(); i++ ) {
    dx = neigh[i].u()+1;
    dy = neigh[i].v()+1;
    dz = neigh[i].w()+1;
    if ( cube[dx][dy][dz] > 0 ) return true;
  }
  return false;
}
Пример #5
0
/* \return The negative of the correlation */
clipper::ftype LLK_map_target::Sampled::correl( const clipper::Xmap<float>& xmap, const clipper::RTop_orth& rtop ) const {
  clipper::ftype x, y, w, sw, swx, swy, swxx, swyy, swxy;
  sw = swx = swy = swxx = swyy = swxy = 0.0;
  for ( int i = 0; i < repxyz.size(); i++ ) {
    w = repwgt[i];
    x = reptgt[i];
    y = xmap.interp<clipper::Interp_linear>( (rtop*repxyz[i]).coord_frac(xmap.cell()) );
    sw   += w;
    swx  += w * x;
    swy  += w * y;
    swxx += w * x * x;
    swyy += w * y * y;
    swxy += w * x * y;
  }
  return -( sw*swxy - swx*swy ) / sqrt( clipper::Util::max(
      ( sw*swxx - swx*swx ) * ( sw*swyy - swy*swy ), 1.0e-20 ) );
}
Пример #6
0
void SSfind::prep_search( const clipper::Xmap<float>& xmap, const double rhocut, const double radcut, const clipper::Coord_orth centre )
{
  // make list of results
  typedef clipper::Xmap<float>::Map_reference_index MRI;
  srctrn.clear();
  double r2cut = ( radcut > 0.0 ) ? radcut*radcut : 1.0e20;
  clipper::Coord_frac cf = centre.coord_frac( xmap.cell() );
  for ( MRI ix = xmap.first(); !ix.last(); ix.next() )
    if ( xmap[ix] > rhocut ) {
      clipper::Coord_frac df = ix.coord().coord_frac( xmap.grid_sampling() );
      df = df.symmetry_copy_near( xmap.spacegroup(), xmap.cell(), cf ) - cf;
      double r2 = df.lengthsq( xmap.cell() );
      if ( r2 < r2cut )
	srctrn.push_back( grid.index( ix.coord() ) );
    }
}
Пример #7
0
/*! Accumulate the statistics for a log-likelihood target using a known
  map and operator maping into that map. After accumulation is
  completed, you must call prep_llk().
  \param xmap The known map from which to accumulate density statistics.
  \param rtop The operator from the target map at the origin into the xmap. */
void LLK_map_target::accumulate( const clipper::Xmap<float>& xmap, const clipper::RTop_orth rtop )
{
  // aliases for maps
  clipper::NXmap<float>& mrho = target;
  clipper::NXmap<float>& mrho2 = weight;

  // zero maps if necessary
  if ( naccum == 0.0 ) target = weight = float(0.0);
  naccum++;

  // accumulate stats
  clipper::ftype extentsq =
    pow( mrho.operator_grid_orth().rot()(0,0) * (mrho.grid().nu()-1)/2, 2 );
  clipper::NXmap_base::Map_reference_index ix;
  float rho;
  for ( ix = mrho.first(); !ix.last(); ix.next() )
    if ( ix.coord_orth().lengthsq() <= extentsq ) {
      rho = xmap.interp<clipper::Interp_cubic>( (rtop*ix.coord_orth()).coord_frac(xmap.cell()) );
      mrho[ix]  += rho;
      mrho2[ix] += rho*rho;
    }
}
Пример #8
0
/*! A log-likelihood FFFear search is performed for the target in the given map.
  \param resultscr The best scores.
  \param resultrot The best rotations.
  \param resulttrn The best translations.
  \param xmap The map to search.
  \param rtops The oprientations to search. */
void LLK_map_target::search( clipper::Xmap<float>& resultscr, clipper::Xmap<int>& resultrot, clipper::Xmap<int>& resulttrn, const clipper::Xmap<float>& xmap, const std::vector<clipper::RTop_orth>& rtops ) const
{
  // set up results
  const clipper::Spacegroup&    spgr = xmap.spacegroup();
  const clipper::Cell&          cell = xmap.cell();
  const clipper::Grid_sampling& grid = xmap.grid_sampling();
  resultscr.init( spgr, cell, grid );
  resultrot.init( spgr, cell, grid );
  resulttrn.init( spgr, cell, grid );
  resultscr = 1.0e20;

  // now search for ML target in each orientation in turn
  clipper::Xmap<float> resultp1( clipper::Spacegroup::p1(), cell, grid );
  clipper::Xmap<float>::Map_reference_index i1(resultp1);
  clipper::Xmap<float>::Map_reference_coord ix(resultscr);

  // set up z scoring
  clipper::FFFear_fft<float> srch( xmap );
  clipper::NX_operator nxop( xmap, target, rtops[0] );
  srch( resultp1, target, weight, nxop );
  clipper::Map_stats zstats( resultp1 );

  // loop over orientations
  for ( int op = 0; op < rtops.size(); op++ ) {
    // do the fffear search
    clipper::NX_operator nxop( xmap, target, rtops[op].inverse() );
    srch( resultp1, target, weight, nxop );

    // store best scores
    for ( i1 = resultp1.first(); !i1.last(); i1.next() ) {
      ix.set_coord( i1.coord() );
      float score = ( resultp1[i1] - zstats.mean() ) / zstats.std_dev();
      if ( score < resultscr[ix] ) {
	resultscr[ix] = score;
	resultrot[ix] = op;
	resulttrn[ix] = grid.index( i1.coord() );
      }
    }
  }
}
Пример #9
0
/* \return The log likelihood */
clipper::ftype LLK_map_target::Sampled::llk( const clipper::Xmap<float>& xmap, const clipper::RTop_orth& rtop ) const {
  clipper::ftype r( 0.0 ), s( 0.0 );
  for ( int i = 0; i < repxyz.size(); i++ ) {
    r += repwgt[i] * pow( xmap.interp<clipper::Interp_linear>( (rtop*repxyz[i]).coord_frac(xmap.cell()) ) - reptgt[i], 2 );
    s += repwgt[i];
  }
  return r/s;
}
Пример #10
0
/*! Search from scratch.

  Combined search, scoring and sorting of fragments. This version is
  for general use.

  \param frag The fragment to search for.
  \param nfrag The maximum  number of fragments to return
  \param xmap The electron density map for scoring models.
  \param coords The coordinates of the model for use in clash scoring.
  \param wdense (optional) weight for the density score
  \param wclash (optional) weight for the clash score
  \param sig1 (optional) the sigma offset for density scores
  \param sig2 (optional) the sigma weight for density scores
  \param clashrad (optional) the radius for clash penalties
  \return A vector of chains, with the first chain representing the best score.
*/
  std::vector<Chain> ProteinDBSearch::search( const Chain& frag, const int nfrag, const clipper::Xmap<float>& xmap, const std::vector<clipper::Coord_orth>& coords, double wdense, double wclash, double sig1, double sig2, double clashrad )
{
  ScoreDensity score_rho( xmap, sig1, sig2 );
  ScoreClashes score_cls( coords, xmap.spacegroup(), xmap.cell(), clashrad );
  return search( frag, nfrag, score_rho, score_cls, wdense, wclash );
}