Skip to content

Commit

Permalink
Import optimisation (#287)
Browse files Browse the repository at this point in the history
* Moved long Xdatcar import to  to HistFile read/write class methods to improve general loading times

* Moved long imports from pymatgen into their read/write class methods to improve general loading times
  • Loading branch information
SurgeArrester authored Feb 7, 2024
1 parent b38b0c8 commit 8a70fa0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion abipy/dynamics/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from monty.string import marquee, list_strings
from pymatgen.core.periodic_table import Element
from pymatgen.analysis.structure_analyzer import RelaxationAnalyzer
from pymatgen.io.vasp.outputs import Xdatcar
from abipy.tools.plotting import add_fig_kwargs, get_ax_fig_plt, get_axarray_fig_plt, set_visible, get_figs_plotly, \
get_fig_plotly, add_plotly_fig_kwargs, plotlyfigs_to_browser, push_to_chart_studio, PlotlyRowColDesc, plotly_set_lims, \
latex_greek_2unicode
Expand Down Expand Up @@ -180,6 +179,8 @@ def to_xdatcar(self, filepath=None, groupby_type=True, to_unit_cell=False, **kwa
to_unit_cell (bool): Whether to translate sites into the unit cell.
kwargs: keywords arguments passed to Xdatcar constructor.
"""
from pymatgen.io.vasp.outputs import Xdatcar

filepath = self.write_xdatcar(filepath=filepath, groupby_type=groupby_type,
to_unit_cell=to_unit_cell, overwrite=True)

Expand All @@ -201,6 +202,9 @@ def write_xdatcar(self, filepath="XDATCAR", groupby_type=True, overwrite=False,
Return:
path to Xdatcar file.
"""
# This library takes 13s to import on HPC (07/02/24) so moved to class method instead of header
from pymatgen.io.vasp.outputs import Xdatcar

if filepath is not None and os.path.exists(filepath) and not overwrite:
raise RuntimeError("Cannot overwrite pre-existing file `%s`" % filepath)

Expand Down
6 changes: 4 additions & 2 deletions abipy/electrons/lobster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from monty.functools import lazy_property
from pymatgen.core.periodic_table import Element
from pymatgen.electronic_structure.core import OrbitalType
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.io.vasp.inputs import Potcar
from pymatgen.io.abinit.pseudos import Pseudo
from abipy.core.func1d import Function1D
from abipy.core.mixins import BaseFile, NotebookWriter
Expand Down Expand Up @@ -1166,6 +1164,10 @@ def from_dir(cls, dirpath, dE=0.01, **kwargs):
Returns:
A LobsterInput.
"""
# These two libraries take a long time to import on HPC (07/02/24) so moved to method instead of header
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.io.vasp.inputs import Potcar

# Try to determine the code used for the calculation
dft_code = None
if os.path.isfile(os.path.join(dirpath, 'vasprun.xml')):
Expand Down

0 comments on commit 8a70fa0

Please sign in to comment.