/rmgpy/qm/qmverifier.py

https://github.com/shamelmerchant/RMG-Py · Python · 71 lines · 39 code · 12 blank · 20 comment · 9 complexity · a3c7f6ec301bd528826b81b9758f7e17 MD5 · raw file

  1. """
  2. Created on Apr 29, 2012
  3. @author: nmvdewie
  4. """
  5. import os
  6. import logging
  7. class QMVerifier:
  8. """
  9. Verifies whether a QM job (externalized) was succesfully completed by
  10. * searching for specific keywords in the output files,
  11. * located in a specific directory (e.g. "QMFiles")
  12. """
  13. def __init__(self,molfile):
  14. self.molfile = molfile
  15. self.gaussianResultExists = False
  16. self.mopacResultExists = False
  17. self.mm4ResultExists = False
  18. self.outputExtension = '.out'
  19. self.inputExtension = '.mop'
  20. def checkForInChiKeyCollision(self,logFileInChI):
  21. """
  22. This method is designed in the case a MOPAC output file was found but the InChI found in the file did not
  23. correspond to the InChI of the given molecule.
  24. This could mean two things:
  25. 1) that the InChI Key hash does not correspond to the InChI it is hashed from. This is the rarest case of them all
  26. 2) the complete InChI did not fit onto just one line in the MOPAC output file. Therefore it was continued on the
  27. second line and only a part of the InChI was actually taken as the 'whole' InChI.
  28. This method reads in the MOPAC input file and compares the found InChI in there to the InChI of the given molecule.
  29. """
  30. # if InChIPartialMatch == 1:#case where the InChI in memory begins with the InChI in the log file we will continue and check the input file, pring a warning if there is no match
  31. #look in the input file if the InChI doesn't match (apparently, certain characters can be deleted in MOPAC output file for long InChIs)
  32. inputFile = os.path.join(self.molfile.directory,self.molfile.name+self.inputExtension)
  33. assert os.path.exists(inputFile)
  34. with open(inputFile) as inputFile:#read the MOPAC inputFile
  35. lineI = inputFile.readline()
  36. for line in inputFile:
  37. if line.startswith("InChI="):
  38. inputFileInChI = lineI.rstrip()
  39. break
  40. if inputFileInChI == self.molfile.InChIAug:
  41. logging.info('An InChI match could be found in the input file, but not in the output file. Anywho, a\
  42. pre-existing successful MOPAC result exists.')
  43. return True
  44. else:
  45. logging.info("*****Warning: potential InChIKey collision: InChIKey(augmented) = " +
  46. self.molfile.name + " RMG Augmented InChI = "+ self.molfile.InChIAug +
  47. " Log file Augmented InChI = "+logFileInChI +
  48. " . InChI could not be found in the MOPAC input file. You should manually check that the output file contains the ended species.")
  49. return False
  50. #returns True if an MM4 output file for the given name and directory (.mm4out suffix) exists and indicates successful completion (same criteria as used after calculation runs) terminates if the InChI doesn't match the InChI in the file or if there is no InChI in the file returns False otherwise
  51. def succesfulJobExists(self):
  52. """
  53. checks whether one of the flags is true.
  54. If so, it returns true.
  55. """
  56. return self.gaussianResultExists or self.mopacResultExists or self.mm4ResultExists