Skip to content
Snippets Groups Projects
Commit e4395b60 authored by Marcin Kirsz's avatar Marcin Kirsz
Browse files

Dealing with ATOMS and WATOMS

parent 2b2454d6
No related branches found
No related tags found
1 merge request!3Develop
Pipeline #47545 failed
......@@ -122,6 +122,7 @@ class DescriptorsCalc: public DC_Base {
void calc(const Structure &st, StDescriptors &std);
void calc_dimer(const Structure &st, StDescriptors &std);
void common_constructor();
double weights[119]; // ignore zero index; w[1]->H
};
......
This diff is collapsed.
......@@ -58,7 +58,7 @@ struct StructureDB {
* Required Config key: \ref DBFILE
*
*/
void add(const Config &config);
void add(Config &config);
/** Add all structures from a file */
void add(const std::string fn);
......@@ -137,6 +137,12 @@ struct StructureDB {
/** Return unique elements for all Structures. */
std::set<Element> get_unique_elements() const;
/** Find unique elements in provided Config file */
static std::set<Element> find_unique_elements(const Config &c);
/** Find unique elements in provided file */
static std::set<Element> find_unique_elements(const std::string &fn);
/** Count number of structures and atoms in all datasets from the Config file. */
static std::pair<int,int> count(const Config &c);
......@@ -146,9 +152,9 @@ struct StructureDB {
void clear_nn();
/** Check consistency of the ATOMS key. */
void check_atoms_key(Config &config) const;
static void check_atoms_key(Config &config, std::set<Element> &unique_elements);
/** Check consistency of the WATOMS key. Add if missing*/
void check_watoms_key(Config &config) const;
static void check_watoms_key(Config &config, std::set<Element> &unique_elements);
};
#endif
#include <tadah/mlip/structure_db.h>
#include <tadah/core/periodic_table.h>
#include <cstdio>
StructureDB::StructureDB() {}
StructureDB::StructureDB(Config &config) {
add(config);
check_atoms_key(config);
check_watoms_key(config);
}
void StructureDB::add(const std::string fn) {
......@@ -59,7 +59,7 @@ void StructureDB::remove(size_t i) {
structures.erase(structures.begin()+i);
}
void StructureDB::add(const Config &config) {
void StructureDB::add(Config &config) {
for (const std::string &s : config("DBFILE")) {
dbidx.push_back(size());
add(s);
......@@ -106,6 +106,50 @@ std::set<Element> StructureDB::get_unique_elements() const {
st.unique_elements.begin(),st.unique_elements.end());
return s;
}
std::set<Element> StructureDB::find_unique_elements(const std::string &fn) {
std::set<Element> s;
std::ifstream datafile(fn);
std::string line;
if (!datafile.is_open()) {
std::cerr << "Could not open the file." << std::endl;
}
char symbol[3];
// move to first non empty line
while (std::getline(datafile, line)) {
if (!line.empty()) {
break;
}
}
// skip
for (int i = 0; i < 7; ++i) {
std::getline(datafile, line);
}
while (std::getline(datafile, line)) {
if(line.empty()) {
for (int i = 0; i < 8; ++i) {
if (!std::getline(datafile, line)) {
// Handle the case where there are not enough lines
break; // or handle the error
}
}
continue;
}
sscanf(line.c_str(), "%2s", symbol);
s.insert(PeriodicTable::find_by_symbol(symbol));
}
return s;
}
std::set<Element> StructureDB::find_unique_elements(const Config &c) {
std::set<Element> s;
for (const auto& fn: c("DBFILE")) {
std::set<Element> temp = find_unique_elements(fn);
s.insert(temp.begin(), temp.end());
}
return s;
}
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> &l,const std::pair<T,U> &r) {
......@@ -140,8 +184,7 @@ std::pair<int,int> StructureDB::count(const std::string fn){
void StructureDB::clear_nn() {
for (auto &struc: structures) struc.clear_nn();
}
void StructureDB::check_atoms_key(Config &config) const {
std::set<Element> unique_elements = get_unique_elements();
void StructureDB::check_atoms_key(Config &config, std::set<Element> &unique_elements) {
bool error=false;
if (config.exist("ATOMS")) {
......@@ -153,7 +196,7 @@ void StructureDB::check_atoms_key(Config &config) const {
auto set_it = unique_elements.begin();
auto atoms_it = config("ATOMS").begin();
while (set_it != unique_elements.end() && atoms_it != config("ATOMS").end()) {
if (set_it->symbol != *atoms_it) {
if (set_it->symbol != (*atoms_it)) {
error=true;
}
++set_it;
......@@ -170,8 +213,7 @@ void StructureDB::check_atoms_key(Config &config) const {
for (const auto &s : unique_elements) config.add("ATOMS", s.symbol);
}
}
void StructureDB::check_watoms_key(Config &config) const {
std::set<Element> unique_elements = get_unique_elements();
void StructureDB::check_watoms_key(Config &config, std::set<Element> &unique_elements) {
bool error=false;
if (config.exist("WATOMS")) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment