Skip to content

Commit

Permalink
Merge pull request mala-project#561 from RandomDefaultUser/TEM_2D
Browse files Browse the repository at this point in the history
MALA for 2D materials
  • Loading branch information
RandomDefaultUser authored Oct 24, 2024
2 parents 217e785 + 768daea commit 7f52d06
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
15 changes: 12 additions & 3 deletions docs/source/basic_usage/more_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ create data for MALA. In order to do so
Make sure to use enough k-points in the DFT calculation (LDOS sampling
requires denser k-grids then regular DFT calculations) and an appropriate
energy grid when calculating the LDOS. See the `initial MALA publication <https://www.doi.org/10.1103/PhysRevB.104.035120>`_
for more information on this topic. Lastly, when calculating
the LDOS with ``pp.x``, make sure to set ``use_gauss_ldos=.true.`` in the
``inputpp`` section.
for more information on this topic.

Also be aware that due to error cancellation in the total free energy, using
regular SCF accuracy may be not be sufficient to accurately sample the LDOS.
If you work with systems which include regions of small electronic density
(e.g., non-metallic systems, 2D systems, etc.) the MALA team strongly advises
to reduce the SCF threshold by roughly three orders of magnitude. I.e., if the
default SCF accuracy in Quantum ESPRESSO is 1e-6, one should use 1e-9 for such
systems.

Lastly, when calculating the LDOS with ``pp.x``, make sure to set
``use_gauss_ldos=.true.`` in the ``inputpp`` section.


Data conversion
Expand Down
6 changes: 6 additions & 0 deletions docs/source/basic_usage/predictions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This guide follows the examples ``ex05_run_predictions.py`` and
``ex06_ase_calculator.py``. In the :ref:`advanced section <production>` on
this topic, performance tweaks and extended access to observables are covered.

.. note::
If you are working with a 2D-system, and you have explicitly calculated
training data as a 2D-system in Quantum ESPRESSO, make sure to set
``parameters.target.assume_two_dimensional = True`` before any prediction.


In order to get direct access to electronic structure via ML, MALA uses
the ``Predictor`` class. Provided that the trained model was saved with
all the necessary information on the bispectrum descriptors and the LDOS,
Expand Down
5 changes: 4 additions & 1 deletion external_modules/total_energy_module/total_energy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,14 @@ SUBROUTINE init_run_setup(calculate_eigts)
CALL ggen( dfftp, gamma_only, at, bg, gcutm, ngm_g, ngm, &
g, gg, mill, ig_l2g, gstart )
END IF


IF (do_cutoff_2D) CALL cutoff_fact()

!
! This seems to be needed by set_rhoc()
!
CALL gshells ( lmovecell )

!
! ... allocate memory for structure factors
!
Expand Down
8 changes: 8 additions & 0 deletions mala/common/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ class ParametersTargets(ParametersBase):
kMax : float
Maximum wave vector up to which to calculate the SSF.
assume_two_dimensional : bool
If True, the total energy calculations will be performed without
periodic boundary conditions in z-direction, i.e., the cell will
be truncated in the z-direction. NOTE: This parameter may be
moved up to a global parameter, depending on whether descriptor
calculation may benefit from it.
"""

def __init__(self):
Expand All @@ -523,6 +530,7 @@ def __init__(self):
self.rdf_parameters = {"number_of_bins": 500, "rMax": "mic"}
self.tpcf_parameters = {"number_of_bins": 20, "rMax": "mic"}
self.ssf_parameters = {"number_of_bins": 100, "kMax": 12.0}
self.assume_two_dimensional = False

@property
def restrict_targets(self):
Expand Down
11 changes: 10 additions & 1 deletion mala/targets/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,12 +942,21 @@ def __setup_total_energy_module(
if qe_pseudopotentials is None:
qe_pseudopotentials = self.qe_pseudopotentials

if self.parameters.assume_two_dimensional:
qe_input_data["assume_isolated"] = "2D"

# In the 2D case, the Gamma point approximation introduces
# errors in the Ewald and Hartree energy for some reason.
kpoints = [1, 1, 1]
else:
kpoints = self.kpoints

self.write_tem_input_file(
atoms_Angstrom,
qe_input_data,
qe_pseudopotentials,
self.grid_dimensions,
self.kpoints,
kpoints,
)

# initialize the total energy module.
Expand Down

0 comments on commit 7f52d06

Please sign in to comment.