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

Weird behavior of LOWER_WALLS #1091

Closed
riccardocapelli opened this issue Jun 28, 2024 · 3 comments
Closed

Weird behavior of LOWER_WALLS #1091

riccardocapelli opened this issue Jun 28, 2024 · 3 comments
Labels

Comments

@riccardocapelli
Copy link
Contributor

Today I used a LOWER_WALLS potential on a distance and set the exponent of the function to 1.

Looking at the bias, I got a value of 0 when d>threshold, but a negative value (i.e. an attractive potential) when d<threshold.

Is this the expected behavior (and I should put a - in front of the KAPPA) or, as the name of LOWER_WALLS suggests, is this a bug?

Thanks a lot!

Riccardo

@Iximiel
Copy link
Member

Iximiel commented Sep 9, 2024

I think the problem is here:

readInputLine( getShortcutLabel() + "_pow_" + argn + ": CUSTOM PERIODIC=NO FUNC=step(-x)*x^" + exp[i] + " ARG=" + getShortcutLabel() + "_scale_" + argn );

LOWER_WALLS now gets shorcut to a custom func step(-x)*x^pow so that if pow is odd x^pow<0 when x<0.

whereas UPPER_WALLS to step(x)*x^pow, but UPPER_WALLS does not care about the sign of x in the exponential part

The solution should be to change the custom function to either:
-step(-x)*abs(x)^pow

  • step(-x)*(-x)^pow.

We need to test the faster between the two and PR it I think (and maybe add a test for this)

Iximiel added a commit to Iximiel/plumed2 that referenced this issue Sep 9, 2024
@GiovanniBussi
Copy link
Member

I agree that this is a bug, should be fixed as @Iximiel suggested (the two approaches should have the same measurable performance)

@Iximiel
Copy link
Member

Iximiel commented Sep 13, 2024

I think @riccardocapelli just kicked a beehive 🐛

#1109 may not be enough:

I'll use a "fancy nomenclature":

  • UPPER_WALL is "above", so it should "push down" when you get above it
  • LOWER_WALL is "below", so it should "push up" when you get under it

With @Puncist we started to set up the most simple test for this (walls on the x coordinate), and we discovered a few interesting things, already in 2.9:

  • UPPER_WALLS works as intended
  • LOWER_WALLS pushes "down" instead of "up"
Some examples in spoiler

We are running with this config

type=driver
arg="--plumed plumed.dat --ixyz trajectory.xyz  --debug-forces forces --dump-forces-fmt=%8.4f"


function plumed_regtest_before() {
    for x in {-5..5}; do
        echo "1" 
        echo "100 100 100"
        echo "C $x 0 0"
    done > trajectory.xyz    
}

function plumed_regtest_after() {   
    awk 'NR==1{print} /^ 0 /{print}' forces > forces_0_x
}

forces_0_x are the values of the forces on the x component of atom 1 (I called it 0_x because I think in C...)

And this plumed.dat:

p: POSITION ATOM=1 NOPBC

UPPER_WALLS ARG=p.x AT=0 KAPPA=1.0 EXP=__FILL__ LABEL=uwall
LOWER_WALLS ARG=p.x AT=0 KAPPA=1.0 EXP=__FILL__ LABEL=lwall

PRINT ARG=p.x,*.bias,*.force2 FILE=COLVAR 

With these two files, you can reproduce the same thing on your PC.

I checked out the branch v2.9, but on master you can get the same results

EXP=1

forces_0_x

#! FIELDS parameter analytical numerical
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000
 0   0.0000  -1.0000
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000
 0  -1.0000  -1.0000

Also, the numerical derivative is -1 in x=0

COLVAR

#! FIELDS time p.x uwall.bias lwall.bias uwall.force2 lwall.force2
 0.000000 -5.000000 0.000000 -5.000000 0.000000 1.000000
 1.000000 -4.000000 0.000000 -4.000000 0.000000 1.000000
 2.000000 -3.000000 0.000000 -3.000000 0.000000 1.000000
 3.000000 -2.000000 0.000000 -2.000000 0.000000 1.000000
 4.000000 -1.000000 0.000000 -1.000000 0.000000 1.000000
 5.000000 0.000000 0.000000 0.000000 0.000000 0.000000
 6.000000 1.000000 1.000000 0.000000 1.000000 0.000000
 7.000000 2.000000 2.000000 0.000000 1.000000 0.000000
 8.000000 3.000000 3.000000 0.000000 1.000000 0.000000
 9.000000 4.000000 4.000000 0.000000 1.000000 0.000000
 10.000000 5.000000 5.000000 0.000000 1.000000 0.000000

EXP=2

forces_0_x

#! FIELDS parameter analytical numerical
 0  10.0000  10.0000
 0   8.0000   8.0000
 0   6.0000   6.0000
 0   4.0000   4.0000
 0   2.0000   2.0000
 0   0.0000  -0.0000
 0  -2.0000  -2.0000
 0  -4.0000  -4.0000
 0  -6.0000  -6.0000
 0  -8.0000  -8.0000
 0 -10.0000 -10.0000

COLVAR

