diff --git a/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h b/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h index b5bc0644fd5e30e7faef4d08d62499f4ffe0e8c6..34c861a26cc041f7331a3e2bcbea0211a2150ff8 100644 --- a/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h +++ b/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h @@ -73,6 +73,7 @@ public: private: std::string raw_data_; // Stores raw file data + std::string filename_; // Stores raw file data double s_conv = 6.241509074e-4; // kbar -> eV/A^3 }; diff --git a/include/tadah/mlip/structure.h b/include/tadah/mlip/structure.h index 9648e651d066839a2cac3953d789717a4369064f..306ca2c7e87695b5041881c41795e5e066fb48ea 100644 --- a/include/tadah/mlip/structure.h +++ b/include/tadah/mlip/structure.h @@ -62,6 +62,12 @@ struct Structure { /** Container for atoms which belong to this structure */ std::vector<Atom> atoms; + /** Temperature of this structure. + * + * Default is 0.0 + */ + double T=0; + /** * Container for nearest neighbour atoms for every atom in the structure. */ diff --git a/src/castep_castep_reader.cpp b/src/castep_castep_reader.cpp index 89fed3a698fe276636ae9f808a7e8207adda284d..b27d0bd7d3869202c10120a3bd861585f0968a6b 100644 --- a/src/castep_castep_reader.cpp +++ b/src/castep_castep_reader.cpp @@ -245,13 +245,21 @@ void CastepCastepReader::parse_data() { } else if (line.find("Potential Energy:") != std::string::npos) { - // MD: end of iteration std::istringstream iss(line); std::string tmp; if (!(iss >> tmp >> tmp >> tmp >> s.energy)) { std::cerr << "Warning, file" << filename << " line: " << counter << std::endl; std::cerr << "Warning: Unexpected end of data when reading total energy" << std::endl; } + } + else if (line.find("Temperature:") != std::string::npos) { + // MD: end of iteration + std::istringstream iss(line); + std::string tmp; + if (!(iss >> tmp >> tmp >> s.T)) { + std::cerr << "Warning, file" << filename << " line: " << counter << std::endl; + std::cerr << "Warning: Unexpected end of data when reading temperature" << std::endl; + } if (!label.size())label = "CASTEP MD, const. volume: false, step: 0"; // the last option s.label = label; diff --git a/src/castep_md_reader.cpp b/src/castep_md_reader.cpp index a592172754bda721a102bac7326d85a9c1763d35..d75b260c441f298c11273da9dc44d661e446bad2 100644 --- a/src/castep_md_reader.cpp +++ b/src/castep_md_reader.cpp @@ -46,7 +46,7 @@ void CastepMDReader::postproc_structure(Structure &s) { // finish conversion s.cell *= d_conv; s.stress *= s_conv; - // T /= k_b; + s.T = T/k_b; // add to database stdb.add(s); @@ -101,17 +101,18 @@ void CastepMDReader::parse_data() { int S_flag=0; bool R_flag=false; bool F_flag=false; + bool T_flag=false; bool complete_structure=false; while (std::getline(stream, line)) { if (ends_with(line,"<-- T")) { - if (/* T_flag || */ complete_structure) { + if (T_flag || complete_structure) { error=true; continue; } std::istringstream iss(line); iss >> T; - //T_flag=true; + T_flag=true; } else if (ends_with(line,"<-- E")) { if (/* T_flag || */ E_flag || complete_structure) { @@ -187,7 +188,7 @@ void CastepMDReader::parse_data() { postproc_structure(s); error=false; - //T_flag=false; + T_flag=false; E_flag=false; H_flag=0; S_flag=0; diff --git a/src/dataset_reader_selector.cpp b/src/dataset_reader_selector.cpp index bdc6d2004520d482132c70e7627dd562d7cef1ee..ef5d8b1cd6ce3d692796a424c5cb36f4b8a1353c 100644 --- a/src/dataset_reader_selector.cpp +++ b/src/dataset_reader_selector.cpp @@ -41,12 +41,11 @@ std::string DatasetReaderSelector::determine_file_type_by_content(const std::str std::string line; while (std::getline(file, line)) { - if (line.find("vasp") != std::string::npos) { - if (line.find("incar:") != std::string::npos || line.find("outcar") != std::string::npos) { - return "VASP.OUTCAR"; - } else if (line.find("<modeling>") != std::string::npos || line.find("<calculation>") != std::string::npos) { - return "VASP.VASPRUN"; - } + if (line.find("incar:") != std::string::npos || line.find("OUTCAR:") != std::string::npos || + line.find("outcar") != std::string::npos || line.find("POTCAR:") != std::string::npos) { + return "VASP.OUTCAR"; + } else if (line.find("<modeling>") != std::string::npos || line.find("<calculation>") != std::string::npos) { + return "VASP.VASPRUN"; } else if (line.find("<-- c") != std::string::npos) { return "CASTEP.GEOM"; diff --git a/src/structure.cpp b/src/structure.cpp index f5c67485f3266e556818436c1e8b250be8613a37..2d870bbecdacab8f4fd35779ef42c9f6cc111174 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -53,8 +53,17 @@ int Structure::read(std::ifstream &ifs) { stream.clear(); stream.seekg(0, std::ios::beg); stream >> eweight >> fweight >> sweight; - // energy - ifs >> energy; + std::getline(ifs,line); + std::stringstream stream2(line); + // energy and T + stream2 >> energy; + if(stream2) stream2 >> T; + } + else if (count == 2) { + stream.clear(); + stream.seekg(0, std::ios::beg); + // energy and T + stream >> energy >> T; } else { energy = std::stod(line); @@ -262,7 +271,7 @@ void Structure::dump_to_file(std::ostream& file, size_t prec) const { file << label << std::endl; file << std::fixed << std::setprecision(prec); file << eweight << " " << fweight << " " << sweight << std::endl; - file << energy << std::endl; + file << energy << " " << T << std::endl; file << std::setw(prec+n) << cell(0,0) << " " diff --git a/src/vasp_outcar_reader.cpp b/src/vasp_outcar_reader.cpp index d5fccef6162056f6137a513447d1b122a0452d15..d1ead35e7ecb00f1c860d7559574f78e475af0e9 100644 --- a/src/vasp_outcar_reader.cpp +++ b/src/vasp_outcar_reader.cpp @@ -10,7 +10,7 @@ VaspOutcarReader::VaspOutcarReader(StructureDB& db) : DatasetReader(db) {} VaspOutcarReader::VaspOutcarReader(StructureDB& db, const std::string& filename) -: DatasetReader(db, filename) { +: DatasetReader(db, filename), filename_(filename) { read_data(filename); } @@ -38,14 +38,21 @@ void VaspOutcarReader::parse_data() { size_t natoms;; bool stress_tensor_bool = false; bool complete_structure = false; + bool is_md = false; Structure s; + size_t counter=0; while (std::getline(stream, line)) { - if (line.find("VRHFIN") != std::string::npos) { + if (line.find("molecular dynamics") != std::string::npos) { + is_md = true; + s.label += "MD "; + } + else if (line.find("VRHFIN") != std::string::npos) { std::string type = line.substr(line.find("=") + 1); type = type.substr(0, type.find(":")); atom_types.push_back(type); + s.label += filename_ + " "; } else if (line.find("NIONS") != std::string::npos) { @@ -164,8 +171,20 @@ void VaspOutcarReader::parse_data() { if (!(iss >> tmp >> tmp >> tmp >> s.energy)) { std::cerr << "Warning: Unexpected end of data when reading total energy" << std::endl; } + else if (!is_md) { + complete_structure = true; + s.label += "Structure " + std::to_string(++counter); + } + } + else if (line.find("EKIN_LAT=") != std::string::npos) { + std::istringstream iss(line); + std::string tmp; + if (!(iss >> tmp >> tmp >> tmp >> tmp >> tmp >> s.T)) { + std::cerr << "Warning: Unexpected end of data when reading temperature" << std::endl; + } else { complete_structure = true; + s.label += "Structure " + std::to_string(++counter); } } diff --git a/src/vasp_vasprun_reader.cpp b/src/vasp_vasprun_reader.cpp index cc8e6620f9f2970a1a00eae8418991c35cbdf667..c6917d31174be17004b1f9e8be6c6ef6c14a04d6 100644 --- a/src/vasp_vasprun_reader.cpp +++ b/src/vasp_vasprun_reader.cpp @@ -25,6 +25,8 @@ void VaspVasprunReader::read_data(const std::string& filename) { } catch (std::exception &e) { std::cerr << "Error reading file: " << e.what() << std::endl; } + + _s.label = filename + " "; } void VaspVasprunReader::parse_data() { @@ -83,6 +85,7 @@ void VaspVasprunReader::extract_atom_types(rx::xml_node<> *root_node) { } void VaspVasprunReader::extract_calculations(rx::xml_node<> *root_node) { + size_t counter=0; for (auto calculation_node = root_node->first_node("calculation"); calculation_node; calculation_node = calculation_node->next_sibling("calculation")) { @@ -102,6 +105,7 @@ void VaspVasprunReader::extract_calculations(rx::xml_node<> *root_node) { extract_forces(calculation_node); + _s.label += "Structure " + std::to_string(++counter); stdb.add(_s); _s = Structure(); // reset } @@ -140,12 +144,12 @@ void VaspVasprunReader::extract_stress_tensor(rx::xml_node<> *calculation_node) _s.stress(r, 0) = x; _s.stress(r, 1) = y; _s.stress(r, 2) = z; - _s.stress *= s_conv; } else { std::cerr << "Error parsing stress tensor components." << std::endl; } r++; } + _s.stress *= s_conv; break; } varray_node = varray_node->next_sibling("varray");