Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup: Force field #7406

Merged
merged 21 commits into from May 10, 2024
Merged

Cleanup: Force field #7406

merged 21 commits into from May 10, 2024

Conversation

AnnaBruenisholz
Copy link
Contributor

What does this implement/fix? Explain your changes.

Some minor changes to modernize Code/ForceField.

Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few suggestions here.

There is a CI failure in the tests on intel-based Macs that looks real.
I was unsuccessful at getting an x64 build working on my Mac this weekend, so I couldn't track down what was causing this.

I would be interested to see if the problem goes away if you revert the changes that I flagged as having potential numerical instabilities. If that doesn't work then I will go back to trying to the x64 env working on my Mac.

Code/ForceField/MMFF/Params.h Outdated Show resolved Hide resolved
Code/ForceField/MMFF/Params.h Outdated Show resolved Hide resolved
Code/ForceField/MMFF/Params.h Outdated Show resolved Hide resolved
Code/ForceField/MMFF/StretchBend.cpp Show resolved Hide resolved
Code/ForceField/UFF/AngleBend.cpp Show resolved Hide resolved
Code/ForceField/UFF/Inversion.cpp Show resolved Hide resolved
Code/ForceField/Wrap/ForceField.cpp Outdated Show resolved Hide resolved
AnnaBruenisholz and others added 2 commits May 8, 2024 07:57
Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
// cos(3x) = cos^3(x) - 3*cos(x)*sin^2(x)
cosNPhi = cosPhi * (cosPhi * cosPhi - 3. * sinPhiSq);
// cos(3x) = cos^3(x) - 3*cos(x)*sin^2(x) = 4cos^3(x) -3cos(x)
cosNPhi = cosPhi * (4 * cosPhi * cosPhi - 3.);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an x64 (intel) build working on my M1 Mac and can now reproduce the problems observed in the CI builds.
This change is responsible for the failure: the minimization at line 163 of Code/ForceField/Wrap/testConstraints.py fails to converge in the default 200 iterations. If I bump the number of itrations up to 211, then it does pass.
When using the original formulation - cosNPhi = cosPhi * (cosPhi * cosPhi - 3. * sinPhiSq) - the minimization converges in ~150 iterations.

Subtracting a constant from these cosPhi products definitely does change something with the stability of the numerics.

Change is not necessarily bad: it could be that your version is actually more stable and that it's highlighting what was previously a problem that we had not noticed.

Your comment on the commits that make this change indicate that you were intending to improve the stability of the numerics; do you have some kind off references indicating that the way you restructured these calculations is actually more stable?

Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@greglandrum greglandrum added the Cleanup Code cleanup and refactoring label May 10, 2024
@greglandrum greglandrum added this to the 2024_03_3 milestone May 10, 2024
@greglandrum
Copy link
Member

Thanks for another nice set of cleanups @AnnaBruenisholz !

@greglandrum greglandrum merged commit d315e24 into rdkit:master May 10, 2024
12 checks passed
Copy link
Contributor

@ricrogz ricrogz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for intruding, I was curious about the changes, so I had a look, and I have a couple comments :)

@@ -278,22 +263,17 @@ class RDKIT_FORCEFIELD_EXPORT MMFFChgCollection {
sign = 1;
}
#ifdef RDKIT_MMFF_PARAMS_USE_STD_MAP
std::map<const unsigned int,
std::map<const unsigned int, MMFFChg>>::const_iterator res1;
std::map < const unsigned int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, this line is not right, I think it should have been deleted.

Comment on lines +535 to +537
unsigned int temp = canIAtomType;
canIAtomType = canKAtomType;
canKAtomType = temp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been a std::swap(canIAtomType, canKAtomType);

Comment on lines +562 to +564
unsigned int temp = canIAtomType;
canIAtomType = canKAtomType;
canKAtomType = temp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::swap here too

for (RDKit::SnapshotVect::const_iterator it = snapshotVect.begin();
it != snapshotVect.end(); ++it) {
l.append(new RDKit::Snapshot(*it));
for (auto it : snapshotVect) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be auto& it, to avoid an extra copy ?

@greglandrum
Copy link
Member

Sorry for intruding, I was curious about the changes, so I had a look, and I have a couple comments :)

If only you'd been 2 hours quicker! ;-)

Thanks for catching the problems. I'll fix them in a separate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Code cleanup and refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants