Skip to content

Commit

Permalink
added a new option to detect contraction_flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosuke-nakano committed Jul 12, 2024
1 parent 6fa9a83 commit eb887a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
20 changes: 16 additions & 4 deletions turbogenius/prep_genius.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import numpy as np
from typing import Optional
import time

# Logger
from logging import getLogger, StreamHandler, Formatter
Expand Down Expand Up @@ -53,6 +54,7 @@ class DFT_genius(GeniusIO):
def __init__(
self,
fort10: str = "fort.10",
det_contraction_flag: Optional[bool] = None,
grid_size: Optional[list] = None,
lbox: Optional[list] = None,
smearing: float = 0.0,
Expand Down Expand Up @@ -92,10 +94,19 @@ def __init__(
self.independent_kpoints = independent_kpoints
self.thr_lindep = thr_lindep
self.kpoints = kpoints

io_fort10 = IO_fort10(self.fort10)
# self.io_fort10 = IO_fort10(self.fort10)
# this should not be an attribute!! because fort.10 is sometimes very large.

if det_contraction_flag is None:
logger.warning('det_contraction_flag is not set.')
logger.warning('det_contraction_flag is detected by reading fort.10, which will be slow for a big WF.')
det_contraction_flag = io_fort10.det_contraction_flag
else:
logger.info(f'det_contraction_flag = {det_contraction_flag}.')
time.sleep(5)
self.det_contraction_flag = det_contraction_flag

if io_fort10.f10structure.pbc_flag:
# for crystals, Lx, Ly, and Lz are cells
Expand Down Expand Up @@ -142,7 +153,7 @@ def __init__(

# self prep class!!
self.prep = Prep.parse_from_default_namelist(
in_fort10=fort10, twist_average=self.twist_average
in_fort10=fort10, twist_average=self.twist_average, det_contraction_flag=self.det_contraction_flag
)

self.prep.set_parameter(
Expand Down Expand Up @@ -171,7 +182,8 @@ def __init__(
# &dft part

# contraction
if io_fort10.det_contraction_flag:
#if io_fort10.det_contraction_flag: # very slow for a large WF
if self.det_contraction_flag:
self.prep.set_parameter(
parameter="contracted_on", value=".true.", namelist="&dft"
)
Expand All @@ -181,7 +193,6 @@ def __init__(
)

# xc
assert self.xc in {"lda", "lsda"}
if self.xc == "lda":
self.prep.set_parameter(parameter="typedft", value=1, namelist="&dft")
elif self.xc == "lsda":
Expand Down Expand Up @@ -391,6 +402,7 @@ def generate_input(
if cont:
self.prep.set_parameter("iopt", 0, "$systems")
self.prep.generate_input(input_name=input_name)
logger.info('check: prep-input generation is done.')

def run(
self, input_name: str = "prep.input", output_name: str = "out_prep"
Expand Down
11 changes: 7 additions & 4 deletions turbogenius/pyturbo/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,19 @@ def check_results(self, output_names: Optional[list] = None):
return flags

@staticmethod
def read_default_namelist(in_fort10: str = "fort.10"):
def read_default_namelist(in_fort10: str = "fort.10", det_contraction_flag=None):
prep_default_file = os.path.join(pyturbo_data_dir, "prep", "prep.input")
namelist = Namelist.parse_namelist_from_file(prep_default_file)

# fort.10
io_fort10 = IO_fort10(fort10=in_fort10)
# ! right! we should keep io_fort10 "local".
# It should not be an attrobute because it could be very large..


if det_contraction_flag is None:
det_contraction_flag = io_fort10.det_contraction_flag
# contraction
if io_fort10.det_contraction_flag:
if det_contraction_flag:
namelist.set_parameter(
parameter="contracted_on", value=".true.", namelist="&dft"
)
Expand Down Expand Up @@ -285,10 +287,11 @@ def parse_from_default_namelist(
in_fort10: str = "fort.10",
magnetic_moments_3d_array: Optional[list] = None,
twist_average: bool = False,
det_contraction_flag: Optional[bool] = None
):
if magnetic_moments_3d_array is None:
magnetic_moments_3d_array = []
namelist = cls.read_default_namelist(in_fort10=in_fort10)
namelist = cls.read_default_namelist(in_fort10=in_fort10, det_contraction_flag=det_contraction_flag)
# fort10
io_fort10 = IO_fort10(fort10=in_fort10)
# occ
Expand Down

0 comments on commit eb887a7

Please sign in to comment.