<commit_before>"""
cclib is a parser for computational chemistry log files.

See http://cclib.sf.net for more information.

Copyright (C) 2006 <NAME> and <NAME>

 This program is free software; you can redistribute and/or modify it
 under the terms of the GNU General Public License as published by the
 Free Software Foundation; either version 2, 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.

Contributions (monetary as well as code :-) are encouraged.
"""
import re,time
import Numeric
import random # For sometimes running the progress updater
from logfileparser import Logfile,convertor

class ADF(Logfile):
    """A Gaussian 98/03 log file"""
    SCFRMS,SCFMAX,SCFENERGY = range(3) # Used to index self.scftargets[]
    def __init__(self,*args):

        # Call the __init__ method of the superclass
        super(ADF, self).__init__(logname="ADF",*args)
        
    def __str__(self):
        """Return a string representation of the object."""
        return "ADF log file %s" % (self.filename)

    def __repr__(self):
        """Return a representation of the object."""
        return 'ADF("%s")' % (self.filename)

    def parse(self,fupdate=0.05,cupdate=0.002):
        """Extract information from the logfile."""
        inputfile = open(self.filename,"r")
        
        if self.progress:
            
            inputfile.seek(0,2) #go to end of file
            nstep=inputfile.tell()
            inputfile.seek(0)
            self.progress.initialize(nstep)
            oldstep=0
            
        for line in inputfile:
            
            if self.progress and random.random()<cupdate:
                
                step = inputfile.tell()
                if step!=oldstep:
                    self.progress.update(step,"Unsupported Information")
                    oldstep = step
                
            if line.find("INPUT FILE")>=0:
#check to make sure we aren't parsing Create jobs
                line2=inputfile.next()
                while line:
                    if line.find("Create")<0:
                        break
                    
                    if self.progress and random.random()<cupdate:
                        step=inputfile.tell()
                        if step!=oldstep:
                            self.progress.update(step,"Unsupported Information")
                            oldstep=step
                            
            
            if line[1:6]=="ATOMS":
# Find the number of atoms and their atomic numbers
                if self.progress and random.random()<cupdate:
                    step=inputfile.tell()
                    if step!=oldstep:
                        self.progress.update(step,"Attributes")
                        oldstep=step
                
                self.logger.info("Creating attribute atomnos[]")
                self.atomnos=[]
                
                underline=inputfile.next()  #clear pointless lines
                label1=inputfile.next()     # 
                label2=inputfile.next()     #
                line=inputfile.next()
                while len(line)>1: #ensure that we are reading no blank lines
                    info=line.split()
                    self.atomnos.append(self.table.number[info[1]])
                    line=inputfile.next()
                
                self.natom=len(self.atomnos)
                self.logger.info("Creating attribute natom: %d" % self.natom)
                
