2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2006 - 2014, The GROMACS development team.
5 * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
39 * \brief This file defines functions used by the domdec module while
40 * building topologies local to a domain
42 * \author Berk Hess <hess@kth.se>
43 * \ingroup module_domdec
48 #include "gromacs/domdec/localtopology.h"
52 #include "gromacs/domdec/domdec_internal.h"
53 #include "gromacs/domdec/domdec_struct.h"
54 #include "gromacs/domdec/ga2la.h"
55 #include "gromacs/domdec/options.h"
56 #include "gromacs/domdec/reversetopology.h"
57 #include "gromacs/math/vec.h"
58 #include "gromacs/mdtypes/forcerec.h"
59 #include "gromacs/mdtypes/mdatom.h"
60 #include "gromacs/pbcutil/pbc.h"
61 #include "gromacs/topology/idef.h"
62 #include "gromacs/topology/mtop_util.h"
63 #include "gromacs/topology/topsort.h"
64 #include "gromacs/utility/arrayref.h"
65 #include "gromacs/utility/fatalerror.h"
66 #include "gromacs/utility/gmxassert.h"
67 #include "gromacs/utility/listoflists.h"
68 #include "gromacs/utility/strconvert.h"
71 using gmx::DDBondedChecking;
72 using gmx::ListOfLists;
75 /*! \brief Store a vsite interaction at the end of \p il
77 * This routine is very similar to add_ifunc, but vsites interactions
78 * have more work to do than other kinds of interactions, and the
79 * complex way nral (and thus vector contents) depends on ftype
80 * confuses static analysis tools unless we fuse the vsite
81 * atom-indexing organization code with the ifunc-adding code, so that
82 * they can see that nral is the same value. */
83 static inline void add_ifunc_for_vsites(t_iatom* tiatoms,
84 const gmx_ga2la_t& ga2la,
90 const t_iatom* iatoms,
94 tiatoms[0] = iatoms[0];
98 /* We know the local index of the first atom */
103 /* Convert later in make_local_vsites */
104 tiatoms[1] = -a_gl - 1;
107 GMX_ASSERT(nral >= 2 && nral <= 5, "Invalid nral for vsites");
108 for (int k = 2; k < 1 + nral; k++)
110 int ak_gl = a_gl + iatoms[k] - a_mol;
111 if (const int* homeIndex = ga2la.findHome(ak_gl))
113 tiatoms[k] = *homeIndex;
117 /* Copy the global index, convert later in make_local_vsites */
118 tiatoms[k] = -(ak_gl + 1);
120 // Note that ga2la_get_home always sets the third parameter if
123 il->push_back(tiatoms[0], nral, tiatoms + 1);
126 /*! \brief Store a position restraint in idef and iatoms, complex because the parameters are different for each entry */
127 static void add_posres(int mol,
129 int numAtomsInMolecule,
130 const gmx_molblock_t& molb,
131 gmx::ArrayRef<int> iatoms,
132 const t_iparams* ip_in,
133 InteractionDefinitions* idef)
135 /* This position restraint has not been added yet,
136 * so it's index is the current number of position restraints.
138 const int n = idef->il[F_POSRES].size() / 2;
140 /* Get the position restraint coordinates from the molblock */
141 const int a_molb = mol * numAtomsInMolecule + a_mol;
142 GMX_ASSERT(a_molb < ssize(molb.posres_xA),
143 "We need a sufficient number of position restraint coordinates");
144 /* Copy the force constants */
145 t_iparams ip = ip_in[iatoms[0]];
146 ip.posres.pos0A[XX] = molb.posres_xA[a_molb][XX];
147 ip.posres.pos0A[YY] = molb.posres_xA[a_molb][YY];
148 ip.posres.pos0A[ZZ] = molb.posres_xA[a_molb][ZZ];
149 if (!molb.posres_xB.empty())
151 ip.posres.pos0B[XX] = molb.posres_xB[a_molb][XX];
152 ip.posres.pos0B[YY] = molb.posres_xB[a_molb][YY];
153 ip.posres.pos0B[ZZ] = molb.posres_xB[a_molb][ZZ];
157 ip.posres.pos0B[XX] = ip.posres.pos0A[XX];
158 ip.posres.pos0B[YY] = ip.posres.pos0A[YY];
159 ip.posres.pos0B[ZZ] = ip.posres.pos0A[ZZ];
161 /* Set the parameter index for idef->iparams_posres */
163 idef->iparams_posres.push_back(ip);
165 GMX_ASSERT(int(idef->iparams_posres.size()) == n + 1,
166 "The index of the parameter type should match n");
169 /*! \brief Store a flat-bottomed position restraint in idef and iatoms, complex because the parameters are different for each entry */
170 static void add_fbposres(int mol,
172 int numAtomsInMolecule,
173 const gmx_molblock_t& molb,
174 gmx::ArrayRef<int> iatoms,
175 const t_iparams* ip_in,
176 InteractionDefinitions* idef)
178 /* This flat-bottom position restraint has not been added yet,
179 * so it's index is the current number of position restraints.
181 const int n = idef->il[F_FBPOSRES].size() / 2;
183 /* Get the position restraint coordinats from the molblock */
184 const int a_molb = mol * numAtomsInMolecule + a_mol;
185 GMX_ASSERT(a_molb < ssize(molb.posres_xA),
186 "We need a sufficient number of position restraint coordinates");
187 /* Copy the force constants */
188 t_iparams ip = ip_in[iatoms[0]];
189 /* Take reference positions from A position of normal posres */
190 ip.fbposres.pos0[XX] = molb.posres_xA[a_molb][XX];
191 ip.fbposres.pos0[YY] = molb.posres_xA[a_molb][YY];
192 ip.fbposres.pos0[ZZ] = molb.posres_xA[a_molb][ZZ];
194 /* Note: no B-type for flat-bottom posres */
196 /* Set the parameter index for idef->iparams_fbposres */
198 idef->iparams_fbposres.push_back(ip);
200 GMX_ASSERT(int(idef->iparams_fbposres.size()) == n + 1,
201 "The index of the parameter type should match n");
204 /*! \brief Store a virtual site interaction, complex because of PBC and recursion */
205 static void add_vsite(const gmx_ga2la_t& ga2la,
206 gmx::ArrayRef<const int> index,
207 gmx::ArrayRef<const int> rtil,
214 const t_iatom* iatoms,
215 InteractionDefinitions* idef)
217 t_iatom tiatoms[1 + MAXATOMLIST];
219 /* Add this interaction to the local topology */
220 add_ifunc_for_vsites(tiatoms, ga2la, nral, bHomeA, a, a_gl, a_mol, iatoms, &idef->il[ftype]);
222 if (iatoms[1 + nral])
224 /* Check for recursion */
225 for (int k = 2; k < 1 + nral; k++)
227 if ((iatoms[1 + nral] & (2 << k)) && (tiatoms[k] < 0))
229 /* This construction atoms is a vsite and not a home atom */
233 "Constructing atom %d of vsite atom %d is a vsite and non-home\n",
237 /* Find the vsite construction */
239 /* Check all interactions assigned to this atom */
240 int j = index[iatoms[k]];
241 while (j < index[iatoms[k] + 1])
243 int ftype_r = rtil[j++];
244 int nral_r = NRAL(ftype_r);
245 if (interaction_function[ftype_r].flags & IF_VSITE)
247 /* Add this vsite (recursion) */
255 a_gl + iatoms[k] - iatoms[1],
260 j += 1 + nral_rt(ftype_r);
267 /*! \brief Returns the squared distance between atoms \p i and \p j */
268 static real dd_dist2(const t_pbc* pbc_null, ArrayRef<const RVec> coordinates, const int i, const int j)
274 pbc_dx_aiuc(pbc_null, coordinates[i], coordinates[j], dx);
278 rvec_sub(coordinates[i], coordinates[j], dx);
284 /*! \brief Append t_idef structures 1 to nsrc in src to *dest */
285 static void combine_idef(InteractionDefinitions* dest, gmx::ArrayRef<const thread_work_t> src)
287 for (int ftype = 0; ftype < F_NRE; ftype++)
290 for (gmx::index s = 1; s < src.ssize(); s++)
292 n += src[s].idef.il[ftype].size();
296 for (gmx::index s = 1; s < src.ssize(); s++)
298 dest->il[ftype].append(src[s].idef.il[ftype]);
301 /* Position restraints need an additional treatment */
302 if (ftype == F_POSRES || ftype == F_FBPOSRES)
304 int nposres = dest->il[ftype].size() / 2;
305 std::vector<t_iparams>& iparams_dest =
306 (ftype == F_POSRES ? dest->iparams_posres : dest->iparams_fbposres);
308 /* Set nposres to the number of original position restraints in dest */
309 for (gmx::index s = 1; s < src.ssize(); s++)
311 nposres -= src[s].idef.il[ftype].size() / 2;
314 for (gmx::index s = 1; s < src.ssize(); s++)
316 const std::vector<t_iparams>& iparams_src =
317 (ftype == F_POSRES ? src[s].idef.iparams_posres : src[s].idef.iparams_fbposres);
318 iparams_dest.insert(iparams_dest.end(), iparams_src.begin(), iparams_src.end());
320 /* Correct the indices into iparams_posres */
321 for (int i = 0; i < src[s].idef.il[ftype].size() / 2; i++)
323 /* Correct the index into iparams_posres */
324 dest->il[ftype].iatoms[nposres * 2] = nposres;
329 int(iparams_dest.size()) == nposres,
330 "The number of parameters should match the number of restraints");
336 //! Options for assigning interactions for atoms
337 enum class InteractionConnectivity
339 Intramolecular, //!< Only intra-molecular interactions
340 Intermolecular //!< Only inter-molecular interactions
343 /*! \brief Determine whether the local domain has responsibility for
344 * any of the bonded interactions for local atom \p atomIndex
345 * and assign those to the local domain.
347 * \returns The total number of bonded interactions for this atom for
348 * which this domain is responsible.
350 template<InteractionConnectivity interactionConnectivity>
351 static inline int assignInteractionsForAtom(const int atomIndex,
352 const int globalAtomIndex,
353 const int atomIndexInMolecule,
354 gmx::ArrayRef<const int> index,
355 gmx::ArrayRef<const int> rtil,
358 const gmx_ga2la_t& ga2la,
359 const gmx_domdec_zones_t* zones,
360 const bool checkDistanceMultiBody,
362 const bool checkDistanceTwoBody,
363 const real cutoffSquared,
364 const t_pbc* pbc_null,
365 ArrayRef<const RVec> coordinates,
366 InteractionDefinitions* idef,
368 const DDBondedChecking ddBondedChecking)
370 gmx::ArrayRef<const DDPairInteractionRanges> iZones = zones->iZones;
372 int numBondedInteractions = 0;
377 t_iatom tiatoms[1 + MAXATOMLIST];
379 const int ftype = rtil[j++];
380 auto iatoms = gmx::constArrayRefFromArray(rtil.data() + j, rtil.size() - j);
381 const int nral = NRAL(ftype);
382 if (interaction_function[ftype].flags & IF_VSITE)
384 GMX_ASSERT(interactionConnectivity == InteractionConnectivity::Intramolecular,
385 "All vsites should be intramolecular");
387 /* The vsite construction goes where the vsite itself is */
408 tiatoms[0] = iatoms[0];
412 GMX_ASSERT(interactionConnectivity == InteractionConnectivity::Intramolecular,
413 "All interactions that involve a single atom are intramolecular");
415 /* Assign single-body interactions to the home zone.
416 * Position restraints are not handled here, but separately.
418 if (iz == 0 && !(ftype == F_POSRES || ftype == F_FBPOSRES))
421 tiatoms[1] = atomIndex;
426 /* This is a two-body interaction, we can assign
427 * analogous to the non-bonded assignments.
429 const int k_gl = (interactionConnectivity == InteractionConnectivity::Intramolecular)
431 /* Get the global index using the offset in the molecule */
432 (globalAtomIndex + iatoms[2] - atomIndexInMolecule)
434 if (const auto* entry = ga2la.find(k_gl))
436 int kz = entry->cell;
441 /* Check zone interaction assignments */
442 bUse = ((iz < iZones.ssize() && iz <= kz && iZones[iz].jZoneRange.isInRange(kz))
443 || (kz < iZones.ssize() && iz > kz && iZones[kz].jZoneRange.isInRange(iz)));
446 GMX_ASSERT(ftype != F_CONSTR || (iz == 0 && kz == 0),
447 "Constraint assigned here should only involve home atoms");
449 tiatoms[1] = atomIndex;
450 tiatoms[2] = entry->la;
451 /* If necessary check the cgcm distance */
452 if (checkDistanceTwoBody
453 && dd_dist2(pbc_null, coordinates, tiatoms[1], tiatoms[2]) >= cutoffSquared)
466 /* Assign this multi-body bonded interaction to
467 * the local domain if we have all the atoms involved
468 * (local or communicated) and the minimum zone shift
469 * in each dimension is zero, for dimensions
470 * with 2 DD cells an extra check may be necessary.
476 for (int k = 1; k <= nral && bUse; k++)
479 (interactionConnectivity == InteractionConnectivity::Intramolecular)
481 /* Get the global index using the offset in the molecule */
482 (globalAtomIndex + iatoms[k] - atomIndexInMolecule)
484 const auto* entry = ga2la.find(k_gl);
485 if (entry == nullptr || entry->cell >= zones->n)
487 /* We do not have this atom of this interaction
488 * locally, or it comes from more than one cell
495 tiatoms[k] = entry->la;
496 for (int d = 0; d < DIM; d++)
498 if (zones->shift[entry->cell][d] == 0)
509 bUse = (bUse && (k_zero[XX] != 0) && (k_zero[YY] != 0) && (k_zero[ZZ] != 0));
510 if (checkDistanceMultiBody)
512 for (int d = 0; (d < DIM && bUse); d++)
514 /* Check if the distance falls within
515 * the cut-off to avoid possible multiple
516 * assignments of bonded interactions.
518 if (rcheck[d] && k_plus[d]
519 && dd_dist2(pbc_null, coordinates, tiatoms[k_zero[d]], tiatoms[k_plus[d]])
529 /* Add this interaction to the local topology */
530 idef->il[ftype].push_back(tiatoms[0], nral, tiatoms + 1);
531 /* Sum so we can check in global_stat
532 * if we have everything.
534 if (ddBondedChecking == DDBondedChecking::All
535 || !(interaction_function[ftype].flags & IF_LIMZERO))
537 numBondedInteractions++;
541 j += 1 + nral_rt(ftype);
544 return numBondedInteractions;
547 /*! \brief Determine whether the local domain has responsibility for
548 * any of the position restraints for local atom \p atomIndex
549 * and assign those to the local domain.
551 * \returns The total number of bonded interactions for this atom for
552 * which this domain is responsible.
554 static inline int assignPositionRestraintsForAtom(const int atomIndex,
556 const int atomIndexInMolecule,
557 const int numAtomsInMolecule,
558 gmx::ArrayRef<const int> rtil,
561 const gmx_molblock_t& molb,
562 const t_iparams* ip_in,
563 InteractionDefinitions* idef)
565 constexpr int nral = 1;
567 int numBondedInteractions = 0;
572 const int ftype = rtil[j++];
573 auto iatoms = gmx::constArrayRefFromArray(rtil.data() + j, rtil.size() - j);
575 if (ftype == F_POSRES || ftype == F_FBPOSRES)
577 std::array<int, 1 + nral> tiatoms = { iatoms[0], atomIndex };
578 if (ftype == F_POSRES)
580 add_posres(mol, atomIndexInMolecule, numAtomsInMolecule, molb, tiatoms, ip_in, idef);
584 add_fbposres(mol, atomIndexInMolecule, numAtomsInMolecule, molb, tiatoms, ip_in, idef);
586 idef->il[ftype].push_back(tiatoms[0], nral, tiatoms.data() + 1);
587 numBondedInteractions++;
589 j += 1 + nral_rt(ftype);
592 return numBondedInteractions;
595 /*! \brief This function looks up and assigns bonded interactions for zone iz.
597 * With thread parallelizing each thread acts on a different atom range:
598 * at_start to at_end.
600 static int make_bondeds_zone(gmx_reverse_top_t* rt,
601 ArrayRef<const int> globalAtomIndices,
602 const gmx_ga2la_t& ga2la,
603 const gmx_domdec_zones_t* zones,
604 const std::vector<gmx_molblock_t>& molb,
605 const bool checkDistanceMultiBody,
607 const bool checkDistanceTwoBody,
608 const real cutoffSquared,
609 const t_pbc* pbc_null,
610 ArrayRef<const RVec> coordinates,
611 const t_iparams* ip_in,
612 InteractionDefinitions* idef,
614 const gmx::Range<int>& atomRange)
619 int atomIndexInMolecule = 0;
621 const auto ddBondedChecking = rt->options().ddBondedChecking;
623 int numBondedInteractions = 0;
625 for (int i : atomRange)
627 /* Get the global atom number */
628 const int globalAtomIndex = globalAtomIndices[i];
629 global_atomnr_to_moltype_ind(
630 rt->molblockIndices(), globalAtomIndex, &mb, &mt, &mol, &atomIndexInMolecule);
631 /* Check all intramolecular interactions assigned to this atom */
632 gmx::ArrayRef<const int> index = rt->interactionListForMoleculeType(mt).index;
633 gmx::ArrayRef<const t_iatom> rtil = rt->interactionListForMoleculeType(mt).il;
635 numBondedInteractions += assignInteractionsForAtom<InteractionConnectivity::Intramolecular>(
641 index[atomIndexInMolecule],
642 index[atomIndexInMolecule + 1],
645 checkDistanceMultiBody,
647 checkDistanceTwoBody,
655 // Assign position restraints, when present, for the home zone
656 if (izone == 0 && rt->hasPositionRestraints())
658 numBondedInteractions += assignPositionRestraintsForAtom(
662 rt->interactionListForMoleculeType(mt).numAtomsInMolecule,
664 index[atomIndexInMolecule],
665 index[atomIndexInMolecule + 1],
671 if (rt->hasIntermolecularInteractions())
673 /* Check all intermolecular interactions assigned to this atom */
674 index = rt->interactionListForIntermolecularInteractions().index;
675 rtil = rt->interactionListForIntermolecularInteractions().il;
677 numBondedInteractions += assignInteractionsForAtom<InteractionConnectivity::Intermolecular>(
683 index[globalAtomIndex],
684 index[globalAtomIndex + 1],
687 checkDistanceMultiBody,
689 checkDistanceTwoBody,
699 return numBondedInteractions;
702 /*! \brief Set the exclusion data for i-zone \p iz */
703 static void make_exclusions_zone(ArrayRef<const int> globalAtomIndices,
704 const gmx_ga2la_t& ga2la,
705 gmx_domdec_zones_t* zones,
706 ArrayRef<const MolblockIndices> molblockIndices,
707 const std::vector<gmx_moltype_t>& moltype,
709 ListOfLists<int>* lexcls,
713 const gmx::ArrayRef<const int> intermolecularExclusionGroup)
715 const auto& jAtomRange = zones->iZones[iz].jAtomRange;
717 const gmx::index oldNumLists = lexcls->ssize();
719 std::vector<int> exclusionsForAtom;
720 for (int at = at_start; at < at_end; at++)
722 exclusionsForAtom.clear();
724 if (GET_CGINFO_EXCL_INTER(atomInfo[at]))
731 /* Copy the exclusions from the global top */
732 int a_gl = globalAtomIndices[at];
733 global_atomnr_to_moltype_ind(molblockIndices, a_gl, &mb, &mt, &mol, &a_mol);
734 const auto excls = moltype[mt].excls[a_mol];
735 for (const int aj_mol : excls)
737 if (const auto* jEntry = ga2la.find(a_gl + aj_mol - a_mol))
739 /* This check is not necessary, but it can reduce
740 * the number of exclusions in the list, which in turn
741 * can speed up the pair list construction a bit.
743 if (jAtomRange.isInRange(jEntry->la))
745 exclusionsForAtom.push_back(jEntry->la);
751 bool isExcludedAtom = !intermolecularExclusionGroup.empty()
752 && std::find(intermolecularExclusionGroup.begin(),
753 intermolecularExclusionGroup.end(),
754 globalAtomIndices[at])
755 != intermolecularExclusionGroup.end();
759 for (int qmAtomGlobalIndex : intermolecularExclusionGroup)
761 if (const auto* entry = ga2la.find(qmAtomGlobalIndex))
763 exclusionsForAtom.push_back(entry->la);
768 /* Append the exclusions for this atom to the topology */
769 lexcls->pushBack(exclusionsForAtom);
773 lexcls->ssize() - oldNumLists == at_end - at_start,
774 "The number of exclusion list should match the number of atoms in the range");
777 /*! \brief Generate and store all required local bonded interactions in \p idef and local exclusions in \p lexcls
779 * \returns Total count of bonded interactions in the local topology on this domain */
780 static int make_local_bondeds_excls(gmx_domdec_t* dd,
781 gmx_domdec_zones_t* zones,
782 const gmx_mtop_t& mtop,
784 const bool checkDistanceMultiBody,
786 const gmx_bool checkDistanceTwoBody,
788 const t_pbc* pbc_null,
789 ArrayRef<const RVec> coordinates,
790 InteractionDefinitions* idef,
791 ListOfLists<int>* lexcls)
793 int nzone_bondeds = 0;
795 if (dd->reverse_top->hasInterAtomicInteractions())
797 nzone_bondeds = zones->n;
801 /* Only single charge group (or atom) molecules, so interactions don't
802 * cross zone boundaries and we only need to assign in the home zone.
807 /* We only use exclusions from i-zones to i- and j-zones */
808 const int numIZonesForExclusions = (dd->haveExclusions ? zones->iZones.size() : 0);
810 gmx_reverse_top_t* rt = dd->reverse_top.get();
812 const real cutoffSquared = gmx::square(cutoff);
814 /* Clear the counts */
816 int numBondedInteractions = 0;
820 for (int izone = 0; izone < nzone_bondeds; izone++)
822 const int cg0 = zones->cg_range[izone];
823 const int cg1 = zones->cg_range[izone + 1];
825 gmx::ArrayRef<thread_work_t> threadWorkObjects = rt->threadWorkObjects();
826 const int numThreads = threadWorkObjects.size();
827 #pragma omp parallel for num_threads(numThreads) schedule(static)
828 for (int thread = 0; thread < numThreads; thread++)
832 InteractionDefinitions* idef_t = nullptr;
834 int cg0t = cg0 + ((cg1 - cg0) * thread) / numThreads;
835 int cg1t = cg0 + ((cg1 - cg0) * (thread + 1)) / numThreads;
843 idef_t = &threadWorkObjects[thread].idef;
847 threadWorkObjects[thread].numBondedInteractions =
848 make_bondeds_zone(rt,
849 dd->globalAtomIndices,
853 checkDistanceMultiBody,
855 checkDistanceTwoBody,
859 idef->iparams.data(),
862 gmx::Range<int>(cg0t, cg1t));
864 if (izone < numIZonesForExclusions)
866 ListOfLists<int>* excl_t = nullptr;
869 // Thread 0 stores exclusions directly in the final storage
874 // Threads > 0 store in temporary storage, starting at list index 0
875 excl_t = &threadWorkObjects[thread].excl;
879 /* No charge groups and no distance check required */
880 make_exclusions_zone(dd->globalAtomIndices,
883 rt->molblockIndices(),
890 mtop.intermolecularExclusionGroup);
893 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
896 if (threadWorkObjects.size() > 1)
898 combine_idef(idef, threadWorkObjects);
901 for (const thread_work_t& th_work : threadWorkObjects)
903 numBondedInteractions += th_work.numBondedInteractions;
906 if (izone < numIZonesForExclusions)
908 for (std::size_t th = 1; th < threadWorkObjects.size(); th++)
910 lexcls->appendListOfLists(threadWorkObjects[th].excl);
917 fprintf(debug, "We have %d exclusions\n", lexcls->numElements());
920 return numBondedInteractions;
923 int dd_make_local_top(gmx_domdec_t* dd,
924 gmx_domdec_zones_t* zones,
930 ArrayRef<const RVec> coordinates,
931 const gmx_mtop_t& mtop,
932 gmx_localtop_t* ltop)
936 t_pbc pbc, *pbc_null = nullptr;
940 fprintf(debug, "Making local topology\n");
943 bool checkDistanceMultiBody = false;
944 bool checkDistanceTwoBody = false;
946 if (dd->reverse_top->hasInterAtomicInteractions())
948 /* We need to check to which cell bondeds should be assigned */
949 rc = dd_cutoff_twobody(dd);
952 fprintf(debug, "Two-body bonded cut-off distance is %g\n", rc);
955 /* Should we check distances when assigning bonded interactions? */
956 for (int d = 0; d < DIM; d++)
959 /* Only need to check for dimensions where the part of the box
960 * that is not communicated is smaller than the cut-off.
962 if (d < npbcdim && dd->numCells[d] > 1
963 && (dd->numCells[d] - npulse[d]) * cellsize_min[d] < 2 * rc)
965 if (dd->numCells[d] == 2)
968 checkDistanceMultiBody = TRUE;
970 /* Check for interactions between two atoms,
971 * where we can allow interactions up to the cut-off,
972 * instead of up to the smallest cell dimension.
974 checkDistanceTwoBody = TRUE;
979 "dim %d cellmin %f bonded rcheck[%d] = %d, checkDistanceTwoBody = %s\n",
984 gmx::boolToString(checkDistanceTwoBody));
987 if (checkDistanceMultiBody || checkDistanceTwoBody)
991 pbc_null = set_pbc_dd(&pbc, fr->pbcType, dd->numCells, TRUE, box);
1000 int numBondedInteractionsToReduce = make_local_bondeds_excls(dd,
1003 fr->atomInfo.data(),
1004 checkDistanceMultiBody,
1006 checkDistanceTwoBody,
1013 /* The ilist is not sorted yet,
1014 * we can only do this when we have the charge arrays.
1016 ltop->idef.ilsort = ilsortUNKNOWN;
1018 return numBondedInteractionsToReduce;
1021 void dd_sort_local_top(const gmx_domdec_t& dd, const t_mdatoms* mdatoms, gmx_localtop_t* ltop)
1023 if (dd.reverse_top->doSorting())
1025 gmx_sort_ilist_fe(<op->idef, mdatoms->chargeA, mdatoms->chargeB);
1029 ltop->idef.ilsort = ilsortNO_FE;