Skip to content

Commit

Permalink
Merged in ReadPSwfc (pull request #533)
Browse files Browse the repository at this point in the history
Reading and Saving the PSWFC data from upf to scratch

Approved-by: Vishal Subramanian
Approved-by: Sambit Das
  • Loading branch information
kartickr authored and dsambit committed Aug 13, 2023
2 parents ca4e625 + 4a5d8a0 commit fad7459
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/xmlTodftfeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace dftfe
std::vector<std::string> mesh;
std::vector<std::tuple<size_t, size_t, std::vector<std::string>>>
projectors;
std::vector<std::tuple<size_t, std::string, std::vector<std::string>>>
PSwfc;

std::vector<std::tuple<size_t, size_t, size_t, double>> d_ij;

std::ofstream loc_pot;
Expand Down
85 changes: 82 additions & 3 deletions pseudoConverters/upfToxml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ namespace dftfe
// std::cerr << " upf_mesh_size = " << upf_mesh_size << std::endl;

// number of wavefunctions
int upf_nwf;
int upf_nwfc;
buf = get_attr(tag, "number_of_wfc");
is.clear();
is.str(buf);
is >> upf_nwf;
is >> upf_nwfc;
// std::cerr << " upf_nwf = " << upf_nwf << std::endl;

// number of projectors
Expand All @@ -311,9 +311,12 @@ namespace dftfe
is.clear();
is.str(buf);
is >> upf_nproj;



// std::cerr << " upf_nproj = " << upf_nproj << std::endl;

std::vector<int> upf_l(upf_nwf);
//std::vector<int> upf_l(upf_nwfc);

// read mesh
find_start_element("PP_MESH", upfFile);
Expand Down Expand Up @@ -428,6 +431,62 @@ namespace dftfe

find_end_element("PP_NONLOCAL", upfFile);



find_start_element("PP_PSWFC", upfFile);
std::vector<std::vector<double>> upf_pswfcdata;
upf_pswfcdata.resize(upf_nwfc);
std::vector<int> upf_wfc_l(upf_nwfc);
std::vector<std::string> upf_wfc_orbital(upf_nwfc);
int upf_lwfcmax=0;
for (int j = 0; j < upf_nwfc; j++)
{
int index, angular_momentum;
std::string orbital;
os.str("");
os << j + 1;
std::string element_name = "PP_CHI." + os.str();
tag = find_start_element(element_name, upfFile);
// std::cerr << tag << std::endl;

buf = get_attr(tag, "index");
is.clear();
is.str(buf);
is >> index;
// std::cerr << " index = " << index << std::endl;

buf = get_attr(tag, "l");
is.clear();
is.str(buf);
is >> angular_momentum;
// std::cerr << " angular_momentum = " << angular_momentum <<
// std::endl;
buf = get_attr(tag, "label");
is.clear();
is.str(buf);
is >> orbital;
upf_lwfcmax = std::max(upf_lwfcmax,angular_momentum);
upf_wfc_l[index - 1] = angular_momentum;
upf_wfc_orbital[index - 1] = orbital;
upf_pswfcdata[j].resize(upf_mesh_size);
for (int i = 0; i < upf_mesh_size; i++)
upfFile >> upf_pswfcdata[j][i];

find_end_element(element_name, upfFile);
}

// compute number of projectors for each l
// nproj_l[l] is the number of projectors having angular momentum l
std::vector<int> npswfc_l(upf_lwfcmax + 1);
for (int l = 0; l <= upf_lwfcmax; l++)
{
npswfc_l[l] = 0;
for (int ip = 0; ip < upf_nwfc; ip++)
if (upf_wfc_l[ip] == l)
npswfc_l[l]++;
}
find_end_element("PP_PSWFC", upfFile);

// NLCC
std::vector<double> upf_nlcc;
if (upf_nlcc_flag == "T")
Expand Down Expand Up @@ -584,6 +643,26 @@ namespace dftfe
}
}

// PSWFC
for(int iwave = 0; iwave < upf_nwfc; iwave++)
{
xmlFile << "<PSwfc i=\"" << iwave<< "\" orbital=\"" << upf_wfc_orbital[iwave]
<< "\" size=\"" << nplin << "\">" << std::endl;
int count2 = 0;
for (int j = 0; j < nplin; j++)
{
count2 += 1;
xmlFile << std::setprecision(14) << upf_pswfcdata[iwave][j]
<< " ";
if (count2 % 4 == 0)
xmlFile << std::endl;
}
xmlFile << "</PSwfc>" << std::endl;
}




