3232
3333#include " SireError/errors.h"
3434
35+ #include " SireMM/cljnbpairs.h"
36+
3537#include " SireMol/atomelements.h"
3638#include " SireMol/atommasses.h"
3739#include " SireMol/connectivity.h"
3840#include " SireMol/core.h"
3941#include " SireMol/mgname.h"
42+ #include " SireMol/moleculeinfodata.h"
4043#include " SireMol/moleditor.h"
4144#include " SireMol/molidx.h"
4245
4952
5053using namespace SireBase ;
5154using namespace SireMaths ;
55+ using namespace SireMM ;
5256using namespace SireMol ;
5357using namespace SireUnits ;
5458using namespace SireVol ;
@@ -1627,7 +1631,7 @@ namespace SireIO
16271631
16281632 Molecule createSodiumIon (const Vector &coords, const QString model, const PropertyMap &map)
16291633 {
1630- // Strip all whitespace from the model name and convert to upper case.
1634+ // Strip all whitespace from the model name and convert to upper case.
16311635 auto _model = model.simplified ().replace (" " , " " ).toUpper ();
16321636
16331637 // Create a hash between the allowed model names and their templace files.
@@ -1658,7 +1662,7 @@ namespace SireIO
16581662
16591663 Molecule createChlorineIon (const Vector &coords, const QString model, const PropertyMap &map)
16601664 {
1661- // Strip all whitespace from the model name and convert to upper case.
1665+ // Strip all whitespace from the model name and convert to upper case.
16621666 auto _model = model.simplified ().replace (" " , " " ).toUpper ();
16631667
16641668 // Create a hash between the allowed model names and their templace files.
@@ -1730,9 +1734,9 @@ namespace SireIO
17301734
17311735 // Set the new coordinates.
17321736 molecule = molecule.edit ()
1733- .atom (AtomIdx (j))
1734- .setProperty (coord_prop, coord)
1735- .molecule ();
1737+ .atom (AtomIdx (j))
1738+ .setProperty (coord_prop, coord)
1739+ .molecule ();
17361740 }
17371741
17381742 // Update the molecule in the system.
@@ -1754,4 +1758,75 @@ namespace SireIO
17541758 return Vector (nx, ny, nz);
17551759 }
17561760
1761+ SireBase::PropertyList mergeIntrascale (const CLJNBPairs &nb0,
1762+ const CLJNBPairs &nb1,
1763+ const MoleculeInfoData &merged_info,
1764+ const QHash<AtomIdx, AtomIdx> &mol0_merged_mapping,
1765+ const QHash<AtomIdx, AtomIdx> &mol1_merged_mapping)
1766+ {
1767+ // Helper lambda: copy the non-default scaling factors from 'nb' to
1768+ // 'nb_merged' according to the provided mapping. Takes nb_merged by
1769+ // reference to avoid copies.
1770+ auto copyIntrascale = [&](const CLJNBPairs &nb, CLJNBPairs &nb_merged,
1771+ const QHash<AtomIdx, AtomIdx> &mapping)
1772+ {
1773+ const int n = nb.nAtoms ();
1774+
1775+ for (int i = 0 ; i < n; ++i)
1776+ {
1777+ const AtomIdx ai (i);
1778+
1779+ // Get the index of this atom in the merged system.
1780+ const AtomIdx merged_ai = mapping.value (ai, AtomIdx (-1 ));
1781+
1782+ // If this atom hasn't been mapped to the merged system, then we
1783+ // can skip it, as any scaling factors involving this atom will
1784+ // just use the default.
1785+ if (merged_ai == AtomIdx (-1 ))
1786+ continue ;
1787+
1788+ for (int j = i; j < n; ++j)
1789+ {
1790+ const AtomIdx aj (j);
1791+
1792+ // Get the scaling factor for this pair of atoms.
1793+ const CLJScaleFactor sf = nb.get (ai, aj);
1794+
1795+ // This is a non-default scaling factor, so we need to copy
1796+ // it across to the merged intrascale object according to
1797+ // the mapping.
1798+ if (sf.coulomb () != 1.0 or sf.lj () != 1.0 )
1799+ {
1800+ // Get the index of the second atom in the merged system.
1801+ const AtomIdx merged_aj = mapping.value (aj, AtomIdx (-1 ));
1802+
1803+ // Only set the scaling factor if both atoms have been
1804+ // mapped to the merged system. If one of the atoms
1805+ // hasn't been mapped, then we can just use the default.
1806+ if (merged_aj != AtomIdx (-1 ))
1807+ nb_merged.set (merged_ai, merged_aj, sf);
1808+ }
1809+ }
1810+ }
1811+ };
1812+
1813+ // Create the intrascale objects for the merged end-states.
1814+ CLJNBPairs intra0 (merged_info);
1815+ CLJNBPairs intra1 (merged_info);
1816+
1817+ // Copy the non-default scaling factors from the original intrascale
1818+ // objects to the merged intrascale objects according to the provided
1819+ // mappings.
1820+ copyIntrascale (nb1, intra0, mol1_merged_mapping);
1821+ copyIntrascale (nb0, intra0, mol0_merged_mapping);
1822+ copyIntrascale (nb0, intra1, mol0_merged_mapping);
1823+ copyIntrascale (nb1, intra1, mol1_merged_mapping);
1824+
1825+ // Assemble the intrascale objects into a property list to return.
1826+ SireBase::PropertyList ret;
1827+ ret.append (intra0);
1828+ ret.append (intra1);
1829+ return ret;
1830+ }
1831+
17571832} // namespace SireIO
0 commit comments