Skip to content

Commit

Permalink
added --remove to sgeom
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Papior <[email protected]>
  • Loading branch information
zerothi committed Sep 21, 2023
1 parent cdcf106 commit f845e95
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/sisl/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/sisl/tests/test_sgeom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit f845e95

Please sign in to comment.