Example #1
0
  def __init__(self, qmout=None, **kwargs):
    GaussianBasisOutput.__init__(self, qmout, **kwargs)
    if qmout:
      self.program = 'nwchem'
      outfile = open(qmout, 'r')
      data = outfile.readlines()
      outfile.close()
      Et = filter(lambda x: 'Total' in x and 'energy' in x, data)
      try:
        self.Et = float(Et[-1].split( )[-1])
      except:
        self.Et = np.nan
      try:
        _Et = filter(lambda x: 'total' in x and 'energy' in x, data)
        _Et = float(_Et[-1].split( )[-1])
        self.Et = _Et
      except:
        pass
      # necessary for opening *.movecs file
      n_basis = filter(lambda x: 'functions' in x, data)
      if ':' in n_basis[-1]:
        try:
          self.n_basis = int(n_basis[-1].split(':')[1])
        except:
          self.n_basis = np.nan
      elif '=' in n_basis[-1]:
        try:
          self.n_basis = int(n_basis[-1].split('=')[1])
        except:
          self.n_basis = np.nan

      nuclear = filter(lambda x: 'repulsion' in x, data)[-1]
      self.nuclear_repulsion = float(nuclear.split(' ')[-1])

      def getBasis():
        ######################################
        # extract basis function information #
        ######################################
      
        basis_dict = {"S":0, "P":1, "D":2, "F":3, "G":4, "H":5}
  
        basis_P = re.compile(r" *[0-9]+ [A-Z]  [0-9]\.[0-9]{8}")
        batom_P = re.compile(r"^  [0-9A-Za-z\-_\.]+ *\([A-Z][a-z]*\)")
        bname_P = re.compile(r"\((.*)\)")
        coord_P = re.compile(r"^ [0-9A-Za-z\.\-_]+ +[- ][0-9\.]{9,}")
        basisStr = filter(basis_P.match, data)
        batomStr = filter(batom_P.match, data)
        coordStr = filter(coord_P.match, data)
  
        # change 'Sulphur' to 'Sulfur' for NWChem format
        # 'Sulphur' 'Sulfur'
        def atomNameConv(old, new):
          _matched = filter(lambda x: old in x, batomStr)
          if _matched:
            _matched = _matched[0]
            _s = batomStr.index(_matched)
            batomStr[_s] = re.sub(old, new, batomStr[_s])
            _s = data.index(_matched)
            data[_s] = re.sub(old, new, data[_s])
        atomNameConv('Sulphur', 'Sulfur')
        atomNameConv('Aluminium', 'Aluminum')
  
        _exponents = [float(filter(None, s.split(' '))\
          [2]) for s in basisStr]
        _coefficients = [float(filter(None, s.split(' '))\
          [3]) for s in basisStr]
        _N = [int(filter(None, s.split(' '))[0])\
          for s in basisStr]
        _type = [filter(None, s.split(' '))[1]\
          for s in basisStr]
        _bfnInd = [data.index(batom) for batom in batomStr]
        _bfnEndPtn = re.compile(r" Summary of \"")
        _bfnEndStr = filter(_bfnEndPtn.match, data)[0]
        _bfnInd.append(data.index(_bfnEndStr))
  
        _ao_keys = [0]
        for ind in range(len(_bfnInd)-1):
          _key = _ao_keys[-1]
          for i in range(_bfnInd[ind]+4, _bfnInd[ind+1]):
            if len(data[i]) > 1:
              _key = _key + 1
          _ao_keys.append(_key)
        _atoms = [getattr(pt, bname_P.match(
          filter(None, s.split(' '))[1]).group(1).lower()).symbol\
          for s in batomStr]
        self.type_list = [re.split(r'[\._]',
          filter(None, s.split(' '))[0])[0].title()\
          for s in coordStr]
        self.type_list_unique = list(
          collections.OrderedDict.fromkeys(self.type_list)
        )
        self.R = np.array([filter(None, s.split(' '))[1:4]\
          for s in coordStr]).astype(float)
        self.N = len(self.R)
        self.Z = [qtk.n2Z(e) for e in self.type_list]
        self.R_bohr = 1.889725989 * self.R
        ZR = []
        for i in range(self.N):
          vec = [self.Z[i]]
          vec.extend(self.R[i])
          ZR.append(vec)
        self.molecule = qtk.Molecule()
        self.molecule.build(ZR)
  
        _N.append(0)
        self.basis = []
        for i in range(len(self.type_list)):
          e = self.type_list[i]
          center = self.R_bohr[i]
          ind = self.type_list_unique.index(e)
          bfn_base = {}
          bfn_base['atom'] = e
          bfn_base['center'] = center
          bfn_base['index'] = i
          exp = []
          cef = []
          for g in range(_ao_keys[ind], _ao_keys[ind+1]):
            exp.append(_exponents[g])
            cef.append(_coefficients[g])
            if _N[g] != _N[g+1] or g+1 >= _ao_keys[ind+1]:
              bfn = copy.deepcopy(bfn_base)
              bfn['exponents'] = copy.deepcopy(exp)
              bfn['coefficients'] = copy.deepcopy(cef)
              if _type[g] in basis_dict:
                _bfnList = self.basisList(basis_dict[_type[g]])
                for bStr in _bfnList:
                  bfn['type'] = _type[g].lower() + bStr
                  self.basis.append(copy.deepcopy(bfn))
              exp = []
              cef = []
  
      try:
        getBasis()
      except AttributeError as err:
        qtk.warning('failed to get basis information with error: %s.'\
                    % err + ' Weird atom names?')

      movecs = os.path.join(self.path, self.stem) + '.modat'
      if os.path.exists(movecs):
        self.getMO(movecs)
