• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ruberhauptmann / quant-met / 16403228399

20 Jul 2025 07:02PM UTC coverage: 37.347% (+0.7%) from 36.605%
16403228399

Pull #125

github

web-flow
Merge 17cb98f37 into b5a0f599e
Pull Request #125: Start q loop

3 of 55 branches covered (5.45%)

Branch coverage included in aggregate %.

62 of 120 new or added lines in 7 files covered. (51.67%)

45 existing lines in 5 files now uncovered.

180 of 435 relevant lines covered (41.38%)

1.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.74
/src/quant_met/cli/q_loop.py
1
"""Functions to run self-consistent calculation for the order parameter."""
2

3
import logging
3✔
4
from pathlib import Path
3✔
5

6
import h5py
3✔
7
import numpy as np
3✔
8
import sisl
3✔
9

10
from quant_met import routines
3✔
11
from quant_met.parameters import Parameters
3✔
12
from quant_met.parameters.control import CritTemp, QLoop
3✔
13

14
logger = logging.getLogger(__name__)
3✔
15

16

17
def q_loop(parameters: Parameters) -> None:
3✔
18
    """Self-consistent calculation for the order parameter.
19

20
    Parameters
21
    ----------
22
    parameters: Parameters
23
        An instance of Parameters containing control settings, the model,
24
        and k-point specifications for the T_C calculation.
25
    """
NEW
26
    if not isinstance(parameters.control, QLoop):
×
NEW
27
        raise ValueError("Wrong parameters for q-loop.")
×
28

NEW
29
    result_path = Path(parameters.control.outdir)
×
NEW
30
    result_path.mkdir(exist_ok=True, parents=True)
×
31

NEW
32
    hamiltonian = sisl.get_sile(parameters.control.hamiltonian_file).read_hamiltonian()
×
NEW
33
    k_grid_obj = sisl.MonkhorstPack(
×
34
        hamiltonian.geometry, [parameters.k_points.nk1, parameters.k_points.nk2, 1]
35
    )
36

NEW
37
    if isinstance(parameters.control.crit_temp, CritTemp):
×
NEW
38
        delta_vs_temp, critical_temperatures, fit_fig = routines.search_crit_temp(
×
39
            hamiltonian=hamiltonian,
40
            kgrid=k_grid_obj,
41
            hubbard_int_orbital_basis=np.array(parameters.control.hubbard_int_orbital_basis),
42
            epsilon=parameters.control.conv_treshold,
43
            max_iter=parameters.control.max_iter,
44
            n_temp_points=20,
45
        )
NEW
46
        logger.info("Search for T_C completed successfully.")
×
NEW
47
        logger.info("Obtained T_Cs: %s", critical_temperatures)
×
48

NEW
49
        fit_fig.savefig(
×
50
            result_path / f"{parameters.control.prefix}_critical_temperatures_fit.pdf",
51
            bbox_inches="tight",
52
        )
53

NEW
54
        result_file_crit_temp = (
×
55
            result_path / f"{parameters.control.prefix}_critical_temperatures.hdf5"
56
        )
NEW
57
        delta_vs_temp.to_hdf(result_file_crit_temp, key="delta_vs_temp")
×
NEW
58
        with h5py.File(result_file_crit_temp, mode="a") as file:
×
NEW
59
            for orbital, crit_temp_orbital in enumerate(critical_temperatures):
×
NEW
60
                file.attrs[f"T_C_{orbital}"] = crit_temp_orbital
×
61

NEW
62
        logger.info("Results saved to %s", result_file_crit_temp)
×
63
    else:
NEW
64
        critical_temperatures = []
×
NEW
65
        with h5py.File(f"{parameters.control.crit_temp}", mode="r") as file:
×
NEW
66
            for key, critical_temperature in file.attrs.items():
×
NEW
67
                if key.startswith("T_C"):
×
NEW
68
                    critical_temperatures.append(critical_temperature)
×
NEW
69
        logger.info("Read critical temperatures from file.")
×
NEW
70
        logger.info("Obtained T_Cs: %s", critical_temperatures)
×
71

NEW
72
    delta_vs_q, fig = routines.loop_over_q(
×
73
        hamiltonian=hamiltonian,
74
        kgrid=k_grid_obj,
75
        hubbard_int_orbital_basis=np.array(parameters.control.hubbard_int_orbital_basis),
76
        epsilon=parameters.control.conv_treshold,
77
        max_iter=parameters.control.max_iter,
78
        n_q_points=parameters.control.n_q_points,
79
        crit_temps=np.array(critical_temperatures),
80
    )
81

NEW
82
    result_file_q = result_path / f"{parameters.control.prefix}_q.hdf5"
×
NEW
83
    for key, df in delta_vs_q.items():
×
NEW
84
        df.to_hdf(result_file_q, key=f"temp_{float(key):.4f}")
×
85

NEW
86
    fig.savefig(f"{parameters.control.outdir}/{parameters.control.prefix}_q_plot.pdf")
×
87

NEW
88
    routines.analyse_q_data(
×
89
        q_data=delta_vs_q,
90
        hamiltonian=hamiltonian
91
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc