Skip to content

Commit 7388d31

Browse files
author
Jordan Bieder
committed
Patch error with qpoints.yaml files from phonopy
TODO: Fix equivalent atoms in BORN file
1 parent 5aa1302 commit 7388d31

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

src/canvas/canvasphonons.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ bool CanvasPhonons::readDdb(const std::string& filename) {
161161
* we can assume this is true. The user should know what he does.
162162
* We cannot do in an other way since qpoints.yaml does not always provide
163163
* the structure (1.10 at least does not)
164-
*/
165164
if ( !(*_ddb==_reference) )
166165
throw EXCEPTION("It seems reference and DDB are different structures",ERRDIV);
166+
*/
167167
_ddb->buildFrom(_reference);
168168
DispDB disp;
169169
try {

src/io/ddb.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,8 @@ geometry::mat3d Ddb::getZeff(const unsigned iatom) const {
199199
throw EXCEPTION("Atom "+utils::to_string(iatom)+" is not in DDB", ERRDIV);
200200

201201
auto data = this->getDdb(qpt);
202-
mat3d zeff;
203-
mat3d count;
204-
for ( auto &e : count ) e = 0e0;
205-
for ( auto &e : zeff ) e = 0e0;
202+
mat3d zeff = {0};
203+
mat3d count = {0};
206204
const double twopi = 2*phys::pi;
207205

208206
/* Read values from ddb into _zeff*/
@@ -383,6 +381,20 @@ void Ddb::setZeff(const unsigned iatom, const geometry::mat3d &zeff) {
383381
mat3d rprimTranspose = transpose(_rprim);
384382
geometry::mat3d d2red = (rprimTranspose * (zeff * _gprim))*twopi;
385383

384+
for ( int i = 0 ; i < 2 ; ++i ) {
385+
for ( unsigned idir1 = 0 ; idir1 < 3 ; ++idir1 ) {
386+
for ( unsigned idir2 = 0 ; idir2 < 3 ; ++idir2 ) {
387+
auto alreadyIn = std::find_if(block.begin(),block.end(),[=](
388+
const std::pair<std::array<unsigned,4>,std::complex<double>>& entry) {
389+
auto& array = entry.first;
390+
return ( array[0] == idir1 && array[1] ==(_natom+1) && array[2] == idir2 && array[3]==iatom) ||
391+
( array[0] == idir2 && array[1] ==iatom && array[2] == idir1 && array[3]==(_natom+1));
392+
});
393+
if ( alreadyIn != block.end() ) block.erase(alreadyIn);
394+
}
395+
}
396+
}
397+
386398
for ( unsigned idir1 = 0 ; idir1 < 3 ; ++idir1 )
387399
for ( unsigned idir2 = 0 ; idir2 < 3 ; ++idir2 ) {
388400
block.push_back(

src/io/ddbphonopy.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void DdbPhonopy::readFromFile(const std::string& filename) {
118118
std::string bornfile = utils::dirname(filename)+"/BORN";
119119
std::ifstream born(bornfile);
120120
if ( born ) {
121-
_zion.resize(_typat.size());
121+
_zion.resize(_typat.size(),0);
122122
unsigned iline = 0;
123123
std::string line;
124124
utils::getline(born,line,iline); // First line is an conversion factor eventually.
@@ -161,15 +161,16 @@ void DdbPhonopy::buildFrom(const Dtset& dtset) {
161161
break;
162162
}
163163
}
164-
if ( currentZ.size() != _natom ) {
165-
throw EXCEPTION("Number of Zeff is smaller than natom is not supported yet",ERRDIV);
164+
if ( currentZ.size() > 0 && currentZ.size() != _natom ) {
165+
auto e = EXCEPTION("Number of Zeff is smaller than natom is not supported yet",ERRWAR);
166+
std::clog << e.fullWhat() << std::endl;
166167
#ifdef HAVE_SPGLIB
167168
SpglibDataset* spgDtset = this->getSpgDtset(0.001*phys::A2b);
168169
if ( spgDtset != nullptr ) {
169-
unsigned prevAtom = 0;
170+
const geometry::mat3d zero = {0};
170171
for ( unsigned iatom = 0, izeff=0; iatom < _natom; ++iatom ) {
171172
unsigned eqatom = static_cast<unsigned>(spgDtset->equivalent_atoms[iatom]);
172-
this->setZeff(iatom,eqatom == prevAtom ? currentZ[izeff] : currentZ[++izeff]);
173+
this->setZeff(iatom,(iatom == eqatom ? currentZ[izeff++]:zero));
173174
}
174175
}
175176
spg_free_dataset(spgDtset);

src/io/procar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void Procar::readFromFile(const std::string& filename) {
7070
std::getline(procar,tmp,':');
7171
procar >> natom;
7272

73-
if ( procar.eof() ) break;
73+
if ( procar && procar.eof() ) break;
7474
if ( !procar )
7575
throw EXCEPTION("Cannot read properly the parameters",ERRDIV);
7676

0 commit comments

Comments
 (0)