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

Running Inference for a large organic molecule #155

Closed
nishi-acog opened this issue Nov 25, 2022 · 11 comments
Closed

Running Inference for a large organic molecule #155

nishi-acog opened this issue Nov 25, 2022 · 11 comments

Comments

@nishi-acog
Copy link

I'm trying to run inference on an organic molecule of 47 atoms. I'm using the equivariant transformer pretrained on the ANI-1 dataset. I passed atomic numbers and the coordinates as tensors and am interested to get the energy. On running the code, it is giving the following error:

Traceback (most recent call last):
  File "//test1.py", line 35, in <module>
    energy, forces = model(z, pos)
  File "/opt/conda/envs/torchmd-net/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/torchmdnet/models/model.py", line 171, in forward
    x, v, z, pos, batch = self.representation_model(z, pos, batch, q=q, s=s)
  File "/opt/conda/envs/torchmd-net/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/torchmdnet/models/torchmd_et.py", line 161, in forward
    edge_index, edge_weight, edge_vec = self.distance(pos, batch)
  File "/opt/conda/envs/torchmd-net/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/torchmdnet/models/utils.py", line 221, in forward
    assert not (
AssertionError: The neighbor search missed some atoms due to max_num_neighbors being too low. Please increase this parameter to include the maximum number of atoms within the cutoff.
@giadefa
Copy link
Contributor

giadefa commented Nov 25, 2022 via email

@nishi-acog
Copy link
Author

Read the error and do what it says

On Fri, Nov 25, 2022, 07:40 Nishi Maru @.***> wrote: I'm trying to run inference on an organic molecule of 47 atoms. I'm using the equivariant transformer pretrained on the ANI-1 dataset. I passed atomic numbers and the coordinates as tensors and am interested to get the energy. On running the code, it is giving the following error: Traceback (most recent call last): File "//test1.py", line 35, in energy, forces = model(z, pos) File "/opt/conda/envs/torchmd-net/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/torchmdnet/models/model.py", line 171, in forward x, v, z, pos, batch = self.representation_model(z, pos, batch, q=q, s=s) File "/opt/conda/envs/torchmd-net/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/torchmdnet/models/torchmd_et.py", line 161, in forward edge_index, edge_weight, edge_vec = self.distance(pos, batch) File "/opt/conda/envs/torchmd-net/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(input, kwargs) File "/torchmdnet/models/utils.py", line 221, in forward assert not ( AssertionError: The neighbor search missed some atoms due to max_num_neighbors being too low. Please increase this parameter to include the maximum number of atoms within the cutoff. — Reply to this email directly, view it on GitHub <#155>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3KUORZ4XGAWNEKW3RJDQLWKBNMNANCNFSM6AAAAAASLAEGSA . You are receiving this because you are subscribed to this thread.Message ID: @.>

Increased the max_num_neighbour value from 32 (default) to 64, 128, 256. But it does not solve the error.

@stefdoerr
Copy link
Collaborator

Are you sure your coordinates are in Angstrom and not nanometers? That would increase the density by enough to make it unusable.

@nishi-acog
Copy link
Author

Are you sure your coordinates are in Angstrom and not nanometers? That would increase the density by enough to make it unusable.

yes, The coordinates are in Angstrom.

@stefdoerr
Copy link
Collaborator

Actually this should not matter. If your molecule is 47 atoms, setting the max_num_neighbour to anything above 47 would trivially solve it anyway. Can you paste here coords.shape and coords.max(axis=1) and coords.min(axis=1)

@nishi-acog
Copy link
Author

correction: molecule has 48 atoms.

coords.shape: (48, 3)
coords.max(axis=1): [8.703  7.7166 6.4845 5.3732 5.3826 7.7184 6.6121 6.4047 7.0476 8.7741
 8.3729 4.4812 6.7936 5.3572 7.0082 6.4674 9.0651 9.7112 4.1776 3.1197
 4.1036 3.5677 2.0255 2.829  4.8971 3.3243 1.2144 4.9898 5.9979 6.1974
 5.0469 7.1477 5.6866 4.7543 4.1629 5.3059 3.2179 4.4738 4.7848 5.4462
 6.7529 6.1005 7.0925 4.0182 5.167  7.5072 8.1241 6.3573]
coords.min(axis=1): [-0.8302 -0.264  -0.924  -0.374   0.8724  1.0362  1.5624 -2.2719  1.0544
  1.9202  1.4383 -0.9964 -2.2341 -2.5844 -2.9782  0.4735  1.2609  1.76
  0.9011  0.3158  0.867   0.2542 -0.252  -0.2992  1.3306 -0.7622 -0.6862
  0.1522  1.3402  2.2517  1.2963  0.7108  0.8486  0.5487  1.781  -0.0556
 -0.6178 -1.1956 -2.4811 -0.5876 -0.8733 -2.9471 -2.1452 -3.0958 -0.9863
 -1.1706 -2.4918 -3.9382]

Actually this should not matter. If your molecule is 47 atoms, setting the max_num_neighbour to anything above 47 would trivially solve it anyway. Can you paste here coords.shape and coords.max(axis=1) and coords.min(axis=1)

@stefdoerr
Copy link
Collaborator

I see you are running it from a custom script. Can you show me how you set the max_num_neighbour attribute? Or the whole script even better.

@nishi-acog
Copy link
Author

I'm running the inference code mentioned in the examples. I'm passing the atomic coordinates as tensor (not using random function).
>Do we have to set max_num_neighbour attribute here?

I changed the cut off values in the files mentioned in the error.

  • /torchmdnet/models/torchmd_et.py line 69.
  • /torchmdnet/models/utlis.py line 200.

@stefdoerr
Copy link
Collaborator

You are not supposed to modify the source code, changing the function argument defaults would probably not do anything if the caller is passing a specific value to it. You should set it in load_model. I guess the documentation is not very clear on that.

model = load_model("ANI1-equivariant_transformer/epoch=359-val_loss=0.0004-test_loss=0.0120.ckpt", derivative=True, max_num_neighbors=50)

@nishi-acog
Copy link
Author

nishi-acog commented Nov 30, 2022

Thanks, Stefan. It worked.

@stefdoerr
Copy link
Collaborator

Great to hear that :)

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

3 participants