def loadScanEnergies(self): """ Extract the optimized energies in J/mol from a QChem log file, e.g. the result of a QChem "PES Scan" quantum chemistry calculation. """ Vlist = [] angle = [] read = False with open(self.path, 'r') as f: for line in f: if '-----------------' in line: read = False if read: values = [float(item) for item in line.split()] angle.append(values[0]) Vlist.append(values[1]) if 'Summary of potential scan:' in line: logging.info('found a sucessfully completed QChem Job') read = True elif 'SCF failed to converge' in line: raise InputError('QChem Job did not sucessfully complete: SCF failed to converge') logging.info(' Assuming {0} is the output from a QChem PES scan...'.format(os.path.basename(self.path))) Vlist = numpy.array(Vlist, numpy.float64) # check to see if the scanlog indicates that one of your reacting species may not be the lowest energy conformer check_conformer_energy(Vlist, self.path) # Adjust energies to be relative to minimum energy conformer # Also convert units from Hartree/particle to J/mol Vlist -= numpy.min(Vlist) Vlist *= constants.E_h * constants.Na angle = numpy.arange(0.0, 2*math.pi+0.00001, 2*math.pi/(len(Vlist)-1), numpy.float64) return Vlist, angle
def load_scan_energies(self): """ Extract the optimized energies in J/mol from a log file, e.g. the result of a Gaussian "Scan" quantum chemistry calculation. """ opt_freq = False rigid_scan = False vlist = [] # The array of potentials at each scan angle # Parse the Gaussian log file, extracting the energies of each # optimized conformer in the scan with open(self.path, 'r') as f: line = f.readline() while line != '': # If the job contains a "freq" then we want to ignore the last energy if ' Freq' in line and ' Geom=' in line: opt_freq = True # if # scan is keyword instead of # opt, then this is a rigid scan job # and parsing the energies is done a little differently if '# scan' in line: rigid_scan = True # The lines containing "SCF Done" give the energy at each # iteration (even the intermediate ones) if 'SCF Done:' in line: energy = float(line.split()[4]) # rigid scans will only not optimize, so just append every time it finds an energy. if rigid_scan: vlist.append(energy) # We want to keep the values of energy that come most recently before # the line containing "Optimization completed", since it refers # to the optimized geometry if 'Optimization completed' in line: vlist.append(energy) line = f.readline() # give warning in case this assumption is not true if rigid_scan: print(' Assuming', os.path.basename(self.path), 'is the output from a rigid scan...') vlist = np.array(vlist, np.float64) # check to see if the scanlog indicates that a one of your reacting species may not be # the lowest energy conformer check_conformer_energy(vlist, self.path) # Adjust energies to be relative to minimum energy conformer # Also convert units from Hartree/particle to J/mol vlist -= np.min(vlist) vlist *= constants.E_h * constants.Na if opt_freq: vlist = vlist[:-1] # Determine the set of dihedral angles corresponding to the loaded energies # This assumes that you start at 0.0, finish at 360.0, and take # constant step sizes in between angle = np.arange(0.0, 2 * math.pi + 0.00001, 2 * math.pi / (len(vlist) - 1), np.float64) return vlist, angle
def load_scan_energies(self): """ Extract the optimized energies in J/mol from a TeraChem torsional scan log file. """ v_list = list() with open(self.path, 'r') as f: lines = f.readlines() v_index, expected_num_of_points = 0, 0 for line in lines: if 'Scan Cycle' in line: # example: '-=#=- Scan Cycle 5/37 -=#=-' v_index += 1 if not expected_num_of_points: expected_num_of_points = int( line.split()[3].split('/')[1]) if 'Optimized Energy:' in line: # example: '-=#=- Optimized Energy: -155.0315243910 a.u.' v = float(line.split()[3]) if len(v_list) == v_index - 1: # append this point, it is in order v_list.append(v) elif len(v_list) < v_index - 1: # seems like points in this scan are missing... add None's instead, # later they'll be removed along with the corresponding angles v_list.extend([None] * (v_index - 1 - len(v_list))) else: # we added more points that we should have, something is wrong with the log file or this method raise LogError( f'Could not parse scan energies from {self.path}') logging.info( ' Assuming {0} is the output from a TeraChem PES scan...'.format( os.path.basename(self.path))) v_list = np.array(v_list, np.float64) # check to see if the scanlog indicates that one of the reacting species may not be the lowest energy conformer check_conformer_energy(v_list, self.path) # Adjust energies to be relative to minimum energy conformer # Also convert units from Hartree/particle to J/mol v_list -= np.min(v_list) v_list *= constants.E_h * constants.Na angles = np.arange(0.0, 2 * math.pi + 0.00001, 2 * math.pi / (len(v_list) - 1), np.float64) # remove None's: indices_to_pop = [ v_list.index[entry] for entry in v_list if entry is None ] for i in reversed(indices_to_pop): v_list.pop(i) angles.pop(i) if v_index != expected_num_of_points: raise LogError( f'Expected to find {expected_num_of_points} scan points in TeraChem scan log file ' f'{self.path}, but found: {v_index}') return v_list, angles
def loadScanEnergies(self): """ Extract the optimized energies in J/mol from a Qchem log file, e.g. the result of a Qchem "PES Scan" quantum chemistry calculation. """ Vlist = [] angle = [] f = open(self.path, 'r') line = f.readline() while line != '': if 'Summary of potential scan:' in line: line = f.readline() print 'found a sucessfully completed Qchem Job' while '-----------------' not in line: # print len(line.split()) # Vlist.append(float(line.split()[1])) values = [float(item) for item in line.split()] angle.append(values[0]) Vlist.append(values[1]) # Read the next line in the file line = f.readline() line = f.readline() if 'SCF failed to converge' in line: print 'Qchem Job did not sucessfully complete: SCF failed to converge' break # Close file when finished print ' Assuming', os.path.basename(self.path), 'is the output from a Qchem PES scan...' f.close() Vlist = numpy.array(Vlist, numpy.float64) # check to see if the scanlog indicates that one of your reacting species may not be the lowest energy conformer check_conformer_energy(Vlist, self.path) # Adjust energies to be relative to minimum energy conformer # Also convert units from Hartree/particle to J/mol Vlist -= numpy.min(Vlist) Vlist *= constants.E_h * constants.Na angle = numpy.arange(0.0, 2*math.pi+0.00001, 2*math.pi/(len(Vlist)-1), numpy.float64) return Vlist, angle