Skip to content

Commit f845e95

Browse files
committed
added --remove to sgeom
Signed-off-by: Nick Papior <[email protected]>
1 parent cdcf106 commit f845e95

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ we hit release version 1.0.0.
88
## [0.14.0] - YYYY-MM-DD
99

1010
### Added
11+
- added --remove to sgeom for removing single atoms
1112
- added a EllipticalCylinder as a new shape
1213
- added basis-enthalpy to the stdoutSiestaSile.read_energy routine
1314
- added `read_trajectory` to read cell vectors, atomic positions, and forces from VASP OUTCAR

src/sisl/geometry.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4758,8 +4758,17 @@ def __call__(self, parser, ns, value, option_string=None):
47584758
# Get atomic indices
47594759
rng = lstranges(strmap(int, value))
47604760
ns._geometry = ns._geometry.sub(rng)
4761-
p.add_argument(*opts('--sub', '-s'), metavar='RNG',
4761+
p.add_argument('--sub', metavar='RNG',
47624762
action=ReduceSub,
4763+
help='Retains specified atoms, can be complex ranges.')
4764+
4765+
class ReduceRemove(argparse.Action):
4766+
def __call__(self, parser, ns, value, option_string=None):
4767+
# Get atomic indices
4768+
rng = lstranges(strmap(int, value))
4769+
ns._geometry = ns._geometry.remove(rng)
4770+
p.add_argument('--remove', metavar='RNG',
4771+
action=ReduceRemove,
47634772
help='Removes specified atoms, can be complex ranges.')
47644773

47654774
# Swaps atoms

src/sisl/tests/test_sgeom.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,18 @@ def test_repeat2(self, setup):
112112
t = setup.sg_g(argv=argv)
113113
assert np.allclose(cell, t.lattice.cell)
114114

115-
def test_sub1(self, setup):
115+
def test_sub(self, setup):
116116
for a, l in [('0', 1), ('0,1', 2), ('0-1', 2)]:
117117
g = setup.sg_g(argv=['--sub', a])
118118
assert len(g) == l
119119

120+
def test_remove(self, setup):
121+
geom = setup.g.tile(2, 0).tile(2, 1)
122+
N = len(geom)
123+
for a, l in [('0', 1), ('0,1', 2), ('0-1', 2)]:
124+
g = setup.sg_g(geometry=geom.copy(), argv=['--remove', a])
125+
assert len(g) == N - l
126+
120127
def test_rotation1(self, setup):
121128
print(setup.g.cell)
122129
rot = setup.sg_g(argv='--rotate 180 z'.split())

0 commit comments

Comments
 (0)