Skip to content

Added a constraint `FixSubsetCom` to fix the center of mass of a subset

Yuji Ikeda requested to merge yuzie007/ase:fixcm-group into master

Checklist

Closes !2621 (closed) (probably for MRs we need to close by hand)

This MR adds a new constraint to fix the center of mass of a "subset" of atoms, essentially the same as !2621 (closed). I think this is very useful, and I would like to have it in ASE.

Summary

Following the comment from @askhl in !2621 (closed) (!2621 (comment 852406555)), I tried to avoid redundant implementation. The new FixSubsetCom inherits from FixCom as well as IndexedConstraint.

To compute a subset center of mass, the Atoms.get_center_of_mass method is first extended to accept the indices option. To make it similar to Atoms.get_angles and Atoms.get_dihedrals, I would like to make the indices option as the first argument. This can break backward-compatibility when scaled is specified as a positional argument. To avoid unexpected behavior, now I make the both options as keyword-only arguments.

To parse the indices in Atoms.get_center_of_mass smartly, I use string2index which was originally in io.formats. To make the method more generic, I moved this method to unils/__init__.py. This should reduce possibility of circular import.

Naming

I thought the original name in !2621 (closed) FixGroupCom could sound as if "a group of several centers of mass", and therefore so far changed the name as FixSubsetCom. This might however be a bit lengthy and might not solve the problem. I am open for your suggestions.

Capability

FixSubsetCom can e.g. do MD simulations for molecular crystals with fixing molecules at their ideal positions.

The followings show Langevin MD trajectories of water (H2O) at 3000 K starting from solid-phase positions.

Without constraints, H2O molecules diffuse as the gas phase.

ase

Using FixSubsetCom, we can fix "each" H2O molecule at its solid-phase position, which might be helpful, e.g., to make a training set for a machine-learning interatomic potential.

ase

The scripts to reproduce the results above are attached.

fixcm-group.zip

Merge request reports

Loading