| 1 |
/******************************************************************************* |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
*******************************************************************************/ |
| 5 |
|
| 6 |
#include <QDebug> |
| 7 |
#include <QStringList> |
| 8 |
|
| 9 |
#include <avogadro/core/avospglib.h> |
| 10 |
#include <avogadro/core/molecule.h> |
| 11 |
#include <avogadro/core/spacegroups.h> |
| 12 |
#include <avogadro/core/unitcell.h> |
| 13 |
#include <avogadro/core/vector.h> |
| 14 |
|
| 15 |
#include "specialkpoints.h" |
| 16 |
#include "specialkpointsdata.h" |
| 17 |
|
| 18 |
using Avogadro::Vector3; |
| 19 |
using Avogadro::Core::AvoSpglib; |
| 20 |
using Avogadro::Core::Molecule; |
| 21 |
using Avogadro::Core::SpaceGroups; |
| 22 |
using Avogadro::Core::UnitCell; |
| 23 |
|
| 24 |
namespace Avogadro::QtPlugins { |
| 25 |
|
| 26 |
QString SpecialKPoints::getSpecialKPoints(Molecule& mol) |
| 27 |
{ |
| 28 |
UnitCell* cell = mol.unitCell(); |
| 29 |
if (cell) { |
| 30 |
// Check to see if the space group is set. |
| 31 |
unsigned short hallNumber = mol.hallNumber(); |
| 32 |
// Try to find the space group if it is not set |
| 33 |
if (!hallNumber) { |
| 34 |
hallNumber = AvoSpglib::getHallNumber(mol); |
| 35 |
// If we still can't find the hall number, just return |
| 36 |
if (!hallNumber) |
| 37 |
return QString(); |
| 38 |
} |
| 39 |
|
| 40 |
unsigned short spgNum = SpaceGroups::internationalNumber(hallNumber); |
| 41 |
if (spgNum != 0 && spgNum < 231) { |
| 42 |
QString specialKPoints = special_k_points[spgNum]; |
| 43 |
if (specialKPoints.contains("#")) |
| 44 |
processConditionKPoints(specialKPoints, mol, spgNum); |
| 45 |
return specialKPoints.replace(',', '\n'); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
// If we made it here, we failed |
| 50 |
return QString(); |
| 51 |
} |
| 52 |
|
| 53 |
void SpecialKPoints::processConditionKPoints(QString& specialKPoints, |
| 54 |
Molecule& mol, |
| 55 |
unsigned short spgNum) |
| 56 |
{ |
| 57 |
// Check to see if the space group is set. |
| 58 |
UnitCell* cell = mol.unitCell(); |
| 59 |
|
| 60 |
if (!cell) { |
| 61 |
qDebug() << "Error in " << __FUNCTION__ << ": cell is NULL!"; |
| 62 |
specialKPoints = ""; |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
// Ensure the space group number is valid |
| 67 |
if (spgNum == 0 || spgNum > 230) { |
| 68 |
qDebug() << "Error in " << __FUNCTION__ << ": spg is invalid!"; |
| 69 |
specialKPoints = ""; |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
QStringList stringSplit = specialKPoints.split("#"); |
| 74 |
|
| 75 |
switch (spgNum) { |
| 76 |
// a > b or a < b |
| 77 |
case 20: |
| 78 |
case 21: |
| 79 |
case 35: |
| 80 |
case 36: |
| 81 |
case 37: |
| 82 |
case 38: |
| 83 |
case 39: |
| 84 |
case 40: |
| 85 |
case 41: |
| 86 |
case 63: |
| 87 |
case 64: |
| 88 |
case 65: |
| 89 |
case 66: |
| 90 |
case 67: |
| 91 |
case 68: { |
| 92 |
if (stringSplit.size() != 2) { |
| 93 |
qDebug() << "Error in " << __FUNCTION__ << ": for spgNum " |
| 94 |
<< QString::number(spgNum) << ", size is not correct!"; |
| 95 |
specialKPoints = ""; |
| 96 |
} else { |
| 97 |
unsigned short ind = 0; |
| 98 |
// a > b? |
| 99 |
if (cell->a() >= cell->b()) |
| 100 |
ind = 0; |
| 101 |
else |
| 102 |
ind = 1; |
| 103 |
specialKPoints = stringSplit[ind]; |
| 104 |
} |
| 105 |
return; |
| 106 |
} |
| 107 |
// a^-2 > b^-2 + c^-2, c^-2 > a^-2 + b^-2, or other |
| 108 |
case 22: |
| 109 |
case 42: |
| 110 |
case 43: |
| 111 |
case 69: |
| 112 |
case 70: { |
| 113 |
if (stringSplit.size() != 3) { |
| 114 |
qDebug() << "Error in " << __FUNCTION__ << ": for spgNum " |
| 115 |
<< QString::number(spgNum) << ", size is not correct!"; |
| 116 |
specialKPoints = ""; |
| 117 |
} else { |
| 118 |
unsigned short ind = 0; |
| 119 |
double a = cell->a(); |
| 120 |
double b = cell->b(); |
| 121 |
double c = cell->c(); |
| 122 |
if (pow(a, -2.0) >= pow(b, -2.0) + pow(c, -2.0)) |
| 123 |
ind = 0; |
| 124 |
else if (pow(c, -2.0) >= pow(a, -2.0) + pow(b, -2.0)) |
| 125 |
ind = 1; |
| 126 |
else |
| 127 |
ind = 2; |
| 128 |
specialKPoints = stringSplit[ind]; |
| 129 |
} |
| 130 |
return; |
| 131 |
} |
| 132 |
// (b > a > c or b > c > a) or other |
| 133 |
case 23: |
| 134 |
case 24: |
| 135 |
case 44: |
| 136 |
case 45: |
| 137 |
case 46: |
| 138 |
case 71: |
| 139 |
case 72: |
| 140 |
case 73: |
| 141 |
case 74: { |
| 142 |
if (stringSplit.size() != 2) { |
| 143 |
qDebug() << "Error in " << __FUNCTION__ << ": for spgNum " |
| 144 |
<< QString::number(spgNum) << ", size is not correct!"; |
| 145 |
specialKPoints = ""; |
| 146 |
} else { |
| 147 |
unsigned short ind = 0; |
| 148 |
double a = cell->a(); |
| 149 |
double b = cell->b(); |
| 150 |
double c = cell->c(); |
| 151 |
if ((b >= a && a >= c) || (b >= c && c >= a)) |
| 152 |
ind = 0; |
| 153 |
else |
| 154 |
ind = 1; |
| 155 |
specialKPoints = stringSplit[ind]; |
| 156 |
} |
| 157 |
return; |
| 158 |
} |
| 159 |
// c/a > 1 or other |
| 160 |
case 79: |
| 161 |
case 80: |
| 162 |
case 82: |
| 163 |
case 87: |
| 164 |
case 88: |
| 165 |
case 97: |
| 166 |
case 98: |
| 167 |
case 107: |
| 168 |
case 108: |
| 169 |
case 109: |
| 170 |
case 110: |
| 171 |
case 119: |
| 172 |
case 120: |
| 173 |
case 121: |
| 174 |
case 122: |
| 175 |
case 139: |
| 176 |
case 140: |
| 177 |
case 141: |
| 178 |
case 142: { |
| 179 |
if (stringSplit.size() != 2) { |
| 180 |
qDebug() << "Error in " << __FUNCTION__ << ": for spgNum " |
| 181 |
<< QString::number(spgNum) << ", size is not correct!"; |
| 182 |
specialKPoints = ""; |
| 183 |
} else { |
| 184 |
unsigned short ind = 0; |
| 185 |
if (cell->c() / cell->a() >= 1) |
| 186 |
ind = 0; |
| 187 |
else |
| 188 |
ind = 1; |
| 189 |
specialKPoints = stringSplit[ind]; |
| 190 |
} |
| 191 |
return; |
| 192 |
} |
| 193 |
// sqrt3a > sqrt2c or other |
| 194 |
case 146: |
| 195 |
case 148: |
| 196 |
case 155: |
| 197 |
case 160: |
| 198 |
case 161: |
| 199 |
case 166: |
| 200 |
case 167: { |
| 201 |
if (stringSplit.size() != 2) { |
| 202 |
qDebug() << "Error in " << __FUNCTION__ << ": for spgNum " |
| 203 |
<< QString::number(spgNum) << ", size is not correct!"; |
| 204 |
specialKPoints = ""; |
| 205 |
} else { |
| 206 |
unsigned short ind = 0; |
| 207 |
if (sqrt(3.0 * cell->a()) >= sqrt(2.0 * cell->c())) |
| 208 |
ind = 0; |
| 209 |
else |
| 210 |
ind = 1; |
| 211 |
specialKPoints = stringSplit[ind]; |
| 212 |
} |
| 213 |
return; |
| 214 |
} |
| 215 |
// This shouldn't happen |
| 216 |
default: { |
| 217 |
qDebug() << "Error in" << __FUNCTION__ << ": failed to process spg " |
| 218 |
<< QString::number(spgNum); |
| 219 |
specialKPoints = ""; |
| 220 |
return; |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
} // namespace Avogadro::QtPlugins |