// d_ij
if (pseudo_type == "NC")
{
Expand Down
93 changes: 92 additions & 1 deletion utils/xmlTodftfeParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,63 @@ namespace dftfe

projectors.push_back(projector_temp);
}
else if (xmlStrcmp(cur_node->name,
(const xmlChar *)"PSwfc") == 0)
{
std::tuple<size_t, std::string, std::vector<std::string>>
PSwfc_temp;
xmlAttr *attribute = cur_node->properties;
int counter = 0;

while (attribute != nullptr)
{
xmlChar *value =
xmlNodeListGetString(doc,
attribute->children,
1);
std::string value_str(
reinterpret_cast<char *>(value));

if (counter == 0)
std::get<0>(PSwfc_temp) = stoi(value_str);
else if (counter == 1)
std::get<1>(PSwfc_temp) = value_str;//stoi(value_str);

attribute = attribute->next;
counter++;
}

std::string PSwfc_content(
reinterpret_cast<char *>(
xmlNodeGetContent(cur_node)));

std::string::size_type n = 0;
while ((n = PSwfc_content.find(" ", n)) !=
std::string::npos)
{
PSwfc_content.replace(n, 3, ",");
n++;
}

n = PSwfc_content.find("\n,", 0);
if (n != std::string::npos)
PSwfc_content.replace(n, 2, "");

n = 0;
while ((n = PSwfc_content.find("\n", n)) !=
std::string::npos)
{
PSwfc_content.replace(n, 1, "");
n++;
}

std::istringstream ss(PSwfc_content);
std::string token;
while (std::getline(ss, token, ','))
std::get<2>(PSwfc_temp).push_back(token);

PSwfc.push_back(PSwfc_temp);
}
else if (xmlStrcmp(cur_node->name,
(const xmlChar *)"d_ij") == 0)
{
Expand Down Expand Up @@ -363,6 +420,8 @@ namespace dftfe
std::ofstream l3;
l3.open(baseOutputPath + "/" + "proj_l3.dat");



std::ofstream denom;
denom.open(baseOutputPath + "/" + "denom.dat");

Expand All @@ -377,7 +436,7 @@ namespace dftfe
l0.precision(14);
l1.precision(14);
l2.precision(14);
l3.precision(14);
l3.precision(14);
denom.precision(14);
pseudo.precision(14);

Expand All @@ -388,6 +447,10 @@ namespace dftfe
std::vector<std::vector<std::string>> l2_vec;
std::vector<std::vector<std::string>> l3_vec;

// Set up vectors for the wfc values;



double r0 = 0.000000000000;
double r1 = 0.000000000000;
double r2 = 0.000000000000;
Expand All @@ -411,6 +474,8 @@ namespace dftfe
l3_vec.push_back(std::get<2>(i));
}



// Output mesh_spacing
int jl = 0;
int jd = 0;
Expand Down Expand Up @@ -536,6 +601,14 @@ namespace dftfe
std::string file2 = "proj_l2.dat";
std::string file3 = "proj_l3.dat";

j0 = 0;
j1 = 0;
j2 = 0;
j3 = 0;




// Populate the PseudoAtomData file
int lead_no = 0;
int l0_count = 0;
Expand Down Expand Up @@ -673,6 +746,22 @@ namespace dftfe
denom << std::endl;
}

for(auto i:PSwfc)
{
std::ofstream wfc;
std::string orbital = std::get<1>(i);
wfc.open(baseOutputPath+"/"+orbital+".dat");
pseudo <<orbital+".dat"<<std::endl;
wfc.precision(14);
int k = 0;
for(auto j: std::get<2>(i))
{
wfc << std::fixed << std::setprecision(14)
<< mesh[k] /* rp*/ << " " << j << std::endl;
k++;
}
}

// Clear the vectors
mult.resize(0);
denom_vec.resize(0);
Expand All @@ -685,6 +774,7 @@ namespace dftfe
l1.close();
l2.close();
l3.close();

denom.close();
pseudo.close();
ad_file.close();
Expand All @@ -696,6 +786,7 @@ namespace dftfe
coreDensity.clear();
mesh.clear();
projectors.clear();
PSwfc.clear();
d_ij.clear();

return false;
Expand Down

0 comments on commit fad7459

Please sign in to comment.