61 std::cout << colorizer.heading(
"Compile-time features:") <<
'\n';
63 std::istringstream stream(FEATURES_STRING);
65 while (std::getline(stream, line)) {
66 if (line.find(
": enabled") != std::string::npos) {
68 size_t colonPos = line.find(
": ");
69 if (colonPos != std::string::npos) {
70 std::string featureName = line.substr(0, colonPos + 2);
71 std::string status = line.substr(colonPos + 2);
72 std::cout << featureName << colorizer.warning(status) <<
'\n';
74 std::cout << line <<
'\n';
76 }
else if (line.find(
": disabled") != std::string::npos) {
78 size_t colonPos = line.find(
": ");
79 if (colonPos != std::string::npos) {
80 std::string featureName = line.substr(0, colonPos + 2);
81 std::string status = line.substr(colonPos + 2);
82 std::cout << featureName << colorizer.error(status) <<
'\n';
84 std::cout << line <<
'\n';
87 std::cout << line <<
'\n';
95 bool sflag =
false, mflag =
false, pflag =
false, cflag =
false;
96 double optConvergedForce = 0.001;
97 std::string potential;
99 std::string confileout;
100 std::string optimizer(
"cg");
102#ifdef WITH_SERVE_MODE
103 std::optional<std::string> config_path;
104 std::optional<std::string> serve_spec;
107 std::optional<std::string> serve_host;
108 std::optional<uint16_t> serve_port;
109 std::optional<size_t> replicas;
110 std::optional<bool> gateway;
115 const char *progname = (argc ? argv[0] :
"eonclient");
117 Argum::Parser parser;
119 parser.add(Argum::Option(
"--help",
"-h")
120 .help(
"show this help message and exit")
123 auto helpText = parser.formatHelp(progname);
124 std::cout << colorizer.heading(
"eOn Client - Help")
126 std::cout << helpText;
127 std::exit(EXIT_SUCCESS);
130 parser.add(Argum::Option(
"--version",
"-v")
131 .help(
"Print version information")
133 std::cout << VERSION_STRING <<
'\n';
134 std::exit(EXIT_SUCCESS);
137 parser.add(Argum::Option(
"--features")
138 .help(
"Print compile-time features")
141 std::exit(EXIT_SUCCESS);
144 parser.add(Argum::Option(
"--minimize",
"-m")
145 .help(
"Minimization of inputConfile saves to outputConfile")
146 .handler([&]() { mflag =
true; }));
148 parser.add(Argum::Option(
"--single",
"-s")
149 .help(
"Single point energy of inputConfile")
150 .handler([&]() { sflag =
true; }));
152 parser.add(Argum::Option(
"--compare",
"-c")
153 .help(
"Compare structures of inputConfile to outputConfile")
154 .handler([&]() { cflag =
true; }));
157 Argum::Option(
"--optimizer",
"-o")
159 .help(
"Optimization method")
160 .handler([&](
const std::string_view &value) { optimizer = value; }));
162 parser.add(Argum::Option(
"--force",
"-f")
164 .help(
"Convergence force")
165 .handler([&](
const std::string_view &value) {
166 optConvergedForce = Argum::parseFloatingPoint<double>(value);
170 Argum::Option(
"--tolerance",
"-t")
172 .help(
"Distance tolerance")
173 .handler([&](
const std::string_view &value) {
178 parser.add(Argum::Option(
"--potential",
"-p")
179 .argName(
"POTENTIAL")
180 .help(
"The potential (e.g. qsc, lj, eam_al)")
181 .handler([&](
const std::string_view &value) {
186#ifdef WITH_SERVE_MODE
188 Argum::Option(
"--serve")
190 .help(
"Serve potential(s) over rgpot Cap'n Proto RPC. "
191 "Spec: 'potential:port' or 'pot1:port1,pot2:port2'")
192 .handler([&](
const std::string_view &value) { serve_spec = value; }));
195 Argum::Option(
"--serve-host")
197 .help(
"Host to bind RPC server(s) to")
198 .handler([&](
const std::string_view &value) { serve_host = value; }));
200 parser.add(Argum::Option(
"--serve-port")
202 .help(
"Port for single-potential serve mode (used with -p)")
203 .handler([&](
const std::string_view &value) {
204 serve_port = Argum::parseIntegral<uint16_t>(value);
207 parser.add(Argum::Option(
"--replicas")
209 .help(
"Number of replicated server instances (used with -p)")
210 .handler([&](
const std::string_view &value) {
211 replicas = Argum::parseIntegral<size_t>(value);
214 parser.add(Argum::Option(
"--gateway")
215 .help(
"Run a single gateway port backed by N pool instances "
216 "(use with -p and --replicas)")
217 .handler([&]() { gateway =
true; }));
219 parser.add(Argum::Option(
"--config")
221 .help(
"Config file for potential parameters (INI format, "
222 "e.g. [Metatomic] model_path=model.pt)")
223 .handler([&](
const std::string_view &value) {
232 Argum::Positional(
"confile")
233 .help(
"Input structure file")
234 .occurs(Argum::zeroOrOneTime)
235 .handler([&](
const std::string_view &value) { confile = value; }));
238 Argum::Positional(
"confileout")
239 .help(
"Output structure file (optional)")
240 .occurs(Argum::zeroOrOneTime)
241 .handler([&](
const std::string_view &value) { confileout = value; }));
244 parser.parse(argc, argv);
245 }
catch (
const Argum::ParsingException &ex) {
246 std::cerr << colorizer.error(ex.message()) <<
'\n';
247 std::cerr << colorizer.warning(parser.formatUsage(progname)) <<
'\n';
248 std::exit(EXIT_FAILURE);
255 if (sflag && mflag) {
256 std::cerr << colorizer.error(
257 "Cannot specify both minimization and single point\n");
258 std::exit(EXIT_FAILURE);
261 if (!pflag && (sflag || mflag)) {
262 std::cerr << colorizer.error(
"Must specify a potential\n");
263 std::exit(EXIT_FAILURE);
266 if (cflag && confileout.empty()) {
267 std::cerr << colorizer.error(
268 "Comparison needs two structure files: the input con file and the "
269 "one to compare it against\n");
270 std::cerr << colorizer.warning(parser.formatUsage(progname)) <<
'\n';
271 std::exit(EXIT_FAILURE);
274#ifdef WITH_SERVE_MODE
277 if (config_path.has_value()) {
278 std::ifstream config_file(config_path.value());
279 if (!config_file.is_open()) {
280 std::cerr << colorizer.error(
"Cannot open config file: ")
281 << config_path.value() <<
'\n';
282 std::exit(EXIT_FAILURE);
284 params.load(config_path.value());
288 if (serve_spec.has_value()) {
290 if (endpoints.empty()) {
291 std::cerr << colorizer.error(
"No valid serve endpoints in spec: ")
292 << serve_spec.value() <<
'\n';
293 std::exit(EXIT_FAILURE);
296 std::exit(EXIT_SUCCESS);
301 if (pflag && !sflag && !mflag && !cflag &&
302 (serve_host.has_value() || serve_port.has_value() ||
303 replicas.has_value() || gateway.has_value())) {
304 for (
auto &ch : potential) {
305 ch = std::tolower(
static_cast<unsigned char>(ch));
308 magic_enum::enum_cast<PotType>(potential, magic_enum::case_insensitive)
310 auto host = serve_host.value_or(
"localhost");
311 auto port = serve_port.value_or(12345);
312 auto reps = replicas.value_or(1);
313 bool gw = gateway.value_or(
false);
317 }
else if (reps > 1) {
322 std::exit(EXIT_SUCCESS);
326 if (!pflag && !sflag && !mflag && !cflag && config_path.has_value() &&
327 !serve_spec.has_value() &&
332 std::exit(EXIT_SUCCESS);
337 if (confile.empty()) {
338 std::cerr << colorizer.error(
339 "At least one non-option argument is required: the con file\n");
340 std::cerr << colorizer.warning(parser.formatUsage(progname)) <<
'\n';
341 std::exit(EXIT_FAILURE);
345 for (
auto &ch : potential) {
346 ch = std::tolower(
static_cast<unsigned char>(ch));
352 magic_enum::enum_cast<PotType>(potential, magic_enum::case_insensitive)
358 magic_enum::enum_cast<OptType>(optimizer, magic_enum::case_insensitive)
373 auto matter = std::make_unique<Matter>(
pot, params);
374 auto matter2 = std::make_unique<Matter>(
pot, params);
376 std::cerr <<
"Failed to load " << confile <<
'\n';
377 std::exit(EXIT_FAILURE);
383 minimize(std::move(matter), confileout);
386 std::cerr <<
"Failed to load " << confileout <<
'\n';
387 std::exit(EXIT_FAILURE);
390 if (probe.
compare(*matter2,
true)) {
391 std::cout <<
"Structures match\n";
393 std::cout << colorizer.error(
"Structures do not match\n");