PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/rmgpy/qm/qmverifier.py

https://github.com/GreenGroup/RMG-Py
Python | 98 lines | 60 code | 5 blank | 33 comment | 0 complexity | 0d7cc3b1a2289379bbad3cd25fa245b1 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. #!/usr/bin/env python3
  2. ###############################################################################
  3. # #
  4. # RMG - Reaction Mechanism Generator #
  5. # #
  6. # Copyright (c) 2002-2021 Prof. William H. Green (whgreen@mit.edu), #
  7. # Prof. Richard H. West (r.west@neu.edu) and the RMG Team (rmg_dev@mit.edu) #
  8. # #
  9. # Permission is hereby granted, free of charge, to any person obtaining a #
  10. # copy of this software and associated documentation files (the 'Software'), #
  11. # to deal in the Software without restriction, including without limitation #
  12. # the rights to use, copy, modify, merge, publish, distribute, sublicense, #
  13. # and/or sell copies of the Software, and to permit persons to whom the #
  14. # Software is furnished to do so, subject to the following conditions: #
  15. # #
  16. # The above copyright notice and this permission notice shall be included in #
  17. # all copies or substantial portions of the Software. #
  18. # #
  19. # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
  20. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
  21. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
  22. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
  23. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
  24. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
  25. # DEALINGS IN THE SOFTWARE. #
  26. # #
  27. ###############################################################################
  28. """
  29. This module contains the QMVerifier class for confirming quantum job success.
  30. """
  31. import logging
  32. import os
  33. class QMVerifier(object):
  34. """
  35. Verifies whether a QM job (externalized) was succesfully completed by
  36. * searching for specific keywords in the output files,
  37. * located in a specific directory (e.g. "QMFiles")
  38. """
  39. def __init__(self, molfile):
  40. self.molfile = molfile
  41. self.gaussianResultExists = False
  42. self.mopacResultExists = False
  43. self.mm4ResultExists = False
  44. self.outputExtension = '.out'
  45. self.inputExtension = '.mop'
  46. def check_for_inchi_key_collision(self, log_file_inchi):
  47. """
  48. This method is designed in the case a MOPAC output file was found but the InChI found in the file did not
  49. correspond to the InChI of the given molecule.
  50. This could mean two things:
  51. 1) that the InChI Key hash does not correspond to the InChI it is hashed from. This is the rarest case of them all
  52. 2) the complete InChI did not fit onto just one line in the MOPAC output file. Therefore it was continued on the
  53. second line and only a part of the InChI was actually taken as the 'whole' InChI.
  54. This method reads in the MOPAC input file and compares the found InChI in there to the InChI of the given molecule.
  55. """
  56. # 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
  57. # look in the input file if the InChI doesn't match (apparently, certain characters can be deleted in MOPAC output file for long InChIs)
  58. input_file = os.path.join(self.molfile.directory, self.molfile.name + self.inputExtension)
  59. assert os.path.exists(input_file)
  60. with open(input_file) as input_file: # read the MOPAC input_file
  61. lineI = input_file.readline()
  62. for line in input_file:
  63. if line.startswith("InChI="):
  64. input_file_inchi = lineI.rstrip()
  65. break
  66. if input_file_inchi == self.molfile.InChIAug:
  67. logging.info('An InChI match could be found in the input file, but not in the output file. Anywho, a\
  68. pre-existing successful MOPAC result exists.')
  69. return True
  70. else:
  71. logging.info("*****Warning: potential InChIKey collision: InChIKey(augmented) = " +
  72. self.molfile.name + " RMG Augmented InChI = " + self.molfile.InChIAug +
  73. " Log file Augmented InChI = " + log_file_inchi +
  74. " . InChI could not be found in the MOPAC input file. You should manually check that the output file contains the ended species.")
  75. return False
  76. # 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
  77. def succesful_job_exists(self):
  78. """
  79. checks whether one of the flags is true.
  80. If so, it returns true.
  81. """
  82. return self.gaussianResultExists or self.mopacResultExists or self.mm4ResultExists