librascal icon indicating copy to clipboard operation
librascal copied to clipboard

Warn the user if two atoms are at the same position

Open Luthaf opened this issue 3 years ago • 4 comments

I'm using the following code and the attached structure.

structure.xyz

import ase
from ase import io  # noqa

from rascal.representations import SphericalInvariants

SOAP_HYPERS = {
    "soap_type": "PowerSpectrum",
    "normalize": False,
    "interaction_cutoff": 5,
    "cutoff_smooth_width": 0.5,
    "max_radial": 8,
    "max_angular": 8,
    "gaussian_sigma_type": "Constant",
    "gaussian_sigma_constant": 0.3,
    "radial_basis": "GTO",
    "compute_gradients": False,
}

frames = ase.io.read("structure.xyz", ":")

soap = SphericalInvariants(**SOAP_HYPERS)
X = soap.transform(frames).get_features(soap)

print(X[:, -1])

I get this output:

Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now
Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now


[1.32404987e-06 1.32389885e-06 1.32389885e-06 1.32404987e-06
 1.32389885e-06 1.32389885e-06 1.32389885e-06 1.32389885e-06
 1.41811625e-07 1.41840593e-07 1.41840261e-07 1.41811957e-07
 1.41840261e-07 1.41840593e-07 1.41840261e-07 1.41840593e-07
 1.41221610e-06 1.41220744e-06 1.41220803e-06 1.41221551e-06
 1.41220803e-06 1.41220744e-06 1.41220803e-06 1.41220744e-06
 1.72678016e-06 1.72675520e-06 1.72676937e-06 1.72676600e-06
 1.72675520e-06 1.72675520e-06 1.72675520e-06 1.72675520e-06
 5.34736727e-07 5.34717055e-07 5.34717055e-07 5.34736727e-07
 5.34717055e-07 5.34717055e-07 5.34717055e-07 5.34717055e-07
 1.54582174e-06 1.54590276e-06 1.54590276e-06 1.54582174e-06
 1.54590276e-06 1.54590476e-06 1.54590476e-06 1.54590276e-06
 4.98412470e-06 4.98413124e-06 4.98413124e-06 4.98412470e-06
 4.98413124e-06 4.98414651e-06 4.98414651e-06 4.98413124e-06
 1.96918563e-06 1.96917678e-06 1.96917678e-06 1.96918563e-06
 1.96917678e-06 1.96907997e-06 1.96907997e-06 1.96917678e-06
 1.42320147e-06 1.42320025e-06 1.42320147e-06 1.42320025e-06
 1.42320663e-06 1.42313415e-06 1.42314054e-06 1.42320025e-06
 2.76238848e-06 2.76238848e-06 2.76238848e-06 2.76238848e-06
 2.76238848e-06 2.76218716e-06 2.76218716e-06 2.76238848e-06
 1.05016731e-06 1.05016731e-06 1.05016731e-06 1.05016731e-06
 1.05016731e-06 1.05017902e-06 1.05018991e-06 1.05015642e-06
 2.58893883e-08 2.58895282e-08 2.58751883e-08 2.58751883e-08
 3.11750909e-06 3.11750909e-06 3.11758865e-06 3.11758865e-06
            nan            nan            nan            nan
            nan            nan            nan            nan
            nan            nan            nan            nan
            nan            nan            nan            nan
            nan            nan            nan            nan]

Notice the nan values for some environments in this structure.

This might be another issue with the neighbor list, given this structure has a strange unit cell. I think the Warning: SphericalHarmonics::calc(): Direction vector unnormalized, normalizing it now come from some direction vectors containing NaN, which are propagated all the way up to SOAP.

Luthaf avatar Mar 10 '21 15:03 Luthaf

So it's clearly SphericalHarmonics getting some weird inputs (like a zero vector). Could you check that the atoms and periodic images are not overlapping? If it's not something silly about the structure then the unit cell/positions are not properly interpreted by the neighborlist indeed.

felixmusil avatar Mar 10 '21 20:03 felixmusil

There are indeed atoms overlapping here =/. The structure comes from a CIF file that contained disorder information and partial occupancy data, leading to multiple atoms at the same position when converted to XYZ.

This is not really a bug on the librascal side, but a surprising behaviour! Should we add some kind of check that all distances in the neighbors list are larger than 1e-3? This would improve the user experience quite a lot.

Luthaf avatar Mar 11 '21 13:03 Luthaf

There could be a warning at the level of the strict NL so that it's clear that whatever happens afterwards will be fishy. Should it just be a warning ? An error ? And the threshold is a bit of an issue since in principle the units could be different from Bohr, angstroms and be millimetres... Do you have some suggestions ?

felixmusil avatar Mar 11 '21 15:03 felixmusil

Since the units could be different, I think a warning is good. If anything else, it should help diagnose bad structures, and can be ignored if you want to.

Luthaf avatar Mar 11 '21 16:03 Luthaf