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

use displayed_structure to create selection info #371

Merged
merged 34 commits into from
Jan 9, 2023

Conversation

superstar54
Copy link
Member

@superstar54 superstar54 commented Oct 18, 2022

fixes #361
fixes #413

Since selection can only be applied to the displayed_structure, I replaced the self.structure by self.displayed_structure.

Copy link
Member

@yakutovicha yakutovicha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @superstar54, I think there is an issue with this approach.

The displayed_structure does not actually correspond to the "real" structure. So does the selection of atoms, etc.

One needs to make sure that the indexes selected for the displayed_structure are mapped to the structure and vice-versa.

That is the most complicated part here (I think).

@superstar54
Copy link
Member Author

superstar54 commented Oct 18, 2022

Yes, this is the tricky part. In the case of the supercell in Appearance tab, this map relation is fulfilled automatically because of the ase.Atoms.repeat method is used.

self.set_trait("displayed_structure", self.structure.repeat(self.supercell))

In this ase.Atoms.repeat method (https://wiki.fysik.dtu.dk/ase/_modules/ase/atoms.html#Atoms.repeat), the numpy.tile function is used to repeat the atoms.arrays. Suppose there are N atoms in the "real" structure, and there are N*M atoms in the repeated structure. The first N atoms in the repeated structure are exactly the same atoms in the "real" structure. Therefore, if the user selects the atoms in the range 0 ~ N, the index is correct. If the user selects atoms index >= N, then the "virtual" atoms are selected, and the selection info is correct too, even though it's meaningless for DFT calculation.

@yakutovicha
Copy link
Member

yakutovicha commented Oct 20, 2022

If the user selects atoms index >= N, then the "virtual" atoms are selected, and the selection info is correct too, even though it's meaningless for DFT calculation.

Unfortunately, this is not always good. Because structure editors typically operate on the real atoms, not the virtual ones. So if you call an atom deletion, you don't want to attempt deleting the virtual atoms. Otherwise, things will crash.

However, I see the need to compute the distance (angles, dihedrals) across the replicas. This can be done by operating on the virtual atoms (your approach).

A possible solution would be to have two selections: displayed_selection and selection that operate on displayed_structure and structure traits.

@cpignedoli implemented an alternative approach in #373. I asked him to remove it from the PR since the "right way" doesn't look obvious.

@superstar54
Copy link
Member Author

Two selections are not necessary, because the selection is the subset of the displayed_selection.

Another solution could be adding the validation of the selection for any operation on the structure. Add a warning message to alert users that they are trying to delete virtual atoms. Because the Appearance tab is only for visualization. If they want to create a supercell and delete atoms, they need to go to the Edit Cell section instead of Appearance.

This applies to the displayed_structure too, e.g. highlight_atoms. Currently, inputting the wrong index in the selection textbox and clicking the apply button will crash the app too.

The validation is straightforward, the selection should be a subset of the range(0, N). N is the number of atoms for structure or displayed_structure.

@yakutovicha
Copy link
Member

yakutovicha commented Oct 21, 2022

Two selections are not necessary, because the selection is the subset of the displayed_selection.

I don't think this is true in this particular case, nor in general. The reason to go from a data object to a subset of data could be simply due to convenience.

See my reasoning below for this particular case.

Another solution could be adding the validation of the selection for any operation on the structure. Add a warning message to alert users that they are trying to delete virtual atoms. Because the Appearance tab is only for visualization. If they want to create a supercell and delete atoms, they need to go to the Edit Cell section instead of Appearance.

Why add this validation to the editor, if this can be done once in the viewer? I think it makes more sense that the viewer already provides the correct selection. In the current approach, one could add an arbitrary number of editors, so this is not clear to me why every one of those should handle the selection if they are not supposed to act on the virtual atoms.

This applies to the displayed_structure too, e.g. highlight_atoms. Currently, inputting the wrong index in the selection textbox and clicking the apply button will crash the app too.

This we must fix.

The validation is straightforward, the selection should be a subset of the range(0, N). N is the number of atoms for structure or displayed_structure.

I agree that the validation is straightforward, I just don't understand why you want to pass the displayed_selection to every editor and repeat the same slicing operation for each of them.

@superstar54
Copy link
Member Author

I think it makes more sense that the viewer already provides the correct selection

Good point! I will implement validation in this way.

@yakutovicha
Copy link
Member

@cpignedoli, @superstar54 and I discussed the selection handling. The draft schema below is what we've agreed on:
Screenshot 2022-11-15 at 15 24 13

@cpignedoli
Copy link
Member

cpignedoli commented Nov 16, 2022

I slightly changed my mind in part recovering what @yakutovicha was suggesting. Please @superstar54 and @yakutovicha consider this:
to have complete info and non-redundant info at the same time
we need to know

  1. to which atom in the unit cell does a supercell atom corresponds
  2. to have the unique is of clicked atoms

Thus I propose updating the skecth that we discussed as follows
The light red circles highlight the atoms that I clicked

This allows me to make a selection in the sometimes more intuitive supercell representation
and e.g. delete the correct atoms from the real unit cell

Screenshot 2022-11-16 at 22 44 56

@superstar54
Copy link
Member Author

superstar54 commented Nov 22, 2022

Here are the changes:

  • replay old selection with displayed_selection.
  • the new selection is generated by selection = [x for x in displayed_selection if x <= self.natom], thus the self.selection is always correct for Structure Editors.
  • add one information line for Unit cell atoms.
  • the unit_cell_selection atoms is calculated by {x % self.natom + 1 for x in displayed_selection}

I implemented what @cpignedoli suggested. However, the line for Selected atoms is not necessary because it duplicates with the top level Selected atoms.

Here is the screenshot:

@cpignedoli
Copy link
Member

I agree we just have to decide how to pass the "unit cell atoms" set to the editors

Copy link
Member

@yakutovicha yakutovicha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @superstar54. A few comments:

  1. I thought we agreed to not convert the field where we type in formulas to the list of indices. That could simplify some logic. Also, some users complained that they were not happy with the disappearance of the formula.
  2. Related to the previous: I think we should display the displayed_selection along with unit cell atoms.

aiidalab_widgets_base/viewers.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/viewers.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/viewers.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/viewers.py Outdated Show resolved Hide resolved
@yakutovicha
Copy link
Member

@superstar54 any progress here? Let me know if I should take over this PR.

@superstar54
Copy link
Member Author

@superstar54 any progress here? Let me know if I should take over this PR.

Last two weeks have been very busy. I will work on this today.

@yakutovicha
Copy link
Member

yakutovicha commented Dec 15, 2022

Hi all,

just a general comment, please make sure everything works for gas phase molecules as well. No information about cell should be displayed when the structure is not periodic. 😊

@danielhollas I can reassure you that we do not touch the handling cells. It is only about atom selection.

@yakutovicha
Copy link
Member

I must admit that structure multiplication is not working as expected in the tests. It seems that the button is not always clicked. Instead of clicking, one should put a number there (2 in this case).

Copy link
Member

@cpignedoli cpignedoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem:
after an edit operation the list of selected atoms /display atoms, should be updated according to what is defined in structures.py in the corresponding edit function. For example, after "copy" of a selection, the user should see highlighted automatically the newly added atoms. This is crucial to be able afterward to move correctly and easily the atoms. This is not the case anymore: after an edit operation, the selected /display atoms are reset.

@yakutovicha
Copy link
Member

@cpignedoli, your concern was addressed in f2d5f19. Please test it again and let me know if everything works as expected.

cpignedoli
cpignedoli previously approved these changes Jan 9, 2023
Copy link
Member

@cpignedoli cpignedoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I tested was working.
Please in replace "Selected atoms" with "Select atoms" in the field where we enter the selection (e.g. x>2)

tests/test_notebooks.py Outdated Show resolved Hide resolved
@yakutovicha yakutovicha self-requested a review January 9, 2023 16:26
@yakutovicha
Copy link
Member

Everything I tested was working. Please in replace "Selected atoms" with "Select atoms" in the field where we enter the selection (e.g. x>2)

done in a2fd1e7

@yakutovicha yakutovicha merged commit 0861b83 into master Jan 9, 2023
@yakutovicha yakutovicha deleted the fix_supercell_selection branch January 9, 2023 18:11

# if atom is selected from nglview, shift to selection tab
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yakutovicha why was this code deleted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember the exact motivation. I think it is because the trait doesn't have to be set by nglview. If it is set elsewhere, the switching will still occur, which might be unwanted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that makes sense. Thanks!

yakutovicha added a commit that referenced this pull request Feb 9, 2023
…ption (#429)

PR #371 broke the `configuration_tabs` option of the `StructureDataViewer`.
In the latest release, no configuration tabs are displayed when this option is
passed to the class constructor.

Co-authored-by: Aliaksandr Yakutovich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants