File: Utils.cpp

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (90 lines) | stat: -rw-r--r-- 2,407 bytes parent folder | download | duplicates (2)
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
//
//  Copyright (C) 2013-2024 Paolo Tosco and other RDKit contributors
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//

#include "Utils.h"
#include <cmath>

namespace ForceFields {
namespace UFF {
namespace Utils {

double calculateCosY(const RDGeom::Point3D &iPoint,
                     const RDGeom::Point3D &jPoint,
                     const RDGeom::Point3D &kPoint,
                     const RDGeom::Point3D &lPoint) {
  constexpr double zeroTol = 1.0e-16;
  RDGeom::Point3D rJI = iPoint - jPoint;
  RDGeom::Point3D rJK = kPoint - jPoint;
  RDGeom::Point3D rJL = lPoint - jPoint;
  auto l2JI = rJI.lengthSq();
  auto l2JK = rJK.lengthSq();
  auto l2JL = rJL.lengthSq();
  if (l2JI < zeroTol || l2JK < zeroTol || l2JL < zeroTol) {
    return 0.0;
  }
  RDGeom::Point3D n = rJI.crossProduct(rJK);
  n /= (sqrt(l2JI) * sqrt(l2JK));
  auto l2n = n.lengthSq();
  if (l2n < zeroTol) {
    return 0.0;
  }
  return n.dotProduct(rJL) / (sqrt(l2JL) * sqrt(l2n));
}

std::tuple<double, double, double, double>
calcInversionCoefficientsAndForceConstant(int at2AtomicNum, bool isCBoundToO) {
  double res = 0.0;
  double C0 = 0.0;
  double C1 = 0.0;
  double C2 = 0.0;
  // if the central atom is sp2 carbon, nitrogen or oxygen
  if ((at2AtomicNum == 6) || (at2AtomicNum == 7) || (at2AtomicNum == 8)) {
    C0 = 1.0;
    C1 = -1.0;
    C2 = 0.0;
    res = (isCBoundToO ? 50.0 : 6.0);
  } else {
    // group 5 elements are not clearly explained in the UFF paper
    // the following code was inspired by MCCCS Towhee's ffuff.F
    double w0 = M_PI / 180.0;
    switch (at2AtomicNum) {
      // if the central atom is phosphorous
      case 15:
        w0 *= 84.4339;
        break;

      // if the central atom is arsenic
      case 33:
        w0 *= 86.9735;
        break;

      // if the central atom is antimonium
      case 51:
        w0 *= 87.7047;
        break;

      // if the central atom is bismuth
      case 83:
        w0 *= 90.0;
        break;
    }
    C2 = 1.0;
    C1 = -4.0 * cos(w0);
    C0 = -(C1 * cos(w0) + C2 * cos(2.0 * w0));
    res = 22.0 / (C0 + C1 + C2);
  }
  res /= 3.0;

  return std::make_tuple(res, C0, C1, C2);
}

}  // end of namespace Utils
}  // namespace UFF
}  // namespace ForceFields