From 1723f746476e687b0ab6fb6bad601a74d2ca0bf0 Mon Sep 17 00:00:00 2001 From: jeremiah Date: Sat, 28 Oct 2023 03:24:08 -0700 Subject: [PATCH 1/5] update import/update descriptions --- src/casm/database/ConfigImport.cc | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/casm/database/ConfigImport.cc b/src/casm/database/ConfigImport.cc index 30fc34d3c..10e67041c 100644 --- a/src/casm/database/ConfigImport.cc +++ b/src/casm/database/ConfigImport.cc @@ -261,7 +261,7 @@ const std::string Import::desc = " 'casm import' of Configuration proceeds in two steps: \n\n" " 1) For each file: \n" - " - Read structure from a CASM structure file (typically namd \n" + " - Read structure from a CASM structure file (typically named \n" " structure.json or properties.calc.json) or VASP POSCAR type file.\n" " - Map the structure onto a Configuration of the primitive crystal \n" " structure. \n" @@ -270,13 +270,13 @@ const std::string Import::desc = " 2) If properties or files import is requested (--properties, \n" " --copy-structure-files, or --copy-additional-files), iterate over \n" " each import record and do the following:\n" - " - If proeperty import is requested, properties are imported from \n" + " - If property import is requested, properties are imported from \n" " all successfully mapped structures. \n" " - If multiple imported structures map onto the same configuration, \n" - " the properties from the structure with the best for \n" + " the properties from the structure with the best value for \n" " \"conflict_score\" are used when querying properties of the \n" " configuration. By default, property \"energy\" is used for the \n" - " conflict score, minimum being best.\n" + " conflict score and the minimum energy is best.\n" " - If it is requested that the structure file or additional files \n" " are copied into the training_data directories, copying \n" " occurs if either the configuration being mapped to has no \n" @@ -317,9 +317,8 @@ const std::string Import::desc = "weight\n" " of the \"lattice_deformation_cost\" and " "\"atomic_deformation_cost\" \n" - " when calculating the total \"deformation_cost\". See _____ for " - " \n" - " details. \n\n" + " when calculating the total \"deformation_cost\". See description \n" + " of Deformation Cost in \"casm update --desc\" for details. \n\n" " max_vol_change: number (optional, default=0.3)\n" " Adjusts range of SCEL volumes searched while mapping imported \n" @@ -393,25 +392,25 @@ const std::string Import::desc = " properties are updated.\n\n" " import_properties: bool (optional, default=false)\n" - " If true (default), attempt to import structure properties. \n" + " If true, attempt to import structure properties. \n" " Properties are read from the structure files indicated by --pos \n" " or --batch. If the file ends in \".json\" or \".JSON\" it is \n" " read as a CASM structure file, otherwise it is read as a VASP \n" " POSCAR.\n\n" - " copy_structure_files: bool (optional, default = false)\n" + " copy_structure_files: bool (optional, default=false)\n" " If true, attempt to copy structure files into the project as \n" " \"properties.calc.json\". Files will only by copied if there \n" " are no existing files or data for the configuration the \n" " structure has been mapped to, or it is the best scoring \n" " mapping and \"overwrite\"=true.\n\n" - " additional_files: bool (optional, default = false)\n" + " additional_files: bool (optional, default=false)\n" " If true, attempt to copy all files & directories in the same \n" " directory as the structure file or, if it exists, the \n" - " properties.calc.json file. Files & directories will only by \n" + " properties.calc.json file. Files & directories will only be \n" " copied if there are no existing files or directories for the \n" - " configuration the structure as been mapped to, or it is the \n" + " configuration the structure has been mapped to, or it is the \n" " best scoring mapping and \"overwrite\"=true.\n\n" " overwrite: bool (optional, default=false)\n" @@ -521,9 +520,7 @@ const std::string Update::desc = "weight\n" " of the \"lattice_deformation_cost\" and " "\"atomic_deformation_cost\" \n" - " when calculating the total \"deformation_cost\". See _____ for " - " \n" - " details. \n\n" + " when calculating the total \"deformation_cost\". See description below. \n\n" " max_vol_change: number (optional, default=0.3)\n" " Adjusts range of SCEL volumes searched while mapping imported \n" From 3028b4607f41bc3993299d390ca0031b2687f22b Mon Sep 17 00:00:00 2001 From: jeremiah Date: Sat, 28 Oct 2023 15:05:19 -0700 Subject: [PATCH 2/5] additional_files -> copy_additional_files --- src/casm/database/ConfigImport.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/casm/database/ConfigImport.cc b/src/casm/database/ConfigImport.cc index 10e67041c..6399f10b4 100644 --- a/src/casm/database/ConfigImport.cc +++ b/src/casm/database/ConfigImport.cc @@ -405,7 +405,7 @@ const std::string Import::desc = " structure has been mapped to, or it is the best scoring \n" " mapping and \"overwrite\"=true.\n\n" - " additional_files: bool (optional, default=false)\n" + " copy_additional_files: bool (optional, default=false)\n" " If true, attempt to copy all files & directories in the same \n" " directory as the structure file or, if it exists, the \n" " properties.calc.json file. Files & directories will only be \n" From 7c25340f96fa6f1981031df1529789f5a1553aae Mon Sep 17 00:00:00 2001 From: jeremiah Date: Sat, 28 Oct 2023 16:02:24 -0700 Subject: [PATCH 3/5] return copied file count --- src/casm/app/DirectoryStructure.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/casm/app/DirectoryStructure.cc b/src/casm/app/DirectoryStructure.cc index 85ae2b9ea..68ed1fc58 100644 --- a/src/casm/app/DirectoryStructure.cc +++ b/src/casm/app/DirectoryStructure.cc @@ -94,7 +94,7 @@ Index recurs_cp_files_impl(const fs::path &from_dir, const fs::path &to_dir, Index recurs_cp_files(const fs::path &from_dir, const fs::path &to_dir, bool dry_run, Log &log) { Index count = 0; - recurs_cp_files_impl(from_dir, to_dir, dry_run, count, log); + count = recurs_cp_files_impl(from_dir, to_dir, dry_run, count, log); return count; } From 3fd630c987abaa2de34fad5bacd9217e1e5bc919 Mon Sep 17 00:00:00 2001 From: jeremiah Date: Sat, 28 Oct 2023 17:36:04 -0700 Subject: [PATCH 4/5] fix copying files during import --- src/casm/database/ConfigData.cc | 20 ++++++++++---------- src/casm/database/ConfigImport.cc | 6 ++++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/casm/database/ConfigData.cc b/src/casm/database/ConfigData.cc index 2da8d5133..fcdf20e53 100644 --- a/src/casm/database/ConfigData.cc +++ b/src/casm/database/ConfigData.cc @@ -327,27 +327,27 @@ void ConfigData::cp_files(ConfigIO::Result &res, bool dry_run, fs::create_directories(target_dir); } } + fs::path src = res.properties.origin; + fs::path dest = target_dir / "properties.calc.json"; log().custom(std::string("Copy calculation files: ") + res.properties.to); - fs::path src = res.properties.origin; - if (copy_additional_files) { + if (!copy_additional_files) { + log() << "cp " << src << " " << dest << std::endl; + if (!dry_run) { + fs::copy_file(src, dest); + } + } + else { fs::path src_dir = src.remove_filename(); Index count = recurs_cp_files(src_dir, target_dir, dry_run, log()); if (count) { res.import_data.copy_additional_files = true; } } - - fs::path dest = target_dir / "properties.calc.json"; - log() << "cp " << src << " " << dest << std::endl; res.import_data.copy_structure = true; - if (!dry_run) { - fs::copy_file(src, dest); - } res.properties.origin = dest.string(); - - res.properties.file_data = FileData(dest.string()); + res.properties.file_data = FileData(dest.string()); log() << std::endl; return; } diff --git a/src/casm/database/ConfigImport.cc b/src/casm/database/ConfigImport.cc index 6399f10b4..cb8c84077 100644 --- a/src/casm/database/ConfigImport.cc +++ b/src/casm/database/ConfigImport.cc @@ -403,7 +403,8 @@ const std::string Import::desc = " \"properties.calc.json\". Files will only by copied if there \n" " are no existing files or data for the configuration the \n" " structure has been mapped to, or it is the best scoring \n" - " mapping and \"overwrite\"=true.\n\n" + " mapping and \"overwrite\"=true. Copying \"properties.calc.json\" \n" + " implies \"import_properties\"=true.\n\n" " copy_additional_files: bool (optional, default=false)\n" " If true, attempt to copy all files & directories in the same \n" @@ -411,7 +412,8 @@ const std::string Import::desc = " properties.calc.json file. Files & directories will only be \n" " copied if there are no existing files or directories for the \n" " configuration the structure has been mapped to, or it is the \n" - " best scoring mapping and \"overwrite\"=true.\n\n" + " best scoring mapping and \"overwrite\"=true. Note that this \n" + " flag also requires setting \"copy_structure_files\"=true.\n\n" " overwrite: bool (optional, default=false)\n" " If true, data and files will be imported that overwrite existing\n" From 24e03aafb258fd196bd9d1c25d0b9656d682bd11 Mon Sep 17 00:00:00 2001 From: jeremiah Date: Sat, 28 Oct 2023 20:36:27 -0700 Subject: [PATCH 5/5] import with missing force data --- .../crystallography/io/SimpleStructureIO.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/casm/crystallography/io/SimpleStructureIO.cc b/src/casm/crystallography/io/SimpleStructureIO.cc index 3cb188860..e6b2989cd 100644 --- a/src/casm/crystallography/io/SimpleStructureIO.cc +++ b/src/casm/crystallography/io/SimpleStructureIO.cc @@ -175,6 +175,23 @@ static void _properties_from_json( auto it = json.find(field); if (it != json.end()) { for (auto it2 = it->begin(); it2 != it->end(); ++it2) { + Index min_data_size = 1; + bool missing_data = false; + if ( (*it2).size() < min_data_size ) { // no "value" field + missing_data = true; + } + else if ( (*it2)["value"].size() < min_data_size ) { // empty "value" + missing_data = true; + } + if (missing_data) { + if (it2.name() == "force") { + std::cout << "no force data (ignoring)\n"; + continue; + } + else { + throw std::runtime_error(it2.name()); + } + } properties[it2.name()] = (*it2)["value"].get().transpose(); }