-
Notifications
You must be signed in to change notification settings - Fork 1
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
[WIP] ABINIT DFPT SHG #1
base: main
Are you sure you want to change the base?
Changes from 76 commits
015987f
29a5731
3b550be
df7c769
d22e247
313f809
c77e21f
7f55cd3
aee4be8
832fdbe
dd582ff
e84f1fa
c369c86
2fefc6f
2d24f81
f826b29
3079e55
a5e502f
91e133f
3336910
58e6c92
25817f4
760e537
8016942
cda583b
5043fe6
179d836
4e86c93
b8ee8a6
905c470
fe52d5a
50ae3c0
40bfecd
0042441
40f6f80
4679806
1ffc588
3875bac
94ef40f
258b9d9
19e1c5f
5297c3b
01a0ac9
861f6d2
40014fc
8c9b64c
e7e350b
9f2a69f
b39fc29
4fd27c3
37581a0
a8e6c0e
d8740de
d8b1f60
0a03331
bfda61a
35b8635
4c43063
8f4c463
06e4a71
55c5dd6
63ec92c
d834c3e
def6a4e
d30890f
738ea89
5397132
0817ede
8c96fb3
fd54870
8c49db9
0291106
7d3e43b
593f962
5984ba9
7fa53f5
99104ac
aaa1f7b
42cae12
8a9b2fc
58f8b9a
1118986
47d5acc
e945136
7b719e5
a9e5ede
06f0140
fd12860
42d697b
3865936
e210b58
96f8674
5a11071
92b43e9
1d2e8fd
b1a93bc
22025bf
018b211
ad68670
1149895
c5b45b7
270408f
0277c8f
fad9396
8726768
631341e
42038ce
9c84108
ded305a
f1c7abf
9ab1b23
69a3b26
f2f315d
6d06014
a7db2ee
8d57884
f5ab8cc
bad9902
03b62fa
b48723c
e9710d2
cc44049
3dce3a5
d11b666
409679b
28ba426
7c74022
87ee21a
ef40fa9
54a9645
1ebc9a7
49d1c1d
2087caf
b343ad2
e51bde7
f14586c
fdd2c9e
f1894c1
d64b2f3
b56e3d7
a54768a
1ddf2dd
b837d5d
00590dd
103038d
1fb11a8
9599178
a8808b1
8fe6935
4403858
3d6a3a3
5131932
7377fca
2513903
fdb4894
79aaf15
96b2b82
9600cef
a24649e
ec1b598
ed853c8
3c0be95
6a49091
e9df035
3055638
fb9a6e8
2469f1a
ce55074
846d3aa
3a90dce
4a704f1
52f1a1f
ae91bf1
4b71309
4944aed
480f75e
7ac2662
f4ce054
b110095
05d1884
00a5405
0c04d1b
6b53ebd
078e3b1
bc95b4a
8a12e54
68f7e07
a0b4bda
ab4182f
cff86cf
b285d30
d90a074
ae97d6b
8b19726
527c4c7
b69ae55
42bc7b8
9c4447c
6266093
6d3c351
faada35
f11ac37
fed13c7
121936b
2d9a1e8
237dcdc
c57f9c1
cda2a81
071d1c8
0fb73a9
d743a69
7761de4
67efb7f
7add7ca
5f0bc75
3d55b2b
3f61317
df1ae35
eaed474
4244da9
4b84d78
11fc0ea
bd336d5
38073cd
f532d27
4bbda09
9832136
6349766
7b4a66a
4bcf127
bbc4933
55a87f0
44a1125
b79b1c1
149f05c
073eac1
906ca38
44de991
76d55ea
5cccaa2
93ef6d2
95ea060
90e6153
96ff9e9
388713d
c526b04
3fc9f2e
012d1cd
784709d
65b657b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
"""DFPT abinit flow makers.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass, field | ||
from typing import TYPE_CHECKING | ||
|
||
from jobflow import Flow, Maker | ||
|
||
from atomate2.abinit.jobs.core import StaticMaker | ||
from atomate2.abinit.jobs.mrgddb import MrgddbMaker | ||
from atomate2.abinit.jobs.response import ( | ||
DdeMaker, | ||
DdkMaker, | ||
DteMaker, | ||
generate_dde_perts, | ||
generate_ddk_perts, | ||
generate_dte_perts, | ||
run_dde_rf, | ||
run_ddk_rf, | ||
run_dte_rf, | ||
) | ||
from atomate2.abinit.powerups import ( | ||
update_factory_kwargs, | ||
update_user_abinit_settings, | ||
update_user_kpoints_settings, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
from pymatgen.core.structure import Structure | ||
|
||
from atomate2.abinit.jobs.base import BaseAbinitMaker | ||
|
||
|
||
@dataclass | ||
class DfptFlowMaker(Maker): | ||
""" | ||
Maker to generate a DFPT flow with abinit. | ||
|
||
The classmethods allow to tailor the flow for specific properties | ||
accessible via DFPT. | ||
|
||
Parameters | ||
---------- | ||
name : str | ||
Name of the flows produced by this maker. | ||
scf_maker : .BaseAbinitMaker | ||
The maker to use for the static calculation. | ||
ddk_maker : .BaseAbinitMaker | ||
The maker to use for the DDK calculations. | ||
dde_maker : .BaseAbinitMaker | ||
The maker to use for the DDE calculations. | ||
dte_maker : .BaseAbinitMaker | ||
The maker to use for the DTE calculations. | ||
mrgddb_maker : .Maker | ||
The maker to merge the DDE and DTE DDB. | ||
use_ddk_sym : bool | ||
True if only the irreducible DDK perturbations should be considered, | ||
False otherwise. | ||
use_dde_sym : bool | ||
True if only the irreducible DDE perturbations should be considered, | ||
False otherwise. | ||
dte_skip_permutations: Since the current version of abinit always performs | ||
all the permutations of the perturbations, even if only one is asked, | ||
if True avoids the creation of inputs that will produce duplicated outputs. | ||
dte_phonon_pert: is True also the phonon perturbations will be considered. | ||
Default False. | ||
dte_ixc: Value of ixc variable. Used to overwrite the default value read | ||
from pseudos. | ||
""" | ||
|
||
name: str = "DFPT" | ||
static_maker: BaseAbinitMaker = field(default_factory=StaticMaker) | ||
VicTrqt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ddk_maker: BaseAbinitMaker | None = field(default_factory=DdkMaker) # | | ||
dde_maker: BaseAbinitMaker | None = field( | ||
default_factory=DdeMaker | ||
) # | VT: replace by bool? | ||
dte_maker: BaseAbinitMaker | None = field(default_factory=DteMaker) # | | ||
mrgddb_maker: Maker | None = field(default_factory=MrgddbMaker) # | | ||
use_ddk_sym: bool | None = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DDK cannot be reduced by symmetry There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
use_dde_sym: bool | None = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this False by default? Is it because for dte it requires all the DDE even if they can be reduced by symmetry? (I seem to remember this, but I am not sure). And at the moment, you have the type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed None and set it to True as default and it is overridden to False in the Shg class. |
||
dte_skip_permutations: bool | None = False | ||
dte_phonon_pert: bool | None = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it make sense to have this option? This is passed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
dte_ixc: int | None = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How many values are acceptable of ixc? I don't remember if it is only one or all the LDA are acceptable. In case there are few values acceptable, cannot this be set in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the end I removed it because it was only affecting the generation of the perturbations, not the calculation in itself. Can be added somewhere in the future if needed. |
||
|
||
def make( | ||
self, | ||
structure: Structure | None = None, | ||
restart_from: str | Path | None = None, | ||
) -> Flow: | ||
""" | ||
Create a DFPT flow. | ||
|
||
Parameters | ||
---------- | ||
structure : Structure | ||
A pymatgen structure object. | ||
restart_from : str or Path or None | ||
One previous directory to restart from. | ||
|
||
Returns | ||
------- | ||
Flow | ||
A DFPT flow | ||
""" | ||
static_job = self.static_maker.make(structure, restart_from=restart_from) | ||
# To avoid metallic case=occopt=3 which is not okay wrt. DFPT \ | ||
# and occopt 1 with spin polarization requires spinmagntarget | ||
static_job = update_factory_kwargs( | ||
VicTrqt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static_job, {"smearing": "nosmearing", "spin_mode": "unpolarized"} | ||
) | ||
# static_job = update_user_kpoints_settings(static_job,{"grid_density": 3000}) | ||
# static_job = update_user_abinit_settings( static_job,{'nstep': 500, | ||
# 'toldfe': 1e-22, | ||
# 'autoparal': 1, | ||
# 'npfft': 1, | ||
# 'chksymbreak': '0'}) | ||
static_job = update_user_kpoints_settings(static_job, {"grid_density": 1000}) | ||
VicTrqt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static_job = update_user_abinit_settings( | ||
static_job, | ||
{ | ||
"nstep": 500, | ||
"toldfe": 1e-6, | ||
"autoparal": 1, | ||
"npfft": 1, | ||
"chksymbreak": "0", | ||
}, | ||
) | ||
jobs = [static_job] | ||
|
||
if self.ddk_maker: | ||
# generate the perturbations for the DDK calculations | ||
ddk_perts = generate_ddk_perts( | ||
gsinput=static_job.output.input.abinit_input, | ||
use_symmetries=self.use_ddk_sym, | ||
) | ||
jobs.append(ddk_perts) | ||
|
||
# perform the DDK calculations | ||
ddk_calcs = run_ddk_rf( | ||
perturbations=ddk_perts.output, | ||
prev_outputs=static_job.output.dir_name, | ||
) | ||
jobs.append(ddk_calcs) | ||
|
||
if self.dde_maker: | ||
# generate the perturbations for the DDE calculations | ||
dde_perts = generate_dde_perts( | ||
gsinput=static_job.output.input.abinit_input, | ||
use_symmetries=self.use_dde_sym, | ||
) | ||
jobs.append(dde_perts) | ||
|
||
# perform the DDE calculations | ||
dde_calcs = run_dde_rf( | ||
perturbations=dde_perts.output, | ||
prev_outputs=[[static_job.output.dir_name], ddk_calcs.output["dirs"]], | ||
VicTrqt marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for the code to be like this? in if isinstance(rf_maker, (DdeMaker, DteMaker)):
prev_outputs = [item for sublist in prev_outputs for item in sublist] in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following our discussion, I unfolded the list of prev_outputs in the construction of the flow. The main issue here is that .dir_name is a string while ["dirs"] is a list of strings so this means that prev_outputs looks like [dir_name, [dirs]] so I had to create a function to unfold it into a non-nested list with np.hstack. |
||
) | ||
jobs.append(dde_calcs) | ||
|
||
if self.dte_maker: | ||
# generate the perturbations for the DTE calculations | ||
dte_perts = generate_dte_perts( | ||
gsinput=static_job.output.input.abinit_input, | ||
skip_permutations=self.dte_skip_permutations, | ||
phonon_pert=self.dte_phonon_pert, | ||
ixc=self.dte_ixc, | ||
) | ||
jobs.append(dte_perts) | ||
|
||
# perform the DTE calculations | ||
dte_calcs = run_dte_rf( | ||
perturbations=dte_perts.output, | ||
prev_outputs=[ | ||
[static_job.output.dir_name], | ||
# ddk_calcs.output["dirs"], #not sure this is needed | ||
dde_calcs.output["dirs"], | ||
VicTrqt marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as for dde perturbations. Can this be made a list of directories directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
], | ||
) | ||
jobs.append(dte_calcs) | ||
|
||
if self.mrgddb_maker: | ||
# merge the DDE and DTE DDB. | ||
|
||
prev_outputs = [dde_calcs.output["dirs"], dte_calcs.output["dirs"]] | ||
|
||
mrgddb_job = self.mrgddb_maker.make( | ||
prev_outputs=prev_outputs, | ||
) | ||
|
||
jobs.append(mrgddb_job) | ||
|
||
# TODO: implement the possibility of other DFPT WFs (phonons,...) | ||
# if self.wfq_maker: | ||
# ... | ||
|
||
return Flow(jobs, output=jobs[-1].output, name=self.name) # TODO: fix outputs | ||
|
||
@classmethod | ||
def shg(cls) -> Flow: | ||
VicTrqt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Chi2 SHG. | ||
|
||
Create a DFPT flow to compute the static nonlinear optical | ||
susceptibility tensor for the second-harmonic generation. | ||
|
||
""" | ||
ddk_maker = DdkMaker() | ||
dde_maker = DdeMaker() | ||
dte_maker = DteMaker() | ||
mrgddb_maker = MrgddbMaker() | ||
return cls( | ||
name="Chi2 SHG", | ||
ddk_maker=ddk_maker, | ||
dde_maker=dde_maker, | ||
dte_maker=dte_maker, | ||
mrgddb_maker=mrgddb_maker, | ||
use_ddk_sym=False, | ||
use_dde_sym=False, | ||
dte_skip_permutations=False, | ||
dte_phonon_pert=False, | ||
dte_ixc=None, # TODO: enforce LDA or not ? | ||
) |
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.
I think you can remove the "VT". Maybe if someone does not know you the comment might be confusing :P
Also, shouldn't this also happen for the 1DEN files?
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.
not called 1DEN rather DEN1, DEN2, etc... let's leave it at that for the moment and deal with it when the time comes (phonons WF?)