# -*- coding: utf-8 -*-
#The MIT License (MIT)
#
#Copyright (c) 2014 Lukasz Mentel
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
import os
from collections import Counter
from subprocess import Popen, call
from .calculator import Calculator, InputTemplate, parse_objective
from ..basisset import get_l
[docs]class Dalton(Calculator):
'Wrapper for running Dalton program'
def __init__(self, name='Dalton', **kwargs):
self.name = name
super(Dalton, self).__init__(**kwargs)
self.daltonpath = os.path.dirname(self.executable)
[docs] def parse(self, fname, objective, regularexp=None):
'''
Parse a value from the output file ``fname`` based on the
``objective``.
If the value of the ``objective`` is ``regexp`` then the
``regularexp`` will be used to parse the file.
'''
regexps = {
'hf total energy': r'^@\s+Final HF energy:\s*(\-?\d+\.\d+)',
'cisd total energy': r'\d+\s*\d+\s*(\-?\d+\.\d+).*converged',
'accomplished': r'End of Wave Function Section',
}
if objective == 'regexp':
if regularexp is None:
raise ValueError("<regularexp> needs to be specified for objective='regexp'")
toparse = regularexp
else:
toparse = regexps.get(objective, None)
if toparse is None:
raise ValueError("Specified objective: '{0:s}' not supported".format(objective))
return parse_objective(fname, toparse)
[docs] def run(self, fname):
'''
Run a single job
Args:
fname : dict
A dictionary with keys ``mol`` and ``dal`` and their
respective file name strings as values
Returns:
out : str
Name of the dalton output file
'''
dalbase = os.path.splitext(fname['dal'])[0]
molbase = os.path.splitext(fname['mol'])[0]
command = [self.executable] + self.runopts + [dalbase, molbase]
call(command)
return dalbase + '_' + molbase + '.out'
[docs] def run_multiple(self, fnames):
'''
Spawn two single jobs as paralell processes
'''
procs = []
outputs = []
for fname in fnames:
dalbase = os.path.splitext(fname['dal'])[0]
molbase = os.path.splitext(fname['mol'])[0]
outputs.append(dalbase + '_' + molbase + '.out')
command = [self.executable] + self.runopts + [dalbase, molbase]
process = Popen(command)
procs.append(process)
for proc in procs:
proc.wait()
return outputs
def __repr__(self):
return "\n".join(["<Dalton(",
"\tname={},".format(self.name),
"\tdaltonpath={},".format(self.daltonpath),
"\texecutable={},".format(self.executable),
"\tscratch={},".format(self.scratch),
"\trunopts={},".format(str(self.runopts)),
")>\n"])