def get_electronic_energy(self, shift=True, optimized=None, rawenergies=False, **params):
        """Pulls Energies from the "Summary" portion of a log file. Shifts the potential energy to 0 to avoid
         problems with DVR later and extrapolates to a regular sized rudy grid to avoid problems with
         interpolation /sizing/ etc.
        :return: an array (col0: scancoord_1(ang), col1: scancoord_2(ang), col2: energy(shifted hartrees))
        :rtype: np.ndarray """
        from McUtils.Zachary.Interpolator import Interpolator
        ens = []
        crds = []
        full_grid = np.array(list(self.cartesians.keys()))
        if optimized is None:
            raise Exception("No energy type specified.")
        for log in self.logs:
            if optimized:
                with GaussianLogReader(log) as reader:
                    parse = reader.parse("OptimizedScanEnergies")
                energy_array, coords = parse["OptimizedScanEnergies"]
                roo = coords['Roo12']
                roh = coords['MrOH']
                if 'far' in log:
                    roh = -roh
                crds.append(np.column_stack((roo, roh)))
                ens.append(energy_array)
            else:
                with GaussianLogReader(log) as reader:
                    parse = reader.parse("ScanEnergies")
                vals = parse["ScanEnergies"]["values"][:, 3]  # N MrOH SCF MP2
                ens.append(vals)
        energy = np.concatenate(ens)
        if len(crds) > 0:
            coord_array = np.concatenate(crds)
            idx = np.lexsort((coord_array[:, 0], coord_array[:, 1]))
            energy = energy[idx]
            idx = np.lexsort((full_grid[:, 0], full_grid[:, 1]))
            full_grid = full_grid[idx]

        energyF = np.column_stack((full_grid, energy))
        idx = np.lexsort((full_grid[:, 1], full_grid[:, 0]))
        out = energyF[idx]
        if shift:
            out[:, 2:] -= min(out[:, 2:])  # shift gaussian numbers to zero HERE to avoid headaches later.
        else:
            pass
        if rawenergies:
            energyArray = out
        else:
            sq_grid, sq_vals = Interpolator(out[:, :2], out[:, 2], interpolation_function=lambda: "ignore").\
                regular_grid(interp_kind='cubic', fillvalues=True)
            energyArray = np.column_stack((sq_grid, sq_vals))
        return energyArray
    def get_scoords(self, midpoint=False):
        """ pulls the optimized (if applicable) structures from  a 2D Gaussian scan.
        :return: atomnum:
        :return: cartesian coordinates at STANDARD optimized geometry keyed by the (scancoord_1, scancoord_2) distances.
        :rtype: OrderedDict
        """
        from MolecularSys import MolecularOperations
        from collections import OrderedDict
        struct = OrderedDict()
        for log in self.logs:
            with GaussianLogReader(log) as reader:
                parse = reader.parse("StandardCartesianCoordinates")
            atomnum, ccs = parse["StandardCartesianCoordinates"]
            xdists = MolecularOperations.calculateBonds(ccs, *self.scancoord_1)
            xdists = np.around(xdists, 4)

            ydists = MolecularOperations.calculateBonds(ccs, *self.scancoord_2)
            ydists = np.around(ydists, 4)
            if midpoint:
                if "flipped" in log:
                    MrOH = -1*((xdists / 2) - ydists)
                    MrOH = np.around(MrOH, 4)
                else:
                    MrOH = (xdists/2) - ydists
                    MrOH = np.around(MrOH, 4)
                coords = zip(xdists, MrOH, ccs)
            else:
                coords = zip(xdists, ydists, ccs)
            struct.update((((x, y), cc) for x, y, cc in coords))
        return struct
Exemplo n.º 3
0
def get_opt_struct(log_file):
    # SHOULD BE ABLE TO CREATE INSTANCE FROM LOGINTERPRETER
    """ pulls the optimized structures from 2D Gaussian scans
        :arg log_file: an output file from a gaussian optimization scan
        :returns is_opt: a vector of true/false statements indication if optimization was completed.
                struct: structure of cartesian coordinates at optimized geometry keyed by the (oo, oh) distances."""
    with GaussianLogReader(log_file) as reader:
        parse = reader.parse(
            ("OptimizationParameters", "StandardCartesianCoordinates"))
    zmcs = parse["StandardCartesianCoordinates"][1]
    is_opt, params = parse["OptimizationParameters"]

    oo_pos = (0, 1)
    oops = zmcs[:, oo_pos]
    diffs = np.diff(oops, axis=1)
    diffs = diffs.reshape((len(diffs), 3))
    oodists = np.linalg.norm(diffs, axis=1)
    oodists = np.around(oodists, 4)

    oh_pos = (1, 2)
    ohps = zmcs[:, oh_pos]
    ohdiffs = np.diff(ohps, axis=1)
    ohdiffs = ohdiffs.reshape((len(ohdiffs), 3))
    ohdists = np.linalg.norm(ohdiffs, axis=1)
    ohdists = np.around(ohdists, 4)

    coords = zip(oodists, ohdists, zmcs)
    struct = OrderedDict((((oo, oh), zm) for oo, oh, zm in coords))

    return is_opt, struct
