IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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>
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 "ScoreWithCache.h"
18
19IMPSCOREFUNCTOR_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 */
28class OrientedSoap : public ScoreWithCache {
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
75 void check_cache_valid(Model *m) const {
76#ifdef IMP_SCORE_FUNCTOR_USE_HDF5
77 doublets_.check_cache_valid(m);
78#endif
79 }
80
81 template <unsigned int D>
82 double get_score_with_cache(Model *m, const Array<D, ParticleIndex> &pis,
83 double distance) const {
84 double score = 0;
85#ifdef IMP_SCORE_FUNCTOR_USE_HDF5
86 int distbin =
87 potential_.get_index(internal::SoapPotential::DISTANCE, distance);
88 if (distbin >= 0) {
89 atom::Atom a1(m, std::get<0>(pis));
90 atom::Atom a2(m, std::get<1>(pis));
91 // Find the other atoms (if any) in the two doublet(s) that (a1,a2)
92 // are members of
93 const DList &doublets1 = doublets_.get_for_atom(a1);
94 if (doublets1.size() > 0) {
95 const DList &doublets2 = doublets_.get_for_atom(a2);
96 for (const internal::SoapModelDoublet &dit1 : doublets1) {
97 for (const internal::SoapModelDoublet &dit2 : doublets2) {
98 score += score_doublets(a1, a2, distbin, dit1, dit2);
99 }
100 }
101 }
102 }
103#endif // IMP_SCORE_FUNCTOR_USE_HDF5
104 return score;
105 }
106 template <unsigned int D>
107 DerivativePair get_score_and_derivative_with_cache(
108 Model *m, const Array<D, ParticleIndex> &pis,
109 double distance) const {
110 // No derivatives are available
111 return DerivativePair(get_score_with_cache(m, pis, distance), 0.);
112 }
113 template <unsigned int D>
114 double get_maximum_range(
115 Model *, const Array<D, ParticleIndex> &) const {
116 return maxrange_;
117 }
118
119 double get_distance_threshold() const { return maxrange_; }
120
121 template <unsigned int D>
122 bool get_is_trivially_zero_with_cache(Model *,
123 const Array<D, ParticleIndex> &,
124 double squared_distance) const {
125 return squared_distance > algebra::get_squared(maxrange_);
126 }
127
128 ModelObjectsTemp get_inputs(
129 Model *m, const ParticleIndexes &pis) const {
131#ifdef IMP_SCORE_FUNCTOR_USE_HDF5
132 // We touch the Residue for each Atom, so make sure that's in the list
133 // Note that we potentially touch other atoms in the Residue that aren't
134 // in the input list; we should really expand the list of Atoms to include
135 // *all* atoms in any Residue we touch.
136 for (unsigned int i = 0; i < pis.size(); ++i) {
137 if (atom::Atom::get_is_setup(m, pis[i])) {
138 atom::Residue r = atom::get_residue(atom::Atom(m, pis[i]));
139 ret.push_back(r);
140 }
141 }
142#endif
143 return ret;
144 }
145};
146
147IMPSCOREFUNCTOR_END_NAMESPACE
148
149#endif /* IMPSCORE_FUNCTOR_ORIENTED_SOAP_H */
A Score on the distance between a pair of particles, with cache.
Various useful constants.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
A class to store a fixed array of same-typed values.
Definition Array.h:40
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
An exception for an invalid value being passed to IMP.
Definition exception.h:136
A decorator for a particle representing an atom.
Definition Atom.h:238
OrientedSoap(std::string library)
Constructor.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition types.h:22
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122