Пример #1
0
def read(filename,silent=False):
    """
    This method reads Q-Chem input files, output files, and coordinate files (xyz,zmat,txyz). 
    """

    extension = (filename.split("."))[-1]

    # Do we have an inputfile?
    if  extension in ("inp","in","IN","INP","qcin","QCIN"):

        seperator = []
        with open(filename) as infile:
            for num, line in enumerate(infile):
                if "@@@"==line.strip() or "@@@@"==line.strip():
                    seperator.append(num)

        N_jobs = len(seperator)

        # Does the file contain multiple jobs? 
        if N_jobs>0:
            if not silent:
                print "Batch Jobfile detected."
            joblist = []
            infile = open(filename,"r")
            content = infile.readlines()
            seperator.insert(0,-1)
            seperator.append(len(content))
    
            # Create batch jobfile object
            re_file = multifile()
    
            # Populate it with jobs
            for k in range(N_jobs+1):
                start=seperator[k]+1
                end=seperator[k+1]
                dummylines = content[start:end]
                dummy = _readinput(dummylines,silent)
                re_file.add(dummy)
            return re_file
    
        # No, it's a single job file    
        else:
            if not silent:
                print "Jobfile detected."
            return _readinput(filename,silent)
        
    # Is it a z-matrix file?
    elif extension in ("zmat","ZMAT","Z","z"):
        if not silent:
            print "Z-matrix file detected."
        return _readzmat(filename)
          
    # Is it a cartesian coordinates file?
    elif extension in ("xyz","XYZ"):
        if not silent:
            print "Cartesian coordinates file detected."
        return _readcartesian(filename)
        
    # Is it a tinker coordinates file?
    elif extension in ("txyz","TXYZ"):
        if not silent:
            print "Tinker coordinates file detected."
        return _readtinker(filename)
    

    # Do we have a Q-Chem outputfile?
    if extension.lower() in ("out", "qcout", "qchem"):

        seperator = []
        with open(filename) as infile:
            for num, line in enumerate(infile):
                if "Welcome to Q-Chem" in line:
                    seperator.append(num)

        N_jobs = len(seperator)

        # Does the file contain multiple jobs? 
        if N_jobs>1:
            if not silent:
                print "Batch-Outputfile detected."
            joblist = []
            infile = open(filename,"r")
            content = infile.readlines()
            #seperator.insert(0,-1)
            seperator.append(len(content))
    
            # Create batch jobfile object
            re_file = _multioutput()
    
            # Populate it with jobs
            for k in range(N_jobs):
                start=seperator[k]+1
                end=seperator[k+1]
                dummylines = content[start:end]
                dummy = _outputfile(dummylines,silent)
                re_file.add(dummy)
            return re_file
    
        # No, it's a single job file    
        else:
            if not silent:
                print "Outputfile detected."
            return _outputfile(filename,silent)

    # What the heck? This is not a valid file.
    else:
        if not silent:
            print "Error: File type not recognized."
