31#include <rapidxml.hpp> 
   33namespace pseudopotential {
 
   35class qso : 
public pseudopotential::base {
 
   39      : file_(filename.c_str()),
 
   40        buffer_((std::istreambuf_iterator<char>(file_)),
 
   41                std::istreambuf_iterator<char>()) {
 
   45    buffer_.push_back(
'\0');
 
   46    doc_.parse<0>(&buffer_[0]);
 
   48    root_node_ = doc_.first_node(
"fpmd:species");
 
   51      root_node_ = doc_.first_node(
"qbox:species");
 
   53      throw status::FORMAT_NOT_SUPPORTED;
 
   55    pseudo_node_ = root_node_->first_node(
"ultrasoft_pseudopotential");
 
   57      type_ = pseudopotential::type::ULTRASOFT;
 
   61          root_node_->first_node(
"norm_conserving_semilocal_pseudopotential");
 
   63        type_ = pseudopotential::type::KLEINMAN_BYLANDER;
 
   67      pseudo_node_ = root_node_->first_node(
"norm_conserving_pseudopotential");
 
   69        type_ = pseudopotential::type::SEMILOCAL;
 
   76    if (pseudo_node_->first_node(
"lmax")) {
 
   77      lmax_ = value<int>(pseudo_node_->first_node(
"lmax"));
 
   79      for (
int l = 0; 
l <= MAX_L; 
l++) {
 
   80        if (!has_projectors(
l)) {
 
   87    assert(lmax_ < MAX_L);
 
   90  pseudopotential::format format()
 const {
 
   91    return pseudopotential::format::QSO;
 
   94  int size()
 const { 
return buffer_.size(); };
 
   97    return root_node_->first_node(
"description")->value();
 
  101    return element::trim(root_node_->first_node(
"symbol")->value());
 
  104  int atomic_number()
 const {
 
  105    return value<int>(root_node_->first_node(
"atomic_number"));
 
  108  double mass()
 const { 
return value<double>(root_node_->first_node(
"mass")); }
 
  110  double valence_charge()
 const {
 
  111    return value<double>(pseudo_node_->first_node(
"valence_charge"));
 
  115    if (pseudo_node_->first_node(
"llocal")) {
 
  116      return value<int>(pseudo_node_->first_node(
"llocal"));
 
  122  int nchannels()
 const {
 
  123    if (type_ == pseudopotential::type::ULTRASOFT) {
 
  126      assert(np % nl == 0);
 
  129    if (type_ == pseudopotential::type::KLEINMAN_BYLANDER)
 
  134  int nquad()
 const { 
return value<int>(pseudo_node_->first_node(
"nquad")); }
 
  136  double rquad()
 const {
 
  137    return value<double>(pseudo_node_->first_node(
"rquad"));
 
  140  double mesh_spacing()
 const {
 
  141    return value<double>(pseudo_node_->first_node(
"mesh_spacing"));
 
  144  int mesh_size()
 const {
 
  145    rapidxml::xml_node<> *node =
 
  146        pseudo_node_->first_node(
"local_potential"); 
 
  148      node = pseudo_node_->first_node(
"vlocal"); 
 
  150      node = pseudo_node_->first_node(
"projector"); 
 
  152    return value<int>(node->first_attribute(
"size"));
 
  155  void local_potential(std::vector<double> &potential)
 const {
 
  156    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"local_potential");
 
  159      node = pseudo_node_->first_node(
"vlocal");
 
  162    int size = value<int>(node->first_attribute(
"size"));
 
  163    potential.resize(size);
 
  164    std::istringstream stst(node->value());
 
  165    for (
int ii = 0; ii < size; ii++) {
 
  166      stst >> potential[ii];
 
  170  int nprojectors()
 const {
 
  172    case pseudopotential::type::ULTRASOFT:
 
  174    case pseudopotential::type::KLEINMAN_BYLANDER: {
 
  176      rapidxml::xml_node<> *node = pseudo_node_->first_node(
"projector");
 
  179        node = node->next_sibling(
"projector");
 
  183    case pseudopotential::type::SEMILOCAL:
 
  189  int nprojectors_per_l(
int l)
 const {
 
  191    case pseudopotential::type::ULTRASOFT:
 
  192      return nbeta() / ( lmax() + 1);
 
  193    case pseudopotential::type::KLEINMAN_BYLANDER: {
 
  195      rapidxml::xml_node<> *node = pseudo_node_->first_node(
"projector");
 
  198        int read_l = value<int>(node->first_attribute(
"l"));
 
  201        node = node->next_sibling(
"projector");
 
  205    case pseudopotential::type::SEMILOCAL: {
 
  207      rapidxml::xml_node<> *node = pseudo_node_->first_node(
"projector");
 
  210        int read_l = value<int>(node->first_attribute(
"l"));
 
  213        node = node->next_sibling(
"projector");
 
  223  void projector(
int l, 
int i, std::vector<double> &proj)
 const {
 
  227    rapidxml::xml_node<> *node = pseudo_node_->first_node(tag.c_str());
 
  230      int read_l = value<int>(node->first_attribute(
"l"));
 
  231      int read_i = value<int>(node->first_attribute(
"i")) - 1;
 
  232      if (
l == read_l && 
i == read_i)
 
  234      node = node->next_sibling(tag.c_str());
 
  237    assert(node != NULL);
 
  239    int size = value<int>(node->first_attribute(
"size"));
 
  241    std::istringstream stst(node->value());
 
  242    for (
int ii = 0; ii < size; ii++)
 
  246  double d_ij(
int l, 
int i, 
int j)
 const {
 
  247    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"d_ij");
 
  250      int read_l = value<int>(node->first_attribute(
"l"));
 
  251      int read_i = value<int>(node->first_attribute(
"i")) - 1;
 
  252      int read_j = value<int>(node->first_attribute(
"j")) - 1;
 
  253      if (
l == read_l && 
i == read_i && 
j == read_j)
 
  255      node = node->next_sibling(
"d_ij");
 
  258    assert(node != NULL);
 
  260    return value<double>(node);
 
  263  bool has_radial_function(
int l)
 const {
 
  264    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"projector");
 
  267      int read_l = value<int>(node->first_attribute(
"l"));
 
  270      node = node->next_sibling(
"projector");
 
  273    return node->first_node(
"radial_function") != NULL;
 
  276  void radial_function(
int l, std::vector<double> &function)
 const {
 
  277    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"projector");
 
  280      int read_l = value<int>(node->first_attribute(
"l"));
 
  283      node = node->next_sibling(
"projector");
 
  286    assert(node != NULL);
 
  287    assert(node->first_node(
"radial_function"));
 
  289    int size = value<int>(node->first_attribute(
"size"));
 
  290    function.resize(size);
 
  291    std::istringstream stst(node->first_node(
"radial_function")->value());
 
  292    for (
int ii = 0; ii < size; ii++) {
 
  293      stst >> function[ii];
 
  297  void radial_potential(
int l, std::vector<double> &function)
 const {
 
  298    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"projector");
 
  301      int read_l = value<int>(node->first_attribute(
"l"));
 
  304      node = node->next_sibling(
"projector");
 
  307    assert(node != NULL);
 
  308    assert(node->first_node(
"radial_potential"));
 
  310    int size = value<int>(node->first_attribute(
"size"));
 
  311    function.resize(size);
 
  312    std::istringstream stst(node->first_node(
"radial_potential")->value());
 
  313    for (
int ii = 0; ii < size; ii++) {
 
  314      stst >> function[ii];
 
  318  bool has_nlcc()
 const { 
return pseudo_node_->first_node(
"rho_nlcc"); }
 
  320  void nlcc_density(std::vector<double> &
density)
 const {
 
  321    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"rho_nlcc");
 
  323    int size = value<int>(node->first_attribute(
"size"));
 
  325    std::istringstream stst(node->value());
 
  326    for (
int ii = 0; ii < size; ii++) {
 
  331  void beta(
int index, 
int &
l, std::vector<double> &proj)
 const {
 
  332    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"beta");
 
  335      node = node->next_sibling(
"beta");
 
  337    assert(node != NULL);
 
  339    l = value<int>(node->first_attribute(
"l"));
 
  340    int size = value<int>(node->first_attribute(
"size"));
 
  342    std::istringstream stst(node->value());
 
  343    for (
int ii = 0; ii < size; ii++) {
 
  348  void dnm_zero(
int nbeta, std::vector<std::vector<double>> &dnm)
 const {
 
  349    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"dnm_zero");
 
  350    std::istringstream stst(node->value());
 
  353    for (
int i = 0; 
i < nbeta; 
i++) {
 
  354      dnm[
i].resize(nbeta);
 
  355      for (
int j = 0; 
j < nbeta; 
j++) {
 
  361  bool has_rinner()
 const {
 
  362    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"rinner");
 
  366  void rinner(std::vector<double> &val)
 const {
 
  367    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"rinner");
 
  369    assert(node != NULL);
 
  371    int size = value<int>(node->first_attribute(
"size"));
 
  373    std::istringstream stst(node->value());
 
  374    for (
int ii = 0; ii < size; ii++) {
 
  379  void qnm(
int index, 
int &l1, 
int &l2, 
int &n, 
int &m,
 
  380           std::vector<double> &val)
 const {
 
  381    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"qnm");
 
  384      node = node->next_sibling(
"qnm");
 
  386    assert(node != NULL);
 
  388    n = value<int>(node->first_attribute(
"n"));
 
  389    m = value<int>(node->first_attribute(
"m"));
 
  390    l1 = value<int>(node->first_attribute(
"l1"));
 
  391    l2 = value<int>(node->first_attribute(
"l2"));
 
  393    int size = value<int>(node->first_attribute(
"size"));
 
  395    std::istringstream stst(node->value());
 
  396    for (
int ii = 0; ii < size; ii++) {
 
  401  void qfcoeff(
int index, 
int ltot, std::vector<double> &val)
 const {
 
  402    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"qfcoeff");
 
  405      int read_index = value<int>(node->first_attribute(
"i"));
 
  406      int read_ltot = value<int>(node->first_attribute(
"ltot"));
 
  407      if (read_index == 
index && read_ltot == ltot)
 
  409      node = node->next_sibling(
"qfcoeff");
 
  412    assert(node != NULL);
 
  414    int size = value<int>(node->first_attribute(
"size"));
 
  416    std::istringstream stst(node->value());
 
  417    for (
int ii = 0; ii < size; ii++) {
 
  423  bool has_projectors(
int l)
 const {
 
  424    rapidxml::xml_node<> *node = pseudo_node_->first_node(
"projector");
 
  426      int read_l = value<int>(node->first_attribute(
"l"));
 
  429      node = node->next_sibling(
"projector");
 
  434  int nbeta()
 const { 
return value<int>(pseudo_node_->first_node(
"nbeta")); }
 
  437  std::vector<char> buffer_;
 
  438  rapidxml::xml_document<> doc_;
 
  439  rapidxml::xml_node<> *root_node_;
 
  440  rapidxml::xml_node<> *pseudo_node_;
 
if write to the Free Software Franklin Fifth USA !If the compiler accepts long Fortran it is better to use that and build all the preprocessor definitions in one line In !this the debuggers will provide the right line numbers !If the compiler accepts line number then CARDINAL and ACARDINAL !will put them just a new line or a ampersand plus a new line !These macros should be used in macros that span several lines They should by !put immedialty before a line where a compilation error might occur and at the !end of the macro !Note that the cardinal and newline words are substituted by the program !preprocess pl by the ampersand and by a real new line just before compilation !The assertions are ignored if the code is compiled in not debug when !prints out the assertion string
 
integer, parameter, public density
 
integer, parameter, public mass
 
const int *restrict index