29 #include <utility/graph/RingDetection.hh>
31 #include <basic/Tracer.hh>
33 #include <utility/vector1.hh>
34 #include <utility/string_util.hh>
35 #include <utility/graph/BFS_prune.hh>
37 #include <ObjexxFCL/FArray2D.hh>
38 #include <ObjexxFCL/string.functions.hh>
45 static THREAD_LOCAL basic::Tracer
TR(
"core.chemical.residue_support" );
47 ObjexxFCL::FArray2D_int
51 using namespace graph;
54 g.set_num_nodes( res.
natoms() );
55 for (
uint ii = 1; ii <= res.
natoms(); ++ii ) {
57 for (
Size jj = 1; jj <= ii_bonded.size(); ++jj ) {
58 if ( ii_bonded[ jj ] > ii ) {
59 g.add_edge( ii, ii_bonded[ jj ] );
63 return g.all_pairs_shortest_paths();
73 boost::property_map<LightWeightResidueGraph, boost::vertex_name_t>::type lwrg_vd_to_VD = boost::get(boost::vertex_name, lwrg);
74 boost::property_map<LightWeightResidueGraph, boost::edge_name_t>::type lwrg_ed_to_ED = boost::get(boost::edge_name, lwrg);
77 std::map<core::chemical::VD, lwrg_VD> map_of_vertex;
80 VD const & full_residue_graph_vd = *vp.first;
82 lwrg_vd_to_VD[lwrg_vd] = full_residue_graph_vd;
83 map_of_vertex[full_residue_graph_vd] = lwrg_vd;
87 for (
EIterPair ep = boost::edges(full_residue_graph); ep.first != ep.second; ++ep.first ) {
88 VD source = boost::source(*ep.first, full_residue_graph);
89 VD target = boost::target(*ep.first, full_residue_graph);
90 lwrg_VD source_lwrg_VD = map_of_vertex[source];
91 lwrg_VD target_lwrg_VD = map_of_vertex[target];
94 boost::tie(e_added, added) = boost::add_edge(source_lwrg_VD, target_lwrg_VD,lwrg );
96 lwrg_ed_to_ED[e_added] = *ep.first;
99 debug_assert(boost::num_vertices(lwrg) == full_residue_graph.num_vertices());
100 debug_assert(boost::num_edges(lwrg) == full_residue_graph.num_edges());
106 utility::graph::RingDetection<LightWeightResidueGraph> ring_detect(lwrg);
107 utility::vector1<utility::vector1<lwrg_VD> > rings = ring_detect.GetRings();
119 std::map< std::string, core::Size > name_counts;
121 VIter iter, iter_end;
122 for ( boost::tie( iter, iter_end ) = boost::vertices( graph ); iter != iter_end; ++iter ) {
123 Atom const & atom( graph[*iter] );
124 if ( preserve && atom.
name().size() != 0 ) {
125 name_counts[ atom.
name() ]++;
129 for ( boost::tie( iter, iter_end ) = boost::vertices( graph ); iter != iter_end; ++iter ) {
130 Atom const & atom( graph[*iter] );
131 if ( !preserve || name_counts[ atom.
name() ] != 1 ) {
142 if ( name.size() == 2 ) {
143 name =
' ' + name +
' ';
144 }
else if ( name.size() == 3 ) {
147 }
while ( name_counts.find( name ) != name_counts.end() );
149 if (
TR.Trace.visible() ) {
150 TR.Trace <<
"Renaming atom from '"<< res.
atom(*iter).
name() <<
"' to '" << name <<
"'" << std::endl;
154 name_counts[ name ]++;
164 typedef utility::vector1< utility::vector1< core::Real > >
Matrix;
176 template <
class ED,
class Res
idueGraphType>
178 VD source( boost::source( edge, graph ) ), target( boost::target( edge, graph ) );
206 template <
class VD,
class Res
idueGraphType>
226 if ( nheavy >= 2 )
return false;
228 if ( nhydro != 1 )
return true;
246 VIter iter, iter_end;
247 for ( boost::tie( iter, iter_end ) = res.
atom_iterators(); iter != iter_end; ++iter ) {
250 utility::graph::breadth_first_search_prune( res.
graph(), *iter, vis );
258 core::Real new_dist( distances[ii][kk] + distances[kk][jj] );
259 if ( new_dist < distances[ii][jj] ) {
260 distances[ii][jj] = new_dist;
266 if (
TR.Trace.visible() ) {
268 TR.Trace << std::setprecision(4);
269 TR.Trace <<
"Atom distance matrix for " << res.
name() << std::endl;
270 TR.Trace <<
" " <<
'\t';
274 TR.Trace << std::endl;
278 TR.Trace << distances[yy][xx] <<
'\t';
280 TR.Trace << std::endl;
301 if ( res.
natoms() == 0 ) {
302 utility_exit_with_message(
"Cannot find neighbor atom distance for empty residue type.");
305 utility::vector1< utility::vector1< core::Real > > distances(res.
natoms(), utility::vector1< core::Real >( res.
natoms(), maxdist ) );
312 utility::vector1< core::Real > maxdists;
314 maxdists.push_back( *(std::max_element( distances[ii].begin(), distances[ii].
end() )) );
319 return maxdists[ res.
atom_index( nbr_atom ) ];
325 if ( maxdists[jj] < maxdist &&
335 if ( bonded_heavy >= 2 ) {
336 maxdist = maxdists[jj];
343 TR.Warning <<
"No suitable neighbor atom found for " << res.
name() <<
" -- picking first atom (" << res.
atom_name(1) <<
") instead." << std::endl;
345 maxdist = maxdists[1];
366 if ( ! ats.has_extra_parameter(
"CHARGE" ) ) {
367 TR.Warning <<
"Atom Type Set " << ats.name() <<
" is missing charging information - skipping recharging." << std::endl;
370 int charge_extra_param_index( ats.extra_parameter_index(
"CHARGE") );
373 VIter iter, iter_end;
374 for ( boost::tie( iter, iter_end ) = boost::vertices( graph ); iter != iter_end; ++iter ) {
378 if ( atm.atom_type_index() != 0 ) {
379 charge = ats[ atm.atom_type_index() ].extra_parameter( charge_extra_param_index );
381 atm.charge( charge );
382 TR.Debug <<
"Residue " << res.
name() <<
": Charging atom " << atm.name() <<
" type " << ats[ atm.atom_type_index() ].name() <<
" at " << atm.charge() << std::endl;
383 current_net += charge;
389 if ( current_net < (desired_net - 0.001) || current_net > (desired_net + 0.001) ) {
390 core::Real correction( (desired_net-current_net)/natoms );
391 for ( boost::tie( iter, iter_end ) = boost::vertices( graph ); iter != iter_end; ++iter ) {
393 if ( atm.charge() != 0 ) {
394 atm.
charge( atm.charge() + correction );
395 TR.Debug <<
"Residue " << res.
name() <<
": Adjusting charge on atom " << atm.name() <<
" type " << ats[ atm.atom_type_index() ].name() <<
" to " << atm.charge() << std::endl;
std::string const & atom_name(Size const index) const
get atom name by index
LightWeightResidueGraph convert_residuetype_to_light_graph(ResidueType const &res)
ResidueType const & restype_
std::pair< EIter, EIter > EIterPair
utility::vector1< Size > AtomIndices
bool examine_edge(ED edge, ResidueGraphType &graph)
Vector const & ideal_xyz() const
static VD const null_vertex
Atom & atom(Size const atom_index)
AtomTypeSet const & atom_type_set() const
access by reference the atomset for which this residue is constructed
AtomIndices const & nbrs(Size const atomno) const
indices of the bonded neighbors for an atom, shortcut for bonded_neighbor(atomno) ...
ResidueGraph::vertex_descriptor VD
std::string const & name() const
std::pair< VIter, VIter > VIterPair
boost::graph_traits< ResidueGraph >::adjacency_iterator AdjacentIter
generic graph class header
Real const & charge() const
bool examine_vertex(VD vertex, ResidueGraphType &)
void calculate_rigid_matrix(ResidueType const &res, utility::vector1< utility::vector1< core::Real > > &distances)
Calculate the rigid matrix - assume that distances has been initialized to some really large value...
ResidueGraph const & graph() const
Constant access to the underlying graph.
boost::graph_traits< ResidueGraph >::vertex_iterator VIter
RigidDistanceVisitor(Matrix &distances, ResidueType const &restype, VD start)
int const & formal_charge() const
Method declarations and simple accessors/getters for ResidueType.
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, boost::property< boost::vertex_name_t, core::chemical::VD >, boost::property< boost::edge_name_t, core::chemical::ED > > LightWeightResidueGraph
void remap_pdb_atom_names(bool rename)
Turn on geometry-based atom renaming when loading this residue type from PDB files.
void rosetta_recharge_fullatom(ResidueType &res)
Apply molfile_to_params style partial charges to the ResidueType.
bool add_vertex(core::Size const v, EdgeList &edges)
add a vertex, splitting edges if necessary
ObjexxFCL::FArray2D_int get_residue_path_distances(ResidueType const &res)
relies on class Graph to find all pairs shortest path information
boost::undirected_graph< Atom, Bond > ResidueGraph
ElementCOP element_type() const
Size atom_index(std::string const &name) const
get atom index by name
VD atom_vertex(std::string const &name) const
get the vertex descriptor from the name of the atom.
Method definitions for chemical::Atom.
core::Real find_nbr_dist(ResidueType const &res, VD &nbr_atom)
Find the neighbor distance to the given neighbor atom. If nbr_atom is null_vertex, give the smallest neighbor distance, and set nbr_atom to the atom for that distance.
support functions for class residue; functions that should not be included as part of the class...
numeric::xyzVector< Length > Vector
A class for defining a type of residue.
std::string const & name() const
get our (unique) residue name
static THREAD_LOCAL basic::Tracer TR("core.chemical.Atom")
ResidueGraph::edge_descriptor ED
utility::vector1< utility::vector1< core::Real > > Matrix
A class for defining atom parameters, known as atom_types.
boost::graph_traits< LightWeightResidueGraph >::vertex_descriptor lwrg_VD
std::string to_string(DOF_Type const &type)
Graph structure for ResidueType.
Vector const & start_pos_
VIterPair atom_iterators() const
Utility visitor for find_nbr_dist Will only traverse those atoms in the "rigid" portion of graph arou...
Size natoms() const
number of atoms
void rename_atoms(ResidueType &res, bool preserve)
Rename atoms in the residue type such that their names are unique. If preserve is true...
boost::graph_traits< LightWeightResidueGraph >::edge_descriptor lwrg_ED
AdjacentIterPair bonded_neighbor_iterators(VD const &atom) const