Skip to content

Draft: FixXXX constraints: Respect whether user specified indices or mask.

Jakob Schiøtz requested to merge mask_vs_indices into master

I just looked at the code in constraints.IndexedConstraint which is a base class for FixAtoms. You can create the constraint either specifying the indices of the fixed atoms, or a mask of booleans indicating which atoms to fix. There are two arguments, called indices and mask. This gives the impression that if you specify indices, you set the indices and if you specify mask you set the mask (specifying both is an error that is caught).

In reality, it does not matter at all if you use the indices or mask argument. What matters is only the type of the array, if it is booleans it is interpreted as a mask, if integers it is an array of indices. That makes little sense, and gives unexpected results if the boolean mask is promoted to an array of integers due to some operation.

I propose changing this so the determination of whether the user is specifying indices or mask is done based on which argument the user gives. This should be a rather simple task. It might break scripts where a mask is specified without writing mask=xxxx in the call, but the error message will be clear.

Edited by Jakob Schiøtz

Merge request reports