aiqm / torchani

Accurate Neural Network Potential on PyTorch
https://aiqm.github.io/torchani/
MIT License
446 stars 125 forks source link

Difficulty with PBC #605

Closed SamTov closed 2 years ago

SamTov commented 2 years ago

Hello, I am trying to train some torchANI models for periodic systems but struggling to get the PBC to work well. The tensors I give it for cell and pbc are of the form:

cell = torch.eye(3, dtype=torch.double) * 10
pbc = torch.ones(3, dtype=torch.bool)

I have this for each configuration of atoms (ase Atoms objects). My pass to the network looks like this:

_, predicted_energies = self.torch_model(
                        (species, coordinates),
                        cell=cell,
                        pbc=condition
                    )

where in this case cell and condition are of the shape (n_configurations, 3, 3) for the cell and (n_configurations, 3) for condition.

When I run this I find an error like this:

num_repeats = torch.where(pbc, num_repeats, num_repeats.new_zeros(()))
RuntimeError: The size of tensor a (3) must match the size of tensor b (64) at non-singleton dimension 1

I have tried to play around with the shape of the data but struggle to get anything meaningful from it. Any suggestions would be greatly appreciated.

isayev commented 2 years ago

Your definition of the periodic system is incorrect. This must pass (3, 3) matrix of cell vectors to cell variable and boolean vector of size 3 to pbc if you want to have periodicity in all 3 dimensions.

zubatyuk commented 2 years ago

Samuel: the current implementation of PBC in TorchANI is not 'batched', you can not do a batch of crystals.

On Fri, Dec 10, 2021 at 11:53 AM Olexandr Isayev @.***> wrote:

Your definition of the periodic system is incorrect. This must pass (3, 3) matrix of cell vectors to cell variable and boolean vector of size 3 to pbc if you want to have periodicity in all 3 dimensions.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aiqm/torchani/issues/605#issuecomment-991133093, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7FDQ4NBRDWHGFZLKHIYCLUQIWB5ANCNFSM5JZPAGZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

SamTov commented 2 years ago

Perfect, thank you for the feedback.