@@ -250,6 +250,8 @@ core::T_sp debug_nonbond(double Energy, double x1, double y1, double z1, double
250250
251251SYMBOL_EXPORT_SC_ (ChemPkg, EnergyNonbond);
252252SYMBOL_EXPORT_SC_ (ChemPkg, EnergyNonbond14);
253+ SYMBOL_EXPORT_SC_ (ChemPkg, trapEnergyNonbondDefineForAtomPair );
254+ SYMBOL_EXPORT_SC_ (ChemPkg, trapEnergyNonbondNotDefineForAtomPair );
253255
254256core::T_sp nonbond_type (bool is14) {
255257 if (is14)
@@ -848,7 +850,16 @@ CL_DEFMETHOD void EnergyNonbond_O::compareAnalyticalAndNumericalForceAndHessianT
848850
849851bool EnergyNonbond::defineForAtomPair (core::T_sp forceField, bool is14, Atom_sp a1, Atom_sp a2, size_t a1CoordinateIndexTimes3,
850852 size_t a2CoordinateIndexTimes3, EnergyNonbond_sp energyNonbond,
851- core::HashTable_sp atomTypes) {
853+ core::HashTable_sp atomTypes, core::T_sp keepInteraction ) {
854+ if (_sym_trapEnergyNonbondDefineForAtomPair->fboundp ()) {
855+ core::eval::funcall (_sym_trapEnergyNonbondDefineForAtomPair,
856+ a1, a2,
857+ core::make_fixnum (a1CoordinateIndexTimes3),
858+ core::make_fixnum (a2CoordinateIndexTimes3),
859+ energyNonbond,
860+ atomTypes,
861+ keepInteraction);
862+ }
852863 double amber_charge_conversion_18dot2223 =
853864 core::Number_O::as_double_float (gc::As<core::Number_sp>(_sym_STARamber_charge_conversion_18_DOT_2223STAR->symbolValue ()));
854865 double dQ1Q2Scale = amber_charge_conversion_18dot2223 * amber_charge_conversion_18dot2223;
@@ -1148,7 +1159,9 @@ void EnergyNonbond_O::construct14InteractionTerms(AtomTable_sp atomTable, Matter
11481159 ea1->atom (), ea4->atom (),
11491160 ea1->coordinateIndexTimes3 (),
11501161 ea4->coordinateIndexTimes3 (),
1151- this ->asSmartPtr (), atomTypes );
1162+ this ->asSmartPtr (),
1163+ atomTypes,
1164+ keepInteraction );
11521165 this ->addTerm14 (energyNonbond);
11531166 ++terms;
11541167 }
@@ -1217,6 +1230,7 @@ core::T_mv EnergyNonbond_O::rebuildPairList(core::T_sp tcoordinates) {
12171230 // If the nonbond pairs are between two matters then don't rebuild the pair-list
12181231 if (this ->_Matter1 .notnilp ()) {
12191232 ASSERT (this ->_Matter2 .notnilp ());
1233+ this ->rebuildPairListBetweenMatters (tcoordinates);
12201234 return Values0<core::T_O>();
12211235 }
12221236
@@ -1284,7 +1298,9 @@ core::T_mv EnergyNonbond_O::rebuildPairList(core::T_sp tcoordinates) {
12841298 iea1->atom (), iea2->atom (),
12851299 iea1->coordinateIndexTimes3 (),
12861300 iea2->coordinateIndexTimes3 (),
1287- this ->asSmartPtr (), this ->_AtomTypes );
1301+ this ->asSmartPtr (),
1302+ this ->_AtomTypes ,
1303+ keepInteraction);
12881304 this ->addTerm (energyNonbond);
12891305 ++interactionsKept;
12901306 } else {
@@ -1303,6 +1319,80 @@ core::T_mv EnergyNonbond_O::rebuildPairList(core::T_sp tcoordinates) {
13031319 core::clasp_make_fixnum (totalInteractions));
13041320}
13051321
1322+ core::T_mv EnergyNonbond_O::rebuildPairListBetweenMatters (core::T_sp tcoordinates) {
1323+ core::print (fmt::format (" DEBUG/in rebuildPairListBetweenMatters --------------\n " ));
1324+ core::T_sp keepInteractionFactory = this ->_KeepInteractionFactory ;
1325+ if (keepInteractionFactory.nilp ()) return Values0<core::T_O>();
1326+ NVector_sp coords = gc::As<NVector_sp>(tcoordinates);
1327+ core::T_sp keepInteraction = specializeKeepInteractionFactory ( keepInteractionFactory, EnergyNonbond_O::staticClass () );
1328+ Matter_sp mat1 = this ->_Matter1 ;
1329+ Matter_sp mat2 = this ->_Matter2 ;
1330+ bool hasKeepInteractionFunction = gc::IsA<core::Function_sp>(keepInteraction);
1331+ double rpairlist2 = this ->_Nonbond_r_pairlist *this ->_Nonbond_r_pairlist ;
1332+ auto atomTable = this ->_AtomTable ;
1333+ auto nbForceField = atomTable->nonbondForceFieldForAggregate ();
1334+ auto atomTypes = this ->_AtomTypes ; // This was energyFunction->atomTypes() - I hope this->_AtomTypes works the same.
1335+ {
1336+ LOG (" Defining NONBONDS" );
1337+ Loop lMat1 (mat1, ATOMS);
1338+ while (lMat1.advanceLoopAndProcess ()) {
1339+ Atom_sp a1 = lMat1.getAtom ();
1340+ size_t i3x1 = atomTable->getCoordinateIndexTimes3 (a1);
1341+ Vector3 v1 (coords,i3x1,Safe ());
1342+ Loop lMat2 (mat2, ATOMS);
1343+ while (lMat2.advanceLoopAndProcess ()) {
1344+ Atom_sp a2 = lMat2.getAtom ();
1345+ size_t i3x2 = atomTable->getCoordinateIndexTimes3 (a2);
1346+ Vector3 v2 (coords,i3x2,Safe ());
1347+ Vector3 vdiff;
1348+ vdiff = v1-v2;
1349+ bool added = false ;
1350+ double dist2 = vdiff.dotProduct (vdiff);
1351+ // if ((i3x1==609&&i3x1==480) || (i3x1==480&&i3x1==609)) {
1352+ core::print (fmt::format (" ai{}/ai{} dist2 = {} rpairlist2 = {}\n " , i3x1, i3x2, dist2, rpairlist2));
1353+ // }
1354+ if (dist2 < rpairlist2) {
1355+ EnergyNonbond energyNonbond;
1356+ bool in14 = false ; // Between residues there are never 1-4
1357+ if (hasKeepInteractionFunction){
1358+ core::T_sp result = core::eval::funcall (keepInteraction,a1,a2,
1359+ core::make_fixnum (i3x1),
1360+ core::make_fixnum (i3x2));
1361+ if (result.notnilp ()) {
1362+ energyNonbond.defineForAtomPair (nbForceField, in14, a1, a2, i3x1, i3x2, this ->asSmartPtr (), atomTypes, keepInteraction);
1363+ added = true ;
1364+ this ->addTerm (energyNonbond);
1365+ }
1366+ } else {
1367+ energyNonbond.defineForAtomPair (nbForceField, in14, a1, a2,
1368+ i3x1, i3x2,
1369+ this ->asSmartPtr (), atomTypes, keepInteraction );
1370+ added = true ;
1371+ this ->addTerm (energyNonbond);
1372+ }
1373+ }
1374+ if (!added) {
1375+ if (_sym_trapEnergyNonbondNotDefineForAtomPair->fboundp ()) {
1376+ core::eval::funcall (_sym_trapEnergyNonbondDefineForAtomPair,
1377+ a1, a2,
1378+ core::make_fixnum (i3x1),
1379+ core::make_fixnum (i3x2),
1380+ this ->asSmartPtr (),
1381+ atomTypes,
1382+ keepInteraction);
1383+ }
1384+ }
1385+ }
1386+ }
1387+ }
1388+ return Values0<core::T_O>();
1389+ }
1390+
1391+
1392+
1393+
1394+
1395+
13061396void EnergyNonbond_O::constructExcludedAtomListFromAtomTable (AtomTable_sp atomTable, core::T_sp nbForceField, core::T_sp keepInteractionFactory ) {
13071397 // ------------------------------------------------------------
13081398 //
@@ -1325,48 +1415,15 @@ bonded to each other. Generate a pair-list in _Terms and that pair-list should
13251415CL_DEFMETHOD void EnergyNonbond_O::constructNonbondTermsBetweenMatters (Matter_sp mat1, Matter_sp mat2,
13261416 EnergyFunction_sp energyFunction,
13271417 core::T_sp keepInteractionFactory) {
1418+ core::print (fmt::format (" DEBUG/in constructNonbondTermsBetweenMatters -------------- {} {}\n " , _rep_ (mat1), _rep_ (mat2)));
13281419 this ->_UsesExcludedAtoms = false ;
13291420 this ->_Matter1 = mat1;
13301421 this ->_Matter2 = mat2;
13311422 this ->_KeepInteractionFactory = keepInteractionFactory;
13321423 this ->_Terms .clear ();
13331424 this ->_Terms14 .clear ();
1334- if (keepInteractionFactory.nilp ()) return ;
13351425
1336- core::T_sp keepInteraction = specializeKeepInteractionFactory ( keepInteractionFactory, EnergyNonbond_O::staticClass () );
1337- bool hasKeepInteractionFunction = gc::IsA<core::Function_sp>(keepInteraction);
1338- auto atomTable = energyFunction->atomTable ();
1339- auto nbForceField = atomTable->nonbondForceFieldForAggregate ();
1340- auto atomTypes = energyFunction->atomTypes ();
1341- {
1342- LOG (" Defining NONBONDS" );
1343- Loop lMat1 (mat1, ATOMS);
1344- while (lMat1.advanceLoopAndProcess ()) {
1345- Atom_sp a1 = lMat1.getAtom ();
1346- size_t a1CoordinateIndexTimes3 = atomTable->getCoordinateIndexTimes3 (a1);
1347- Loop lMat2 (mat2, ATOMS);
1348- while (lMat2.advanceLoopAndProcess ()) {
1349- Atom_sp a2 = lMat2.getAtom ();
1350- size_t a2CoordinateIndexTimes3 = atomTable->getCoordinateIndexTimes3 (a2);
1351- EnergyNonbond energyNonbond;
1352- bool in14 = false ; // Between residues there are never 1-4
1353- if (hasKeepInteractionFunction){
1354- core::T_sp result = core::eval::funcall (keepInteraction,a1,a2,
1355- core::make_fixnum (a1CoordinateIndexTimes3),
1356- core::make_fixnum (a2CoordinateIndexTimes3));
1357- if (result.notnilp ()) {
1358- energyNonbond.defineForAtomPair (nbForceField, in14, a1, a2, a1CoordinateIndexTimes3, a2CoordinateIndexTimes3, this ->asSmartPtr (), atomTypes);
1359- this ->addTerm (energyNonbond);
1360- }
1361- } else {
1362- energyNonbond.defineForAtomPair (nbForceField, in14, a1, a2,
1363- a1CoordinateIndexTimes3, a2CoordinateIndexTimes3,
1364- this ->asSmartPtr (), atomTypes);
1365- this ->addTerm (energyNonbond);
1366- }
1367- }
1368- }
1369- }
1426+
13701427}
13711428
13721429SYMBOL_EXPORT_SC_ (KeywordPkg, da);
0 commit comments