*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
adga.py 3.6 KiB
Newer Older
Patrick Kappl's avatar
Patrick Kappl committed
# %%
import h5py
from shutil import copyfile
import numpy as np
import subprocess
Patrick Kappl's avatar
Patrick Kappl committed


# %%
class Adga(object):
    def __init__(self, adga_root_path, adga_config_file_name,
                 two_particle_greens_function_file_name):
Patrick Kappl's avatar
Patrick Kappl committed
        self.adga_executable = adga_root_path + "/bin/abinitiodga"
        self.symmetrize_script = adga_root_path + "/scripts/symmetrize.py"
        self.adga_config_file_name = adga_config_file_name
        self.adga_output_file_name = "adga.hdf5"
        self.configure_adga_output_file_name()
        self.g2_file = h5py.File(two_particle_greens_function_file_name, "r")
        copyfile(two_particle_greens_function_file_name, "g4iw.hdf5")
        self.g4iw_file = h5py.File("g4iw.hdf5", "r+")
Patrick Kappl's avatar
Patrick Kappl committed
        self.worm_groups = [s + "/ineq-001/g4iw-worm/"
                            for s in self.g2_file.keys()
                            if (("worm-" in s) and (s != "worm-last"))]
        self.n_worm_samples = len(self.worm_groups)
        self.compound_indexes = list(self.g2_file[self.worm_groups[0]].keys())

    def get_worm_sample_generator(self):
        """Return a generator yielding green's functions from different
        worm samples."""
        def worm_sample_generator():
            for worm_group in self.worm_groups:
                value_groups = [worm_group + i + "/value"
                                for i in self.compound_indexes]
Patrick Kappl's avatar
Patrick Kappl committed
                yield np.array([self.g2_file[value_group][...]
Patrick Kappl's avatar
Patrick Kappl committed
                                for value_group in value_groups])
        return worm_sample_generator

    def __call__(self, two_particle_greens_function):
        g2 = two_particle_greens_function
Patrick Kappl's avatar
Patrick Kappl committed
        print("__call__ with g2[0,0,0,0]={}".format(g2[0, 0, 0, 0]))
        # Write g2 to g4iw.hdf5/worm-001
        for i in range(len(self.compound_indexes)):
            data_set = self.g4iw_file["worm-001/ineq-001/g4iw-worm/" +
                                      self.compound_indexes[i] + "/value"]
Patrick Kappl's avatar
Patrick Kappl committed
            data_set[...] = g2[i, ...]
            print(data_set[0, 0, 0])

        output = subprocess.check_output("python print_hdf5_data.py g4iw.hdf5"
                                         + " worm-001/ineq-001/g4iw-worm"
                                         + "/00001/value", shell=True)
        print(output.decode("utf-8"))
        self.g4iw_file.flush()
        output = subprocess.check_output("python print_hdf5_data.py g4iw.hdf5"
                                         + " worm-001/ineq-001/g4iw-worm"
                                         + "/00001/value", shell=True)
        print(output.decode("utf-8"))
Patrick Kappl's avatar
Patrick Kappl committed

        # Delete g4iw_sym.hdf5
        symmetry_file = "g4iw_sym.hdf5"
        if os.path.exists(symmetry_file):
            os.remove(symmetry_file)
Patrick Kappl's avatar
Patrick Kappl committed
        # Call /ADGA/scrips/symmetrize.py worm-001
        print(self.symmetrize_script + " worm-001")
        subprocess.call([self.symmetrize_script, "worm-001"])
        # Call /ADGA/bin/abinitiodga <path/to/dga.conf>
        print(self.adga_executable + " " + self.adga_config_file_name)
        subprocess.call([self.adga_executable, self.adga_config_file_name])
        # Return adga.hdf5/selfenergy/nonloc/dga
        adga_file = h5py.File(self.adga_output_file_name, "r")
        data_set = adga_file["selfenergy/nonloc/dga"]
        self_energy = np.array(data_set[...])
        adga_file.close()
Patrick Kappl's avatar
Patrick Kappl committed
        print(self_energy[0, 0, 0, 0, 0, 0])
        return self_energy[0, 0, 0, 0, 0, 0]

    def configure_adga_output_file_name(self):
        # TODO: Read the config file and check if "Outfile" exists in
        # [General]. If not, create it. In any case, set the "Outfile" in
        # self.adga_config_file_path
        pass