20 template class DataFormatter<DB::ConfigIO::Result>;
49 std::set<std::string>
const &dof_managed_properties,
54 for (
auto const &prop : simple_structure.
properties) {
55 if (!dof_managed_properties.count(prop.first)) {
56 result.
global[prop.first] = prop.second;
59 if (prop.first.find(
"strain") != std::string::npos) {
66 if (!dof_managed_properties.count(prop.first)) {
67 result.
site[prop.first] = prop.second;
70 if (prop.first ==
"disp") {
78 result.
scalar(
"total_cost") = total_cost;
97 return m_configmapper->settings();
105 m_configmapper.reset(
122 fs::path p, std::vector<std::string>
const &req_properties,
123 std::unique_ptr<Configuration>
const &hint_config,
136 res.
fail_msg =
"Specified file does not exist!";
143 m_configmapper->import_structure(sstruc, hint_config.get());
147 *result++ = std::move(res);
153 " optimal mappings, when only one was expected.";
154 *result++ = std::move(res);
158 for (
auto const &map : map_result.
maps) {
161 map.second.config.insert(settings().primitive_only);
174 for (std::string
const &propname : req_properties) {
202 *result++ = prim_res;
213 const fs::path &p)
const {
215 if (p.extension() ==
".json" || p.extension() ==
".JSON") {
219 fs::ifstream struc_stream(p);
232 std::string
const &report_dir)
239 "Import Configuration: \n\n"
241 " 'casm import' of Configuration proceeds in two steps: \n\n"
243 " 1) For each file: \n"
244 " - Read structure from VASP POSCAR type file or CASM "
245 "properties.calc.json \n"
247 " - Map the structure onto a Configuration of the primitive crystal \n"
249 " - Record relaxation data (lattice & basis deformation cost). \n\n"
251 " 2) If data import is requested, iterate over each import record and do "
254 " - If multiple imported structures map onto a configuration for which "
256 " there is no calculation data, import calculation data from the "
258 " structure with the lowest \"conflict_score\". "
260 " - If one or more imported structures map onto a configuration for "
262 " which calculation data already exist, do not import any new data "
264 " unless the \"overwrite\" option is given, in which case data and "
266 " files are imported if the \"conflict_score\" will be improved. \n"
267 " - If data is imported, the corresponding properties.calc.json file "
269 " copied into the directory of the mapped configuration. Optionally, "
271 " additional files in the directory of the imported structure file "
273 " also be copied. \n"
274 " - Reports are generated detailing the results of the import: \n"
275 " - import_map_fail: Structures that could not be mapped onto the "
277 " primitive crystal structure. \n"
278 " - import_map_success: Configurations that were successfully mapped "
280 " and imported into the Configuration database (or already "
282 " - import_data_fail: Structures with data that would be imported "
284 " except preexisting data prevents it. \n"
285 " - import_conflict: Configurations that were mapped to by multiple "
291 " mapping: JSON object (optional)\n"
292 " A JSON object containing the following options controlling the "
294 " mapping algorithm:\n"
296 " primitive_only: bool (optional, default=false)\n"
297 " By convention, primitive configurations are always imported along "
299 " non-primitive configurations. If false, only the primitive "
301 " will be imported. Note: data from non-primitive configurations is "
303 " used for primitive configurations.\n\n"
305 " lattice_weight: number in range [0.0, 1.0] (optional, default=0.5) \n"
306 " Candidate configurations are compared using \"deformation_cost\" "
308 " determine the best mapping of the import structure to a "
310 " configuration. The \"lattice_weight\" determines the relative "
312 " of the \"lattice_deformation_cost\" and "
313 "\"atomic_deformation_cost\" \n"
314 " when calculating the total \"deformation_cost\". See _____ for "
318 " max_vol_change: number (optional, default=0.3)\n"
319 " Adjusts range of SCEL volumes searched while mapping imported \n"
320 " structure onto ideal crystal (only necessary if the presence of \n"
321 " vacancies makes the volume ambiguous). Default is +/- 30% of the "
323 " integer volume (relaxed volume / primitive unit cell volume) of "
325 " structure . Smaller values yield faster execution, larger values "
327 " yield more accurate mapping.\n\n"
329 " max_va_frac: number (optional, default=0.5)\n"
330 " Places upper bound on the fraction of sites that are allowed to "
332 " vacant after relaxed structure is mapped onto the ideal crystal. "
334 " Smaller values yield faster execution, larger values may yield "
336 " accurate mapping. Has no effect if supercell volume can be "
338 " from the number of atoms in the structure. Default value allows "
340 " 50% of sites to be vacant.\n\n"
342 " min_va_frac: number (optional, default=0.0)\n"
343 " Places lower bound on the fraction of sites that are allowed to "
345 " vacant after relaxed structure is mapped onto the ideal crystal. "
347 " Nonzero values may yield faster execution if updating "
349 " that are known to have a large number of vacancies, at potential "
351 " sacrifice of mapping accuracy. Has no effect if supercell volume "
353 " be inferred from the number of atoms in the structure. Default "
355 " allows as few as 0% of sites to be vacant.\n\n"
357 " ideal: bool (optional, default=false)\n"
358 " Assume imported structures are in the setting of the ideal "
360 " This results in faster mapping, but may not identify the ideal "
362 " If large mapping costs are encountered, try re-running with ideal "
365 " robust: bool (optional, default=false)\n"
366 " Perform additional checks to determine if mapping is degenerate "
368 " to other mappings, which can occur if the imported structure has "
370 " that is incompatible with prim.json. Results in slower "
373 " filter: string (optional) \n"
374 " Restricts the import to only consider supercells that match a "
376 " casm query expression.\n\n"
378 " forced_lattices: array of strings (optional) \n"
379 " Restricts the import to only consider supercells provided via a "
381 " a list of their conventional names (i.e., "
382 "\"SCEL2_2_1_1_1_1_0\").\n\n"
384 " data: JSON object (optional)\n"
385 " A JSON object containing the following options controlling when "
387 " properties are updated.\n\n"
389 " import: bool (optional, default=false)\n"
390 " If true (default), attempt to import calculation results. Results "
392 " added from a \"properties.calc.json\" file which is checked for "
394 " following locations, relative to the input file path, 'pos': \n"
396 " 1) Is 'pos' a JSON file? If 'pos' ends in \".json\" or \".JSON\", "
398 " it is assumed to be a 'properties.calc.json' file.\n"
399 " 2) If / path / to / pos, checks for / path / to / "
400 "calctype.current / properties.calc.json\n"
401 " 3) If / path / to / pos, checks for / path / to / "
402 "properties.calc.json \n\n"
404 " If false, only configuration structure is imported.\n\n"
406 " additional_files: bool (optional, default = false)\n"
407 " If true, attempt to copy all files & directories in the same "
409 " as the structure file or , if it exists, the properties.calc.json "
411 " Files & directories will only by copied if there are no existing "
413 " or directories in the 'training_data' directory for the "
415 " the structure as been mapped to or \"overwrite\"=true.\n\n"
417 " overwrite: bool (optional, default=false)\n"
418 " If true, data and files will be imported that overwrite existing\n"
419 " data and files, if the score calculated by the "
420 "\"conflict_score\"\n"
421 " for the configuration being mapped to will be improved.\n\n";
436 std::string report_dir =
437 (fs::path(
primclex.dir().reports_dir()) /
"import_report").
string();
445 used_settings[
"mapping"] = mapper.
settings();
446 used_settings[
"data"] = import_settings;
451 log << used_settings << std::endl << std::endl;
457 std::set<fs::path> pos;
465 f.
import(pos.begin(), pos.end());
472 "Update Configuration calculation results: \n\n"
474 " 'casm update' of Configuration calculation results proceeds as follows: "
477 " For each Configuration in the input selection: \n"
478 " - Read properties.calc.json file from training_data directory. "
480 " - Map the relaxed structure onto a Configuration of the primitive "
483 " - Record relaxation data: \n"
484 " - Lattice & basis deformation cost \n"
485 " - Initial configuration and relaxed configuration \n\n"
486 " - If multiple configurations relax onto a configuration for which "
488 " is no calculation data, the calculation data from the with the "
490 " conflict resolution score is used for the relaxed configuration.\n\n"
494 " force: bool (optional, default=false) \n"
495 " Force update all specified Configuration, else use timestamps to "
497 " determine which to update. \n"
501 " mapping: JSON object (optional)\n"
502 " A JSON object containing the following options controlling the "
504 " mapping algorithm:\n"
506 " primitive_only: bool (optional, default=false)\n"
507 " By convention, primitive configurations are always imported along "
509 " non-primitive configurations. If false, only the primitive "
511 " will be imported. Note: data from non-primitive configurations is "
513 " used for primitive configurations.\n\n"
515 " lattice_weight: number in range [0.0, 1.0] (optional, default=0.5) \n"
516 " Candidate configurations are compared using \"deformation_cost\" "
518 " determine the best mapping of the import structure to a "
520 " configuration. The \"lattice_weight\" determines the relative "
522 " of the \"lattice_deformation_cost\" and "
523 "\"atomic_deformation_cost\" \n"
524 " when calculating the total \"deformation_cost\". See _____ for "
528 " max_vol_change: number (optional, default=0.3)\n"
529 " Adjusts range of SCEL volumes searched while mapping imported \n"
530 " structure onto ideal crystal (only necessary if the presence of \n"
531 " vacancies makes the volume ambiguous). Default is +/- 30% of the "
533 " integer volume (relaxed volume / primitive unit cell volume) of "
535 " structure . Smaller values yield faster execution, larger values "
537 " yield more accurate mapping.\n\n"
539 " max_va_frac: number (optional, default=0.5)\n"
540 " Places upper bound on the fraction of sites that are allowed to "
542 " vacant after relaxed structure is mapped onto the ideal crystal. "
544 " Smaller values yield faster execution, larger values may yield "
546 " accurate mapping. Has no effect if supercell volume can be "
548 " from the number of atoms in the structure. Default value allows "
550 " 50% of sites to be vacant.\n\n"
552 " min_va_frac: number (optional, default=0.0)\n"
553 " Places lower bound on the fraction of sites that are allowed to "
555 " vacant after relaxed structure is mapped onto the ideal crystal. "
557 " Nonzero values may yield faster execution if updating "
559 " that are known to have a large number of vacancies, at potential "
561 " sacrifice of mapping accuracy. Has no effect if supercell volume "
563 " be inferred from the number of atoms in the structure. Default "
565 " allows as few as 0% of sites to be vacant.\n\n"
567 " ideal: bool (optional, default=false)\n"
568 " Assume imported structures are in the setting of the ideal "
570 " This results in faster mapping, but may not identify the ideal "
572 " If large mapping costs are encountered, try re-running with ideal "
575 " fix_volume: bool (optional, default=false)\n"
576 " Assume imported structures have the same integer volume as the "
578 " configuration. All supercells of this volume are considered for "
580 " This assumption may fail for systems that allow vacancies, when "
582 " concentration is high. Increases execution speed in these "
585 " fix_lattice: bool (optional, default=false)\n"
586 " Assume imported structures have the same lattice as the starting "
588 " Only this supercell will be considered for mapping, but all "
590 " relationships will still be considered. Increases execution "
591 "speed, especially\n"
592 " at large supercell volume, but cannot detect relaxation to a "
593 "different supercell.\n\n"
595 " robust: bool (optional, default=false)\n"
596 " Perform additional checks to determine if mapping is degenerate "
598 " to other mappings, which can occur if the imported structure has "
600 " that is incompatible with prim.json. Results in slower "
603 " data: JSON object (optional)\n"
604 " A JSON object containing the following options controlling how "
606 " properties are updated. After structural relaxation, a structural "
608 " began as structure 'A' may map more closely onto a different "
610 " In some cases, multiple structures may map onto the same 'B', and a "
612 " metric is used to specify which set of calculation data is "
614 " configuration 'B'. The following values determine the scoring "
617 " \"deformation_cost\":\n"
618 " \"lattice_weight\": number, in range [0, 1.0]\n"
620 " Uses a weighted sum of cost functions for lattice and basis \n"
621 " deformation. See below for complete definition. Ex: \n"
622 " {\"method\":\"deformation_cost\":, \"lattice_weight\":0.5} \n\n"
625 " \"property\": property name (ex: \"energy\")\n"
627 " Reads the specified property from the mapped properties and\n"
628 " selects the minimum to be the best mapping. Ex: \n"
629 " {\"method\":\"minimum\":, \"property\": \"energy\"} \n\n"
632 " \"property\": property name (ex: \"energy\")\n"
634 " Reads the specified property from the mapped properties and\n"
635 " selects the maximum to be the best mapping. Ex: \n"
636 " {\"method\":\"maximum\":, \"property\": \"energy\"} \n\n"
638 " \"direct_selection\":\n"
639 " \"name\": configname to force as 'best' (ex: "
640 "\"SCEL3_1_1_3_0_0_0/4\")\n"
642 " Directly specify which configuration's properties should be used. "
644 " {\"method\":\"direct_selection\":, \"name\": "
645 "\"SCEL3_1_1_3_0_0_0/4\"} \n\n"
647 " The default value used by CASM is:\n"
648 " {\"method\": \"minimum\", \"property\": \"energy\"}\n\n"
650 "Deformation cost:\n"
652 " The \"deformation_cost\" is:\n\n"
654 " deformation_cost = w*lattice_deformation_cost + \n"
655 " (1.0-w)*atomic_deformation_cost,\n\n"
657 " where \"w\" is the \"lattice_weight\" factor (default=0.5),\n\n"
659 " the \"lattice_deformation_cost\" is the mean-square displacement of a \n"
660 " points on the surface of a sphere of volume equal to the atomic volume "
662 " when it is deformed by the volume preserving deviatoric deformation \n"
663 " matrix, F_deviatoric:\n\n"
665 " V = relaxed_atomic_volume;\n"
666 " F = deformation matrix (lattice_relaxed = F*lattice_ideal);\n"
667 " F_deviatoric = F/pow(F.determinant(), 1./3.);\n"
668 " I = 3x3 identity matrix;\n\n"
670 " lattice_deformation_cost = pow( 3.*V / (4.*pi), 2.0/3.0) / 3.0 * \n"
671 " (0.5 * (F.t * F / pow(std::abs(F.determinant()), 2.0/3.0) - "
672 "I)).squaredNorm()\n\n"
674 " and the \"atomic_deformation_cost\" is a cost function for the amount "
676 " basis site relaxation:\n\n"
678 " D = 3xN matrix of basis site displacements (displacements are "
681 " Natoms = number of atoms in configuration\n"
682 " atomic_deformation_cost = (F*D * D.transpose() * "
683 "F.transpose()).trace() \n"
684 " / (max(Natoms, 1.))\n\n";
692 std::vector<std::string> col = {
"initial_path",
701 "import_additional_files",
705 "lattice_deformation_cost",
706 "atomic_deformation_cost",
709 return dict.
parse(col);
717 std::string
const &report_dir)
725 const po::variables_map &vm = update_opt.
vm();
730 if (vm.count(
"force")) {
733 kwargs.
get_else(force,
"force",
false);
735 used[
"force"] = force;
746 used[
"mapping"] = mapper.
settings();
756 log << used << std::endl << std::endl;
760 std::string report_dir =
761 (fs::path(
primclex.dir().reports_dir()) /
"update_report").
string();
782 std::vector<std::string> col = {
"data_origin",
790 "lattice_deformation_cost",
791 "atomic_deformation_cost",
794 return dict.
parse(col);
po::variables_map & vm()
Get the variables map.
const fs::path & selection_path() const
Returns the string corresponding to add_config_suboption()
Configuration-specialized Import.
Generic ConfigType-dependent part of Import.
void import(PathIterator begin, PathIterator end)
const ConfigMapping::Settings & settings() const
Returns settings used for mapping.
std::back_insert_iterator< std::vector< ConfigIO::Result > > map_result_inserter
Configuration-specialized Import.
Generic ConfigType-dependent part of Import.
void update(const DB::Selection< ConfigType > &selection, bool force)
Re-parse calculations 'from' all selected configurations.
void read(const std::string &what)
PrimClex is the top-level data structure for a CASM project.
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
BasicStructure specifies the lattice and atomic basis of a crystal.
static BasicStructure from_poscar_stream(std::istream &poscar_stream, double tol=TOL)
Representation of a crystal of molecular and/or atomic occupants, and any additional properties....
std::map< std::string, Eigen::MatrixXd > properties
Eigen::Matrix3d lat_column_mat
std::string to_string(ENUM val)
Return string representation of enum class.
double crystallography_tol() const
Get the crystallography_tol.
bool get_else(T &t, const std::string &key, const T &default_value, Args &&... args) const
T get(Args &&... args) const
Get data from json, using one of several alternatives.
GenericDatumFormatter< double, Result > lattice_deformation_cost()
GenericDatumFormatter< double, Result > atomic_deformation_cost()
void default_import_formatters(DataFormatterDictionary< Result > &dict, PropertiesDatabase &db_props)
Insert default formatters to dictionary, for 'casm import'.
void default_update_formatters(DataFormatterDictionary< Result > &dict, PropertiesDatabase &db_props)
Insert default formatters to dictionary, for 'casm update'.
jsonParser const & from_json(ImportSettings &_set, jsonParser const &_json)
std::string create_report_dir(std::string report_dir)
Create a new report directory to avoid overwriting existing results.
std::pair< OutputIterator, int > construct_pos_paths(const PrimClex &primclex, const Completer::ImportOption &import_opt, OutputIterator result)
Construct pos_paths from input args –pos && –batch.
MappedProperties make_mapped_properties(SimpleStructure const &simple_structure, std::set< std::string > const &dof_managed_properties, double lattice_deformation_cost, double atomic_deformation_cost, double total_cost)
static MappedProperties _make_mapped_properties(MappingNode const &_node, ConfigMapperResult::Individual const &_map)
xtal::SimpleStructure make_simple_structure(Supercell const &_scel, ConfigDoF const &_dof, std::vector< DoFKey > const &_which_dofs={})
Construct from ConfigDoF _dof belonging to provided Supercell _scel.
void from_json(ClexDescription &desc, const jsonParser &json)
Holds results of Configuration::insert.
bool insert_canonical
True if canonical configuration did not exist before insertion.
iterator primitive_it
Iterator pointing at primitive.
bool insert_primitive
True if primitive did not exist before insertion.
iterator canonical_it
Iterator pointing at canonical, if existing.
std::set< std::string > dof_managed_properties
SimpleStructure resolved_struc
Data structure holding results of ConfigMapper algorithm.
std::string fail_msg
Failure message if could not map to prim.
std::map< MappingNode, Individual > maps
The configurations that the input structure mapped onto.
Index n_optimal(double tol=TOL) const
Struct with optional parameters for Config Mapping Specifies default parameters for all values,...
Data structure for mapping / import results.
MappedProperties properties
Struct with optional parameters for Config/Data Import Specifies default parameters for all values,...
double const & scalar(std::string const &_name) const
std::map< std::string, Eigen::MatrixXd > site
std::map< std::string, Eigen::MatrixXd > global
double cost
Total cost of best solution to the constrained assignment problem having some forced_on assignments.
double cost
strain_cost of the LatticeNode
AssignmentNode atomic_node
double cost
total, finalized cost, populated by a StrucMapCalculator. Not guaranteed to be a linear function of l...
Eigen::MatrixXd coords
(3 x names.size()) matrix of coordinates. coords.col(i) is Cartesian coordinate of site 'i'
std::map< std::string, Eigen::MatrixXd > properties
map of [property name, (m x names.size()) matrix] for all numerical site properties properties are as...