예제 #1
0
def get_values(filename, filetype):
    """Get values of interest from given file of given type."""
    box_a = 0.0
    box_b = 0.0
    box_c = 0.0
    alpha = 0.0
    beta = 0.0
    gamma = 0.0
    energy = 0.0
    density = 0.0
    volume = 0.0
    temp = 0.0

    if filetype == "pwout":
        molsys = read_pw_out(filename)
        molsys.ts_boxes[-1].box_cart2lat()
        box = molsys.ts_boxes[-1]
        box_a = box.ltc_a
        box_b = box.ltc_b
        box_c = box.ltc_c
        alpha = np.degrees(box.ltc_alpha)
        beta = np.degrees(box.ltc_beta)
        gamma = np.degrees(box.ltc_gamma)
        energy = molsys.pw_other_info["ENERGIES"][-1]
        density = molsys.pw_other_info["DENSITIES"][-1]
        volume = molsys.pw_other_info["VOLUMES"][-1]
        temp = 0.0  # ab initio is always at 0 K
    elif filetype == "lmplog":
        molsys = ag_lmplog.LmpLog()
        molsys.read_lmplog(filename)
        box_a = molsys.data[-1]["Cella"][-1]
        box_b = molsys.data[-1]["Cellb"][-1]
        box_c = molsys.data[-1]["Cellc"][-1]
        alpha = molsys.data[-1]["CellAlpha"][-1]
        beta = molsys.data[-1]["CellBeta"][-1]
        gamma = molsys.data[-1]["CellGamma"][-1]
        energy = molsys.data[-1]["PotEng"][-1]
        density = molsys.data[-1]["Density"][-1]
        volume = molsys.data[-1]["Volume"][-1]
        temp = molsys.data[-1]["Temp"][-1]
    elif filetype == "cif":
        box = get_cell_from_cif(filename)
        cif_others = get_other_stuff_from_cif(filename)
        box_a = box.ltc_a
        box_b = box.ltc_b
        box_c = box.ltc_c
        alpha = np.degrees(box.ltc_alpha)
        beta = np.degrees(box.ltc_beta)
        gamma = np.degrees(box.ltc_gamma)
        density = cif_others["density"]
        volume = cif_others["cell_volume"]
        temp = cif_others["cell_measurement_temperature"]
    else:
        raise Warning("Only pwout, lmplog and cif are valid keywords")

    keys = ("a", "b", "c", "alpha", "beta", "gamma", "temp", "volume",
            "density", "energy")
    values = (box_a, box_b, box_c, alpha, beta, gamma, temp, volume, density,
              energy)
    return OrderedDict(list(zip(keys, values)))
예제 #2
0
def _append_data(data, lmplog, fstart=1, thermo="PotEng"):
    """
    fstart : int
        frame to start recording from
    """
    cur_log = agl.LmpLog()
    cur_log.read_lmplog(lmplog)

    # potential energy of the whole system (solvent included if part of system)
    cur_data = cur_log.data[-1][thermo][fstart:]
    data.extend(cur_data)
예제 #3
0
def find_best_frame(lmplogs, dcds, thermo="c_pe_solvate_complete", percentage_to_check=80):
    """
    Find the frame with the lowest energy / value for use in the requenching procedure.

    Parameters
    ----------
    lmplogs : tuple or list
        lammps-log files with thermo information.

    dcds : tuple or list
        dcd files with coordinates which correspond the given data of the
        log files (same number of frames is mandatory)

    Returns
    -------
    total_min_dcd : str
        name of dcd file with the lowest energy / value

    total_min_idx : int
        index of frame with the lowest energy / value

    total_min_val : int or float
        lowest value found over all lmplogs for thermo

    """
    #total_min_val = 1e20
    #total_min_idx = None
    #total_min_dcd = ""
    total_data = []

    # read the whole dataset, i.e. all lmplog files
    for lmplog in lmplogs:
        cur_log = agl.LmpLog()
        cur_log.read_lmplog(lmplog)

        # flatten list if more than one run was done
        # neglect the first frame since it is redundant in the log file
        cur_data = [i[thermo][1:] for i in cur_log.data]
        cur_data = [item for i in cur_data for item in i]
        total_data.append(cur_data)

    del cur_data

    # find minimum value in the last X % of the data
    total_data_flattened = [item for i in total_data for item in i]
    last_frames_to_check = int(percentage_to_check / 100 * len(total_data_flattened))
    data_to_check = total_data_flattened[-last_frames_to_check:]
    min_val = min(data_to_check)

    for cur_data, dcd in zip(total_data, dcds):
        if min_val in cur_data:
            return (dcd, cur_data.index(min_val), min_val)
    else:
        raise Exception("This should not have happened :/")