Пример #2
0
    def __init__(self, file_input, silent=False):

        #Check input type
        if type(file_input) == list:
            content = file_input
        else:
            infile = open(file_input, "r")
            content = infile.readlines()

        spin = '0'
        energy = 'undetermined'
        jobtype = 'undetermined'
        version = 'undetermined'
        basis_size = 'undetermined'
        status = 'unfinished'
        wall_time = -99
        cpu_time = -99

        # flag for detection of basis2 job
        basis2_flag = False

        mm_type = ""
        self.aifdem = 0
        self.N_Fragments = 1
        self.N_SET = 0

        switch = 0
        for line in content:
            if "JOBTYPE" in line:
                jobtype = ((line.split())[-1]).lower()
            if "jobtype" in line:
                jobtype = ((line.split())[-1]).lower()
            if "JOB_TYPE" in line:
                jobtype = ((line.split())[-1]).lower()
            if "basis2" in line.lower():
                basis2_flag = True
            if ("QM_MM_INTERFACE" in line) or ("qm_mm_interface" in line):
                mm_type = ((line.split())[-1]).lower()
            if ("AIFDEM" in line) or ("aifdem" in line):
                self.aifdem = ((line.split())[-1]).lower()
            if ("CIS_N_ROOTS" in line):
                self.N_SET = ((line.split())[-1]).lower()
            if "Q-Chem, Version" in line:
                version = (((line.split(","))[1]).split())[1]
            if "<S^2> =" in line:
                spin = (line.split())[2]
            if ("Total energy in the final basis set"
                ) in line and mm_type != "mm":
                energy = (line.split())[8]
            if ("Convergence criterion met") in line and basis2_flag:
                energy = (line.split())[1]
            if ("Etot:" in line) and (mm_type == "mm"):
                energy = (line.split())[4]
            if ("There are" in line) and ("shells" in line):
                basis_size = (line.split())[5]
            if ("Total job time:" in line):
                wall_time = float(line.split()[3].split("s")[0])
                cpu_time = float(line.split()[4].split("s")[0])
            if "MISSION" in line:
                status = 'finished'
            if "--fragment" in line:
                ifrgm = int((line.split())[-1])
                if ifrgm + 1 > self.N_Fragments:
                    self.N_Fragments = ifrgm + 1
            if "TIME STEPS COMPLETED" in line and jobtype == "aimd":
                status = 'time steps completed'
            # Create corresponding inputfile:
            if switch == 0 and "User input:" in line:
                switch = 1
                infile_content = []
            if switch == 1:
                infile_content.append(line)
            if switch == 1 and "Standard Nuclear Orientation" in line:
                switch = 2
                initial_cartesian = cartesian(
                    "sp job - initial geometry in standard orientation")
                continue
            if switch == 2 and ("Repulsion" in line or "Molecular" in line):
                switch = 3
            elif switch == 2 and "Atom" not in line and "---" not in line:
                dummy = (line.split())[1:]
                initial_cartesian.add_atom(dummy[0], dummy[1], dummy[2],
                                           dummy[3])

        inputfile = _readinput(infile_content, silent)

        # Creating geometry objects under 'general' for convenience, final geometry will be overwritten later if different

        # Final geometry is NOT read directly from inputfile, but from Q-Chem standard orientation output in order to
        # avoid issues with molecule 'read' in batch jobs

        initial_geometry = inputfile.molecule.geometry()
        final_geometry = initial_cartesian

        # The info object 'general' will be created after ALL OTHER objects are finished with parsing

        # Make another round if we have an MM or a QM/MM Janus job (just one MM per step)
        if mm_type == "mm" or mm_type == "janus":
            etot = []
            ecoulomb = []
            etorsion = []
            eimptors = []
            eureybrad = []
            eangle = []
            ebond = []
            evdw = []

            first_bond = 1
            for line in content:
                if ("MM bonds to file" in line) and (first_bond == 1):
                    nbonds = int((line.split())[1])
                    first_bond = 0
                if "Ebond:" in line:
                    ebond.append(float((line.split())[1]))
                if "Eangle:" in line:
                    eangle.append(float((line.split())[1]))
                if "EUreyBrad:" in line:
                    eureybrad.append(float((line.split())[1]))
                if "Eimptors:" in line:
                    eimptors.append(float((line.split())[1]))
                if "Etorsion:" in line:
                    etorsion.append(float((line.split())[1]))
                if "Evdw:" in line:
                    evdw.append(float((line.split())[1]))
                if "Ecoulomb:" in line:
                    ecoulomb.append(float((line.split())[1]))
                if "Etot:" in line:
                    etot.append(float((line.split())[1]))
            self.mm = _mm([
                etot, ecoulomb, evdw, etorsion, eimptors, eureybrad, eangle,
                ebond, nbonds
            ])  # Create MM info object

        # Make another round if we have an QM/MM ONIOM job (has two MM calulations per step)
        elif mm_type == "oniom":
            etot = []
            ecoulomb = []
            etorsion = []
            eimptors = []
            eureybrad = []
            eangle = []
            ebond = []
            evdw = []

            etot2 = []
            ecoulomb2 = []
            etorsion2 = []
            eimptors2 = []
            eureybrad2 = []
            eangle2 = []
            ebond2 = []
            evdw2 = []

            mm_step = 0

            first_bond = 1
            first_bond2 = 1

            for line in content:
                if "Step 1: MM calculation on the entire system" in line:
                    mm_step = 1
                if "Step 2: MM calculation on the model system" in line:
                    mm_step = 2

                if ("MM bonds to file" in line) and (first_bond
                                                     == 1) and (mm_step == 1):
                    nbonds = int((line.split())[1])
                    first_bond = 0
                if "Ebond:" in line and (mm_step == 1):
                    ebond.append(float((line.split())[1]))
                if "Eangle:" in line and (mm_step == 1):
                    eangle.append(float((line.split())[1]))
                if "EUreyBrad:" in line and (mm_step == 1):
                    eureybrad.append(float((line.split())[1]))
                if "Eimptors:" in line and (mm_step == 1):
                    eimptors.append(float((line.split())[1]))
                if "Etorsion:" in line and (mm_step == 1):
                    etorsion.append(float((line.split())[1]))
                if "Evdw:" in line and (mm_step == 1):
                    evdw.append(float((line.split())[1]))
                if "Ecoulomb:" in line and (mm_step == 1):
                    ecoulomb.append(float((line.split())[1]))
                if "Etot:" in line and (mm_step == 1):
                    etot.append(float((line.split())[1]))

                if ("n_qm_bonds =" in line) and (first_bond2 == 1) and (mm_step
                                                                        == 2):
                    nbonds2 = int((line.split())[2])
                    first_bond2 = 0
                if "Ebond:" in line and (mm_step == 2):
                    ebond2.append(float((line.split())[1]))
                if "Eangle:" in line and (mm_step == 2):
                    eangle2.append(float((line.split())[1]))
                if "EUreyBrad:" in line and (mm_step == 2):
                    eureybrad2.append(float((line.split())[1]))
                if "Eimptors:" in line and (mm_step == 2):
                    eimptors2.append(float((line.split())[1]))
                if "Etorsion:" in line and (mm_step == 2):
                    etorsion2.append(float((line.split())[1]))
                if "Evdw:" in line and (mm_step == 2):
                    evdw2.append(float((line.split())[1]))
                if "Ecoulomb:" in line and (mm_step == 2):
                    ecoulomb2.append(float((line.split())[1]))
                if "Etot:" in line and (mm_step == 2):
                    etot2.append(float((line.split())[1]))

            # Create MM info object for entire system
            self.mm_total = _mm([
                etot, ecoulomb, evdw, etorsion, eimptors, eureybrad, eangle,
                ebond, nbonds
            ])
            # Create MM info object for model system
            self.mm_model = _mm([
                etot2, ecoulomb2, evdw2, etorsion2, eimptors2, eureybrad2,
                eangle2, ebond2, nbonds2
            ])

        if jobtype == "sp":
            # Retrieve rem object from input file
            index = inputfile.list_of_content.index("rem")
            rem = inputfile.list_of_arrays[index]
            adc_variant = ''
            if "METHOD" in rem.dict_of_keywords:
                if "adc" in rem.dict_of_keywords["METHOD"]:
                    adc_variant = rem.dict_of_keywords["METHOD"]
            elif "ADC_ORDER" in rem.dict_of_keywords:
                adc_order = int(rem.dict_of_keywords["ADC_ORDER"])
                adc_ext = False
                if adc_order == 2 and "ADC_EXTENDED" in rem.dict_of_keywords:
                    if int(rem.dict_of_keywords["ADC_EXTENDED"] == 1):
                        adc_ext = True
                adc_variant = "adc(" + str(adc_order) + ")"
                if adc_ext:
                    adc_variant += "-x"

            if adc_variant:
                if "ADC_SOS" in rem.dict_of_keywords:
                    if int(rem.dict_of_keywords("ADC_SOS")) != 0:
                        if "adc(2)" in adc_variant and not "sos" in adc_variant:
                            adc_variant = "sos-" + adc_variant
                if "ADC_CVS" in rem.dict_of_keywords:
                    if int(rem.dict_of_keywords("ADC_CVS")) != 0:
                        if not "cvs" in adc_variant:
                            adc_variant = "cvs-" + adc_variant

                self.adc = _parse_adc(adc_variant, content, silent)

        if jobtype == "freq":
            H2kcal = constants.hartree_to_kcal_pro_mole
            E = float(energy)
            temp = []
            press = []
            R_T = []
            enth_corr = []
            entr_corr = []
            zero_point = []

            mass = []
            mom_inertia = []
            rot_sym = []

            switch = 0
            frequencies = []
            intensities = []

            loop = 0

            linear_switch = 0

            for line in content:
                if "STANDARD THERMODYNAMIC QUANTITIES AT" in line:
                    temp.append(float((line.split())[4]))
                    press.append(1.01325e5 * float((line.split())[7]))
                if "Zero point vibrational energy" in line:
                    zero_point.append(float((line.split())[4]) / H2kcal)
                if "gas constant (RT):" in line:
                    R_T.append(float((line.split())[3]) / H2kcal)
                if "Total Enthalpy:" in line:
                    enth_corr.append(float((line.split())[2]) / H2kcal)
                if "Total Entropy:" in line:
                    entr_corr.append(float((line.split())[2]) / 1000 / H2kcal)
                if "We detect a D*h symmetry" in line:
                    linear_switch = 1
                if "We detect a C*v symmetry" in line:
                    linear_switch = 1
                if "We detect a C*h symmetry" in line:  # necessary because of wrong nomenclature in Q-chem (thermodyn.F)
                    linear_switch = 1
                if "Molecular Mass:" in line:
                    loop += 1
                    if "*" in line:
                        if not silent:
                            print "Warning: Molecular mass in loop " + str(
                                loop
                            ) + " is unphysically large. Will use mass of first loop instead."
                        mass.append(mass[0])
                    else:
                        dummy = float((line.split())[2])
                        mass.append(dummy)
                if "Rotational Symmetry Number is" in line:
                    rot_sym.append(float((line.split())[4]))
                if "Eigenvalues --" in line:
                    if "*" in line:
                        if not silent:
                            print "Warning: Moment of inertia in loop " + str(
                                loop
                            ) + " is unphysically large. Will use values of first loop instead."
                        mom_inertia.append(mom_inertia[0])
                    else:
                        dummy = [
                            float((line.split())[2]),
                            float((line.split())[3]),
                            float((line.split())[4])
                        ]
                        mom_inertia.append(dummy)

                if "VIBRATIONAL ANALYSIS" in line:
                    loop1 = []
                    loop2 = []
                    switch = 1
                    infile_content = []
                if switch == 1:
                    if "Frequency:" in line:
                        dummy = line.split()
                        del dummy[0]
                        for k in dummy:
                            loop1.append(float(k))
                    if "IR Intens:" in line:
                        dummy = line.split()
                        del dummy[0]
                        del dummy[0]
                        for k in dummy:
                            loop2.append(float(k))
                if switch == 1 and "STANDARD THERMODYNAMIC" in line:
                    switch = 0
                    frequencies.append(loop1)
                    intensities.append(loop2)

            T = _np.asarray(temp)
            p = _np.asarray(press)
            ZPE = _np.asarray(zero_point)
            H = E + _np.asarray(enth_corr)
            S = _np.asarray(entr_corr)
            ITE = _np.asarray(
                enth_corr
            ) - R_T  # RT = pV is subtracted from H to obtain the ZPE corrected ITE
            F = E + ITE - (T * S)
            G = H - (T * S)
            self.thermo = _thermo(E, ZPE, ITE, T, p, S, H, F, G, frequencies,
                                  intensities, mass, mom_inertia, rot_sym,
                                  linear_switch)

        if jobtype == "opt" or jobtype == "optimization" or jobtype == "ts":
            energies = []
            gradient_vector = []
            gradient = [0.0]
            displacement = []
            change = []
            geometries = []
            optstat = "no convergence"
            N_step = 1
            switch = 0
            for line in content:
                if "Energy is" in line:
                    dummy = float((line.split())[-1])
                    energies.append(dummy)
                if "Gradient   " in line:
                    try:
                        dummy = float((line.split())[1])
                    except:
                        dummy = 0.0
                    gradient.append(dummy)
                if "Displacement   " in line:
                    dummy = float((line.split())[1])
                    displacement.append(dummy)
                if "Energy change   " in line:
                    try:
                        dummy = float((line.split())[2])
                    except:
                        dummy = 0.0
                    change.append(dummy)
                if "**  OPTIMIZATION CONVERGED  **" in line:
                    optstat = "converged"
                if "ATOM                X               Y               Z" in line:
                    switch = 1
                    cycle_name = "Optimization step " + str(N_step)
                    cart_dummy = cartesian(cycle_name)
                if switch == 1 and "ATOM" not in line and "Point Group" not in line:
                    con = line.split()
                    cart_dummy.add_atom(con[1], con[2], con[3], con[4])
                if "Point Group" in line and switch == 1:
                    geometries.append(deepcopy(cart_dummy))
                    N_step += 1
                    switch = 0
                if "Gradient of SCF Energy" in line:
                    switch = 2
                    grad_dummy = []
                elif "Max gradient component" in line and switch == 2:
                    # Assuming that the array will always have a 3xN structure:
                    matrix = [[], [], []]
                    for i, sp in enumerate(grad_dummy):
                        if not i % 4 == 0:
                            matrix[i % 4 - 1].extend(
                                [float(si) for si in sp[1:]])
                    switch = 0
                    gradient_vector.append(_np.array(matrix))
                elif switch == 2:
                    grad_dummy.append(line.split())

            # The geometry has changed, so let's update a variable in the 'general' info object
            final_geometry = deepcopy(geometries[-1])

            if jobtype == "opt" or jobtype == "optimization":
                self.opt = _opt(geometries, energies, gradient,
                                gradient_vector, displacement, change, optstat)
            else:
                self.ts = _opt(geometries, energies, gradient, gradient_vector,
                               displacement, change, optstat)

        if jobtype == "aimd":
            drift = []
            kinetic_energies = []
            time = []
            energies = []
            geometries = []
            aimdstat = "steps not completed"
            temp = 0

            aimd_step = 0
            drift_switch = 0
            geom_switch = 0
            for line in content:
                if "Simulation temperature" in line:
                    temp = float((line.split())[3])
                if "AIMD will take" in line:
                    N_steps = int((line.split())[3])
                if "Time step =" in line:
                    time_step = float((line.split())[7])  # use fs units
                if "Total simulation time requested" in line:
                    total_time = float((line.split())[5])  # use fs units
                if "TIME STEP #" in line:  # AIMD starts
                    aimd_step += 1
                    time.append(float((line.split())[5]))
                if ("Drift factor =" in line) and (aimd_step > 0):
                    drift_switch = 1
                if ("Total" in line) and (drift_switch
                                          == 1) and (aimd_step > 0):
                    drift.append(float((line.split())[2]))
                    kinetic_energies.append(float((line.split())[1]))
                    drift_switch = 0
                if ("Total energy in the final" in line) and (aimd_step > 0):
                    dummy = float((line.split())[8])
                    energies.append(dummy)
                #if "Atom           X                Y                Z" in line and (aimd_step>0):
                if "Standard Nuclear Orientation (Angstroms)" in line and (
                        aimd_step > 0):
                    geom_switch = 1
                    cycle_name = "time step " + str(aimd_step)
                    cart_dummy = cartesian(cycle_name)
                if (geom_switch == 1) and ("------" not in line) and (
                        "Atom" not in line) and ("Nuclear" not in line):
                    con = line.split()
                    cart_dummy.add_atom(con[1], con[2], con[3], con[4])
                if geom_switch == 1 and "Nuclear Repulsion Energy" in line:
                    geometries.append(deepcopy(cart_dummy))
                    geom_switch = 0
                if "TIME STEPS COMPLETED" in line:
                    aimdstat = "steps completed"

            # The geometry has changed, so let's update a variable in the 'general' info object
            final_geometry = deepcopy(geometries[-1])

            self.aimd = _aimd(temp, N_steps, time_step, total_time, time,
                              energies, drift, kinetic_energies, geometries,
                              aimdstat)

        if self.aifdem != 0:
            self.EvalStrng = ""
            self.aifdem_E_Excite = 0.0
            self.aifdem_Time = 0.0
            EvalSwitch = 0
            for line in content:
                if ("AIFDEM Time:" in line):
                    self.aifdem_Time = float(line.split()[6])
                if (" EigenVectors " in line) and (EvalSwitch == 1):
                    EvalSwitch = 0
                if EvalSwitch == 1:
                    self.EvalStrng += line
                if " EigenValues \n" in line:
                    EvalSwitch = 1
                _ierr = 0
            for i in range(len(self.EvalStrng.split())):
                _ierr += 1
                if _ierr > 7:
                    print "Possible Error finding AIFDEM Excitation Energy in output_classes.py"
                if len(self.EvalStrng.split()[i]) > 1:
                    _iFirstline = i
                    break

            _EvalStrngFirstline = self.EvalStrng.split()[_iFirstline]

            self.aifdem_E_Excite = float(
                (_EvalStrngFirstline.split("-"))[1]) - float(
                    (_EvalStrngFirstline.split("-"))[2])
            self.aifdem_E_Excite = round(self.aifdem_E_Excite, 7)
        if self.N_SET > 0 and self.aifdem == 0:
            self.excited_states = []
            self.cis_time = 0
            _N_SET = 0
            for line in content:
                if ("Excited state" in line):
                    _E_Exc_eV = float(line.split()[-1])
                    _N_SET += 1
                if ("Total energy for state" in line):
                    _E_Exc_total = float(line.split()[-1])
                if ("Multiplicity:" in line):
                    _Mult = line.split()[-1]
                if ("Trans. Mom.:" in line):
                    _momX = line.split()[2]
                    _momY = line.split()[4]
                    _momZ = line.split()[6]
                if ("Strength" in line):
                    _osc = line.split()[-1]
                    self.excited_states.append({
                        "Exc_eV": _E_Exc_eV,
                        "Tot": _E_Exc_total,
                        "Mult": _Mult,
                        "X": _momX,
                        "Y": _momY,
                        "Z": _momZ,
                        "Strength": _osc
                    })
                if ("CPU time" in line):
                    self.cis_time = line.split()[-1]
            self.N_SET = _N_SET

        if self.N_SET > 0 and self.aifdem == 0:
            self.excited_states = []
            self.cis_time = 0
            _N_SET = 0
            for line in content:
                if ("Excited state" in line):
                    _E_Exc_eV = float(line.split()[-1])
                    _N_SET += 1
                if ("Total energy for state" in line):
                    _E_Exc_total = float(line.split()[-1])
                if ("Multiplicity:" in line):
                    _Mult = line.split()[-1]
                if ("Trans. Mom.:" in line):
                    _momX = line.split()[2]
                    _momY = line.split()[4]
                    _momZ = line.split()[6]
                if ("Strength" in line):
                    _osc = line.split()[-1]
                    self.excited_states.append({
                        "Exc_eV": _E_Exc_eV,
                        "Tot": _E_Exc_total,
                        "Mult": _Mult,
                        "X": _momX,
                        "Y": _momY,
                        "Z": _momZ,
                        "Strength": _osc
                    })
                if ("CPU time" in line):
                    self.cis_time = line.split()[-1]
            self.N_SET = _N_SET

        # Finally, we create the global info object 'general'
        self.general = _general(jobtype, version, spin, basis_size, energy,
                                status, inputfile, mm_type, initial_geometry,
                                final_geometry, wall_time, cpu_time)
