-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: protos
Are you sure you want to change the base?
Conversation
…to maciej/simplify-atom-selection
…to maciej/simplify-atom-selection
…to maciej/simplify-atom-selection
Looks good. Just one thing about the SMARTS pattern matching. In the RDKit molecule object we use the Chem.rdchem.BondType.UNSPECIFIED for all of the bondtypes. This means that most SMARTS patterns you'd think should work won't and that is why the SMARTS patterns we use are a bit unusual. The correct thing would be to set all the correct bond types and atom properties but I think this might get difficult to get working for a general molecule e.g. setting single/double/aromatic bonds for a benzene or cyclooctatetraene or some big protein. |
VALID_SELECTION = "Valid selection" | ||
USELESS_SELECTION = "Selection did not change. This operation is not needed." | ||
MALFORMED_SELECTION = "This is not a valid JSON string." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making these an Enum
|
||
def current_steps(self) -> str: | ||
result = {} | ||
for row in range(self.rowCount()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you not iterate over the children directly?
self.molecule_names = [str(x) for x in self.system._clusters.keys()] | ||
self.labels = [str(x) for x in self.system._labels.keys()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be:
self.molecule_names = [str(x) for x in self.system._clusters.keys()] | |
self.labels = [str(x) for x in self.system._labels.keys()] | |
self.molecule_names = list(map(str, self.system._clusters)) | |
self.labels = list(map(str, self.system._labels)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will note you keep externally accessing these variables which are marked _private
, suggest making them public.
if self.mode_box.currentIndex() == 2: | ||
return "difference" | ||
elif self.mode_box.currentIndex() == 1: | ||
return "intersection" | ||
else: | ||
return "union" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better as an Enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One complication here is that these values have to be JSON encoded and decoded (and remain human-readable when saved as a text string). I am sure that it can be done. Do you think it is worth the effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually referring to the 1
, 2
...
If you had:
class Modes(Enum):
DIFFERENCE = auto()
INTERSECTION = auto()
UNION = auto()
...
if self.mode_box.currentIndex() == Modes.DIFFERENCE:
return "difference"
elif self.mode_box.currentIndex() == Modes.INTERSECTION:
return "intersection"
elif self.mode_box.currentIndex() == Modes.UNION:
return "union"
It removes magic numbers and ensures internal consistency a bit better if we ever add other operations.
As an aside, Enum
s can act as strings
self.selection_field.setPlaceholderText("0,1,2") | ||
self.selection_keyword = "index_list" | ||
self.selection_separator = "," | ||
if new_mode == "range": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also probably Enum
…to maciej/simplify-atom-selection
Co-authored-by: Jacob Wilkins <[email protected]> Signed-off-by: Maciej Bartkowiak <[email protected]>
…SISNeutronMuon/MDANSE into maciej/simplify-atom-selection
Description of work
The intention behind this PR is to implement a mechanism of selecting atoms which is:
We can still discuss if the implementation in this PR meets the requirements.
This screenshot shows the carbon dioxide trajectory in which two out of three atoms have been selected in the molecules from the first half of the index range. This is not scientifically meaningful, but illustrates how the selection operations can be combined.

Fixes
The JSON representation is saved as str:


The indices are saved as a mask array:
To test
All tests must pass.