void Fragment::set_residue_indexes(kernel::Model *m, kernel::ParticleIndex pi, Ints o) { if (o.empty()) { set_residue_indexes(m, pi, IntPairs()); return; } std::sort(o.begin(), o.end()); o.erase(std::unique(o.begin(), o.end()), o.end()); IntPairs pairs; int begin = 0; for (unsigned int i = 1; i < o.size(); ++i) { if (o[i] != o[i - 1] + 1) { pairs.push_back(IntPair(o[begin], o[i - 1] + 1)); begin = i; } } pairs.push_back(IntPair(o[begin], o.back() + 1)); set_residue_indexes(m, pi, pairs); using IMP::operator<<; IMP_IF_CHECK(USAGE) { for (unsigned int i = 0; i < o.size(); ++i) { IMP_INTERNAL_CHECK(Fragment(m, pi).get_contains_residue(o[i]), "Residue index not found after addition: " << o << " became " << pairs); } } }
Hierarchy create_protein(Model *m, std::string name, double resolution, const Ints db) { Hierarchy root = Hierarchy::setup_particle(new Particle(m)); Domain::setup_particle(root, IntRange(db.front(), db.back())); for (unsigned int i = 1; i < db.size(); ++i) { std::ostringstream oss; oss << name << "-" << i - 1; Hierarchy cur = create_protein( m, oss.str(), resolution, db[i] - db[i - 1], db[i - 1], atom::get_volume_from_mass( atom::get_mass_from_number_of_residues(db[i] - db[i - 1])), false); root.add_child(cur); } Molecule::setup_particle(root); root->set_name(name); return root; }