示例#1
0
def read_orca(orca_out):
    xcc, lzmat, atonums, ch, mtp, E, calclevel = read_orcaout(orca_out)
    # Looking for files with gcc and Fcc
    orca_engrad = ".".join(orca_out.split(".")[:-1]) + ".engrad"
    orca_hess = ".".join(orca_out.split(".")[:-1]) + ".hess"
    # Read them
    gcc = read_orcaengrad(orca_engrad)[0]
    Fcc = read_orcahess(orca_hess)
    # Get masses
    masses = atonums2masses(atonums)
    # return data
    return xcc, atonums, ch, mtp, E, gcc, Fcc, masses, calclevel
示例#2
0
def read_gtsfile(gtsfile):
    lines = read_file(gtsfile)
    # check extension
    end_gts = (gtsfile.lower()).endswith(".gts")
    if (not end_gts): raise Exc.FileType(Exception)
    # CHECK FILE IS GTS
    correct = False
    for line in lines:
        if line.startswith("start_cc"):
            correct = True
            break
    if not correct:
        exception = Exc.FileIsNotGTS(Exception)
        exception._var = gtsfile
        raise exception
    # Read cartesian coordinates
    info_cc = fncs.extract_lines(lines, "start_cc", "end_cc")
    xcc, atonums = [], []
    for line in info_cc:
        atonum, xx, yy, zz = line.split()
        xcc += [float(xx), float(yy), float(zz)]
        atonums.append(int(atonum))
    # Read basic information
    info_basic = fncs.extract_lines(lines, "start_basic", "end_basic")
    ch, mtp, E, pgroup, rotsigma = None, None, None, None, None
    for line in info_basic:
        if line.startswith("pointgroup"): pgroup = line.split()[1]
        if line.startswith("charge"): ch = int(line.split()[1])
        if line.startswith("multiplicity"): mtp = int(line.split()[1])
        if line.startswith("rotsigma"): rotsigma = int(line.split()[1])
        if line.startswith("energy"): E = float(line.split()[1])
    # Read cartesian gradient
    info_grad = fncs.extract_lines(lines, "start_grad", "end_grad")
    gcc = []
    for line in info_grad:
        gx, gy, gz = line.split()
        gcc += [float(gx), float(gy), float(gz)]
    # Read Hessian matrix
    info_hess = fncs.extract_lines(lines, "start_hess", "end_hess")
    Fcc = []
    for line in info_hess:
        Fcc += [float(Fij) for Fij in line.split()]
    # Read frequencies (only special cases)
    info_freqs = fncs.extract_lines(lines, "start_freqs", "end_freqs")
    freq_list = []
    for line in info_freqs:
        freq_list += [float(freqs) * CM2H for freqs in line.split()]
    # Return data
    masses = fncs.atonums2masses(atonums)
    return xcc, atonums, ch, mtp, E, gcc, Fcc, masses, pgroup, rotsigma, freq_list
示例#3
0
def read_gauout(filename):
    # read gaussian file
    data_gaulog = read_gaussian_log(filename)
    # split data
    ch = data_gaulog[2]
    mtp = data_gaulog[3]
    symbols = data_gaulog[4]
    xcc = data_gaulog[5]
    gcc = data_gaulog[6]
    Fcc = data_gaulog[7]
    V0 = data_gaulog[8]
    level = data_gaulog[11]
    # symbols to atomic numbers
    atonums = symbols2atonums(symbols)
    # atomic mass
    atomasses = atonums2masses(atonums)
    # return data
    return xcc, atonums, ch, mtp, V0, gcc, Fcc, atomasses, level
