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

Feature/handling molecules #834

Merged
merged 15 commits into from
Oct 5, 2024
Merged

Conversation

AndresOrtegaGuerrero
Copy link
Member

@AndresOrtegaGuerrero AndresOrtegaGuerrero commented Oct 1, 2024

This feature handles #734

  • Include the option molecule for StructureData editor
  • Band structure calculation should be disabled
  • Cell Optimizatio not available if structure is molecule
  • kpoint_distance should be disable and force [1,1,1]
  • Realoading an old workflow should restore normal behavior of app
  • PdosCalculation Test

Modification to molecule editor
molecule_editor

Cell option no available for Molecule
cell_opt_option_no_available

Kpoint_Distance disable for Molecules
kpoint_distance_disable_for_molecules

New Workflow shuold restore behavior
new_workflow_or_reset_restore_normal_behavior

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 68.12%. Comparing base (9503aed) to head (e302867).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/aiidalab_qe/app/configuration/advanced.py 88.46% 3 Missing ⚠️
src/aiidalab_qe/app/configuration/workflow.py 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #834      +/-   ##
==========================================
+ Coverage   67.87%   68.12%   +0.25%     
==========================================
  Files          50       50              
  Lines        4507     4555      +48     
==========================================
+ Hits         3059     3103      +44     
- Misses       1448     1452       +4     
Flag Coverage Δ
python-3.11 68.12% <90.00%> (+0.25%) ⬆️
python-3.9 68.15% <90.00%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AndresOrtegaGuerrero
Copy link
Member Author

For this PR We need #833 merged to get the PDOS peaks otherwise is all 0.0

@AndresOrtegaGuerrero
Copy link
Member Author

@edan-bainglass I included you since it involves widgets and some behaviour of the app , so you can give your opinion for changes or things to consider

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.

tested in combination with #833
Automatic selection of periodicity will have to follow as a separate PR. The user can then override the automatic selection.

Copy link
Member

@edan-bainglass edan-bainglass left a comment

Choose a reason for hiding this comment

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

Okay, all good from me! Note that it will likely all change in my PR - not the behavior, but the implementation, due to the introduction of MVC.

One comment though - I find it odd that a control that modifies the app behavior (disable this, remove that) is somewhat "hidden" deep down (expand step, expand editors, switch tab...). I would consider elevating such controls. I am planning a layout redesign PR after my MVC PR. Should be a fun one!

Comment on lines +157 to +159
@tl.observe("input_structure")
def _on_input_structure_change(self, change):
"""Update the relax type options based on the input structure."""
Copy link
Member

Choose a reason for hiding this comment

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

In my rework, I generally reserve _on_some_state_change methods as handlers of observations, as you do here. But this also means they themselves do not handle logic. So everything below the method header (including the docstring) moves to a more specific method, here maybe _update_relax_type, passing to is change["new"] (or change if more than "new" is required). This keeps the "controller" _on methods light and clear. Reading them effectively tells you what is happening in the app (e.g., on input_structure change). Note that in my design, such methods as _update_relax_type end up moving to the model. The controller triggers this so-called "business logic" via the model, keeping the controller light and dedicated only to reactions.

Copy link
Member

Choose a reason for hiding this comment

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

Just giving you a heads up of what to expect in my beast PR, so no worries on changing it here 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I know! that part of removing was something that i wanted to check with you , so for molecules we cannot allow the user to do Cell Optimization , however in ipywidgets the ToogleButtons , there is no way to disable one option .. so I opted to go my way around and remove that option for molecules, while making sure it should be present for 1d,2d, and 3d systems.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I've encountered the limitation before. Would be nice in general if any option-selection widget allowed disabling certain options. Oh well...

Copy link
Member Author

Choose a reason for hiding this comment

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

So , i would rename as
@tl.observe("input_structure")
def _update_relax_type(self, change):

or keep the name of _on_input_structure_change name , since i need the traitlets to trigger this function ?

Copy link
Member

Choose a reason for hiding this comment

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

Again, I wouldn't change it at this stage. But if you did...

@tl.observe("input_structure")
def _on_input_structure_change(self, change):
    self._update_relax_type(change["new"])  # or `change` if you need more from it 

def _update_relax_type(self, input_structure):  # or change (see above)
    ...

Sometimes, the triggered handler (_on_<state>_change) might trigger several methods. This pattern makes it clear what does are. For example:

on structure change:
  do this()
  then do that()
  then finally do the last thing()

Easier to maintain. Also, this, that, etc. are effectively "business logic", so they are moved to the model. Then you get

on structure change:
  model.do_this()
  model.do_that()
  model.the_last_thing()

Exception to the rule: controllers can also modify the view directly. In such a case, the method would not go through the model.


Please don't let any of the above block your PR 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

ok i will keep the name , and i guess later we sit together for lazy loading :D

@AndresOrtegaGuerrero
Copy link
Member Author

I have adapted the PDOS tab for molecules where is compulsory to use degauss
image

@AndresOrtegaGuerrero
Copy link
Member Author

