IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
ProteinKinematics.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kinematics/ProteinKinematics.h
3  * \brief functionality for defining a kinematic forest for proteins
4  *
5  * Copyright 2007-2017 IMP Inventors. All rights reserved.
6  * \authors Dina Schneidman, Barak Raveh
7  *
8  */
9 
10 #ifndef IMPKINEMATICS_PROTEIN_KINEMATICS_H
11 #define IMPKINEMATICS_PROTEIN_KINEMATICS_H
12 
13 #include "kinematics_config.h"
14 
17 
18 #include <IMP/core/rigid_bodies.h>
19 #include <IMP/atom/Atom.h>
20 
21 #include <boost/unordered_map.hpp>
22 #include <IMP/Vector.h>
23 #include <vector>
24 #include <iostream>
25 
26 #include <boost/graph/adjacency_list.hpp>
27 #include <boost/graph/undirected_dfs.hpp>
28 
29 IMPKINEMATICS_BEGIN_NAMESPACE
30 
31 typedef boost::adjacency_list<
32  boost::vecS, boost::vecS, boost::undirectedS > Graph;
33 
34 class MyDFSVisitor : public boost::default_dfs_visitor {
35 public:
36  MyDFSVisitor(std::vector<int>& dfs_order, std::vector<int>& parents) :
37  dfs_order_(dfs_order), parents_(parents), counter_(0) {}
38 
39  template < typename Vertex, typename Graph >
40  void discover_vertex(Vertex v, const Graph& ) {
41  dfs_order_[v] = counter_;
42  counter_++;
43  }
44 
45  template < typename Edge, typename Graph >
46  void tree_edge(Edge e, const Graph& g) {
47  std::cerr << "tree_edge " << source(e, g) << " -- " << target(e, g)
48  << " dfs_order " << dfs_order_[source(e, g)] << " -- " << dfs_order_[target(e, g)] << std::endl;
49  parents_[target(e,g)] = source(e, g);
50  }
51 
52  std::vector<int>& dfs_order_;
53  std::vector<int>& parents_;
54  int counter_;
55 };
56 
57 //! Kinematic structure over a protein, with backbone and side chain dihedrals
58 class IMPKINEMATICSEXPORT ProteinKinematics {
59  public:
60 
61  //! Constructor with all phi/psi rotatable
62  ProteinKinematics(atom::Hierarchy mhd, bool flexible_backbone = true,
63  bool flexible_side_chains = false);
64 
65  // Constructor; only torsions from dihedral_angles list are rotatable
67  const atom::Residues& flexible_residues,
68  const std::vector<atom::Atoms>& dihedral_angles,
69  atom::Atoms open_loop_bond_atoms = atom::Atoms(),
70  bool flexible_backbone = true,
71  bool flexible_side_chains = false);
72 
73  private:
74  //! the actual construction is done here,
75  //! see constructors for documentation
76  void init( const atom::Residues& flexible_residues,
77  const std::vector<atom::Atoms>& dihedral_angles,
78  atom::Atoms open_loop_bond_atoms,
79  bool flexible_backbone,
80  bool flexible_side_chains);
81 
82  void add_edges_to_rb_graph(const std::vector<atom::Atoms>& dihedral_angles);
83 
84  public:
85  /* Access methods */
86 
87  double get_phi(const atom::Residue r) const {
88  return get_phi_joint(r)->get_angle();
89  }
90 
91  double get_psi(const atom::Residue r) const {
92  return get_psi_joint(r)->get_angle();
93  }
94 
95  DihedralAngleRevoluteJoints get_joints() { return joints_; }
96 
97  DihedralAngleRevoluteJoints get_loop_joints() { return loop_joints_; }
98 
99  DihedralAngleRevoluteJoints get_ordered_joints() {
101  IMP_FOREACH(Joint *j, kf_->get_ordered_joints() ){
102  ret.push_back(dynamic_cast<DihedralAngleRevoluteJoint*>(j));
103  }
104  return ret;
105  }
106 
107  KinematicForest* get_kinematic_forest() { return kf_; }
108 
109  core::RigidBodies get_rigid_bodies() { return rbs_; }
110 
111  // TODO: add chi
112 
113  /* Modifier methods */
114 
115  void set_phi(const atom::Residue r, double angle) {
116  get_phi_joint(r)->set_angle(angle);
117  kf_->update_all_external_coordinates();
118  }
119 
120  void set_psi(const atom::Residue r, double angle) {
121  get_psi_joint(r)->set_angle(angle);
122  kf_->update_all_external_coordinates();
123  }
124 
125  // TODO: add chi
126 
127  private:
128  enum ProteinAngleType {
129  PHI,
130  PSI,
131  CHI1,
132  CHI2,
133  CHI3,
134  CHI4,
135  OTHER,
136  TOTAL
137  };
138 
139  void build_topology_graph();
140 
141  void order_rigid_bodies(const std::vector<atom::Atoms>& dihedral_angles,
142  const std::vector<atom::Atoms>& phi_angles,
143  const std::vector<atom::Atoms>& psi_angles,
144  atom::Atoms open_loop_bond_atoms);
145 
146  void mark_rotatable_angles(const std::vector<atom::Atoms>& dihedral_angles);
147 
148  void build_rigid_bodies();
149 
150  void add_dihedral_joints(const std::vector<atom::Atoms>& dihedral_angles);
151 
152  void add_dihedral_joints(const std::vector<atom::Residue>& residues,
153  ProteinAngleType angle_type,
154  const std::vector<atom::Atoms>& dihedral_angles);
155 
156  void add_dihedral_joint(const atom::Residue r,
157  ProteinAngleType angle_type,
158  const atom::Atoms& atoms);
159 
160  void open_loop(atom::Atoms open_loop_bond_atoms);
161 
162  /* Joint access methods */
163  DihedralAngleRevoluteJoint* get_phi_joint(const atom::Residue r) const {
164  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, PHI);
165  }
166 
167  DihedralAngleRevoluteJoint* get_psi_joint(const atom::Residue r) const {
168  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, PSI);
169  }
170 
171  DihedralAngleRevoluteJoint* get_other_joint(const atom::Residue r) const {
172  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, OTHER);
173  }
174 
175  //DihedralAngleRevoluteJoints get_joints(const atom::Residue r) const;
176 
177 #ifndef IMP_DOXYGEN
178  // A map between residue phi/psi and joints
179  class AngleToJointMap {
180  public:
181  // Joint access
182  Joint* get_joint(const atom::Residue r,
183  ProteinAngleType angle_type) const;
184 
185  // store Joint
186  void add_joint(const atom::Residue r, ProteinAngleType angle_type,
187  Joint* joint);
188 
189  private:
190  /* mapping to phi/psi/chi for a specific residue.
191  the joints are stored using ProteinAngleType as an index */
192  typedef std::vector<Joint*> ResidueJoints;
193  /* mapping between residue and its joints */
194  boost::unordered_map<ParticleIndex, ResidueJoints>
195  residue_to_joints_;
196  };
197 #endif // IMP_DOXYGEN
198 
199  private:
200  // protein hierarchy
201  atom::Hierarchy mhd_;
202 
203  // atom particles
204  ParticlesTemp atom_particles_;
205 
206  // topology graph: nodes = atoms, edges = bonds
207  Graph graph_;
208 
209  // rigid bodies topology graph: node = atoms, edges = joints
210  Graph rb_graph_;
211 
212  // dfs order of rigid bodies
213  std::vector<int> rb_order_, parents_;
214 
215  int largest_rb_;
216 
217  // mapping between atom ParticleIndex and node number in the graph
218  boost::unordered_map<ParticleIndex, int> particle_index_to_node_map_, rb_particle_index_to_node_map_;
219 
220  Vector<ParticleIndex> node_to_particle_index_map_;
221 
222  // rigid bodies
223  core::RigidBodies rbs_;
224 
225  // joints
227 
229 
230  // map between residue phi/psi/chis and joints
231  AngleToJointMap joint_map_;
232 
233  boost::unordered_map<int, boost::unordered_map<int, Pointer<DihedralAngleRevoluteJoint> > > rigid_bodies_2_joint_map_;
234 
235  DihedralAngleRevoluteJoints loop_joints_;
236 };
237 
238 IMPKINEMATICS_END_NAMESPACE
239 
240 #endif /* IMPKINEMATICS_PROTEIN_KINEMATICS_H */
Kinematic structure over a protein, with backbone and side chain dihedrals.
Simple atom decorator.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
The standard decorator for manipulating molecular structures.
functionality for defining rigid bodies
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
A class for storing lists of IMP items.
Joint that is parameterized as a dihedral angle between two planes.
A decorator for a residue.
Definition: Residue.h:134
Base class for joints between rigid bodies in a kinematic tree.
Definition: Joint.h:30
Define and manipulate a kinematic structure over a model.
Define and manipulate a kinematic structure over a model.
functionality for defining various revolute kinematic joints between rigid bodies as part of a kinema...