From 076dbfce5079827e1ba6422eb2fb50c5e1c239fb Mon Sep 17 00:00:00 2001 From: Jordan Bieder Date: Tue, 1 Jun 2021 16:29:59 +0200 Subject: [PATCH] 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 --- include/plot/graph.hpp | 20 ++---------- src/canvas/canvas.cpp | 3 +- src/plot/graph.cpp | 70 +++++++++++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/include/plot/graph.hpp b/include/plot/graph.hpp index 37b17c3..c798204 100644 --- a/include/plot/graph.hpp +++ b/include/plot/graph.hpp @@ -96,23 +96,7 @@ class Graph { /** * Save a list of 15 custom colors */ - const char HTMLcolor[15][8]={ - "#505050", //Grey - "#CF009E", // line04 - "#6EC4E8", // line13 - "#FF7E2E", // line05 - "#6ECA97", // line06 - "#FA9ABA", // line07 - "#003CA6", // line03 - "#E19BDF", // line08 - "#C9910D", // line10 - "#B6BD00", // line09 - "#704B1C", // line11 - "#007852", // line12 - "#62259D", // line14 - "#FFCD00", // line01 - "#837902" // line02 - }; + static const char HTMLcolor[15][8]; public : @@ -314,7 +298,7 @@ class Graph { * @param gplot The graph to plot to. If nullptr, nothing plot but data written * @param save What to do with the calculated data : plot ? save to file ? save raw data? */ - static void plotBand(EigParser &eigparser, ConfigParser &config, Graph* gplot, Graph::GraphSave save); + static void plotBand(EigParser &eigparser, ConfigParser &config, Graph* gplot, Config& conf); /** * Function to plot DOS diff --git a/src/canvas/canvas.cpp b/src/canvas/canvas.cpp index 1e92eb9..57cb872 100644 --- a/src/canvas/canvas.cpp +++ b/src/canvas/canvas.cpp @@ -515,8 +515,7 @@ void Canvas::plot(unsigned tbegin, unsigned tend, std::istream &stream) { } } - - Graph::plotBand(*(_eigparser.get()),parser,_gplot.get(),_graphConfig.save); + Graph::plotBand(*(_eigparser.get()), parser, _gplot.get(), _graphConfig); } else if ( function == "dos" ) { DosDB db; diff --git a/src/plot/graph.cpp b/src/plot/graph.cpp index fef628b..11464e8 100644 --- a/src/plot/graph.cpp +++ b/src/plot/graph.cpp @@ -32,6 +32,24 @@ #include "io/eigparserelectrons.hpp" #include "io/electrondos.hpp" +const char Graph::HTMLcolor[15][8] = { + "#505050", // Grey + "#CF009E", // line04 + "#6EC4E8", // line13 + "#FF7E2E", // line05 + "#6ECA97", // line06 + "#FA9ABA", // line07 + "#003CA6", // line03 + "#E19BDF", // line08 + "#C9910D", // line10 + "#B6BD00", // line09 + "#704B1C", // line11 + "#007852", // line12 + "#62259D", // line14 + "#FFCD00", // line01 + "#837902" // line02 +}; + // Graph::Graph() : _xlabel(), _ylabel(), @@ -232,8 +250,8 @@ void Graph::clearCustom() { _arrows.clear(); } -void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, Graph::GraphSave save) { - Graph::Config config; +void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph *gplot, + Graph::Config &config) { std::vector &x = config.x; std::list> &y = config.y; std::list &labels = config.labels; @@ -244,6 +262,14 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G std::string &title = config.title; bool &doSumUp = config.doSumUp; + static int colorId = 0; + if (config.x.size() == 0) + colorId = 0; + auto color_1 = Graph::rgb(HTMLcolor[colorId++]); + colorId = colorId % 15; + auto color_2 = Graph::rgb(HTMLcolor[colorId++]); + colorId = colorId % 15; + if ( gplot != nullptr ) gplot->setWinTitle("Band Structure"); doSumUp = false; @@ -318,19 +344,24 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G std::vector projectionUMask; bool projection = false; if ( parser.hasToken("fatband") ) { + if (parser.hasToken("color")) { + Exception e = + EXCEPTION("fatband and color options are exclusive", ERRWAR); + std::clog << e.fullWhat() << std::endl; + } projection = true; try { - projectionUMask = parser.getToken("fatband",eigparser.getNband()); - } - catch ( Exception &e ) { - if ( e.getReturnValue() & ConfigParser::ERDIM ) { - auto blabla = e.what("",true); + projectionUMask = + parser.getToken("fatband", eigparser.getNband()); + } catch (Exception &e) { + if (e.getReturnValue() & ConfigParser::ERDIM) { + auto blabla = e.what("", true); auto pos = blabla.find("Could only read "); int maxToRead = 0; - if ( pos != std::string::npos ) { - std::istringstream sub(blabla.substr(pos+16)); + if (pos != std::string::npos) { + std::istringstream sub(blabla.substr(pos + 16)); sub >> maxToRead; - projectionUMask = parser.getToken("fatband",maxToRead); + projectionUMask = parser.getToken("fatband", maxToRead); } } } @@ -376,13 +407,21 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G eeig = nullptr; } + if (parser.hasToken("color")) { + std::vector rgb = + parser.getToken("color", eigparser.isPolarized() ? 6 : 3); + color_1 = Graph::rgb(rgb[0], rgb[1], rgb[2]); + if (eigparser.isPolarized()) + color_2 = Graph::rgb(rgb[3], rgb[4], rgb[5]); + } + x = eigparser.getPath(); std::list> &projectionsColor = config.rgb; for ( unsigned iband = ignore ; iband < eigparser.getNband() ; ++iband ) { y.push_back(eigparser.getBand(iband,fermi,1)); if ( projection ) projectionsColor.push_back(eigparser.getBandColor(iband,1,projectionUMask)); - colors.push_back(Graph::rgb(0,0,0)); + colors.push_back(color_1); labels.push_back(""); } if ( eigparser.isPolarized() ) { @@ -392,7 +431,7 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G y.push_back(eigparser.getBand(iband,fermi,2)); if ( projection ) projectionsColor.push_back(eigparser.getBandColor(iband,2,projectionUMask)); - colors.push_back(Graph::rgb(255,0,0)); + colors.push_back(color_2); labels.push_back(""); } labels.pop_back(); @@ -431,12 +470,13 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G throw EXCEPTION("Number of ndiv not compatible with number of labels: "+tmp.str(),ERRDIV); } } - if ( save == Graph::GraphSave::DATA ) { + auto save = config.save; + if (config.save == Graph::GraphSave::DATA) { eigparser.dump(filename+".dat",EigParser::PRTKPT|EigParser::PRTIKPT|(projection ? EigParser::PRTPROJ : 0)); - save = Graph::GraphSave::NONE; + config.save = Graph::GraphSave::NONE; } + Graph::plot(config, gplot); config.save = save; - Graph::plot(config,gplot); if ( gplot != nullptr ) gplot->clearCustom(); }