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

Adding Symprec Widget #85

Merged
merged 7 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions src/aiidalab_qe_vibroscopy/app/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def _update_view(self):
_bands_plot_view_class.update_layout(
yaxis=dict(autorange=True), # Automatically scale the y-axis
)


# the data (bands and pdos) are the first element of the lists phonon_data["bands"] and phonon_data["pdos"]!
downloadBandsPdos_widget = DownloadBandsPdosWidget(
Expand Down Expand Up @@ -209,14 +208,13 @@ def _update_view(self):
dielectric_results = DielectricResults(dielectric_data)
children_result_widget += (dielectric_results,)
tab_titles.append("Dielectric properties")

# euphonic
if ins_data:
intensity_maps = EuphonicSuperWidget(fc=ins_data["fc"])
children_result_widget += (intensity_maps,)
tab_titles.append("Inelastic Neutrons")


self.result_tabs = ipw.Tab(children=children_result_widget)

for title_index in range(len(tab_titles)):
Expand Down
11 changes: 11 additions & 0 deletions src/aiidalab_qe_vibroscopy/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ def change_supercell(_=None):
self.supercell_widget.layout.display = "block"
# end Supercell.

self.symmetry_symprec = ipw.FloatText(
value=1e-5,
description="Symmetry tolerance (symprec):",
style={"description_width": "initial"},
layout={"width": "300px"},
)

self.children = [
ipw.VBox(
[
Expand All @@ -167,6 +174,7 @@ def change_supercell(_=None):
],
),
self.supercell_widget,
self.symmetry_symprec,
]

super().__init__(**kwargs)
Expand Down Expand Up @@ -208,16 +216,19 @@ def get_panel_value(self):
return {
"simulation_mode": self.calc_options.value,
"supercell_selector": self.supercell,
"symmetry_symprec": self.symmetry_symprec.value,
}

def set_panel_value(self, input_dict):
"""Load a dictionary with the input parameters for the plugin."""
self.calc_options.value = input_dict.get("simulation_mode", 1)
self.supercell = input_dict.get("supercell_selector", [2, 2, 2])
self.symmetry_symprec.value = input_dict.get("symmetry_symprec", 1e-5)
self._sc_x.value, self._sc_y.value, self._sc_z.value = self.supercell

def reset(self):
"""Reset the panel"""
self.calc_options.value = 1
self.supercell = [2, 2, 2]
self.symmetry_symprec.value = 1e-5
self._sc_x.value, self._sc_y.value, self._sc_z.value = self.supercell
1 change: 1 addition & 0 deletions src/aiidalab_qe_vibroscopy/app/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get_builder(codes, structure, parameters):
"supercell_matrix": supercell_matrix,
},
"dielectric": {"scf": deepcopy(parameters["advanced"])},
"symmetry": {"symprec": parameters["vibronic"]["symmetry_symprec"]},
}

