IMP logo
IMP Reference Guide  2.8.0
The Integrative Modeling Platform
OrientedSoap.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/OrientedSoap.h
3  * \brief Score a particle pair using an orientation-dependent SOAP potential.
4  *
5  * Copyright 2007-2017 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPSCORE_FUNCTOR_ORIENTED_SOAP_H
9 #define IMPSCORE_FUNCTOR_ORIENTED_SOAP_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/algebra/constants.h>
13 #include <IMP/core/internal/angle_helpers.h>
14 #include <IMP/core/internal/dihedral_helpers.h>
15 #include "internal/soap_hdf5.h"
16 #include "internal/soap_helpers.h"
17 #include "Score.h"
18 
19 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
20 
21 //! Orientation-dependent SOAP score.
22 /** Such scores include those that score loops
23  (SOAP-Loop), protein-peptide interfaces (SOAP-Peptide) and proteins
24  (SOAP-Protein). The library files themselves, such as soap_loop.hdf5 or
25  soap_protein_od.hdf5, are rather large (~1.5GB) and so are not included
26  here. They can be downloaded separately from https://salilab.org/SOAP/.
27  */
28 class OrientedSoap : public Score {
29  double maxrange_;
30  std::string library_;
31 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
32  internal::SoapPotential potential_;
33  internal::SoapDoublets doublets_;
34 
35  typedef std::vector<internal::SoapModelDoublet> DList;
36 
37  void read_library(std::string library) {
38  internal::Hdf5File file_id(library);
39  doublets_.read(file_id);
40  potential_.read(file_id, doublets_);
41  maxrange_ = potential_.get_max_range();
42  }
43 
44  //! Return the score for the interaction between a pair of doublets
45  double score_doublets(atom::Atom a1, atom::Atom a2, int distbin,
46  const internal::SoapModelDoublet &d1,
47  const internal::SoapModelDoublet &d2) const {
48  double ang1 =
49  core::internal::angle(a1, a2, d2.atom, nullptr, nullptr, nullptr) *
50  180.0 / PI;
51  double ang2 =
52  core::internal::angle(d1.atom, a1, a2, nullptr, nullptr, nullptr) *
53  180.0 / PI;
54  double dih = core::internal::dihedral(d1.atom, a1, a2, d2.atom, nullptr,
55  nullptr, nullptr, nullptr) *
56  180.0 / PI;
57  return potential_.get_value(distbin, ang1, ang2, dih, d1.doublet_class,
58  d2.doublet_class);
59  }
60 #endif // IMP_SCORE_FUNCTOR_USE_HDF5
61 
62  public:
63  //! Constructor.
64  /** \param[in] library The HDF5 file containing the SOAP library.
65  */
66  OrientedSoap(std::string library) : library_(library) {
67 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
68  read_library(library);
69 #else
70  maxrange_ = 0.;
71  IMP_THROW("Must configure IMP with HDF5 to use this class", ValueException);
72 #endif
73  }
74  template <unsigned int D>
75  double get_score(Model *m,
76  const Array<D, ParticleIndex> &pis,
77  double distance) const {
78  double score = 0;
79 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
80  int distbin =
81  potential_.get_index(internal::SoapPotential::DISTANCE, distance);
82  if (distbin >= 0) {
83  atom::Atom a1(m, pis[0]);
84  atom::Atom a2(m, pis[1]);
85  // Find the other atoms (if any) in the two doublet(s) that (a1,a2)
86  // are members of
87  DList doublets1 = doublets_.get_for_atom(a1);
88  if (doublets1.size() > 0) {
89  DList doublets2 = doublets_.get_for_atom(a2);
90  for (DList::const_iterator dit1 = doublets1.begin();
91  dit1 != doublets1.end(); ++dit1) {
92  for (DList::const_iterator dit2 = doublets2.begin();
93  dit2 != doublets2.end(); ++dit2) {
94  score += score_doublets(a1, a2, distbin, *dit1, *dit2);
95  }
96  }
97  }
98  }
99 #endif // IMP_SCORE_FUNCTOR_USE_HDF5
100  return score;
101  }
102  template <unsigned int D>
103  DerivativePair get_score_and_derivative(
104  Model *m, const Array<D, ParticleIndex> &pis,
105  double distance) const {
106  // No derivatives are available
107  return DerivativePair(get_score(m, pis, distance), 0.);
108  }
109  template <unsigned int D>
110  double get_maximum_range(
111  Model *, const Array<D, ParticleIndex> &) const {
112  return maxrange_;
113  }
114 
115  double get_distance_threshold() const { return maxrange_; }
116 
117  template <unsigned int D>
118  bool get_is_trivially_zero(Model *,
119  const Array<D, ParticleIndex> &,
120  double squared_distance) const {
121  return squared_distance > algebra::get_squared(maxrange_);
122  }
123 
124  ModelObjectsTemp get_inputs(
125  Model *m, const ParticleIndexes &pis) const {
126  ModelObjectsTemp ret = IMP::get_particles(m, pis);
127 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
128  // We touch the Residue for each Atom, so make sure that's in the list
129  // Note that we potentially touch other atoms in the Residue that aren't
130  // in the input list; we should really expand the list of Atoms to include
131  // *all* atoms in any Residue we touch.
132  for (unsigned int i = 0; i < pis.size(); ++i) {
133  if (atom::Atom::get_is_setup(m, pis[i])) {
134  atom::Residue r = atom::get_residue(atom::Atom(m, pis[i]));
135  ret.push_back(r);
136  }
137  }
138 #endif
139  return ret;
140  }
141 };
142 
143 IMPSCOREFUNCTOR_END_NAMESPACE
144 
145 #endif /* IMPSCORE_FUNCTOR_ORIENTED_SOAP_H */
OrientedSoap(std::string library)
Constructor.
Definition: OrientedSoap.h:66
Orientation-dependent SOAP score.
Definition: OrientedSoap.h:28
static const double PI
the constant pi
A class to store an fixed array of same-typed values.
Definition: Array.h:33
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:82
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
A decorator for a particle representing an atom.
Definition: atom/Atom.h:234
Various useful constants.
A Score on the distance between a pair of particles.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Definition: check_macros.h:50
Residue get_residue(Atom d, bool nothrow=false)
Return the Residue containing this atom.
A functor for computing a distance based score for two particles.
Definition: Score.h:20
An exception for an invalid value being passed to IMP.
Definition: exception.h:137