예제 #4
0
    def read_file(self, filename, filetype):
        """Get values of interest from given file of given type."""
        if filetype == "pwout":
            molsys = read_pw_out(filename)
            molsys.ts_boxes[-1].box_cart2lat()
            # get box and convert angles to degrees
            self.box = molsys.ts_boxes[-1]
            self.box.ltc_alpha = np.degrees(molsys.ts_boxes[-1].ltc_alpha)
            self.box.ltc_beta = np.degrees(molsys.ts_boxes[-1].ltc_beta)
            self.box.ltc_gamma = np.degrees(molsys.ts_boxes[-1].ltc_gamma)

            self.energy = molsys.pw_other_info["ENERGIES"][-1]
            self.density = molsys.pw_other_info["DENSITIES"][-1]
            self.volume = molsys.pw_other_info["VOLUMES"][-1]
            # ab initio is always at 0 K
            self.temp = 0.0
            self.natoms = len(molsys.ts_coords[-1])
        elif filetype == "lmplog":
            molsys = ag_lmplog.LmpLog()
            molsys.read_lmplog(filename)

            # box stuff
            self.box = mdb.Box()
            self.box.ltc_a = molsys.data[-1]["Cella"][-1]
            self.box.ltc_b = molsys.data[-1]["Cellb"][-1]
            self.box.ltc_c = molsys.data[-1]["Cellc"][-1]
            self.box.ltc_alpha = molsys.data[-1]["CellAlpha"][-1]
            self.box.ltc_beta = molsys.data[-1]["CellBeta"][-1]
            self.box.ltc_gamma = molsys.data[-1]["CellGamma"][-1]

            # other
            self.energy = molsys.data[-1]["PotEng"][-1]
            self.density = molsys.data[-1]["Density"][-1]
            self.volume = molsys.data[-1]["Volume"][-1]
            self.temp = molsys.data[-1]["Temp"][-1]

            with open(filename) as fin:
                line = fin.readline()
                while line != '':
                    if line.startswith("Loop time of"):
                        self.natoms = int(line.split()[-2])

                    line = fin.readline()

        elif filetype == "cif":
            # box stuff
            self.box = get_cell_from_cif(filename)
            cif_others = get_other_stuff_from_cif(filename)
            self.box.ltc_alpha = np.degrees(self.box.ltc_alpha)
            self.box.ltc_beta = np.degrees(self.box.ltc_beta)
            self.box.ltc_gamma = np.degrees(self.box.ltc_gamma)

            # other
            self.density = cif_others["density"]
            self.volume = cif_others["cell_volume"]
            self.temp = cif_others["cell_measurement_temperature"]
        else:
            raise Warning("Only pwout, lmplog and cif are valid keywords")

        if filetype == "lmplog" or filetype == "pwout":
            self.nmols = int(self.natoms / self.atoms_p_molecule)
        else:
            self.nmols = cif_others["cell_formula_units"]
예제 #5
0
    iterations_on = (0, 107)
    #iterations_off = (0, 107, 115)
    dreiding = "off"

    for iteration in iterations_on:
        # get box from original (multiplied and untouched) supercell in order to get the
        # factors of each unit cell it was built from
        # using the box from the last snapshot could lead to inconsistencies due to rounding
        #original_supercell = agum.Unification()
        #original_supercell.read_lmpdat(lmpdat_supercell.format(iteration, polymorph))
        #original_supercell.ts_boxes[0].box_lmp2lat()

        lammps_polymorphs = {}

        FF_SINGLE_MOLECULE = ag_lmplog.LmpLog()
        FF_SINGLE_MOLECULE.read_lmplog(path_single.format(iteration))
        # convert to kcal*mol-1
        FF_SINGLE_MOLECULE.data[-1]["PotEng"][-1] *= 23

        for index, polymorph in enumerate(("I", "II", "III", "IV", "V")):

            if iteration == 0 or dreiding == "off":
                # no dreiding force field for stock gaff force field
                cur_file = path_scell_dreiding_off.format(iteration, polymorph)
            else:
                cur_file = path_scell_dreiding_on.format(iteration, polymorph)

            #print(cur_file)
            cur_polymorph = Polymorph(30)
            cur_polymorph.read_file(cur_file, "lmplog")