Пример #3
0
    def __init__(self,file_input,silent=False):

        #Check input type
        if type(file_input)==list:
            content = file_input
        else:
            infile = open(file_input, "r")
            content = infile.readlines()
        
        spin = '0'
        energy = 'undetermined'
        jobtype = 'undetermined'
        version = 'undetermined'
        basis_size = 'undetermined'
        status = 'unfinished'

        # flag for detection of basis2 job
        basis2_flag = False

        mm_type = "" 

        switch = 0
        for line in content:
            if "JOBTYPE" in line:
                jobtype = ((line.split())[-1]).lower()
            if "jobtype" in line:
                jobtype = ((line.split())[-1]).lower()    
            if "JOB_TYPE" in line:
                jobtype = ((line.split())[-1]).lower()
            if "basis2" in line.lower():
                basis2_flag = True
            if ("QM_MM_INTERFACE" in line) or ("qm_mm_interface" in line):
                mm_type = ((line.split())[-1]).lower()
            if "Q-Chem, Version" in line:
                version = (((line.split(","))[1]).split())[1]
            if "<S^2> =" in line:
                spin = (line.split())[2]
            if ("Total energy in the final basis set") in line and mm_type!="mm":
                energy = (line.split())[8]
            if ("Convergence criterion met") in line and basis2_flag:
                energy = (line.split())[1]
            if ("Etot:" in line) and (mm_type=="mm"):
                energy = (line.split())[4]
            if ("There are" in line) and ("shells" in line):
                basis_size = (line.split())[5]
            if "MISSION" in line:
                status = 'finished'
            if "TIME STEPS COMPLETED" in line and jobtype=="aimd":
                status = 'time steps completed'
            # Create corresponding inputfile:
            if "User input:" in line:
                switch = 1
                infile_content = []
            if switch == 1:
                infile_content.append(line)
            if switch == 1 and "Standard Nuclear Orientation" in line:
                switch = 0
        inputfile = _readinput(infile_content,silent)

        self.general = _general(jobtype,version,spin,basis_size,energy,status,inputfile,mm_type)

        # Make another round if we have an MM or a QM/MM Janus job (just one MM per step)
        if mm_type=="mm" or mm_type=="janus":
            etot = []
            ecoulomb = []
            etorsion = []
            eimptors = []
            eureybrad = []
            eangle = []
            ebond = []
            evdw = []

            first_bond=1
            for line in content:
                if ("MM bonds to file" in line) and (first_bond==1):
                    nbonds = int((line.split())[1])
                    first_bond = 0
                if "Ebond:" in line:
                    ebond.append(float((line.split())[1]))
                if "Eangle:" in line:
                    eangle.append(float((line.split())[1]))
                if "EUreyBrad:" in line:
                    eureybrad.append(float((line.split())[1]))
                if "Eimptors:" in line:
                    eimptors.append(float((line.split())[1]))
                if "Etorsion:" in line:
                    etorsion.append(float((line.split())[1]))
                if "Evdw:" in line:
                    evdw.append(float((line.split())[1]))
                if "Ecoulomb:" in line:
                    ecoulomb.append(float((line.split())[1]))
                if "Etot:" in line:
                    etot.append(float((line.split())[1]))
            self.mm = _mm([etot,ecoulomb,evdw,etorsion,eimptors,eureybrad,eangle,ebond,nbonds]) # Create MM info object

        # Make another round if we have an QM/MM ONIOM job (has two MM calulations per step)
        elif mm_type=="oniom":
            etot = []
            ecoulomb = []
            etorsion = []
            eimptors = []
            eureybrad = []
            eangle = []
            ebond = []
            evdw = []

            etot2 = []
            ecoulomb2 = []
            etorsion2 = []
            eimptors2 = []
            eureybrad2 = []
            eangle2 = []
            ebond2 = []
            evdw2 = []

            mm_step = 0

            first_bond=1
            first_bond2=1

            for line in content:
                if "Step 1: MM calculation on the entire system" in line:
                    mm_step = 1
                if "Step 2: MM calculation on the model system" in line:
                    mm_step = 2

                if ("MM bonds to file" in line) and (first_bond==1) and (mm_step==1):
                    nbonds = int((line.split())[1])
                    first_bond = 0
                if "Ebond:" in line and (mm_step==1):
                    ebond.append(float((line.split())[1]))
                if "Eangle:" in line and (mm_step==1):
                    eangle.append(float((line.split())[1]))
                if "EUreyBrad:" in line and (mm_step==1):
                    eureybrad.append(float((line.split())[1]))
                if "Eimptors:" in line and (mm_step==1):
                    eimptors.append(float((line.split())[1]))
                if "Etorsion:" in line and (mm_step==1):
                    etorsion.append(float((line.split())[1]))
                if "Evdw:" in line and (mm_step==1):
                    evdw.append(float((line.split())[1]))
                if "Ecoulomb:" in line and (mm_step==1):
                    ecoulomb.append(float((line.split())[1]))
                if "Etot:" in line and (mm_step==1):
                    etot.append(float((line.split())[1]))

                if ("n_qm_bonds =" in line) and (first_bond2==1) and (mm_step==2):
                    nbonds2 = int((line.split())[2])
                    first_bond2 = 0
                if "Ebond:" in line and (mm_step==2):
                    ebond2.append(float((line.split())[1]))
                if "Eangle:" in line and (mm_step==2):
                    eangle2.append(float((line.split())[1]))
                if "EUreyBrad:" in line and (mm_step==2):
                    eureybrad2.append(float((line.split())[1]))
                if "Eimptors:" in line and (mm_step==2):
                    eimptors2.append(float((line.split())[1]))
                if "Etorsion:" in line and (mm_step==2):
                    etorsion2.append(float((line.split())[1]))
                if "Evdw:" in line and (mm_step==2):
                    evdw2.append(float((line.split())[1]))
                if "Ecoulomb:" in line and (mm_step==2):
                    ecoulomb2.append(float((line.split())[1]))
                if "Etot:" in line and (mm_step==2):
                    etot2.append(float((line.split())[1]))

            # Create MM info object for entire system
            self.mm_total = _mm([etot,ecoulomb,evdw,etorsion,eimptors,eureybrad,eangle,ebond,nbonds]) 
            # Create MM info object for model system
            self.mm_model = _mm([etot2,ecoulomb2,evdw2,etorsion2,eimptors2,eureybrad2,eangle2,ebond2,nbonds2])

        

        if jobtype=="freq":
            H2kcal=constants.hartree_to_kcal_pro_mole
            E = float(energy)
            temp = []
            press = []
            R_T = []
            enth_corr = []
            entr_corr = []
            zero_point = []

            mass = []
            mom_inertia = []
            rot_sym = []

            switch = 0
            frequencies = []
            intensities = []

            loop = 0

            linear_switch = 0

            for line in content:
                if "STANDARD THERMODYNAMIC QUANTITIES AT" in line:
                    temp.append(float((line.split())[4]))
                    press.append(1.01325e5*float((line.split())[7]))
                if "Zero point vibrational energy" in line:
                    zero_point.append(float((line.split())[4])/H2kcal)
                if "gas constant (RT):" in line:
                    R_T.append(float((line.split())[3])/H2kcal)
                if "Total Enthalpy:" in line:
                    enth_corr.append(float((line.split())[2])/H2kcal)
                if "Total Entropy:" in line:
                    entr_corr.append(float((line.split())[2])/1000/H2kcal)
                if "We detect a D*h symmetry" in line:
                    linear_switch = 1
                if "We detect a C*v symmetry" in line: 
                    linear_switch = 1
                if "We detect a C*h symmetry" in line:  # necessary because of wrong nomenclature in Q-chem (thermodyn.F)
                    linear_switch = 1
                if "Molecular Mass:" in line:
                    loop += 1
                    if "*" in line:
                        if not silent:
                            print "Warning: Molecular mass in loop " + str(loop) + " is unphysically large. Will use mass of first loop instead."
                        mass.append(mass[0])
                    else:
                        dummy = float((line.split())[2])
                        mass.append(dummy)
                if "Rotational Symmetry Number is" in line:
                    rot_sym.append(float((line.split())[4]))
                if "Eigenvalues --" in line:
                    if "*" in line:
                        if not silent:
                            print "Warning: Moment of inertia in loop " + str(loop) + " is unphysically large. Will use values of first loop instead."
                        mom_inertia.append(mom_inertia[0])
                    else:
                        dummy = [float((line.split())[2]),float((line.split())[3]),float((line.split())[4])]
                        mom_inertia.append(dummy)

                if "VIBRATIONAL ANALYSIS" in line:
                    loop1 = []
                    loop2 = []
                    switch = 1
                    infile_content = []
                if switch == 1:
                    if "Frequency:" in line:
                        dummy = line.split()
                        del dummy[0]
                        for k in dummy:
                            loop1.append(float(k))
                    if "IR Intens:" in line:
                        dummy = line.split()
                        del dummy[0]
                        del dummy[0]
                        for k in dummy:
                            loop2.append(float(k))
                if switch == 1 and "STANDARD THERMODYNAMIC" in line:
                    switch = 0
                    frequencies.append(loop1)
                    intensities.append(loop2)

            T = _np.asarray(temp)
            p = _np.asarray(press)
            ZPE = _np.asarray(zero_point)
            H = E + _np.asarray(enth_corr)
            S = _np.asarray(entr_corr)
            ITE = _np.asarray(enth_corr) - R_T # RT = pV is subtracted from H to obtain the ZPE corrected ITE
            F = E + ITE - (T*S)
            G = H - (T*S)
            self.thermo = _thermo(E,ZPE,ITE,T,p,S,H,F,G,frequencies,intensities,mass,mom_inertia,rot_sym,linear_switch)

        if jobtype=="opt" or jobtype=="optimization" or jobtype=="ts":
            energies = []
            gradient = [0.0]
            displacement = []
            change = []
            geometries = []
            optstat = "no convergence"
            N_step = 1
            switch = 0
            for line in content:
                if "Energy is" in line:
                    dummy = float((line.split())[2])
                    energies.append(dummy)
                if "Gradient   " in line:
                    try:
                        dummy = float((line.split())[1])
                    except:
                        dummy = 0.0
                    gradient.append(dummy)
                if "Displacement   " in line:
                    dummy = float((line.split())[1])
                    displacement.append(dummy)
                if "Energy change   " in line:
                    try:
                        dummy = float((line.split())[2])
                    except:
                        dummy = 0.0
                    change.append(dummy)
                if "**  OPTIMIZATION CONVERGED  **" in line:
                    optstat = "converged"
                if "ATOM              X           Y           Z" in line:
                    switch = 1
                    cycle_name = "Optimization step " + str(N_step)
                    cart_dummy = cartesian(cycle_name)
                if "ATOM                X               Y               Z" in line:
                    switch = 1
                    cycle_name = "Optimization step " + str(N_step)
                    cart_dummy = cartesian(cycle_name)
                if switch == 1 and "ATOM" not in line and "Point Group" not in line:
                    con = line.split()
                    cart_dummy.add_atom(con[1],con[2],con[3],con[4])
                if "Point Group" in line and switch == 1:
                    geometries.append(deepcopy(cart_dummy))
                    N_step += 1
                    switch = 0

            if jobtype=="opt" or jobtype=="optimization":
                self.opt = _opt(geometries,energies,gradient,displacement,change,optstat)
            else:
                self.ts = _opt(geometries,energies,gradient,displacement,change,optstat)



        if jobtype=="aimd":
            drift = []
            kinetic_energies = []
            time = []
            energies = []
            geometries = []
            aimdstat = "steps not completed"

            aimd_step = 0
            drift_switch = 0
            geom_switch = 0
            for line in content:
                if "Simulation temperature" in line:
                    temp = float((line.split())[3])
                if "AIMD will take" in line:
                    N_steps = int((line.split())[3])
                if "Time step =" in line:
                    time_step = float((line.split())[7])  # use fs units
                if "Total simulation time requested" in line:
                    total_time = float((line.split())[5])  # use fs units
                if "TIME STEP #" in line:  # AIMD starts
                    aimd_step += 1
                    time.append(float((line.split())[5]))
                if ("Drift factor =" in line) and (aimd_step>0):  
                    drift_switch = 1
                if ("Total" in line) and (drift_switch==1) and (aimd_step>0):
                    drift.append(float((line.split())[2]))
                    kinetic_energies.append(float((line.split())[1]))
                    drift_switch = 0 
                if ("Total energy in the final" in line) and (aimd_step>0):
                    dummy = float((line.split())[8])
                    energies.append(dummy)
                if "Atom         X            Y            Z" in line and (aimd_step>0):
                    geom_switch = 1
                    cycle_name = "time step " + str(aimd_step)
                    cart_dummy = cartesian(cycle_name)
                if (geom_switch == 1) and ("------" not in line) and ("Atom" not in line) and ("Nuclear" not in line):
                    con = line.split()
                    cart_dummy.add_atom(con[1],con[2],con[3],con[4])
                if geom_switch==1 and "Nuclear Repulsion Energy" in line:
                    geometries.append(deepcopy(cart_dummy))
                    geom_switch = 0
                if "TIME STEPS COMPLETED" in line:
                    aimdstat = "steps completed"

            self.aimd = _aimd(temp,N_steps,time_step,total_time,time,energies,drift,kinetic_energies,geometries,aimdstat)
