-
Notifications
You must be signed in to change notification settings - Fork 64
Integrate LOBSTER apps into crystal toolkit #459
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
Open
JaGeo
wants to merge
14
commits into
materialsproject:main
Choose a base branch
from
JaGeo:add_lobster_integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
277a4fc
add lobsterneighbors
JaGeo c4da734
fix linting
JaGeo 4ef7c6e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fd403e9
fix linting
JaGeo 14b60ae
fix linting
JaGeo a3f0b24
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7eec6bf
fix missing brackets
JaGeo a97a0c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 958dbe9
add cohp_dosplotter component
naik-aakash cb29602
add example code to create app
naik-aakash a77a857
add lobsterpy in ci
naik-aakash d26ea7e
add lobserpy as optional dependency
naik-aakash c5391d0
Merge pull request #3 from naik-aakash/add_lobster_integration
JaGeo 32bdd4b
Merge branch 'main' into add_lobster_integration
tschaume File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| __version__ = "2020.8.15.dev2217" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import os | ||
| import warnings | ||
|
|
||
| import dash | ||
| import numpy as np | ||
| from pymatgen.core import Structure | ||
| from pymatgen.electronic_structure.cohp import CompleteCohp | ||
| from pymatgen.io.lobster.inputs import Lobsterin | ||
| from pymatgen.io.lobster.outputs import ( | ||
| Bandoverlaps, | ||
| Charge, | ||
| Doscar, | ||
| Icohplist, | ||
| Lobsterout, | ||
| MadelungEnergies, | ||
| ) | ||
| from pymatgen.io.vasp.outputs import Vasprun | ||
|
|
||
| import crystal_toolkit.components as ctc | ||
| from crystal_toolkit.helpers.layouts import H3, Container | ||
| from crystal_toolkit.settings import SETTINGS | ||
|
|
||
|
|
||
| class CustomVasprun(Vasprun): | ||
| """Override final_energy property without unitized decorator""" | ||
|
|
||
| def __init__(self, filename, **kwargs): | ||
| super().__init__(filename, **kwargs) | ||
|
|
||
| @property | ||
| def final_energy(self) -> float: | ||
| """Final energy from the VASP run.""" | ||
|
|
||
| try: | ||
| final_istep = self.ionic_steps[-1] | ||
| total_energy = final_istep["e_0_energy"] | ||
|
|
||
| # Fix a bug in vasprun.xml. | ||
| # See https://www.vasp.at/forum/viewtopic.php?f=3&t=16942 | ||
| final_estep = final_istep["electronic_steps"][-1] | ||
| electronic_energy_diff = ( | ||
| final_estep["e_0_energy"] - final_estep["e_fr_energy"] | ||
| ) | ||
| total_energy_bugfix = np.round( | ||
| electronic_energy_diff + final_istep["e_fr_energy"], 8 | ||
| ) | ||
| if np.abs(total_energy - total_energy_bugfix) > 1e-7: | ||
| return total_energy_bugfix | ||
|
|
||
| return total_energy | ||
|
|
||
| except (IndexError, KeyError): | ||
| warnings.warn( | ||
| "Calculation does not have a total energy. Possibly a GW or similar kind of run. Infinity is returned.", | ||
| stacklevel=2, | ||
| ) | ||
| return float("inf") | ||
|
|
||
|
|
||
| calc_dir = "path/to/your/lobster/output" # Replace with your actual path | ||
|
|
||
| icohplist_obj = Icohplist( | ||
| filename=f"{calc_dir}/ICOHPLIST.lobster.gz", are_cobis=False, are_coops=False | ||
| ) | ||
|
|
||
| completecohp_obj = CompleteCohp.from_file( | ||
| filename=f"{calc_dir}/COHPCAR.lobster.gz", | ||
| structure_file=f"{calc_dir}/CONTCAR.gz", | ||
| fmt="LOBSTER", | ||
| are_cobis=False, | ||
| are_coops=False, | ||
| ) | ||
|
|
||
| charge_obj = Charge(filename=f"{calc_dir}/CHARGE.lobster.gz") | ||
| madelung_obj = MadelungEnergies(filename=f"{calc_dir}/MadelungEnergies.lobster.gz") | ||
| lob_dos = Doscar( | ||
| doscar=f"{calc_dir}/DOSCAR.LSO.lobster.gz", structure_file=f"{calc_dir}/CONTCAR.gz" | ||
| ) | ||
|
|
||
| vasprun_obj = CustomVasprun(filename=f"{calc_dir}/vasprun.xml.gz") | ||
| structure_obj = Structure.from_file(f"{calc_dir}/CONTCAR.gz") | ||
| lobsterin_obj = Lobsterin.from_file(f"{calc_dir}/lobsterin.gz") | ||
| lobsterout_obj = Lobsterout(filename=f"{calc_dir}/lobsterout.gz") | ||
| # Include band overlaps file if it exists available | ||
| bandoverlaps_obj = ( | ||
| Bandoverlaps(filename=f"{calc_dir}/bandOverlaps.lobster.gz") | ||
| if os.path.exists(f"{calc_dir}/bandOverlaps.lobster.gz") | ||
| else None | ||
| ) | ||
|
|
||
| cohp_component = ctc.CohpAndDosComponent( | ||
| density_of_states=lob_dos.completedos, | ||
| charge_obj=charge_obj, | ||
| icohplist_obj=icohplist_obj, | ||
| completecohp_obj=completecohp_obj, | ||
| madelung_obj=madelung_obj, | ||
| vasprun_obj=vasprun_obj, | ||
| structure_obj=structure_obj, | ||
| lobsterin_obj=lobsterin_obj, | ||
| lobsterout_obj=lobsterout_obj, | ||
| bandoverlaps_obj=bandoverlaps_obj, | ||
| mpid="mp-xxx", | ||
| disable_callbacks=False, | ||
| ) | ||
|
|
||
| # example layout to demonstrate capabilities of component | ||
| layout = Container([H3("COHP and Density of States Example"), cohp_component.layout()]) | ||
|
|
||
| app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH, prevent_initial_callbacks=True) # | ||
|
|
||
| ctc.register_crystal_toolkit(app, layout=layout) | ||
|
|
||
| if __name__ == "__main__": | ||
| app.run(debug=True, port=8051) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
For this class, I would recommend against copying all of
Vasprun.final_energy: