Skip to content

Commit 65702e9

Browse files
committed
add documentation in source codes
1 parent 85cf23c commit 65702e9

File tree

10 files changed

+1447
-115
lines changed

10 files changed

+1447
-115
lines changed

src/hwave/dos.py

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,54 @@
99

1010

1111
class DoS:
12+
"""
13+
A class to represent the Density of States (DoS).
14+
15+
Attributes
16+
----------
17+
dos : np.ndarray
18+
The density of states array.
19+
ene : np.ndarray
20+
The energy levels array.
21+
ene_num : int
22+
The number of energy levels.
23+
norb : int
24+
The number of orbitals.
25+
"""
26+
1227
dos: np.ndarray
1328
ene: np.ndarray
1429
ene_num: int
1530
norb: int
1631

1732
def __init__(self, ene: np.ndarray, dos: np.ndarray):
33+
"""
34+
Initialize the DoS object.
35+
36+
Parameters
37+
----------
38+
ene : np.ndarray
39+
The energy levels array.
40+
dos : np.ndarray
41+
The density of states array.
42+
"""
1843
assert ene.shape[0] == dos.shape[1]
1944
self.ene = ene
2045
self.dos = dos
2146
self.ene_num = ene.shape[0]
2247
self.norb = dos.shape[0]
2348

2449
def plot(self, filename: str = "", verbose: bool = False):
50+
"""
51+
Plot the density of states.
52+
53+
Parameters
54+
----------
55+
filename : str, optional
56+
The filename to save the plot (default is "").
57+
verbose : bool, optional
58+
If True, print additional information (default is False).
59+
"""
2560
try:
2661
import matplotlib.pyplot as plt
2762
except ImportError:
@@ -45,6 +80,16 @@ def plot(self, filename: str = "", verbose: bool = False):
4580
plt.close()
4681

4782
def write_dos(self, output: str, verbose: bool = False):
83+
"""
84+
Write the density of states to a file.
85+
86+
Parameters
87+
----------
88+
output : str
89+
The output filename.
90+
verbose : bool, optional
91+
If True, print additional information (default is False).
92+
"""
4893
if verbose:
4994
print("Writing DOS to file: ", output)
5095
total_dos = np.sum(self.dos, axis=0)
@@ -60,21 +105,51 @@ def write_dos(self, output: str, verbose: bool = False):
60105
fw.write("{:15.8f} ".format(self.dos[j, i]))
61106
fw.write("\n")
62107

63-
64108
def __read_geom(file_name="./dir-model/zvo_geom.dat"):
109+
"""
110+
Read the geometry from a file.
111+
112+
Parameters
113+
----------
114+
file_name : str, optional
115+
The filename to read the geometry from (default is "./dir-model/zvo_geom.dat").
116+
117+
Returns
118+
-------
119+
np.ndarray
120+
A 3x3 array representing the geometry.
121+
"""
65122
with open(file_name, "r") as fr:
66123
uvec = np.zeros((3, 3))
67124
for i, line in enumerate(itertools.islice(fr, 3)): # take first 3 lines
68125
uvec[i, :] = np.array(line.split())
69126
return uvec
70127

71-
72128
def calc_dos(
73129
input_dict: dict,
74130
ene_window: list | None = None,
75131
ene_num: int = 101,
76132
verbose: bool = False,
77133
) -> DoS:
134+
"""
135+
Calculate the density of states (DoS).
136+
137+
Parameters
138+
----------
139+
input_dict : dict
140+
Dictionary containing input parameters and file paths.
141+
ene_window : list, optional
142+
List containing the energy window [ene_low, ene_high]. If None, defaults to [ene_min - 0.2, ene_max + 0.2].
143+
ene_num : int, optional
144+
Number of energy points (default is 101).
145+
verbose : bool, optional
146+
If True, print additional information (default is False).
147+
148+
Returns
149+
-------
150+
DoS
151+
An instance of the DoS class containing the calculated density of states.
152+
"""
78153
try:
79154
import libtetrabz
80155
except ImportError:

src/hwave/qlms.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
from requests.structures import CaseInsensitiveDict
1717

1818
def run(*, input_dict: Optional[dict] = None, input_file: Optional[str] = None):
19+
"""
20+
Run the main process with the given input dictionary or input file.
21+
22+
Parameters:
23+
input_dict (Optional[dict]): A dictionary containing input parameters.
24+
input_file (Optional[str]): A path to a TOML file containing input parameters.
25+
26+
Raises:
27+
RuntimeError: If neither input_dict nor input_file is provided, or if both are provided.
28+
"""
1929
if input_dict is None:
2030
if input_file is None:
2131
raise RuntimeError("Neither input_dict nor input_file are passed")

src/hwave/qlmsio/read_input.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@
77

88

99
class QLMSInput():
10+
"""
11+
Class to handle QLMS input files and parameters.
12+
"""
13+
1014
valid_namelist = ["trans", "coulombinter", "coulombintra", "pairhop", "hund", "exchange", "ising", "pairlift", "interall", "initial", "onebodyg"]
15+
1116
def __init__(self, file_name_list, solver_type="UHFr"):
17+
"""
18+
Initialize the QLMSInput class.
19+
20+
Parameters:
21+
file_name_list (dict): Dictionary of file names.
22+
solver_type (str): Type of solver to use. Default is "UHFr".
23+
"""
1224
self.file_names = file_name_list
1325
self.ham_param = CaseInsensitiveDict()
1426
self.ham_param["Transfer"] = self._read_ham("trans", value_type="complex")
@@ -28,6 +40,15 @@ def __init__(self, file_name_list, solver_type="UHFr"):
2840
self.green["OneBodyG"] = self._read_green("onebodyg")
2941

