From f845e957f1540c56d3a46caac874568c99603d9e Mon Sep 17 00:00:00 2001 From: Nick Papior Date: Thu, 21 Sep 2023 09:27:40 +0200 Subject: [PATCH] added --remove to sgeom Signed-off-by: Nick Papior --- CHANGELOG.md | 1 + src/sisl/geometry.py | 11 ++++++++++- src/sisl/tests/test_sgeom.py | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c1f9ee9..ee44bbfbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ we hit release version 1.0.0. ## [0.14.0] - YYYY-MM-DD ### Added +- added --remove to sgeom for removing single atoms - added a EllipticalCylinder as a new shape - added basis-enthalpy to the stdoutSiestaSile.read_energy routine - added `read_trajectory` to read cell vectors, atomic positions, and forces from VASP OUTCAR diff --git a/src/sisl/geometry.py b/src/sisl/geometry.py index 392c5c9c9..813c79977 100644 --- a/src/sisl/geometry.py +++ b/src/sisl/geometry.py @@ -4758,8 +4758,17 @@ def __call__(self, parser, ns, value, option_string=None): # Get atomic indices rng = lstranges(strmap(int, value)) ns._geometry = ns._geometry.sub(rng) - p.add_argument(*opts('--sub', '-s'), metavar='RNG', + p.add_argument('--sub', metavar='RNG', action=ReduceSub, + help='Retains specified atoms, can be complex ranges.') + + class ReduceRemove(argparse.Action): + def __call__(self, parser, ns, value, option_string=None): + # Get atomic indices + rng = lstranges(strmap(int, value)) + ns._geometry = ns._geometry.remove(rng) + p.add_argument('--remove', metavar='RNG', + action=ReduceRemove, help='Removes specified atoms, can be complex ranges.') # Swaps atoms diff --git a/src/sisl/tests/test_sgeom.py b/src/sisl/tests/test_sgeom.py index 2f1f2356f..41f90c512 100644 --- a/src/sisl/tests/test_sgeom.py +++ b/src/sisl/tests/test_sgeom.py @@ -112,11 +112,18 @@ def test_repeat2(self, setup): t = setup.sg_g(argv=argv) assert np.allclose(cell, t.lattice.cell) - def test_sub1(self, setup): + def test_sub(self, setup): for a, l in [('0', 1), ('0,1', 2), ('0-1', 2)]: g = setup.sg_g(argv=['--sub', a]) assert len(g) == l + def test_remove(self, setup): + geom = setup.g.tile(2, 0).tile(2, 1) + N = len(geom) + for a, l in [('0', 1), ('0,1', 2), ('0-1', 2)]: + g = setup.sg_g(geometry=geom.copy(), argv=['--remove', a]) + assert len(g) == N - l + def test_rotation1(self, setup): print(setup.g.cell) rot = setup.sg_g(argv='--rotate 180 z'.split())