lammps/lammps

[Feature Request] Refactor access to and error messages for atom styles

akohlmey opened this issue · 0 comments

Summary

Currently, there is a mixed bag of error messages for when a specific atom style is needed and what per-atom attributes are missing for using a specific command or option of a command. The suggestion is to remove some redundancy, simplify the checking and provide consistent errors.

Detailed Description

Atom styles provide access to per-atom data. An atom style corresponds to an AtomVecXXX class which internally maintains lists of which per-atom properties are managed by a specific atom style. These lists can be augmented through using a hybrid atom style or using fix property/atom. On the other hand, commands (e.g. fix nve/sphere) may require per-atom attributes (radius, torque, omega) that are not present in all atom styles. To avoid crashes due to NULL pointer dereferencing this is being checked for. Sometimes there are checks for specific atom styles, sometimes for a "_flag" being set to 1, and sometimes for whether the array with the data is a NULL pointer or not. Historically, checking for the atom style was simplest, since atom style and commands were often part of a package and could only be used together. However, in recent years this distinction has been blurred and there are now variants of atom styles and more flexible ways to mix per-atom attributes, so that it is more consistent to check for individual attributes being available than for specific atom styles. This will also maintain compatibility when new variants of atom styles are introduced. A further simplification is that the "_flag" variables have become redundant, since after the last refactoring of the AtomVec classes, it is guaranteed that attributes are present when the pointer is non-NULL, so checking for the pointer can be used instead of the "_flag" variables.

This suggestion is to make things consistent and perform checks only on attributes and report their names in the source (i.e. the name of the pointer variable in the Atom class) and not the name used in the description of the data file. In some cases, the internal attribute is determined from other attributes (e.g. radius is diameter/2, rmass is computed from density and diameter, rmass is the pointer for per-atom masses while mass is the pointer for per-type masses).

Further Information, Files, and Links

This is an extension of the changes from PR #4054