void remove_charmm_untyped_atoms(Hierarchy hierarchy)
{
  Atoms untyped = get_charmm_untyped_atoms(hierarchy);
  for (Atoms::iterator it = untyped.begin(); it != untyped.end(); ++it) {
    destroy(Hierarchy(it->get_particle()));
  }
}
Exemple #2
0
ModelObjectsTemp LeavesRefiner::do_get_inputs(
    kernel::Model *m, const kernel::ParticleIndexes &pis) const {
  kernel::ModelObjectsTemp ret;
  for (unsigned int i = 0; i < pis.size(); ++i) {
    ret += get_all_descendants(Hierarchy(m, pis[i], traits_));
  }
  return ret;
}
Exemple #3
0
IMPATOM_BEGIN_NAMESPACE

double get_resolution(Model* m, ParticleIndex pi) {
  double min = std::numeric_limits<double>::max();
  IMP_FOREACH(Hierarchy l, get_leaves(Hierarchy(m, pi))) {
    double cur = core::XYZR(l).get_radius();
    IMP_USAGE_CHECK(cur > 0, "Particle " << l << " has an invalid radius");
    min = std::min(min, cur);
  }
Exemple #4
0
Hierarchy get_residue(Hierarchy mhd, unsigned int index) {
  MatchResidueIndex mi(index);
  Hierarchy hd = core::find_breadth_first(mhd, mi);
  if (hd == IMP::core::Hierarchy()) {
    return Hierarchy();
  } else {
    return hd;
  }
}
Exemple #5
0
Chain get_chain(Hierarchy h) {
    do {
        if (h == Hierarchy()) {
            return Chain();
        }

        if (Chain::get_is_setup(h)) {
            return Chain(h);
        }
    } while ((h = h.get_parent()));
    return Chain();
}
ModelObjectsTemp SameResiduePairFilter::do_get_inputs(
    Model *m, const ParticleIndexes &pis) const {
  ModelObjectsTemp ret = IMP::get_particles(m, pis);
  for (unsigned int i = 0; i < pis.size(); ++i) {
    if (Atom::get_is_setup(m, pis[i])) {
      Particle *parent = Hierarchy(m, pis[i]).get_parent();
      if (parent) {
        ret.push_back(parent);
      }
    }
  }
  return ret;
}
void Hierarchy::show(std::ostream &out) const
{
  if (*this == Hierarchy()) {
    out << "nullptr Molecular Hierarchy node";
    return;
  }
  bool found=false;
  if (get_as_atom()) {
    found=true;
    out << get_as_atom();
  }
  if (get_as_residue()){
    found=true;
    out << get_as_residue();
  }
  if (get_as_chain()) {
    found=true;
    out << get_as_chain();
  } else if (get_as_molecule()) {
    found=true;
    out << get_as_molecule();
  }
  if (get_as_fragment()) {
    found=true;
    out << get_as_fragment();
  }
  if (get_as_domain()) {
    found=true;
    out << get_as_domain();
  }
  if (core::RigidBody::particle_is_instance(get_particle())) {
    found=true;
    out << core::RigidBody(get_particle());
  }
  if (core::RigidMember::particle_is_instance(get_particle())) {
      found=true;
      out << " rigid member: " << core::RigidMember(get_particle())
        .get_rigid_body()->get_name();
    }
  if (get_as_xyzr()) {
    found=true;
    out << " sphere: " << get_as_xyzr().get_sphere();
  } else if (get_as_xyz()) {
    found=true;
    out << " coordinates: " << get_as_xyz().get_coordinates();
  }
  if (!found) {
    out << "Hierarchy \"" <<  get_particle()->get_name()
        << "\"";
  }
}
Exemple #8
0
Residue get_residue(Atom d, bool nothrow) {
  Hierarchy mhd(d.get_particle());
  do {
    mhd= mhd.get_parent();
    if (mhd== Hierarchy()) {
      if (nothrow) return Residue();
      else {
        IMP_THROW("Atom is not the child of a residue "  << d,
                  ValueException);
      }
    }
  } while (!Residue::particle_is_instance(mhd.get_particle()));
  Residue rd(mhd.get_particle());
  return rd;
}
Exemple #9
0
//-----------------------------------------------------------------------------
// Exports mstudiolocalhierarchy_t.
//-----------------------------------------------------------------------------
void export_hierarchy(scope _studio)
{
    class_<mstudiolocalhierarchy_t, mstudiolocalhierarchy_t *, boost::noncopyable> Hierarchy("Hierarchy");

    // Properties...
    Hierarchy.def_readwrite("bone", &mstudiolocalhierarchy_t::iBone);
    Hierarchy.def_readwrite("new_parent", &mstudiolocalhierarchy_t::iNewParent);
    Hierarchy.def_readwrite("start", &mstudiolocalhierarchy_t::start);
    Hierarchy.def_readwrite("peak", &mstudiolocalhierarchy_t::peak);
    Hierarchy.def_readwrite("tail", &mstudiolocalhierarchy_t::tail);
    Hierarchy.def_readwrite("end", &mstudiolocalhierarchy_t::end);
    Hierarchy.def_readwrite("start", &mstudiolocalhierarchy_t::iStart);

    // Add memory tools...
    Hierarchy ADD_MEM_TOOLS(mstudiolocalhierarchy_t);
}
Exemple #10
0
core::RigidBody setup_as_rigid_body(Hierarchy h) {
  IMP_USAGE_CHECK(h.get_is_valid(true),
                  "Invalid hierarchy passed to setup_as_rigid_body");
  IMP_WARN("create_rigid_body should be used instead of setup_as_rigid_body"
           << " as the former allows one to get volumes correct at coarser"
           << " levels of detail.");
  core::RigidBody rbd = core::RigidBody::setup_particle(h, get_leaves(h));
  rbd.set_coordinates_are_optimized(true);
  kernel::ParticlesTemp internal = core::get_internal(h);
  for (unsigned int i = 0; i < internal.size(); ++i) {
    if (internal[i] != h) {
      core::RigidMembers leaves(get_leaves(Hierarchy(internal[i])));
      if (!leaves.empty()) {
        algebra::ReferenceFrame3D rf = core::get_initial_reference_frame(
            get_as<kernel::ParticlesTemp>(leaves));
        core::RigidBody::setup_particle(internal[i], rf);
      }
    }
  }
  IMP_INTERNAL_CHECK(h.get_is_valid(true), "Invalid hierarchy produced");
  return rbd;
}
Exemple #11
0
void Hierarchy::show(std::ostream &out, std::string delimiter) const {
  if (*this == Hierarchy()) {
    out << "nullptr Molecular Hierarchy node";
    return;
  }
  out << "\"" << get_particle()->get_name() << "\"" << delimiter;
  if (get_as_atom()) {
    out << get_as_atom() << delimiter;
  }
  if (get_as_residue()) {
    out << get_as_residue() << delimiter;
  }
  if (get_as_chain()) {
    out << get_as_chain() << delimiter;
  } else if (get_as_molecule()) {
    out << get_as_molecule() << delimiter;
  }
  if (get_as_fragment()) {
    out << get_as_fragment() << delimiter;
  }
  if (get_as_domain()) {
    out << get_as_domain() << delimiter;
  }
  if (core::RigidBody::get_is_setup(get_particle())) {
    out << core::RigidBody(get_particle());
  }
  if (core::RigidMember::get_is_setup(get_particle())) {
    out << " rigid member: "
        << core::RigidMember(get_particle()).get_rigid_body()->get_name();
  }
  if (get_as_xyzr()) {
    out << get_as_xyzr().get_sphere();
  } else if (get_as_xyz()) {
    out << get_as_xyz().get_coordinates();
  }
}
int SameResiduePairFilter::get_value_index(
    Model *m, const ParticleIndexPair &p) const {
  return Hierarchy(m, p[0]).get_parent() == Hierarchy(m, p[1]).get_parent();
}
ParticlesTemp SameResiduePairFilter::get_input_particles( Particle* t) const {
  ParticlesTemp ret;
  ret.push_back(t);
  ret.push_back(Hierarchy(t).get_parent());
  return ret;
}
int SameResiduePairFilter::get_value(const ParticlePair &pp)
 const {
     return Hierarchy(pp[0]).get_parent() ==
            Hierarchy(pp[1]).get_parent();
}
Exemple #15
0
const kernel::ParticlesTemp LeavesRefiner::get_refined(kernel::Particle *p)
    const {
  // force filling of the cache, yeah, its not good organization
  IMP_INTERNAL_CHECK(get_can_refine(p), "Trying to refine the unrefinable");
  return core::get_leaves(Hierarchy(p, traits_));
}
Exemple #16
0
Hierarchy
create_simplified_along_backbone(Chain in,
                                 const IntRanges& residue_segments,
                                 bool keep_detailed) {
  IMP_USAGE_CHECK(in.get_is_valid(true), "Chain " << in
                  << " is not valid.");
  if (in.get_number_of_children() ==0 || residue_segments.empty()) {
    IMP_LOG_TERSE( "Nothing to simplify in " << (in? in->get_name(): "nullptr")
            << " with " << residue_segments.size() << " segments.\n");
    return Hierarchy();
  }
  for (unsigned int i=0; i< residue_segments.size(); ++i) {
    IMP_USAGE_CHECK(residue_segments[i].first < residue_segments[i].second,
                    "Residue intervals must be non-empty");
  }
  IMP_IF_LOG(VERBOSE) {
    for (unsigned int i=0; i < residue_segments.size(); ++i) {
      IMP_LOG_VERBOSE( "[" << residue_segments[i].first
              << "..." << residue_segments[i].second << ") ");
    }
    IMP_LOG_VERBOSE( std::endl);
  }
  unsigned int cur_segment=0;
  Hierarchies cur;
  Hierarchy root=create_clone_one(in);
  for (unsigned int i=0; i< in.get_number_of_children(); ++i) {
    Hierarchy child=in.get_child(i);
    int index= Residue(child).get_index();
    IMP_LOG_VERBOSE( "Processing residue " << index
            << " with range " << residue_segments[cur_segment].first
            << " " << residue_segments[cur_segment].second << std::endl);
    if (index >= residue_segments[cur_segment].first
        && index < residue_segments[cur_segment].second) {
    } else if (!cur.empty()) {
      IMP_LOG_VERBOSE( "Added particle for "
              << residue_segments[cur_segment].first
              << "..." << residue_segments[cur_segment].second
              << std::endl);
      Hierarchy cur_approx=create_approximation_of_residues(cur);
      root.add_child(cur_approx);
      if (keep_detailed) {
        for (unsigned int j=0; j< cur.size(); ++j) {
          cur[j].get_parent().remove_child(cur[j]);
          cur_approx.add_child(cur[j]);
        }
      }
      cur.clear();
      ++cur_segment;
    }
    cur.push_back(child);
  }
  if (!cur.empty()) {
    root.add_child(create_approximation_of_residues(cur));
  }
  /*#ifdef IMP_ATOM_USE_IMP_CGAL
  double ov= get_volume(in);
  double cv= get_volume(root);
  double scale=1;
  ParticlesTemp rt= get_by_type(root, XYZR_TYPE);
  Floats radii(rt.size());
  for (unsigned int i=0; i< rt.size(); ++i) {
    core::XYZR d(rt[i]);
    radii[i]=d.get_radius();
  }
  do {
    show(root);
    double f= ov/cv*scale;
    scale*=.95;
    IMP_LOG_TERSE( "Bumping radius by " << f << std::endl);
    for (unsigned int i=0; i< rt.size(); ++i) {
      core::XYZR d(rt[i]);
      d.set_radius(radii[i]*f);
    }
    double nv=get_volume(root);
    IMP_LOG_TERSE( "Got volume " << nv << " " << ov << std::endl);
    if (nv < ov) {
      break;
    }
  } while (true);
#else
#endif*/
  IMP_INTERNAL_CHECK(root.get_is_valid(true),
                     "Invalid hierarchy produced " << root);
  return root;
}
bool Generalization::Init( Microdata* pMicrodata, const vector<string>& rVecHrchFile, const vector<long>& rVecQi, const long nSenAttr )
{
	AnonyException temp_exception;
	temp_exception.m_bShallContinue = true;
	stringstream temp_sstream;

	Clear();

	try
	{
		if (pMicrodata == NULL)
		{
			temp_sstream << "Generalization::Init Error: Pointer to the microdata cannot be NULL";
			temp_exception.SetMsg( temp_sstream.str() );
			throw( temp_exception );
		}

		m_pMicrodata = pMicrodata;

		m_vecStatus.insert( m_vecStatus.end(), m_pMicrodata->GetTupleNum(), anony::NORMAL );

		const vector<Metadata>& r_meta = pMicrodata->GetVecMeta();

		if (rVecHrchFile.size() != rVecQi.size() || rVecQi.size() == 0 || rVecQi.size() > r_meta.size())
		{
			temp_sstream << "Generalization::Init Error: Incorrect number of hierarchy files or QI attributes";
			temp_exception.SetMsg( temp_sstream.str() );
			throw( temp_exception );
		}

		if (nSenAttr < 0 || nSenAttr >= r_meta.size() || find( rVecQi.begin(), rVecQi.end(), nSenAttr ) != rVecQi.end() )
		{
			temp_sstream << "Generalization::Init Error: Incorrect sensitive attribute";
			temp_exception.SetMsg( temp_sstream.str() );
			throw( temp_exception );
		}
		m_nSenAttr = nSenAttr;
		

		long i, j, k;
		const long qi_num = rVecQi.size();

		//	Initialize m_vecQiAttr
		AttrWghtPair temp_pair;
		temp_pair.m_fWght = 1;
		m_vecQiAttr.reserve( qi_num );			
		for (i = 0; i < qi_num; ++i)
		{
			temp_pair.m_nAttr = rVecQi[i];
			m_vecQiAttr.push_back( temp_pair );
		}

		//	Check whether the QI attributes specified in rVecQI are correct
		sort( m_vecQiAttr.begin(), m_vecQiAttr.end(), CompareByAttr() );

		if ((m_vecQiAttr.back().m_nAttr < 0) || (m_vecQiAttr.back().m_nAttr >= m_pMicrodata->GetAttrNum()))
		{
			temp_sstream << "Generalization::Init Error: Incorrect QI attribute indices";
			temp_exception.SetMsg( temp_sstream.str() );
			throw( temp_exception );
		}

		for (i = 1; i < qi_num; ++i)
		{
			if (m_vecQiAttr[i].m_nAttr == m_vecQiAttr[i - 1].m_nAttr)
			{
				temp_sstream << "Generalization::Init Error: There exist duplicate QI attributes";
				temp_exception.SetMsg( temp_sstream.str() );
				throw( temp_exception );
			}
		}


		//	Initialize m_vecQiInd
		m_vecQiInd.insert( m_vecQiInd.begin(), m_pMicrodata->GetAttrNum(), -1 );
		for (i = 0; i < qi_num; ++i)
		{
			m_vecQiInd[m_vecQiAttr[i].m_nAttr] = m_vecQiAttr[i].m_nAttr;
		}

		m_vecHrch.insert( m_vecHrch.end(), r_meta.size(), Hierarchy() );
		for (i = 0; i < qi_num; ++i)
		{
			m_vecHrch[m_vecQiAttr[i].m_nAttr].Init( rVecHrchFile[i].c_str(), 100000, r_meta[m_vecQiAttr[i].m_nAttr].m_nType );
		}

		//	Initialize the "root" equivalence class
		InitRootClass();
	}
	catch( AnonyException e )
	{
		Clear();
		cout << e.GetMsg() << endl;
		throw( e );
	}

	return true;
}