Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Import fix #321

Open
wants to merge 5 commits into
base: 1.X
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/casm/app/DirectoryStructure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 17 additions & 0 deletions src/casm/crystallography/io/SimpleStructureIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Eigen::MatrixXd>().transpose();
}
Expand Down
20 changes: 10 additions & 10 deletions src/casm/database/ConfigData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
33 changes: 16 additions & 17 deletions src/casm/database/ConfigImport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const std::string Import<Configuration>::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"
Expand All @@ -270,13 +270,13 @@ const std::string Import<Configuration>::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"
Expand Down Expand Up @@ -317,9 +317,8 @@ const std::string Import<Configuration>::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"
Expand Down Expand Up @@ -393,26 +392,28 @@ const std::string Import<Configuration>::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"
" mapping and \"overwrite\"=true. Copying \"properties.calc.json\" \n"
" implies \"import_properties\"=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 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"
" best scoring mapping and \"overwrite\"=true.\n\n"
" configuration the structure has been mapped to, or it is the \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"
Expand Down Expand Up @@ -521,9 +522,7 @@ const std::string Update<Configuration>::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"
Expand Down