mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
ForceFieldHelpers: fix “No Python class registered” error (#8800)
Fixes github issue #8597. * UFFGetMoleculeForceField was returning PyForceField* before the class was registered via rdForceField, which caused “No Python class registered” errors in Python when using multiple conformers. * This patch forces rdForceField to be imported during rdForceFieldHelpers module init, ensuring the class is always registered before helper functions are used. * Add unit test
This commit is contained in:
@@ -248,6 +248,8 @@ PyObject *getUFFVdWParams(const RDKit::ROMol &mol, const unsigned int idx1,
|
||||
} // namespace ForceFields
|
||||
|
||||
BOOST_PYTHON_MODULE(rdForceFieldHelpers) {
|
||||
boost::python::import("rdkit.ForceField.rdForceField");
|
||||
|
||||
python::scope().attr("__doc__") =
|
||||
"Module containing functions to handle force fields";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import numpy
|
||||
|
||||
from rdkit import Chem, RDConfig
|
||||
from rdkit.Chem import ChemicalForceFields, rdDistGeom
|
||||
|
||||
from rdkit.Chem.rdForceFieldHelpers import UFFGetMoleculeForceField
|
||||
|
||||
def feq(v1, v2, tol2=1e-4):
|
||||
return abs(v1 - v2) <= tol2
|
||||
@@ -408,5 +408,14 @@ M END"""
|
||||
self.assertAlmostEqual((posa - posb).Length(), 100, delta=10e-5)
|
||||
|
||||
|
||||
def test_uff_get_forcefield_runs(self):
|
||||
mol = Chem.MolFromSmiles("CCO")
|
||||
mol = Chem.AddHs(mol)
|
||||
rdDistGeom.EmbedMolecule(mol, randomSeed=42)
|
||||
ff = UFFGetMoleculeForceField(mol, ignoreInterfragInteractions=False)
|
||||
self.assertIsNotNone(ff)
|
||||
self.assertTrue(hasattr(ff, "CalcEnergy"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user