Skip to content

Commit

Permalink
update functions for DOS plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Bieder committed Sep 26, 2019
1 parent 9824b77 commit 5daa48e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/io/electrondos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ElectronDos {
std::vector<double> dos(SOCProj proj) const; // prtdos 5

std::vector<double> energies() const;
bool pawDecomposition() const;
};

#endif // ELECTRONDOS_HPP
2 changes: 2 additions & 0 deletions include/plot/dosdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class DosDB {

std::vector<unsigned> list() const;

void clear();

const ElectronDos& total() const;

const ElectronDos& atom(unsigned iatom) const;
Expand Down
9 changes: 8 additions & 1 deletion include/plot/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,14 @@ class Graph {
* @param B red value between 0 and 255
* @return the integer value;
*/
static unsigned rgb(unsigned R, unsigned G, unsigned B);
static unsigned rgb(unsigned R, unsigned G, unsigned B);

/**
* Convert hexa string to rgb
* @param str is a string in the HTML color form like #RRGGBB
* @return the integer value;
*/
static unsigned rgb(std::string str);

/**
* Convert R G B color to unsigned value
Expand Down
5 changes: 5 additions & 0 deletions src/io/electrondos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ std::vector<double> ElectronDos::energies() const
return _energies;
}

bool ElectronDos::pawDecomposition() const
{
return _pawDecomposition;
}

ElectronDos::ElectronDos() :
_prtdos(0),
_nsppol(1),
Expand Down
5 changes: 5 additions & 0 deletions src/plot/dosdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ std::vector<unsigned> DosDB::list() const {

}

void DosDB::clear() {
_db.clear();
_ordering.clear();
}

const ElectronDos& DosDB::total() const {
auto it = _ordering.find(0);
if ( it == _ordering.end() )
Expand Down
33 changes: 29 additions & 4 deletions src/plot/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ unsigned Graph::rgb(unsigned R, unsigned G, unsigned B) {
return 65536*R + 256*G + B;
}

unsigned Graph::rgb(std::string str) {
if ( str[0] != '#' ) return static_cast<unsigned>(-1);
else if ( str.size() != 7 ) return static_cast<unsigned>(-1);
return std::stoul(str.substr(1),nullptr,16);
}

unsigned Graph::rgb(float color[])
{
return 65536*static_cast<unsigned>(color[0]*255)
Expand Down Expand Up @@ -447,6 +453,10 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS
std::string &ylabel = config.ylabel;
std::string &title = config.title;
config.doSumUp = false;
std::array<double,2> xrange;
std::array<double,2> yrange;

parser.setSensitive(true);

title = "Density of States";
std::clog << std::endl << " -- Density of States --" << std::endl;
Expand All @@ -460,8 +470,10 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS
if ( parser.hasToken("xrange")) {
std::string range = parser.getToken<std::string>("xrange");
auto r = utils::explode(range,':');
xrange[0] = utils::parseNumber<double>(r[0]);
xrange[1] = utils::parseNumber<double>(r[1]);
if ( r.size() != 2 ) throw EXCEPTION("xrange must be like xmin:xmax",ERRDIV);
if ( gplot != nullptr ) gplot->setXRange(utils::parseNumber<double>(r[0]),utils::parseNumber<double>(r[1]));
if ( gplot != nullptr ) gplot->setXRange(xrange[0],xrange[1]);
}

if ( parser.hasToken("yrange")) {
Expand Down Expand Up @@ -508,7 +520,7 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS
pawLabel = " "+utils::toupper((const std::string)inpaw);
}

auto colorAndLabel = [](std::vector<std::string>& params, unsigned& color, std::string& label) {
auto colorAndLabel = [](std::vector<std::string>& params, unsigned& color, std::string& label, bool desaturate=false) {
color = -1;
if ( params.size() == 0 ) return;
auto it = params.begin();
Expand All @@ -519,6 +531,12 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS
unsigned G = utils::parseNumber<unsigned>(testColors[1]);
unsigned B = utils::parseNumber<unsigned>(testColors[2]);
if ( R< 256 && G < 256 && B < 256 ) {
if (desaturate) {
unsigned mean = (R+G+B)/3;
R = std::min((R+mean)/2,static_cast<unsigned>(255));
G = std::min((G+mean)/2,static_cast<unsigned>(255));
B = std::min((B+mean)/2,static_cast<unsigned>(255));
}
color = Graph::rgb(R,G,B);
params.erase(it);
break;
Expand All @@ -543,6 +561,9 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS
if (spin[ispin] == false) continue;
std::string spinLabel = (nsppol==1) ? "" :
(ispin==0 ? " Spin 1" : " Spin 2");
double factor = 1./unit;
if ( ispin==1 && parser.hasToken("updown")) {factor *= -1;}

// Total DOS
{
auto it = std::find(list.begin(),list.end(),0);
Expand Down Expand Up @@ -571,11 +592,13 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS
else throw EXCEPTION("Bad Value for soc",ERRDIV);

y.push_back(total.dos(soc));
for (auto &d : y.back()) d *= factor;
labels.push_back(label);
colors.push_back(color);
}
}
y.push_back(total.dos(ispin+1));
for (auto &d : y.back()) d *= factor;
labels.push_back("Total"+spinLabel);
colors.push_back(rgb(100,100,100)*(ispin+1));
}
Expand All @@ -589,7 +612,7 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS

unsigned color = -1;
std::string label;
colorAndLabel(params,color,label);
colorAndLabel(params,color,label,ispin==1);

unsigned iatom = static_cast<unsigned>(utils::stoi(params[0]));
auto it = std::find(list.begin(),list.end(),iatom);
Expand Down Expand Up @@ -623,7 +646,9 @@ void Graph::plotDOS(DosDB& db, ConfigParser &parser, Graph *gplot, Graph::GraphS
toPlot = dos.dos(ispin+1);
}
y.push_back(toPlot);
if ( label.empty() ) label = proj+spinLabel+pawLabel;
for (auto &d : y.back()) d *= factor;
if ( label.empty() ) label = proj+pawLabel;
label += spinLabel;
labels.push_back(label);
colors.push_back(color);
}
Expand Down

0 comments on commit 5daa48e

Please sign in to comment.