Example #2
0
    def __init__(self, qmout=None, **kwargs):
        GaussianBasisOutput.__init__(self, qmout, **kwargs)
        if qmout:
            self.program = 'nwchem'
            outfile = open(qmout, 'r')
            data = outfile.readlines()
            outfile.close()
            Et = filter(lambda x: 'Total' in x and 'energy' in x, data)
            try:
                self.Et = float(Et[-1].split()[-1])
            except:
                self.Et = np.nan
            try:
                _Et = filter(lambda x: 'total' in x and 'energy' in x, data)
                _Et = float(_Et[-1].split()[-1])
                self.Et = _Et
            except:
                pass
            # necessary for opening *.movecs file
            n_basis = filter(lambda x: 'functions' in x, data)
            if ':' in n_basis[-1]:
                try:
                    self.n_basis = int(n_basis[-1].split(':')[1])
                except:
                    self.n_basis = np.nan
            elif '=' in n_basis[-1]:
                try:
                    self.n_basis = int(n_basis[-1].split('=')[1])
                except:
                    self.n_basis = np.nan

            nuclear = filter(lambda x: 'repulsion' in x, data)[-1]
            self.nuclear_repulsion = float(nuclear.split(' ')[-1])

            def getBasis():
                ######################################
                # extract basis function information #
                ######################################

                basis_dict = {"S": 0, "P": 1, "D": 2, "F": 3, "G": 4, "H": 5}

                basis_P = re.compile(r" *[0-9]+ [A-Z]  [0-9]\.[0-9]{8}")
                batom_P = re.compile(r"^  [0-9A-Za-z\-_\.]+ *\([A-Z][a-z]*\)")
                bname_P = re.compile(r"\((.*)\)")
                coord_P = re.compile(r"^ [0-9A-Za-z\.\-_]+ +[- ][0-9\.]{9,}")
                basisStr = filter(basis_P.match, data)
                batomStr = filter(batom_P.match, data)
                coordStr = filter(coord_P.match, data)

                # change 'Sulphur' to 'Sulfur' for NWChem format
                # 'Sulphur' 'Sulfur'
                def atomNameConv(old, new):
                    _matched = filter(lambda x: old in x, batomStr)
                    if _matched:
                        _matched = _matched[0]
                        _s = batomStr.index(_matched)
                        batomStr[_s] = re.sub(old, new, batomStr[_s])
                        _s = data.index(_matched)
                        data[_s] = re.sub(old, new, data[_s])

                atomNameConv('Sulphur', 'Sulfur')
                atomNameConv('Aluminium', 'Aluminum')

                _exponents = [float(filter(None, s.split(' '))\
                  [2]) for s in basisStr]
                _coefficients = [float(filter(None, s.split(' '))\
                  [3]) for s in basisStr]
                _N = [int(filter(None, s.split(' '))[0])\
                  for s in basisStr]
                _type = [filter(None, s.split(' '))[1]\
                  for s in basisStr]
                _bfnInd = [data.index(batom) for batom in batomStr]
                _bfnEndPtn = re.compile(r" Summary of \"")
                _bfnEndStr = filter(_bfnEndPtn.match, data)[0]
                _bfnInd.append(data.index(_bfnEndStr))

                _ao_keys = [0]
                for ind in range(len(_bfnInd) - 1):
                    _key = _ao_keys[-1]
                    for i in range(_bfnInd[ind] + 4, _bfnInd[ind + 1]):
                        if len(data[i]) > 1:
                            _key = _key + 1
                    _ao_keys.append(_key)
                _atoms = [getattr(pt, bname_P.match(
                  filter(None, s.split(' '))[1]).group(1).lower()).symbol\
                  for s in batomStr]
                self.type_list = [re.split(r'[\._]',
                  filter(None, s.split(' '))[0])[0].title()\
                  for s in coordStr]
                self.type_list_unique = list(
                    collections.OrderedDict.fromkeys(self.type_list))
                self.R = np.array([filter(None, s.split(' '))[1:4]\
                  for s in coordStr]).astype(float)
                self.N = len(self.R)
                self.Z = [qtk.n2Z(e) for e in self.type_list]
                self.R_bohr = 1.889725989 * self.R
                ZR = []
                for i in range(self.N):
                    vec = [self.Z[i]]
                    vec.extend(self.R[i])
                    ZR.append(vec)
                self.molecule = qtk.Molecule()
                self.molecule.build(ZR)

                _N.append(0)
                self.basis = []
                for i in range(len(self.type_list)):
                    e = self.type_list[i]
                    center = self.R_bohr[i]
                    ind = self.type_list_unique.index(e)
                    bfn_base = {}
                    bfn_base['atom'] = e
                    bfn_base['center'] = center
                    bfn_base['index'] = i
                    exp = []
                    cef = []
                    for g in range(_ao_keys[ind], _ao_keys[ind + 1]):
                        exp.append(_exponents[g])
                        cef.append(_coefficients[g])
                        if _N[g] != _N[g + 1] or g + 1 >= _ao_keys[ind + 1]:
                            bfn = copy.deepcopy(bfn_base)
                            bfn['exponents'] = copy.deepcopy(exp)
                            bfn['coefficients'] = copy.deepcopy(cef)
                            if _type[g] in basis_dict:
                                _bfnList = self.basisList(basis_dict[_type[g]])
                                for bStr in _bfnList:
                                    bfn['type'] = _type[g].lower() + bStr
                                    self.basis.append(copy.deepcopy(bfn))
                            exp = []
                            cef = []

            try:
                getBasis()
            except AttributeError as err:
                qtk.warning('failed to get basis information with error: %s.'\
                            % err + ' Weird atom names?')

            movecs = os.path.join(self.path, self.stem) + '.modat'
            if os.path.exists(movecs):
                self.getMO(movecs)
