示例#1
0
def generate_gts_file(esfile, gtsfile, read_method):
    '''
    Generate gts file (and molden & frozen files)
    from given electronic structure (ES) file;
    The ES file is read using read_method
    '''
    # Extra files that (maybe) will be generated
    file_frozen = gtsfile + ".frozen"  # only if any frozen atom
    file_molden = gtsfile + ".molden"  # molden file
    # read file
    xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = read_method(
        PN.UFOLDER + esfile)[0:9]
    # clevel is not really clevel when using read_gtsfile as read_method
    if read_method == read_gtsfile: clevel = ""
    # symbols and atonums
    symbols, atonums = fncs.symbols_and_atonums(atonums)
    # is masses available?
    if masses is None or len(masses) == 0 or sum(masses) == 0.0:
        masses = atonums2masses(atonums)
    # is Fcc available?
    if len(atonums) != 1 and (Fcc is None or len(Fcc) == 0):
        status = -1
        cache = None
        molec = None
    else:
        # Generate Molecule instance
        molec = Molecule()
        molec.setvar(xcc=xcc, gcc=gcc, Fcc=Fcc)
        molec.setvar(atonums=atonums, masses=masses)
        molec.setvar(ch=ch, mtp=mtp, V0=E)
        molec.prepare()
        # Deal with frozen atoms [atom i is frozen if Fij=0 forall j)
        frozen_xcc, frozen_symbols = molec.remove_frozen()
        # Calculate point group (must be done after remove frozen)
        molec.calc_pgroup(force=True)
        # Deal with Hessian
        molec.setup()
        # write gts file
        molec.genfile_gts(PN.DIR1 + gtsfile, level=clevel)
        status = 1
        # write frozen (if there are frozen atoms)
        RW.write_frozen(PN.DIR1 + file_frozen, frozen_xcc, frozen_symbols)
        # write molden file
        idata = (PN.DIR1 + file_molden, molec._xcc, molec._symbols,
                 molec._ccfreqs, molec._ccFevecs)
        write_molden(*idata)
        # save to cache
        nimag = int(fncs.numimag(molec._ccfreqs))
        pgroup = str(molec._pgroup)
        mform = str(molec._mform)
        cache = [esfile, gtsfile, E, ch, mtp, nimag, mform, pgroup]
    # delete variable, just in case
    del xcc, gcc, Fcc
    del symbols, atonums, masses
    del molec
    # return
    return status, cache
示例#2
0
def userfile_to_gtsfile(filename, gtsfile):
    '''
    Read a file given by the user and generate gts file
    if possible
    '''
    gtsfile = gtsname(gtsfile, "full")
    read_methods = []
    read_methods.append(read_gtsfile)  #(a) a gts file
    read_methods.append(read_fchk)  #(b) a fchk file
    read_methods.append(read_gauout_v1)  #(c.1) a Gaussian output file (ramos)
    read_methods.append(read_gauout_v2)  #(c.2) a Gaussian output file (ferro)
    read_methods.append(read_orca)  #(d) an Orca output file
    for read_method in read_methods:
        try:
            xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = read_method(
                filename)[0:9]
            if read_method == read_gtsfile: clevel = ""
            # in case no data in masses
            if masses is None or len(masses) == 0 or sum(masses) == 0.0:
                masses = atonums2masses(atonums)
            # Some checking
            if len(atonums) != 1 and Fcc in ([], None):
                #raise Exc.FccNotFound
                return -1, None
            # Generate Molecule instance
            molecule = Molecule()
            molecule.setvar(xcc=xcc, gcc=gcc, Fcc=Fcc)
            molecule.setvar(atonums=atonums, masses=masses)
            molecule.setvar(ch=ch, mtp=mtp, V0=E)
            molecule.prepare()
            # Deal with frozen atoms
            ffrozen = gtsfile + ".frozen"
            frozen_xcc, frozen_symbols = molecule.remove_frozen()
            RW.write_frozen(ffrozen, frozen_xcc, frozen_symbols)
            # write gts
            molecule.calc_pgroup(force=True)
            molecule.genfile_gts(gtsfile, level=clevel)
            return 1, E
        except Exc.FileType:
            continue
        except:
            continue
    return 0, None