42 return std::make_shared<Structure const>(
read_prim(project_settings));
50 std::shared_ptr<PrimType const> _shared_prim)
86 mutable std::shared_ptr<PrimNeighborList>
nlist;
92 mutable std::map<ClexDescription, ECIContainer>
eci;
99 std::shared_ptr<PrimType const> _shared_prim)
100 : m_data(new
PrimClexData(_project_settings, _shared_prim)) {
101 m_data->settings.set_crystallography_tol(
TOL);
123 m_data->vacancy_allowed =
false;
124 for (
int i = 0; i < struc_mol_name.size(); ++i) {
126 m_data->vacancy_allowed =
true;
127 m_data->vacancy_index = i;
135 bool read_settings =
false;
136 bool read_composition =
true;
137 bool read_chem_ref =
true;
138 bool read_configs =
true;
139 bool clear_clex =
false;
141 refresh(read_settings, read_composition, read_chem_ref, read_configs,
157 bool read_chem_ref,
bool read_configs,
bool clear_clex) {
161 }
catch (std::exception &e) {
168 if (read_composition) {
169 m_data->has_composition_axes =
false;
173 if (fs::is_regular_file(comp_axes_path)) {
177 m_data->has_composition_axes =
true;
181 }
catch (std::exception &e) {
183 err_log() <<
"file: " << comp_axes_path <<
"\n" << std::endl;
193 m_data->settings.default_clex().ref);
196 if (fs::is_regular_file(chem_ref_path)) {
201 }
catch (std::exception &e) {
203 err_log() <<
"file: " << chem_ref_path <<
"\n" << std::endl;
212 m_data->db_handler->close();
218 m_data->clex_basis.clear();
219 m_data->clexulator.clear();
239 return m_data->has_composition_axes;
244 return m_data->comp_converter;
251 return static_cast<bool>(
m_data->chem_ref);
265 return this->
m_data->prim_ptr;
274 m_data->nlist = std::make_shared<PrimNeighborList>(
276 settings().nlist_sublat_indices().begin(),
277 settings().nlist_sublat_indices().end());
291 template <
typename T>
296 template <
typename T>
298 return db_handler().template const_generic_db<T>();
301 template <
typename T>
306 template <
typename T>
311 template <
typename T>
313 return db_handler().template db_props<T>(calc_type);
316 template <
typename T>
318 std::string calc_type)
const {
319 return db_handler().template const_db_props<T>(calc_type);
323 if (!
m_data->db_handler) {
324 m_data->db_handler = notstd::make_unique<DB::DatabaseHandler>(*
this);
326 return *
m_data->db_handler;
330 if (!
m_data->db_handler) {
331 m_data->db_handler = notstd::make_unique<DB::DatabaseHandler>(*
this);
333 return *
m_data->db_handler;
337 auto it =
m_data->basis_set_specs.find(basis_set_name);
338 if (it ==
m_data->basis_set_specs.end()) {
339 return fs::exists(
dir().bspecs(basis_set_name));
345 std::string
const &basis_set_name)
const {
346 auto it =
m_data->basis_set_specs.find(basis_set_name);
347 if (it ==
m_data->basis_set_specs.end()) {
350 fs::path basis_set_specs_path =
dir().
bspecs(basis_set_name);
356 std::stringstream ss;
357 ss <<
"Error: Invalid file " << basis_set_specs_path;
359 std::runtime_error{ss.str()});
361 it =
m_data->basis_set_specs.emplace(basis_set_name, *parser.value).first;
367 auto it =
m_data->clexulator.find(basis_set_name);
368 if (it ==
m_data->clexulator.end()) {
370 dir().clexulator_src(
settings().project_name(), basis_set_name))) {
371 std::stringstream ss;
372 ss <<
"Error loading clexulator " << basis_set_name
373 <<
". No basis functions exist.";
374 throw std::runtime_error(ss.str());
381 }
catch (std::exception &e) {
383 err_log() <<
"Error constructing Clexulator. Current settings: \n"
398 auto it =
m_data->eci.find(key);
399 if (it ==
m_data->eci.end()) {
407 auto it =
m_data->eci.find(key);
408 if (it ==
m_data->eci.end()) {
411 if (!fs::exists(eci_path)) {
412 std::stringstream ss;
413 ss <<
"Error loading ECI. eci.json does not exist.\n Expected at: "
414 << eci_path.string();
415 throw std::runtime_error(ss.str());
420 std::stringstream ss;
421 ss <<
"Error loading ECI: Invalid file " << eci_path;
423 std::runtime_error{ss.str()});
425 it =
m_data->eci.emplace(key, *parser.value).first;
434 std::string
const &_basis_set_name,
449 template <
typename OrbitVecType>
458 clex_basis.generate(orbits.begin(), orbits.end());
473 write_clust(orbits.begin(), orbits.end(), clust_json, sites_printer,
474 basis_set_specs_json);
475 clust_json.
write(clust_json_path);
483 align, orbit_printer_options};
484 write_clust(orbits.begin(), orbits.end(), basis_json, funcs_printer,
485 basis_set_specs_json);
486 basis_json.
write(basis_json_path);
489 fs::path clexulator_src_path =
493 fs::ofstream outfile;
494 outfile.open(clexulator_src_path);
496 clexwriter.print_clexulator(clexulator_name, clex_basis, orbits,
506 std::string
const &basis_set_name,
525 std::string
const &basis_set_name,
540 #define INST_PrimClex(r, data, type) \
541 template DB::Database<type> &PrimClex::db<type>() const; \
542 template const DB::Database<type> &PrimClex::const_db<type>() const; \
543 template DB::ValDatabase<type> &PrimClex::generic_db<type>() const; \
544 template const DB::ValDatabase<type> &PrimClex::const_generic_db<type>() \
548 #define INST_PrimClexProps(r, data, type) \
549 template DB::PropertiesDatabase &PrimClex::db_props<type>( \
550 std::string calc_type) const; \
551 template const DB::PropertiesDatabase &PrimClex::const_db_props<type>( \
552 std::string calc_type) const;
#define CASM_DB_CONFIG_TYPES
std::shared_ptr< Structure const > shared_prim
PrimNeighborList const & prim_neighbor_list
#define INST_PrimClex(r, data, type)
#define INST_PrimClexProps(r, data, type)
Convert between number of species per unit cell and parametric composition.
Provides access to all databases.
Generic interface for database of a particular CASM type.
Specification of CASM project directory structure.
fs::path prim() const
Return prim.json path.
fs::path project_settings() const
Return project_settings.json path.
fs::path chemical_reference(std::string calctype, std::string ref) const
Return chemical reference file path.
fs::path eci(std::string property, std::string calctype, std::string ref, std::string bset, std::string eci) const
Returns path to eci.json.
fs::path composition_axes() const
Return composition axes file path.
fs::path bspecs(std::string bset) const
Return basis function specs (bspecs.json) file path.
fs::path clexulator_dir(std::string bset) const
Returns path to directory containing clexulator files.
A sparse container of ECI values and their corresponding orbit indices.
void error(const std::string &what)
Parsing dictionary for obtaining the correct MoleculeAttribute given a name.
The PrimNeighborList gives the coordinates of UnitCell that are neighbors of the origin UnitCell.
bool has_dir() const
Check if DirectoryStructure exists.
std::string global_clexulator_name() const
Name to use for clexulator printing.
DirectoryStructure const & dir() const
Access DirectoryStructure object. Throw if not set.
std::string compile_options() const
std::string project_name() const
Get project name.
std::string so_options() const
double crystallography_tol() const
Get current project crystallography tolerance.
Structure specifies the lattice and atomic basis of a crystal.
const Lattice & lattice() const
const std::vector< xtal::Site > & basis() const
void write(const std::string &file_name, unsigned int indent=2, unsigned int prec=12) const
Write json to file.
BasicStructure specifies the lattice and atomic basis of a crystal.
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va")
const DB::PropertiesDatabase & const_db_props(std::string calc_type) const
DB::Database< T > & db() const
DB::DatabaseHandler & db_handler() const
ProjectSettings & settings()
Index vacancy_index() const
returns the index of vacancies in composition vectors
bool has_chemical_reference() const
check if ChemicalReference object initialized
std::shared_ptr< PrimNeighborList > const & shared_nlist() const
Access to the primitive neighbor list as a shared resource.
double crystallography_tol() const
Get the crystallography_tol.
const DirectoryStructure & dir() const
Access DirectoryStructure object. Throw if not set.
std::unique_ptr< PrimClexData > m_data
Index n_basis() const
const Access to number of basis atoms
void write_basis_set_data(std::shared_ptr< Structure const > shared_prim, ProjectSettings const &settings, std::string const &basis_set_name, ClexBasisSpecs const &basis_set_specs, PrimNeighborList &prim_neighbor_list)
bool has_dir() const
Check if DirectoryStructure exists.
PrimClex(ProjectSettings const &_project_settings, std::shared_ptr< PrimType const > _shared_prim)
Initial construction of a PrimClex, from ProjectSettings and shared prim.
bool vacancy_allowed() const
returns true if vacancy are an allowed species
bool has_eci(const ClexDescription &key) const
Clexulator make_clexulator(ProjectSettings const &settings, std::string const &basis_set_name, PrimNeighborList &prim_neighbor_list)
void refresh(bool read_settings=false, bool read_composition=false, bool read_chem_ref=false, bool read_configs=false, bool clear_clex=false)
Reload PrimClex data from settings.
ClexBasisSpecs const & basis_set_specs(std::string const &basis_set_name) const
ECIContainer const & eci(const ClexDescription &key) const
const DB::DatabaseHandler & const_db_handler() const
DB::ValDatabase< T > & generic_db() const
Clexulator clexulator(std::string const &basis_set_name) const
DB::PropertiesDatabase & db_props(std::string calc_type) const
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
PrimNeighborList & nlist() const
Access to the primitive neighbor list.
std::shared_ptr< PrimType const > const & shared_prim() const
Access to the primitive Structure as a shared resource.
bool has_composition_axes() const
check if CompositionConverter object initialized
~PrimClex()
Necessary for "pointer to implementation".
void _init()
Initialization routines.
const DB::ValDatabase< T > & const_generic_db() const
const ChemicalReference & chemical_reference() const
const Access ChemicalReference object
bool has_basis_set_specs(std::string const &basis_set_name) const
const DB::Database< T > & const_db() const
const PrimType & prim() const
const Access to primitive Structure
ProjectSettings open_project_settings(fs::path path_in_project)
void print_compiler_settings_summary(ProjectSettings const &set, Log &log)
Print summary of compiler settings, as for 'casm settings -l'.
std::vector< std::string > struc_molecule_name(BasicStructure const &_struc)
Returns an Array of each possible Molecule in this Structure.
TraitsDictionary & traits_dict()
jsonParser & write_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end, jsonParser &json, Printer printer)
Write Orbit<SymCompareType> to JSON.
void for_all_orbits(ClusterSpecs const &cluster_specs, std::vector< IntegralCluster > const &generating_elements, FunctorType const &f)
void write_site_basis_funcs(std::shared_ptr< const Structure > prim_ptr, ClexBasis const &clex_basis, jsonParser &json)
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void throw_if_no_basis_set_specs(std::string basis_set_name, DirectoryStructure const &dir)
void throw_if_no_clexulator_src(std::string project_name, std::string basis_set_name, DirectoryStructure const &dir)
xtal::BasicStructure read_prim(fs::path filename, double xtal_tol, ParsingDictionary< AnisoValTraits > const *_aniso_val_dict=nullptr)
ChemicalReference read_chemical_reference(fs::path filename, const xtal::BasicStructure &prim, double tol)
Read chemical reference states from JSON file.
std::shared_ptr< Structure const > read_shared_prim(ProjectSettings const &project_settings)
CompositionAxes read_composition_axes(fs::path _filename)
void report_and_throw_if_invalid(KwargsParser const &parser, Log &log, ErrorType error)
INDEX_TYPE Index
For long integer indexing:
DirectoryStructure const & dir
PARAM_PACK_TYPE param_pack_type
Specify the Clexulator underlying data structure type.
Provides parameters for constructing a cluster expansion basis (ClexBasis)
notstd::cloneable_ptr< ClusterSpecs > cluster_specs
BasisFunctionSpecs basis_function_specs
Specifies a particular cluster expansion.
bool has_current_axes() const
True if curr_key is set.
CompositionConverter curr
Print Orbit<SymCompareType>, including only prototypes.
bool print_invariant_group
CompositionConverter comp_converter
PrimClex::PrimType PrimType
std::shared_ptr< PrimNeighborList > nlist
std::unique_ptr< DB::DatabaseHandler > db_handler
notstd::cloneable_ptr< ChemicalReference > chem_ref
std::map< BasisSetName, Clexulator > clexulator
std::shared_ptr< PrimType const > PrimType_ptr
PrimClexData(const fs::path &_root)
bool has_composition_axes
std::map< BasisSetName, ClexBasis > clex_basis
std::map< ClexDescription, ECIContainer > eci
PrimClexData(ProjectSettings const &_project_settings, std::shared_ptr< PrimType const > _shared_prim)
std::map< BasisSetName, ClexBasisSpecs > basis_set_specs
Print Orbit<SymCompareType> & ClexBasis, including prototypes and prototype basis functions.
Write clust.json, basis.json, and clexulator source code, given orbits.
ClexBasisSpecs const & basis_set_specs
PrimNeighborList & prim_neighbor_list
ProjectSettings const & settings
WriteBasisSetDataImpl(std::shared_ptr< Structure const > _shared_prim, ProjectSettings const &_settings, std::string const &_basis_set_name, ClexBasisSpecs const &_basis_set_specs, PrimNeighborList &_prim_neighbor_list)
std::string const & basis_set_name
void operator()(OrbitVecType const &orbits) const
std::shared_ptr< Structure const > shared_prim