Debian Codegraph @

avogadro/core/residue.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_CORE_RESIDUE_H
7 #define AVOGADRO_CORE_RESIDUE_H
8
9 #include "avogadrocoreexport.h"
10
11 #include "avogadrocore.h"
12
13 #include <limits>
14 #include <map>
15 #include <string>
16
17 #include "vector.h"
18
19 namespace Avogadro::Core {
20
21 class Atom;
22 class Molecule;
23
24 /**
25 * @class Residue residue.h <avogadro/core/residue.h>
26 * @brief The Residue class represents a chemical residue, used commonly in the
27 * PDB format.
28 */
29 class AVOGADROCORE_EXPORT Residue
30 {
31 public:
32 /** Type for atom name map. */
33 using AtomNameMap = std::map<std::string, Atom>;
34
35 // using codes from MMTF specification
36 // https://github.com/rcsb/mmtf/blob/master/spec.md#secstructlist
37 enum SecondaryStructure
38 {
39 piHelix = 0, // DSSP "I"
40 bend = 1, // DSSP "S"
41 alphaHelix = 2, // DSSP "H"
42 betaSheet = 3, // DSSP "E"
43 helix310 = 4, // DSSP "G"
44 betaBridge = 5, // DSSP "B"
45 turn = 6, // DSSP "T"
46 coil = 7, // DSSP "C"
47 maybeBeta = -3, // potential beta strand
48 undefined = -1
49 };
50
51 /** Creates a new, empty residue. */
52 Residue() = default;
53 Residue(std::string& name);
54 Residue(std::string& name, Index& number);
55 Residue(std::string& name, Index& number, char& id);
56
57 Residue(const Residue& other);
58
59 Residue& operator=(Residue other);
60
61 virtual ~Residue() = default;
62
63 std::string residueName() const { return m_residueName; }
64
65 void setResidueName(std::string& name) { m_residueName = name; }
66
67 Index residueId() const { return m_residueId; }
68
69 void setResidueId(Index& number) { m_residueId = number; }
70
71 char chainId() const { return m_chainId; }
72
73 void setChainId(const char& id) { m_chainId = id; }
74
75 SecondaryStructure secondaryStructure() const { return m_secondaryStructure; }
76
77 void setSecondaryStructure(const SecondaryStructure& ss)
78 {
79 m_secondaryStructure = ss;
80 }
81
82 /** Adds an atom to the residue class */
83 void addResidueAtom(const std::string& name, const Atom& atom);
84
85 /** \return a vector containing the atoms added to the residue */
86 std::vector<Atom> residueAtoms() const;
87
88 /** \return the atom map for the residue */
89 AtomNameMap& atomNameMap() { return m_atomNameMap; }
90
91 /** Sets bonds to atoms in the residue based on data from residuedata header
92 */
93 void resolveResidueBonds(Molecule& mol);
94
95 /**
96 * \return the atom with the name specified (e.g., "CA")
97 */
98 Atom atomByName(std::string name) const;
99 /**
100 * \return the atomic number of the atom with the name specified (e.g., "CA" =
101 * "C")
102 */
103 int atomicNumber(std::string name) const;
104
105 /**
106 * \return the name of @p atom or an empty string if not in this residue
107 */
108 std::string atomName(const Atom atom) const;
109
110 /**
111 * \return the name of atom @p index or an empty string if not in this residue
112 */
113 std::string atomName(const Index index) const;
114
115 bool hasAtomByIndex(Index index) const;
116 /** Set whether this residue is a "HET" / "HETATOM" ligand
117 */
118 void setHeterogen(bool heterogen) { m_heterogen = heterogen; }
119
120 /** \return is this residue a heterogen (HET / HETATM)
121 */
122 bool isHeterogen() const { return m_heterogen; }
123
124 /** Set a custom color for this residue
125 */
126 void setColor(const Vector3ub color);
127
128 /** \return the color set for this residue, or a default from the chain id
129 */
130 Vector3ub color() const;
131
132 protected:
133 std::string m_residueName;
134 Index m_residueId = std::numeric_limits<Index>::max();
135 char m_chainId = 'A';
136 AtomNameMap m_atomNameMap;
137 bool m_heterogen = false;
138 Vector3ub m_color = Vector3ub(0, 0, 0);
139 bool m_customColorSet = false;
140 SecondaryStructure m_secondaryStructure = undefined;
141 };
142
143 } // namespace Avogadro::Core
144
145 #endif // AVOGADRO_CORE_RESIDUE_H