Example #3
0
    def __init__(self, qmout=None, **kwargs):
        GaussianBasisOutput.__init__(self, qmout, **kwargs)
        if qmout:
            outfile = open(qmout)
            data = outfile.readlines()

            pattern = re.compile(" *R *M *S *D *=")
            try:
                report = filter(lambda x: "\\" in x, data)
            except Exception as e:
                qtk.exit("error when access final report with message %s" %
                         str(e))
            final_str = ''.join(report)
            final_str = final_str.replace('\n', '')
            final_list = final_str.split('\\')
            try:
                rmsd = filter(pattern.match, final_list)[0]
            except Exception as e:
                qtk.exit("something wrong when accessing final energy" +\
                  " with error message: %s" % str(e))

            ind = final_list.index(rmsd) - 1
            Et_str = final_list[ind]
            term = Et_str.split('=')[0].replace(' ', '')
            E_list = [
                'HF', 'CCSD', 'CCSD(T)', 'MP4SDQ', 'MP4DQ'
                'MP4D', 'MP3', 'MP2', 'HF'
            ]
            while term not in E_list:
                ind = ind - 1
                Et_str = final_list[ind]
                term = Et_str.split('=')[0].replace(' ', '')

            self.Et = float(Et_str.split('=')[1].replace(' ', ''))
            self.detail = final_list

            EJStr = filter(lambda x: 'EJ=' in x, data)
            if len(EJStr) > 0:
                EJStr = EJStr[-1]
                EJind = data.index(EJStr)
                EJStr = data[EJind].replace(' ', '')
                EComponents = filter(None, EJStr.split('E'))
                tags_dict = {
                    'T': 'Ekin',
                    'V': 'Eext',
                    'J': 'Eee',
                    'K': 'Ex',
                    'Nuc': 'Enn',
                }
                for EStr in EComponents:
                    tag, E = EStr.split('=')
                    try:
                        self.energies[tags_dict[tag]] = float(E)
                    except Exception as e:
                        qtk.warning("FORTRAN float overflow " + \
                                    "when extracting energy components for " +\
                                    qmout + " with error message %s" % str(e))
                        self.energies[tags_dict[tag]] = np.nan

            crdStr = filter(lambda x: 'Angstroms' in x, data)[-1]
            ind = len(data) - data[::-1].index(crdStr) + 2
            ZR = []
            while True:
                if not data[ind].startswith(' ---'):
                    crdData = [
                        float(c) for c in filter(None, data[ind].split(' '))
                    ]
                    crd = [crdData[1]]
                    crd.extend(crdData[3:])
                    ZR.append(crd)
                    ind = ind + 1
                else:
                    break
            self.molecule = qtk.Molecule()
            self.molecule.build(ZR)
            self.nuclear_repulsion = self.molecule.nuclear_repulsion()

            force = []
            fStr_list = filter(lambda x: 'Forces (Hartrees' in x, data)
            if len(fStr_list) > 0:
                fStr = fStr_list[-1]
                ind = len(data) - data[::-1].index(fStr) + 2
                for i in range(self.molecule.N):
                    fLst = filter(None, data[ind + i].split(' '))[2:]
                    force.append([float(s) for s in fLst])
                self.force = np.array(force)
            else:
                self.force = np.nan

            dipole = []
            uStr_list = filter(lambda x: 'Debye)' in x, data)
            if len(uStr_list) > 0:
                uStr = uStr_list[-1]
                ind = len(data) - data[::-1].index(uStr)
                dipoleStr = filter(None, data[ind].split(' '))
                for i in [1, 3, 5]:
                    dipole.append(float(dipoleStr[i]))
                self.dipole = np.array(dipole)
            else:
                self.dipole = np.nan

            qp = []
            qStr_list = filter(lambda x: ' Quadrupole moment' in x, data)
            if len(qStr_list) > 0:
                qStr = qStr_list[-1]
                ind = len(data) - data[::-1].index(qStr)
                for i in range(2):
                    tmp = dipoleStr = filter(None, data[ind + i].split(' '))
                    for j in [1, 3, 5]:
                        qp.append(float(tmp[j]))
                xx, yy, zz, xy, xz, yz = qp
                self.quadrupole = np.array([
                    [xx, xy, xz],
                    [xy, yy, yz],
                    [xz, yz, zz],
                ])
            else:
                self.quadrupole = np.nan

            read_fchk = True
            if 'read_fchk' in kwargs:
                read_fchk = kwargs['read_fchk']

            if read_fchk:
                fchk = os.path.join(self.path, self.stem) + ".fchk"
                if os.path.exists(fchk):
                    if 'debug' in kwargs and kwargs['debug']:
                        self.getMO(fchk)
                    else:
                        try:
                            self.getMO(fchk)
                        except Exception as e:
                            qtk.warning("something wrong while loading fchk file"+\
                              " with error message: %s" % str(e))