I will wait for the input from @superstar54 or @PNOGillespie , to know there is no conflict with the XAS or XPS plugins. or extra modifications so is 100% compatible

@AndresOrtegaGuerrero AndresOrtegaGuerrero linked an issue Oct 4, 2024 that may be closed by this pull request
Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

Hi @AndresOrtegaGuerrero , thanks for the nice work! I requested a few changes.

  • For the kpoints, I think we need to use gamma_only for molecule instead of [1, 1, 1], because the former one is faster.

  • XAS plugin does not support molecule calculation. I think @PNOGillespie could add a warning message in the XAS GUI if users activate the molecule option (in a future PR).

  • XPS plugin supports molecule, and has a molecule option in the XPS GUI explicitly, I can modify it in a future PR to use the molecule option from this PR.

So, I think your PR can go ahead without worry XAS and XPS.

src/aiidalab_qe/app/configuration/workflow.py Outdated Show resolved Hide resolved
src/aiidalab_qe/app/configuration/__init__.py Outdated Show resolved Hide resolved
Comment on lines +284 to +297
def create_kpoints_distance_link(self):
"""Create the dlink for override and kpoints_distance."""
self.kpoints_distance_link = ipw.dlink(
(self.override, "value"),
(self.kpoints_distance, "disabled"),
lambda override: not override,
)

def remove_kpoints_distance_link(self):
"""Remove the kpoints_distance_link."""
if hasattr(self, "kpoints_distance_link"):
self.kpoints_distance_link.unlink()
del self.kpoints_distance_link

Copy link
Member

Choose a reason for hiding this comment

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

I suggest not creating the link; instead, modify the _override_changed method. In this way, you only need to keep the logic in one place.

Copy link
Member Author

@AndresOrtegaGuerrero AndresOrtegaGuerrero Oct 4, 2024

Choose a reason for hiding this comment

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

I need this link to be created and removed , so that the kpoints distance is not modify for molecules , while keeping the same logic for other periodicities

Copy link
Member Author

Choose a reason for hiding this comment

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

since is liked to the reset()

Copy link
Member

Choose a reason for hiding this comment

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

I understand that the link is used to disable the kpoints_distance widget. You can achieve this in _override_changed. If input_structure is a molecule, the kpoints_distance widget is disabled no matter the change is.

Copy link
Member Author

Choose a reason for hiding this comment

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

but the issue, is when uploading a job with pbc that is not molecule , so I tried with the override ,but i realize that since is linked with the reset , it was better to create and remove the link ,

@AndresOrtegaGuerrero
Copy link
Member Author

Hi @AndresOrtegaGuerrero , thanks for the nice work! I requested a few changes.

  • For the kpoints, I think we need to use gamma_only for molecule instead of [1, 1, 1], because the former one is faster.
  • XAS plugin does not support molecule calculation. I think @PNOGillespie could add a warning message in the XAS GUI if users activate the molecule option (in a future PR).
  • XPS plugin supports molecule, and has a molecule option in the XPS GUI explicitly, I can modify it in a future PR to use the molecule option from this PR.

So, I think your PR can go ahead without worry XAS and XPS.

I would not use gamma_only , then there will be problems for vibroscopy app

@superstar54
Copy link
Member

there will be problems for vibroscopy app

gamma_only is one time faster than [1, 1, 1] and is suggested to be used in a normal case. The plugin could have its logic to handle the molecule case, e.g., the vibroscopy app can override the gamma_only to [1, 1,1].

Another parameter is assume_isolated; it's also suggested to use mt for the molecular system.

@AndresOrtegaGuerrero
Copy link
Member Author

AndresOrtegaGuerrero commented Oct 4, 2024

there will be problems for vibroscopy app

gamma_only is one time faster than [1, 1, 1] and is suggested to be used in a normal case. The plugin could have its logic to handle the molecule case, e.g., the vibroscopy app can override the gamma_only to [1, 1,1].

Another parameter is assume_isolated; it's also suggested to use mt for the molecular system.

The idea is to set this first and in a follow up set the MT , since this a change in the workchain ,

@superstar54
Copy link
Member

Ok to add MT in another PR.

btw, I can not find the gamma_only in the latest docs of pw, 😆

@AndresOrtegaGuerrero
Copy link
Member Author

AndresOrtegaGuerrero commented Oct 4, 2024

Ok to add MT in another PR.

btw, I can not find the gamma_only in the latest docs of pw, 😆

and the MT for the assume isolate ,
and logic for K_POINT{gamma} (And i think for this we will require a PR in aiida-quantumespresso)

Yest the best is to set that logic and how it affect other plugins in a follow up PR

Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

LGTM!

@AndresOrtegaGuerrero AndresOrtegaGuerrero merged commit 860f59b into main Oct 5, 2024
12 checks passed
@AndresOrtegaGuerrero AndresOrtegaGuerrero deleted the feature/handling_molecules branch October 5, 2024 06:48
edan-bainglass added a commit to edan-bainglass/aiidalab-qe that referenced this pull request Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling Molecules
4 participants