Skip to content

Commit

Permalink
Bugfix: phono3py, if run with QE, uses distances in Bohr, while with …
Browse files Browse the repository at this point in the history
…VASP uses Angstroms. Now the phono(3)py parsers take that into account.
  • Loading branch information
cepellotti committed Nov 11, 2021
1 parent 3a1fc5b commit 1ee027e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
39 changes: 36 additions & 3 deletions src/parser/ifc3_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,39 @@ Interaction3Ph IFC3Parser::parseFromPhono3py(Context &context,
// set up so that the first nAtoms*dimSup of the superCell are unit cell
// atom #1, and the second nAtoms*dimSup are atom #2, and so on.



// First, we open the phonopyDispFileName to check the distance units.
// Phono3py uses Bohr for QE calculations and Angstrom for VASP
// so, here we decide which is the correct unit,
// by parsing the phono3py_disp.yaml file
double distanceConversion = 1. / distanceBohrToAng;
{
std::string fileName = context.getPhonopyDispFileName();
std::ifstream infile;
if (fileName.empty()) {
Error("Phono3py parser required file phonopyDispFileName "
"(phonon3py_disp.yaml) not specified in input file.");
}
infile.open(fileName);
if (not infile.is_open()) {
Error("Phono3py parser couldn't open the file (phono3py_disp.yaml)");
}
if (mpi->mpiHead())
std::cout << "Reading in " + fileName << std::endl;

std::string line;
while (std::getline(infile, line)) {
if (line.find("length") != std::string::npos) {
if (line.find("au") != std::string::npos) {
distanceConversion = 1.; // distances already in Bohr
break;
}
}
}
infile.close();
}

// First, read in the information form disp_fc3.yaml
int numAtoms = crystal.getNumAtoms();

Expand Down Expand Up @@ -437,12 +470,12 @@ Interaction3Ph IFC3Parser::parseFromPhono3py(Context &context,
std::string temp = line.substr(5, 62);// just the elements
int idx1 = temp.find(',');
lattice(iLattice, 0) =
std::stod(temp.substr(0, idx1)) / distanceBohrToAng;
std::stod(temp.substr(0, idx1)) * distanceConversion;
int idx2 = temp.find(',', idx1 + 1);
lattice(iLattice, 1) =
std::stod(temp.substr(idx1 + 1, idx2)) / distanceBohrToAng;
std::stod(temp.substr(idx1 + 1, idx2)) * distanceConversion;
lattice(iLattice, 2) =
std::stod(temp.substr(idx2 + 1)) / distanceBohrToAng;
std::stod(temp.substr(idx2 + 1)) * distanceConversion;
iLattice++;
}
if (line.find("lattice:") != std::string::npos) {
Expand Down
27 changes: 19 additions & 8 deletions src/parser/phonopy_input_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ std::tuple<Crystal, PhononH0> PhonopyParser::parsePhHarmonic(Context &context) {
// If both superCells were the same, both are written to disp_fc3.yaml,
// and disp_fc2.yaml will not have been created.

double distanceConversion = 1. / distanceBohrToAng;

// open input file
auto fileName = context.getDispFC2FileName();
std::ifstream infile(fileName);
Expand Down Expand Up @@ -104,12 +106,12 @@ std::tuple<Crystal, PhononH0> PhonopyParser::parsePhHarmonic(Context &context) {
std::string temp = line.substr(5, 62); // just the elements
int idx1 = temp.find(',');
supLattice(ilatt, 0) =
std::stod(temp.substr(0, idx1)) / distanceBohrToAng;
std::stod(temp.substr(0, idx1));
int idx2 = temp.find(',', idx1 + 1);
supLattice(ilatt, 1) =
std::stod(temp.substr(idx1 + 1, idx2)) / distanceBohrToAng;
std::stod(temp.substr(idx1 + 1, idx2));
supLattice(ilatt, 2) =
std::stod(temp.substr(idx2 + 1)) / distanceBohrToAng;
std::stod(temp.substr(idx2 + 1));
ilatt++;
}
if (line.find("lattice:") != std::string::npos) {
Expand Down Expand Up @@ -145,8 +147,7 @@ std::tuple<Crystal, PhononH0> PhonopyParser::parsePhHarmonic(Context &context) {
// we have to do this first, because we need to use this info
// to allocate the below data storage.
Eigen::Vector3i qCoarseGrid;
while (infile) {
getline(infile, line);
while (std::getline(infile, line)) {

// In the case where force constants where generated with different
// superCells for fc2 and fc3, the label we need is dim_fc2.
Expand Down Expand Up @@ -231,12 +232,12 @@ std::tuple<Crystal, PhononH0> PhonopyParser::parsePhHarmonic(Context &context) {
std::string temp = line.substr(9, 67); // just the elements
int idx1 = temp.find(',');
directUnitCell(ilatt, 0) =
std::stod(temp.substr(0, idx1)) / distanceBohrToAng;
std::stod(temp.substr(0, idx1));
int idx2 = temp.find(',', idx1 + 1);
directUnitCell(ilatt, 1) =
std::stod(temp.substr(idx1 + 1, idx2)) / distanceBohrToAng;
std::stod(temp.substr(idx1 + 1, idx2));
directUnitCell(ilatt, 2) =
std::stod(temp.substr(idx2 + 1, temp.find(']'))) / distanceBohrToAng;
std::stod(temp.substr(idx2 + 1, temp.find(']')));
ilatt++;
}
if (line.find("lattice:") != std::string::npos) {
Expand All @@ -246,9 +247,19 @@ std::tuple<Crystal, PhononH0> PhonopyParser::parsePhHarmonic(Context &context) {
if (line.find("reciprocal_lattice:") != std::string::npos) {
break;
}

if (line.find("length") != std::string::npos) {
if (line.find("au") != std::string::npos) {
distanceConversion = 1.; // distances already in Bohr
}
}
}
infile.close();

// convert distances to Bohr
supLattice *= distanceConversion;
directUnitCell *= distanceConversion;

// Process the information that has been read in
// =================================================
// calculate species mass values (in Ry) for later use
Expand Down

0 comments on commit 1ee027e

Please sign in to comment.