Is this a bug in Value::bringBackInPbc?

36 views
Skip to first unread message

Snow Summer

unread,
May 19, 2017, 10:49:24 AM5/19/17
to PLUMED users
Hello,

It seems when domainMax + domainMin != 0, the Value::bringBackInPbc doesn't work properly.

For example, if value X is in [0,6], when X=4, bringBackInPbc(X) will return 1 instead of 4.

The related code is:
inline
double Value::bringBackInPbc(double d1)const {
   
return difference(min+max_minus_min/2., d1);
}

If min+max_minus_min/2. is zero then the result is right, but when min+max_minus_min/2. is not zero the result is wrong.

I modified the code like this:
inline
double Value::bringBackInPbc(double d1)const {
  if(d1 > min && d1 < max) 
    return d1;
  else
    return difference(min+max_minus_min/2., d1);
}

The result now seems right.

Is this a bug?

Thanks.

Giovanni Bussi

unread,
May 19, 2017, 11:13:06 AM5/19/17
to plumed...@googlegroups.com
I think you are right, this is a bug. Very bad, since it was there since a long time.

I think the right expression should be something like:

inline
double Value::bringBackInPbc(double d1)const {
    return min+max_minus_min/2+ difference(min+max_minus_min/2., d1);
}

Can you check if this solves the problem?

By using grep to see where this is used I would suppose this could affect the following situations:
- METAD with ADAPT=DIFF
- EXTENDED_LAGRANGIAN
In both cases, the problem would only arise for periodic variables where min+max!=0.0, which is probably uncommon.

Can you confirm? Do you know other places where this could hurt? 

Thanks a lot!

Giovanni

--
You received this message because you are subscribed to the Google Groups "PLUMED users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plumed-users+unsubscribe@googlegroups.com.
To post to this group, send email to plumed...@googlegroups.com.
Visit this group at https://groups.google.com/group/plumed-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/plumed-users/63f5605b-3a5a-4696-a4b2-4b062e2a186e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Snow Summer

unread,
May 19, 2017, 11:41:49 AM5/19/17
to PLUMED users
I noticed this bug when I was testing PUCKERING with my new bias code. My code uses bringBackInPbc the same as in EXTENDED_LAGRANGIAN.

The 6-member puckering has phi that ranges from 0 to 2pi.

By the way, I am not sure whether using atan2 to calculate phi is correct. The atan2 ranges from -pi to pi. Is it necessary to add 2*pi when phi < 0?

Thanks.

在 2017年5月19日星期五 UTC+8下午11:13:06,Giovanni Bussi写道:
To unsubscribe from this group and stop receiving emails from it, send an email to plumed-users...@googlegroups.com.

Giovanni Bussi

unread,
May 19, 2017, 11:49:08 AM5/19/17
to plumed...@googlegroups.com
I think that when the value is set with value->set() it is automatically brought in the correct range (using a method with the bug you reported). So, even though using atan2() the result reported will be in the range (0,2pi).

I checked with this command
grep componentIsPeriodic */*cpp

and it looks like the only variable with a periodicity not in (-x,x) range is PUCKERING phi component. Thanks again for finding the problem!

Giovanni

To unsubscribe from this group and stop receiving emails from it, send an email to plumed-users+unsubscribe@googlegroups.com.

To post to this group, send email to plumed...@googlegroups.com.
Visit this group at https://groups.google.com/group/plumed-users.
Reply all
Reply to author
Forward
0 new messages