示例#4
0
 def prepare(self):
     # check atnums
     if self._atnums is not None and type(self._atnums[0]) == str:
        self._symbols = list(self._atnums)
     # check symbols
     if self._symbols is not None and type(self._symbols[0]) == int:
        self._atnums  = list(self._symbols)
     # Get both atnums and symbols if None
     if self._atnums  is None: self._atnums  = fncs.symbols2atonums(self._symbols)
     if self._symbols is None: self._symbols = fncs.atonums2symbols(self._atnums)
     # check masses
     if self._masses is None:
        self._masses = fncs.atonums2masses(self._atnums)
     # derivated magnitudes
     self.genderivates()
     # check Fcc
     if self._Fcc not in (None,[]) and len(self._Fcc) != 3*self._natoms:
        self._Fcc = fncs.lowt2matrix(self._Fcc)
示例#5
0
def read_gauout_old(gauout):
    '''
    Read Gaussian output (data in final message)
    and return important data
    '''
    # check extension
    end_out = (gauout.lower()).endswith(".out")
    end_log = (gauout.lower()).endswith(".log")
    if (not end_out) and (not end_log):
        raise Exc.FileType(Exception)
    # read lines
    lines = read_file(gauout)
    # CHECK FILE IS GAUSSIAN OUT
    correct = False
    for line in lines:
        if "Entering Gaussian System" in line:
           correct = True
           break
    if not correct: raise Exc.FileType(Exception)
    # ONIOM energy?
    try:
       E_ONIOM = None
       for line in lines[::-1]:
           if "ONIOM: extrapolated energy" in line:
               E_ONIOM = float(line.split()[-1])
               break
    except: E_ONIOM = None
    # Get Forces if exists
    key1 = "Forces (Hartrees/Bohr)"
    key2 = "Cartesian Forces:"
    try:
       gcc = []
       for line in extract_string(lines,key1,key2).split("\n")[3:-3]:
           dummy, dummy, gx, gy, gz = line.split()
           gcc += [float(gx),float(gy),float(gz)]
       # forces to gradient
       gcc = [-g_i for g_i in gcc]
    except: gcc = None
    if gcc == []: gcc = None
    # Read string from gaussian output
    DATA_LAST = []
    DATA_WFCC = []
    key1, key2 = "\GINC-","@"
    strings = extract_string(lines,key1,key2,accumulate=True)
    for string in strings:
        lines = "".join([line.strip() for line in string.split()])
        lines = lines.split("\\\\")
        if lines == [""]: return None, None, None, None, None, None

        # lines[3]: ch, mtp, symbols, xcc
        str_geom = lines[3].split("\\")
        ch , mtp = str_geom[0].split(",")
        xcc      = []
        symbols  = []
        ch  = int(ch)
        mtp = int(mtp)
        E   = None
        masses = []
        for line in str_geom[1:]:
            coords = line.split(",")
            if   len(coords) == 4:
               symbol, x, y, z = line.split(",")
            else:
               symbol, tmp, x, y, z = line.split(",")
            xcc += [float(x),float(y),float(z)]
            symbols.append(symbol)
        xcc = [xi/ANGSTROM for xi in xcc] # in bohr
        # lines[4]: energy
        E = float(lines[4].split("HF=")[1].split("\\")[0])
        # Gradient
        if gcc is None or len(gcc) == 0: gcc = [0.0 for x in xcc]
        # Hessian
        Fcc = []
        for idx in range(len(lines)):
            line = lines[idx]
            if "NImag" not in line: continue
            Fcc = [float(fij) for fij in lines[idx+1].split(",")]
        # other lists
        atonums = get_atonums(symbols)
        masses  = atonums2masses(atonums)
        calclevel = ""
        # Does it have hessian?
        if Fcc != []: DATA_WFCC = [xcc, atonums, ch, mtp, E, gcc, Fcc, masses, calclevel]
        # Save data
        DATA_LAST = [xcc, atonums, ch, mtp, E, gcc, Fcc, masses, calclevel]
    # Use ONIOM extrapolated energy if found!
    if E_ONIOM is not None:
       if len(DATA_WFCC) != 0: DATA_WFCC[4] = E_ONIOM
       if len(DATA_LAST) != 0: DATA_LAST[4] = E_ONIOM
    # return
    if DATA_WFCC != []: return DATA_WFCC
    else              : return DATA_LAST
