#!/usr/bin/env python3 # resultsFile is a library which allows to read output files of quantum # chemistry codes and write input files. # Copyright (C) 2007 Anthony SCEMAMA # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # Anthony Scemama # LCPQ - IRSAMC # Universite Paul Sabatier # 118, route de Narbonne # 31062 Toulouse Cedex 4 # scemama@irsamc.ups-tlse.fr """resultsFile library.""" __author__ = "Anthony SCEMAMA " __date__ = "20 Nov 2007" # For relative imports to work in Python 3.6 import os, sys cwd = os.path.dirname(os.path.realpath(__file__)) sys.path = [ cwd ] + sys.path from lib import * import lib.basis as Basis import sys import copy fileTypes = [] local_vars = [ \ # File properties ( 'filename' , "Name of the results file."), ( 'text' , "Text of the results file."), ( 'pos' , "Position in the results file."), ( 'date' , "When the calculation was performed."), ( 'version' , "Version of the code generating the file."), ( 'author' , "Who ran the calculation."), ( 'machine' , "Machine where the calculation was run."), ( 'memory' , "Requested memory for the calculation."), ( 'disk' , "Requested disk space for the calculation."), ( 'num_proc' , "Number of processors used."), ( 'cpu_time' , "CPU time."), # General properties ( 'title' , "Title of the run."), ( 'options' , "Options given in the input file."), ( 'units' , "Units for the geometry (au or angstroms)."), ( 'methods' , "List of calculation methods."), ( 'spin_restrict' , "Open-shell or closed-shell calculations."), ( 'conv_threshs' , "List of convergence thresholds."), ( 'energies' , "List of energies."), ( 'one_e_energies', "List of one electron energies."), ( 'two_e_energies', "List of two electron energies."), ( 'ee_pot_energies',"List of electron-electron potential energies."), ( 'Ne_pot_energies',"List of nucleus-electron potential energies."), ( 'pot_energies' , "List of potential energies."), ( 'kin_energies' , "List of kinetic energies."), ( 'virials' , "Virial ratios."), ( 'mulliken_mo' , "Mulliken atomic population in each MO."), ( 'mulliken_ao' , "Mulliken atomic population in each AO."), ( 'lowdin_ao' , "Lowdin atomic population in each AO."), ( 'mulliken_atom' , "Mulliken atomic population."), ( 'lowdin_atom' , "Lowdin atomic population."), ( 'dipole' , "Dipole moment"), ( 'quadrupole' , "Quadrupole moment"), ( 'num_states' , "Number of electronic states"), # Geometry properties ( 'point_group' , "Symmetry used."), ( 'geometry' , "Atom types and coordinates."), ( 'symmetries' , "Irreducible representations"), ( 'num_elec' , "Number of electrons."), ( 'num_alpha' , "Number of Alpha electrons."), ( 'num_beta' , "Number of Beta electrons."), ( 'charge' , "Charge of the system."), ( 'multiplicity' , "Spin multiplicity of the system."), ( 'nuclear_energy ', "Repulsion of the nuclei."), ( 'gradient_energy', "Gradient of the Energy wrt nucl coord."), # Basis set ( 'basis' , "Basis set definition"), ( 'uncontracted_basis', "Uncontracted Basis set"), # Pseudopotentials ( 'pseudo' , "Pseudopotential data"), # Orbitals ( 'mo_sets' , "List of molecular orbitals"), ( 'mo_types' , "Types of molecular orbitals (canonical, natural,...)"), ( 'occ_num' , "Occupation numbers"), ( 'uncontracted_mo_sets', "List of molecular orbitals in the uncontracted basis set."), # Determinants ( 'closed_mos' , "Closed shell molecular orbitals"), ( 'active_mos' , "Active molecular orbitals"), ( 'virtual_mos' , "Virtual molecular orbitals"), ( 'csf' , "List of Configuration State Functions"), ( 'determinants' , "List of Determinants"), ( 'csf_mo_type' , "MO type of the determinants"), ( 'determinants_mo_type' , "MO type of the determinants"), ( 'csf_coefficients', "Coefficients of the CSFs"), ( 'det_coefficients', "Coefficients of the determinants"), # Integrals ( 'one_e_int_ao' , "One electron integrals in AO basis"), ( 'two_e_int_ao' , "Two electron integrals in AO basis"), ( 'one_e_int_mo' , "One electron integrals in MO basis"), ( 'two_e_int_mo' , "Two electron integrals in MO basis"), ] resultsFile_defined_vars = ["text","uncontracted_basis", "uncontracted_mo_sets"] class resultsFileX(object): """ Class containing the definition of files. """ local_vars = list(local_vars) defined_vars = list(resultsFile_defined_vars) def __init__(self,name): """All local variables are set to None, except filename. """ for var, doc in local_vars: setattr(self,'_'+var,None) self._filename = name def get_text(self): """Reads the whole file. """ if self._text is None: try: file = open(self.filename,"r") self._text = file.readlines() except IOError: print("Unable to open "+self.filename) sys.exit(1) file.close() return self._text def get_uncontracted_basis(self): if self._uncontracted_basis is None: try: from resultsFile_cython import get_uncontracted_basis as f has_cython = True except ImportError: has_cython = False basis = self.basis if has_cython: self._uncontracted_basis = f(basis) else: uncontr = [] for contr in basis: for b in contr.prim: uncontr.append(b) self._uncontracted_basis = uncontr return self._uncontracted_basis def get_uncontracted_mo_sets(self): if self._uncontracted_mo_sets is None: try: from resultsFile_cython import get_uncontracted_mo_sets as f has_cython = True except ImportError: has_cython = False if has_cython: self._uncontracted_mo_sets = f(self.basis, self.uncontracted_basis, self.mo_sets, self.mo_types) else: uncontr = {} basis = self.basis for motype in self.mo_types: uncontr[motype] = [] for mo in self.mo_sets[motype]: lenmovector = len(mo.vector) monew = orbital() monew.basis = self.uncontracted_basis monew.eigenvalue = mo.eigenvalue monew.set = motype v = [] for i, contr in enumerate(basis): if i