IMP logo
IMP Reference Guide  2.5.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-2015 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) : dfs_order_(dfs_order), counter_(0) {}
37 
38  template < typename Vertex, typename Graph >
39  void discover_vertex(Vertex v, const Graph& ) {
40  dfs_order_[v] = counter_;
41  counter_++;
42  }
43 
44  std::vector<int>& dfs_order_;
45  int counter_;
46 };
47 
48 /**
49  Defines a kinematic structure over a protein, with backbone
50  and side chain dihedrals
51  */
52 class IMPKINEMATICSEXPORT ProteinKinematics {
53  public:
54  /* Constructors */
55 
56  // all phi/psi rotatable
57  ProteinKinematics(IMP::atom::Hierarchy mhd, bool flexible_backbone = true,
58  bool flexible_side_chains = false);
59 
60  // only torsions from dihedral_angles list are rotatable
62  const IMP::atom::Residues& flexible_residues,
63  const std::vector<IMP::atom::Atoms>& dihedral_angles,
64  IMP::atom::Atoms open_loop_bond_atoms = IMP::atom::Atoms(),
65  bool flexible_backbone = true,
66  bool flexible_side_chains = false);
67 
68  private:
69  //! the actual construction is done here,
70  //! see constructors for documentation
71  void init( const IMP::atom::Residues& flexible_residues,
72  const std::vector<IMP::atom::Atoms>& dihedral_angles,
73  IMP::atom::Atoms open_loop_bond_atoms,
74  bool flexible_backbone,
75  bool flexible_side_chains);
76 
77  void add_edges_to_rb_graph(const std::vector<IMP::atom::Atoms>& dihedral_angles);
78 
79  public:
80  /* Access methods */
81 
82  double get_phi(const IMP::atom::Residue r) const {
83  return get_phi_joint(r)->get_angle();
84  }
85 
86  double get_psi(const IMP::atom::Residue r) const {
87  return get_psi_joint(r)->get_angle();
88  }
89 
90  DihedralAngleRevoluteJoints get_joints() { return joints_; }
91 
92  DihedralAngleRevoluteJoints get_ordered_joints() {
94  IMP_FOREACH(Joint *j, kf_->get_ordered_joints() ){
95  ret.push_back(dynamic_cast<DihedralAngleRevoluteJoint*>(j));
96  }
97  return ret;
98  }
99 
100  KinematicForest* get_kinematic_forest() { return kf_; }
101  // TODO: not sure if we have to return Pointer or just raw pointer
102 
103  IMP::core::RigidBodies get_rigid_bodies() { return rbs_; }
104 
105  // TODO: add chi
106 
107  /* Modifier methods */
108 
109  void set_phi(const IMP::atom::Residue r, double angle) {
110  get_phi_joint(r)->set_angle(angle);
111  kf_->update_all_external_coordinates();
112  }
113 
114  void set_psi(const IMP::atom::Residue r, double angle) {
115  get_psi_joint(r)->set_angle(angle);
116  kf_->update_all_external_coordinates();
117  }
118 
119  // TODO: add chi
120 
121  private:
122  enum ProteinAngleType {
123  PHI,
124  PSI,
125  CHI1,
126  CHI2,
127  CHI3,
128  CHI4,
129  OTHER,
130  TOTAL
131  };
132 
133  void build_topology_graph();
134 
135  void mark_rotatable_angles(
136  const std::vector<IMP::atom::Atoms>& dihedral_angles);
137 
138  void build_rigid_bodies();
139 
140  void add_dihedral_joints(
141  const std::vector<IMP::atom::Atoms>& dihedral_angles);
142 
143  void add_dihedral_joints(
144  const std::vector<IMP::atom::Residue>& residues,
145  ProteinAngleType angle_type,
146  const std::vector<IMP::atom::Atoms>& dihedral_angles);
147 
148  void add_dihedral_joint(const IMP::atom::Residue r,
149  ProteinAngleType angle_type,
150  const IMP::atom::Atoms& atoms);
151 
152  void open_loop(IMP::atom::Atoms open_loop_bond_atoms);
153 
154  /* Joint access methods */
155  DihedralAngleRevoluteJoint* get_phi_joint(const IMP::atom::Residue r) const {
156  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, PHI);
157  }
158 
159  DihedralAngleRevoluteJoint* get_psi_joint(const IMP::atom::Residue r) const {
160  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, PSI);
161  }
162 
163  DihedralAngleRevoluteJoint* get_other_joint(const IMP::atom::Residue r) const {
164  return (DihedralAngleRevoluteJoint*)joint_map_.get_joint(r, OTHER);
165  }
166 
167  //DihedralAngleRevoluteJoints get_joints(const IMP::atom::Residue r) const;
168 
169 #ifndef IMP_DOXYGEN
170  // A map between residue phi/psi and joints
171  class AngleToJointMap {
172  public:
173  // Joint access
174  Joint* get_joint(const IMP::atom::Residue r,
175  ProteinAngleType angle_type) const;
176 
177  // store Joint
178  void add_joint(const IMP::atom::Residue r, ProteinAngleType angle_type,
179  Joint* joint);
180 
181  private:
182  /* mapping to phi/psi/chi for a specific residue.
183  the joints are stored using ProteinAngleType as an index */
184  typedef std::vector<Joint*> ResidueJoints;
185  /* mapping between residue and its joints */
186  boost::unordered_map<IMP::ParticleIndex, ResidueJoints>
187  residue_to_joints_;
188  };
189 #endif // IMP_DOXYGEN
190 
191  private:
192  // protein hierarchy
194 
195  // atom particles
196  IMP::ParticlesTemp atom_particles_;
197 
198  // topology graph: nodes = atoms, edges = bonds
199  Graph graph_;
200 
201  // rigid bodies topology graph: node = atoms, edges = joints
202  Graph rb_graph_;
203 
204  // dfs order of rigid bodies
205  std::vector<int> rb_order_;
206 
207  int largest_rb_;
208 
209  // mapping between atom ParticleIndex and node number in the graph
210  boost::unordered_map<IMP::ParticleIndex, int> particle_index_to_node_map_, rb_particle_index_to_node_map_;
211 
212  IMP::Vector<IMP::ParticleIndex> node_to_particle_index_map_;
213 
214  // rigid bodies
216 
217  // joints
219 
221 
222  // map between residue phi/psi/chis and joints
223  AngleToJointMap joint_map_;
224 };
225 
226 IMPKINEMATICS_END_NAMESPACE
227 
228 #endif /* IMPKINEMATICS_PROTEIN_KINEMATICS_H */
Simple atom decorator.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
The standard decorator for manipulating molecular structures.
functionality for defining rigid bodies
A class for storing lists of IMP items.
A decorator for a residue.
Definition: Residue.h:134
Wrapper class for a kinematic forest (collection of trees) made of KinematicNode objects, interconnected by joints. This data structure allows for kinematic control of the tree and interconversion between internal and external coordinates.
functionality for defining various revolute kinematic joints between rigid bodies as part of a kinema...