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

Should we have functions to add and remove atoms to/from a System? #152

Open
jgreener64 opened this issue Oct 1, 2023 · 3 comments
Open

Comments

@jgreener64
Copy link
Collaborator

A few people, most recently @Liozou, have asked about adding and removing atoms to/from a system. This isn't easy in other MD software so could be a selling point here, opening up simulation in the grand canonical ensemble among other things.

From a quick look it seems that the simulators allow the system to change atom number between steps. The challenge then is changing System itself (with an extension to ReplicaSystem). The following properties would need to change:

  • atoms
  • coords
  • velocities
  • atoms_data
  • masses (derived from atoms)
  • Indices in specific_inter_lists
  • Indices in constraints
  • Data in topology
  • Neighbour finder eligible and special matrices

The idea would be to have add_atom! and/or add_atoms! that add one or more atoms and all associated data to the end of the arrays, and delete_atom! and/or delete_atoms! that remove one or more atoms at the given indices. These functions would modify the arrays and indices as appropriate.

There are lots of details, such as providing a mini eligible matrix for added atoms to allow the addition of molecules. There are caveats, like loggers that rely on specific atom indices breaking, but those can be documented. GPU performance would probably be poor with an initial implementation, since arrays would be moved to the CPU and back. Longer term, GPU kernels could be written. Visualisation functions would also need updating.

It's also possible to hack this currently, if you know the maximum number of possible atoms, by manually changing the eligible matrix in the neighbour finder to turn on/off whole rows/columns. It might be worth making an example for that.

Let me know any thoughts.

@jgreener64
Copy link
Collaborator Author

Another consideration is how to make this work efficiently when doing trials in a Monte Carlo simulation. You may want to add atom(s), sample the energy, then decide to keep or remove the added atom(s).

@ejmeitz
Copy link
Collaborator

ejmeitz commented Jan 13, 2024

The only reason I can think of to add this is if you want to support the grad canonical ensemble. I'm sure there's other as well, but at the moment I don't see a reason to hack the interface to add this. I think effort would be better put in making the interfaces more generic so that changes like this are easier.

@jgreener64
Copy link
Collaborator Author

Yes, that's the idea.

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

2 participants