예제 #1
0
파일: files.py 프로젝트: catenate15/Pilgrim
def read_orcaout(orca_out):
    # Read lines
    lines = read_file(orca_out)
    # CHECK FILE IS ORCA OUT
    correct = False
    for line in lines:
        if "This ORCA versions uses" in line:
            correct = True
            break
    if not correct: raise Exc.FileType(Exception)
    # Initialize
    ch, mtp, E = None, None, None
    xcc, symbols, atonums = [], [], []
    # basis set
    basisset = ""
    try:
        for line in lines:
            if "utilizes the basis" in line:
                basisset = line.split(":")[1]
                break
    except:
        pass
    # hamiltonian
    hamiltonian = ""
    try:
        for idx, line in enumerate(lines):
            if "Hamiltonian:" in line:
                hamiltonian = lines[idx + 1].split()[-1]
                break
    except:
        pass
    # level of calculation
    calclevel = hamiltonian + " " + basisset
    # Get ch, mtp, E
    pos = None
    for idx in range(len(lines)):
        line = lines[idx]
        if "Total Charge           Charge" in line: ch = int(line.split()[-1])
        if "Multiplicity           Mult" in line: mtp = int(line.split()[-1])
        if "FINAL SINGLE POINT ENERGY " in line: E = float(line.split()[-1])
        if "CARTESIAN COORDINATES (A.U.)" in line: pos = idx
    # Get xcc, symbols, atonums
    if pos is None:
        sys.exit(
            "Unable to find 'CARTESIAN COORDINATES (A.U.)' label in file!")
    pos = pos + 3
    for line in lines[pos:]:
        line = line.strip()
        if line == "": break
        idx, symbol, atonum, dummy, mass, x, y, z = line.split()
        xcc = xcc + [float(x), float(y), float(z)]
        symbols.append(symbol)
        atonums.append(int(atonum.split(".")[0]))
    # Return
    return xcc, atonums, ch, mtp, E, calclevel.strip()
예제 #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_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
예제 #4
0
def read_fchk(fchkfile):
    #------------------------#
    # The labels to look for #
    #------------------------#
    labels     = {}                              ; found_dict    = {}
    labels[0]  = "Number of atoms"               ; found_dict[0] = False
    labels[1]  = "Charge"                        ; found_dict[1] = False
    labels[2]  = "Multiplicity"                  ; found_dict[2] = False
    labels[3]  = "Total Energy"                  ; found_dict[3] = False
    labels[4]  = "Atomic numbers"                ; found_dict[4] = False
    labels[5]  = "Current cartesian coordinates" ; found_dict[5] = False
    labels[6]  = "Real atomic weights"           ; found_dict[6] = False
    labels[7]  = "Cartesian Gradient"            ; found_dict[7] = False
    labels[8]  = "Cartesian Force Constants"     ; found_dict[8] = False
    # mandatory labels in fchk
    idx_basic_labels = [0,1,2,3,4,5,6]
    # initialization
    natoms   = None ; ch     = None ; mtp  = None  ; E = None
    atonums  = []   ; masses = []
    xcc      = []   ; gcc    = []   ; Fcc  = []
    # read file
    lines = read_file(fchkfile)
    # check extension
    end_fchk = (fchkfile.lower()).endswith(".fchk")
    if (not end_fchk): raise Exc.FileType(Exception)
    # CHECK FILE IS FCHK
    correct = False
    for line in lines:
        if line.startswith("Current cartesian coordinates  "):
           correct = True
           break
    if not correct: raise Exc.FileType(Exception)
    # Get level of calculation
    calclevel = " ".join(lines[1].split()[1:])
    # get data from lines
    for idx in range(len(lines)):
        line = lines[idx]
        # Number of atoms
        if line.startswith(labels[0]):
            found_dict[0] = True
            natoms = int(line.split()[-1])
        # Charge
        elif line.startswith(labels[1]):
            found_dict[1] = True
            ch = int(line.split()[-1])
        # Spin multiplicity
        elif line.startswith(labels[2]):
            found_dict[2] = True
            mtp = int(line.split()[-1])
        # Total Energy
        elif line.startswith(labels[3]):
            found_dict[3] = True
            E = float(line.split()[-1])
        # Atomic Numbers
        elif line.startswith(labels[4]):
            found_dict[4] = True
            length = int(line.split()[-1])
            idx2   = idx+1
            while len(atonums) != length:
                  nextline = lines[idx2]
                  atonums += [int(i) for i in nextline.split()]
                  idx2    += 1
        # Cartesian Coordinates
        elif line.startswith(labels[5]):
            found_dict[5] = True
            length = int(line.split()[-1])
            idx2   = idx+1
            while len(xcc) != length:
                  nextline = lines[idx2]
                  xcc     += [float(i) for i in nextline.split()]
                  idx2    += 1
        # List of atomic masses
        elif line.startswith(labels[6]):
            found_dict[6] = True
            length = int(line.split()[-1])
            idx2   = idx+1
            while len(masses) != length:
                  nextline = lines[idx2]
                  masses  += [float(i) for i in nextline.split()]
                  idx2    += 1
        # Cartesian Gradient
        elif line.startswith(labels[7]) and natoms != 1:
            found_dict[7] = True
            length = int(line.split()[-1])
            idx2   = idx+1
            while len(gcc) != length:
                  nextline = lines[idx2]
                  gcc     += [float(i) for i in nextline.split()]
                  idx2    += 1
        # Cartesian Force Constant Matrix
        elif line.startswith(labels[8]) and natoms != 1:
            found_dict[8] = True
            length = int(line.split()[-1])
            idx2   = idx+1
            while len(Fcc) != length:
                  nextline = lines[idx2]
                  Fcc     += [float(fij) for fij in nextline.split()]
                  idx2    += 1
    # Return data
    #if gcc == []: gcc = None
    #if Fcc == []: Fcc = None
    return xcc,atonums,ch,mtp,E,gcc,Fcc,masses, calclevel.strip()
