lab-cosmo / librascal

A scalable and versatile library to generate representations for atomic-scale learning
https://lab-cosmo.github.io/librascal/
GNU Lesser General Public License v2.1
80 stars 20 forks source link

Pad Representation with zeros for non-present species #350

Open rosecers opened 3 years ago

rosecers commented 3 years ago

I have this problem quite often, where I'm computing a subset of SOAP vectors for who species ABCD are present, then another subset where only ABD are present. I know that I can use the species pair dictionary to collect SOAPs per species pair, but it would be far, far more convenient to do something like this:

hyperparameters = {
    "soap_type": "PowerSpectrum",
    ...

    # I know this keyword exists, but seems to only affect `expansion_by_species_method`
    "global_species": [A, B, C, D, ...] 
}
soap = SOAP(**hyperparameters)

featuresABCD = soap.transform(framesABCD).get_features(soap)
featuresABD = soap.transform(framesABD).get_features(soap)

where featuresABCD and featuresABD have the same indexing and shape.

max-veit commented 3 years ago

For global_species to work, I think you also have to set expansion_by_species_method="user defined" in the hypers. Is that what you meant by the comment in your example?

ceriottm commented 3 years ago

Would it make sense to have a non-null "global_species" automatically set "user_defined" expansion_by_species_method?

On Thu, 6 May 2021 at 18:15, Max Veit @.***> wrote:

For global_species to work, I think you also have to set expansion_by_species_method="user defined" in the hypers. Is that what you meant by the comment in your example?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cosmo-epfl/librascal/issues/350#issuecomment-833651912, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIREZ3W6CS7LUNSYXAIQ7DTMK6A5ANCNFSM44HK2Y7Q .

rosecers commented 3 years ago

Yes, that would fix it quite nicely!

On May 6, 2021, at 9:41 PM, Michele Ceriotti @.***> wrote:

Would it make sense to have a non-null "global_species" automatically set "user_defined" expansion_by_species_method?

On Thu, 6 May 2021 at 18:15, Max Veit @.***> wrote:

For global_species to work, I think you also have to set expansion_by_species_method="user defined" in the hypers. Is that what you meant by the comment in your example?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cosmo-epfl/librascal/issues/350#issuecomment-833651912, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIREZ3W6CS7LUNSYXAIQ7DTMK6A5ANCNFSM44HK2Y7Q .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cosmo-epfl/librascal/issues/350#issuecomment-833809413, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALKVP3RGO7NW2MLR4JQUGETTMLWILANCNFSM44HK2Y7Q.

max-veit commented 3 years ago

Ok, this is now implemented in bugfix/soap_global_species. Let me know if you want to add tests as well; I think that could be a good idea.

rosecers commented 3 years ago

Looking at the code, I have a few thoughts (first of which is turning the branch into a draft PR).