IMP logo
IMP Reference Guide  2.19.0
The Integrative Modeling Platform
SoapPairFilter.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/SoapPairFilter.h
3  * \brief PairFilter for SOAP
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPATOM_SOAP_PAIR_FILTER_H
10 #define IMPATOM_SOAP_PAIR_FILTER_H
11 
12 #include <IMP/atom/atom_config.h>
13 #include <IMP/score_functor/score_functor_config.h>
14 #include <IMP/PairPredicate.h>
15 #include <IMP/pair_macros.h>
16 #include "internal/soap_chain_separation.h"
17 #include "internal/soap_bond_separation.h"
18 
19 IMPATOM_BEGIN_NAMESPACE
20 
21 //! Filter atom pairs for SOAP.
22 /** Most SOAP potentials are trained using only a subset of particle pairs
23  (e.g. only pairs where the atoms are in different chains). This filter
24  can be used to exclude atom pairs not in that subset.
25  */
26 class SoapPairFilter : public PairPredicate {
27 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
28  internal::SoapBondSeparation bondsep_;
29  internal::SoapChainSeparation chainsep_;
30 #endif
31  public:
32  SoapPairFilter(std::string library) {
33 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
34  score_functor::internal::Hdf5File file_id(library);
35  bondsep_.read(file_id);
36  chainsep_.read(file_id);
37 #else
38  IMP_UNUSED(library);
39  IMP_THROW("Must configure IMP with HDF5 to use this class", ValueException);
40 #endif
41  }
42 
43  virtual int get_value_index(Model *m,
44  const ParticleIndexPair &p) const
45  override {
46 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
47  return !chainsep_.get_separation_ok(m, p) ||
48  !bondsep_.get_separation_ok(m, p);
49 #else
50  return true;
51 #endif
52  }
53 
55  Model *m, const ParticleIndexes &pis) const override {
57 #ifdef IMP_SCORE_FUNCTOR_USE_HDF5
58  if (chainsep_.enabled() || bondsep_.enabled()) {
59  // We touch the two parents (residue and chain) of each atom to
60  // determine chain separation; for bond separation we potentially touch
61  // other residues and atoms in the same chain as the inputs
62  // (to detect disulfides) but this isn't currently handled here.
63  for (unsigned int i = 0; i < pis.size(); ++i) {
64  if (Atom::get_is_setup(m, pis[i])) {
65  Residue r = get_residue(Atom(m, pis[i]));
66  Hierarchy c = r.get_parent();
67  ret.push_back(r);
68  ret.push_back(c);
69  }
70  }
71  }
72 #endif
73  return ret;
74  }
75 
78 };
79 
80 IMPATOM_END_NAMESPACE
81 
82 #endif /* IMPATOM_SOAP_PAIR_FILTER_H */
Hierarchy get_parent() const
Get the parent particle.
virtual int get_value_index(Model *m, const ParticleIndexPair &p) const override
Compute the predicate and the derivative if needed.
Macros for various classes.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Filter atom pairs for SOAP.
The standard decorator for manipulating molecular structures.
#define IMP_UNUSED(variable)
A decorator for a particle representing an atom.
Definition: atom/Atom.h:238
Define PairPredicate.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Definition: check_macros.h:50
A decorator for a residue.
Definition: Residue.h:137
Abstract predicate function.
Definition: PairPredicate.h:31
Residue get_residue(Atom d, bool nothrow=false)
Return the Residue containing this atom.
An exception for an invalid value being passed to IMP.
Definition: exception.h:136
#define IMP_PAIR_PREDICATE_METHODS(Name)
Define extra the functions needed for a PairPredicate.
Definition: pair_macros.h:78