152 const std::vector<const Segment*>& linkers,
153 const Segment& seg2_positioned)
const {
154 std::vector<Segment> results;
155 if (linkers.empty()) {
160 results.reserve(linkers.size());
167 const Segment* previous_positioned = &seg1_positioned;
168 for (
const Segment* current_raw : linkers) {
170 *previous_positioned, current_raw->
getId());
172 *current_raw, previous_positioned->
getId());
177 Eigen::Vector3d expected_partner_pos =
186 Eigen::Vector3d shift =
189 Segment current_shifted = *current_raw;
191 results.push_back(current_shifted);
192 previous_positioned = &results.back();
209 std::string ipodcoupling_work_dir =
"OR_FILES";
210 std::string frame_dir =
211 "frame_" + boost::lexical_cast<std::string>(top.
getStep());
219 std::vector<tools::Property*> segment_list = job_input.
Select(
"segment");
220 Index ID_A = segment_list.front()->getAttribute<
Index>(
"id");
221 Index ID_B = segment_list.back()->getAttribute<
Index>(
"id");
223 std::string qmgeo_state_A =
"n";
224 if (segment_list.front()->exists(
"qm_geometry")) {
226 segment_list.front()->getAttribute<std::string>(
"qm_geometry");
228 std::string qmgeo_state_B =
"n";
229 if (segment_list.back()->exists(
"qm_geometry")) {
231 segment_list.back()->getAttribute<std::string>(
"qm_geometry");
240 if (pair ==
nullptr) {
242 "No pair " + std::to_string(ID_A) +
":" +
243 std::to_string(ID_B) +
" found in the neighbor list.");
251 std::string pair_dir =
252 (boost::format(
"%1%%2%%3%%4%%5%") %
"pair" %
"_" % ID_A %
"_" % ID_B)
254 std::filesystem::path arg_path;
255 std::string orbFileAB =
256 (arg_path / ipodcoupling_work_dir /
"pairs_ipodcoupling" / frame_dir /
257 (boost::format(
"%1%%2%%3%%4%%5%") %
"pair_" % ID_A %
"_" % ID_B %
".orb")
260 std::string package_append =
"workdir_" +
Identify();
261 std::string work_dir =
262 (arg_path / ipodcoupling_work_dir / package_append / frame_dir / pair_dir)
267 const Segment* seg1 = pair->Seg1();
268 Segment seg2 = pair->Seg2PbCopy();
275 bool seg1_has_any_bonds =
false;
276 for (
const Atom& atom : *seg1) {
277 if (atom.getBondedPartnerIds()[0] != -1) {
278 seg1_has_any_bonds =
true;
282 bool seg2_has_any_bonds =
false;
283 for (
const Atom& atom : seg2) {
284 if (atom.getBondedPartnerIds()[0] != -1) {
285 seg2_has_any_bonds =
true;
289 if (!seg1_has_any_bonds && !seg2_has_any_bonds) {
291 <<
"WARNING: neither segment " << seg1->
getId() <<
" nor segment "
293 <<
" has any MD-level bond connectivity; H-saturation of cut "
294 "segment boundaries will do nothing for this pair. The topology "
295 "reader used at xtp_map time probably provided no bond data."
302 std::vector<Segment> positioned_linkers;
305 if (!linkers.empty()) {
310 std::vector<const Segment*> segments = {seg1, &seg2};
311 for (
const Segment& linker : positioned_linkers) {
312 segments.push_back(&linker);
322 Index n_fragment_AB_atoms = qmmol.
size();
331 std::set<Index> linker_atom_ids;
332 for (
const Segment& linker : positioned_linkers) {
333 Index linker_start_atom_id = qmmol.
size();
335 for (
Index i = linker_start_atom_id; i < qmmol.
size(); i++) {
336 linker_atom_ids.insert(i);
342 std::set<Index> present_segment_ids;
343 for (
const Segment* seg : segments) {
344 present_segment_ids.insert(seg->getId());
352 for (
QMAtom& atom : qmmol) {
353 if (!atom.hasExternalBond()) {
356 if (present_segment_ids.count(atom.getExternalBondPartnerSegmentId()) > 0) {
357 atom.clearExternalBond();
372 std::vector<Index> fragment_A_atoms;
373 std::vector<Index> fragment_B_atoms;
374 for (
const QMAtom& atom : relaxed) {
375 Index owning_atom_id = atom.getId();
376 if (owning_atom_id >= n_original_atoms) {
379 if (linker_atom_ids.count(owning_atom_id) > 0) {
382 if (owning_atom_id < n_fragment_A_atoms) {
383 fragment_A_atoms.push_back(atom.getId());
384 }
else if (owning_atom_id < n_fragment_AB_atoms) {
385 fragment_B_atoms.push_back(atom.getId());
390 orbitalsAB.
QMAtoms() = relaxed;
393 std::string qmpackage_work_dir = work_dir;
401 std::string
package = dftpackage_options_.get("name").as<std::string>();
403 qmpackage->setLog(&dft_logger);
404 qmpackage->setRunDir(qmpackage_work_dir);
408 std::filesystem::create_directories(qmpackage_work_dir);
413 if (qmpackage->GuessRequested()) {
415 <<
"A DFT guess was requested in the dftpackage options, but "
416 "IPodCoupling does not support it (the saturating H atoms "
417 "have no monomer orbitals). Using the DFT package's default "
418 "starting guess instead."
421 qmpackage->WriteInputFile(orbitalsAB);
426 bool run_dft_status = qmpackage->Run();
427 if (!run_dft_status) {
428 SetJobToFailed(jres, pLog, qmpackage->getPackageName() +
" run failed");
435 bool parse_log_status = qmpackage->ParseLogFile(orbitalsAB);
436 if (!parse_log_status) {
440 bool parse_orbitals_status = qmpackage->ParseMOsFile(orbitalsAB);
441 if (!parse_orbitals_status) {
446 qmpackage->CleanUp();
451 }
catch (std::runtime_error&) {
453 "Do input: failed loading orbitals from " + orbFileAB);
459 std::filesystem::create_directories(
460 std::filesystem::path(orbFileAB).parent_path());
476 <<
"PODCoupling: fragment_A_atoms (" << fragment_A_atoms.size()
477 <<
" atoms):" << std::flush;
478 for (
Index a : fragment_A_atoms) {
482 <<
"PODCoupling: fragment_B_atoms (" << fragment_B_atoms.size()
483 <<
" atoms):" << std::flush;
484 for (
Index b : fragment_B_atoms) {
487 if (!linker_atom_ids.empty()) {
489 <<
"PODCoupling: linker_atom_ids, excluded from both fragments ("
490 << linker_atom_ids.size() <<
" atoms):" << std::flush;
491 for (
Index l : linker_atom_ids) {
496 PODCoupling pod(orbitalsAB, &pLog, fragment_A_atoms, fragment_B_atoms);
524 coupling.
setAttribute(
"j", (boost::format(
"%1$1.6e") % J_ev).str());
527 }
catch (std::runtime_error& error) {
528 SetJobToFailed(jres, pLog, std::string(
"PODCoupling: ") + error.what());