#! FIELDS time p.x uwall.bias lwall.bias uwall.force2 lwall.force2
 0.000000 -5.000000 0.000000 25.000000 0.000000 100.000000
 1.000000 -4.000000 0.000000 16.000000 0.000000 64.000000
 2.000000 -3.000000 0.000000 9.000000 0.000000 36.000000
 3.000000 -2.000000 0.000000 4.000000 0.000000 16.000000
 4.000000 -1.000000 0.000000 1.000000 0.000000 4.000000
 5.000000 0.000000 0.000000 0.000000 0.000000 0.000000
 6.000000 1.000000 1.000000 0.000000 4.000000 0.000000
 7.000000 2.000000 4.000000 0.000000 16.000000 0.000000
 8.000000 3.000000 9.000000 0.000000 36.000000 0.000000
 9.000000 4.000000 16.000000 0.000000 64.000000 0.000000
 10.000000 5.000000 25.000000 0.000000 100.000000 0.000000

EXP=3

forces_0_x

#! FIELDS parameter analytical numerical
 0 -75.0000 -75.0000
 0 -48.0000 -48.0000
 0 -27.0000 -27.0000
 0 -12.0000 -12.0000
 0  -3.0000  -3.0000
 0   0.0000  -0.0000
 0  -3.0000  -3.0000
 0 -12.0000 -12.0000
 0 -27.0000 -27.0000
 0 -48.0000 -48.0000
 0 -75.0000 -75.0000

COLVAR

#! FIELDS time p.x uwall.bias lwall.bias uwall.force2 lwall.force2
 0.000000 -5.000000 0.000000 -125.000000 0.000000 5625.000000
 1.000000 -4.000000 0.000000 -64.000000 0.000000 2304.000000
 2.000000 -3.000000 0.000000 -27.000000 0.000000 729.000000
 3.000000 -2.000000 0.000000 -8.000000 0.000000 144.000000
 4.000000 -1.000000 0.000000 -1.000000 0.000000 9.000000
 5.000000 0.000000 0.000000 0.000000 0.000000 0.000000
 6.000000 1.000000 1.000000 0.000000 9.000000 0.000000
 7.000000 2.000000 8.000000 0.000000 144.000000 0.000000
 8.000000 3.000000 27.000000 0.000000 729.000000 0.000000
 9.000000 4.000000 64.000000 0.000000 2304.000000 0.000000
 10.000000 5.000000 125.000000 0.000000 5625.000000 0.000000

EXP=10

forces_0_x

#! FIELDS parameter analytical numerical
 0 19531250.0000 19531249.7500
 0 2621440.0000 2621439.9531
 0 196830.0000 196829.9956
 0 5120.0000 5119.9998
 0  10.0000  10.0000
 0   0.0000  -0.0000
 0 -10.0000 -10.0000
 0 -5120.0000 -5120.0002
 0 -196830.0000 -196830.0044
 0 -2621440.0000 -2621440.0469
 0 -19531250.0000 -19531250.2500

COLVAR

#! FIELDS time p.x uwall.bias lwall.bias uwall.force2 lwall.force2
 0.000000 -5.000000 0.000000 9765625.000000 0.000000 381469726562500.000000
 1.000000 -4.000000 0.000000 1048576.000000 0.000000 6871947673600.000000
 2.000000 -3.000000 0.000000 59049.000000 0.000000 38742048900.000000
 3.000000 -2.000000 0.000000 1024.000000 0.000000 26214400.000000
 4.000000 -1.000000 0.000000 1.000000 0.000000 100.000000
 5.000000 0.000000 0.000000 0.000000 0.000000 0.000000
 6.000000 1.000000 1.000000 0.000000 100.000000 0.000000
 7.000000 2.000000 1024.000000 0.000000 26214400.000000 0.000000
 8.000000 3.000000 59049.000000 0.000000 38742048900.000000 0.000000
 9.000000 4.000000 1048576.000000 0.000000 6871947673600.000000 0.000000
 10.000000 5.000000 9765625.000000 0.000000 381469726562500.000000 0.000000

EXP=11

forces_0_x

 0 -107421875.0000 -107421873.5000
 0 -11534336.0000 -11534335.7812
 0 -649539.0000 -649538.9844
 0 -11264.0000 -11263.9996
 0 -11.0000 -11.0000
 0   0.0000  -0.0000
 0 -11.0000 -11.0000
 0 -11264.0000 -11264.0004
 0 -649539.0000 -649539.0156
 0 -11534336.0000 -11534336.1875
 0 -107421875.0000 -107421876.5000

COLVAR

#! FIELDS time p.x uwall.bias lwall.bias uwall.force2 lwall.force2
 0.000000 -5.000000 0.000000 -48828125.000000 0.000000 11539459228515624.000000
 1.000000 -4.000000 0.000000 -4194304.000000 0.000000 133040906960896.000000
 2.000000 -3.000000 0.000000 -177147.000000 0.000000 421900912521.000000
 3.000000 -2.000000 0.000000 -2048.000000 0.000000 126877696.000000
 4.000000 -1.000000 0.000000 -1.000000 0.000000 121.000000
 5.000000 0.000000 0.000000 0.000000 0.000000 0.000000
 6.000000 1.000000 1.000000 0.000000 121.000000 0.000000
 7.000000 2.000000 2048.000000 0.000000 126877696.000000 0.000000
 8.000000 3.000000 177147.000000 0.000000 421900912521.000000 0.000000
 9.000000 4.000000 4194304.000000 0.000000 133040906960896.000000 0.000000
 10.000000 5.000000 48828125.000000 0.000000 11539459228515624.000000 0.000000

and so on

Iximiel added a commit to Iximiel/plumed2 that referenced this issue Oct 10, 2024
carlocamilloni pushed a commit that referenced this issue Oct 10, 2024
Co-authored-by: Daniele Rapetti <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants