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