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

[Bug] Error in SOAP derivatives when using weighting. #113

Closed
Mads-PeterVC opened this issue Jun 29, 2023 · 2 comments
Closed

[Bug] Error in SOAP derivatives when using weighting. #113

Mads-PeterVC opened this issue Jun 29, 2023 · 2 comments

Comments

@Mads-PeterVC
Copy link

Mads-PeterVC commented Jun 29, 2023

Hey.

I have been playing around with SOAP but could not obtain the result I was expecting.

I believe I have narrowed this down to an issue with weighting not being taken into account for derivatives:

The following code reproduces my error:

import numpy as np
from dscribe.descriptors import SOAP as dscribeSOAP
from ase import Atoms

r_cut = 5

weighting_schemes = {
    'none': None,
    'poly':{'function':'poly', 'r0':r_cut, 'c':1, 'm':1},
    'exp': {'function':'exp', 'r0':r_cut, 'c':1, 'd':1, 'threshold':1e-2},
    'pow': {'function':'pow', 'r0':r_cut, 'c':1, 'd':1, 'm':2},
}

atoms = Atoms('H2', positions=[[0, 0, -1/2], [0, 0, 1/2]])

for name, weighting in weighting_schemes.items():

    soap = dscribeSOAP(
        species=['H'],
        n_max=2,    
        l_max=1,
        r_cut=r_cut,
        weighting=weighting
    )

    f_analytical = soap.derivatives(atoms, return_descriptor=False, method='analytical')
    f_numerical = soap.derivatives(atoms, return_descriptor=False, method='numerical')

    check = np.allclose(f_analytical, f_numerical)
    mse = np.mean((f_analytical - f_numerical)**2)

    print(f'Weighting scheme: {name} - Match: {check} - MSE: {mse}')

For which I get:

Weighting scheme: none - Match: True - MSE: 5.281413372692342e-16
Weighting scheme: poly - Match: False - MSE: 16.873294169196846
Weighting scheme: exp - Match: False - MSE: 0.33886820479981145
Weighting scheme: pow - Match: False - MSE: 2.666499232005996

So the numerical and analytical derivatives only match when no weighting function is used, and with weighting only the numerical derivatives result in correct force predictions for my model.

Also, if r_cut is decreased the error grows, which I believe is because the slope of the weighting function is steeper.
So all of this indicates that the analytical derivatives don't take the weight function into account.

Versions
dscribe version: 2.0.0
numpy version: 1.23.5
ase version: 3.23.0b1

@lauri-codes
Copy link
Contributor

Hi @Mads-PeterVC,

Thanks for the report. I believe that analytical derivatives are not implemented for weighting. An exception should be raised if the user requests analytical derivatives with weighting turned on. I will implement a fix for this.

@lauri-codes
Copy link
Contributor

Now fixed in branch v2.0.1 which will be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants