Skip to content

Commit 076dbfc

Browse files
author
Jordan Bieder
committed
Add hold functionnality to plot band.
Customize the color with color=R G B if no spin or 1 spin and color=R B G R B G for 2 spin chnnels
1 parent 7bd5df3 commit 076dbfc

File tree

3 files changed

+58
-35
lines changed

3 files changed

+58
-35
lines changed

include/plot/graph.hpp

+2-18
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,7 @@ class Graph {
9696
/**
9797
* Save a list of 15 custom colors
9898
*/
99-
const char HTMLcolor[15][8]={
100-
"#505050", //Grey
101-
"#CF009E", // line04
102-
"#6EC4E8", // line13
103-
"#FF7E2E", // line05
104-
"#6ECA97", // line06
105-
"#FA9ABA", // line07
106-
"#003CA6", // line03
107-
"#E19BDF", // line08
108-
"#C9910D", // line10
109-
"#B6BD00", // line09
110-
"#704B1C", // line11
111-
"#007852", // line12
112-
"#62259D", // line14
113-
"#FFCD00", // line01
114-
"#837902" // line02
115-
};
99+
static const char HTMLcolor[15][8];
116100

117101
public :
118102

@@ -314,7 +298,7 @@ class Graph {
314298
* @param gplot The graph to plot to. If nullptr, nothing plot but data written
315299
* @param save What to do with the calculated data : plot ? save to file ? save raw data?
316300
*/
317-
static void plotBand(EigParser &eigparser, ConfigParser &config, Graph* gplot, Graph::GraphSave save);
301+
static void plotBand(EigParser &eigparser, ConfigParser &config, Graph* gplot, Config& conf);
318302

319303
/**
320304
* Function to plot DOS

src/canvas/canvas.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,7 @@ void Canvas::plot(unsigned tbegin, unsigned tend, std::istream &stream) {
515515
}
516516
}
517517

518-
519-
Graph::plotBand(*(_eigparser.get()),parser,_gplot.get(),_graphConfig.save);
518+
Graph::plotBand(*(_eigparser.get()), parser, _gplot.get(), _graphConfig);
520519
}
521520
else if ( function == "dos" ) {
522521
DosDB db;

src/plot/graph.cpp

+55-15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
#include "io/eigparserelectrons.hpp"
3333
#include "io/electrondos.hpp"
3434

35+
const char Graph::HTMLcolor[15][8] = {
36+
"#505050", // Grey
37+
"#CF009E", // line04
38+
"#6EC4E8", // line13
39+
"#FF7E2E", // line05
40+
"#6ECA97", // line06
41+
"#FA9ABA", // line07
42+
"#003CA6", // line03
43+
"#E19BDF", // line08
44+
"#C9910D", // line10
45+
"#B6BD00", // line09
46+
"#704B1C", // line11
47+
"#007852", // line12
48+
"#62259D", // line14
49+
"#FFCD00", // line01
50+
"#837902" // line02
51+
};
52+
3553
//
3654
Graph::Graph() : _xlabel(),
3755
_ylabel(),
@@ -232,8 +250,8 @@ void Graph::clearCustom() {
232250
_arrows.clear();
233251
}
234252

235-
void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, Graph::GraphSave save) {
236-
Graph::Config config;
253+
void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph *gplot,
254+
Graph::Config &config) {
237255
std::vector<double> &x = config.x;
238256
std::list<std::vector<double>> &y = config.y;
239257
std::list<std::string> &labels = config.labels;
@@ -244,6 +262,14 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G
244262
std::string &title = config.title;
245263
bool &doSumUp = config.doSumUp;
246264

265+
static int colorId = 0;
266+
if (config.x.size() == 0)
267+
colorId = 0;
268+
auto color_1 = Graph::rgb(HTMLcolor[colorId++]);
269+
colorId = colorId % 15;
270+
auto color_2 = Graph::rgb(HTMLcolor[colorId++]);
271+
colorId = colorId % 15;
272+
247273
if ( gplot != nullptr )
248274
gplot->setWinTitle("Band Structure");
249275
doSumUp = false;
@@ -318,19 +344,24 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G
318344
std::vector<unsigned> projectionUMask;
319345
bool projection = false;
320346
if ( parser.hasToken("fatband") ) {
347+
if (parser.hasToken("color")) {
348+
Exception e =
349+
EXCEPTION("fatband and color options are exclusive", ERRWAR);
350+
std::clog << e.fullWhat() << std::endl;
351+
}
321352
projection = true;
322353
try {
323-
projectionUMask = parser.getToken<unsigned>("fatband",eigparser.getNband());
324-
}
325-
catch ( Exception &e ) {
326-
if ( e.getReturnValue() & ConfigParser::ERDIM ) {
327-
auto blabla = e.what("",true);
354+
projectionUMask =
355+
parser.getToken<unsigned>("fatband", eigparser.getNband());
356+
} catch (Exception &e) {
357+
if (e.getReturnValue() & ConfigParser::ERDIM) {
358+
auto blabla = e.what("", true);
328359
auto pos = blabla.find("Could only read ");
329360
int maxToRead = 0;
330-
if ( pos != std::string::npos ) {
331-
std::istringstream sub(blabla.substr(pos+16));
361+
if (pos != std::string::npos) {
362+
std::istringstream sub(blabla.substr(pos + 16));
332363
sub >> maxToRead;
333-
projectionUMask = parser.getToken<unsigned>("fatband",maxToRead);
364+
projectionUMask = parser.getToken<unsigned>("fatband", maxToRead);
334365
}
335366
}
336367
}
@@ -376,13 +407,21 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G
376407
eeig = nullptr;
377408
}
378409

410+
if (parser.hasToken("color")) {
411+
std::vector<unsigned> rgb =
412+
parser.getToken<unsigned>("color", eigparser.isPolarized() ? 6 : 3);
413+
color_1 = Graph::rgb(rgb[0], rgb[1], rgb[2]);
414+
if (eigparser.isPolarized())
415+
color_2 = Graph::rgb(rgb[3], rgb[4], rgb[5]);
416+
}
417+
379418
x = eigparser.getPath();
380419
std::list<std::vector<unsigned>> &projectionsColor = config.rgb;
381420
for ( unsigned iband = ignore ; iband < eigparser.getNband() ; ++iband ) {
382421
y.push_back(eigparser.getBand(iband,fermi,1));
383422
if ( projection )
384423
projectionsColor.push_back(eigparser.getBandColor(iband,1,projectionUMask));
385-
colors.push_back(Graph::rgb(0,0,0));
424+
colors.push_back(color_1);
386425
labels.push_back("");
387426
}
388427
if ( eigparser.isPolarized() ) {
@@ -392,7 +431,7 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G
392431
y.push_back(eigparser.getBand(iband,fermi,2));
393432
if ( projection )
394433
projectionsColor.push_back(eigparser.getBandColor(iband,2,projectionUMask));
395-
colors.push_back(Graph::rgb(255,0,0));
434+
colors.push_back(color_2);
396435
labels.push_back("");
397436
}
398437
labels.pop_back();
@@ -431,12 +470,13 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G
431470
throw EXCEPTION("Number of ndiv not compatible with number of labels: "+tmp.str(),ERRDIV);
432471
}
433472
}
434-
if ( save == Graph::GraphSave::DATA ) {
473+
auto save = config.save;
474+
if (config.save == Graph::GraphSave::DATA) {
435475
eigparser.dump(filename+".dat",EigParser::PRTKPT|EigParser::PRTIKPT|(projection ? EigParser::PRTPROJ : 0));
436-
save = Graph::GraphSave::NONE;
476+
config.save = Graph::GraphSave::NONE;
437477
}
478+
Graph::plot(config, gplot);
438479
config.save = save;
439-
Graph::plot(config,gplot);
440480
if ( gplot != nullptr )
441481
gplot->clearCustom();
442482
}

0 commit comments

Comments
 (0)