glotzerlab / hoomd-blue

Molecular dynamics and Monte Carlo soft matter simulation on GPUs.
http://glotzerlab.engin.umich.edu/hoomd-blue
BSD 3-Clause "New" or "Revised" License
329 stars 127 forks source link

special_pair.lj passes r_cut instead of r_cut**2 which leads to incorrect bond energies #246

Closed joaander closed 7 years ago

joaander commented 7 years ago

Original report by Bjørnar Jensen (Bitbucket: bjensen80, ).


EvaluatorSpecialPairLJ.h expects:

#!c++
DEVICE EvaluatorSpecialPairLJ(Scalar _rsq, const param_type& _params)
            : rsq(_rsq), lj1(_params.x), lj2(_params.y), rcutsq(_params.z)

but is passed:

#!python
    def process_coeff(self, coeff):
        r_cut = coeff['r_cut'];
(...)
        return _hoomd.make_scalar3(lj1, lj2,r_cut);

leading to this comparison being incorrect:

#!c++
if (rsq < rcutsq && lj1 != 0)
{

Thus, bond energies will not be evaluated when the bond distance is less than sqrt(r_cut), rather than the expected r_cut.

To fix this issue change the return statement in special_pair.lj.process_coeff():

#!python
    def process_coeff(self, coeff):
        r_cut = coeff['r_cut'];
(...)
        return _hoomd.make_scalar3(lj1, lj2, r_cut * r_cut );

or:

#!python
    def process_coeff(self, coeff):
        r_cut = coeff['r_cut'];
        r_cutsq = r_cut * r_cut;
(...)
        return _hoomd.make_scalar3(lj1, lj2, r_cutsq);

BTW: The unit test does not check for inside/outside cutoff functionality.

joaander commented 7 years ago

Fix bug (Issue #246) incorrect value for r_cutsq passed. Add unit test.

Fixing issue 246 by calculating and passing r_cut * r_cut (as expected) to the evaluator class.

Add unit test for checking that cutoff is correctly handled.

joaander commented 7 years ago

Merged in bjensen80/hoomd-blue/fix_special_pair_lj_cutoff_not_squared (pull request #339)

Fix bug (Issue #246) incorrect value for r_cutsq passed. Add unit test.

fixes #246

Approved-by: Jens-Steffen Glaser jsglaser@umich.edu Approved-by: Joshua Anderson joaander@umich.edu