Skip to content

Commit

Permalink
Moved generateQMData to higher QMMolecule class along with minor modi…
Browse files Browse the repository at this point in the history
…fications
  • Loading branch information
keceli committed Nov 12, 2013
1 parent 6ec8ae7 commit 5dd2c17
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 62 deletions.
27 changes: 2 additions & 25 deletions rmgpy/qm/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def run(self):
# submits the input file to Gaussian
process = Popen([self.executablePath, self.inputFilePath, self.outputFilePath])
process.communicate()# necessary to wait for executable termination!
import time
time.sleep(1)

return self.verifyOutputFile()

def verifyOutputFile(self):
Expand Down Expand Up @@ -185,28 +184,6 @@ def inputFileKeywords(self, attempt):
"""
raise NotImplementedError("Should be defined by subclass, eg. GaussianMolPM3")

def generateQMData(self):
"""
Calculate the QM data and return a QMData object.
"""
self.createGeometry()
if self.verifyOutputFile():
logging.info("Found a successful output file already; using that.")
else:
success = False
for attempt in range(1, self.maxAttempts+1):
self.writeInputFile(attempt)
success = self.run()
if success:
logging.info('Attempt {0} of {1} on species {2} succeeded.'.format(attempt, self.maxAttempts, self.molecule.toAugmentedInChI()))
break
else:
logging.error('QM thermo calculation failed for {0}.'.format(self.molecule.toAugmentedInChI()))
return None
result = self.parse() # parsed in cclib
return result



class GaussianMolPM3(GaussianMol):

Expand Down Expand Up @@ -251,4 +228,4 @@ def inputFileKeywords(self, attempt):
assert attempt <= self.maxAttempts
if attempt > self.scriptAttempts:
attempt -= self.scriptAttempts
return self.keywords[attempt-1]
return self.keywords[attempt-1]
7 changes: 4 additions & 3 deletions rmgpy/qm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self,

def setDefaultOutputDirectory(self, outputDirectory):
"""
IF the fileStore or scratchDirectory are not already set, put them in here.
If the fileStore or scratchDirectory are not already set, put them in here.
"""
if not self.settings.fileStore:
self.settings.fileStore = os.path.join(outputDirectory, 'QMfiles')
Expand Down Expand Up @@ -124,7 +124,8 @@ def checkPaths(self):
"""
self.settings.fileStore = os.path.expandvars(self.settings.fileStore) # to allow things like $HOME or $RMGpy
self.settings.scratchDirectory = os.path.expandvars(self.settings.scratchDirectory)
for path in [self.settings.fileStore, self.settings.scratchDirectory]:
# for path in [self.settings.fileStore, self.settings.scratchDirectory]:

This comment has been minimized.

Copy link
@rwest

rwest Dec 21, 2013

Member

Is there a reason for this change? Hmm - perhaps we are not using the scratchDirectory for anything yet.