Пример #4
0
def read(filename, silent=False):
    """
    This method reads Q-Chem input files, output files, and coordinate files (xyz,zmat,txyz). 
    """

    extension = (filename.split("."))[-1]

    #catchall pybel list
    pybel_inlist = [
        'txyz', 'text', 'alc', 'castep', 'nwo', 'cdx', 'xml', 'pwscf', 'rsmi',
        'xtc', 'g09', 'pcm', 'mopin', 'mopcrt', 'xyz', 'fchk', 'g03', 'cube',
        'axsf', 'mpc', 'mpo', 'mop', 'pos', 'dat', 'moo', 'dx', 'mol', 'inchi',
        'hin', 'cml', 'outmol', 'xsf', 'qcout', 'output', 'mdl', 'unixyz',
        'pdbqt', 'gzmat', 'arc', 'out', 'c09out', 'feat', 'crk3d', 'got',
        'mopout', 'tdd', 'mmod', 'bs', 'mmd', 'box', 'bgf', 'vmol', 'acr',
        'pqs', 'crk2d', 'CONFIG', 'pdb', 'ck', 'c3d2', 't41', 'c3d1',
        'CONTCAR', 'gamout', 'mmcif', 'txt', 'ct', 'therm', 'log', 'pc',
        'dmol', 'molden', 'ml2', 'fract', 'msi', 'cdxml', 'g98', 'prep', 'gpr',
        'cub', 'gam', 'gukin', 'cmlr', 'abinit', 'POSCAR', 'ins', 'tmol',
        'png', 'cif', 'gamess', 'car', 'mcif', 'smi', 'can', 'caccrt',
        'fhiaims', 'inp', 'gukout', 'sy2', 'fasta', 'mpqc', 'mold', 'molf',
        'jout', 'yob', 'mcdl', 'ent', 'adfout', 'gro', 'smiles', 'fs', 'mol2',
        'fa', 'pqr', 'g94', 'g92', 'fch', 'VASP', 'fck', 'HISTORY', 'fsa',
        'gamin', 'rxn', 'mrv', 'sdf', 'gal', 'res', 'sd', 'ccc', 'acesout'
    ]

    # Do we have an inputfile?
    if extension in ("inp", "in", "IN", "INP", "qcin", "QCIN"):

        seperator = []
        with open(filename) as infile:
            for num, line in enumerate(infile):
                if "@@@" == line.strip() or "@@@@" == line.strip():
                    seperator.append(num)

        N_jobs = len(seperator)

        # Does the file contain multiple jobs?
        if N_jobs > 0:
            if not silent:
                print "Batch Jobfile detected."
            joblist = []
            infile = open(filename, "r")
            content = infile.readlines()
            seperator.insert(0, -1)
            seperator.append(len(content))

            # Create batch jobfile object
            re_file = multifile()

            # Populate it with jobs
            for k in range(N_jobs + 1):
                start = seperator[k] + 1
                end = seperator[k + 1]
                dummylines = content[start:end]
                dummy = _readinput(dummylines, silent)
                re_file.add(dummy)
            return re_file

        # No, it's a single job file
        else:
            if not silent:
                print "Jobfile detected."
            return _readinput(filename, silent)

    # Is it a z-matrix file?
    elif extension in ("zmat", "ZMAT", "Z", "z"):
        if not silent:
            print "Z-matrix file detected."
        return _readzmat(filename)

    # Is it a cartesian coordinates file?
    elif extension in ("xyz", "XYZ"):
        if not silent:
            print "Cartesian coordinates file detected."
        return _readcartesian(filename)

    # Is it a tinker coordinates file?
    elif extension in ("txyz", "TXYZ"):
        if not silent:
            print "Tinker coordinates file detected."
        return _readtinker(filename)

    # Do we have a Q-Chem outputfile?
    if extension.lower() in ("out", "qcout", "qchem"):

        seperator = []
        with open(filename) as infile:
            for num, line in enumerate(infile):
                if "Welcome to Q-Chem" in line:
                    seperator.append(num)

        N_jobs = len(seperator)

        # Does the file contain multiple jobs?
        if N_jobs > 1:
            if not silent:
                print "Batch-Outputfile detected."
            joblist = []
            infile = open(filename, "r")
            content = infile.readlines()
            #seperator.insert(0,-1)
            seperator.append(len(content))

            # Create batch jobfile object
            re_file = _multioutput()

            # Populate it with jobs
            for k in range(N_jobs):
                start = seperator[k] + 1
                end = seperator[k + 1]
                dummylines = content[start:end]
                dummy = _outputfile(dummylines, silent)
                re_file.add(dummy)
            return re_file

        # No, it's a single job file
        else:
            if not silent:
                print "Outputfile detected."
            return _outputfile(filename, silent)

    # Is it anything pybel can read?
    elif extension in pybel_inlist:
        try:
            import pybel
        except:
            print "Error: File type not recognized."
            return
        if not silent:
            print pybel.informats[extension], " detected"
        return _readpybel(extension, filename)

    # What the heck? This is not a valid file.
    else:
        if not silent:
            print "Error: File type not recognized."
