cclib / cclib

Parsers and algorithms for computational chemistry logfiles
https://cclib.github.io/
BSD 3-Clause "New" or "Revised" License
331 stars 168 forks source link

Use of logging utilities #237

Open berquist opened 8 years ago

berquist commented 8 years ago

Should we be more liberal with the use of the logger? It seems like a very nice thing to have that isn't being taken advantage of. This is all we have right now:

./molproparser.py:467:                            self.logger.warn("setting mocoeff element to zero: %s" % detail)
./molproparser.py:736:            self.logger.info("Creating attribute hessian")
./gaussianparser.py:458:                    self.logger.debug(line)
./gaussianparser.py:621:                self.logger.debug(line)
./gaussianparser.py:626:                    self.logger.error("Problem parsing the value for geometry optimisation: %s is not a number." % parts[2])
./gaussianparser.py:1028:                self.logger.debug(parts)
./gaussianparser.py:1122:                    self.logger.warning("Number of basis functions (nbasis) has changed from %i to %i" % (self.nbasis, nbasis))
./gaussianparser.py:1213:                    self.logger.warning("Molecular coefficients header found but no coefficients.")
./orcaparser.py:190:                self.logger.warning('The geotargets attribute should not exist yet. There is a problem in the parser.')
./orcaparser.py:544:                self.logger.warning(msg)
./orcaparser.py:707:                    self.logger.warning('Overwriting previous multipole moments with new values')
./nwchemparser.py:552:                            self.logger.warning("Symmetry of MO %i has changed" % (index+1))
./nwchemparser.py:905:                self.logger.warning("Found quadrupole moments but no previous dipole")
./nwchemparser.py:960:                self.logger.warning("Found octupole moments but no previous dipole or quadrupole moments")
./nwchemparser.py:963:                self.logger.warning("Found octupole moments but no previous quadrupole moments")
./nwchemparser.py:1021:            self.logger.warning("Found a non-standard aoname representation type.")
./nwchemparser.py:1034:                self.logger.warning(msg)
./gamessparser.py:653:                    self.logger.warning(msg)
./gamessparser.py:658:                    self.logger.warning("\n   " + "\n   ".join((line1, line2, line3)))
./gamessparser.py:886:                    self.logger.warning('MO section found but could not be parsed!')
./gamessparser.py:1076:                            self.logger.warning("Number of occupied orbitals not consistent. This is normal for ECP and FMO jobs.")
./gamessparser.py:1118:                self.logger.info("Reading additional aooverlaps...")
./gamessparser.py:1248:                    self.logger.warning('Overwriting previous multipole moments with new values')
./gamessparser.py:1249:                    self.logger.warning('This could be from post-HF properties or geometry optimization')
./psiparser.py:758:                    self.logger.warning('Overwriting previous multipole moments with new values')
./psiparser.py:759:                    self.logger.warning('This could be from post-HF properties or geometry optimization')
./adfparser.py:121:            self.logger.warning("Skipping remaining calculations")
./adfparser.py:351:                    self.logger.warning("SCF did not converge, so attributes may be missing")
./adfparser.py:355:                self.logger.warning("SCF not fully converged, results acceptable")
./adfparser.py:358:                self.logger.warning("SCF did not converge! moenergies and mocoeffs are unreliable")
./adfparser.py:539:                self.logger.warning("MO info up to #%s is missing" % info[0])
./adfparser.py:1040:                            self.logger.warning("Etsecs are not accurate!")
./adfparser.py:1047:                            self.logger.warning("Etsecs are not accurate!")
./adfparser.py:1128:                    self.logger.warning('Overwriting previous multipole moments with new values')
./logfileparser.py:227:        self.logger = logging.getLogger('%s %s' % (self.logname, self.filename))
./logfileparser.py:228:        self.logger.setLevel(self.loglevel)
./logfileparser.py:229:        if len(self.logger.handlers) == 0:
./logfileparser.py:232:            self.logger.addHandler(handler)
./logfileparser.py:257:                    self.logger.info("Creating attribute %s[]" % name)
./logfileparser.py:259:                    self.logger.info("Creating attribute %s: %s" % (name, str(value)))
./logfileparser.py:415:                self.logger.warning("Attribute %s changed value (%s -> %s)" % (name, getattr(self, name), value))
./logfileparser.py:450:                    self.logger.warning(msg)
./logfileparser.py:461:                        self.logger.warning(msg)

If so, it would be rather tedious to go back to each of the parsers and duplicate the same message everywhere, since most of the messages probably shouldn't be unique to specific parsers or programs. Could there be a way to have a set_attribute hook to spit out a message that's attribute dependent? For example, when setting etenergies, a warning for negative excitation energies, or for vibfreqs, a warning for imaginary frequencies.

At least, when we (eventually) update the documentation, we might want some guidelines on using the logger for people who contribute.

langner commented 8 years ago

Definitely. I agree that verboseness is always a good thing, and you're spot on with the set_attribute trigger. If there's too much output, it can always be modulated with an option/flag.

langner commented 5 years ago

OK, I did a little bit to start, but pushing the rest back to v1.6.2.