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

HubbardStructureData reach by StructureBrowserWidget #718

Merged
merged 19 commits into from
May 3, 2024

Conversation

AndresOrtegaGuerrero
Copy link
Member

This addresses #716

@AndresOrtegaGuerrero AndresOrtegaGuerrero marked this pull request as draft May 3, 2024 06:39
@superstar54
Copy link
Member

Hi @AndresOrtegaGuerrero is this ready for review, or it's a draft?

@AndresOrtegaGuerrero
Copy link
Member Author

@superstar54 This is a draft , i am testing it , but we have to change the logic of the workchain ( i am on it).

@AndresOrtegaGuerrero AndresOrtegaGuerrero marked this pull request as ready for review May 3, 2024 07:47
@AndresOrtegaGuerrero
Copy link
Member Author

@superstar54 Now is ready, please let me know what you think of the logic? Basically if you put an HubbardStructureData and you dont define new the option DFT+U in advanced tab, the workchain will just create a new StructureData (No Hubbard Parameters) from your HubbardStructureData, and run. If you define new parameter in the advanced tab, it will create a new HubbardStructureData with the new parameters.

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, I understand your logic in the workchain: If a user doesn't specify Hubbard parameters in the GUI, the workchain will use pure StructureData.

Maybe you could also think in another way: if a structure is generated by geometry optimization using certain Hubbard parameters. Then, it's better to do the following calculation using the same Hubbard parameters, which means it is better to pass the HubbardStructureData directly to the builder, to make the results are more consistent.
If you want to keep the logic, we can make the GUI load the Hubbard parameters from the structure if it's a HubbardStructureData.
You don't need to change it in this PR, but we can discuss it in the next relesae.

@AndresOrtegaGuerrero
Copy link
Member Author

@superstar54 I did the changes you suggested, so now if you select a HubbardStructureData, the app will set your u values in the widget and activate override so in case you continue you will be using the same u parameters. In the workchain if the hubbard parameters set are exactly the same as in your structure, there wont be a new HubbardStructureData, but instead the user will do calculations on the same structure. Have a look

Comment on lines 144 to 148
if hubbard_structure.hubbard == structure.hubbard:
builder.structure = structure
else:
hubbard_structure.store()
builder.structure = hubbard_structure
Copy link
Member

@superstar54 superstar54 May 3, 2024

Choose a reason for hiding this comment

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

Raise error when structure is a normal StructureData, which doesn't have hubbard. I think you don't need check the hubbard here, because you need to use the newly created hubbard_structure.

Suggested change
if hubbard_structure.hubbard == structure.hubbard:
builder.structure = structure
else:
hubbard_structure.store()
builder.structure = hubbard_structure
hubbard_structure.store()
builder.structure = hubbard_structure

@AndresOrtegaGuerrero
Copy link
Member Author

@superstar54 Should i add this logic in a function ? outside the class, so it is not no long the logic of the class ?

Comment on lines 152 to 156
should_store_and_assign = (
not isinstance(structure, HubbardStructureData)
or hubbard_structure.hubbard != structure.hubbard
)

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 understand why we need to check hubbard_structure.hubbard != structure.hubbard?

Copy link
Member Author

Choose a reason for hiding this comment

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

because if the user is setting the same hubbard parameters, then i do not store the HubbardStructureData, and just give the builder the same structure, otherwise i will create a copy of the same HubbardStructureData. But there is also the other case where the user uses a HubbardStructureData, but decided to change the U parameters, then i should create a new structure and store it.

Copy link
Member

Choose a reason for hiding this comment

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

I see. thanks!

Comment on lines 166 to 170
# Common logic to store and assign the new structure if conditions are met
if should_store_and_assign and "hubbard_structure" in locals():
hubbard_structure.store()
builder.structure = hubbard_structure

Copy link
Member

Choose a reason for hiding this comment

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

one more question. why not move to line 156?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 149 to 166
# Initialize flag to determine when to store hubbard_structure
should_store_and_assign = False

if not isinstance(structure, HubbardStructureData):
# Store the HubbardStructureData is structure is not a HubbardStructureData
should_store_and_assign = True
else:
# Check if hubbard parameters are different from the structure
if hubbard_structure.hubbard != structure.hubbard:
should_store_and_assign = True
else:
# If criteria is not met, assign the structure to the builder
builder.structure = structure

# Common logic to store and assign hubbard_structure if conditions are met
if should_store_and_assign:
hubbard_structure.store()
builder.structure = hubbard_structure
Copy link
Member

Choose a reason for hiding this comment

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

this logic can be simplified.

Suggested change
# Initialize flag to determine when to store hubbard_structure
should_store_and_assign = False
if not isinstance(structure, HubbardStructureData):
# Store the HubbardStructureData is structure is not a HubbardStructureData
should_store_and_assign = True
else:
# Check if hubbard parameters are different from the structure
if hubbard_structure.hubbard != structure.hubbard:
should_store_and_assign = True
else:
# If criteria is not met, assign the structure to the builder
builder.structure = structure
# Common logic to store and assign hubbard_structure if conditions are met
if should_store_and_assign:
hubbard_structure.store()
builder.structure = hubbard_structure
# If this is a new HubbardStructureData or the hubbard is different
if not isinstance(structure, HubbardStructureData) or hubbard_structure.hubbard != structure.hubbard:
hubbard_structure.store()
builder.structure = hubbard_structure
else:
builder.structure = structure

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.

Thanks for the fix, LGTM!

@AndresOrtegaGuerrero AndresOrtegaGuerrero merged commit ba09f0d into main May 3, 2024
18 checks passed
@AndresOrtegaGuerrero AndresOrtegaGuerrero deleted the mod/structure_browser_widget branch May 3, 2024 13:43
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.

2 participants