Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New atom selection mechanism #672

Merged
merged 46 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fdf460f
Merge branch 'protos' of https://github.com/ISISNeutronMuon/MDANSE in…
MBartkowiakSTFC Feb 11, 2025
a32a0f9
Add new selection functions
MBartkowiakSTFC Feb 11, 2025
ffe37cf
Merge branch 'protos' of https://github.com/ISISNeutronMuon/MDANSE in…
MBartkowiakSTFC Feb 11, 2025
054657e
Merge branch 'protos' of https://github.com/ISISNeutronMuon/MDANSE in…
MBartkowiakSTFC Feb 11, 2025
881d4c6
Add first unit tests for selection
MBartkowiakSTFC Feb 12, 2025
f21f07e
Add tests for molecule and group selection
MBartkowiakSTFC Feb 12, 2025
438a462
Add tests for selection saving
MBartkowiakSTFC Feb 12, 2025
4f10e0f
Update configurators to use the new selection mechanism
MBartkowiakSTFC Feb 12, 2025
f4042e0
Update configurators to use the new selection mechanism
MBartkowiakSTFC Feb 12, 2025
d2fa0cd
Consistently rename load_from_json method
MBartkowiakSTFC Feb 12, 2025
10263c8
Make all tests pass
MBartkowiakSTFC Feb 12, 2025
2abad53
Add a selection mechanism via widgets
MBartkowiakSTFC Feb 13, 2025
5371440
Add atom selection widgets
MBartkowiakSTFC Feb 13, 2025
d8604f9
Add string parsing to index range selection widget
MBartkowiakSTFC Feb 14, 2025
edaedc7
Add new selectors and change layout in AtomSelectionWidget
MBartkowiakSTFC Feb 14, 2025
795a7b6
Save selection as array of bool values
MBartkowiakSTFC Feb 14, 2025
10581a8
Merge branch 'protos' of https://github.com/ISISNeutronMuon/MDANSE in…
MBartkowiakSTFC Feb 19, 2025
16c56f9
Apply suggestions from code review
MBartkowiakSTFC Feb 19, 2025
1013a97
Merge branch 'maciej/simplify-atom-selection' of https://github.com/I…
MBartkowiakSTFC Feb 19, 2025
e1f971b
Adjust code after review suggestions
MBartkowiakSTFC Feb 19, 2025
727fe53
Correct the docstrings of selection functions
MBartkowiakSTFC Feb 19, 2025
f517419
Add inversion to the GUI
MBartkowiakSTFC Feb 20, 2025
d20fa64
Add position selection widget
MBartkowiakSTFC Feb 20, 2025
aaf0b68
Add cube and sphere selection to the GUI
MBartkowiakSTFC Feb 20, 2025
47b2a8e
Format code using black
MBartkowiakSTFC Feb 20, 2025
e1ffb96
Convert list to set in select_atoms
MBartkowiakSTFC Feb 20, 2025
a5d2fd1
Merge branch 'protos' of https://github.com/ISISNeutronMuon/MDANSE in…
MBartkowiakSTFC Feb 27, 2025
b540e8f
Correct atom transmutation and partial charge widgets
MBartkowiakSTFC Feb 27, 2025
d128109
Apply suggestions from code review
MBartkowiakSTFC Feb 28, 2025
437de9a
Implement changes from code review
MBartkowiakSTFC Feb 28, 2025
634eab4
Replace some constants with StrEnum
MBartkowiakSTFC Feb 28, 2025
5253823
Rewrite selection tests using parametrize
MBartkowiakSTFC Feb 28, 2025
d117d6e
Apply suggestions from code review
MBartkowiakSTFC Mar 3, 2025
e463a9f
Merge branch 'protos' of https://github.com/ISISNeutronMuon/MDANSE in…
MBartkowiakSTFC Mar 4, 2025
c3fe813
Merge branch 'maciej/simplify-atom-selection' of https://github.com/I…
MBartkowiakSTFC Mar 4, 2025
baac644
Respond to review, correct selection functions
MBartkowiakSTFC Mar 4, 2025
05e0bd8
Improve docstrings, add all_indices property
MBartkowiakSTFC Mar 4, 2025
35db18d
Merge branch 'protos' of https://github.com/ISISNeutronMuon/MDANSE in…
MBartkowiakSTFC Mar 5, 2025
4eab203
Format the code according to linter
MBartkowiakSTFC Mar 5, 2025
3b61207
Format the GUI code according to linter
MBartkowiakSTFC Mar 5, 2025
77f6c4c
Use keyword arguments in set_selection
MBartkowiakSTFC Mar 6, 2025
970c49b
Implement review suggestions
MBartkowiakSTFC Mar 6, 2025
c9d8acc
Add style corrections
MBartkowiakSTFC Mar 6, 2025
d3dbca4
Validate SMARTS input
MBartkowiakSTFC Mar 6, 2025
97b4a5a
Select all atoms explicitly, disable dragging
MBartkowiakSTFC Mar 6, 2025
b022132
Reset internal selection in the transmuter
MBartkowiakSTFC Mar 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion MDANSE/Src/MDANSE/Chemistry/ChemicalSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

