8#ifndef IMPNPCTRANSPORT_LINEAR_DISTANCE_PAIR_SCORES_H
9#define IMPNPCTRANSPORT_LINEAR_DISTANCE_PAIR_SCORES_H
11#include "npctransport_config.h"
16#include "internal/sites.h"
18#include <boost/array.hpp>
20IMPNPCTRANSPORT_BEGIN_NAMESPACE
45 double delta_length,
double x0,
double k) {
46 double shifted_length = delta_length - x0;
47 double score = k * shifted_length;
48 static const double MIN_DISTANCE = .00001;
49 if (da && delta_length > MIN_DISTANCE) {
51 Model::add_to_coordinate_derivatives(d_xyzr0, deriv, *da);
52 Model::add_to_coordinate_derivatives(d_xyzr1, -deriv, *da);
53 IMP_LOG(
TERSE,
"Distance: " << shifted_length <<
"\nscore: " << score
54 <<
"\nderiv: " << deriv << std::endl);
57 IMP_LOG(
TERSE,
"Distance: " << shifted_length <<
"\nscore: " << score
69class IMPNPCTRANSPORTEXPORT LinearSoftSpherePairScore :
public PairScore {
86 LinearSoftSpherePairScore(
double k,
87 std::string name =
"LinearSSPairScore%1%");
95 unsigned int lower_bound,
96 unsigned int upper_bound,
97 bool all_indexes_checked=
false)
const override;
103 double max,
unsigned int lower_bound,
104 unsigned int upper_bound,
bool all_indexes_checked=
false)
const override
108 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
110 if (ret > max)
return std::numeric_limits<double>::max();
140 s0.get_center() - s1.get_center();
141 double delta_length_2 =
142 delta.get_squared_magnitude();
144 s0.get_radius() + s1.get_radius();
145 double x0_2 = x0 * x0;
146 bool not_penetrating = delta_length_2 > x0_2;
147 if (not_penetrating)
return 0;
149 double delta_length = std::sqrt(delta_length_2);
151 delta, delta_length, x0, -k_);
157LinearSoftSpherePairScore::evaluate_index
166 m->access_sphere_derivatives_data();
169 return evaluate_index(s0, s1, ds0, ds1, da);
175LinearSoftSpherePairScore::evaluate_indexes
177 const ParticleIndexPairs &pips,
178 DerivativeAccumulator *da,
179 unsigned int lower_bound,
180 unsigned int upper_bound,
bool)
const
183 algebra::Sphere3D
const* xyzrs=
184 m->access_spheres_data();
185 algebra::Sphere3D* d_xyzrs=
186 m->access_sphere_derivatives_data();
188 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
189 int i0(pips[i][0].get_index());
190 int i1(pips[i][1].get_index());
191 ret += evaluate_index( xyzrs[i0], xyzrs[i1],
192 d_xyzrs[i0], d_xyzrs[i1],
214 double particles_delta_squared;
216 double sum_particles_radii;
256 std::string name =
"LinearIDPairScore%1%");
274 return evaluate_index(m, p, da);
283 unsigned int lower_bound,
284 unsigned int upper_bound,
285 bool all_indexes_checked=
false)
const override;
289 unsigned int lower_bound,
290 unsigned int upper_bound)
const {
292 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
293 ret += evaluate_if_good_index(m, p[i], da, max - ret);
294 if (ret > max)
return std::numeric_limits<double>::max();
337 double &delta_length_2 = cache_.particles_delta_squared;
338 double &x0 = cache_.sum_particles_radii;
340 s0.get_center() - s1.get_center();
341 delta_length_2 = delta.get_squared_magnitude();
343 "LinearInteractionPairScore cached delta2 "
344 << cache_.particles_delta_squared << std::endl);
345 x0 = s0.get_radius() + s1.get_radius();
348 if (delta_length_2 > std::pow(x0 + range_attr_, 2))
return 0;
349 double offset = -range_attr_ * k_attr_;
350 double delta_length = std::sqrt(delta_length_2);
351 if (delta_length > x0) {
354 delta, delta_length, x0, k_attr_) +
357 return (do_evaluate_index(ds0, ds1, da,
358 delta, delta_length, x0, -k_rep_) +
364LinearInteractionPairScore::evaluate_index
366 const ParticleIndexPair &pp,
367 DerivativeAccumulator *da)
const
370 algebra::Sphere3D
const& s0(m->get_sphere(pp[0]));
371 algebra::Sphere3D
const& s1(m->get_sphere(pp[1]));
372 algebra::Sphere3D* d_xyzrs=
373 m->access_sphere_derivatives_data();
374 algebra::Sphere3D& ds0( d_xyzrs[pp[0].
get_index()] );
375 algebra::Sphere3D& ds1( d_xyzrs[pp[1].
get_index()] );
376 return evaluate_index(s0, s1, ds0, ds1, da);
380LinearInteractionPairScore::evaluate_indexes
382 const ParticleIndexPairs &pips,
383 DerivativeAccumulator *da,
384 unsigned int lower_bound,
385 unsigned int upper_bound,
bool)
const
388 algebra::Sphere3D
const* xyzrs=
389 m->access_spheres_data();
390 algebra::Sphere3D* d_xyzrs=
391 m->access_sphere_derivatives_data();
393 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
396 ret += evaluate_index( xyzrs[i0], xyzrs[i1],
397 d_xyzrs[i0], d_xyzrs[i1],
412 double rest_length_factor_, k_;
426 std::string name =
"LinearIDPairScore%1%");
428 void set_rest_length_factor(
double rest_length_factor)
429 { rest_length_factor_ = rest_length_factor; }
430 double get_rest_length_factor()
const {
return rest_length_factor_; }
433 double get_k() {
return k_; }
454 m->access_sphere_derivatives_data();
457 double x0 = (s0.get_radius() + s1.get_radius()) * rest_length_factor_;
459 double delta_length_2 = delta.get_squared_magnitude();
460 double delta_length = std::sqrt(delta_length_2);
461 if (delta_length > x0) {
464 delta, delta_length, x0, k_);
467 do_evaluate_index(ds0, ds1, da,
468 delta, delta_length, x0, -k_);
476IMPNPCTRANSPORT_END_NAMESPACE
Decorator for a sphere-like particle.
Functions to deal with very common math operations.
#define IMP_CHECK_CODE(expr)
Only compile the code if checks are enabled.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
virtual double evaluate_if_good_index(Model *m, const ParticleIndexPair &vt, DerivativeAccumulator *da, double max) const
Compute the score and the derivative if needed, only if "good".
LinearInteractionPairScore(double k_rep, double range_attr, double k_attr, std::string name="LinearIDPairScore%1%")
double evaluate_index(algebra::Sphere3D const &s0, algebra::Sphere3D const &s1, algebra::Sphere3D &ds0, algebra::Sphere3D &ds1, DerivativeAccumulator *da) const
double get_range_attraction() const
returns the range for sphere-sphere attraction in A
double get_k_attraction() const
returns the k for sphere-sphere attraction in kcal/mol/A units
double get_k_repulsion() const
returns the k for sphere-sphere repulsion in kcal/mol/A units
virtual double evaluate_indexes(Model *m, const ParticleIndexPairs &pips, DerivativeAccumulator *da, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const override
void set_k_repulsion(double k_rep)
set k for sphere-sphere repulsion in kcal/mol/A units
ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
void set_k_attraction(double k_attr)
set k for sphere-sphere attraction in kcal/mol/A units
virtual double evaluate_indexes(Model *m, const ParticleIndexPairs &pips, DerivativeAccumulator *da, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const override
Compute the score and the derivative if needed over a set.
double get_k() const
returns the k for sphere-sphere repulsion
double evaluate_if_good_indexes(Model *m, const ParticleIndexPairs &p, DerivativeAccumulator *da, double max, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const override
double evaluate_index(algebra::Sphere3D const &s0, algebra::Sphere3D const &s1, algebra::Sphere3D &ds0, algebra::Sphere3D &ds1, DerivativeAccumulator *da) const
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, const ParticleIndexPair &p, DerivativeAccumulator *da) const override
Compute the score and the derivative if needed.
double evaluate_index(Model *m, const ParticleIndexPair &p, DerivativeAccumulator *da) const override
Compute the score and the derivative if needed.
LinearWellPairScore(double rest_length_factor, double k, std::string name="LinearIDPairScore%1%")
ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
#define IMP_IMPLEMENT(signature)
#define IMP_IMPLEMENT_INLINE(signature, body)
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
SphereD< 3 > Sphere3D
Typedef for Python.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
IMP::Vector< IMP::Pointer< LinearWellPairScore > > LinearWellPairScores
double do_evaluate_index(algebra::Sphere3D &d_xyzr0, algebra::Sphere3D &d_xyzr1, DerivativeAccumulator *da, const algebra::Vector3D &delta, double delta_length, double x0, double k)
IMP::Vector< ParticleIndexPair, std::allocator< ParticleIndexPair > > ParticleIndexPairs
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
@ TERSE
Output a line or two per evaluation call.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Macros for various classes.
#define IMP_PAIR_SCORE_METHODS(Name)
#define IMP_UNUSED(variable)