Skip to content

Commit 9e73e51

Browse files
authored
Patch v0.4.1 (#24)
* Initial commit version 0.5.0 * Writing patch 0.4.1
1 parent 15879bc commit 9e73e51

File tree

2 files changed

+2
-74
lines changed

2 files changed

+2
-74
lines changed

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
#pragma once
2222

2323
#define PROGRAM_NAME "Atom Architect"
24-
#define PROGRAM_VERSION "0.4.0"
24+
#define PROGRAM_VERSION "0.4.1"

src/data/structure_loader.cpp

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <array>
2727
#include <cmath>
2828
#include <cstdio>
29-
#include <limits>
3029

3130
namespace {
3231
/**
@@ -42,32 +41,6 @@ int leading_spaces(const std::string& value) {
4241
return count;
4342
}
4443

45-
/**
46-
* @brief sorted_mae.
47-
*
48-
* @param lhs Parameter lhs.
49-
* @param rhs Parameter rhs.
50-
*/
51-
double sorted_mae(const std::vector<double>& lhs,
52-
const std::vector<double>& rhs) {
53-
const size_t n = std::min(lhs.size(), rhs.size());
54-
if(n == 0) {
55-
return std::numeric_limits<double>::infinity();
56-
}
57-
58-
std::vector<double> a(lhs.begin(), lhs.begin() + n);
59-
std::vector<double> b(rhs.begin(), rhs.begin() + n);
60-
std::sort(a.begin(), a.end());
61-
std::sort(b.begin(), b.end());
62-
63-
double mae = 0.0;
64-
for(size_t i=0; i<n; i++) {
65-
mae += std::abs(a[i] - b[i]);
66-
}
67-
68-
return mae / (double)n;
69-
}
70-
7144
/**
7245
* @brief contains_token.
7346
*
@@ -173,7 +146,6 @@ std::vector<std::shared_ptr<Structure>> StructureLoader::load_yaml(const std::st
173146
None,
174147
Lattice,
175148
Coordinates,
176-
Frequencies,
177149
DofLabels,
178150
Hessian
179151
};
@@ -188,7 +160,6 @@ std::vector<std::shared_ptr<Structure>> StructureLoader::load_yaml(const std::st
188160
double z = 0.0;
189161
};
190162
std::vector<ParsedAtom> coordinates_direct;
191-
std::vector<double> frequencies_cm1;
192163
std::vector<std::string> dof_labels;
193164
std::vector<std::vector<double>> hessian_rows;
194165
std::vector<double> current_hessian_row;
@@ -223,10 +194,6 @@ std::vector<std::shared_ptr<Structure>> StructureLoader::load_yaml(const std::st
223194
mode = ParseMode::Coordinates;
224195
continue;
225196
}
226-
if(trimmed == "frequencies_cm-1:") {
227-
mode = ParseMode::Frequencies;
228-
continue;
229-
}
230197
if(trimmed == "dof_labels:") {
231198
mode = ParseMode::DofLabels;
232199
continue;
@@ -246,7 +213,6 @@ std::vector<std::shared_ptr<Structure>> StructureLoader::load_yaml(const std::st
246213
if(trimmed.endsWith(":") &&
247214
trimmed != "lattice_vectors:" &&
248215
trimmed != "coordinates_direct:" &&
249-
trimmed != "frequencies_cm-1:" &&
250216
trimmed != "dof_labels:" &&
251217
trimmed != "matrix:") {
252218
mode = ParseMode::None;
@@ -294,13 +260,6 @@ std::vector<std::shared_ptr<Structure>> StructureLoader::load_yaml(const std::st
294260
break;
295261
}
296262

297-
case ParseMode::Frequencies: {
298-
if(trimmed.startsWith("- ")) {
299-
frequencies_cm1.push_back(trimmed.mid(2).trimmed().toDouble());
300-
}
301-
break;
302-
}
303-
304263
case ParseMode::DofLabels: {
305264
if(trimmed.startsWith("- ")) {
306265
dof_labels.push_back(trimmed.mid(2).trimmed().toStdString());
@@ -433,43 +392,13 @@ std::vector<std::shared_ptr<Structure>> StructureLoader::load_yaml(const std::st
433392
constexpr double HZ_TO_THZ = 1.0e-12;
434393

435394
std::vector<double> computed_freq_cm1;
436-
std::vector<double> computed_freq_cm1_flipped;
437395
computed_freq_cm1.reserve(n);
438-
computed_freq_cm1_flipped.reserve(n);
439396

440-
size_t negative_count_normal = 0;
441-
size_t negative_count_flipped = 0;
442397

443398
for(size_t mode_idx=0; mode_idx<n; mode_idx++) {
444399
const double eig = solver.eigenvalues()((int)mode_idx);
445400
const double signed_cm1 = (eig >= 0.0 ? 1.0 : -1.0) * std::sqrt(std::abs(eig)) * SQRT_UNIT_TO_HZ * HZ_TO_THZ * 33.35640951981521;
446-
const double signed_cm1_flipped = -signed_cm1;
447-
448401
computed_freq_cm1.push_back(signed_cm1);
449-
computed_freq_cm1_flipped.push_back(signed_cm1_flipped);
450-
451-
if(signed_cm1 < -1e-8) {
452-
negative_count_normal++;
453-
}
454-
if(signed_cm1_flipped < -1e-8) {
455-
negative_count_flipped++;
456-
}
457-
}
458-
459-
bool flip_frequency_sign = false;
460-
if(!frequencies_cm1.empty()) {
461-
const double mae_normal = sorted_mae(computed_freq_cm1, frequencies_cm1);
462-
const double mae_flipped = sorted_mae(computed_freq_cm1_flipped, frequencies_cm1);
463-
flip_frequency_sign = (mae_flipped + 1e-12 < mae_normal);
464-
465-
qDebug() << "PyMKMKit YAML reconstructed frequency MAE (cm^-1), normal sign:" << mae_normal
466-
<< ", flipped sign:" << mae_flipped
467-
<< ", selected:" << (flip_frequency_sign ? "flipped" : "normal");
468-
} else {
469-
flip_frequency_sign = (negative_count_flipped < negative_count_normal);
470-
qDebug() << "PyMKMKit YAML sign heuristic based on negative-mode count, normal/flipped:"
471-
<< negative_count_normal << "/" << negative_count_flipped
472-
<< ", selected:" << (flip_frequency_sign ? "flipped" : "normal");
473402
}
474403

475404
structure->clear_eigenmodes();
@@ -494,8 +423,7 @@ std::vector<std::shared_ptr<Structure>> StructureLoader::load_yaml(const std::st
494423
}
495424
}
496425

497-
const double freq_cm1 = flip_frequency_sign ? computed_freq_cm1_flipped[mode_idx]
498-
: computed_freq_cm1[mode_idx];
426+
const double freq_cm1 = computed_freq_cm1[mode_idx];
499427
const double freq_thz = freq_cm1 / 33.35640951981521;
500428

501429
structure->add_eigenmode(freq_thz, mode_vectors);

0 commit comments

Comments
 (0)