-
Notifications
You must be signed in to change notification settings - Fork 6
/
molecule.h
82 lines (69 loc) · 2.03 KB
/
molecule.h
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
#ifndef SMILEY_MOLECULE_H
#define SMILEY_MOLECULE_H
namespace Smiley {
struct Atom
{
int element;
int isotope;
int hCount;
int charge;
int atomClass;
bool aromatic;
};
struct Bond
{
int source;
int target;
int order;
bool isUp;
bool isDown;
};
struct Molecule
{
const Bond* bond(int source, int target) const
{
for (std::size_t i = 0; i < bonds.size(); ++i)
if ((source == bonds[i].source && target == bonds[i].target) || (source == bonds[i].target && target == bonds[i].source))
return &bonds[i];
return 0;
}
std::vector<Atom> atoms;
std::vector<Bond> bonds;
std::map<int, std::pair<Chirality, std::vector<int> > > chirality;
};
struct MoleculeSmilesCallback : public CallbackBase
{
void clear()
{
molecule.atoms.clear();
molecule.bonds.clear();
molecule.chirality.clear();
}
void addAtom(int atomicNumber, bool aromatic, int isotope, int hCount, int charge, int atomClass)
{
//std::cout << "addAtom(atomicNumber = " << atomicNumber << ", hCount = " << hCount << ")" << std::endl;
molecule.atoms.resize(molecule.atoms.size() + 1);
molecule.atoms.back().element = atomicNumber;
molecule.atoms.back().aromatic = aromatic;
molecule.atoms.back().isotope = isotope;
molecule.atoms.back().hCount = hCount;
molecule.atoms.back().charge = charge;
molecule.atoms.back().atomClass = atomClass;
}
void addBond(int source, int target, int order, bool isUp, bool isDown)
{
molecule.bonds.resize(molecule.bonds.size() + 1);
molecule.bonds.back().source = source;
molecule.bonds.back().target = target;
molecule.bonds.back().order = order;
molecule.bonds.back().isUp = isUp;
molecule.bonds.back().isDown = isDown;
}
void setChiral(int index, Chirality chirality, const std::vector<int> &chiralRefs)
{
molecule.chirality[index] = std::make_pair(chirality, chiralRefs);
}
Molecule molecule;
};
}
#endif