Skip to content

Commit 25dd443

Browse files
author
Christian Schafmeisterr
committed
Rearrange nonbond evaluation
Separate out 1-4 interactions into a separate _Terms14 vector. Add code to rebuild the pair list in _Terms
1 parent e8d0c91 commit 25dd443

File tree

5 files changed

+381
-401
lines changed

5 files changed

+381
-401
lines changed

include/cando/chem/energyFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,16 @@ namespace chem {
263263
EnergyAtom* getEnergyAtomPointer(Atom_sp a);
264264

265265
void assignAtomTypes(Matter_sp matter, bool show_progress);
266-
void defineForMatter(Matter_sp agg, bool useExcludedAtoms, core::T_sp keepInteractionFactory=nil<core::T_O>(), bool assign_types=true );
267-
void defineForMatterWithAtomTypes(Matter_sp matter, bool useExcludedAtoms, core::T_sp keepInteractionFactory, core::T_sp cip_priorities, core::HashTable_sp atomTypes );
266+
void defineForMatter(Matter_sp agg, bool useExcludedAtoms, core::T_sp keepInteractionFactory=nil<core::T_O>(), bool assign_types=true, core::T_sp coordinates=nil<core::T_O>() );
267+
void defineForMatterWithAtomTypes(Matter_sp matter, bool useExcludedAtoms, core::T_sp keepInteractionFactory, core::T_sp cip_priorities, core::HashTable_sp atomTypes, core::T_sp coordinates );
268268
void generateStandardEnergyFunctionTables(Matter_sp mol,
269269
FFStretchDb_sp stretchDb,
270270
FFAngleDb_sp angleDb,
271271
FFPtorDb_sp ptorDb,
272272
FFItorDb_sp itorDb,
273273
core::T_sp keepInteractionFactory,
274274
core::HashTable_sp atomTypes);
275-
void generateNonbondEnergyFunctionTables(bool useExcludedAtoms, Matter_sp agg, core::T_sp forceField, core::T_sp keepInteractionFactory, core::HashTable_sp atomTypes );
275+
void generateNonbondEnergyFunctionTables(bool useExcludedAtoms, Matter_sp agg, core::T_sp forceField, core::T_sp keepInteractionFactory, core::HashTable_sp atomTypes, core::T_sp coordinates );
276276
void generateRestraintEnergyFunctionTables(Matter_sp agg, core::T_sp nonbonds, core::T_sp keepInteractionFactory, core::T_sp cip_priorities, core::HashTable_sp atomTypes );
277277

278278
/*! Add the restraints to the energy function.

include/cando/chem/energyNonbond.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class EnergyNonbond : public EnergyTerm {
7474
Atom_sp _Atom1_enb;
7575
Atom_sp _Atom2_enb;
7676
TermNonBond term;
77-
bool _Is14;
7877
#if TURN_ENERGY_FUNCTION_DEBUG_ON
7978
bool _calcForce;
8079
bool _calcDiagonalHessian;
@@ -171,13 +170,17 @@ class EnergyNonbond_O : public EnergyComponent_O
171170
double _Nonbond_invdd; // Distance dependent dielectric reciprocal
172171
size_t _NonbondsKept;
173172
size_t _NonbondsDiscarded;
174-
// Original way of defining nonbonds with list of nonbond terms
173+
gctools::Vec0<TermType> _Terms14;
174+
// Pairlist
175+
AtomTable_sp _AtomTable;
176+
core::T_sp _NonbondForceField;
177+
core::HashTable_sp _AtomTypes;
178+
core::T_sp _KeepInteractionFactory;
175179
gctools::Vec0<TermType> _Terms;
176180
gctools::Vec0<TermType> _BeyondThresholdTerms;
177181
// Correct way of defining nonbonds using excluded atom indexes
178182
// FIXME: Get rid of _FFNonbondDb - and the old code that uses it.
179183
core::T_sp _FFNonbondDb;
180-
AtomTable_sp _AtomTable;
181184
// Tables for nonbonded calculation using excluded atoms and the Amber way
182185
size_t _ntypes; // ntypes
183186
core::SimpleVector_sp _atom_name_vector; // atom-name-vector
@@ -200,12 +203,12 @@ class EnergyNonbond_O : public EnergyComponent_O
200203

201204
public:
202205
typedef gctools::Vec0<TermType>::iterator iterator;
203-
iterator begin() { return this->_Terms.begin(); };
204-
iterator end() { return this->_Terms.end(); };
206+
// iterator begin() { return this->_Terms.begin(); };
207+
// iterator end() { return this->_Terms.end(); };
205208
//added by G 7.19.2011
206209
public:
207210
// core::List_sp termAtIndex(size_t index) const;
208-
virtual size_t numberOfTerms() { return this->_Terms.size();};
211+
virtual size_t numberOfTerms() { return this->_Terms.size(); };
209212
void callForEachTerm(core::Function_sp callback);
210213
public:
211214

@@ -216,6 +219,7 @@ class EnergyNonbond_O : public EnergyComponent_O
216219
CL_DEFMETHOD core::SimpleVector_int32_t_sp excluded_atom_list() const { return this->_ExcludedAtomIndexes;}
217220
public:
218221
void constructNonbondTermsBetweenResidues(Residue_sp res1, Residue_sp res2, core::T_sp nbForceField, core::HashTable_sp atomTypes );
222+
void addTerm14(const TermType& term);
219223
void addTerm(const TermType& term);
220224
virtual void dumpTerms(core::HashTable_sp atomTypes);
221225

@@ -269,7 +273,8 @@ class EnergyNonbond_O : public EnergyComponent_O
269273

270274
core::T_sp getFFNonbondDb();
271275

272-
void constructNonbondTermsFromAtomTable(bool ignore14s, AtomTable_sp atomTable, core::T_sp nbforceField, core::HashTable_sp atomTypes, core::T_sp keepInteractionFactory );
276+
void updatePairList(core::T_sp tcoordinates);
277+
void constructNonbondTermsFromAtomTable( AtomTable_sp atomTable, core::T_sp nbforceField, core::HashTable_sp atomTypes, core::T_sp keepInteractionFactory, core::T_sp coordinates);
273278
void constructNonbondTermsBetweenMatters( Matter_sp matter1, Matter_sp matter2, EnergyFunction_sp energyFunction, core::T_sp keepInteractionFactory );
274279
void construct14InteractionTerms(AtomTable_sp atomTable, Matter_sp matter, core::T_sp nbforceField, core::T_sp keepInteractionFactory, core::HashTable_sp atomTypes );
275280
void constructExcludedAtomListFromAtomTable(AtomTable_sp atomTable, core::T_sp nbforceField, core::T_sp keepInteractionFactory );

src/chem/energyFunction.cc

Lines changed: 78 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,103 +1292,92 @@ __END_DOC
12921292
SYMBOL_EXPORT_SC_(ChemPkg,STARcurrent_aromaticity_informationSTAR);
12931293

12941294
CL_LISPIFY_NAME("defineForMatter");
1295-
CL_LAMBDA((energy-function chem:energy-function) matter &key use-excluded-atoms (keep-interaction-factory t) (assign-types t));
1296-
CL_DEFMETHOD void EnergyFunction_O::defineForMatter(Matter_sp matter, bool useExcludedAtoms, core::T_sp keepInteractionFactory, bool assign_types )
1297-
{
1298-
if ( !(matter.isA<Aggregate_O>() || matter.isA<Molecule_O>() ) )
1299-
{
1300-
SIMPLE_ERROR("You can only define energy functions for Aggregates or Molecules");
1301-
}
1302-
1303-
core::DynamicScopeManager scope(_sym_STARparameter_warningsSTAR,nil<core::T_O>());
1304-
//
1305-
// Identify rings
1306-
//
1307-
if (chem__verbose(0)) core::clasp_write_string("Searching for rings.\n");
1308-
1309-
// If *current-rings* is bound then reuse it, otherwise, calculate rings and bind those
1310-
core::T_sp rings = unbound<core::T_sp>();
1311-
if (_sym_STARcurrent_ringsSTAR->boundP()) {
1312-
rings = _sym_STARcurrent_ringsSTAR->symbolValue();
1313-
} else if (keepInteractionFactory.notnilp()) {
1314-
rings = RingFinder_O::identifyRings(matter);
1315-
} else {
1316-
rings = nil<core::T_O>();
1295+
CL_LAMBDA((energy-function chem:energy-function) matter &key use-excluded-atoms (keep-interaction-factory t) (assign-types t) (coordinates nil));
1296+
CL_DEFMETHOD void EnergyFunction_O::defineForMatter(Matter_sp matter, bool useExcludedAtoms, core::T_sp keepInteractionFactory, bool assign_types, core::T_sp coordinates )
1297+
{
1298+
if ( !(matter.isA<Aggregate_O>() || matter.isA<Molecule_O>() ) )
1299+
{
1300+
SIMPLE_ERROR("You can only define energy functions for Aggregates or Molecules");
13171301
}
1318-
core::DynamicScopeManager ring_scope(_sym_STARcurrent_ringsSTAR, rings );
13191302

1320-
//
1321-
// Assign relative Cahn-Ingold-Preylog priorities
1322-
//
1323-
if (chem__verbose(0)) core::clasp_write_string("Assigning CIP priorities.\n");
1324-
core::HashTable_sp cip = unbound<core::HashTable_O>();
1325-
if (keepInteractionFactory.notnilp()) {
1326-
cip = CipPrioritizer_O::assignPrioritiesHashTable(matter);
1327-
}
1303+
core::DynamicScopeManager scope(_sym_STARparameter_warningsSTAR,nil<core::T_O>());
1304+
//
1305+
// Identify rings
1306+
//
1307+
if (chem__verbose(0)) core::clasp_write_string("Searching for rings.\n");
1308+
1309+
// If *current-rings* is bound then reuse it, otherwise, calculate rings and bind those
1310+
core::T_sp rings = unbound<core::T_sp>();
1311+
if (_sym_STARcurrent_ringsSTAR->boundP()) {
1312+
rings = _sym_STARcurrent_ringsSTAR->symbolValue();
1313+
} else if (keepInteractionFactory.notnilp()) {
1314+
rings = RingFinder_O::identifyRings(matter);
1315+
} else {
1316+
rings = nil<core::T_O>();
1317+
}
1318+
core::DynamicScopeManager ring_scope(_sym_STARcurrent_ringsSTAR, rings );
13281319

1329-
//
1330-
// Assign atom types for each molecule
1331-
//
1320+
//
1321+
// Assign relative Cahn-Ingold-Preylog priorities
1322+
//
1323+
if (chem__verbose(0)) core::clasp_write_string("Assigning CIP priorities.\n");
1324+
core::HashTable_sp cip = unbound<core::HashTable_O>();
1325+
if (keepInteractionFactory.notnilp()) {
1326+
cip = CipPrioritizer_O::assignPrioritiesHashTable(matter);
1327+
}
13321328

1333-
core::HashTable_sp force_fields = core::HashTable_O::createEq();
1334-
Loop moleculeLoop;
1329+
//
1330+
// Assign atom types for each molecule
1331+
//
1332+
1333+
core::HashTable_sp force_fields = core::HashTable_O::createEq();
1334+
Loop moleculeLoop;
1335+
moleculeLoop.loopTopGoal(matter,MOLECULES);
1336+
while (moleculeLoop.advanceLoopAndProcess() ) {
1337+
Molecule_sp molecule = moleculeLoop.getMolecule();
1338+
core::T_sp force_field_name = molecule->force_field_name();
1339+
if (force_fields->gethash(force_field_name).nilp()) {
1340+
core::T_sp combined_force_field = core::eval::funcall(_sym_find_force_field,force_field_name);
1341+
force_fields->setf_gethash(force_field_name,combined_force_field);
1342+
}
1343+
}
1344+
core::HashTable_sp atomTypes = core::HashTable_O::createEq();
1345+
// Assign given atom-types
1346+
Loop atom_loop;
1347+
atom_loop.loopTopGoal(matter,ATOMS);
1348+
while (atom_loop.advanceLoopAndProcess()) {
1349+
Atom_sp atom = atom_loop.getAtom();
1350+
core::T_sp type = atom->getPropertyOrDefault( kw::_sym_given_atom_type, nil<core::T_O>() );
1351+
if (type.notnilp()) {
1352+
atomTypes->setf_gethash(atom,type);
1353+
}
1354+
}
1355+
this->_AtomTypes = atomTypes;
1356+
if (assign_types) {
1357+
if (chem__verbose(0)) core::clasp_write_string("Assigning atom types.\n");
13351358
moleculeLoop.loopTopGoal(matter,MOLECULES);
13361359
while (moleculeLoop.advanceLoopAndProcess() ) {
13371360
Molecule_sp molecule = moleculeLoop.getMolecule();
13381361
core::T_sp force_field_name = molecule->force_field_name();
1339-
if (force_fields->gethash(force_field_name).nilp()) {
1340-
core::T_sp combined_force_field = core::eval::funcall(_sym_find_force_field,force_field_name);
1341-
force_fields->setf_gethash(force_field_name,combined_force_field);
1342-
}
1343-
}
1344-
core::HashTable_sp atomTypes = core::HashTable_O::createEq();
1345-
// Assign given atom-types
1346-
Loop atom_loop;
1347-
atom_loop.loopTopGoal(matter,ATOMS);
1348-
while (atom_loop.advanceLoopAndProcess()) {
1349-
Atom_sp atom = atom_loop.getAtom();
1350-
core::T_sp type = atom->getPropertyOrDefault( kw::_sym_given_atom_type, nil<core::T_O>() );
1351-
if (type.notnilp()) {
1352-
atomTypes->setf_gethash(atom,type);
1353-
}
1354-
}
1355-
this->_AtomTypes = atomTypes;
1356-
if (assign_types) {
1357-
if (chem__verbose(0)) core::clasp_write_string("Assigning atom types.\n");
1358-
moleculeLoop.loopTopGoal(matter,MOLECULES);
1359-
while (moleculeLoop.advanceLoopAndProcess() ) {
1360-
Molecule_sp molecule = moleculeLoop.getMolecule();
1361-
core::T_sp force_field_name = molecule->force_field_name();
1362-
[[maybe_unused]]core::T_sp use_given_types = molecule->force_field_use_given_types();
1363-
// if (use_given_types.nilp()) {
1364-
core::T_sp combined_force_field = force_fields->gethash(force_field_name);
1365-
if (chem__verbose(0)) core::clasp_write_string(fmt::format("Assigning atom types for molecule {} using {}.\n" , _rep_(molecule->getName()) , _rep_(force_field_name)));
1366-
//
1367-
// Calculate aromaticity using the rings we just calculated
1368-
//
1369-
core::T_sp aromaticity_info = core::eval::funcall(_sym_identify_aromatic_rings,matter,force_field_name);
1370-
if (aromaticity_info.nilp()) SIMPLE_ERROR("The aromaticity-info was NIL when about to assign force field types - it should not be");
1371-
core::DynamicScopeManager aromaticity_scope(_sym_STARcurrent_aromaticity_informationSTAR,aromaticity_info);
1372-
core::eval::funcall(_sym_assign_force_field_types,combined_force_field,molecule,atomTypes);
1373-
#if 0
1374-
} else {
1375-
if (chem__verbose(0)) core::clasp_write_string(fmt::format("Assigning atom types for molecule {} using given-types for {}.\n" , _rep_(molecule->getName()) , _rep_(force_field_name)));
1376-
Loop atom_loop;
1377-
atom_loop.loopTopGoal(molecule,ATOMS);
1378-
while (atom_loop.advanceLoopAndProcess()) {
1379-
Atom_sp atom = atom_loop.getAtom();
1380-
atomTypes->setf_gethash(atom,atom->atomType());
1381-
}
1362+
[[maybe_unused]]core::T_sp use_given_types = molecule->force_field_use_given_types();
1363+
// if (use_given_types.nilp()) {
1364+
core::T_sp combined_force_field = force_fields->gethash(force_field_name);
1365+
if (chem__verbose(0)) core::clasp_write_string(fmt::format("Assigning atom types for molecule {} using {}.\n" , _rep_(molecule->getName()) , _rep_(force_field_name)));
1366+
//
1367+
// Calculate aromaticity using the rings we just calculated
1368+
//
1369+
core::T_sp aromaticity_info = core::eval::funcall(_sym_identify_aromatic_rings,matter,force_field_name);
1370+
if (aromaticity_info.nilp()) SIMPLE_ERROR("The aromaticity-info was NIL when about to assign force field types - it should not be");
1371+
core::DynamicScopeManager aromaticity_scope(_sym_STARcurrent_aromaticity_informationSTAR,aromaticity_info);
1372+
core::eval::funcall(_sym_assign_force_field_types,combined_force_field,molecule,atomTypes);
13821373
}
1383-
#endif
13841374
}
1385-
}
1386-
this->defineForMatterWithAtomTypes(matter,useExcludedAtoms,keepInteractionFactory,cip,atomTypes);
1375+
this->defineForMatterWithAtomTypes(matter,useExcludedAtoms,keepInteractionFactory,cip,atomTypes,coordinates);
13871376
}
13881377

13891378

1390-
CL_LAMBDA((energy-function chem:energy-function) matter &key use-excluded-atoms (keep-interaction-factory t) cip-priorities atom-types);
1391-
CL_DEFMETHOD void EnergyFunction_O::defineForMatterWithAtomTypes(Matter_sp matter, bool useExcludedAtoms, core::T_sp keepInteractionFactory, core::T_sp cip_priorities, core::HashTable_sp atomTypes )
1379+
CL_LAMBDA((energy-function chem:energy-function) matter &key use-excluded-atoms (keep-interaction-factory t) cip-priorities atom-types coordinates);
1380+
CL_DEFMETHOD void EnergyFunction_O::defineForMatterWithAtomTypes(Matter_sp matter, bool useExcludedAtoms, core::T_sp keepInteractionFactory, core::T_sp cip_priorities, core::HashTable_sp atomTypes, core::T_sp coordinates )
13921381
{
13931382
if (keepInteractionFactory.notnilp() && !gc::IsA<core::HashTable_sp>(cip_priorities)) {
13941383
SIMPLE_ERROR("You need to provide a hash-table of atoms to relative CIP priorities - see CipPrioritizer_O::assignPrioritiesHashTable(matter)");
@@ -1507,7 +1496,7 @@ CL_DEFMETHOD void EnergyFunction_O::defineForMatterWithAtomTypes(Matter_sp matte
15071496
if (keepInteractionFactory.notnilp()) {
15081497
if (chem__verbose(1)) core::clasp_write_string("About to calculate nonbond and restraint terms");
15091498
core::T_sp nonbondForceField = this->_AtomTable->nonbondForceFieldForAggregate();
1510-
this->generateNonbondEnergyFunctionTables(useExcludedAtoms,matter,nonbondForceField,keepInteractionFactory,atomTypes);
1499+
this->generateNonbondEnergyFunctionTables(useExcludedAtoms,matter,nonbondForceField,keepInteractionFactory,atomTypes,coordinates);
15111500
this->generateRestraintEnergyFunctionTables(matter,nonbondForceField,keepInteractionFactory,cip_priorities,atomTypes);
15121501
}
15131502
core::eval::funcall(_sym_report_parameter_warnings);
@@ -1775,7 +1764,7 @@ CL_DEFMETHOD void EnergyFunction_O::generateStandardEnergyFunctionTables(Matter_
17751764
SYMBOL_EXPORT_SC_(ChemPkg,prepare_amber_energy_nonbond);
17761765

17771766
CL_DOCSTRING(R"dx(Generate the nonbond energy function tables. The atom types, and CIP priorities need to be precalculated.)dx");
1778-
CL_DEFMETHOD void EnergyFunction_O::generateNonbondEnergyFunctionTables(bool useExcludedAtoms, Matter_sp matter, core::T_sp nonbondForceField, core::T_sp keepInteractionFactory, core::HashTable_sp atomTypes )
1767+
CL_DEFMETHOD void EnergyFunction_O::generateNonbondEnergyFunctionTables(bool useExcludedAtoms, Matter_sp matter, core::T_sp nonbondForceField, core::T_sp keepInteractionFactory, core::HashTable_sp atomTypes, core::T_sp coordinates )
17791768
{
17801769
if (keepInteractionFactory.nilp()) return;
17811770
if (chem__verbose(0))
@@ -1792,7 +1781,9 @@ CL_DEFMETHOD void EnergyFunction_O::generateNonbondEnergyFunctionTables(bool use
17921781
this->_Nonbond->constructExcludedAtomListFromAtomTable(this->_AtomTable, nonbondForceField,keepInteractionFactory);
17931782
this->_Nonbond->construct14InteractionTerms(this->_AtomTable,matter,nonbondForceField,keepInteractionFactory,atomTypes);
17941783
} else {
1795-
this->_Nonbond->constructNonbondTermsFromAtomTable(false,this->_AtomTable, nonbondForceField,atomTypes, keepInteractionFactory );
1784+
this->_Nonbond->constructNonbondTermsFromAtomTable(this->_AtomTable, nonbondForceField,atomTypes,
1785+
keepInteractionFactory, coordinates );
1786+
this->_Nonbond->construct14InteractionTerms(this->_AtomTable,matter,nonbondForceField,keepInteractionFactory,atomTypes);
17961787
}
17971788
if (chem__verbose(0)) core::clasp_write_string(fmt::format("Built nonbond table for {} terms\n" , this->_Nonbond->numberOfTerms()));
17981789
}

0 commit comments

Comments
 (0)