Exemplo n.º 4
0
def get_scan_dips(log_file, mass):
    with GaussianLogReader(log_file) as reader:
        parse = reader.parse(("DipoleMoments", "StandardCartesianCoordinates"))
    dips = parse["DipoleMoments"]
    zmcs = parse["StandardCartesianCoordinates"][1]
    oo_pos = (0, 1)
    oops = zmcs[:, oo_pos]
    diffs = np.diff(oops, axis=1)
    diffs = diffs.reshape((len(diffs), 3))
    oodists = np.linalg.norm(diffs, axis=1)
    oodists = np.around(oodists, 4)

    oh_pos = (1, 2)
    ohps = zmcs[:, oh_pos]
    ohdiffs = np.diff(ohps, axis=1)
    ohdiffs = ohdiffs.reshape((len(ohdiffs), 3))
    ohdists = np.linalg.norm(ohdiffs, axis=1)
    ohdists = np.around(ohdists, 4)

    # shift dipole to COM DONT SHIFT FOR ECKART ROTATION
    com = np.dot(mass, zmcs) / np.sum(mass)
    dipshift = dips - com

    things = zip(oodists, ohdists, dips)
    struct = OrderedDict((((oo, oh), dip) for oo, oh, dip in things))
    return struct
Exemplo n.º 5
0
def get_opt_struct(log_file):
    """ pulls the optimized structures from 2D Gaussian scans
        :arg log_file: an output file from a gaussian optimization scan
        :returns is_opt: a vector of true/false statements indication if optimization was completed.
                struct: structure of cartesian coordinates at optimized geometry keyed by the (oo, oh) distances."""
    with GaussianLogReader(log_file) as reader:
        parse = reader.parse(("OptimizationParameters", "ZMatCartesianCoordinates"))
    zmcs = parse["ZMatCartesianCoordinates"][1]
    is_opt, params = parse["OptimizationParameters"]

    oo_pos = (0, 3)
    oops = zmcs[:, oo_pos]
    diffs = np.diff(oops, axis=1)
    diffs = diffs.reshape((len(diffs), 3))
    oodists = np.linalg.norm(diffs, axis=1)
    oo_idx = [i for i, oo in enumerate(oodists) if oo >= 3.3]
    oodists = np.delete(oodists, oo_idx)

    oh_pos = (3, 4)
    ohps = zmcs[:, oh_pos]
    ohdiffs = np.diff(ohps, axis=1)
    ohdiffs = ohdiffs.reshape((len(ohdiffs), 3))
    ohdists = np.linalg.norm(ohdiffs, axis=1)
    ohdists = np.delete(ohdists, oo_idx)
    zmcs = np.delete(zmcs, oo_idx, axis=0)
    coords = zip(oodists, ohdists, zmcs)
    struct = OrderedDict((((oo, oh), zm) for oo, oh, zm in coords))

    return is_opt, struct
Exemplo n.º 6
0
def get_coords(log_file=None):
    """Uses McUtils parser to pull cartesian coordinates
        :arg log_file: a Gaussian Frequency output file
        :returns coords: nx3 coordinate matrix"""
    with GaussianLogReader(log_file) as reader:
        parse = reader.parse("CartesianCoordinates")
    i, coords = parse["CartesianCoordinates"]
    # i is the atomic information for the coordinates, not needed in this implementation
    return coords[0]
Exemplo n.º 7
0
def get_dips(log_file):
    with GaussianLogReader(log_file) as reader:
        parse = reader.parse("OptimizedDipoleMoments")
    dips = parse["OptimizedDipoleMoments"]
    dips = np.array(list(dips))
    is_opt, struct = get_opt_struct(log_file)
    coord = struct.keys()
    dipz = OrderedDict(((c, d) for c, d in zip(coord, dips)))
    return is_opt, dipz
 def get_electronic_energyOH(self, shift=True, optimized=None, rawenergies=False, **params):
     """USE IF WE EVER NEED OH SCANS BACK
      Pulls Energies from the "Summary" portion of a log file. Shifts the potential energy to 0 to avoid
      problems with DVR later and extrapolates to a regular sized rudy grid to avoid problems with
      interpolation /sizing/ etc.
     :return: an array (col0: scancoord_1(ang), col1: scancoord_2(ang), col2: energy(shifted hartrees))
     :rtype: np.ndarray """
     from McUtils.Zachary.Interpolator import Interpolator
     ens = []
     if optimized is None:
         raise Exception("No energy type specified.")
     for log in self.logs:
         if optimized:
             with GaussianLogReader(log) as reader:
                 parse = reader.parse("OptimizedScanEnergies")
             energy_array, coords = parse["OptimizedScanEnergies"]
             roo = coords['Roo12']
             roh = coords['Roh']
             ens.append(np.column_stack((roo, roh, energy_array)))
         else:
             with GaussianLogReader(log) as reader:
                 parse = reader.parse("ScanEnergies")
             just_the_val = parse["ScanEnergies"]["values"][:, 1:]  # returns only the MP2 energy
             just_the_val = np.concatenate((just_the_val[:, :2], just_the_val[:, [-1]]), axis=1)
             ens.append(just_the_val)
         energy = np.concatenate(ens)
         energy[:, 0] *= 2
         idx = np.lexsort((energy[:, 1], energy[:, 0]))
         energyF = energy[idx]
         row_mask = np.append([True], np.any(np.diff(energyF, axis=0), 1))
         out = energyF[row_mask]
     if shift:
         out[:, 2:] -= min(out[:, 2:])  # shift gaussian numbers to zero HERE to avoid headaches later.
     else:
         pass
     if rawenergies:
         energyArray = out
     else:
         sq_grid, sq_vals = Interpolator(out[:, :2], out[:, 2], interpolation_function=lambda: "ignore").\
             regular_grid(interp_kind='cubic', fillvalues=True)
         energyArray = np.column_stack((sq_grid, sq_vals))
     return energyArray
