Skip to content

Commit 5dd2c17

Browse files
committed
Moved generateQMData to higher QMMolecule class along with minor modifications
1 parent 6ec8ae7 commit 5dd2c17

File tree

5 files changed

+30
-62
lines changed

5 files changed

+30
-62
lines changed

rmgpy/qm/gaussian.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def run(self):
5151
# submits the input file to Gaussian
5252
process = Popen([self.executablePath, self.inputFilePath, self.outputFilePath])
5353
process.communicate()# necessary to wait for executable termination!
54-
import time
55-
time.sleep(1)
54+
5655
return self.verifyOutputFile()
5756

5857
def verifyOutputFile(self):
@@ -185,28 +184,6 @@ def inputFileKeywords(self, attempt):
185184
"""
186185
raise NotImplementedError("Should be defined by subclass, eg. GaussianMolPM3")
187186

188-
def generateQMData(self):
189-
"""
190-
Calculate the QM data and return a QMData object.
191-
"""
192-
self.createGeometry()
193-
if self.verifyOutputFile():
194-
logging.info("Found a successful output file already; using that.")
195-
else:
196-
success = False
197-
for attempt in range(1, self.maxAttempts+1):
198-
self.writeInputFile(attempt)
199-
success = self.run()
200-
if success:
201-
logging.info('Attempt {0} of {1} on species {2} succeeded.'.format(attempt, self.maxAttempts, self.molecule.toAugmentedInChI()))
202-
break
203-
else:
204-
logging.error('QM thermo calculation failed for {0}.'.format(self.molecule.toAugmentedInChI()))
205-
return None
206-
result = self.parse() # parsed in cclib
207-
return result
208-
209-
210187

211188
class GaussianMolPM3(GaussianMol):
212189

@@ -251,4 +228,4 @@ def inputFileKeywords(self, attempt):
251228
assert attempt <= self.maxAttempts
252229
if attempt > self.scriptAttempts:
253230
attempt -= self.scriptAttempts
254-
return self.keywords[attempt-1]
231+
return self.keywords[attempt-1]

rmgpy/qm/main.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(self,
9696

9797
def setDefaultOutputDirectory(self, outputDirectory):
9898
"""
99-
IF the fileStore or scratchDirectory are not already set, put them in here.
99+
If the fileStore or scratchDirectory are not already set, put them in here.
100100
"""
101101
if not self.settings.fileStore:
102102
self.settings.fileStore = os.path.join(outputDirectory, 'QMfiles')
@@ -124,7 +124,8 @@ def checkPaths(self):
124124
"""
125125
self.settings.fileStore = os.path.expandvars(self.settings.fileStore) # to allow things like $HOME or $RMGpy
126126
self.settings.scratchDirectory = os.path.expandvars(self.settings.scratchDirectory)
127-
for path in [self.settings.fileStore, self.settings.scratchDirectory]:
127+
# for path in [self.settings.fileStore, self.settings.scratchDirectory]:
128+
for path in [self.settings.fileStore]:
128129
if not os.path.exists(path):
129130
logging.info("Creating directory %s for QM files."%os.path.abspath(path))
130131
os.makedirs(path)
@@ -148,7 +149,7 @@ def getThermoData(self, molecule):
148149
mopacPM7: PM7, excludes computational results from training set, might be better or slightly worse compared to PM6
149150
gaussian: Only PM3 is available.
150151
"""
151-
if self.settings.software == 'mopac':
152+
if self.settings.software == 'mopac' or self.settings.software == 'mopacPM3':
152153
qm_molecule_calculator = rmgpy.qm.mopac.MopacMolPM3(molecule, self.settings)
153154
thermo0 = qm_molecule_calculator.generateThermoData()
154155
elif self.settings.software == 'mopacPM6':

rmgpy/qm/molecule.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,27 @@ def createGeometry(self):
202202

203203
def generateQMData(self):
204204
"""
205-
Calculate the QM data somehow and return a CCLibData object, or None if it fails.
205+
Calculate the QM data and return a QMData object, or None if it fails.
206206
"""
207-
raise NotImplementedError("This should be defined in a subclass that inherits from QMMolecule")
208-
return qmdata.QMData() or None
207+
if self.verifyOutputFile():
208+
logging.info("Found a successful output file already; using that.")
209+
source = "QM {0} result file found from previous run.".format(self.__class__.__name__)
210+
else:
211+
self.createGeometry()
212+
success = False
213+
for attempt in range(1, self.maxAttempts+1):
214+
self.writeInputFile(attempt)
215+
logging.info('Trying {3} attempt {0} of {1} on molecule {2}.'.format(attempt, self.maxAttempts, self.molecule.toSMILES(), self.__class__.__name__))
216+
success = self.run()
217+
if success:
218+
source = "QM {0} calculation attempt {1}".format(self.__class__.__name__, attempt )
219+
break
220+
else:
221+
logging.error('QM thermo calculation failed for {0}.'.format(self.molecule.toAugmentedInChI()))
222+
return None
223+
result = self.parse() # parsed in cclib
224+
result.source = source
225+
return result # a CCLibData object
209226

210227
def generateThermoData(self):
211228
"""

