1 /*
2  *  sketcherMinimizerConstraintInteraction.h
3  *
4  *  Created by Nicola Zonta on 7/02/2019.
5  *   Copyright Schrodinger, LLC. All rights reserved.
6  *
7  */
8 
9 #ifndef sketcherMINIMIZERCONSTRAINTINTERACTION
10 #define sketcherMINIMIZERCONSTRAINTINTERACTION
11 
12 #include "sketcherMinimizerInteraction.h"
13 
14 static const float CONSTRAINT_SCALE = .5f;
15 /* force field bond stretches */
16 class sketcherMinimizerConstraintInteraction
17     : public sketcherMinimizerInteraction
18 {
19   public:
sketcherMinimizerConstraintInteraction(sketcherMinimizerAtom * at1,const sketcherMinimizerPointF & position)20     sketcherMinimizerConstraintInteraction(
21         sketcherMinimizerAtom* at1, const sketcherMinimizerPointF& position)
22         : sketcherMinimizerInteraction(at1, at1), origin(position)
23     {
24         k = CONSTRAINT_SCALE;
25     }
26     ~sketcherMinimizerConstraintInteraction() override = default;
27 
28     /* calculate the energy of the interaction */
energy(float & e)29     void energy(float& e) override
30     {
31         e += k * sketcherMinimizerMaths::squaredDistance(atom1->coordinates,
32                                                          origin);
33     }
34 
35     /* calculate the forces and apply them */
36     void score(float& totalE, bool = false) override { energy(totalE); }
37 
38   private:
39     sketcherMinimizerPointF origin;
40 };
41 
42 #endif // sketcherMINIMIZERCONSTRAINTINTERACTION
43