Skip to content

Commit

Permalink
Add hold functionnality to plot band.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jordan Bieder committed Jun 1, 2021
1 parent 7bd5df3 commit 076dbfc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 35 deletions.
20 changes: 2 additions & 18 deletions include/plot/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 55 additions & 15 deletions src/plot/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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<double> &x = config.x;
std::list<std::vector<double>> &y = config.y;
std::list<std::string> &labels = config.labels;
Expand All @@ -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;
Expand Down Expand Up @@ -318,19 +344,24 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G
std::vector<unsigned> 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<unsigned>("fatband",eigparser.getNband());
}
catch ( Exception &e ) {
if ( e.getReturnValue() & ConfigParser::ERDIM ) {
auto blabla = e.what("",true);
projectionUMask =
parser.getToken<unsigned>("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<unsigned>("fatband",maxToRead);
projectionUMask = parser.getToken<unsigned>("fatband", maxToRead);
}
}
}
Expand Down Expand Up @@ -376,13 +407,21 @@ void Graph::plotBand(EigParser &eigparser, ConfigParser &parser, Graph* gplot, G
eeig = nullptr;
}

if (parser.hasToken("color")) {
std::vector<unsigned> rgb =
parser.getToken<unsigned>("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<std::vector<unsigned>> &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() ) {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 076dbfc

Please sign in to comment.