File: Compound.hpp

package info (click to toggle)
libpdb-redo 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,968 kB
  • sloc: cpp: 9,385; sh: 15; makefile: 8
file content (324 lines) | stat: -rw-r--r-- 9,633 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#pragma once

#include <map>
#include <set>
#include <tuple>
#include <vector>

#include "cif++.hpp"

namespace pdb_redo
{

// --------------------------------------------------------------------
// The chemical composition of the structure in an mmCIF file is
// defined in the class composition. A compositon consists of
// entities. Each Entity can be either a polymer, a non-polymer
// a macrolide or a water molecule.
// Entities themselves are made up of compounds. And compounds
// contain CompoundAtom records for each atom.

class Compound;
class Link;
struct CompoundAtom;

enum BondType
{
	singleBond,
	doubleBond,
	tripleBond,
	aromaticBond,
	delocalizedBond
};

// --------------------------------------------------------------------
// struct containing information about an atom in a chemical compound
// This information comes from the CCP4 monomer library.

struct CompoundAtom
{
	std::string id;
	cif::atom_type typeSymbol;
	std::string typeEnergy;
	float partialCharge;
};

// --------------------------------------------------------------------
// struct containing information about the bonds
// This information comes from the CCP4 monomer library.

struct CompoundBond
{
	std::string atomID[2];
	BondType type;
	bool aromatic;
	float distance;
	float esd;
};

// --------------------------------------------------------------------
// struct containing information about the bond-angles
// This information comes from the CCP4 monomer library.

struct CompoundAngle
{
	std::string atomID[3];
	float angle;
	float esd;
};

// --------------------------------------------------------------------
// struct containing information about the bond-angles
// This information comes from the CCP4 monomer library.

struct CompoundTorsion
{
	std::string atomID[4];
	float angle;
	float esd;
	int period;
};

// --------------------------------------------------------------------
// struct containing information about the bond-angles
// This information comes from the CCP4 monomer library.

struct CompoundPlane
{
	std::string id;
	std::vector<std::string> atomID;
	float esd;
};

// --------------------------------------------------------------------
// struct containing information about a chiral centre
// This information comes from the CCP4 monomer library.

enum ChiralVolumeSign
{
	negativ,
	positiv,
	both
};

struct CompoundChiralCentre
{
	std::string id;
	std::string atomIDCentre;
	std::string atomID[3];
	ChiralVolumeSign volumeSign;
};

// --------------------------------------------------------------------
// a class that contains information about a chemical compound.
// This information is derived from the ccp4 monomer library by default.
// To create compounds, you'd best use the factory method.

class Compound
{
  public:
	Compound(const cif::datablock &db, const std::string &id, const std::string &name,
		const std::string &group);

	// accessors
	std::string id() const { return mID; }
	std::string name() const { return mName; }
	std::string type() const;
	std::string group() const { return mGroup; }
	std::vector<CompoundAtom> atoms() const { return mAtoms; }
	std::vector<CompoundBond> bonds() const { return mBonds; }
	std::vector<CompoundAngle> angles() const { return mAngles; }
	std::vector<CompoundChiralCentre> chiralCentres() const
	{
		return mChiralCentres;
	}
	std::vector<CompoundPlane> planes() const { return mPlanes; }
	std::vector<CompoundTorsion> torsions() const { return mTorsions; }

	CompoundAtom get_atom_by_atom_id(const std::string &atomID) const;

	bool atomsBonded(const std::string &atomId_1, const std::string &atomId_2) const;
	float atomBondValue(const std::string &atomId_1, const std::string &atomId_2) const;
	float bondAngle(const std::string &atomId_1, const std::string &atomId_2, const std::string &atomId_3) const;
	float chiralVolume(const std::string &centreID) const;

	std::string formula() const;
	float formulaWeight() const;
	int charge() const;
	bool isWater() const;
	bool isSugar() const;

	// std::vector<std::string> isomers() const;
	// bool isIsomerOf(const Compound &c) const;
	// std::vector<std::tuple<std::string, std::string>> mapToIsomer(const Compound &c) const;