# Update code information with resource configurations
Expand Down
59 changes: 41 additions & 18 deletions src/aiidalab_qe_vibroscopy/workflows/vibroworkchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,24 @@ def get_builder_from_protocol(
if structure.pbc == (True, False, False):
builder.phonopy_bands_dict = Dict(
dict={
"symmetry_tolerance": 1e-3,
"symmetry_tolerance": overrides["symmetry"]["symprec"],
Copy link
Owner

Choose a reason for hiding this comment

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

Hi @AndresOrtegaGuerrero , do we really need to update the symprec here? is it not sufficient to do builder_harmonic.phonon.symmetry = overrides["symmetry"]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This phonopy calculation is different , since is part of the three independent phonopy calculations to obtain the bands, pdos, and thermal properties

Copy link
Owner

Choose a reason for hiding this comment

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

right, I was not taking into account this. Thanks!

"band": [0, 0, 0, 1 / 2, 0, 0],
"band_points": 100,
"band_labels": [GAMMA, "$\\mathrm{X}$"],
}
)
# change symprec for 1D materials to 1e-3
builder.phonopy_pdos_dict["symmetry_tolerance"] = 1e-3
builder.phonopy_thermo_dict["symmetry_tolerance"] = 1e-3
builder.harmonic.symmetry.symprec = orm.Float(1e-3)
builder.phonopy_pdos_dict["symmetry_tolerance"] = overrides[
"symmetry"
]["symprec"] # 1e-3
builder.phonopy_thermo_dict["symmetry_tolerance"] = overrides[
"symmetry"
]["symprec"] # 1e-3
builder.harmonic.symmetry.symprec = orm.Float(
overrides["symmetry"]["symprec"]
)
builder.harmonic.phonon.phonopy.parameters = orm.Dict(
{"symmetry_tolerance": 1e-3}
{"symmetry_tolerance": overrides["symmetry"]["symprec"]}
)

elif structure.pbc == (True, True, False):
Expand All @@ -475,8 +481,12 @@ def get_builder_from_protocol(
)
else:
builder.phonopy_bands_dict = Dict(dict=PhononProperty.BANDS.value)
builder.phonopy_bands_dict["symmetry_tolerance"] = overrides[
"symmetry"
]["symprec"]
builder.phonopy_pdos_dict = Dict(
dict={
"symmetry_tolerance": overrides["symmetry"]["symprec"],
"pdos": "auto",
"mesh": 150, # 1000 is too heavy
"write_mesh": False,
Expand All @@ -485,6 +495,7 @@ def get_builder_from_protocol(

builder.phonopy_thermo_dict = Dict(
dict={
"symmetry_tolerance": overrides["symmetry"]["symprec"],
"tprop": True,
"mesh": 200, # 1000 is too heavy
"write_mesh": False,
Expand Down Expand Up @@ -517,9 +528,11 @@ def get_builder_from_protocol(
builder_iraman.dielectric.pop("kpoints_parallel_distance", None)

if structure.pbc == (True, False, False):
builder_iraman.symmetry.symprec = orm.Float(1e-3)
builder_iraman.symmetry.symprec = orm.Float(
overrides["symmetry"]["symprec"]
)
builder_iraman.phonon.phonopy.parameters = orm.Dict(
{"symmetry_tolerance": 1e-3}
{"symmetry_tolerance": overrides["symmetry"]["symprec"]}
)

builder.iraman = builder_iraman
Expand All @@ -544,9 +557,8 @@ def get_builder_from_protocol(
builder_phonon.phonopy.settings = Dict(dict={"keep_phonopy_yaml": True})

# MBO: I do not understand why I have to do this, but it works
symmetry = builder_phonon.pop("symmetry")
builder.phonon = builder_phonon
builder.phonon.symmetry = symmetry
builder.phonon.symmetry = overrides["symmetry"]

# Adding the bands and pdos inputs.
if structure.pbc != (True, True, True):
Expand Down Expand Up @@ -574,18 +586,24 @@ def get_builder_from_protocol(
if structure.pbc == (True, False, False):
builder.phonopy_bands_dict = Dict(
dict={
"symmetry_tolerance": 1e-3,
"symmetry_tolerance": overrides["symmetry"]["symprec"],
"band": [0, 0, 0, 1 / 2, 0, 0],
"band_points": 100,
"band_labels": [GAMMA, "$\\mathrm{X}$"],
}
)
# change symprec for 1D materials to 1e-3
builder.phonopy_pdos_dict["symmetry_tolerance"] = 1e-3
builder.phonopy_thermo_dict["symmetry_tolerance"] = 1e-3
builder.phonon.symmetry.symprec = orm.Float(1e-3)
builder.phonopy_pdos_dict["symmetry_tolerance"] = overrides[
"symmetry"
]["symprec"]
builder.phonopy_thermo_dict["symmetry_tolerance"] = overrides[
"symmetry"
]["symprec"]
builder.phonon.symmetry.symprec = orm.Float(
overrides["symmetry"]["symprec"]
)
builder.phonon.phonopy.parameters = orm.Dict(
{"symmetry_tolerance": 1e-3}
{"symmetry_tolerance": overrides["symmetry"]["symprec"]}
)

elif structure.pbc == (True, True, False):
Expand All @@ -610,8 +628,12 @@ def get_builder_from_protocol(
)
else:
builder.phonopy_bands_dict = Dict(dict=PhononProperty.BANDS.value)
builder.phonopy_bands_dict["symmetry_tolerance"] = overrides[
"symmetry"
]["symprec"]
builder.phonopy_pdos_dict = Dict(
dict={
"symmetry_tolerance": overrides["symmetry"]["symprec"],
"pdos": "auto",
"mesh": 150, # 1000 is too heavy
"write_mesh": False,
Expand All @@ -620,6 +642,7 @@ def get_builder_from_protocol(

builder.phonopy_thermo_dict = Dict(
dict={
"symmetry_tolerance": overrides["symmetry"]["symprec"],
"tprop": True,
"mesh": 200, # 1000 is too heavy
"write_mesh": False,
Expand All @@ -635,12 +658,10 @@ def get_builder_from_protocol(
**kwargs,
)

# MBO: I do not understand why I have to do this, but it works. maybe related with excludes.
symmetry = builder_dielectric.pop("symmetry")
if structure.pbc != (True, True, True):
builder_dielectric.pop("kpoints_parallel_distance", None)
builder.dielectric = builder_dielectric
builder.dielectric.symmetry = symmetry
builder.dielectric.symmetry = overrides["symmetry"]
builder.dielectric.property = dielectric_property

# Deleting the not needed parts of the builder:
Expand All @@ -659,7 +680,9 @@ def get_builder_from_protocol(
"num_mpiprocs_per_machine": 1,
}
if structure.pbc == (True, False, False):
builder.phonopy_calc.parameters = orm.Dict({"symmetry_tolerance": 1e-3})
builder.phonopy_calc.parameters = orm.Dict(
{"symmetry_tolerance": overrides["symmetry"]["symprec"]}
)
builder.structure = structure

return builder
Expand Down
24 changes: 19 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ def _fixture_code(entry_point_name):
def generate_structure_data():
"""generate a `StructureData` object."""

def _generate_structure_data(name="silicon", pbc=(True, True, True)):
def _generate_structure_data(name="silicon"):
if name == "silicon":
structure = orm.StructureData(
cell=[
[3.84737, 0.0, 0.0],
[1.923685, 3.331920, 0.0],
[1.923685, 1.110640, 3.141364],
]
],
pbc=(True, True, True),
)
structure.append_atom(position=(0.0, 0.0, 0.0), symbols="Si")
structure.append_atom(position=(1.923685, 1.110640, 0.785341), symbols="Si")
Expand All @@ -65,7 +66,8 @@ def _generate_structure_data(name="silicon", pbc=(True, True, True)):
[4.18, 0.0, 0.0],
[0.0, 4.18, 0.0],
[0.0, 0.0, 2.66],
]
],
pbc=(True, True, True),
)
structure.append_atom(position=(0.0, 0.0, 0.0), symbols="Si")
structure.append_atom(position=(2.09, 2.09, 1.33), symbols="Si")
Expand All @@ -88,11 +90,23 @@ def _generate_structure_data(name="silicon", pbc=(True, True, True)):
["O", "O", (0, 0, 10.201532881212)],
["Li", "Li", (0, 0, 6.9018028772754)],
]
structure = orm.StructureData(cell=cell)
structure = orm.StructureData(cell=cell, pbc=(True, True, True))

for site in sites:
structure.append_atom(position=site[2], symbols=site[0], name=site[1])
structure.pbc = pbc

elif name == "2D-xy-arsenic":
cell = [[3.61, 0, 0], [-1.80, 3.13, 0], [0, 0, 21.3]]
structure = orm.StructureData(cell=cell, pbc=(True, True, False))
structure.append_atom(
position=(1.804, 1.042, 11.352), symbols="As", name="As"
)
structure.append_atom(position=(0, 2.083, 9.960), symbols="As", name="As")

elif name == "1D-x-carbon":
cell = [[4.2, 0, 0], [0, 20, 0], [0, 0, 20]]
structure = orm.StructureData(cell=cell, pbc=(True, False, False))
structure.append_atom(position=(0, 0, 0), symbols="C", name="C")

return structure

Expand Down
28 changes: 28 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,31 @@ def test_settings():
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["simulation_mode"] == 1
assert parameters["supercell_selector"] == [2, 2, 2]


@pytest.mark.usefixtures("sssp")
def test_xy_settings(generate_structure_data):
"""Test the settings of the vibroscopy app."""

from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep

configure_step = ConfigureQeAppWorkChainStep()
structure = generate_structure_data("2D-xy-arsenic")
configure_step.input_structure = structure
configure_step.workchain_settings.properties["vibronic"].run.value = True
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["supercell_selector"] == [2, 2, 1]


@pytest.mark.usefixtures("sssp")
def test_x_settings(generate_structure_data):
"""Test the settings of the vibroscopy app."""

from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep

configure_step = ConfigureQeAppWorkChainStep()
structure = generate_structure_data("1D-x-carbon")
configure_step.input_structure = structure
configure_step.workchain_settings.properties["vibronic"].run.value = True
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["supercell_selector"] == [2, 1, 1]
2 changes: 1 addition & 1 deletion tests/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_create_builder_default(
submit_step.codes["dielectric"].value = pw_code.uuid
submit_step.codes["phonopy"].value = phonopy_code.uuid

submit_step.codes["pw"].num_cpus.value = 10
submit_step.codes["pw"].num_cpus.value = 8
submit_step.codes["phonon"].num_cpus.value = 2
submit_step.codes["dielectric"].num_cpus.value = 3

Expand Down
5 changes: 3 additions & 2 deletions tests/test_submit/test_create_builder_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ codes:
nodes: 1
ntasks_per_node: 1
pw:
cpus: 10
cpus: 8
cpus_per_task: 1
max_wallclock_seconds: 43200
nodes: 1
ntasks_per_node: 10
ntasks_per_node: 8
parallelization: {}
vibronic:
simulation_mode: 1
supercell_selector:
- 2
- 2
- 2
symmetry_symprec: 1.0e-05
workchain:
electronic_type: metal
properties:
Expand Down
Loading