3042
def get_param(self, key):
43+
"""
44+
Get parameters based on the key.
45+
46+
Parameters:
47+
key (str): Key to identify the parameter type.
48+
49+
Returns:
50+
dict or None: Returns the corresponding parameter dictionary or None if the key is invalid.
51+
"""
3152
if key == "mod" or key == "parameter":
3253
#return self.mod_param
3354
return None
@@ -41,6 +62,16 @@ def get_param(self, key):
4162
return None
4263

4364
def _read_para(self, file_key, start_line=5):
65+
"""
66+
Read parameters from a file.
67+
68+
Parameters:
69+
file_key (str): Key to identify the file.
70+
start_line (int): Line number to start reading from. Default is 5.
71+
72+
Returns:
73+
CaseInsensitiveDict: Dictionary of parameters read from the file.
74+
"""
4475
file_name = self.file_names[file_key]
4576
value = CaseInsensitiveDict()
4677
with open(file_name, "r") as f:
@@ -54,13 +85,32 @@ def _read_para(self, file_key, start_line=5):
5485
return value
5586

5687
def _read_ham(self, file_key, value_type="real"):
88+
"""
89+
Read Hamiltonian parameters from a file.
90+
91+
Parameters:
92+
file_key (str): Key to identify the file.
93+
value_type (str): Type of values to read ("real" or "complex"). Default is "real".
94+
95+
Returns:
96+
dict or None: Dictionary of Hamiltonian parameters or None if the file key is not found.
97+
"""
5798
if file_key in self.file_names:
5899
file_name = self.file_names[file_key]
59100
return self._load_text(file_name, value_type)
60101
else:
61102
return None
62103

63104
def _read_green(self, file_key):
105+
"""
106+
Read Green's function data from a file.
107+
108+
Parameters:
109+
file_key (str): Key to identify the file.
110+
111+
Returns:
112+
numpy.ndarray or None: Array of Green's function data or None if the file key is not found.
113+
"""
64114
if file_key in self.file_names:
65115
file_name = self.file_names[file_key]
66116
data = np.loadtxt(file_name, skiprows = 5)
@@ -69,6 +119,16 @@ def _read_green(self, file_key):
69119
return data
70120

71121
def _load_text(self, file_name, value_type):
122+
"""
123+
Load text data from a file.
124+
125+
Parameters:
126+
file_name (str): Name of the file to read.
127+
value_type (str): Type of values to read ("real" or "complex").
128+
129+
Returns:
130+
dict: Dictionary of data read from the file.
131+
"""
72132
if value_type == "real":
73133
value_width = 1
74134
_make_value = lambda v: float(v[0])

src/hwave/qlmsio/read_input_k.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@
1010

1111

1212
class QLMSkInput():
13+
"""
14+
Class to handle QLMS input files and parameters.
15+
"""
1316
valid_namelist = [s.lower() for s in ["path_to_input", "Geometry", "Transfer", "CoulombIntra", "CoulombInter", "Hund", "Ising", "PairLift", "Exchange", "PairHop", "Extern"]]
1417

1518
def __init__(self, info_inputfile, solver_type="UHFk"):
19+
"""
20+
Initialize the QLMSkInput object.
21+
22+
Parameters:
23+
info_inputfile (dict): Dictionary containing input file information.
24+
solver_type (str): Type of solver to use. Default is "UHFk".
25+
"""
1626
logger.debug(">>> QLMSkInput init")
1727

1828
# [file.input]
@@ -91,6 +101,16 @@ def __init__(self, info_inputfile, solver_type="UHFk"):
91101
self.green["onebodyg_uhf"] = self._read_green(file_name)
92102

93103
def _read_data(self, file_name, value_type="real"):
104+
"""
105+
Read data from a file.
106+
107+
Parameters:
108+
file_name (str): Name of the file to read.
109+
value_type (str): Type of values in the file ("real" or "complex"). Default is "real".
110+
111+
Returns:
112+
dict: Dictionary containing the data read from the file.
113+
"""
94114
info = {}
95115
try:
96116
data = np.loadtxt(file_name, skiprows = 5)
@@ -110,6 +130,15 @@ def _read_data(self, file_name, value_type="real"):
110130
return info
111131

112132
def _read_green(self, file_name):
133+
"""
134+
Read green function data from a file.
135+
136+
Parameters:
137+
file_name (str): Name of the file to read.
138+
139+
Returns:
140+
numpy.ndarray: Array containing the green function data.
141+
"""
113142
try:
114143
_data = np.loadtxt(file_name, dtype=np.int32, skiprows = 5)
115144
except FileNotFoundError:
@@ -118,6 +147,15 @@ def _read_green(self, file_name):
118147
return _data
119148

120149
def get_param(self, key):
150+
"""
151+
Get parameters based on the provided key.
152+
153+
Parameters:
154+
key (str): Key to specify which parameters to return ("mod", "ham", "output", etc.).
155+
156+
Returns:
157+
dict or None: Dictionary containing the requested parameters or None if the key is invalid.
158+
"""
121159
if key == "mod" or key == "parameter":
122160
return None
123161
elif key == "ham" or key == "hamiltonian":

0 commit comments

Comments
 (0)