2 #include <boost/algorithm/string.hpp>
11 _stream <<
"Prints the properties for a set of configurations for the set of currently selected" << std::endl
12 <<
"configurations or for a set of configurations specifed by a selection file." << std::endl
14 <<
"Property values are output in column-separated (default) or JSON format. By default, " << std::endl
15 <<
"entries for 'name' and 'selected' values are included in the output. " << std::endl
18 for(
const std::string &help_opt : help_opt_vec) {
22 if(help_opt[0] ==
'o') {
23 _stream <<
"Available operators for use within queries:" << std::endl;
26 else if(help_opt[0] ==
'p') {
27 _stream <<
"Available property tags are currently:" << std::endl;
46 (
"columns,k", po::value<std::vector<std::string> >(&
m_columns_vec)->multitoken()->zero_tokens()->value_name(
ArgHandler::query()),
"List of values you want printed as columns")
47 (
"json,j", po::value(&
m_json_flag)->default_value(
false)->zero_tokens(),
"Print in JSON format (CSV otherwise, unless output extension is .json/.JSON)")
48 (
"verbatim,v", po::value(&
m_verbatim_flag)->default_value(
false)->zero_tokens(),
"Print exact properties specified, without prepending 'name' and 'selected' entries")
49 (
"all,a",
"Print results all configurations in input selection, whether or not they are selected.")
50 (
"no-header,n", po::value(&
m_no_header_flag)->default_value(
false)->zero_tokens(),
"Print without header (CSV only)")
51 (
"alias", po::value<std::vector<std::string> >(&
m_new_alias_vec)->multitoken(),
52 "Create an alias for a query that will persist within this project. "
53 "Ex: 'casm query --alias is_Ni_dilute = lt(atom_frac(Ni),0.10001)'")
54 (
"write-pos",
"Write POS file for each configuration");
83 std::string selection_str;
85 std::vector<std::string> columns, help_opt_vec, new_alias;
87 bool json_flag(
false), no_header(
false), verbatim_flag(
false), gz_flag(
false);
94 po::store(po::parse_command_line(args.
argc, args.
argv, query_opt.
desc()), vm);
98 if(vm.count(
"help")) {
99 args.
log << std::endl << query_opt.
desc() << std::endl;
116 if(vm.count(
"help")) {
117 if(args.
root.empty()) {
118 auto dict = make_dictionary<Configuration>();
123 Log &status_log = (out_path.string() ==
"STDOUT") ? args.
err_log : args.
log;
127 std::unique_ptr<PrimClex> uniq_primclex;
128 if(out_path.string() ==
"STDOUT") {
142 catch(po::error &e) {
143 args.
err_log <<
"ERROR: " << e.what() << std::endl << std::endl;
147 catch(std::exception &e) {
148 args.
err_log <<
"Unhandled Exception reached the top of main: "
149 << e.what() <<
", application will now exit" << std::endl;
153 if(!vm.count(
"alias") && !vm.count(
"columns")) {
154 args.
log << std::endl << query_opt.
desc() << std::endl;
165 if(vm.count(
"alias")) {
170 std::string new_alias_str;
171 for(
auto const &substr : new_alias) {
172 new_alias_str += substr;
176 auto it =
std::find(new_alias_str.cbegin(), new_alias_str.cend(),
'=');
177 std::string alias_name = boost::trim_copy(std::string(new_alias_str.cbegin(), it));
178 std::string alias_command = boost::trim_copy(std::string(++it, new_alias_str.cend()));
185 catch(std::runtime_error &e) {
186 args.
err_log <<
"Unable to learn alias\n"
187 <<
" \"" << alias_name <<
" = " << alias_command <<
"\"\n"
188 << e.what() << std::endl;
193 if(!vm.count(
"columns") && !vm.count(
"write-pos")) {
194 args.
err_log <<
"ERROR: the option '--columns' or '--write-pos' is required but missing" << std::endl;
203 if(p.extension() ==
".gz" || p.extension() ==
".GZ") {
209 auto check_json = [ = ](
fs::path p) {
210 if(p.extension() ==
".json" || p.extension() ==
".JSON") {
218 if(check_gz(out_path)) {
220 json_flag = check_json(out_path.stem()) || json_flag;
223 json_flag = check_json(out_path) || json_flag;
227 std::unique_ptr<std::ostream> uniq_fout;
228 std::ostream &output_stream =
make_ostream_if(vm.count(
"output"), args.
log, uniq_fout, out_path, gz_flag);
232 Log &status_log = (out_path.string() ==
"STDOUT") ? args.
err_log : args.
log;
236 std::unique_ptr<PrimClex> uniq_primclex;
237 if(out_path.string() ==
"STDOUT") {
246 status_log <<
"Print:" << std::endl;
247 for(
int p = 0; p < columns.size(); p++) {
248 status_log <<
" - " << columns[p] << std::endl;
250 if(vm.count(
"output")) {
251 if(out_path.string() ==
"STDOUT") {
252 status_log <<
"to " << out_path << std::endl;
255 status_log <<
"to " << fs::absolute(out_path) << std::endl;
258 status_log << std::endl;
266 std::vector<std::string> all_columns;
269 all_columns.push_back(
"selected");
271 all_columns.insert(all_columns.end(), columns.cbegin(), columns.cend());
276 catch(std::exception &e) {
277 args.
err_log <<
"Parsing error: " << e.what() <<
"\n\n";
286 if(vm.count(
"write-pos")) {
287 for(
auto it = begin; it != end; ++it) {
297 json = formatter(begin, end);
299 output_stream << json;
304 output_stream << formatter(begin, end);
308 catch(std::exception &e) {
309 args.
err_log <<
"Initialization error: " << e.what() <<
"\n\n";
314 status_log <<
"\n -Output printed to terminal, since no output file specified-\n";
317 status_log <<
" DONE." << std::endl << std::endl;
void query_help(const DataFormatterDictionary< Configuration > &_dict, std::ostream &_stream, std::vector< std::string > help_opt_vec)
Data structure holding basic CASM command info.
std::vector< std::string > m_columns_vec
std::vector< std::string > m_new_alias_vec
void add_output_suboption()
Add a –output suboption. Expects to allow "STDOUT" to print to screen.
void commit() const
Save settings to project settings file.
iterator selected_config_begin()
void add_general_help_suboption()
Add a smart –help suboption that takes "properties" or "operators".
void add_configlist_suboption(const fs::path &_default="MASTER")
Add –config suboption (defaults to MASTER)
const fs::path & selection_path() const
Returns the string corresponding to add_config_suboption()
int query_command(const CommandArgs &args)
const po::options_description & desc()
Get the program options, filled with the initialized values.
Read/modify settings of an already existing CASM project.
const std::vector< std::string > & help_opt_vec() const
Returns the list of strings corresponding to add_general_help_suboption()
static std::string query()
Get value_type string for query completion.
QueryHandler< DataObject > & query_handler()
iterator selected_config_end()
po::options_description m_desc
Boost program options. All the derived classes have them, but will fill them up themselves.
ProjectSettings & settings()
bool gzip_flag() const
Returns the value assigned for add_gzip_suboption()
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
PrimClex is the top-level data structure for a CASM project.
void add_gzip_suboption()
Add a –gzip suboption. The value will default to false unless overridden by the derived class...
std::ostream & make_ostream_if(bool output, std::ostream &sout, std::unique_ptr< std::ostream > &fout, fs::path out_path, bool gzip)
Return a reference to proper std::ostream.
const std::vector< std::string > & columns_vec() const
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...
bool no_header_flag() const
void set_verbosity(int _verbosity)
void error(const std::string &what)
const fs::path output_path() const
Returns the path corresponding to add_output_suboption()
const std::vector< std::string > & new_alias_vec() const
void initialize() override
Fill in the options descriptions accordingly.
A Configuration represents the values of all degrees of freedom in a Supercell.
bool verbatim_flag() const