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 |