Exemplo n.º 9
0
def get_opt_dips(log_file, mass):
    with GaussianLogReader(log_file) as reader:
        parse = reader.parse("OptimizedDipoleMoments")
    dips = parse["OptimizedDipoleMoments"]
    dips = np.array(list(dips))
    is_opt, struct = get_opt_struct(log_file)
    zmcs = np.array(list(struct.values()))
    coord = struct.keys()

    # shift dipole to COM DONT SHIFT FOR ECKART ROTATION
    com = np.dot(mass, zmcs) / np.sum(mass)
    dipshift = dips - com

    dipz = OrderedDict(((c, d) for c, d in zip(coord, dips)))
    return is_opt, dipz
 def minimum_pot(self):
     """Pulls the Scan Energies of a 1D Scan and shifts so that minimum is 0. So far hard coded to "Roo12" and "Roh"
     :return: array (col0: scancoord_1, col1: scancoord_2, col1: energy)
     :rtype: np.ndarray
     """
     import os
     scan_dir = os.path.join(self.molecule.mol_dir, '1D Scans')
     onedeescan = os.path.join(scan_dir, ("1D_%s_ooscan.log" % self.method))
     with GaussianLogReader(onedeescan) as reader:
         parse = reader.parse("OptimizedScanEnergies")
     energy_array, coords = (parse["OptimizedScanEnergies"])
     roo = coords['Roo12']*2
     roh = coords['Roh']
     ens = np.column_stack((roo, roh, energy_array))
     ens[:, 2:] -= min(ens[:, 2:])  # shift gaussian numbers to zero HERE to avoid headaches later.
     return ens[:18, :]
Exemplo n.º 11
0
def get_structs(log_file):
    """ pulls the structures from a 1D Gaussian scan
        :arg log_file: an output file from a gaussian scan
        :returns struct: structure of Z-matrix values keyed by the oo distances."""
    with GaussianLogReader(log_file) as reader:
        parse = reader.parse("ZMatrices")
    zmcs = parse["ZMatrices"]
    refs = zmcs[1]
    vals = zmcs[2]
    oops = vals[:, 0]
    oodists = oops[:, 0] * 2
    oodists = np.around(oodists, 4)

    things = zip(oodists, vals)
    struct = OrderedDict(((oo, zm) for oo, zm in things))

    return refs, struct
    def get_zmats(self, zmat_coord=None):
        """ pulls the Z-Matrices from a 1D Gaussian scan
        :param zmat_coord: x-coordinate of the scan
        :type zmat_coord: tuple
        :return: Z-matrix values keyed by the coordinate distances.
        :rtype: OrderedDict
        """
        from collections import OrderedDict
        struct = OrderedDict()
        for log in self.logs:
            with GaussianLogReader(log) as reader:
                parse = reader.parse("ZMatrices")
            zmcs = parse["ZMatrices"]
            atom_num = zmcs[1]
            vals = zmcs[2]
            xps = vals[:, 0, zmat_coord]
            xdists = np.around(xps, 4)

            things = zip(xdists, vals)
            struct.update(((oo, zm) for oo, zm in things))
        return atom_num, struct
 def get_dips(self, optimized=False, **params):
     """Pulls the dipoles from a list of Gaussian log files
     :param optimized: if True, the list of log files are optimization scans
     :type optimized: bool
     :return: Dipole values keyed by the coordinate distances.
     :rtype: OrderedDict
     """
     from collections import OrderedDict
     struct = OrderedDict()
     for log in self.logs:
         with GaussianLogReader(log) as reader:
             parse = reader.parse(("OptimizedDipoleMoments", "DipoleMoments"))
         if optimized:
             dips = parse["OptimizedDipoleMoments"]
             dips = np.array(list(dips))
             Findips = dips / 0.393456  # convert dipoles from au to debye IMMEDIATELY!
         else:
             dips = parse["DipoleMoments"]
             Findips = np.array(list(dips))
         coord = LogInterpreter(log, moleculeObj=self.molecule).cartesians.keys()
         struct.update(((c, d) for c, d in zip(coord, Findips)))
     return struct