-
Notifications
You must be signed in to change notification settings - Fork 28
/
sketcherMinimizerRing.cpp
172 lines (157 loc) · 4.06 KB
/
sketcherMinimizerRing.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* sketcherMinimizerRing.cpp
*
* Created by Nicola Zonta on 24/05/2011.
* Copyright Schrodinger, LLC. All rights reserved.
*
*/
#include "sketcherMinimizerRing.h"
#include "sketcherMinimizerAtom.h"
#include "sketcherMinimizerBond.h"
#include "sketcherMinimizerMaths.h"
using namespace std;
sketcherMinimizerRing::sketcherMinimizerRing()
: visited(false), coordinatesGenerated(false)
{
// assert (0);
side = false;
}
sketcherMinimizerRing::~sketcherMinimizerRing() = default;
sketcherMinimizerPointF sketcherMinimizerRing::findCenter()
{
sketcherMinimizerPointF o(0.f, 0.f);
for (auto& _atom : _atoms) {
o += _atom->coordinates;
}
o /= _atoms.size();
return o;
}
bool sketcherMinimizerRing::isBenzene()
{
if (_atoms.size() != 6) {
return false;
}
for (auto& _atom : _atoms) {
if (_atom->atomicNumber != 6) {
return false;
}
}
for (auto a : _atoms) {
bool found = false;
for (auto& bond : a->bonds) {
if (bond->bondOrder == 2) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
bool sketcherMinimizerRing::isAromatic() // not chemically accurate, but good
// enough for minimizer
{
size_t bonds = _bonds.size();
int doubleBonds = 0;
int NSOCount = 0;
for (auto& _bond : _bonds) {
if (_bond->bondOrder == 2) {
doubleBonds++;
}
}
for (auto& _atom : _atoms) {
int an = _atom->atomicNumber;
bool doubleBound = false;
for (auto& bond : _atom->bonds) {
if (bond->bondOrder == 2) {
doubleBound = true;
}
}
if (!doubleBound) {
if (an == 8 || an == 7 || an == 16) {
NSOCount++;
}
}
}
if (bonds == 6 && doubleBonds == 3) {
return true;
}
if (bonds == 5 && doubleBonds == 2 && NSOCount == 1) {
return true;
}
return false;
}
bool sketcherMinimizerRing::containsAtom(const sketcherMinimizerAtom* a) const
{
for (auto _atom : _atoms) {
if (_atom == a) {
return true;
}
}
return false;
}
bool sketcherMinimizerRing::containsBond(sketcherMinimizerBond* b)
{
for (auto& _bond : _bonds) {
if (_bond == b) {
return true;
}
}
return false;
}
bool sketcherMinimizerRing::isFusedWith(sketcherMinimizerRing* ring)
{
for (auto& i : fusedWith) {
if (i == ring) {
return true;
}
}
return false;
}
std::vector<sketcherMinimizerAtom*> sketcherMinimizerRing::getFusionAtomsWith(
const sketcherMinimizerRing* ring) const
{
for (unsigned int i = 0; i < fusedWith.size(); i++) {
if (fusedWith[i] == ring) {
return fusionAtoms[i];
}
}
std::vector<sketcherMinimizerAtom*> empty;
return empty;
}
bool sketcherMinimizerRing::sameAs(sketcherMinimizerRing* ring)
{
if (!(_bonds.size() == ring->_bonds.size())) {
return false;
}
for (auto& _bond : _bonds) {
if (!ring->containsBond(_bond)) {
return false;
}
}
return true;
}
bool sketcherMinimizerRing::contains(const sketcherMinimizerPointF& p)
{
int n = 0;
for (auto b : _bonds) {
if ((p.y() < b->startAtom->coordinates.y() &&
p.y() > b->endAtom->coordinates.y()) ||
(p.y() > b->startAtom->coordinates.y() &&
p.y() < b->endAtom->coordinates.y())) {
sketcherMinimizerPointF v =
b->endAtom->coordinates - b->startAtom->coordinates;
if (v.y() > SKETCHER_EPSILON || v.y() < -SKETCHER_EPSILON) {
v *= (p.y() - b->startAtom->coordinates.y()) / v.y();
v += b->startAtom->coordinates;
if (p.x() > v.x()) {
n++;
}
}
}
}
return (n % 2) != 0;
}
// std::vector <sketcherMinimizerBond *> _bonds;