#             if line[1:44]=='Requested convergence on RMS density matrix':
# # Find the targets for SCF convergence (QM calcs)                
#                 if not hasattr(self,"scftargets"):
#                     self.logger.info("Creating attribute scftargets[]")
#                 self.scftargets = Numeric.array([0.0,0.0,0.0],'f')
#                 self.scftargets[G03.SCFRMS] = self.float(line.split('=')[1].split()[0])
#             if line[1:44]=='Requested convergence on MAX density matrix':
#                 self.scftargets[G03.SCFMAX] = self.float(line.strip().split('=')[1][:-1])
#             if line[1:44]=='Requested convergence on             energy':
#                 self.scftargets[G03.SCFENERGY] = self.float(line.strip().split('=')[1][:-1])
# 
#             if line[1:10]=='Cycle   1':
# # Extract SCF convergence information (QM calcs)
#                 if self.progress and random.random()<fupdate:
#                     step=inputfile.tell()
#                     if step!=oldstep:
#                         self.progress.update(step,"QM Convergence")
#                         oldstep=step
#                         
#                 if not hasattr(self,"scfvalues"):
#                     self.logger.info("Creating attribute scfvalues")
#                     self.scfvalues = []
#                 newlist = [ [] for x in self.scftargets ]
#                 line = inputfile.next()
#                 while line.find("SCF Done")==-1:
#                     if line.find(' E=')==0:
#                         self.logger.debug(line)
#                     if line.find(" RMSDP")==0:
#                         parts = line.split()
#                         newlist[G03.SCFRMS].append(self.float(parts[0].split('=')[1]))
#                         newlist[G03.SCFMAX].append(self.float(parts[1].split('=')[1]))
#                         energy = 1.0
#                         if len(parts)>4:
#                             energy = parts[2].split('=')[1]
#                             if energy=="":
#                                 energy = self.float(parts[3])
#                             else:
#                                 energy = self.float(energy)
#                         # I moved the following line back a TAB to see the effect
#                         # (it was originally part of the above "if len(parts)")
#                         newlist[G03.SCFENERGY].append(energy)
#                     try:
#                         line = inputfile.next()
#                     except StopIteration: # May be interupted by EOF
#                         break
#                 self.scfvalues.append(newlist)
# 
#             if line[1:4]=='It=':
# # Extract SCF convergence information (AM1 calcs)
#                 if self.progress:
#                     step=inputfile.tell()
#                     if step!=oldstep:
#                         self.progress.update(step,"AM1 Convergence")
#                         oldstep=step
#                         
#                 self.logger.info("Creating attributes scftargets, scfvalues")
#                 self.scftargets = Numeric.array([1E-7],"f") # This is the target value for the rms
#                 self.scfvalues = [[]]
#                 line = inputfile.next()
#                 while line.find(" Energy")==-1:
#                     parts = line.strip().split()
#                     self.scfvalues[0].append(self.float(parts[-1][:-1]))
#                     line = inputfile.next()
# 
#             if line[1:9]=='SCF Done':
# # Note: this needs to follow the section where 'SCF Done' is used to terminate
# # a loop when extracting SCF convergence information
#                 if not hasattr(self,"scfenergies"):
#                     self.logger.info("Creating attribute scfenergies[]")
#                     self.scfenergies = []
#                 self.scfenergies.append(self.float(line.split()[4]))
# 
#             if line[49:59]=='Converged?':
# # Extract Geometry convergence information
#                 if not hasattr(self,"geotargets"):
#                     self.logger.info("Creating attributes geotargets[],geovalues[[]]")
#                     self.geovalues = []
#                     self.geotargets = Numeric.array( [0.0,0.0,0.0,0.0],"f")
#                 newlist = [0]*4
#                 for i in range(4):
#                     line = inputfile.next()
#                     self.logger.debug(line)
#                     parts = line.split()
#                     try:
#                         value = self.float(parts[2])
#                     except ValueError:
#                         self.logger.error("Problem parsing the value for geometry optimisation: %s is not a number." % parts[2])
#                     else:
#                         newlist[i] = value
#                     self.geotargets[i] = self.float(parts[3])
#                 self.geovalues.append(newlist)
# 
#             if line[1:19]=='Orbital symmetries' and not hasattr(self,"mosyms"):
# # Extracting orbital symmetries
#                 if self.progress and random.random()<fupdate:<commit_msg>parse moenergies,mosyms (only restricted calcs)<commit_after>"""
cclib is a parser for computational chemistry log files.

See http://cclib.sf.net for more information.

Copyright (C) 2006 <NAME> and <NAME>

 This program is free software; you can redistribute and/or modify it
 under the terms of the GNU General Public License as published by the
 Free Software Foundation; either version 2, 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.

