-
Notifications
You must be signed in to change notification settings - Fork 91
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
Similarity kernel implementation? #150
Comments
Hi @alejandroarche! The SOAP output from dscribe contains all of the information needed for the vector In that same documentation page, you can see how the output vector is ordered, and you can also get a part belonging to a specific So if I understood the alchemical kernel correctly, you should be able to build it from the dscribe SOAP output. It would look something like this: import numpy as np
from dscribe.descriptors import SOAP
from ase.build import molecule
from ase import Atoms
# Setup two systems that have completely different species.
system_1 = Atoms(symbols=['H'], positions=[[0,0,0]])
system_2 = Atoms(symbols=['O'], positions=[[0,0,0]])
# Set up the SOAP descriptor
species = ['H', 'O']
soap = SOAP(
species=species,
periodic=False,
r_cut=2,
sigma=0.5,
n_max=6,
l_max=6,
)
# Create power spectrums. A "normal" kernel would see these two SOAP vectors as
# completely different as they dont share any species.
p_1 = soap.create(system_1, centers=[0])
p_2 = soap.create(system_2, centers=[0])
# Define dummy "alchemical" kernel
kernel = {
("H", "H"): 1,
("H", "O"): 1,
("O", "H"): 1,
("O", "O"): 1,
}
# Calculate similarity between p_1 and p_2: our dummy kernel says that H and O
# are chemically identical, so the similarity will be very big (note that the
# kernel is not normalized).
similarity = 0
for alpha_1 in species:
for beta_1 in species:
for alpha_2 in species:
for beta_2 in species:
# TODO: Here I only use the same-species terms, which is a
# major simplification. The same-species terms have a smaller
# size than cross-species terms due to the fact that dscribe
# does not store the symmetric elements. To have shapes that
# are compatible for the dot-product, you would have to
# re-create the dropped terms here manually. Maybe the SOAP
# descriptor should have flag that disables the dropping out of
# these terms? See also issue #48
if alpha_1 == beta_1 and alpha_2 == beta_2:
similarity += np.dot(
p_1[0, soap.get_location([alpha_1, beta_1])],
p_2[0, soap.get_location([alpha_2, beta_2])]
) * kernel[alpha_1, alpha_2] * kernel[beta_1, beta_2]
print(similarity) The only catch is that the It should be possible to introduce a flag in SOAP that disables the dropping out of these symmetric parts. That would just require a bit of digging around in the codebase (see e.g. here). We would be more than happy to include such a PR. |
Hi all!
I am reading https://doi.org/10.1039/C6CP00415F and I would like to use a global similarity kernel, as defined in Equation 18, which basically gives information about mixed-species components:
![Screenshot 2024-12-16 at 14 55 52](https://private-user-images.githubusercontent.com/136444735/396142549-34c0e301-2693-46da-8ca5-2e8325d9f8b0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NzY2MjYsIm5iZiI6MTczODk3NjMyNiwicGF0aCI6Ii8xMzY0NDQ3MzUvMzk2MTQyNTQ5LTM0YzBlMzAxLTI2OTMtNDZkYS04Y2E1LTJlODMyNWQ5ZjhiMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwOFQwMDU4NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kMGJlZjYxYmJmNWY5ZjUzOWU2NzgzZGQyZTU1MzcwNjkwZjY5YTQyYjQyM2ZkYjc3M2U2Y2Q3YzcxZWRmOWY3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.SMTWdlJwRyaFWAEGsxzcUMG5efuVKTfjdcXIBXx7wUo)
Is this feature available in dscribe? Or perhaps could you show me the corresponding source code to be modified? In the end it's just about adding a customised function that lives between 0 and 1. For instance;
![Screenshot 2024-12-16 at 14 56 56](https://private-user-images.githubusercontent.com/136444735/396142970-2356fca1-66b5-4bb1-82a3-79d64c91d18c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NzY2MjYsIm5iZiI6MTczODk3NjMyNiwicGF0aCI6Ii8xMzY0NDQ3MzUvMzk2MTQyOTcwLTIzNTZmY2ExLTY2YjUtNGJiMS04MmEzLTc5ZDY0YzkxZDE4Yy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwOFQwMDU4NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNmYxZWI2ZDJiNzQxMjYzOTliYTgwMjM3Y2EwNjE0NjFlNTY5NDIyYTQ4ZDBiNjkzYjc5MzkyOWEwNDRjNzZjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.SN5Fogv6EjcQNGi2LVRzxC9eU0QLs_wTPPd_UXI4FQA)
Many thanks in advance.
Best,
Alejandro
The text was updated successfully, but these errors were encountered: