Hierarchy get_previous_residue(Residue rd) { // only handle simple case so far Hierarchy p = rd.get_parent(); Chain c = p.get_as_chain(); Hierarchy r = get_residue(c, rd.get_index() - 1); return r; }
Hierarchy get_next_residue(Residue rd) { // only handle simple case so far Hierarchy p = rd.get_parent(); /*if (!p.get_as_chain()) { IMP_NOT_IMPLEMENTED("get_next_residue() only handles the simple case" << " so far. Complain about it."); }*/ IMP_USAGE_CHECK(Chain::get_is_setup(p), "Parent of residue must be a chain. It is not."); Hierarchy r = get_residue(Chain(p), rd.get_index() + 1); return r; }
void write_pdb(const ParticlesTemp& ps, TextOutput out) { IMP_FUNCTION_LOG; int last_index = 0; bool use_input_index = true; for (unsigned int i = 0; i < ps.size(); ++i) { if (Atom(ps[i]).get_input_index() != last_index + 1) { use_input_index = false; break; } else { ++last_index; } } for (unsigned int i = 0; i < ps.size(); ++i) { if (Atom::get_is_setup(ps[i])) { Atom ad(ps[i]); Residue rd = get_residue(ad); // really dumb and slow, fix later char chain; Chain c = get_chain(rd); if (c) { chain = c.get_id()[0]; } else { chain = ' '; } int inum = i+1; if (i>=99999) inum=99999; out.get_stream() << get_pdb_string( core::XYZ(ps[i]).get_coordinates(), use_input_index ? ad.get_input_index() : static_cast<int>(inum), ad.get_atom_type(), rd.get_residue_type(), chain, rd.get_index(), rd.get_insertion_code(), ad.get_occupancy(), ad.get_temperature_factor(), ad.get_element()); if (!out) { IMP_THROW("Error writing to file in write_pdb", IOException); } } else if (Residue::get_is_setup(ps[i])) { // if C-alpha residue is available Residue rd = IMP::atom::Residue(ps[i]); // comment 1 by SJ - TODO: How to retrieve the correct chain information without an hierarchy? char chain; Chain c = get_chain(rd); if (c) { chain = c.get_id()[0]; } else { chain = ' '; } // comment 2 by SJ - TODO: The C-alpha residues are not sorted yet. We need to sort the residues similarly to what PMI does. out.get_stream() << get_pdb_string( core::XYZ(ps[i]).get_coordinates(), static_cast<int>(i + 1), IMP::atom::AT_CA, rd.get_residue_type(), chain, rd.get_index(), ' ', 1.0, IMP::core::XYZR(ps[i]).get_radius()); } else { // if a coarse-grained BEAD is available Ints resindexes = IMP::atom::Fragment(ps[i]).get_residue_indexes(); int resindex = (int)resindexes.front() + (int)(resindexes.size()/2); // comment 1 by SJ - TODO: How to retrieve the correct chain information without an hierarchy? char chain = ' '; // comment 3 by SJ - TODO: The BEADs are not sorted yet. We need to sort the residues similarly to what PMI does. // comment 4 by SJ - TODO: currently IMP does not allow "BEA" as a residue name, while PMI allows it. Thus "UNK" was used instead. out.get_stream() << get_pdb_string( core::XYZ(ps[i]).get_coordinates(), static_cast<int>(i + 1), IMP::atom::AT_CA, IMP::atom::UNK, chain, (int)resindex, ' ', 1.0, IMP::core::XYZR(ps[i]).get_radius()); } } }