for path in [self.settings.fileStore]:
if not os.path.exists(path):
logging.info("Creating directory %s for QM files."%os.path.abspath(path))
os.makedirs(path)
Expand All @@ -148,7 +149,7 @@ def getThermoData(self, molecule):
mopacPM7: PM7, excludes computational results from training set, might be better or slightly worse compared to PM6
gaussian: Only PM3 is available.
"""
if self.settings.software == 'mopac':
if self.settings.software == 'mopac' or self.settings.software == 'mopacPM3':
qm_molecule_calculator = rmgpy.qm.mopac.MopacMolPM3(molecule, self.settings)
thermo0 = qm_molecule_calculator.generateThermoData()
elif self.settings.software == 'mopacPM6':
Expand Down
23 changes: 20 additions & 3 deletions rmgpy/qm/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,27 @@ def createGeometry(self):

def generateQMData(self):
"""
Calculate the QM data somehow and return a CCLibData object, or None if it fails.
Calculate the QM data and return a QMData object, or None if it fails.
"""
raise NotImplementedError("This should be defined in a subclass that inherits from QMMolecule")
return qmdata.QMData() or None
if self.verifyOutputFile():
logging.info("Found a successful output file already; using that.")
source = "QM {0} result file found from previous run.".format(self.__class__.__name__)
else:
self.createGeometry()
success = False
for attempt in range(1, self.maxAttempts+1):
self.writeInputFile(attempt)
logging.info('Trying {3} attempt {0} of {1} on molecule {2}.'.format(attempt, self.maxAttempts, self.molecule.toSMILES(), self.__class__.__name__))
success = self.run()
if success:
source = "QM {0} calculation attempt {1}".format(self.__class__.__name__, attempt )
break
else:
logging.error('QM thermo calculation failed for {0}.'.format(self.molecule.toAugmentedInChI()))
return None
result = self.parse() # parsed in cclib
result.source = source
return result # a CCLibData object

def generateThermoData(self):
"""
Expand Down
33 changes: 3 additions & 30 deletions rmgpy/qm/mopac.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def run(self):
# submits the input file to mopac
process = Popen([self.executablePath, self.inputFilePath])
process.communicate()# necessary to wait for executable termination!
#Wait for OS to flush the buffer to disk. There should be a better way
# import time
# time.sleep(1)

return self.verifyOutputFile()

def verifyOutputFile(self):
Expand All @@ -88,7 +86,7 @@ def verifyOutputFile(self):
if not os.path.exists(self.outputFilePath):
logging.debug("Output file {0} does not (yet) exist.".format(self.outputFilePath))
return False

InChIMatch=False #flag (1 or 0) indicating whether the InChI in the file matches InChIaug this can only be 1 if InChIFound is also 1
InChIFound=False #flag (1 or 0) indicating whether an InChI was found in the log file

Expand Down Expand Up @@ -195,31 +193,6 @@ def inputFileKeywords(self, attempt):
"""
raise NotImplementedError("Should be defined by subclass, eg. MopacMolPM3")

def generateQMData(self):
"""
Calculate the QM data and return a QMData object, or None if it fails.
"""
if self.verifyOutputFile():
logging.info("Found a successful output file already; using that.")
source = "QM MOPAC result file found from previous run."
else:
self.createGeometry()
success = False
for attempt in range(1, self.maxAttempts+1):
self.writeInputFile(attempt)
logging.info('Trying {3} attempt {0} of {1} on molecule {2}.'.format(attempt, self.maxAttempts, self.molecule.toSMILES(), self.__class__.__name__))
success = self.run()
if success:
source = "QM {0} calculation attempt {1}".format(self.__class__.__name__, attempt )
break
else:
logging.error('QM thermo calculation failed for {0}.'.format(self.molecule.toAugmentedInChI()))
return None
result = self.parse() # parsed in cclib
result.source = source
return result # a CCLibData object


class MopacMolPM3(MopacMol):

#: Keywords that will be added at the top and bottom of the qm input file
Expand Down Expand Up @@ -368,4 +341,4 @@ def inputFileKeywords(self, attempt):
multiplicity_keys,
)

return top_keys, bottom_keys, polar_keys
return top_keys, bottom_keys, polar_keys
2 changes: 1 addition & 1 deletion rmgpy/rmg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def makeThermoForSpecies(spec,qmValue=None):
import cPickle, logging
filename = scoop.shared.getConst('databaseFile')
database_hash = scoop.shared.getConst('databaseHash')
logging.info('Loading database pickle2 file from {0!r} on worker {1}'.format(filename, scoop.WORKER_NAME.decode() ))
#logging.info('Loading database pickle2 file from {0!r} on worker {1}'.format(filename, scoop.WORKER_NAME.decode() ))
f = open(filename, 'rb')
__database = cPickle.load(f)
f.close()
Expand Down

0 comments on commit 5dd2c17

Please sign in to comment.