3 #include <boost/filesystem.hpp>
19 namespace DoFSpaceIO {
23 : state_index(_state_index),
24 identifier(_identifier),
32 std::string
const &identifier,
34 std::vector<PermuteIterator>
const &group) {
47 DoFSpace const &dof_space, std::string
const &identifier,
49 std::optional<SymRepTools_v2::VectorSpaceSymReport>
const &sym_report) {
51 to_json(dof_space, json, identifier, config_enum_input, sym_report);
52 errors().emplace_back(state_index, identifier, dof_space.
dof_key(), e.what(),
63 fs::path output_path = fs::current_path() /
"dof_space_errors.json";
65 while (fs::exists(output_path)) {
66 output_path = fs::current_path() / (std::string(
"dof_space_errors.") +
72 for (
auto const e :
errors()) {
74 tjson[
"state_index"] = e.state_index;
75 tjson[
"identifier"] = e.identifier;
76 tjson[
"dof"] = e.dof_key;
77 tjson[
"what"] = e.what;
78 tjson[
"data"] = e.data;
81 CASM::log() <<
"Encountered " <<
errors().size() <<
" errors" << std::endl;
83 fs::ofstream outfile{output_path};
85 CASM::log() <<
"Writing: " << output_path << std::endl;
89 std::string
const &identifier,
94 _check_config(state_index, identifier, config_enum_input);
95 fs::path output_dir = _output_dir(state_index, identifier, config_enum_input);
101 fs::path output_path = output_dir /
"lattice_point_group.json";
102 fs::ofstream outfile{output_path};
104 CASM::log() <<
"Writing: " << output_path << std::endl;
111 fs::path output_path = output_dir /
"factor_group.json";
112 fs::ofstream outfile{output_path};
114 CASM::log() <<
"Writing: " << output_path << std::endl;
121 fs::path output_path = output_dir /
"crystal_point_group.json";
122 fs::ofstream outfile{output_path};
124 CASM::log() <<
"Writing: " << output_path << std::endl;
146 Index state_index, std::string
const &identifier,
148 _check_config(state_index, identifier, config_enum_input);
149 fs::path output_dir = _output_dir(state_index, identifier, config_enum_input);
151 fs::path output_path = output_dir /
"structure.json";
152 fs::ofstream outfile{output_path};
156 CASM::log() <<
"Writing: " << output_path << std::endl << std::endl;
160 Index state_index,
DoFSpace const &dof_space, std::string
const &identifier,
162 std::optional<SymRepTools_v2::VectorSpaceSymReport>
const &sym_report) {
163 _check_config(state_index, identifier, config_enum_input);
164 fs::path output_dir = _output_dir(state_index, identifier, config_enum_input);
167 to_json(dof_space, json, identifier, config_enum_input, sym_report);
169 std::string filename =
"dof_space_" + dof_space.
dof_key() +
".json";
170 fs::path output_path = output_dir / filename;
171 json.
write(output_path);
172 CASM::log() <<
"Writing: " << output_path << std::endl << std::endl;
181 Index state_index, std::string
const &identifier,
187 if (configuration.id() ==
"none") {
188 throw std::runtime_error(
189 "Error in output_dof_space: Cannot output to symmetry directory, "
190 "configuration does not exist in database. Choose a different output "
193 if (identifier != configuration.name()) {
194 throw std::runtime_error(
195 "Error in output_dof_space: Cannot output to symmetry directory, "
196 "unknown name error. Choose a different output method.");
198 if (config_enum_input.
sites().size() != configuration.
size()) {
199 throw std::runtime_error(
200 "Error in output_dof_space: Cannot output to symmetry directory, "
201 "incomplete site selection. Choose a different output method.");
207 Index state_index, std::string
const &identifier,
209 fs::path output_dir =
211 fs::create_directories(output_dir);
216 : m_output_dir(output_dir) {
218 throw std::runtime_error(
219 "Error in output_dof_space: \"dof_space\" directory "
220 "already exists. Will not overwrite.");
226 Index state_index, std::string
const &identifier,
233 Index state_index, std::string
const &identifier,
235 std::string dirname = std::string(
"state.") +
std::to_string(state_index);
236 fs::path output_dir =
m_output_dir /
"dof_space" / dirname;
237 fs::create_directories(output_dir);
242 : m_combined_json(
jsonParser::array()), m_output_dir(output_dir) {
244 if (fs::exists(output_path)) {
245 throw std::runtime_error(
246 "Error in output_dof_space: \"dof_space.json\" file "
247 "already exists. Will not overwrite.");
253 fs::ofstream outfile{output_path};
255 CASM::log() <<
"Writing: " << output_path << std::endl;
259 Index state_index, std::string
const &identifier,
279 Index state_index, std::string
const &identifier,
283 output_json[
"structure"]);
287 Index state_index,
DoFSpace const &dof_space, std::string
const &identifier,
289 std::optional<SymRepTools_v2::VectorSpaceSymReport>
const &sym_report) {
292 to_json(dof_space, output_json, identifier, config_enum_input, sym_report);
334 log <<
"Working on: " << identifier <<
" " << dof << std::endl;
336 std::optional<SymRepTools_v2::VectorSpaceSymReport> report;
340 dof_space, sym_info, group, options.
calc_wedge, report);
343 log <<
"Error: " << e.what() << std::endl;
344 log <<
"skipping: " << identifier <<
" " << dof << std::endl << std::endl;
346 input_state, report);
349 output.
write_dof_space(state_index, dof_space, identifier, input_state,
358 std::vector<std::pair<std::string, ConfigEnumInput>>
const &named_inputs,
362 Index state_index{0};
363 for (
auto const &named_input : named_inputs) {
364 std::string identifier = named_input.first;
const Lattice & ideal_lattice() const
const Supercell & supercell() const
Get the Supercell for this Configuration.
Index size() const
Returns number of sites, NOT the number of primitives that fit in here.
Specification of CASM project directory structure.
fs::path symmetry_dir() const
Return symmetry directory path.
DoFKey const & dof_key() const
jsonParser m_combined_json
jsonParser & _output_json(Index state_index)
CombinedJsonOutput(fs::path output_dir)
void write_symmetry(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input, std::vector< PermuteIterator > const &group)
void write_structure(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input) override
Write input state structure.
void write_dof_space(Index state_index, DoFSpace const &dof_space, std::string const &identifier, ConfigEnumInput const &config_enum_input, std::optional< SymRepTools_v2::VectorSpaceSymReport > const &sym_report) override
Write dof space analysis.
void write_symmetry(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input, std::vector< PermuteIterator > const &group)
void write_dof_space(Index state_index, DoFSpace const &dof_space, std::string const &identifier, ConfigEnumInput const &config_enum_input, std::optional< SymRepTools_v2::VectorSpaceSymReport > const &sym_report) override
Write dof space analysis.
void write_structure(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input) override
Write input state structure.
std::vector< Error > const & errors() const
void write_dof_space_error(make_symmetry_adapted_dof_space_error const &e, Index state_index, DoFSpace const &dof_space, std::string const &identifier, ConfigEnumInput const &config_enum_input, std::optional< SymRepTools_v2::VectorSpaceSymReport > const &sym_report)
Write dof space analysis error information.
void write_symmetry(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input, std::vector< PermuteIterator > const &group)
virtual void write_dof_space(Index state_index, DoFSpace const &dof_space, std::string const &identifier, ConfigEnumInput const &config_enum_input, std::optional< SymRepTools_v2::VectorSpaceSymReport > const &sym_report)=0
Write dof space analysis.
virtual void write_structure(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input)=0
Write input state structure.
void write_errors() const
fs::path _output_dir(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input) override
For SequentialDirectoryOutput return output directory path.
void _check_config(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input) override
For SequentialDirectoryOutput, any input state is allowed.
SequentialDirectoryOutput(fs::path output_dir)
fs::path _output_dir(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input) override
For SymmetryDirectoryOutput return output directory path in symmetry dir.
DirectoryStructure const & m_dir
void _check_config(Index state_index, std::string const &identifier, ConfigEnumInput const &config_enum_input) override
SymmetryDirectoryOutput(DirectoryStructure const &dir)
void begin(const std::string &what)
const SupercellSymInfo & sym_info() const
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
static SymGroup lattice_point_group(Lattice const &_lat)
static jsonParser object()
Returns an empty json object.
static jsonParser array()
Returns an empty json array.
void write(const std::string &file_name, unsigned int indent=2, unsigned int prec=12) const
Write json to file.
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
std::string to_string(ENUM val)
Return string representation of enum class.
std::set< Index > const & sites() const
Configuration const & configuration() const
std::vector< PermuteIterator > make_invariant_subgroup(ConfigEnumInput const &config_enum_input)
jsonParser & push_back(const T &value, Args &&... args)
void output_dof_space(Index state_index, std::string const &identifier, ConfigEnumInput const &input_state, DoFSpaceAnalysisOptions const &options, OutputImpl &output)
void dof_space_analysis(std::vector< std::pair< std::string, ConfigEnumInput >> const &named_inputs, DoFSpaceAnalysisOptions const &options, OutputImpl &output)
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.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
DoFSpace make_dof_space(DoFKey dof_key, ConfigEnumInput const &input_state, std::optional< Eigen::MatrixXd > const &basis=std::nullopt)
SymGroup make_sym_group(const PermuteIteratorContainer &container, const Lattice &supercell_lattice)
Returns a SymGroup generated from a container of PermuteIterator.
void write_symgroup(SymGroup const &grp, jsonParser &json)
INDEX_TYPE Index
For long integer indexing:
DoFSpace make_symmetry_adapted_dof_space_v2(DoFSpace const &dof_space, SupercellSymInfo const &sym_info, std::vector< PermuteIterator > const &group, bool calc_wedges, std::optional< SymRepTools_v2::VectorSpaceSymReport > &symmetry_report)
Make DoFSpace with symmetry adapated basis.
SymGroup make_point_group(const PermuteIteratorContainer &container, const Lattice &supercell_lattice)
Returns a SymGroup generated from a container of PermuteIterator.
DirectoryStructure const & dir
std::vector< std::string > dofs
Error(Index _state_index, std::string _identifier, DoFKey _dof_key, std::string _what, jsonParser _data)