Contributions (monetary as well as code :-) are encouraged.
"""
import re,time
import Numeric
import random # For sometimes running the progress updater
from logfileparser import Logfile,convertor

class ADF(Logfile):
    """A Gaussian 98/03 log file"""
    SCFRMS,SCFMAX,SCFENERGY = range(3) # Used to index self.scftargets[]
    def __init__(self,*args):

        # Call the __init__ method of the superclass
        super(ADF, self).__init__(logname="ADF",*args)
        
    def __str__(self):
        """Return a string representation of the object."""
        return "ADF log file %s" % (self.filename)

    def __repr__(self):
        """Return a representation of the object."""
        return 'ADF("%s")' % (self.filename)

    def parse(self,fupdate=0.05,cupdate=0.002):
        """Extract information from the logfile."""
        inputfile = open(self.filename,"r")
        
        if self.progress:
            
            inputfile.seek(0,2) #go to end of file
            nstep=inputfile.tell()
            inputfile.seek(0)
            self.progress.initialize(nstep)
            oldstep=0
            
        for line in inputfile:
            
            if self.progress and random.random()<cupdate:
                
                step = inputfile.tell()
                if step!=oldstep:
                    self.progress.update(step,"Unsupported Information")
                    oldstep = step
                
            if line.find("INPUT FILE")>=0:
#check to make sure we aren't parsing Create jobs
                while line:
                    if line.find("INPUT FILE")>=0:
                      line2=inputfile.next()
                    if line2.find("Create")<0:
                      break
                    
                    if self.progress and random.random()<cupdate:
                      step=inputfile.tell()
                      if step!=oldstep:
                          self.progress.update(step,"Unsupported Information")
                          oldstep=step
                            
                    line=inputfile.next()
            
            if line[1:6]=="ATOMS":
# Find the number of atoms and their atomic numbers
                if self.progress and random.random()<cupdate:
                    step=inputfile.tell()
                    if step!=oldstep:
                        self.progress.update(step,"Attributes")
                        oldstep=step
                
                self.logger.info("Creating attribute atomnos[]")
                self.atomnos=[]
                
                underline=inputfile.next()  #clear pointless lines
                label1=inputfile.next()     # 
                label2=inputfile.next()     #
                line=inputfile.next()
                while len(line)>1: #ensure that we are reading no blank lines
                    info=line.split()
                    self.atomnos.append(self.table.number[info[1]])
                    line=inputfile.next()
                
                self.natom=len(self.atomnos)
                self.logger.info("Creating attribute natom: %d" % self.natom)
                
#             if line[1:44]=='Requested convergence on RMS density matrix':
# # Find the targets for SCF convergence (QM calcs)                
#                 if not hasattr(self,"scftargets"):
#                     self.logger.info("Creating attribute scftargets[]")
#                 self.scftargets = Numeric.array([0.0,0.0,0.0],'f')
#                 self.scftargets[G03.SCFRMS] = self.float(line.split('=')[1].split()[0])
#             if line[1:44]=='Requested convergence on MAX density matrix':
#                 self.scftargets[G03.SCFMAX] = self.float(line.strip().split('=')[1][:-1])
#             if line[1:44]=='Requested convergence on             energy':
#                 self.scftargets[G03.SCFENERGY] = self.float(line.strip().split('=')[1][:-1])
# 
#             if line[1:10]=='Cycle   1':
# # Extract SCF convergence information (QM calcs)
#                 if self.progress and random.random()<fupdate:
#                     step=inputfile.tell()
#                     if step!=oldstep:
#                         self.progress.update(step,"QM Convergence")
#                         oldstep=step
#                         
#                 if not hasattr(self,"scfvalues"):
#                     self.logger.info("Creating attribute scfvalues")
#                     self.scfvalues = []
#                 newlist = [ [] for x in self.scftargets ]
#                 line = inputfile.next()
#                 while line.find("SCF Done")==-1:
#                     if line.find(' E=')==0:
#                         self.logger.debug(line)
#                     if line.find(" RMSDP")==0:
#                         parts = line.split()
#                         newlist[G03.SCFRMS].append(self.float(parts[0].split('=')[1]))
#                         newlist[G03.SCFMAX].append(self.float(parts[1].split('=')[1]))
#                         energy = 1.0
#                         if len(parts)>4:
#                             energy = parts[2].split('=')[1]
#                             if energy=="":
#                                 energy = self.float(parts[3])
#                             else:
#                                 energy = self.float(energy)
#                         # I moved the following line back a TAB to see the effect
#                         # (it was originally part of the above "if len(parts)")
#                         newlist[G03.SCFENERGY].append(energy)
#                     try:
#                         line = inputfile.next()
#                     except StopIteration: # May be interupted by EOF
#                         break
#                 self.scfvalues.append(newlist)
# 
#             if line[1:4]=='It=':
# # Extract SCF convergence information (AM1 calcs)
#                 if self.progress:
#                     step=inputfile.tell()
#                     if step!=oldstep:
#                         self.progress.update(step,"AM1 Convergence")
#                         oldstep=step
#                         
#                 self.logger.info("Creating attributes scftargets, scfvalues")
#                 self.scftargets = Numeric.array([1E-7],"f") # This is the target value for the rms
#                 self.scfvalues = [[]]
#                 line = inputfile.next()
#                 while line.find(" Energy")==-1:
#                     parts = line.strip().split()
#                     self.scfvalues[0].append(self.float(parts[-1][:-1]))
#                     line = inputfile.next()
# 
#             if line[1:9]=='SCF Done':
# # Note: this needs to follow the section where 'SCF Done' is used to terminate
# # a loop when extracting SCF convergence information
#                 if not hasattr(self,"scfenergies"):
#                     self.logger.info("Creating attribute scfenergies[]")
#                     self.scfenergies = []
#                 self.scfenergies.append(self.float(line.split()[4]))
# 
#             if line[49:59]=='Converged?':
# # Extract Geometry convergence information
#                 if not hasattr(self,"geotargets"):
#                     self.logger.info("Creating attributes geotargets[],geovalues[[]]")
#                     self.geovalues = []
#                     self.geotargets = Numeric.array( [0.0,0.0,0.0,0.0],"f")
#                 newlist = [0]*4
#                 for i in range(4):
#                     line = inputfile.next()
#                     self.logger.debug(line)
#                     parts = line.split()
#                     try:
#                         value = self.float(parts[2])
#                     except ValueError:
#                         self.logger.error("Problem parsing the value for geometry optimisation: %s is not a number." % parts[2])
#                     else:
#                         newlist[i] = value
#                     self.geotargets[i] = self.float(parts[3])
#                 self.geovalues.append(newlist)
# 
            if line[1:29]=='Orbital Energies, all Irreps' and not hasattr(self,"mosyms"):
#Extracting orbital symmetries and energies
              self.logger.info("Creating attribute mosyms[[]]")
              self.mosyms=[[]]
              
              self.logger.info("Creating attribute moenergies[[]]")
              self.moenergies=[[]]
              
              underline=inputfile.next()
              blank=inputfile.next()
              header=inputfile.next()
              underline2=inputfile.next()
              line=inputfile.next()
              
              while len(line)>1:
                info=line.split()
                if len(info)==5: #this is restricted
                  self.mosyms[0].append(info[0])
                  self.moenergies[0].append(convertor(float(info[3]),'hartree','eV'))
                  line=inputfile.next()
              self.moenergies=Numeric.array(self.moenergies,"f")
              
#             if line[1:19]=='Orbital symmetries' and not hasattr(self,"mosyms"):
# # Extracting orbital symmetries
#                 if self.progress and random.random()<fupdate:
{'fraction_non_alphanumeric': 0.11353875885763368, 'fraction_numerical': 0.012883830792355593, 'mean_word_length': 1.4579759862778732, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6318793', 'n_tokens_mistral': 5152, 'n_tokens_neox': 4825, 'n_words': 1159}