Luthaf/rascaline

infinite loop for cutoff=0.0 from python interface

Closed this issue · 1 comments

This piece of code leads to an infinite loop

import ase
from rascaline import SphericalExpansion

atoms = ase.Atoms("OO", positions=((0,0,0),(1,0,0)), pbc=True, cell=[2,2,2])

HYPER_PARAMETERS = {
    "cutoff": 0.0,
    "max_radial": 9,
    "max_angular": 6,
    "atomic_gaussian_width": 0.3,
    "center_atom_weight": 1.0,
    "radial_basis": {"Gto": {"spline_accuracy": 1e-6}},
    "cutoff_function": {"ShiftedCosine": {"width": 0.5}},
    "radial_scaling": {"Willatt2018": {"scale": 2.0, "rate": 1.0, "exponent": 4}},
}


calculator = SphericalExpansion(**HYPER_PARAMETERS)
descriptor0 = calculator.compute(atoms)

However a rust test

    #[test]
    fn cutoff_zero() {
        let soap_parameters = r#"{
            "cutoff": 0.0,
            "max_radial": 9,
            "max_angular": 6,
            "atomic_gaussian_width": 0.3,
            "center_atom_weight": 1.0,
            "radial_basis": {"Gto": {"spline_accuracy": 1e-6}},
            "cutoff_function": {"ShiftedCosine": {"width": 0.5}},
            "radial_scaling": {"Willatt2018": {"scale": 2.0, "rate": 1.0, "exponent": 4}}
        }"#;
    
        let mut calculator = Calculator::new(
            "spherical_expansion",
            soap_parameters.into(),
        ).unwrap();

        let mut systems = test_systems(&["water", "methane"]);
        calculator.compute(&mut systems, Default::default()).unwrap();
    }

leads to

thread 'calculators::soap::spherical_expansion::tests::cutoff_zero' panicked at 'assertion failed: `(left == right)`
  left: `NaN`,
 right: `NaN`: matrix is not symmetric', rascaline/src/math/eigen.rs:254:17

I guess these two checks should use <=:

if self.cutoff < 0.0 || !self.cutoff.is_finite() {
return Err(Error::InvalidParameter(
"cutoff must be a positive number for GTO radial integral".into()
));
}
if self.atomic_gaussian_width < 0.0 || !self.atomic_gaussian_width.is_finite() {

What happens with cutoff=1e-16?