IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
ZBiasSingletonScore.h
Go to the documentation of this file.
1/**
2 * \file ZBiasSingletonScore.h
3 * \brief score that biases particles to go down the Z axis
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 */
7
8#ifndef IMPNPCTRANSPORT_Z_BIAS_SINGLETON_SCORE_H
9#define IMPNPCTRANSPORT_Z_BIAS_SINGLETON_SCORE_H
10
11#include "npctransport_config.h"
12#include "enums.h"
13#include <IMP/SingletonScore.h>
16#include <limits>
17#include <utility>
18
19IMPNPCTRANSPORT_BEGIN_NAMESPACE
20
21
22//! Score that biases particles to go down the Z axis
23class IMPNPCTRANSPORTEXPORT ZBiasSingletonScore
24 : public SingletonScore {
25 private:
26 double k_; // force constant (positive for pulling towards z_, negative for pushing away from z_)
27 double max_r2_; // maximal square r (distance from z axis)
28 double z_; // z to bias towards/away from
29 public:
30 /**
31 Exclude particles from the range of z coordinates [bottom_..top_]
32 with repulsive force constant k
33
34 @param k force constant (positive for pulling towards z, negative for pushing away from z)
35 @param max_r maximal distance from z axis (radius
36 relative to pore axis) in which force is applied.
37 if 0.0, no limitation
38 @param z z of xy plane to bias towards / against (relevant only if k is non-zero)
39 */
41 ( double k,
42 double max_r = HALF_SQRT_MAX_DOUBLE, // half for numerical margin error
43 double z = std::numeric_limits<double>::min())
44 : k_(k), max_r2_( max_r * max_r ), z_(z) {}
45
46
47 /**
48 returns the force constant for pulling
49 */
50 double get_k() const { return k_; }
51
52 /**
53 evaluates the derivative according to the particle position
54
55 @param d core::XYZR position of the particle
56 @return a pair with the score and the derivative vector
57 */
58 std::pair<double, algebra::Vector3D> evaluate_deriv(const core::XYZR &d) const {
59 double score;
60 algebra::Vector3D v_deriv;
61 double r2 = std::pow(d.get_x(), 2) + std::pow(d.get_y(), 2);
62 if (r2 > max_r2_ && max_r2_ > 0.0) {
63 score = 0.0;
64 v_deriv = algebra::Vector3D(0, 0, 0); // nothing to add to derivatives( = 0);
65 return std::make_pair(score, v_deriv);
66 }
67
68 double dz = d.get_z() - z_;
69 if (dz > 1e-6) {
70 score = k_ * dz;
71 v_deriv = algebra::Vector3D(0, 0, k_);
72 }
73 else if (dz < -1e-6) {
74 score = k_ * (-dz);
75 v_deriv = algebra::Vector3D(0, 0, -k_);
76 }
77 else{
78 score = 0;
79 v_deriv = algebra::Vector3D(0, 0, 0);
80 }
81
82 return std::make_pair(score, v_deriv);
83 }
84
85 virtual double evaluate_index(Model *m, ParticleIndex pi,
86 DerivativeAccumulator *da) const override
87 {
88 core::XYZR d(m,pi);
89 auto score_deriv = evaluate_deriv(d);
90 auto score = score_deriv.first;
91 auto v_deriv = score_deriv.second;
92 if (da) {
93 IMP_LOG(VERBOSE, "result in " << score
94 << " and " << v_deriv << std::endl);
95 d.add_to_derivatives(v_deriv, *da);
96 }
97 return score;
98 }
99
101 const ParticleIndexes &pis) const
102 override
103 { return IMP::get_particles(m, pis); }
104
107};
108
109IMPNPCTRANSPORT_END_NAMESPACE
110
111#endif /* IMPNPCTRANSPORT_Z_BIAS_SINGLETON_SCORE_H */
Define SingletonScore.
Simple 3D vector class.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
A decorator for a particle with x,y,z coordinates and a radius.
Definition XYZR.h:27
std::pair< double, algebra::Vector3D > evaluate_deriv(const core::XYZR &d) const
ZBiasSingletonScore(double k, double max_r=HALF_SQRT_MAX_DOUBLE, double z=std::numeric_limits< double >::min())
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
virtual double evaluate_index(Model *m, ParticleIndex pi, DerivativeAccumulator *da) const override
Compute the score and the derivative if needed.
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
VectorD< 3 > Vector3D
Definition VectorD.h:407
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
@ VERBOSE
Produce copious output to allow someone to trace through the computation.
Definition enums.h:33
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Macros for various classes.
#define IMP_SINGLETON_SCORE_METHODS(Name)