rmgpy/qm/mopac.py

+3-30
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def run(self):
6363
# submits the input file to mopac
6464
process = Popen([self.executablePath, self.inputFilePath])
6565
process.communicate()# necessary to wait for executable termination!
66-
#Wait for OS to flush the buffer to disk. There should be a better way
67-
# import time
68-
# time.sleep(1)
66+
6967
return self.verifyOutputFile()
7068

7169
def verifyOutputFile(self):
@@ -88,7 +86,7 @@ def verifyOutputFile(self):
8886
if not os.path.exists(self.outputFilePath):
8987
logging.debug("Output file {0} does not (yet) exist.".format(self.outputFilePath))
9088
return False
91-
89+
9290
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
9391
InChIFound=False #flag (1 or 0) indicating whether an InChI was found in the log file
9492

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

198-
def generateQMData(self):
199-
"""
200-
Calculate the QM data and return a QMData object, or None if it fails.
201-
"""
202-
if self.verifyOutputFile():
203-
logging.info("Found a successful output file already; using that.")
204-
source = "QM MOPAC result file found from previous run."
205-
else:
206-
self.createGeometry()
207-
success = False
208-
for attempt in range(1, self.maxAttempts+1):
209-
self.writeInputFile(attempt)
210-
logging.info('Trying {3} attempt {0} of {1} on molecule {2}.'.format(attempt, self.maxAttempts, self.molecule.toSMILES(), self.__class__.__name__))
211-
success = self.run()
212-
if success:
213-
source = "QM {0} calculation attempt {1}".format(self.__class__.__name__, attempt )
214-
break
215-
else:
216-
logging.error('QM thermo calculation failed for {0}.'.format(self.molecule.toAugmentedInChI()))
217-
return None
218-
result = self.parse() # parsed in cclib
219-
result.source = source
220-
return result # a CCLibData object
221-
222-
223196
class MopacMolPM3(MopacMol):
224197

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

371-
return top_keys, bottom_keys, polar_keys
344+
return top_keys, bottom_keys, polar_keys

rmgpy/rmg/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def makeThermoForSpecies(spec,qmValue=None):
7474
import cPickle, logging
7575
filename = scoop.shared.getConst('databaseFile')
7676
database_hash = scoop.shared.getConst('databaseHash')
77-
logging.info('Loading database pickle2 file from {0!r} on worker {1}'.format(filename, scoop.WORKER_NAME.decode() ))
77+
#logging.info('Loading database pickle2 file from {0!r} on worker {1}'.format(filename, scoop.WORKER_NAME.decode() ))
7878
f = open(filename, 'rb')
7979
__database = cPickle.load(f)
8080
f.close()

0 commit comments

Comments
 (0)