示例#6
0
def read_gauout(filename):

    # check extension
    end_out = (filename.lower()).endswith(".out")
    end_log = (filename.lower()).endswith(".log")
    if (not end_out) and (not end_log):
        raise Exc.FileType(Exception)

    key = 'GINC'
    fin = '@'
    str_end = 'Normal termination'
    str_atoms = 'NAtoms'
    str_geom1a = 'Z-Matrix orientation'
    str_geom1b = 'Input orientation'
    str_geom2 = 'Standard orientation'
    str_nosym = 'Nosym'
    str_zmat = 'Final structure in terms of initial Z-matrix'
    start_archives = []
    end_archives = []
    str_endfiles = []
    latom = []
    idx_last_zmat = -1
    list_zmat_backup = []

    # More then one archive file for instance Link1
    filex = open(filename, 'r')
    nlin = 0
    for linea in filex:
        nlin += 1
        if str_end in linea: str_endfiles.append(nlin)
        if key in linea: start_archives.append(nlin)
        if fin in linea: end_archives.append(nlin)
        if str_atoms in linea:
            latom = linea.split()
    filex.close()
    # It does not consider an archive file right after the main archive file
    # For some reason gaussian sometimes print one archive after the other
    str_tmp = str_endfiles[:]
    num_tmp = len(str_tmp)
    if num_tmp > 1:
        for i in range(num_tmp - 1, 0, -1):
            if abs(str_tmp[i - 1] - str_tmp[i]) < 300:
                del str_endfiles[i]
                del start_archives[i]
                del end_archives[i]
    #
    #
    number_archives = len(start_archives)
    if number_archives == 0: return -1
    str_beginfiles = str_endfiles[:]
    str_beginfiles.insert(0, 0)
    str_beginfiles.pop()

    natoms = int(latom[1])
    if number_archives == 1 and start_archives[0] == 0: return

    str_geom1s = []
    str_geom2s = []
    str_nosyms = []
    str_zmats = []
    for i in range(number_archives):
        str_geom1s.append(0)
        str_geom2s.append(0)
        str_nosyms.append(0)
        str_zmats.append(0)
        start_archive = start_archives[i]
        end_archive = end_archives[i]
        pos_beginfile = str_beginfiles[i]
        pos_endfile = str_endfiles[i]
        filex = open(filename, 'r')
        nlin = 0
        for linea in filex:
            nlin += 1
            if nlin >= pos_beginfile and nlin <= pos_endfile:
                if str_nosym.lower() in linea.lower(): str_nosyms[i] = nlin
                if str_geom1a in linea or str_geom1b in linea:
                    str_geom1s[i] = nlin
                if str_geom2 in linea: str_geom2s[i] = nlin
                if str_zmat in linea: str_zmats[i] = nlin
        filex.close()

        # position of the geometries
        pos_nosym = str_nosyms[i]
        pos_geom1 = str_geom1s[i]
        pos_geom2 = str_geom2s[i]
        pos_zmat1 = str_zmats[i]
        num_imag,charge,mult,commands,list_level,list_energy,atomic_number,ccgeom,list_zmat,\
            hess_data,hess_full,grad=\
            archive(filename,natoms,start_archive,end_archive,\
            pos_beginfile,pos_endfile,pos_nosym,pos_geom1,pos_geom2,pos_zmat1)

        # Saves the last available z-matrix
        if str_zmats[i] != 0:
            idx_last_zmat = i
            list_zmat_backup = list_zmat[:]

    # atomic mass
    atomic_mass = atonums2masses(atomic_number)

    ccgeom = flatten_llist(ccgeom)

    energy = list_energy[-1]
    level = list_level[-1]
    # from Angstrom to Bohr
    ccgeom = [xx / ANGSTROM for xx in ccgeom]

    return ccgeom, atomic_number, charge, mult, energy, grad, hess_data, atomic_mass, level