def testDetermineQMSoftware(self): """ Ensures that determine_qm_software returns a GaussianLog object """ log = determine_qm_software( os.path.join(os.path.dirname(__file__), 'data', 'oxygen.log')) self.assertIsInstance(log, GaussianLog)
def parse_e_elect(path, zpe_scale_factor=1.): """ Parse the zero K energy, E0, from an sp job output file. """ if not os.path.isfile(path): raise InputError('Could not find file {0}'.format(path)) log = determine_qm_software(fullpath=path) try: e_elect = log.loadEnergy(zpe_scale_factor) * 0.001 # convert to kJ/mol except Exception: logger.warning('Could not read e_elect from {0}'.format(path)) e_elect = None return e_elect
def get_zpe(path): """ Determine the calculated ZPE from a frequency output file" Args: path (str): The path to a frequency calculation output file. Returns: float: The calculated zero point energy in J/mol. """ statmech_log = determine_qm_software(path) zpe = statmech_log.loadZeroPointEnergy() return zpe
def parse_e0(path): """ Parse the zero K energy, E0, from an sp job output file """ if not os.path.isfile(path): raise InputError('Could not find file {0}'.format(path)) log = determine_qm_software(fullpath=path) try: e0 = log.loadEnergy(frequencyScaleFactor=1.) * 0.001 # convert to kJ/mol except Exception: logging.warning('Could not read E0 from {0}'.format(path)) e0 = None return e0
def parse_dipole_moment(path): """ Parse the dipole moment in Debye from an opt job output file. """ lines = _get_lines_from_file(path) log = determine_qm_software(path) dipole_moment = None if isinstance(log, GaussianLog): # example: # Dipole moment (field-independent basis, Debye): # X= -0.0000 Y= -0.0000 Z= -1.8320 Tot= 1.8320 read = False for line in lines: if 'dipole moment' in line.lower() and 'debye' in line.lower(): read = True elif read: dipole_moment = float(line.split()[-1]) read = False elif isinstance(log, QChemLog): # example: # Dipole Moment (Debye) # X 0.0000 Y 0.0000 Z 2.0726 # Tot 2.0726 skip = False read = False for line in lines: if 'dipole moment' in line.lower() and 'debye' in line.lower(): skip = True elif skip: skip = False read = True elif read: dipole_moment = float(line.split()[-1]) read = False elif isinstance(log, MolproLog): # example: # Dipole moment /Debye 2.96069859 0.00000000 0.00000000 for line in lines: if 'dipole moment' in line.lower() and '/debye' in line.lower(): splits = line.split() dm_x, dm_y, dm_z = float(splits[-3]), float(splits[-2]), float( splits[-1]) dipole_moment = (dm_x**2 + dm_y**2 + dm_z**2)**0.5 else: raise ParserError( 'Currently dipole moments can only be parsed from either Gaussian, Molpro, or QChem ' 'optimization output files') if dipole_moment is None: raise ParserError('Could not parse the dipole moment') return dipole_moment
def parse_xyz_from_file(path): """ Parse xyz coordinated from: .xyz - XYZ file .gjf - Gaussian input file .out or .log - ESS output file (Gaussian, QChem, Molpro) other - Molpro or QChem input file """ lines = _get_lines_from_file(path) file_extension = os.path.splitext(path)[1] xyz = None relevant_lines = list() if file_extension == '.xyz': relevant_lines = lines[2:] elif file_extension == '.gjf': start_parsing = False for line in lines: if start_parsing and line and line != '\n' and line != '\r\n': relevant_lines.append(line) elif start_parsing: break else: splits = line.split() if len(splits) == 2 and all([s.isdigit() for s in splits]): start_parsing = True elif 'out' in file_extension or 'log' in file_extension: log = determine_qm_software(fullpath=path) coords, number, _ = log.loadGeometry() xyz = get_xyz_string(coords=coords, numbers=number) else: record = False for line in lines: if '$end' in line or '}' in line: break if record and len(line.split()) == 4: relevant_lines.append(line) elif '$molecule' in line: record = True elif 'geometry={' in line: record = True if not relevant_lines: raise ParserError( 'Could not parse xyz coordinates from file {0}'.format(path)) if xyz is None and relevant_lines: xyz = ''.join([line for line in relevant_lines if line]) return standardize_xyz_string(xyz)
def test_determine_qm_software(self): """ Ensures that determine_qm_software returns a GaussianLog object """ log = determine_qm_software(os.path.join(self.data_path, 'oxygen.log')) self.assertIsInstance(log, GaussianLog)
def testDetermineQMSoftware(self): """ Ensures that determine_qm_software returns a GaussianLog object """ log = determine_qm_software(os.path.join(os.path.dirname(__file__),'data','oxygen.log')) self.assertIsInstance(log,GaussianLog)