File: ChiralViolationContrib.h

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (102 lines) | stat: -rw-r--r-- 3,549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Created by Santosh Putta, Nov 2006
//
#include <RDGeneral/export.h>
#ifndef __RD_CHIRALVIOLATIONCONTRIB_H__
#define __RD_CHIRALVIOLATIONCONTRIB_H__

#include <ForceField/Contrib.h>
#include <Geometry/point.h>

namespace DistGeom {
class ChiralSet;

//! A term to capture the violation of chirality at an atom center
//!
class RDKIT_DISTGEOMETRY_EXPORT ChiralViolationContrib : public ForceFields::ForceFieldContrib {
 public:
  ChiralViolationContrib()
      : d_idx1(0),
        d_idx2(0),
        d_idx3(0),
        d_idx4(0),
        d_volLower(0.0),
        d_volUpper(0.0),
        d_weight(0.0){};

  //! Constructor
  /*!
    \param owner      pointer to the owning forcefield
    \param cset       a chiral set containing the four chiral atom ids (in
    sequence)
                      and the upper and lower limits on the signed chiral volume
    \param weight     (optional) the weight to be used for this contrib

  */
  ChiralViolationContrib(ForceFields::ForceField *owner, const ChiralSet *cset,
                         double weight = 1.0);

  //! return the contribution of this contrib to the energy of a given state
  double getEnergy(double *pos) const;

  //! calculate the contribution of this contrib to the gradient at a given
  //state
  void getGrad(double *pos, double *grad) const;
  virtual ChiralViolationContrib *copy() const {
    return new ChiralViolationContrib(*this);
  };

  static double calcChiralVolume(unsigned int idx1, unsigned int idx2,
                                 unsigned int idx3, unsigned int idx4,
                                 const double *pos, unsigned int dim) {
    // even if we are minimizing in higher dimension the chiral volume is
    // calculated using only the first 3 dimensions
    RDGeom::Point3D v1(pos[idx1 * dim] - pos[idx4 * dim],
                       pos[idx1 * dim + 1] - pos[idx4 * dim + 1],
                       pos[idx1 * dim + 2] - pos[idx4 * dim + 2]);

    RDGeom::Point3D v2(pos[idx2 * dim] - pos[idx4 * dim],
                       pos[idx2 * dim + 1] - pos[idx4 * dim + 1],
                       pos[idx2 * dim + 2] - pos[idx4 * dim + 2]);

    RDGeom::Point3D v3(pos[idx3 * dim] - pos[idx4 * dim],
                       pos[idx3 * dim + 1] - pos[idx4 * dim + 1],
                       pos[idx3 * dim + 2] - pos[idx4 * dim + 2]);

    RDGeom::Point3D v2xv3 = v2.crossProduct(v3);

    double vol = v1.dotProduct(v2xv3);
    return vol;
  }
  static double calcChiralVolume(unsigned int idx1, unsigned int idx2,
                                 unsigned int idx3, unsigned int idx4,
                                 const RDGeom::PointPtrVect &pts) {
    // even if we are minimizing in higher dimension the chiral volume is
    // calculated using only the first 3 dimensions
    RDGeom::Point3D v1((*pts[idx1])[0] - (*pts[idx4])[0],
                       (*pts[idx1])[1] - (*pts[idx4])[1],
                       (*pts[idx1])[2] - (*pts[idx4])[2]);

    RDGeom::Point3D v2((*pts[idx2])[0] - (*pts[idx4])[0],
                       (*pts[idx2])[1] - (*pts[idx4])[1],
                       (*pts[idx2])[2] - (*pts[idx4])[2]);

    RDGeom::Point3D v3((*pts[idx3])[0] - (*pts[idx4])[0],
                       (*pts[idx3])[1] - (*pts[idx4])[1],
                       (*pts[idx3])[2] - (*pts[idx4])[2]);

    RDGeom::Point3D v2xv3 = v2.crossProduct(v3);

    double vol = v1.dotProduct(v2xv3);
    return vol;
  }

 private:
  unsigned int d_idx1, d_idx2, d_idx3, d_idx4;
  double d_volLower;
  double d_volUpper;
  double d_weight;
};
}

#endif