Example #4
0
  def __init__(self, qmout=None, **kwargs):
    GaussianBasisOutput.__init__(self, qmout, **kwargs)
    if qmout:
      outfile = open(qmout)
      data = outfile.readlines()

      pattern = re.compile(" *R *M *S *D *=")
      try:
        report = filter(lambda x: "\\" in x, data)
      except Exception as e:
        qtk.exit("error when access final report with message %s" % str(e))
      final_str = ''.join(report)
      final_str = final_str.replace('\n', '')
      final_list = final_str.split('\\')
      try:
        rmsd = filter(pattern.match, final_list)[0]
      except Exception as e:
        qtk.exit("something wrong when accessing final energy" +\
          " with error message: %s" % str(e))
        
      ind = final_list.index(rmsd) - 1
      Et_str = final_list[ind]
      term = Et_str.split('=')[0].replace(' ', '')
      E_list = ['HF', 'CCSD', 'CCSD(T)', 'MP4SDQ', 'MP4DQ'
                'MP4D', 'MP3', 'MP2', 'HF']
      while term not in E_list:
        ind = ind - 1
        Et_str = final_list[ind]
        term = Et_str.split('=')[0].replace(' ', '')
        
      self.Et = float(Et_str.split('=')[1].replace(' ',''))
      self.detail = final_list

      EJStr = filter(lambda x: 'EJ=' in x, data)
      if len(EJStr) > 0:
        EJStr = EJStr[-1]
        EJind = data.index(EJStr)
        EJStr = data[EJind].replace(' ', '')
        EComponents = filter(None, EJStr.split('E'))
        tags_dict = {
          'T':'Ekin',
          'V':'Eext',
          'J':'Eee',
          'K':'Ex',
          'Nuc':'Enn',
        }
        for EStr in EComponents:
          tag, E = EStr.split('=')
          try:
	          self.energies[tags_dict[tag]] = float(E)
          except Exception as e:
            qtk.warning("FORTRAN float overflow " + \
                        "when extracting energy components for " +\
                        qmout + " with error message %s" % str(e))
            self.energies[tags_dict[tag]] = np.nan

      crdStr = filter(lambda x: 'Angstroms' in x, data)[-1]
      ind = len(data) - data[::-1].index(crdStr) + 2
      ZR = []
      while True:
        if not data[ind].startswith(' ---'):
          crdData = [float(c) 
                     for c in filter(None, data[ind].split(' '))]
          crd = [crdData[1]]
          crd.extend(crdData[3:])
          ZR.append(crd)
          ind = ind + 1
        else:
          break
      self.molecule = qtk.Molecule()
      self.molecule.build(ZR)
      self.nuclear_repulsion = self.molecule.nuclear_repulsion()

      force = []
      fStr_list = filter(lambda x: 'Forces (Hartrees' in x, data)
      if len(fStr_list) > 0:
        fStr = fStr_list[-1]
        ind = len(data) - data[::-1].index(fStr) + 2
        for i in range(self.molecule.N):
          fLst = filter(None, data[ind+i].split(' '))[2:]
          force.append([float(s) for s in fLst])
        self.force = np.array(force)
      else:
        self.force = np.nan

      dipole = []
      uStr_list = filter(lambda x: 'Debye)' in x, data)
      if len(uStr_list) > 0:
        uStr = uStr_list[-1]
        ind = len(data) - data[::-1].index(uStr)
        dipoleStr = filter(None, data[ind].split(' '))
        for i in [1,3,5]:
          dipole.append(float(dipoleStr[i]))
        self.dipole = np.array(dipole)
      else:
        self.dipole = np.nan

      qp = []
      qStr_list = filter(lambda x: ' Quadrupole moment' in x, data)
      if len(qStr_list) > 0:
        qStr = qStr_list[-1]
        ind = len(data) - data[::-1].index(qStr)
        for i in range(2):
          tmp = dipoleStr = filter(None, data[ind+i].split(' '))
          for j in [1,3,5]:
            qp.append(float(tmp[j]))
        xx, yy, zz, xy, xz, yz = qp
        self.quadrupole = np.array([
          [xx, xy, xz],
          [xy, yy, yz],
          [xz, yz, zz],
        ])
      else:
        self.quadrupole = np.nan

      read_fchk = True
      if 'read_fchk' in kwargs:
        read_fchk = kwargs['read_fchk']

      if read_fchk:
        fchk = os.path.join(self.path, self.stem) + ".fchk"
        if os.path.exists(fchk):
          if 'debug' in kwargs and kwargs['debug']: 
            self.getMO(fchk)
          else:
            try:
              self.getMO(fchk)
            except Exception as e:
              qtk.warning("something wrong while loading fchk file"+\
                " with error message: %s" % str(e))