	/// @brief Return the content of this restraint compound in a CCD format
	/// @return Datablock containing the CCD information for this compound
	cif::datablock generateCCDCompound() const;

  private:
	cif::datablock mCF;
	std::string mID;
	std::string mName;
	std::string mGroup;
	std::vector<CompoundAtom> mAtoms;
	std::vector<CompoundBond> mBonds;
	std::vector<CompoundAngle> mAngles;
	std::vector<CompoundTorsion> mTorsions;
	std::vector<CompoundChiralCentre> mChiralCentres;
	std::vector<CompoundPlane> mPlanes;
};

// --------------------------------------------------------------------
// struct containing information about the bonds
// This information comes from the CCP4 monomer library.

struct LinkAtom
{
	int compID;
	std::string atomID;

	bool operator==(const LinkAtom &rhs) const { return compID == rhs.compID and atomID == rhs.atomID; }
};

struct LinkBond
{
	LinkAtom atom[2];
	BondType type;
	float distance;
	float esd;
};

// --------------------------------------------------------------------
// struct containing information about the bond-angles
// This information comes from the CCP4 monomer library.

struct LinkAngle
{
	LinkAtom atom[3];
	float angle;
	float esd;
};

// --------------------------------------------------------------------
// struct containing information about the bond-torsions
// This information comes from the CCP4 monomer library.

struct LinkTorsion
{
	LinkAtom atom[4];
	float angle;
	float esd;
	int period;
};

// --------------------------------------------------------------------
// struct containing information about the bond-angles
// This information comes from the CCP4 monomer library.

struct LinkPlane
{
	std::string id;
	std::vector<LinkAtom> atoms;
	float esd;
};

// --------------------------------------------------------------------
// struct containing information about a chiral centre
// This information comes from the CCP4 monomer library.

struct LinkChiralCentre
{
	std::string id;
	LinkAtom atomCentre;
	LinkAtom atom[3];
	ChiralVolumeSign volumeSign;
};

// --------------------------------------------------------------------
// a class that contains information about a chemical link between compounds.
// This information is derived from the ccp4 monomer library by default.

class Link
{
  public:
	Link(cif::datablock &db);

	// accessors
	std::string id() const { return mID; }
	std::vector<LinkBond> bonds() const { return mBonds; }
	std::vector<LinkAngle> angles() const { return mAngles; }
	std::vector<LinkChiralCentre> chiralCentres() const { return mChiralCentres; }
	std::vector<LinkPlane> planes() const { return mPlanes; }
	std::vector<LinkTorsion> torsions() const { return mTorsions; }

	float atomBondValue(const LinkAtom &atomId_1, const LinkAtom &atomId_2) const;
	float bondAngle(const LinkAtom &atomId_1, const LinkAtom &atomId_2, const LinkAtom &atomId_3) const;

	/// \brief Calculate the target chiral volume for \a id for the link between \a compound_id_1 and \a compound_id_2
	/// The compound id's are required to calculate standard bond lengths in case these are not recorded in the link record
	float chiralVolume(const std::string &id, const std::string &compound_id_1, const std::string &compound_id_2) const;

  private:

	std::string mID;
	std::vector<LinkBond> mBonds;
	std::vector<LinkAngle> mAngles;
	std::vector<LinkTorsion> mTorsions;
	std::vector<LinkChiralCentre> mChiralCentres;
	std::vector<LinkPlane> mPlanes;
};

// --------------------------------------------------------------------
// Factory class for Compound and Link objects

class CompoundFactory
{
  public:
	static CompoundFactory &instance();

	const Compound *get(std::string id);
	const Compound *create(std::string id);

	const Link *getLink(std::string id);
	const Link *createLink(std::string id);

	~CompoundFactory();

	void pushDictionary(const std::filesystem::path &inDictFile);
	void pushDictionary(std::istream &inDictionary);
	void popDictionary();

  private:
	CompoundFactory();

	class CompoundFactoryImpl *mImpl;
};

} // namespace pdb_redo