예제 #5
0
def read_orcaout(orca_out):
    # Read lines
    lines = read_file(orca_out)
    # CHECK FILE IS ORCA OUT
    correct = False
    for line in lines:
        if "This ORCA versions uses" in line:
            correct = True
            break
    if not correct: raise Exc.FileType(Exception)
    # Initialize
    ch, mtp, E = None, None, None
    xcc, symbols, atonums = [], [], []
    # basis set
    basisset = ""
    try:
        for line in lines:
            if "utilizes the basis" in line:
                basisset = line.split(":")[1]
                break
    except:
        pass
    # hamiltonian
    hamiltonian = ""
    try:
        for idx, line in enumerate(lines):
            if "Hamiltonian:" in line:
                hamiltonian = lines[idx + 1].split()[-1]
                break
    except:
        pass
    # level of calculation
    calclevel = hamiltonian + " " + basisset
    # Get ch, mtp, E
    pos_cart = None
    pos_zmat = None
    for idx in range(len(lines)):
        line = lines[idx]
        if "Total Charge           Charge" in line: ch = int(line.split()[-1])
        if "Multiplicity           Mult" in line: mtp = int(line.split()[-1])
        if "FINAL SINGLE POINT ENERGY " in line: E = float(line.split()[-1])
        if "CARTESIAN COORDINATES (A.U.)" in line: pos_cart = idx
        if "INTERNAL COORDINATES (ANGST" in line: pos_zmat = idx
    # Get xcc, symbols, atonums
    if pos_cart is None:
        sys.exit(
            "Unable to find 'CARTESIAN COORDINATES (A.U.)' label in file!")
    pos_cart += 3
    for line in lines[pos_cart:]:
        line = line.strip()
        if line == "": break
        idx, symbol, atonum, dummy, mass, x, y, z = line.split()
        if symbol == "-": symbol = "XX"
        xcc += [float(x), float(y), float(z)]
        symbols.append(symbol)
        atonums.append(int(atonum.split(".")[0]))
    # data in internal coordinates
    lzmat = None
    if pos_zmat is not None:
        pos_zmat += 2
        lzmat = []
        for idx, line in enumerate(lines[pos_zmat:]):
            line = line.strip()
            if line == "": break
            symbol, atk, atj, ati, dist, angle, dihedral = line.split()
            if symbol == "-": symbol = "XX"
            atk, atj, ati = int(atk) - 1, int(atj) - 1, int(ati) - 1
            dist, angle, dihedral = float(dist), float(angle), float(dihedral)
            if idx == 0: connections, values = (), ()
            elif idx == 1: connections, values = (atk, ), (dist, )
            elif idx == 2: connections, values = (atk, atj), (dist, angle)
            else:
                connections, values = (atk, atj, ati), (dist, angle, dihedral)
            data = (symbol, connections, values)
            lzmat += [data]
    # Return
    return xcc, lzmat, atonums, ch, mtp, E, calclevel.strip()