454 {
456
458 std::memcpy(
oldBox, box, 9 *
sizeof(
double));
459
463 }
464
465
466 std::map<int, int> type_map;
467 int ntypes = 0;
468 for (long i = 0; i < N; i++) {
469 if (type_map.count(atomicNrs[i]) == 0) {
470 type_map.insert({atomicNrs[i], ++ntypes});
471 }
472 }
473
474#ifdef EONMPI
475 const char *lmpargv[] = {"liblammps", "-log", "none", "-echo", "log",
476 "-screen", "none", "-suffix", "omp"};
477 int lmpargc = sizeof(lmpargv) / sizeof(const char *);
478 if (!lmp.open_mpi) {
479 throw std::runtime_error(
480 "LAMMPS library found but lacks MPI support (lammps_open not found).\n"
481 "Install an MPI-enabled LAMMPS build.");
482 }
483 MPI_Comm inst_comm = MPI_COMM_NULL;
484 MPI_Comm_dup(mpiComm, &inst_comm);
486 lmp.open_mpi(lmpargc, const_cast<char **>(lmpargv), inst_comm, nullptr);
487#else
488 const char *lmpargv[] = {"liblammps", "-log", "none", "-echo",
489 "log", "-screen", "none"};
490 int lmpargc = sizeof(lmpargv) / sizeof(const char *);
491 LAMMPSObj = lmp.open_no_mpi(lmpargc,
const_cast<char **
>(lmpargv),
nullptr);
492#endif
493
495 std::string cmd = std::format(
"package omp {} force/neigh",
lammpsThr);
497 }
498
499
501 if (std::filesystem::exists("in.lammps")) {
502 std::ifstream infile("in.lammps");
503 std::string line;
504 while (std::getline(infile, line)) {
505 if (line == "#!units real") {
507 break;
508 }
509 }
510 } else {
511 EONC_LOG_ERROR(
"[LAMMPS] in.lammps not found in working directory");
512 return;
513 }
514
517 } else {
519 }
520
521 lmp.command(
LAMMPSObj,
"atom_style charge");
522 lmp.command(
LAMMPSObj,
"atom_modify map array sort 0 0");
523 lmp.command(
LAMMPSObj,
"neigh_modify delay 1");
524
525
526 std::string region_cmd =
527 std::format("region cell prism 0 {} 0 {} 0 {} {} {} {} units box", box[0],
528 box[4], box[8], box[3], box[6], box[7]);
529 lmp.command(
LAMMPSObj, region_cmd.c_str());
530
531 std::string create_box_cmd = std::format("create_box {} cell", ntypes);
532 lmp.command(
LAMMPSObj, create_box_cmd.c_str());
533
534
535 for (long i = 0; i < N; i++) {
536 std::string atom_cmd =
537 std::format("create_atoms {} single {} {} {} units box",
538 type_map[atomicNrs[i]], 0.0, 0.0, 0.0);
539 lmp.command(
LAMMPSObj, atom_cmd.c_str());
540 }
541
543
544
546
547
548 lmp.command(
LAMMPSObj,
"variable fx atom fx");
549 lmp.command(
LAMMPSObj,
"variable fy atom fy");
550 lmp.command(
LAMMPSObj,
"variable fz atom fz");
551 lmp.command(
LAMMPSObj,
"variable pe equal pe");
552}
#define EONC_LOG_ERROR(...)