51 py::module_ sys = py::module_::import("sys");
52
53
54 eonc::FPEHandler fpeh;
56 ase = py::module_::import(
"ase");
58 py::module_ ase_nwchem = py::module_::import("ase.calculators.nwchem");
59 py::module_ psutil = py::module_::import("psutil");
64 "Using 1 as a default multiplicity, i.e. an RHF calculation suitable for "
65 "closed shell molecules, set multiplicity or the "
66 "environment variable NWCHEM_MULTIPLICITY.\n");
67
68
69
70 py::object NWCHEM = ase_nwchem.attr("NWChem");
71 size_t nproc{0};
72 auto mult = std::stoi(nwc_mult);
73
74
76 nproc = py::cast<int>(psutil.attr("cpu_count")(false));
77 } else {
79 }
80
81
82
84 std::string mpi_cmd;
85 if (launcher == "srun") {
86
87 mpi_cmd =
88 std::format("srun -n {} {} PREFIX.nwi > PREFIX.nwo", nproc, nwchempth);
89 } else {
90
91 mpi_cmd = std::format("{} -n {} {} PREFIX.nwi > PREFIX.nwo", launcher,
92 nproc, nwchempth);
93 }
94
95 if (mult != 1 && mult != 2) {
96 throw std::runtime_error("Unknown spin multiplicity, we support 1 for "
97 "singlet and 2 for doublet ONLY.");
98 }
99
100
101
102 workDir = makeAseWorkDir(
"eon_ase_nwchem");
103
104
105 py::dict nwchem_params = py::dict(
106 "label"_a = "_eonpot_engrad",
107 "set"_a = py::dict("geom:dont_verify"_a = true),
108 "command"_a = py::str(mpi_cmd), "memory"_a = py::str("2 gb"),
109 "scf"_a = py::dict("nopen"_a = mult - 1,
112 "basis"_a = py::str("3-21G"), "task"_a = py::str("gradient"),
113 "directory"_a =
workDir.string());
114
115
116 if (mult == 2) {
117 nwchem_params["scf"]["uhf"] = py::none();
118 }
119
120 try {
121 this->
calc = NWCHEM(**nwchem_params);
122 } catch (...) {
123 std::error_code ec;
124 std::filesystem::remove_all(
workDir, ec);
126 throw;
127 }
128};
std::filesystem::path workDir
struct eonc::Parameters::ase_nwchem_options_t ase_nwchem_options
Potential(PotType a_ptype)
std::string get_value_from_env_or_param(const char *env_variable, const std::string ¶m_value, const std::string &default_value, const std::string &warning_message, const bool is_mandatory)
void ensure_interpreter()