1 #ifndef CASM_DB_Update_impl
2 #define CASM_DB_Update_impl
4 #include <boost/filesystem/fstream.hpp>
17 template <
typename _ConfigType>
20 std::string report_dir)
22 m_structure_mapper(mapper),
23 m_report_dir(report_dir) {}
26 template <
typename _ConfigType>
30 auto const &project_settings = this->
primclex().settings();
31 auto calctype = project_settings.default_clex().calctype;
32 auto required_properties =
36 std::vector<ConfigIO::Result> results;
37 for (
const auto &val : selection.
data()) {
42 std::string
name = val.first;
61 if ((!force && this->no_change(
name))) {
67 db_props().erase_via_origin(pos);
69 if (!fs::exists(pos))
continue;
71 log <<
"Updating data records for " <<
name << std::endl;
72 std::vector<ConfigIO::Result> tvec;
73 auto config_it = db_config<ConfigType>().find(
name);
74 if (config_it == db_config<ConfigType>().end())
75 m_structure_mapper.map(resolve_struc_path(pos,
primclex()),
76 required_properties,
nullptr,
77 std::back_inserter(tvec));
79 m_structure_mapper.map(resolve_struc_path(pos,
primclex()),
81 notstd::make_unique<ConfigType>(*config_it),
82 std::back_inserter(tvec));
83 for (
auto &res : tvec) {
84 results.push_back(res);
86 if (!res.properties.to.empty() && res.has_data) {
88 db_props().insert(res.properties);
92 _update_report(results, selection);
94 db_supercell().commit();
95 db_config<ConfigType>().commit();
99 template <
typename _ConfigType>
101 std::vector<ConfigIO::Result> &results,
112 std::vector<ConfigIO::Result> fail;
113 std::vector<ConfigIO::Result> success;
114 std::vector<ConfigIO::Result> conflict;
115 std::vector<ConfigIO::Result> unstable;
116 std::vector<ConfigIO::Result> unselected;
117 std::vector<ConfigIO::Result> new_config;
119 std::string prefix =
"update_";
122 std::map<std::string, int> all_to;
124 for (
auto const &res : results) {
125 if (res.properties.to.empty()) {
128 auto it = all_to.find(res.properties.to);
129 if (it == all_to.end()) {
130 it = all_to.insert(std::make_pair(res.properties.to, 0)).first;
133 if (res.properties.origin !=
135 unstable.push_back(res);
136 if (res.is_new_config) {
137 new_config.push_back(res);
140 unselected.push_back(res);
143 success.push_back(res);
147 for (
auto const &res : results) {
148 if (all_to[res.properties.to] > 1) {
149 conflict.push_back(res);
153 auto formatter = _update_formatter();
156 fs::path p = fs::path(m_report_dir) / (prefix +
"_fail");
157 fs::ofstream sout(p);
159 log() <<
"WARNING: Could not map " << fail.size() <<
" results."
161 log() <<
" See detailed report: " << p << std::endl << std::endl;
163 sout << formatter(fail.begin(), fail.end());
166 if (success.size()) {
167 fs::path p = fs::path(m_report_dir) / (prefix +
"_success");
168 fs::ofstream sout(p);
170 log() <<
"Successfully mapped " << success.size() <<
" results."
172 log() <<
" See detailed report: " << p << std::endl << std::endl;
174 sout << formatter(success.begin(), success.end());
177 if (conflict.size()) {
178 fs::path p = fs::path(m_report_dir) / (prefix +
"_conflict");
179 fs::ofstream sout(p);
181 log() <<
"WARNING: Found " << conflict.size()
182 <<
" conflicting relaxation results." << std::endl;
183 log() <<
" See detailed report: " << p << std::endl << std::endl;
185 sout << formatter(conflict.begin(), conflict.end());
188 if (unstable.size()) {
189 fs::path p = fs::path(m_report_dir) / (prefix +
"_unstable");
190 fs::ofstream sout(p);
192 log() <<
"WARNING: Found " << unstable.size() <<
" unstable relaxations."
194 log() <<
" See detailed report: " << p << std::endl << std::endl;
196 sout << formatter(unstable.begin(), unstable.end());
199 if (unselected.size()) {
200 fs::path p = fs::path(m_report_dir) / (prefix +
"_unselected");
201 fs::ofstream sout(p);
203 log() <<
"WARNING: Found " << unselected.size()
204 <<
" unstable relaxations to unselected configurations." << std::endl;
205 log() <<
" See detailed report: " << p << std::endl << std::endl;
207 sout << formatter(unselected.begin(), unselected.end());
210 if (new_config.size()) {
211 fs::path p = fs::path(m_report_dir) / (prefix +
"_new");
212 fs::ofstream sout(p);
214 log() <<
"WARNING: Found " << new_config.size()
215 <<
" unstable relaxations to new configurations." << std::endl
216 <<
" These configurations have been added to the project."
218 log() <<
" See detailed report: " << p << std::endl << std::endl;
220 sout << formatter(unselected.begin(), unselected.end());
bool is_selected(const std::string &name_or_alias) const
True if obj is in Selection and is selected; false otherwise.
UpdateT(const PrimClex &primclex, const StructureMap< ConfigType > &mapper, std::string report_dir)
Constructor.
void _update_report(std::vector< ConfigIO::Result > &results, const DB::Selection< ConfigType > &selection) const
void update(const DB::Selection< ConfigType > &selection, bool force)
Re-parse calculations 'from' all selected configurations.
PrimClex is the top-level data structure for a CASM project.
std::string calc_properties_path(const ConfigType &config, std::string calctype="")
GenericDatumFormatter< std::string, DataObject > name()