from __future__ import annotations
from typing import List, Tuple, Dict, Any
from typing import List, Tuple, Dict, Any, Set
import copy
from functools import reduce

Expand Down Expand Up @@ -229,6 +229,11 @@ def number_of_atoms(self) -> int:
"""The number of non-ghost atoms in the ChemicalSystem."""
return self._total_number_of_atoms

@property
def all_indices(self) -> Set[int]:
"""The number of non-ghost atoms in the ChemicalSystem."""
return set(self._atom_indices)

@property
def total_number_of_atoms(self) -> int:
"""The number of all atoms in the ChemicalSystem, including ghost ones."""
Expand Down
1 change: 0 additions & 1 deletion MDANSE/Src/MDANSE/Framework/AtomSelector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from .selector import Selector
54 changes: 0 additions & 54 deletions MDANSE/Src/MDANSE/Framework/AtomSelector/all_selector.py

This file was deleted.

79 changes: 79 additions & 0 deletions MDANSE/Src/MDANSE/Framework/AtomSelector/atom_selection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This file is part of MDANSE.
#
# MDANSE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

from collections.abc import Sequence
from typing import Optional

from MDANSE.MolecularDynamics.Trajectory import Trajectory


def select_atoms(
trajectory: Trajectory,
*,
index_list: Optional[Sequence[int]] = None,
index_range: Optional[Sequence[int]] = None,
index_slice: Optional[Sequence[int]] = None,
atom_types: Sequence[str] = (),
atom_names: Sequence[str] = (),
**_kwargs: str,
) -> set[int]:
"""Select specific atoms in the trajectory.

Atoms can be selected based
on indices, atom type or trajectory-specific atom name.
The atom type is normally the chemical element, while
the atom name can be more specific and depend on the
force field used.

Parameters
----------
trajectory : Trajectory
A trajectory instance to which the selection is applied
index_list : Sequence[int]
a list of indices to be selected
index_range : Sequence[int]
a pair of (first, last+1) indices defining a range
index_slice : Sequence[int]
a sequence of (first, last+1, step) indices defining a slice
atom_types : Sequence[str]
a list of atom types (i.e. chemical elements) to be selected, given as string
atom_names : Sequence[str]
a list of atom names (as used by the MD engine, force field, etc.) to be selected

Returns
-------
set[int]
A set of indices which have been selected

"""
selection = set()
system = trajectory.chemical_system
element_list = system.atom_list
name_list = system.name_list
indices = system.all_indices
if index_list is not None:
selection |= indices & set(index_list)
if index_range is not None:
selection |= indices & set(range(*index_range))
if index_slice is not None:
selection |= indices & set(range(*index_slice))
if atom_types:
new_indices = {index for index in indices if element_list[index] in atom_types}
selection |= new_indices
if atom_names:
new_indices = {index for index in indices if name_list[index] in atom_names}
selection |= new_indices
return selection
236 changes: 0 additions & 236 deletions MDANSE/Src/MDANSE/Framework/AtomSelector/atom_selectors.py

This file was deleted.

Loading