Skip to content

Fixed CONVERT_TO_FES to make it more back compatible with earlier versions of PLUMED. #1376

Open
gtribello wants to merge 4 commits intov2.10from
fix-gridmin-bug
Open

Fixed CONVERT_TO_FES to make it more back compatible with earlier versions of PLUMED. #1376
gtribello wants to merge 4 commits intov2.10from
fix-gridmin-bug

Conversation

@gtribello
Copy link
Member

@gtribello gtribello commented Mar 9, 2026

Description

CONVERT_TO_FES is now a shortcut action in PLUMED 2.10 that uses CUSTOM to convert to take the negative logarithm of a histogram and to multiply that by k_B T. However, I made a mistake when adapting the MINTOZERO command to work with the new version of PLUMED. To be clear, the shortcut that does this calculation works like this:

# Use -k T log P(s) to get the free energy from the histogram (h)
fu: CUSTOM ARG=h FUNC=-2.5*log(x) PERIODIC=NO
# Find the location of the minimum in the free energy surface that we have just calculated
m: FIND_GRID_MINIMUM ARG=fu 
# Subtract the minimum in the free energy from the grid so that the minimum has a free energy of zero.
f: CUSTOM ARG=fu,m.optval FUNC=x-y PERIODIC=NO

Because I am too clever for my own good, FIND_GRID_MINIMUM uses spine interpolation and a conjugate gradient algorithm to find the coordinates of the actual minimum of the free energy surface. However, the earlier implementation of MINTOZERO just searched the value of the free energy on the various grid points, found the lowest and used that as the origin.

With this change, I have thus adjusted the shortcut so that if you use the MINTOZERO option, you just find the lowest free energy point on the grid and use that for the position of the origin. The behaviour with this option thus recovers what was done in old versions of the code.

If you want to do the actual minimisation, you can use the FINDMINTOZERO, which does the conjugate gradient minimisation.

In rt-fes-periodic there were two CONVERT_TO_FES commands that use the MINTOZERO option. I changed one of these commands to FINDMINTOZERO (this is the one where the reference is unchanged). For the other, I kept it as MINTOZERO and checked that the values that you get out with this option are the same as what they would be in older versions of PLUMED. I thus ensured that we are properly maintaining back compatibility.

Target release

I would like my code to appear in release 2.10

Type of contribution
  • changes to code or doc authored by PLUMED developers, or additions of code in the core or within the default modules
  • changes to a module not authored by you
  • new module contribution or edit of a module authored by you
Copyright
  • I agree to transfer the copyright of the code I have written to the PLUMED developers or to the author of the code I am modifying.
  • the module I added or modified contains a COPYRIGHT file with the correct license information. Code should be released under an open source license. I also used the command cd src && ./header.sh mymodulename in order to make sure the headers of the module are correct.
Tests
  • I added a new regtest or modified an existing regtest to validate my changes.
  • I verified that all regtests are passed successfully on GitHub Actions.

Gareth Aneurin Tribello and others added 2 commits March 5, 2026 13:54
@GiovanniBussi
Copy link
Member

@gtribello I think the CG idea is cool, but where do you start it from? If it has multiple minima it would be stuck.

Does it make sense to start the CG from the minimum of the grid? Could this be just the new default option? This would be by definition <= than the minimum on the grid, and also very likely <= than the minimum with CG starting from 0.

@gtribello
Copy link
Member Author

@GiovanniBussi

This works by finding the grid point where the free energy has the lowest value. I then do the CG starting from there. This is what happens if you use the FINDMINTOZERO option

I wanted to make this change because Omar had a crash when he used the MINTOZERO option because the CG wasn't converging. This wouldn't have happened in old versions of the code because you are not doing the CG. I thus thought that introducing the new flag for turning this option makes sure people know what they are doing.

@GiovanniBussi
Copy link
Member

Good point! So: can you make it so that if the CG gradient does not converge it just uses the lowest point seen so far? This should be robust enough for all applications, without the need to learn an extra option

Gareth Aneurin Tribello added 2 commits March 11, 2026 12:44
… you use MINTOZERO option

Note that if no minimum is found then the lowest point is assumed to be the point on the grid where the free energy is lowest.
A warning is also printed to the log to inform users that an optimum was not found
@gtribello
Copy link
Member Author

OK @GiovanniBussi with this commit, I have done what you suggested so the behaviour now is that we try to find an optimum using the conjugate gradient. If no optimum is found then you use the lowest point on the grid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants