Add UFF forcefield C++ implementation#123
Conversation
Cherry-picked from pr5_uff (e7477a9). Adds UFF bond stretch, angle bend, torsion, inversion, and van der Waals terms with batched GPU evaluation. Includes RDKit UFF parameter flattening, batched forcefield wrapper, and C++ tests. Made-with: Cursor
|
| Filename | Overview |
|---|---|
| src/forcefields/uff_kernels_device.cuh | Core device-side kernel implementations for all UFF energy/gradient terms; contains a P1 inversion gradient bug where the plane normal used in uffInversionGrad is negated relative to uffCalculateCosY, causing incorrect gradient magnitudes for non-planar sp2 centres. |
| rdkit_extensions/uff_flattened_builder.cpp | Flattens RDKit UFF parameters into SoA host buffers; logic closely mirrors RDKit's UFF builder. The unusual neighborSlot increment pattern in addInversions (skipping slot 1 for the central atom) is correct but hard to follow. |
| src/forcefields/uff.cu | Host-side batch management: stream assignment, host-to-device transfers, addMoleculeToBatch, and kernel dispatchers for energy and gradient. Implementation is consistent and handles all term types including constraint terms borrowed from MMFF. |
| src/forcefields/uff_kernels.cu | Kernel launchers and two block-per-molecule kernels (combined energy + gradient). The blockSizePerMol = 128 shared-memory gradient path correctly limits to 256 atoms; fallback to global memory is correct. |
| tests/test_uff.cu | Validates GPU UFF against RDKit reference for energy, gradient, batched, and minimizer paths. Tests cover edge cases (single-atom SMILES, small molecules) and a 25-molecule validation set. Gradient tolerance of 2e-4 may be too loose to catch the inversion gradient bug on near-planar test molecules. |
Reviews (2): Last reviewed commit: "Apply copyright script" | Re-trigger Greptile
|
Partial implementation for #114 has not yet been optimized, we'll go through the kernels but lower priority. |
evasnow1992
left a comment
There was a problem hiding this comment.
Changes look good to me. Understand that further optimizations may be applied later. Also a note that python APIs haven't been added yet and document files like docs/index.rst may need updates to include UFF alongside MMFF.
Adds UFF bond stretch, angle bend, torsion, inversion, and van der Waals terms with batched GPU evaluation. Includes RDKit UFF parameter flattening, batched forcefield wrapper, and C++ tests.