From: <bao...@us...> - 2006-04-15 08:40:40
|
Revision: 69 Author: baoilleach Date: 2006-04-15 01:40:26 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/cclib/?rev=69&view=rev Log Message: ----------- Adding the bones of a jaguarparser, along with some tests Modified Paths: -------------- trunk/src/cclib/parser/__init__.py trunk/test/testall.py Added Paths: ----------- trunk/src/cclib/parser/jaguarparser.py trunk/test/parseJaguar.py Modified: trunk/src/cclib/parser/__init__.py =================================================================== --- trunk/src/cclib/parser/__init__.py 2006-04-15 04:17:14 UTC (rev 68) +++ trunk/src/cclib/parser/__init__.py 2006-04-15 08:40:26 UTC (rev 69) @@ -1,3 +1,4 @@ from g03parser import G03 from gamessparser import GAMESS from adfparser import ADF +from jaguarparser import Jaguar Added: trunk/src/cclib/parser/jaguarparser.py =================================================================== --- trunk/src/cclib/parser/jaguarparser.py (rev 0) +++ trunk/src/cclib/parser/jaguarparser.py 2006-04-15 08:40:26 UTC (rev 69) @@ -0,0 +1,140 @@ +""" +cclib is a parser for computational chemistry log files. + +See http://cclib.sf.net for more information. + +Copyright (C) 2006 Noel O'Boyle and Adam Tenderholt + + 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 Jaguar(Logfile): + """A Jaguar output file""" + + def __init__(self,*args): + + # Call the __init__ method of the superclass + super(Jaguar, self).__init__(logname="Jaguar",*args) + + def __str__(self): + """Return a string representation of the object.""" + return "Jaguar output file %s" % (self.filename) + + def __repr__(self): + """Return a representation of the object.""" + return 'Jaguar("%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[0:4]=="etot": +# Get SCF convergence information + if not hasattr(self,"scfvalues"): + self.scfvalues = [] + self.logger.info("Creating attribute: scfvalues") + while line[0:4]=="etot": + if line[39:47].strip(): + denergy = float(line[39:47]) + else: + denergy = 0 # Should really be greater than target value + # or should we just ignore the values in this line + ddensity = float(line[48:56]) + maxdiiserr = float(line[57:65]) + self.scfvalues.append([denergy,ddensity,maxdiiserr]) + line = inputfile.next() + + if line[1:5]=="SCFE": +# Get the energy of the molecule + if not hasattr(self,"scfenergies"): + self.logger.info("Creating attribute scfenergies") + self.scfenergies = [] + temp = line.strip().split() + self.scfenergies.append(float(temp[temp.index("hartrees")-1])) + + if line[2:28]=="geometry optimization step": +# Get Geometry Opt convergence information + if not hasattr(self,"geovalues"): + self.geovalues = [] + self.geotargets = Numeric.zeros(4,"float") + self.logger.info("Creating attributes: geovalues,geotargets") + blank = inputfile.next() + blank = inputfile.next() + line = inputfile.next() + i = 0 + values = [] + while line!=blank: + if line[41]=="(": + # A new geo convergence value + values.append(float(line[26:37])) + self.geotargets[i] = float(line[43:54]) + i+=1 + line = inputfile.next() + self.geovalues.append(values) + + if line[2:33]=="Orbital energies/symmetry label": +# Get MO Energies and symmetrys + if not hasattr(self,"moenergies"): + self.logger.info("Creating attributes: moenergies, mosyms") + self.mosyms = [[]] + self.moenergies = [[]] + line = inputfile.next() + while line.strip(): + temp = line.strip().split() + for i in range(0,len(temp),2): + self.moenergies[0].append(float(temp[i])) + self.mosyms[0].append(temp[i+1]) + line = inputfile.next() + self.moenergies = Numeric.array(self.moenergies,"f") + + if line[1:28]=="number of occupied orbitals": + if not hasattr(self,"homos"): + self.logger.info("Creating attribute: homos") + self.homos = Numeric.array([float(line.strip().split()[-1])-1],"i") + + if line[2:27]=="number of basis functions": + if not hasattr(self,"nbasis"): + self.logger.info("Creating attribute: nbasis") + self.nbasis = float(line.strip().split()[-1]) + + inputfile.close() + + if hasattr(self,"scfvalues"): + self.scfvalues = Numeric.array(self.scfvalues,"f") + if hasattr(self,"scfenergies"): + self.scfenergies = Numeric.array(self.scfenergies,"f") + +if __name__=="__main__": + import doctest,g03parser + doctest.testmod(g03parser,verbose=False) Property changes on: trunk/src/cclib/parser/jaguarparser.py ___________________________________________________________________ Name: svn:executable + * Added: trunk/test/parseJaguar.py =================================================================== --- trunk/test/parseJaguar.py (rev 0) +++ trunk/test/parseJaguar.py 2006-04-15 08:40:26 UTC (rev 69) @@ -0,0 +1,14 @@ +import os +from cclib.parser import Jaguar + +os.chdir(os.path.join("..","data","Jaguar","basicJaguar")) + +os.chdir("eg01") + +for file in ["dvb_gopt.out"]: + t = Jaguar(file) + t.parse() + +print t.moenergies[0,:] +print t.homos[0] +print t.moenergies[0,t.homos[0]] Property changes on: trunk/test/parseJaguar.py ___________________________________________________________________ Name: svn:executable + * Modified: trunk/test/testall.py =================================================================== --- trunk/test/testall.py 2006-04-15 04:17:14 UTC (rev 68) +++ trunk/test/testall.py 2006-04-15 08:40:26 UTC (rev 69) @@ -1,5 +1,5 @@ import os, unittest -from cclib.parser import GAMESS,G03,ADF +from cclib.parser import GAMESS,G03,ADF,Jaguar from Numeric import array class GenericGeoOptTest(unittest.TestCase): @@ -12,7 +12,7 @@ self.assertEquals(self.data.natom,20) def testnbasis(self): - """Is the number of basis set function equal to 60?""" + """Is the number of basis set functions equal to 60?""" self.assertEquals(self.data.nbasis,60) def testscfenergy(self): @@ -39,9 +39,13 @@ def setUp(self): self.data = getfile(ADF,"basicADF2004.01","dvb_gopt.adfout") +class JaguarGeoOptTest(GenericGeoOptTest): + def setUp(self): + self.data = getfile(Jaguar,"basicJaguar","eg01","dvb_gopt.out") + def getfile(parser,*location): """Returns a parsed logfile.""" - if parser.__name__ in ['GAMESS','ADF']: + if parser.__name__ in ['GAMESS','ADF','Jaguar']: fullpath = ("..","data",parser.__name__) + location elif parser.__name__=="G03": fullpath = ("..","data","Gaussian") + location @@ -55,7 +59,8 @@ logfiles = [ getfile(G03,"basicGaussian03","dvb_gopt.out"), getfile(GAMESS,"basicPCGAMESS","dvb_gopt_a.out"), getfile(GAMESS,"basicGAMESS-US","dvb_gopt_a.out"), - getfile(ADF,"basicADF2004.01","dvb_gopt.adfout") ] + getfile(ADF,"basicADF2004.01","dvb_gopt.adfout"), + getfile(Jaguar,"basicJaguar","eg01","dvb_gopt.out")] print "\n\nMO energies of optimised dvb" print " ","".join(["%8s" % x for x in ['Gaussian','PCGAMESS','GAMESS-US','ADF']]) @@ -72,6 +77,7 @@ pcgamesstests = unittest.makeSuite(PCGamessGeoOptTest) gamessustests = unittest.makeSuite(GamessUSGeoOptTest) adftests = unittest.makeSuite(ADFGeoOptTest) + jaguartests = unittest.makeSuite(JaguarGeoOptTest) print "\n*** Testing Gaussian dvb_gopt.out ***" unittest.TextTestRunner(verbosity=2).run(gaussiantests) print "\n\n*** Testing PCGAMESS dvb_gopt_a.out ***" @@ -80,5 +86,7 @@ unittest.TextTestRunner(verbosity=2).run(gamessustests) print "\n\n*** Testing ADF dvb_gopt.adfout ***" unittest.TextTestRunner(verbosity=2).run(adftests) + print "\n\n*** Testing Jaguar dvb_gopt.out ***" + unittest.TextTestRunner(verbosity=2).run(jaguartests) print "\n\n*** Visual tests ***" visualtests() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |