SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
include
colour.h
Go to the documentation of this file.
1
#ifndef COLOUR_H
2
#define COLOUR_H
3
4
#include <map>
5
#include <string>
6
#include <filesystem>
7
#include <sstream>
8
#include <fstream>
9
10
#include <glm/glm.hpp>
11
12
#include <
element.h
>
13
18
const
std::map<Element, glm::vec4>
CPK_COLOURS
=
19
{
20
{
Element::Unknown
, {1.0,0.5,0.5,1.0}},
21
{
Element::H
, {1.0,1.0,1.0,1.0}},
22
{
Element::He
, {1.0,0.753,0.796,1.0}},
23
{
Element::Li
, {0.698,0.133,0.133,1.0}},
24
{
Element::Be
, {1.0,0.078,0.576,1.0}},
25
{
Element::B
, {0.0,1.0,0.0,1.0}},
26
{
Element::C
, {0.784,0.784,0.784,1.0}},
27
{
Element::N
, {0.561,0.561,1.0,1.0}},
28
{
Element::O
, {0.941,0.0,0.0,1.0}},
29
{
Element::F
, {0.855,0.647,0.125,1.0}},
30
{
Element::Ne
, {1.0,0.078,0.576,1.0}},
31
{
Element::Na
, {0.0,0.0,1.0,1.0}},
32
{
Element::Mg
, {0.133,0.545,0.133,1.0}},
33
{
Element::Al
, {0.502,0.502,0.565,1.0}},
34
{
Element::Si
, {0.855,0.647,0.125,1.0}},
35
{
Element::P
, {1.0,0.647,0.0,1.0}},
36
{
Element::S
, {1.0,0.784,0.196,1.0}},
37
{
Element::Cl
, {0.0,1.0,0.0,1.0}},
38
{
Element::Ar
, {1.0,0.078,0.576,1.0}},
39
{
Element::K
, {1.0,0.078,0.576,1.0}},
40
{
Element::Ca
, {0.502,0.502,0.565,1.0}},
41
{
Element::Sc
, {1.0,0.078,0.576,1.0}},
42
{
Element::Ti
, {0.502,0.502,0.565,1.0}},
43
{
Element::V
, {1.0,0.078,0.576,1.0}},
44
{
Element::Cr
, {0.502,0.502,0.565,1.0}},
45
{
Element::Mn
, {0.502,0.502,0.565,1.0}},
46
{
Element::Fe
, {1.0,0.647,0.0,1.0}},
47
{
Element::Co
, {1.0,0.078,0.576,1.0}},
48
{
Element::Ni
, {0.647,0.165,0.165,1.0}},
49
{
Element::Cu
, {0.647,0.165,0.165,1.0}},
50
{
Element::Zn
, {0.647,0.165,0.165,1.0}},
51
{
Element::Ga
, {1.0,0.078,0.576,1.0}},
52
{
Element::Ge
, {1.0,0.078,0.576,1.0}},
53
{
Element::As
, {1.0,0.078,0.576,1.0}},
54
{
Element::Se
, {1.0,0.078,0.576,1.0}},
55
{
Element::Br
, {0.647,0.165,0.165,1.0}},
56
{
Element::Kr
, {1.0,0.078,0.576,1.0}},
57
{
Element::Rb
, {1.0,0.078,0.576,1.0}},
58
{
Element::Sr
, {1.0,0.078,0.576,1.0}},
59
{
Element::Y
, {1.0,0.078,0.576,1.0}},
60
{
Element::Zr
, {1.0,0.078,0.576,1.0}},
61
{
Element::Nb
, {1.0,0.078,0.576,1.0}},
62
{
Element::Mo
, {1.0,0.078,0.576,1.0}},
63
{
Element::Tc
, {1.0,0.078,0.576,1.0}},
64
{
Element::Ru
, {1.0,0.078,0.576,1.0}},
65
{
Element::Rh
, {1.0,0.078,0.576,1.0}},
66
{
Element::Pd
, {1.0,0.078,0.576,1.0}},
67
{
Element::Ag
, {0.502,0.502,0.565,1.0}},
68
{
Element::Cd
, {1.0,0.078,0.576,1.0}},
69
{
Element::In
, {1.0,0.078,0.576,1.0}},
70
{
Element::Sn
, {1.0,0.078,0.576,1.0}},
71
{
Element::Sb
, {1.0,0.078,0.576,1.0}},
72
{
Element::Te
, {1.0,0.078,0.576,1.0}},
73
{
Element::I
, {0.627,0.125,0.941,1.0}},
74
{
Element::Xe
, {1.0,0.078,0.576,1.0}},
75
{
Element::Cs
, {1.0,0.078,0.576,1.0}},
76
{
Element::Ba
, {1.0,0.647,0.0,1.0}},
77
{
Element::La
, {1.0,0.078,0.576,1.0}},
78
{
Element::Ce
, {1.0,0.078,0.576,1.0}},
79
{
Element::Pr
, {1.0,0.078,0.576,1.0}},
80
{
Element::Nd
, {1.0,0.078,0.576,1.0}},
81
{
Element::Pm
, {1.0,0.078,0.576,1.0}},
82
{
Element::Sm
, {1.0,0.078,0.576,1.0}},
83
{
Element::Eu
, {1.0,0.078,0.576,1.0}},
84
{
Element::Gd
, {1.0,0.078,0.576,1.0}},
85
{
Element::Tb
, {1.0,0.078,0.576,1.0}},
86
{
Element::Dy
, {1.0,0.078,0.576,1.0}},
87
{
Element::Ho
, {1.0,0.078,0.576,1.0}},
88
{
Element::Er
, {1.0,0.078,0.576,1.0}},
89
{
Element::Tm
, {1.0,0.078,0.576,1.0}},
90
{
Element::Yb
, {1.0,0.078,0.576,1.0}},
91
{
Element::Lu
, {1.0,0.078,0.576,1.0}},
92
{
Element::Hf
, {1.0,0.078,0.576,1.0}},
93
{
Element::Ta
, {1.0,0.078,0.576,1.0}},
94
{
Element::W
, {1.0,0.078,0.576,1.0}},
95
{
Element::Re
, {1.0,0.078,0.576,1.0}},
96
{
Element::Os
, {1.0,0.078,0.576,1.0}},
97
{
Element::Ir
, {1.0,0.078,0.576,1.0}},
98
{
Element::Pt
, {1.0,0.078,0.576,1.0}},
99
{
Element::Au
, {0.855,0.647,0.125,1.0}},
100
{
Element::Hg
, {1.0,0.078,0.576,1.0}},
101
{
Element::Tl
, {1.0,0.078,0.576,1.0}},
102
{
Element::Pb
, {1.0,0.078,0.576,1.0}},
103
{
Element::Bi
, {1.0,0.078,0.576,1.0}},
104
{
Element::Po
, {1.0,0.078,0.576,1.0}},
105
{
Element::At
, {1.0,0.078,0.576,1.0}},
106
{
Element::Rn
, {1.0,1.0,1.0,1.0}},
107
{
Element::Fr
, {1.0,1.0,1.0,1.0}},
108
{
Element::Ra
, {1.0,1.0,1.0,1.0}},
109
{
Element::Ac
, {1.0,1.0,1.0,1.0}},
110
{
Element::Th
, {1.0,0.078,0.576,1.0}},
111
{
Element::Pa
, {1.0,1.0,1.0,1.0}},
112
{
Element::U
, {1.0,0.078,0.576,1.0}},
113
{
Element::Np
, {1.0,1.0,1.0,1.0}},
114
{
Element::Pu
, {1.0,1.0,1.0,1.0}},
115
{
Element::Am
, {1.0,1.0,1.0,1.0}},
116
{
Element::Cm
, {1.0,1.0,1.0,1.0}},
117
{
Element::Bk
, {1.0,1.0,1.0,1.0}},
118
{
Element::Cf
, {1.0,1.0,1.0,1.0}},
119
{
Element::Es
, {1.0,1.0,1.0,1.0}},
120
{
Element::Fm
, {1.0,1.0,1.0,1.0}},
121
{
Element::Md
, {1.0,1.0,1.0,1.0}},
122
{
Element::No
, {1.0,1.0,1.0,1.0}},
123
{
Element::Lw
, {1.0,1.0,1.0,1.0}}
124
};
125
132
glm::vec4
elementToColour
(
Element
& e)
133
{
134
return
CPK_COLOURS
.at(e);
135
}
136
143
glm::vec4
stringSymbolToColour
(std::string & s)
144
{
145
return
CPK_COLOURS
.at(
stringSymbolToElement
(s));
146
}
147
157
std::map<Element, glm::vec4>
coloursFromFile
(std::filesystem::path path)
158
{
159
if
(std::filesystem::exists(path))
160
{
161
std::map<Element, glm::vec4> colours(
CPK_COLOURS
);
162
std::ifstream in(path);
163
std::string line;
164
std::stringstream ss;
165
std::string name;
166
Element
element;
167
float
r, g, b, a;
168
while
(std::getline(in, line))
169
{
170
ss = std::stringstream(line);
171
ss >> name >> r >> g >> b >> a;
172
element =
stringSymbolToElement
(name);
173
if
(!ss.fail() && element !=
Element::Unknown
)
174
{
175
colours[element] = glm::vec4(r, g, b, a);
176
}
177
}
178
179
return
colours;
180
}
181
else
182
{
183
std::cout <<
"Could not find colourmap file "
<< path <<
" defaulting to CPK\n"
;
184
return
CPK_COLOURS
;
185
}
186
}
187
197
std::map<uint64_t, glm::vec4>
atomColoursFromFile
(std::filesystem::path path)
198
{
199
std::map<uint64_t, glm::vec4> colours;
200
if
(std::filesystem::exists(path))
201
{
202
std::ifstream in(path);
203
std::string line;
204
std::stringstream ss;
205
std::string name;
206
uint64_t atom;
207
float
r, g, b, a;
208
while
(std::getline(in, line))
209
{
210
ss = std::stringstream(line);
211
ss >> atom >> r >> g >> b >> a;
212
if
(!ss.fail())
213
{
214
colours[atom] = glm::vec4(r, g, b, a);
215
}
216
}
217
}
218
return
colours;
219
}
220
221
#endif
/* COLOUR_H */
CPK_COLOURS
const std::map< Element, glm::vec4 > CPK_COLOURS
Corey–Pauling–Koltun colourings.
Definition
colour.h:18
elementToColour
glm::vec4 elementToColour(Element &e)
Map an Element to a CPK colour.
Definition
colour.h:132
coloursFromFile
std::map< Element, glm::vec4 > coloursFromFile(std::filesystem::path path)
Read an Element colour map from a file.
Definition
colour.h:157
atomColoursFromFile
std::map< uint64_t, glm::vec4 > atomColoursFromFile(std::filesystem::path path)
Read an atom index colour map from a file.
Definition
colour.h:197
stringSymbolToColour
glm::vec4 stringSymbolToColour(std::string &s)
Map a string symbol to a CPK colour.
Definition
colour.h:143
element.h
Element
Element
Representable elements.
Definition
element.h:13
Element::Os
@ Os
Element::Nb
@ Nb
Element::Pb
@ Pb
Element::Po
@ Po
Element::C
@ C
Element::Tl
@ Tl
Element::Tm
@ Tm
Element::Nd
@ Nd
Element::Hg
@ Hg
Element::Cd
@ Cd
Element::Ag
@ Ag
Element::La
@ La
Element::Al
@ Al
Element::Tc
@ Tc
Element::Sm
@ Sm
Element::Er
@ Er
Element::Te
@ Te
Element::Es
@ Es
Element::As
@ As
Element::Si
@ Si
Element::Yb
@ Yb
Element::Cl
@ Cl
Element::Lw
@ Lw
Element::Ca
@ Ca
Element::Bi
@ Bi
Element::Be
@ Be
Element::Ce
@ Ce
Element::P
@ P
Element::Cr
@ Cr
Element::U
@ U
Element::Cm
@ Cm
Element::Ne
@ Ne
Element::Pm
@ Pm
Element::Au
@ Au
Element::V
@ V
Element::Hf
@ Hf
Element::Kr
@ Kr
Element::Y
@ Y
Element::Ti
@ Ti
Element::S
@ S
Element::Rh
@ Rh
Element::Zn
@ Zn
Element::W
@ W
Element::Ra
@ Ra
Element::Mn
@ Mn
Element::Co
@ Co
Element::Sn
@ Sn
Element::Pd
@ Pd
Element::Ho
@ Ho
Element::F
@ F
Element::Li
@ Li
Element::Ar
@ Ar
Element::Ta
@ Ta
Element::Unknown
@ Unknown
Element::Ac
@ Ac
Element::Zr
@ Zr
Element::Sr
@ Sr
Element::Cs
@ Cs
Element::Br
@ Br
Element::N
@ N
Element::Np
@ Np
Element::Xe
@ Xe
Element::Na
@ Na
Element::Pt
@ Pt
Element::B
@ B
Element::Ir
@ Ir
Element::Pa
@ Pa
Element::Ni
@ Ni
Element::Se
@ Se
Element::K
@ K
Element::He
@ He
Element::Cu
@ Cu
Element::Md
@ Md
Element::Rb
@ Rb
Element::Ru
@ Ru
Element::Mg
@ Mg
Element::Rn
@ Rn
Element::Gd
@ Gd
Element::Lu
@ Lu
Element::Ba
@ Ba
Element::No
@ No
Element::Pr
@ Pr
Element::Tb
@ Tb
Element::Mo
@ Mo
Element::H
@ H
Element::Bk
@ Bk
Element::Ge
@ Ge
Element::Dy
@ Dy
Element::Sc
@ Sc
Element::Fe
@ Fe
Element::Pu
@ Pu
Element::Sb
@ Sb
Element::Eu
@ Eu
Element::At
@ At
Element::I
@ I
Element::Ga
@ Ga
Element::Fm
@ Fm
Element::Th
@ Th
Element::In
@ In
Element::Am
@ Am
Element::O
@ O
Element::Re
@ Re
Element::Cf
@ Cf
Element::Fr
@ Fr
stringSymbolToElement
Element stringSymbolToElement(const std::string &s)
Map a string symbol to an Element.
Definition
element.h:681
Generated by
1.9.8