Пример #5
0
def read(filename,silent=False):
    """
    This method reads Q-Chem input files, output files, and coordinate files (xyz,zmat,txyz). 
    """

    extension = (filename.split("."))[-1]

    #catchall pybel list
    pybel_inlist=['txyz', 'text', 'alc', 'castep', 'nwo', 'cdx', 'xml', 'pwscf', 'rsmi', 'xtc', 'g09', 'pcm', 'mopin', 'mopcrt', 'xyz', 'fchk', 'g03', 'cube', 'axsf', 'mpc', 'mpo', 'mop', 'pos', 'dat', 'moo', 'dx', 'mol', 'inchi', 'hin', 'cml', 'outmol', 'xsf', 'qcout', 'output', 'mdl', 'unixyz', 'pdbqt', 'gzmat', 'arc', 'out', 'c09out', 'feat', 'crk3d', 'got', 'mopout', 'tdd', 'mmod', 'bs', 'mmd', 'box', 'bgf', 'vmol', 'acr', 'pqs', 'crk2d', 'CONFIG', 'pdb', 'ck', 'c3d2', 't41', 'c3d1', 'CONTCAR', 'gamout', 'mmcif', 'txt', 'ct', 'therm', 'log', 'pc', 'dmol', 'molden', 'ml2', 'fract', 'msi', 'cdxml', 'g98', 'prep', 'gpr', 'cub', 'gam', 'gukin', 'cmlr', 'abinit', 'POSCAR', 'ins', 'tmol', 'png', 'cif', 'gamess', 'car', 'mcif', 'smi', 'can', 'caccrt', 'fhiaims', 'inp', 'gukout', 'sy2', 'fasta', 'mpqc', 'mold', 'molf', 'jout', 'yob', 'mcdl', 'ent', 'adfout', 'gro', 'smiles', 'fs', 'mol2', 'fa', 'pqr', 'g94', 'g92', 'fch', 'VASP', 'fck', 'HISTORY', 'fsa', 'gamin', 'rxn', 'mrv', 'sdf', 'gal', 'res', 'sd', 'ccc', 'acesout']


    # Do we have an inputfile?
    if  extension in ("inp","in","IN","INP","qcin","QCIN"):

        seperator = []
        with open(filename) as infile:
            for num, line in enumerate(infile):
                if "@@@"==line.strip() or "@@@@"==line.strip():
                    seperator.append(num)

        N_jobs = len(seperator)

        # Does the file contain multiple jobs? 
        if N_jobs>0:
            if not silent:
                print "Batch Jobfile detected."
            joblist = []
            infile = open(filename,"r")
            content = infile.readlines()
            seperator.insert(0,-1)
            seperator.append(len(content))
    
            # Create batch jobfile object
            re_file = multifile()
    
            # Populate it with jobs
            for k in range(N_jobs+1):
                start=seperator[k]+1
                end=seperator[k+1]
                dummylines = content[start:end]
                dummy = _readinput(dummylines,silent)
                re_file.add(dummy)
            return re_file
    
        # No, it's a single job file    
        else:
            if not silent:
                print "Jobfile detected."
            return _readinput(filename,silent)
        
    # Is it a z-matrix file?
    elif extension in ("zmat","ZMAT","Z","z"):
        if not silent:
            print "Z-matrix file detected."
        return _readzmat(filename)
          
    # Is it a cartesian coordinates file?
    elif extension in ("xyz","XYZ"):
        if not silent:
            print "Cartesian coordinates file detected."
        return _readcartesian(filename)
        
    # Is it a tinker coordinates file?
    elif extension in ("txyz","TXYZ"):
        if not silent:
            print "Tinker coordinates file detected."
        return _readtinker(filename)


    

    # Do we have a Q-Chem outputfile?
    if extension.lower() in ("out", "qcout", "qchem"):

        seperator = []
        with open(filename) as infile:
            for num, line in enumerate(infile):
                if "Welcome to Q-Chem" in line:
                    seperator.append(num)

        N_jobs = len(seperator)

        # Does the file contain multiple jobs? 
        if N_jobs>1:
            if not silent:
                print "Batch-Outputfile detected."
            joblist = []
            infile = open(filename,"r")
            content = infile.readlines()
            #seperator.insert(0,-1)
            seperator.append(len(content))
    
            # Create batch jobfile object
            re_file = _multioutput()
    
            # Populate it with jobs
            for k in range(N_jobs):
                start=seperator[k]+1
                end=seperator[k+1]
                dummylines = content[start:end]
                dummy = _outputfile(dummylines,silent)
                re_file.add(dummy)
            return re_file
    
        # No, it's a single job file    
        else:
            if not silent:
                print "Outputfile detected."
            return _outputfile(filename,silent)

    # Is it anything pybel can read?
    elif extension in pybel_inlist:
        try: 
            import pybel
        except:
            print "Error: File type not recognized."
            return
        if not silent:
            print pybel.informats[extension], " detected"
        return _readpybel(extension,filename)   

    # What the heck? This is not a valid file.
    else:
        if not silent:
            print "Error: File type not recognized."