8#ifndef IMPNPCTRANSPORT_SLAB_PAIR_SCORE_H
9#define IMPNPCTRANSPORT_SLAB_PAIR_SCORE_H
11#include "npctransport_config.h"
18IMPNPCTRANSPORT_BEGIN_NAMESPACE
31class IMPNPCTRANSPORTEXPORT
37 mutable double thickness_;
38 mutable double pore_radius_;
40 mutable double bottom_;
42 mutable bool is_pore_radius_optimized_;
81 unsigned int lower_bound,
82 unsigned int upper_bound,
83 bool all_indexes_checked=
false) const override final;
99 unsigned int lower_bound,
100 unsigned int upper_bound,
101 bool all_indexes_checked=false)
const override
105 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
107 if (ret > max)
return std::numeric_limits<double>::max();
126 inline double evaluate_sphere
137 std::pair<double, algebra::Vector3D> get_displacement_vector(
142 void update_cached_slab_params
147SlabWithCylindricalPorePairScore::update_cached_slab_params
151 thickness_= slab.get_thickness();
152 top_= 0.5*thickness_;
153 bottom_= -0.5*thickness_;
155 pore_radius_= slab.get_pore_radius();
156 is_pore_radius_optimized_= slab.get_pore_radius_is_optimized();
168 "pip[0] is not a SlabWithCylindricalPore in evaluate_index()");
170 update_cached_slab_params(slab);
173 if (!d.get_coordinates_are_optimized())
176 double score=evaluate_sphere(d_sphere,
177 da ? &displacement :
nullptr);
180 IMP_LOG(
PROGRESS,
"result in " << score <<
" and " << derivative_vector << std::endl);
181 d.add_to_derivatives(derivative_vector, *da);
182 if(is_pore_radius_optimized_){
184 double radial_displacement_magnitude=
185 std::sqrt(displacement[0]*displacement[0]+displacement[1]*displacement[1]);
186 slab.add_to_pore_radius_derivative(-k_*radial_displacement_magnitude, *da);
198 unsigned int lower_bound,
199 unsigned int upper_bound,
bool)
const
201 if(upper_bound<lower_bound){
205 double radial_displacements_magnitude(0.0);
207 m->access_spheres_data();
209 m->access_sphere_derivatives_data();
210 IMP::internal::BoolAttributeTableTraits::Container
const& is_optimizable_table=
211 m->access_optimizeds_data(core::XYZ::get_coordinate_key(0));
214 update_cached_slab_params(slab);
216 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
218 int pi_index=pi.get_index();
222 "All particles are assumed to be evaluated against"
227 "optimable table inconsistent with d.get_coordinates_are_optimized for particle " << d);
229 "Different coords for particle " << d <<
" *** "
230 << d.get_coordinates() <<
" vs. " << s.get_center());
232 "Different radii for particle " << d <<
" *** "
233 << d.get_radius() <<
" vs. " << s.get_radius());
235 if(!is_optimizable_table[pi]) {
239 double cur_score = evaluate_sphere(spheres_table[pi_index],
240 da ? &displacement :
nullptr);
242 if(cur_score>0.0 && da) {
245 for(
unsigned int j=0; j<3; j++) {
246 sphere_derivatives_table[pi_index][j] += (*da)(derivative_vector[j]);
249 radial_displacements_magnitude+=
250 std::sqrt(displacement[0]*displacement[0] + displacement[1]*displacement[1]);
253 if(da && is_pore_radius_optimized_){
254 slab.add_to_pore_radius_derivative(-k_ * radial_displacements_magnitude, *da);
261SlabWithCylindricalPorePairScore::evaluate_sphere
266 IMP_LOG(
VERBOSE,
"evaluate_sphere " << s << std::endl);
267 double const x= s[0];
268 double const y= s[1];
269 double const z= s[2];
270 double const sr= s.get_radius();
272 if ((z-sr > top_) || (z+sr < bottom_)) {
275 double const x2= x*x;
276 double const y2= y*y;
277 double const R= pore_radius_-sr;
278 double const R2= R*R;
283 std::pair<double, algebra::Vector3D> dp = get_displacement_vector(s.get_center());
285 "At point " << s.get_center() <<
" have distance " << dp.first
286 <<
" and direction " << dp.second << std::endl);
287 double const distance = dp.first;
291 double const score= k_ * (sr - distance);
292 if(out_displacement){
293 *out_displacement= dp.second;
295 "Not a unit vector");
305inline std::pair<double, algebra::Vector3D>
306SlabWithCylindricalPorePairScore::get_displacement_vector(
const algebra::Vector3D &v)
const {
307 double dXY2 = square(v[0]) + square(v[1]);
308 double dZ = v[2] - midZ_;
310 if (dXY2 > square(pore_radius_) ||
311 (v[2] <= top_ && v[2] >= bottom_)) {
312 double abs_dZ = std::abs(dZ);
313 double abs_dXY = std::sqrt(dXY2);
314 double dR = abs_dXY - pore_radius_;
315 if (dR + abs_dZ < .5 * thickness_) {
318 return std::make_pair(pore_radius_, algebra::Vector3D(0, 0, 1));
320 algebra::Vector3D rv(-v[0], -v[1], 0);
321 return std::make_pair(pore_radius_ - abs_dXY, rv.get_unit_vector());
326 return std::make_pair(v[2] - top_, algebra::Vector3D(0, 0, 1));
328 return std::make_pair(bottom_ - v[2], algebra::Vector3D(0, 0, -1));
336 return std::make_pair(v[2] - top_, algebra::Vector3D(0, 0, 1));
338 return std::make_pair(bottom_ - v[2], algebra::Vector3D(0, 0, -1));
341 algebra::Vector3D rim =
342 algebra::Vector3D(v[0], v[1], 0).get_unit_vector() * pore_radius_;
349 algebra::Vector3D diff = v - rim;
350 return std::make_pair(diff.get_magnitude(), diff.get_unit_vector());
357IMPNPCTRANSPORT_END_NAMESPACE
A decorator for a particle that's a slab with a cylindrical pore.
Decorator for a sphere-like particle.
Helper macros for throwing and handling exceptions.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
#define IMP_CHECK_CODE(expr)
Only compile the code if checks are enabled.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
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".
A decorator for a particle with x,y,z coordinates and a radius.
virtual double evaluate_index(Model *m, const ParticleIndexPair &pip, DerivativeAccumulator *da) const override
evaluate score for particle pair pip in model m
algebra::Vector3D get_displacement_direction(SlabWithCylindricalPore const &slab, const algebra::Vector3D &v) const
returns the direction vector for the displacement of point v relative to the slab surface
double get_displacement_magnitude(SlabWithCylindricalPore const &slab, const algebra::Vector3D &v) const
returns the displacement magnitude of point v relative to the slab surface
SlabWithCylindricalPorePairScore(double k)
double evaluate_if_good_indexes(Model *m, const ParticleIndexPairs &pips, DerivativeAccumulator *da, double max, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const override
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
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 final
#define IMP_LOG_PROGRESS(expr)
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
SphereD< 3 > Sphere3D
Typedef for Python.
Index< ParticleIndexTag > ParticleIndex
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
@ VERBOSE
Produce copious output to allow someone to trace through the computation.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Macros for various classes.
#define IMP_UNUSED(variable)