1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
from ase.build import molecule
from ase.constraints import FixAtoms
N = 2
atoms = molecule('CO2')
atoms.set_cell((15, 15, 15))
# Indices method:
atomsi = atoms.copy()
atomsi.set_constraint(FixAtoms(indices=[0]))
atomsi = atomsi.repeat((N, 1, 1))
atomsiref = atoms.copy().repeat((N, 1, 1))
atomsiref.set_constraint(FixAtoms(indices=list(range(0, 3 * N, 3))))
lcatomsi = list(atomsi.constraints[0].index)
lcatomsiref = list(atomsiref.constraints[0].index)
assert lcatomsi == lcatomsiref
# Mask method:
atomsm = atoms.copy()
atomsm.set_constraint(FixAtoms(mask=[True, False, False]))
atomsm = atomsm.repeat((N, 1, 1))
atomsmref = atoms.copy().repeat((N, 1, 1))
atomsmref.set_constraint(FixAtoms(mask=[True, False, False] * N))
lcatomsm = list(atomsm.constraints[0].index)
lcatomsmref = list(atomsmref.constraints[0].index)
assert lcatomsm == lcatomsmref
assert lcatomsm == lcatomsi
|