1 #include <boost/filesystem.hpp>
2 #include <boost/filesystem/fstream.hpp>
45 if (true_prim.
basis().size() < prim.
basis().size()) {
48 " The structure in the provided file is not primitive. Some "
50 " features cannot be used with a non-primitive starting "
57 return {err,
".primitive.json", true_prim};
67 if (!is_standard_niggli) {
69 " The structure in the provided file is not the Niggli cell in "
71 " standard orientation.\n\n";
76 return {err,
".niggli.json", tmp};
84 " The lattice vectors of the provided structure do not form a "
86 " coordinate system. Some electronic-structure codes will not "
94 return {err,
".right_handed.json", tmp};
97 return {err,
"", prim};
100 namespace Completer {
113 "Initialize a project in sub-directory of an existing project. After "
114 "initialization, commands executed below the sub-directory will act on "
115 "the sub-directory project; commmands executed above the sub-directory "
116 "act on the original project.")(
118 "Create prim.json file for specified configuration(s). Each prim.json is "
119 "written to the training_data directory of the corresponding "
121 "Utilize relaxed coordinates for writing "
122 "configuration-specific prim.json files.")(
124 "Keep multi-atom species as molecules. By default, multi-atom species "
125 "are split into constituent atoms.")(
127 "Print sites that can only be vacancies; otherwise these sites are "
130 "Force using a non-reduced, non-primitive, or left-handed PRIM.");
141 po::variables_map vm;
147 po::store(po::parse_command_line(args.
argc(), args.
argv(), init_opt.
desc()),
152 if (vm.count(
"help")) {
154 log() << init_opt.
desc() << std::endl;
159 if (vm.count(
"desc")) {
161 log() << init_opt.
desc() << std::endl;
165 <<
" Initialize a new CASM project in the current directory.\n"
166 <<
" - Expects a prim.json file in the current directory \n"
167 <<
" - If not found, looks for a PRIM file in the current \n"
168 <<
" directory and creates prim.json. \n\n";
175 }
catch (po::error &e) {
176 err_log() <<
"ERROR: " << e.what() << std::endl << std::endl;
179 }
catch (std::exception &e) {
180 err_log() <<
"Unhandled Exception reached the top of main: " << e.what()
181 <<
", application will now exit" << std::endl;
185 fs::path root = fs::current_path();
188 }
else if (!args.
root.empty()) {
193 if (vm[
"config"].defaulted() && init_opt.
config_strs().empty()) {
199 }
catch (std::exception &e) {
200 err_log() << e.what() << std::endl;
205 std::map<DoFKey, xtal::DoFSet> new_global_dofs = prim.
global_dofs();
206 std::map<DoFKey, xtal::SiteDoFSet> new_site_dofs;
207 for (std::string
const &doftype : init_opt.
dof_strs()) {
209 if (ttraits.
global() && !new_global_dofs.count(doftype))
210 new_global_dofs.emplace(doftype, ttraits);
212 new_site_dofs.emplace(doftype, ttraits);
217 std::map<DoFKey, xtal::SiteDoFSet> site_dofs = site.dofs();
218 site_dofs.insert(new_site_dofs.begin(), new_site_dofs.end());
219 site.set_dofs(std::move(site_dofs));
224 std::string extension;
225 std::tie(err_msg, extension, prim) =
229 if (!err_msg.empty()) {
230 if (vm.count(
"force")) {
232 <<
" failed the following check(s): \n"
234 <<
"Continuing due to usage of '--force' modifier.\n\n";
236 std::string new_path = init_opt.
prim_path().string();
237 std::string tpath = new_path.substr(0, new_path.find(
".json"));
238 new_path = tpath.substr(0, new_path.find(
".JSON"));
239 new_path += extension;
242 <<
"Standardizing structure and writing to JSON file: "
246 err_log() <<
"To initialize your project anyway, use the --force "
256 log() << json_prim << std::endl;
258 log() <<
"\n***************************\n" << std::endl;
260 root = fs::current_path();
266 if (existing == root) {
267 log() <<
"Directory '" << root
268 <<
"' is already the head directory of a casm project."
272 if (existing.empty()) {
273 log() <<
"Cannot create sub-directory project at '" << root
274 <<
"' because no existing project was found at a higher level."
276 <<
"To initialize a top-level project, try again without the --"
280 }
else if (!existing.empty()) {
281 log() <<
"Already in a casm project. To create a project at " << root
290 log() <<
"Please enter a short title for this project.\n";
291 log() <<
" Use something suitable as a prefix for files specific to "
292 "this project, such as 'ZrO' or 'TiAl'.\n\n";
300 log() <<
"Initializing CASM project '" << prim.
title() <<
"'"
302 auto project_settings =
305 }
catch (std::runtime_error &e) {
306 err_log() <<
"ERROR: Could not build CASM project.\n";
307 err_log() << e.what() << std::endl;
311 log() <<
" DONE" << std::endl;
315 log() <<
"\n***************************\n" << std::endl;
321 std::unique_ptr<PrimClex> uniq_primclex;
331 SimpleStructure::SpeciesMode::ATOM;
333 species_mode = SimpleStructure::SpeciesMode::MOL;
340 fs::create_directories(config_dir);
341 }
catch (
const fs::filesystem_error &ex) {
342 err_log() <<
"Error making directory " << config_dir << std::endl;
343 err_log() << ex.what() << std::endl;
346 std::string prim_title =
config.name();
347 auto it = prim_title.begin();
348 for (; it != prim_title.end(); ++it) {
355 prim_title.insert(it,
'_');
362 log() <<
"Wrote file " << (config_dir /
"prim.json") << std::endl;
#define ERR_INVALID_INPUT_FILE
Specifies traits of (possibly) anisotropic crystal properties.
bool global() const
Returns true if type is global.
COORD_TYPE coordtype_enum() const
Return the coordinate type recasted as the CASM defined enum.
const std::vector< std::string > & config_strs() const
void initialize() override
Fill in the options descriptions accordingly.
const fs::path & selection_path() const
Returns the string corresponding to add_config_suboption()
const fs::path & prim_path() const
Returns the string corsresponding to add_prim_path_suboption()
const std::vector< std::string > & dof_strs() const
Returns the names of the DoF type names for add_dofs_suboption()
const fs::path & file_path() const
Returns the string corsresponding to add_file_path_suboption()
void add_prim_path_suboption(const fs::path &_default="")
Add –prim suboption.
void add_confignames_suboption()
Add a –confignames suboption.
const po::options_description & desc()
Get the program options, filled with the initialized values.
void add_help_suboption()
Add a plain –help and –desc suboptions.
po::options_description m_desc
void add_configlist_suboption(const fs::path &_default="MASTER")
Add –config suboption (defaults to MASTER)
void add_coordtype_suboption()
Add a –coord suboption to specify FRAC or CART.
void add_dofs_suboption()
Add a –dofs suboption to specify DoF Types.
void add_file_path_suboption(const fs::path &_default="")
Add –path suboption (defaults to MASTER)
boost::iterator_range< iterator > selected()
Specification of CASM project directory structure.
fs::path configuration_dir(std::string configname) const
Return configuration directory path.
PrimClex is the top-level data structure for a CASM project.
Structure specifies the lattice and atomic basis of a crystal.
BasicStructure specifies the lattice and atomic basis of a crystal.
void set_lattice(const Lattice &lattice, COORD_TYPE mode)
std::map< DoFKey, DoFSet > const & global_dofs() const
std::vector< Site > & set_basis()
const std::string & title() const
void set_title(std::string const &_title)
Set the title of the structure.
void within()
Translate all basis sites so that they are inside the unit cell.
const Lattice & lattice() const
void set_global_dofs(std::map< DoFKey, DoFSet > const &new_dof_map)
Manually set the global DoFs.
const std::vector< Site > & basis() const
bool is_right_handed() const
Check if the lattice is right handed.
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Lattice & make_right_handed()
Flip c vector if it's on the wrong side of a-b plane – return (*this)
Representation of a crystal of molecular and/or atomic occupants, and any additional properties....
PrimClex & make_primclex_if_not(const CommandArgs &args, std::unique_ptr< PrimClex > &uniq_primclex)
If !_primclex, construct new PrimClex stored in uniq_primclex, then return reference to existing or c...
DB::Database< T > & db() const
const DirectoryStructure & dir() const
Access DirectoryStructure object. Throw if not set.
bool is_valid_project_name(std::string project_name)
ConfigIO::GenericConfigFormatter< jsonParser > config()
Lattice equivalent(Lattice const &in_lat, SymOpVector const &point_grp, double compare_tol)
BasicStructure make_basic_structure(SimpleStructure const &_sstruc, std::vector< DoFKey > const &_all_dofs, SimpleStructureTools::SpeciesMode mode, std::vector< std::vector< Molecule >> _allowed_occupants={})
Construct BasicStructure from SimpleStructure.
BasicStructure make_primitive(const BasicStructure &non_primitive_struc, double tol=TOL)
Returns the smallest possible tiling unit of the given structure.
bool almost_equal(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Check if ClusterInvariants are equal.
const std::string relaxed_opt
std::tuple< std::string, std::string, BasicStructure > standardize_prim(BasicStructure const &prim, bool force)
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.
const std::string molecule_opt
void write_prim(const xtal::BasicStructure &prim, fs::path filename, COORD_TYPE mode, bool include_va=false)
Write prim.json to file.
const std::string include_va_opt
void build_project(ProjectSettings const &project_settings, Structure const &prim)
const std::string subproject_opt
xtal::BasicStructure read_prim(fs::path filename, double xtal_tol, ParsingDictionary< AnisoValTraits > const *_aniso_val_dict=nullptr)
const std::string write_prim_opt
GenericDatumFormatter< std::string, DataObject > name()
fs::path find_casmroot(const fs::path &cwd)
ProjectSettings make_default_project_settings(xtal::BasicStructure const &prim, std::string project_name)
int init_command(const CommandArgs &args)
DirectoryStructure const & dir
Data structure holding basic CASM command info.