Skip to content

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

@jgreener64

Description

@jgreener64

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions