@@ -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_
17751764SYMBOL_EXPORT_SC_ (ChemPkg,prepare_amber_energy_nonbond);
17761765
17771766CL_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