IMP logo
IMP Reference Guide  2.12.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-2019 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 
28 IMPKINEMATICS_BEGIN_NAMESPACE
29 
30 //! Kinematic structure over a protein, with backbone and side chain dihedrals
31 //!
32 //! Note: Particles that are handled by this class should never be decorated
33 //! with IMP::core::RigidBody externally, as this could lead to unexpected behavior
34 //! (e.g., wrong coordinates) and it cannot be detected by IMP at the current time.
35 class IMPKINEMATICSEXPORT ProteinKinematics : public IMP::Object {
36  public:
37 
38  //! Constructor with all phi/psi rotatable
39  ProteinKinematics(atom::Hierarchy mhd, bool flexible_backbone = true,
40  bool flexible_side_chains = false);
41 
42  // Constructor; only torsions from dihedral_angles list are rotatable
44  const atom::Residues& flexible_residues,
45  const std::vector<atom::Atoms>& dihedral_angles,
46  atom::Atoms open_loop_bond_atoms = atom::Atoms(),
47  bool flexible_backbone = true,
48  bool flexible_side_chains = false);
49 
50  private:
51  //! the actual construction is done here,
52  //! see constructors for documentation
53  void init( const atom::Residues& flexible_residues,
54  const std::vector<atom::Atoms>& dihedral_angles,
55  atom::Atoms open_loop_bond_atoms,
56  bool flexible_backbone,
57  bool flexible_side_chains);
58 
59  void add_edges_to_rb_graph(const std::vector<atom::Atoms>& dihedral_angles);
60 
61  public:
62  /* Access methods */
63 
64  double get_phi(const atom::Residue r) const {
65  return get_phi_joint(r)->get_angle();
66  }
67 
68  double get_psi(const atom::Residue r) const {
69  return get_psi_joint(r)->get_angle();
70  }
71 
72  DihedralAngleRevoluteJoints get_joints() { return joints_; }
73 
74  DihedralAngleRevoluteJoints get_loop_joints() { return loop_joints_; }
75 
76  DihedralAngleRevoluteJoints get_ordered_joints() {
78  IMP_FOREACH(Joint *j, kf_->get_ordered_joints() ){
79  ret.push_back(dynamic_cast<DihedralAngleRevoluteJoint*>(j));
80  }
81  return ret;
82  }
83 
84  KinematicForest* get_kinematic_forest() { return kf_; }
85 
86  //! get all rigid bodies that were automatically
87  //! generated in the tree
89 
90  // TODO: add chi
91 
92  /* Modifier methods */
93 
94  void set_phi(const atom::Residue r, double angle) {
95  get_phi_joint(r)->set_angle(angle);
96  kf_->update_all_external_coordinates();
97  }
98 
99  void set_psi(const atom::Residue r, double angle) {
100  get_psi_joint(r)->set_angle(angle);
101  kf_->update_all_external_coordinates();
102  }
103 
104  // TODO: add chi
105 
107 
108  private:
109  enum ProteinAngleType {
110  PHI,
111  PSI,
112  CHI1,
113  CHI2,
114  CHI3,
115  CHI4,
116  OTHER,
117  TOTAL
118  };
119 
120  void build_topology_graph();
121 
122  void order_rigid_bodies(const std::vector<atom::Atoms>& dihedral_angles,
123  const std::vector<atom::Atoms>& phi_angles,
124  const std::vector<atom::Atoms>& psi_angles,
125  atom::Atoms open_loop_bond_atoms);
126 
127  void mark_rotatable_angles(const std::vector<atom::Atoms>& dihedral_angles);
128 
129  //! automatically build rigid bodies for the protein kinematics structure
130  void build_rigid_bodies();
131 
132  void add_dihedral_joints(const std::vector<atom::Atoms>& dihedral_angles);
133 
134  void add_dihedral_joints(const std::vector<atom::Residue>& residues,
135  ProteinAngleType angle_type,
136  const std::vector<atom::Atoms>& dihedral_angles);
137 
138  void add_dihedral_joint(const atom::Residue r,
139  ProteinAngleType angle_type,
140  const atom::Atoms& atoms);
141 
142  void open_loop(atom::Atoms open_loop_bond_atoms);
143 
144  /* Joint access methods */
145  DihedralAngleRevoluteJoint* get_phi_joint(const atom::Residue r) const {
146  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, PHI);
147  }
148 
149  DihedralAngleRevoluteJoint* get_psi_joint(const atom::Residue r) const {
150  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, PSI);
151  }
152 
153  DihedralAngleRevoluteJoint* get_other_joint(const atom::Residue r) const {
154  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, OTHER);
155  }
156 
157  //DihedralAngleRevoluteJoints get_joints(const atom::Residue r) const;
158 
159 #ifndef IMP_DOXYGEN
160  // A map between residue phi/psi and joints
161  class AngleToJointMap {
162  public:
163  // Joint access
164  Joint* get_joint(const atom::Residue r,
165  ProteinAngleType angle_type) const;
166 
167  // store Joint
168  void add_joint(const atom::Residue r, ProteinAngleType angle_type,
169  Joint* joint);
170 
171  private:
172  /* mapping to phi/psi/chi for a specific residue.
173  the joints are stored using ProteinAngleType as an index */
174  typedef std::vector<Joint*> ResidueJoints;
175  /* mapping between residue and its joints */
176  boost::unordered_map<ParticleIndex, ResidueJoints>
177  residue_to_joints_;
178  };
179 #endif // IMP_DOXYGEN
180 
181  private:
182 
183  typedef boost::adjacency_list<
184  boost::vecS, boost::vecS, boost::undirectedS > Graph;
185 
186  // protein hierarchy
187  atom::Hierarchy mhd_;
188 
189  // atom particles
190  ParticlesTemp atom_particles_;
191 
192  // topology graph: nodes = atoms, edges = bonds
193  Graph graph_;
194 
195  // rigid bodies topology graph: node = atoms, edges = joints
196  Graph rb_graph_;
197 
198  // dfs order of rigid bodies
199  std::vector<int> rb_order_, parents_;
200 
201  int largest_rb_;
202 
203  // mapping between atom ParticleIndex and node number in the graph
204  boost::unordered_map<ParticleIndex, int> particle_index_to_node_map_, rb_particle_index_to_node_map_;
205 
206  Vector<ParticleIndex> node_to_particle_index_map_;
207 
208  // rigid bodies
209  core::RigidBodies rbs_;
210 
211  // joints
213 
214  PointerMember<kinematics::KinematicForest> kf_;
215 
216  // map between residue phi/psi/chis and joints
217  AngleToJointMap joint_map_;
218 
219  boost::unordered_map<int, boost::unordered_map<int, Pointer<DihedralAngleRevoluteJoint> > > rigid_bodies_2_joint_map_;
220 
221  DihedralAngleRevoluteJoints loop_joints_;
222 };
223 
225 
226 IMPKINEMATICS_END_NAMESPACE
227 
228 #endif /* IMPKINEMATICS_PROTEIN_KINEMATICS_H */
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Simple atom decorator.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
The standard decorator for manipulating molecular structures.
Common base class for heavy weight IMP objects.
Definition: Object.h:106
functionality for defining rigid bodies
IMP::Vector< IMP::Pointer< DihedralAngleRevoluteJoint > > DihedralAngleRevoluteJoints
A class for storing lists of IMP items.
Joint that is parameterized as a dihedral angle between two planes.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
A decorator for a residue.
Definition: Residue.h:135
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...