Ejemplo n.º 1
0
def main():
    # Get user input.
    args = parse_user_input()
    # Start timer.
    click()
    # Run Q-Chem geometry optimization.
    M = QCOptIC(args.initial, args.charge, args.mult, args.method, args.basis, cycles=args.cycles)
    # Select frames where the energy is monotonically decreasing.
    M = M[monotonic_decreasing(M.qm_energies)]
    # Write optimization results to file.
    M.write('optimize.xyz')
    # Write Mulliken charge and spin populations to file.
    QS = M.get_populations()
    QS.write('optimize.pop', ftype='xyz')
    # Archive and exit.
    tarexit()
Ejemplo n.º 2
0
def main():
    # Get user input.
    args = parse_user_input()
    # Start timer.
    click()

    subxyz = []
    subna = []
    subchg = []
    submult = []
    subvalid = []
    subefstart = []
    subeffinal = []
    SumFrags = []
    fragfiles = []

    # Pick out the files in the tarfile that have the structure "example*.sub_*.xyz"
    idhome = os.path.abspath('..')
    tar = tarfile.open(os.path.join(idhome, 'fragmentid.tar.bz2'), 'r')
    for tarinfo in tar:
        splitlist = tarinfo.name.split(".")
        if len(splitlist) > 2:
            if splitlist[2] == "xyz":
                subxyz.append(tarinfo.name)
                fragfiles.append(tarinfo)
    # Extract these files from the tarfile
    tar.extractall(members=fragfiles)
    tar.close()

    # Load files as molecules
    for frag in subxyz:
        M = Molecule(frag)
        M.read_comm_charge_mult()
        subchg.append(M.charge)
        submult.append(M.mult)
        subna.append(M.na)
        efstart = re.search('(?<=Molecular formula )\w+', M.comms[0]).group(0)
        subefstart.append(efstart)

    print("Running individual optimizations.")
    # Run individual geometry optimizations.
    FragE = 0.0
    FragZPE = 0.0
    FragEntr = 0.0
    FragEnth = 0.0
    for i in range(len(subxyz)):
        if subna[i] > 1:
            M = QCOptIC(subxyz[i],
                        subchg[i],
                        submult[i],
                        args.method,
                        args.basis,
                        cycles=args.cycles,
                        qcin='%s.opt.in' % os.path.splitext(subxyz[i])[0])
            # Select frames where the energy is monotonically decreasing.
            M = M[monotonic_decreasing(M.qm_energies)]
        else:
            # Special case of a single atom
            QCSP = QChem(subxyz[i],
                         charge=subchg[i],
                         mult=submult[i],
                         method=args.method,
                         basis=args.basis,
                         qcin='%s.sp.in' % os.path.splitext(subxyz[i])[0])
            QCSP.make_stable()
            QCSP.jobtype = 'sp'
            QCSP.calculate()
            M = QCSP.load_qcout()
        # Write optimization final result to file.
        M = M[-1]
        fragoptfile = os.path.splitext(subxyz[i])[0] + ".opt.xyz"
        M.write(fragoptfile)
        QCFR = QChem(fragoptfile,
                     charge=subchg[i],
                     mult=submult[i],
                     method=args.method,
                     basis=args.basis,
                     qcin='%s.freq.in' % os.path.splitext(fragoptfile)[0])
        QCFR.freq()
        M = QCFR.load_qcout()
        # Print out new molecular formulas.
        # This time we should be able to use covalent radii.
        M.build_topology(force_bonds=True)
        optformula = ' '.join([m.ef() for m in M.molecules])
        subeffinal.append(optformula)
        print(("%s.opt.xyz : formula %s; charge %i; mult %i; energy %f Ha;"
               "ZPE %f kcal/mol; entropy %f cal/mol.K; enthalpy %f kcal/mol" %
               (os.path.splitext(subxyz[i])[0], optformula, subchg[i],
                submult[i], M.qm_energies[0], M.qm_zpe[0], M.qm_entropy[0],
                M.qm_enthalpy[0])))
        FragE += M.qm_energies[0]
        FragZPE += M.qm_zpe[0]
        FragEntr += M.qm_entropy[0]
        FragEnth += M.qm_enthalpy[0]
        SumFrags.append(M[0])
    for fragment in SumFrags:
        fragment.write('fragmentopt.xyz', append=True)
    if subefstart != subeffinal:
        print("Fragments changed during optimization, calculation invalid")
    print("Final electronic energy (Ha) of optimized frags: % 18.10f" % FragE)
    print("Final ZPE (kcal/mol) of optimized frags: % 18.10f" % FragZPE)
    print("Final entropy (cal/mol.K) of optimized frags: % 18.10f" % FragEntr)
    print("Final enthalpy (kcal/mol) of optimized frags: % 18.10f" % FragEnth)
    nrg = open('fragmentopt.nrg', 'w')
    for subef in subeffinal:
        nrg.write(subef + " ")
    nrg.write("\nTotal electronic energy: %f Ha\n" % FragE)
    nrg.write("Total ZPE: %f kcal/mol\n" % FragZPE)
    nrg.write("Total entropy (STP): %f cal/mol.K\n" % FragEntr)
    nrg.write("Total enthalpy (STP): %f kcal/mol\n" % FragEnth)
    if subefstart != subeffinal: nrg.write("invalid")
    nrg.close()
    # Archive and exit.
    tarexit()
Ejemplo n.º 3
0
    M = M[::-1]
    iTS = len(M) - iTS

# Energies in kcal/mol.
E = M.qm_energies
E -= E[0]
E *= 627.51

# Write IRC energies to comments.
M.comms = [
    "Intrinsic Reaction Coordinate: Energy = % .4f kcal/mol" % i for i in E
]
M.comms[iTS] += " (Transition State)"

# Eliminate geometry optimization frames that go up in energy.
selct = np.concatenate((monotonic_decreasing(E, iTS, 0, verbose=True)[::-1],
                        monotonic_decreasing(E, iTS, len(M),
                                             verbose=True)[1:]))
M = M[selct]
E = E[selct]

# Save the IRC energy as a function of arc length.
ArcMol = arc(M, RMSD=True)
ArcMolCumul = np.insert(np.cumsum(ArcMol), 0, 0.0)
np.savetxt("irc.nrg",
           np.hstack((ArcMolCumul.reshape(-1, 1), E.reshape(-1, 1))),
           fmt="% 14.6f",
           header="Arclength(Ang) Energy(kcal/mol)")

MOld = Molecule("irc.xyz")
ArcOld = arc(MOld, RMSD=True)