From: Xaver W. <xav...@we...> - 2009-11-30 15:22:17
|
Hi guys, I've got a few questions about using cclib. Actually, Noel asked me to cc them here, but I thought it might make sense to generally discuss them here. I hope they're not too much "newbie-questions", because I'm not really advanced in programming and python. -In which case is the variable 'scfvalues' (not) created? I tried to get it with a couple of gaussian03 log files, but it was never existant. -When is cclib closing its input file? From my understanding of the source code, that should be done after parsing (?! logparser.py/line 145 in current stable), but it seems the files are still open when testing it in a python console. Just wondering if I have to do anything to cleanly have all files closed at the end of my code. - Can I trick cclib into reading a string instead of a file? Noel pointed me to StringIO objects. However, StringIO simulates an "opened file" while cclib needs a non-open file, right?: >>> mimicfile=StringIO.StringIO(" Entering Gaussian System, Link 0=/opt/g03/g03/g03\n SCF Done: E(UB+HF-LYP) = -887.172106755 A.U. after 59 cycles") >>> myfile = cclib.parser.Gaussian("mimicfile") >>> print myfile Gaussian log file mimicfile >>> myfile.parse() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/site-packages/cclib/parser/logfileparser.py", line 104, in parse inputfile = utils.openlogfile(self.filename) File "/usr/lib/python2.6/site-packages/cclib/parser/utils.py", line 61, in openlogfile fileobject = open(filename, "r") IOError: [Errno 2] No such file or directory: 'mimicfile' >>> cclib.parser.ccopen(mimicfile) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/site-packages/cclib/parser/utils.py", line 96, in ccopen for line in inputfile: File "/usr/lib/python2.6/fileinput.py", line 253, in next line = self.readline() File "/usr/lib/python2.6/fileinput.py", line 343, in readline self._file = self._openhook(self._filename, self._mode) File "/usr/lib/python2.6/fileinput.py", line 387, in hook_compressed return open(filename, mode) IOError: [Errno 2] No such file or directory: ' Entering Gaussian System, Link 0=/opt/g03/g03/g03\n' Thanks in advance, Xaver W. |
From: Noel O'B. <bao...@gm...> - 2009-11-30 15:29:17
|
2009/11/30 Xaver Wurzenberger <xav...@we...>: > Hi guys, > > I've got a few questions about using cclib. Actually, Noel asked me to cc them > here, but I thought it might make sense to generally discuss them here. I > hope they're not too much "newbie-questions", because I'm not really advanced > in programming and python. > > -In which case is the variable 'scfvalues' (not) created? > I tried to get it with a couple of gaussian03 log files, but it was never > existant. If the values are present, they will be parsed, so this may be a bug. > -When is cclib closing its input file? > From my understanding of the source code, that should be done after > parsing (?! logparser.py/line 145 in current stable), but it seems the files > are still open when testing it in a > python console. Just wondering if I have to do anything to cleanly have all > files closed at the end of my code. How did you test that the file is still open? > - Can I trick cclib into reading a string instead of a file? Noel pointed me > to StringIO objects. However, StringIO > simulates an "opened file" while cclib needs a non-open file, right?: >>>> mimicfile=StringIO.StringIO(" Entering Gaussian System, Link > 0=/opt/g03/g03/g03\n SCF Done: E(UB+HF-LYP) = -887.172106755 A.U. after > 59 cycles") >>>> myfile = cclib.parser.Gaussian("mimicfile") You passed the string mimicfile - you should pass the variable, e.g. Gaussian(mimicfile). However, cclib has been written to parse entire files, not portions of files, so this example may not work. > > Thanks in advance, > Xaver W. > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > cclib-devel mailing list > ccl...@li... > https://lists.sourceforge.net/lists/listinfo/cclib-devel > |
From: Karol M. L. <kar...@gm...> - 2009-11-30 17:59:51
|
On Monday 30 November 2009 16:29:04 Noel O'Boyle wrote: > > - Can I trick cclib into reading a string instead of a file? Noel > > pointed me to StringIO objects. However, StringIO > > > > simulates an "opened file" while cclib needs a non-open file, right?: > >>>> mimicfile=StringIO.StringIO(" Entering Gaussian System, Link > > > > 0=/opt/g03/g03/g03\n SCF Done: E(UB+HF-LYP) = -887.172106755 > > A.U. after 59 cycles") > > > >>>> myfile = cclib.parser.Gaussian("mimicfile") > > You passed the string mimicfile - you should pass the variable, e.g. > Gaussian(mimicfile). However, cclib has been written to parse entire > files, not portions of files, so this example may not work. Let met just input on this at the moment. In fact cclib.parser.ccopen can process an input stream, which can an open file object or instance of StringIO.StringIO. Generally, whatever can be read and implements 'read', 'next' and other methods. >>> import cclib >>> print cclib.parser.ccopen.__doc__ Guess the identity of a particular log file and return an instance of it. Inputs: source - a single logfile, a list of logfiles, or an input stream Returns: one of ADF, GAMESS, GAMESS UK, Gaussian, Jaguar, Molpro, ORCA, or None (if it cannot figure it out or the file does not exist). Currently passing a string would generate an error, but that functionality could be added quite easily. If needed, please file a feature request and I'm sure Noel or I could implement it pretty fast. - Karol -- written by Karol Langner Mon Nov 30 19:03:23 CET 2009 |
From: Xaver W. <xav...@we...> - 2009-12-04 16:38:11
|
Hi, OK, since you seem to be talking about the latest svn code, I got the latest revision now. > Let met just input on this at the moment. In fact cclib.parser.ccopen can > process an input stream, which can an open file object or instance of > StringIO.StringIO. Generally, whatever can be read and > implements 'read', 'next' and other methods. I don't get errors while Gaussian(stringiofile).parse(), so it seems to generally work. However, I don't get an scfenergies attribute from StringIO.StringIO(" Entering Gaussian System, Link 0=/opt/g03/g03/g03\n SCF Done: E(UB+HF-LYP) = -887.172106755 A.U. after 59 cycles") , and ccopen() doesn't recognize it as Gaussian type. Well, I guess that's because cclib is not really made to handle small fake logfiles. As I don't have the time to test how to trick it, I think I'll take Karol's friendly offer and put sth like that as a feature request on sourceforge... (But first I'll wait if it is a bug that sometimes, I don't get an scfvalues attribute even for real gaussian03 log files. I'll post a bug report on that) > How did you test that the file is still open? I can't remember, but it doesn't matter. I'd just like to know if I have to 'do' sth to cleanly close my log files at the end of my program code. You know, sth like ccopen(myfile) ... ccclose(myfile) ...or does cclib handle this? Regards, Xaver Am Monday 30 November 2009 19:09:57 schrieb Karol M. Langner: > On Monday 30 November 2009 16:29:04 Noel O'Boyle wrote: > > > - Can I trick cclib into reading a string instead of a file? Noel > > > pointed me to StringIO objects. However, StringIO > > > > > > simulates an "opened file" while cclib needs a non-open file, right?: > > >>>> mimicfile=StringIO.StringIO(" Entering Gaussian System, Link > > > > > > 0=/opt/g03/g03/g03\n SCF Done: E(UB+HF-LYP) = -887.172106755 > > > A.U. after 59 cycles") > > > > > >>>> myfile = cclib.parser.Gaussian("mimicfile") > > > > You passed the string mimicfile - you should pass the variable, e.g. > > Gaussian(mimicfile). However, cclib has been written to parse entire > > files, not portions of files, so this example may not work. > > Let met just input on this at the moment. In fact cclib.parser.ccopen can > process an input stream, which can an open file object or instance of > StringIO.StringIO. Generally, whatever can be read and > implements 'read', 'next' and other methods. > > >>> import cclib > >>> print cclib.parser.ccopen.__doc__ > > Guess the identity of a particular log file and return an instance of it. > > Inputs: > source - a single logfile, a list of logfiles, or an input stream > > Returns: > one of ADF, GAMESS, GAMESS UK, Gaussian, Jaguar, Molpro, ORCA, or > None (if it cannot figure it out or the file does not exist). > > Currently passing a string would generate an error, but that functionality > could be added quite easily. If needed, please file a feature request and > I'm sure Noel or I could implement it pretty fast. > > - Karol |