24 if (!std::regex_match(project_name, std::regex(R
"([_a-zA-Z]\w*)"))) {
33 throw std::runtime_error(
34 std::string(
" Invalid Project name: '") + project_name +
36 " Must be a valid C++ identifier: \n"
37 " - only alphanumeric characters and underscores allowed\n"
38 " - cannot start with a number");
43 : m_project_name(project_name),
44 m_crystallography_tol(
CASM::
TOL),
46 m_default_database_name(
"jsonDB") {
51 : m_project_name(project_name),
53 m_crystallography_tol(
CASM::
TOL),
55 m_default_database_name(
"jsonDB") {
67 throw std::runtime_error(
68 "Error accessing DirectoryStructure from ProjectSettings: Does not "
75 m_dir = notstd::make_cloneable<DirectoryStructure>(root);
98 std::vector<std::string>
const &_required_properties) {
102 std::map<std::string, ClexDescription>
const &
112 return m_clex.find(clex_name)->second;
190 return cxx().first +
" " +
cxxflags().first +
" " +
197 return cxx().first +
" " +
soflags().first +
" " +
225 std::string _default_database_name) {
245 std::string alias_name,
246 std::string alias_value) {
251 template <
typename DataObject>
270 for (
auto const &value : type_it->second) {
277 template <
typename DataObject>
327 m_cxx = std::make_pair(opt,
"project_settings");
332 m_cxxflags = std::make_pair(opt,
"project_settings");
337 m_soflags = std::make_pair(opt,
"project_settings");
343 m_casm_libdir = std::make_pair(prefix /
"lib",
"project_settings");
359 m_boost_libdir = std::make_pair(prefix /
"lib",
"project_settings");
401 for (
auto const &pair : cluster_expansions) {
409 std::string _wdefaultval(std::string
name,
410 std::pair<std::string, std::string> val) {
411 return name +
": '" + val.first +
"' (" + val.second +
")\n";
414 std::string _wdefaultval(std::string
name,
415 std::pair<fs::path, std::string> val) {
416 return _wdefaultval(
name, std::make_pair(val.first.string(), val.second));
437 for (
auto it = clex.begin(); it != clex.end(); ++it) {
439 bool is_default = (
desc.
name == default_clex_name);
450 for (
int i = 0; i < all_bset.size(); i++) {
452 if (all_bset[i] == default_desc.
bset) {
462 for (
int i = 0; i < all_calctype.size(); i++) {
463 std::vector<std::string> all_ref =
set.
dir().
all_ref(all_calctype[i]);
464 for (
int j = 0; j < all_ref.size(); j++) {
465 log << all_calctype[i] <<
" / " << all_ref[j];
466 if (all_calctype[i] == default_desc.
calctype &&
467 all_ref[j] == default_desc.
ref) {
476 std::vector<std::string> all_eci =
478 default_desc.
ref, default_desc.
bset);
480 for (
int i = 0; i < all_eci.size(); i++) {
482 if (all_eci[i] == default_desc.
eci) {
489 log <<
"*: indicates the default settings used by CASM whenever particular \n"
490 "settings are not explicitly specified (i.e. the basis set to "
492 "for 'casm query -k corr')\n\n";
515 [&](std::string
name,
516 std::pair<std::string, std::string> value_and_source) {
517 if (value_and_source.second ==
"project_settings") {
518 json[
name] = value_and_source.first;
522 auto _write_path_if = [&](std::string
name,
523 std::pair<fs::path, std::string> value_and_source) {
524 if (value_and_source.second ==
"project_settings") {
525 json[
name] = value_and_source.first.string();
529 _write_str_if(
"cxx",
set.
cxx());
540 json[
"crystallography_tol"].set_scientific();
542 json[
"lin_alg_tol"].set_scientific();
554 if (json.
contains(
"required_properties") &&
555 json[
"required_properties"].
size()) {
556 auto it = json.
find(
"required_properties");
559 settings.set_required_properties(tmp);
563 if (json.
contains(
"cluster_expansions") &&
564 json[
"cluster_expansions"].
size()) {
565 auto it = json.
find(
"cluster_expansions");
566 auto clex_it = it->begin();
567 auto clex_end = it->end();
568 for (; clex_it != clex_end; ++clex_it) {
572 if (json.
contains(
"default_clex")) {
573 settings.set_default_clex_name(json[
"default_clex"].get<std::string>());
575 if (settings.has_clex(
"formation_energy")) {
576 settings.set_default_clex_name(
"formation_energy");
578 settings.set_default_clex_name(
579 settings.cluster_expansions().begin()->first);
586 settings.insert_clex(
desc);
587 settings.set_default_clex_name(
desc.name);
593 if (json.
get_if(tmp_str,
"cxx")) {
594 settings.set_cxx(tmp_str);
596 if (json.
get_if(tmp_str,
"cxxflags")) {
597 settings.set_cxxflags(tmp_str);
599 if (json.
get_if(tmp_str,
"soflags")) {
600 settings.set_soflags(tmp_str);
604 if (json.
get_if(tmp_path,
"casm_prefix")) {
605 settings.set_casm_prefix(tmp_path);
607 if (json.
get_if(tmp_path,
"boost_prefix")) {
608 settings.set_boost_prefix(tmp_path);
610 if (json.
get_if(tmp_path,
"casm_includedir")) {
611 settings.set_casm_includedir(tmp_path);
613 if (json.
get_if(tmp_path,
"casm_libdir")) {
614 settings.set_casm_libdir(tmp_path);
616 if (json.
get_if(tmp_path,
"boost_includedir")) {
617 settings.set_boost_includedir(tmp_path);
619 if (json.
get_if(tmp_path,
"boost_libdir")) {
620 settings.set_boost_libdir(tmp_path);
624 if (json.
get_if(tmp_str,
"view_command")) {
625 settings.set_view_command(tmp_str);
627 if (json.
get_if(tmp_str,
"view_command_video")) {
628 settings.set_view_command_video(tmp_str);
632 double tmp_double =
TOL;
633 json.
get_if(tmp_double,
"crystallography_tol");
634 settings.set_crystallography_tol(tmp_double);
636 json.
get_else(tmp_double,
"lin_alg_tol", 1e-10);
637 settings.set_lin_alg_tol(tmp_double);
640 if (json.
contains(
"nlist_weight_matrix")) {
641 settings.set_nlist_weight_matrix(
642 json[
"nlist_weight_matrix"].get<Eigen::Matrix3l>());
644 if (json.
contains(
"nlist_sublat_indices")) {
645 settings.set_nlist_sublat_indices(
646 json[
"nlist_sublat_indices"].
get<std::set<int>>());
650 if (json.
contains(
"query_alias") && json[
"query_alias"].
size()) {
651 auto it = json.
find(
"query_alias");
654 settings.set_query_alias(tmp);
659 }
catch (std::exception &e) {
660 err_log() <<
"Error reading ProjectSettings from JSON." << std::endl;
666 fs::path project_settings_path) {
671 file.
open(project_settings_path);
678 fs::ifstream file{project_settings_path};
681 }
catch (std::exception &e) {
682 err_log() <<
"Error reading ProjectSettings from: '"
683 << project_settings_path <<
"'" << std::endl;
694 if (checkroot.empty()) {
695 throw std::runtime_error(std::string(
"Error in open_project_settings:") +
696 " No CASM project includes path: '" +
697 path.string() +
"'");
709 #define INST_ProjectSettings_all(r, data, type) \
710 template QueryHandler<type> &ProjectSettings::query_handler<type>(); \
711 template const QueryHandler<type> &ProjectSettings::query_handler<type>() \
#define INST_ProjectSettings_all(r, data, type)
Specification of CASM project directory structure.
fs::path root_dir() const
Return casm project directory path.
std::vector< std::string > all_eci(std::string property, std::string calctype, std::string ref, std::string bset) const
Check filesystem directory structure and return list of all eci names.
fs::path project_settings() const
Return project_settings.json path.
std::vector< std::string > all_calctype() const
Check filesystem directory structure and return list of all calctype names.
bool new_casm_dir() const
Create new project data directory.
std::vector< std::string > all_bset() const
Check filesystem directory structure and return list of all basis set names.
bool new_reports_dir() const
Create new reports directory.
bool new_symmetry_dir() const
Create new symmetry directory.
std::vector< std::string > all_ref(std::string calctype) const
Check filesystem directory structure and return list of all ref names for a given calctype.
void custom(const std::string &what)
static const int standard
void set_query_alias(query_alias_map_type const &_query_alias)
notstd::cloneable_ptr< Eigen::Matrix3l > m_nlist_weight_matrix
std::pair< fs::path, std::string > boost_includedir() const
Get boost includedir (pair of value and source for the value)
double lin_alg_tol() const
Get current project linear algebra tolerance.
ClexDescription const & clex(std::string clex_name) const
Get a ClexDescription by name.
notstd::cloneable_ptr< std::set< int > > m_nlist_sublat_indices
std::pair< std::string, std::string > m_soflags
std::string view_command() const
Get current command used by 'casm view'.
bool set_crystallography_tol(double _tol)
Set crystallography tolerance.
bool set_view_command(std::string opt)
Set command used by 'casm view'.
bool has_dir() const
Check if DirectoryStructure exists.
std::pair< fs::path, std::string > casm_libdir() const
Get casm libdir (pair of value and source for the value)
bool insert_clex(ClexDescription const &desc)
notstd::cloneable_ptr< notstd::Cloneable > m_hamiltonian_modules
Eigen::Matrix3l nlist_weight_matrix() const
Get neighbor list weight matrix.
bool set_nlist_sublat_indices(std::set< int > value)
std::map< std::string, ClexDescription > const & cluster_expansions() const
Const access map of all ClexDescription.
notstd::cloneable_ptr< DirectoryStructure > m_dir
bool set_cxxflags(std::string opt)
Set c++ compiler options (empty string to use default)
std::map< std::string, notstd::cloneable_ptr< notstd::Cloneable > > m_query_handler
std::string default_clex_name() const
Get default ClexDescription name.
bool set_boost_libdir(fs::path dir)
Set boost libdir (empty string to use default)
bool has_m_nlist_weight_matrix() const
Check if neighbor list weight matrix exists.
std::string global_clexulator_name() const
Name to use for clexulator printing.
required_properties_map_type m_required_properties
double m_crystallography_tol
DirectoryStructure const & dir() const
Access DirectoryStructure object. Throw if not set.
EnumeratorHandler & enumerator_handler()
std::pair< std::string, std::string > m_cxx
std::string compile_options() const
bool set_boost_prefix(fs::path dir)
Set boost prefix (empty string to use default)
HamiltonianModules & hamiltonian_modules()
query_alias_map_type const & query_alias() const
bool set_nlist_weight_matrix(Eigen::Matrix3l M)
std::pair< fs::path, std::string > casm_includedir() const
Get casm includedir (pair of value and source for the value)
std::string m_view_command_video
notstd::cloneable_ptr< notstd::Cloneable > m_enumerator_handler
bool set_default_clex_name(std::string const &clex_name)
Set default ClexDescription by name.
std::string m_default_clex_name
std::pair< fs::path, std::string > boost_libdir() const
Get boost libdir (pair of value and source for the value)
query_alias_map_type m_query_alias
bool set_casm_includedir(fs::path dir)
Set casm includedir (empty string to use default)
std::string m_default_database_name
std::map< ObjectTypeName, std::map< QueryAliasName, QueryAliasValue > > query_alias_map_type
std::map< ObjectTypeName, std::map< CalcTypeName, std::vector< std::string > > > required_properties_map_type
std::pair< fs::path, std::string > m_boost_includedir
std::string m_view_command
std::string project_name() const
Get project name.
std::map< std::string, ClexDescription > m_clex
std::pair< fs::path, std::string > m_boost_libdir
std::string m_project_name
bool set_casm_prefix(fs::path dir)
Set casm prefix (empty string to use default)
bool has_clex(std::string clex_name) const
Check if a ClexDescription exists.
ClexDescription const & default_clex() const
Get default ClexDescription.
fs::path root_dir() const
Access dir().root_dir(). Throw if not set.
QueryHandler< DataObject > & query_handler()
std::pair< std::string, std::string > soflags() const
Get shared object options (pair of value and source for the value)
std::pair< std::string, std::string > m_cxxflags
required_properties_map_type const & required_properties() const
bool has_nlist_sublat_indices() const
Check if set of sublattice indices to include in neighbor lists exists.
bool set_view_command_video(std::string opt)
Set video viewing command used by 'casm view'.
std::pair< fs::path, std::string > m_casm_includedir
bool set_lin_alg_tol(double _tol)
Set linear algebra tolerance.
std::string so_options() const
std::set< int > const & nlist_sublat_indices() const
Get set of sublattice indices to include in neighbor lists.
std::pair< std::string, std::string > cxx() const
Get c++ compiler (pair of value and source for the value)
bool set_default_clex(ClexDescription const &desc)
double crystallography_tol() const
Get current project crystallography tolerance.
bool set_soflags(std::string opt)
Set shared object options (empty string to use default)
void set_default_database_name(std::string _default_database_name)
Set default database type name (for future)
std::pair< fs::path, std::string > m_casm_libdir
void set_required_properties(required_properties_map_type const &_required_properties)
bool erase_clex(ClexDescription const &desc)
bool set_casm_libdir(fs::path dir)
Set casm libdir (empty string to use default)
bool set_boost_includedir(fs::path dir)
Set boost includedir (empty string to use default)
bool set_cxx(std::string opt)
Set c++ compiler (empty string to use default)
bool set_root_dir(fs::path root)
Set DirectoryStructure.
std::pair< std::string, std::string > cxxflags() const
Get c++ compiler options (pair of value and source for the value)
ProjectSettings(std::string project_name)
std::string view_command_video() const
Get current video viewing command used by 'casm view'.
std::string default_database_name() const
Get default database type name.
void add_alias(const std::string &alias_name, const std::string &alias_command)
Add user-defined query alias.
static std::pair< std::string, std::string > default_soflags()
Default c++ compiler options.
static std::pair< fs::path, std::string > default_boost_includedir()
Return default includedir for boost.
static std::pair< std::string, std::string > default_cxxflags()
Default c++ compiler options.
static std::pair< fs::path, std::string > default_casm_includedir()
Return default includedir for CASM.
static std::pair< fs::path, std::string > default_boost_libdir()
Return default libdir for boost.
static std::pair< std::string, std::string > default_cxx()
Return default compiler.
static std::pair< fs::path, std::string > default_casm_libdir()
Return default libdir for CASM.
Write to a temporary file to ensure a good write, then rename.
void close()
Closes stream, and if not a failed write, removes "file" and renames "file.tmp" to "file".
void open(fs::path name, std::string tmp_ext="tmp")
Opens "file.tmp" for writing, with intended final target "file".
fs::ofstream & ofstream()
Access underlying stream.
static jsonParser object()
Returns an empty json object.
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
iterator find(const std::string &name)
Return iterator to JSON object value with 'name'.
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
void commit(ProjectSettings const &set)
ProjectSettings open_project_settings(fs::path path_in_project)
void print_summary(ProjectSettings const &set, Log &log)
Print summary of ProjectSettings, as for 'casm settings -l'.
bool is_valid_project_name(std::string project_name)
bool create_all_directories(ProjectSettings const &set)
void throw_if_project_name_is_not_valid(std::string project_name)
Throw if project name is invalid.
void print_compiler_settings_summary(ProjectSettings const &set, Log &log)
Print summary of compiler settings, as for 'casm settings -l'.
void write_project_settings(ProjectSettings const &set, fs::path project_settings_path)
ProjectSettings read_project_settings(fs::path project_settings_path)
bool get_if(T &t, const std::string &key, Args &&... args) const
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.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
std::string include_path(const fs::path &dir)
DoFSpecsType const & get(DoFKey const &key, BasisFunctionSpecs const &basis_function_specs)
GenericDatumFormatter< std::string, DataObject > name()
fs::path find_casmroot(const fs::path &cwd)
std::string link_path(const fs::path &dir)
void from_json(ClexDescription &desc, const jsonParser &json)
bool new_dir(const DirectoryStructure &dir, ClexDescription const &desc)
ClexDescription default_configuration_clex()
Matrix< long int, 3, 3 > Matrix3l
Non-std smart pointer classes and functions.
std::unique_ptr< T > clone(const T &obj)
std::unique_ptr< T > make_unique(Args &&... args)
c++17 does not include 'make_unique'
DirectoryStructure const & dir
Specifies a particular cluster expansion.
void print(std::ostream &sout, bool is_default, int indent=0) const
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.