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

Quickstart and Basic usage example #123

Merged
merged 9 commits into from
Dec 13, 2024
Merged

Quickstart and Basic usage example #123

merged 9 commits into from
Dec 13, 2024

Conversation

PicoCentauri
Copy link
Contributor

@PicoCentauri PicoCentauri commented Dec 9, 2024

We have good examples explaining various aspects of torch-pme. But we lack a very basic usage example for beginners. This PR adds such a tutorial which will be displayed prominently just after the installation page and refer users to the examples and API references in the end.

Contributor (creator of pull-request) checklist

  • Tests updated (for new features and bugfixes)?
  • Documentation updated (for new features)?
  • Issue referenced (for PRs that solve an issue)?

Reviewer checklist

  • CHANGELOG updated with public API or any other important changes?

📚 Documentation preview 📚: https://torch-pme--123.org.readthedocs.build/en/123/

Copy link
Contributor Author

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good start. Thanks @kvhuguenin.

examples/basic-usage.py Show resolved Hide resolved
examples/basic-usage.py Show resolved Hide resolved
Comment on lines +222 to +271
potentials_aperiodic = calculator._compute_rspace(
charges, neighbor_indices_aperiodic, neighbor_distances_aperiodic
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe define a new calculatur here. Which is just torchpme.Calculator and a new potential with 0 smearing? This might be cleaner compared to using private methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but also feel that this should be a separate PR. I can open an issue about this. Until then, we can either keep this example using the private function, or even just remove it altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can already do it

from torchpme import Calculator

calculator = Calculator(potential=CoulombPotential(smearing=0))
calculator.forward(...)

even though I agree the same is not perfect;y indicating that this is for aperiodic structures.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, because in its current version, Calculator's forward requires an implementation of the reciprocal space sum. So this just raises an error. I have kept the example for now, but made the comments more detailed to reduce potential confusion about why this has been implemented like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arghh yes. Can you open an issue. We should fix this to allow easy usage of Real space Coulomb!

@kvhuguenin kvhuguenin marked this pull request as ready for review December 12, 2024 14:33
@kvhuguenin
Copy link
Contributor

Thanks for the changes you made and the comments @PicoCentauri . I have now generally tried to improve the comments, with suggestions coming from our beta tester as well. The issue regarding the aperiodic calculator goes beyond the intention of this PR, which is why I kept the example simple on that front.

@kvhuguenin
Copy link
Contributor

Good addition for the quickstart @PicoCentauri . Should we perhaps also reference the newly added basic-usage example there for more details?

@PicoCentauri PicoCentauri changed the title Basic usage example Quickstart and Basic usage example Dec 12, 2024
@PicoCentauri
Copy link
Contributor Author

Yes, I will update the link!

cell = 8 * torch.eye(3)
charges = torch.tensor([[1.0]])

# No neighbors for a single atom; use `vesin` for neighbors if needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it would be better to say how to use vesin here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point and I thought about it as well. In the end I decided against to keep the quickstart short and only about torch-pme; details will be shown in the basic usage tutorial.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point though. I added some comments in basic-usage.py to explain why we use the neighbor list from vesin instead of some other package.

@kvhuguenin kvhuguenin merged commit 657926b into main Dec 13, 2024
13 checks passed
@kvhuguenin kvhuguenin deleted the usage branch December 13, 2024 14:01
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

Successfully merging this pull request may close these issues.

3 participants