def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setSerial() configDic = { 'dynmatInput': 'dyn.in', 'dynmatOutput': 'dyn.out', # 'dynmatfildyn': None, # 'dynmatfilout': None, # 'dynmatfilmol': None, # 'dynmatfilxsf': None, } # QE input file's path containing variables' defaults (will be moved to # QE input parser) self._path_defaults = { 'fildyn': 'matdyn', 'filout': 'dynmat.out', 'filmol': 'dynmat.mold', 'filxsf': 'dynmat.axsf', } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = QEInput(filename=self.setting.get('dynmatInput'), type='dynmat') self.output = QEOutput(self.setting, type='dynmat')
def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setSerial() configDic = { 'matdynInput': 'matdyn.in', # 'flfrc': None, 'matdynOutput': 'matdyn.out', # 'flvec': None, # 'flfrq': None, # 'fldos': None } # QE input file's path containing variables' defaults (will be moved to # QE input parser) self._path_defaults = { 'flfrc': None, 'flvec': 'matdyn.modes', 'flfrq': 'matdyn.freq', 'fldos': 'matdyn.dos' } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = MatdynInput(filename=self.setting.get('matdynInput')) self.output = QEOutput(self.setting, type='matdyn')
def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setSerial() configDic = { 'd3Input': 'd3.in', 'd3Output': 'd3.out', #'fildyn': None, #'fildrho': None, #'fild0rho': None, #'outdir': None } self._path_defaults = { 'fildyn': 'd3dyn', 'fildrho': ' ', 'fild0rho': ' ', 'outdir': './', 'prefix': 'pwscf' } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = D3Input(filename=self.setting.get('d3Input')) self.output = QEOutput(self.setting, type='d3')
def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setParallel() # pw main input and output configDic = { 'pwInput': 'scf.in', 'pwOutput': 'scf.out', } # QE input file's path containing variables' defaults (will be moved to # QE input parser) self._path_defaults = { 'outdir': './', 'pseudo_dir': './', 'prefix': 'pwscf' } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = PWInput( self.setting.get('pwInput') ) self.output = QEOutput(self.setting, type='pw')
def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setSerial() configDic = { 'projwfcInput': 'pdos.in', 'projwfcOutput': 'pdos.out', } # QE input file's path containing variables' defaults (will be moved to # QE input parser) self._path_defaults = { 'outdir': './', 'prefix': 'pwscf', } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = QEInput(self.setting.get('projwfcInput'), type='projwfc') self.output = QEOutput(self.setting, type='projwfc')
def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setParallel() configDic = { 'phInput': 'ph.in', 'phOutput': 'ph.out', 'fildyn': None, # 'fildrho' : None, # 'fildvscf' : None } # QE input file's path containing variables' defaults (will be moved to # QE input parser) self._path_defaults = { 'fildyn': 'matdyn', 'fildrho': '', 'fildvscf': '', 'outdir': './' } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = PHInput(filename=self.setting.get('phInput')) self.output = QEOutput(self.setting, type='ph')
def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setSerial() configDic = { 'q2rInput': 'q2r.in', 'q2rOutput': 'q2r.out', # 'fildyn': None, # 'flfrc': None } # QE input file's path containing variables' defaults (will be moved to # QE input parser) self._path_defaults = { 'fildyn': None, 'flfrc': None, } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = QEInput(filename=self.setting.get('q2rInput'), type='q2r') self.output = QEOutput(self.setting, type='q2r')
def __init__(self, filename = None,configString = None, cleanOutDir = False,\ sectionName = None): QETask.__init__(self, filename, configString, cleanOutDir) self.setSerial() configDic = { 'dosInput' : 'dos.in', 'dosOutput': 'dos.out', #'dosfldos' : None } # QE input file's path containing variables' defaults (will be moved to # QE input parser) self._path_defaults = { 'fldos': 'fldos.dos', 'outdir': './' } if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = QEInput(self.setting.get('dosInput'), type = 'dos') self.output = QEOutput(self.setting, type='dos')
def __init__(self, filename=None, configString=None, cleanOutDir=None): QETask.__init__(self, filename, configString, cleanOutDir) #self.name = 'dynmat.x' configDic = {'dynmatInput': 'dynmat.in', 'dynmatOutput': 'dynmat.out'} self.setting.section(self.name(), configDic) self.input = QEInput(filename=self.setting.dynmatInput, type='dynmat') self.output = QEOutput(self.setting, type='dynmat')
def __init__(self, filename=None, configString=None, cleanOutDir=None): QETask.__init__(self, filename, configString, cleanOutDir) #self.name = 'q2r.x' configDic = {'q2rInput': 'q2r.in', 'q2rOutput': 'q2r.out'} self.setting.section(self.name(), configDic) self.input = QEInput(filename=self.setting.q2rInput, type='q2r') self.output = QEOutput(self.setting, type='q2r')
def __init__(self, filename, cleanOutDir=None): QETask.__init__(self, filename, cleanOutDir) self.name = 'dynmat.x' configDic = {'dynmatInput': 'dynmat.in', 'dynmatOutput': 'dynmat.out'} self.setting.section(self.name, configDic) self.input = QEInput(filename=self.setting.dynmatInput, type='dynmat') self.output = QEOutput(self.setting, type='dynmat') self._cmdStr = "dynmat.x < " + self.setting.dynmatInput + " > " + \ self.setting.dynmatOutput
def __init__(self, filename=None, configString=None, cleanOutDir=None): QETask.__init__(self, filename, configString, cleanOutDir) #self.name = 'pw.x' # pwscf input and output configDic = { 'pwscfInput': 'scf.in', 'pwscfOutput': 'scf.out', } self.setting.section(self.name(), configDic) self.input = PWInput(self.setting.pwscfInput) self.output = QEOutput(self.setting, type='pw')
def _setSettingInputOutput(self, configDic, filename=None, configString=None, sectionName=None): """ Helper method for readSetting() """ if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = PWInput( self.setting.pwInput) #self.setting.get('pwInput') ) # add pointer to setting for input filenames synchronization self.input._setting = self.setting self.output = QEOutput(self.setting, type='pw') if filename != None or configString != None: self.syncSetting()
def __init__(self, filename=None, configString=None, cleanOutDir=None): QETask.__init__(self, filename, configString, cleanOutDir) #self.name = 'ph.x' configDic = { 'd3Input': 'd3.in', 'd3fildyn': 'd3dyn', 'd3Output': 'd3.out' } self.setting.section(self.name(), configDic) self.input = D3Input(filename=self.setting.d3Input) self.output = QEOutput(self.setting, type='d3')
def __init__(self, filename=None, configString=None, cleanOutDir=None): QETask.__init__(self, filename, configString, cleanOutDir) #self.name = 'dos.x' # pwscf input and output configDic = { 'dosInput': 'dos.in', 'dosOutput': 'dos.out', 'fldos': 'fldos.dos' } self.setting.section(self.name(), configDic) self.input = QEInput(self.setting.dosInput, type='dos') self.output = QEOutput(self.setting, type='dos')
def __init__(self, filename=None, configString=None, cleanOutDir=None): QETask.__init__(self, filename, configString, cleanOutDir) #self.name = 'ph.x' configDic = { 'phInput': 'ph.in', 'phOutput': 'ph.out', 'phFildyn': 'matdyn' } self.setting.section(self.name(), configDic) self.input = PHInput(filename=self.setting.phInput) self.output = QEOutput(self.setting, type='ph')
def __init__(self, filename, cleanOutDir=None): QETask.__init__(self, filename, cleanOutDir) self.name = 'ph.x' configDic = {'phInput': 'ph.in', 'phOutput': 'ph.out'} self.setting.section(self.name, configDic) self.input = QEInput(filename=self.setting.phInput, type='ph') self.output = QEOutput(self.setting, type='ph') self._cmdStr = self.setting.paraPrefix + " ph.x " + \ self.setting.paraPostfix + " -inp " + \ self.setting.phInput + " > " + \ self.setting.phOutput + "< /dev/null"
def __init__(self, filename, cleanOutDir = None): QETask.__init__(self, filename, cleanOutDir) self.name = 'q2r.x' configDic = { 'q2rInput': 'q2r.in', 'q2rOutput': 'q2r.out' } self.setting.section(self.name, configDic) self.input = QEInput(filename = self.setting.q2rInput, type = 'q2r') self.output = QEOutput(self.setting, type = 'q2r') self._cmdStr = "q2r.x < " + self.setting.q2rInput + " > " + \ self.setting.q2rOutput
def __init__(self, filename=None, configString=None, cleanOutDir=None): QETask.__init__(self, filename, configString, cleanOutDir) #self.name = 'matdyn.x' configDic = { 'matdynInput': 'matdyn.in', 'matdynOutput': 'matdyn.out', 'matdynModes': 'matdyn.modes', 'matdynFreqs': 'matdyn.freq', 'matdynfldos': 'matdyn.phdos' } self.setting.section(self.name(), configDic) self.input = MatdynInput(filename=self.setting.matdynInput) self.output = QEOutput(self.setting, type='matdyn')
def _setSetiingInputOutput(self, configDic, filename = None, configString = None, sectionName = None): """ Helper method for readSetting() """ if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = PWInput( self.setting.pwInput ) #self.setting.get('pwInput') ) # add pointer to setting for input filenames synchronization self.input._setting = self.setting self.output = QEOutput(self.setting, type='pw') if filename != None or configString != None: self.syncSetting()
def __init__(self, filename, cleanOutDir=None): QETask.__init__(self, filename, cleanOutDir) self.name = 'pw.x' # pwscf input and output configDic = { 'pwscfInput': 'scf.in', 'pwscfOutput': 'scf.out', } self.setting.section(self.name, configDic) self.input = PWInput(self.setting.pwscfInput) self.output = QEOutput(self.setting, type='pw') self._cmdStr = self.setting.paraPrefix + " pw.x " + \ self.setting.paraPostfix + " -inp " + \ self.setting.pwscfInput + " > " + \ self.setting.pwscfOutput + "< /dev/null"
def __init__(self, filename, cleanOutDir = None): QETask.__init__(self, filename, cleanOutDir) self.name = 'dos.x' # pwscf input and output configDic = { 'dosInput' : 'dos.in', 'dosOutput': 'dos.out', 'fldos' : 'fldos.dos' } self.setting.section(self.name, configDic) self.input = QEInput(self.setting.dosInput, type = 'dos') self.output = QEOutput(self.setting, type='dos') self._cmdStr = self.setting.paraPrefix + " dos.x " + \ " -inp " + \ self.setting.dosInput + " > " + \ self.setting.dosOutput + "< /dev/null"
def readSetting(self, filename = None, configString = None, \ sectionName = None): """ Initializes setting class """ configDic = { 'useTorque' : 'False', 'paraTorqueParams': '-l nodes=1:ppn=1', 'serialTorqueParams': '-l nodes=1:ppn=1', 'paraPrefix': '', 'paraPostfix': '', 'serialPrefix': '', 'serialPostfix': '', 'paraRemoteShell': '', 'outdir': None } # if filename == None and configString == None: # configString = '' # filename = 'config.ini' if filename == None and configString == None: self.setting = Setting(configString = "") else: self.setting = Setting(filename, configString) self.setting.section(QETask.name(self), configDic) if self.setting.get('useTorque') == 'True': self.setting.set('useTorque', True) else: self.setting.set('useTorque', False) if self.setting.get('useTorque'): if self.isSerial(): self._torque = QETorque(self.setting.get('serialTorqueParams')) else: self._torque = QETorque(self.setting.get('paraTorqueParams')) # ********************************************************************** # Task subclass specific part: if hasattr(self, '_type'): defaultModName = 'QESInput' modname = self._inputConstructor #Input = __import__("qeparser." + modname.lower(), globals(), \ # locals(), [modname], -1) mod_cmd = "from qeparser.%s import %s as Input"%(modname.lower(), modname) exec(mod_cmd) from qeparser.qeoutput import QEOutput if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, self._configDic) # add pointer to setting for input filenames synchronization #self.input._setting = self.setting self.output = QEOutput(self.setting, type = self._type) args = { 'setting': self.setting, } if modname == defaultModName: args['type'] = self._type if filename != None or configString != None: self.input = Input(**args) self.syncSetting() else: # add parse: args['parse'] = False self.input = Input( **args)
class QETask(object): """ Base abstract class for 'TaskNameTask' family of classes. It also provides the interface to launch tasks All user defined tasks should be derived from this class setting -- provides access to parallel environment and QE input/output files """ def __init__(self, filename = None, configString = None, cleanOutDir = False): # parallelization parameters # Default values, see explanations below: #self.name = 'Launcher' self._isSerial = True self._mergedTask = False self.cleanOutDir = cleanOutDir QETask.readSetting(self, filename, configString) def readSetting(self, filename = None, configString = None, \ sectionName = None): """ Initializes setting class """ configDic = { 'useTorque' : 'False', 'paraTorqueParams': '-l nodes=1:ppn=1', 'serialTorqueParams': '-l nodes=1:ppn=1', 'paraPrefix': '', 'paraPostfix': '', 'serialPrefix': '', 'serialPostfix': '', 'paraRemoteShell': '', 'outdir': None } # if filename == None and configString == None: # configString = '' # filename = 'config.ini' if filename == None and configString == None: self.setting = Setting(configString = "") else: self.setting = Setting(filename, configString) self.setting.section(QETask.name(self), configDic) if self.setting.get('useTorque') == 'True': self.setting.set('useTorque', True) else: self.setting.set('useTorque', False) if self.setting.get('useTorque'): if self.isSerial(): self._torque = QETorque(self.setting.get('serialTorqueParams')) else: self._torque = QETorque(self.setting.get('paraTorqueParams')) # ********************************************************************** # Task subclass specific part: if hasattr(self, '_type'): defaultModName = 'QESInput' modname = self._inputConstructor #Input = __import__("qeparser." + modname.lower(), globals(), \ # locals(), [modname], -1) mod_cmd = "from qeparser.%s import %s as Input"%(modname.lower(), modname) exec(mod_cmd) from qeparser.qeoutput import QEOutput if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, self._configDic) # add pointer to setting for input filenames synchronization #self.input._setting = self.setting self.output = QEOutput(self.setting, type = self._type) args = { 'setting': self.setting, } if modname == defaultModName: args['type'] = self._type if filename != None or configString != None: self.input = Input(**args) self.syncSetting() else: # add parse: args['parse'] = False self.input = Input( **args) def name(self): return 'Launcher' def parse(self): self.syncSetting() def syncSetting(self): """ Will syncronise QE input file with class Setting for given task (QE input files may contain multiple input/ouput file names definitions which can be overriden in this method) """ pass def cleanOutputDir(self, cleanOutDir = None): """ Cleans the output directory (directory, where large files, used for calculation are stored, can be for example 'temp/' or 'scratch/') """ # import shutil if cleanOutDir == None: cleanOutDir = self.cleanOutDir # if cleanOutDir == None: # raise Exception('outDir can not be cleaned, since it was not defined') if cleanOutDir: outDir = self.setting.get('outdir') os.system(self.setting.paraRemoteShell + ' rm -r -f ' + outDir) os.system(self.setting.paraRemoteShell + ' mkdir ' + outDir) # if self.setting.useTorque: # # else: # shutil.rmtree(cleanOutDir) # os.mkdir(cleanOutDir) # def cmdLine(self): # """ # returns command string of a given task # """ # return self._cmdStr def launch(self, cleanOutDir = False): """ Parses input. Launches task. Parses output. """ # if cleanOutDir == None: # cleanOutDir = self.cleanOutDir # if cleanOutDir != None: # self.cleanOutputDir(cleanOutDir) #self.input.parse() self.syncSetting() # sync setting with QE input file self.input.save() self.cleanOutputDir(cleanOutDir) self._run() self.output.parse(parserList = 'all') def setSerial(self): #self._serialThroughMPI = serialThroughMPI self._isSerial = True def setParallel(self): self._isSerial = False def isSerial(self): if self._isSerial: return True else: return False def getPrefix(self) : if self.isSerial(): # if self._isSerialThroughMPI(): # return '' # else: return self.setting.get('serialPrefix') else: return self.setting.get('paraPrefix') def getPostfix(self): if self.isSerial(): return self.setting.get('serialPostfix') else: return self.setting.get('paraPostfix') def isMerged(self): return self._mergedTask def _initCmdLineParams(self): self._inp = '-inp' self._devnul = '< /dev/null' if self.isSerial(): self._inp = '<' self._devnul = '' # def _isSerialThroughMPI(self): # if self.isSerial(): # if self._serialThroughMPI: # return True # else: # return False def _check(self, x): """ Will check the exit status of the program to be executed """ signal = x & 0xFF exitcode = (x >> 8) & 0xFF if exitcode != 0: raise Exception("Task " + self.name() + " crashed: check your \ settings!\n" + "Command string: " + self.cmdLine()) def _run(self): if os.path.exists('CRASH'): os.remove('CRASH') outdir = self.setting.get('outdir') if outdir != None: os.system(self.setting.paraRemoteShell + ' mkdir -p ' + outdir) if self.setting.get('useTorque'): if self.isSerial(): if self.setting.get('serialPrefix') == '': self._check(os.system(self.cmdLine())) else: self._torque.serial(self.cmdLine(), torqueParams = self.setting.serialTorqueParams) else: self._torque.serial(self.cmdLine(), torqueParams = self.setting.paraTorqueParams) else: self._check(os.system(self.cmdLine())) # if self.setting.paraPrefix != '' and self.setting.paraPrefix in self.cmdLine(): # if self.setting.useTorque: # self._torque.serial(self.cmdLine()) # else: # self._check(os.system(self.cmdLine())) # else: # self._check(os.system(self.cmdLine())) if os.path.exists('CRASH'): raise Exception("Task " + self.name() + " crashed: 'CRASH' file was discovered") def _getCmdLine(self, executable, input, output): self._initCmdLineParams() return self.getPrefix() + ' ' + executable + " " + self.getPostfix() + \ ' ' + self._inp + ' ' + self.setting.get(input) + ' > ' + \ self.setting.get(output) + self._devnul def _setSetiingInputOutput(self, configDic, filename = None, configString = None, sectionName = None): """ Helper method for readSetting() """ if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = PWInput( self.setting.pwInput ) #self.setting.get('pwInput') ) # add pointer to setting for input filenames synchronization self.input._setting = self.setting self.output = QEOutput(self.setting, type='pw') if filename != None or configString != None: self.syncSetting()
def readSetting(self, filename = None, configString = None, \ sectionName = None): """ Initializes setting class """ configDic = { 'useTorque': 'False', 'paraTorqueParams': '-l nodes=1:ppn=1', 'serialTorqueParams': '-l nodes=1:ppn=1', 'paraPrefix': '', 'paraPostfix': '', 'serialPrefix': '', 'serialPostfix': '', 'paraRemoteShell': '', 'outdir': None } # if filename == None and configString == None: # configString = '' # filename = 'config.ini' if filename == None and configString == None: self.setting = Setting(configString="") else: self.setting = Setting(filename, configString) self.setting.section(QETask.name(self), configDic) if self.setting.get('useTorque') == 'True': self.setting.set('useTorque', True) else: self.setting.set('useTorque', False) if self.setting.get('useTorque'): if self.isSerial(): self._torque = QETorque(self.setting.get('serialTorqueParams')) else: self._torque = QETorque(self.setting.get('paraTorqueParams')) # ********************************************************************** # Task subclass specific part: if hasattr(self, '_type'): defaultModName = 'QESInput' modname = self._inputConstructor #Input = __import__("qeparser." + modname.lower(), globals(), \ # locals(), [modname], -1) mod_cmd = "from qeparser.%s import %s as Input" % (modname.lower(), modname) exec(mod_cmd) from qeparser.qeoutput import QEOutput if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, self._configDic) # add pointer to setting for input filenames synchronization #self.input._setting = self.setting self.output = QEOutput(self.setting, type=self._type) args = { 'setting': self.setting, } if modname == defaultModName: args['type'] = self._type if filename != None or configString != None: self.input = Input(**args) self.syncSetting() else: # add parse: args['parse'] = False self.input = Input(**args)
class QETask(object): """ Base abstract class for 'TaskNameTask' family of classes. It also provides the interface to launch tasks All user defined tasks should be derived from this class setting -- provides access to parallel environment and QE input/output files """ def __init__(self, filename=None, configString=None, cleanOutDir=False): # parallelization parameters # Default values, see explanations below: #self.name = 'Launcher' self._isSerial = True self._mergedTask = False self.cleanOutDir = cleanOutDir QETask.readSetting(self, filename, configString) def readSetting(self, filename = None, configString = None, \ sectionName = None): """ Initializes setting class """ configDic = { 'useTorque': 'False', 'paraTorqueParams': '-l nodes=1:ppn=1', 'serialTorqueParams': '-l nodes=1:ppn=1', 'paraPrefix': '', 'paraPostfix': '', 'serialPrefix': '', 'serialPostfix': '', 'paraRemoteShell': '', 'outdir': None } # if filename == None and configString == None: # configString = '' # filename = 'config.ini' if filename == None and configString == None: self.setting = Setting(configString="") else: self.setting = Setting(filename, configString) self.setting.section(QETask.name(self), configDic) if self.setting.get('useTorque') == 'True': self.setting.set('useTorque', True) else: self.setting.set('useTorque', False) if self.setting.get('useTorque'): if self.isSerial(): self._torque = QETorque(self.setting.get('serialTorqueParams')) else: self._torque = QETorque(self.setting.get('paraTorqueParams')) # ********************************************************************** # Task subclass specific part: if hasattr(self, '_type'): defaultModName = 'QESInput' modname = self._inputConstructor #Input = __import__("qeparser." + modname.lower(), globals(), \ # locals(), [modname], -1) mod_cmd = "from qeparser.%s import %s as Input" % (modname.lower(), modname) exec(mod_cmd) from qeparser.qeoutput import QEOutput if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, self._configDic) # add pointer to setting for input filenames synchronization #self.input._setting = self.setting self.output = QEOutput(self.setting, type=self._type) args = { 'setting': self.setting, } if modname == defaultModName: args['type'] = self._type if filename != None or configString != None: self.input = Input(**args) self.syncSetting() else: # add parse: args['parse'] = False self.input = Input(**args) def name(self): return 'Launcher' def parse(self): self.syncSetting() def syncSetting(self): """ Will syncronise QE input file with class Setting for given task (QE input files may contain multiple input/ouput file names definitions which can be overriden in this method) """ pass def cleanOutputDir(self, cleanOutDir=None): """ Cleans the output directory (directory, where large files, used for calculation are stored, can be for example 'temp/' or 'scratch/') """ # import shutil if cleanOutDir == None: cleanOutDir = self.cleanOutDir # if cleanOutDir == None: # raise Exception('outDir can not be cleaned, since it was not defined') if cleanOutDir: outDir = self.setting.get('outdir') os.system(self.setting.paraRemoteShell + ' rm -r -f ' + outDir) os.system(self.setting.paraRemoteShell + ' mkdir ' + outDir) # if self.setting.useTorque: # # else: # shutil.rmtree(cleanOutDir) # os.mkdir(cleanOutDir) # def cmdLine(self): # """ # returns command string of a given task # """ # return self._cmdStr def launch(self, cleanOutDir=False): """ Parses input. Launches task. Parses output. """ # if cleanOutDir == None: # cleanOutDir = self.cleanOutDir # if cleanOutDir != None: # self.cleanOutputDir(cleanOutDir) #self.input.parse() self.syncSetting() # sync setting with QE input file self.input.save() self.cleanOutputDir(cleanOutDir) self._run() self.output.parse(parserList='all') def setSerial(self): #self._serialThroughMPI = serialThroughMPI self._isSerial = True def setParallel(self): self._isSerial = False def isSerial(self): if self._isSerial: return True else: return False def getPrefix(self): if self.isSerial(): # if self._isSerialThroughMPI(): # return '' # else: return self.setting.get('serialPrefix') else: return self.setting.get('paraPrefix') def getPostfix(self): if self.isSerial(): return self.setting.get('serialPostfix') else: return self.setting.get('paraPostfix') def isMerged(self): return self._mergedTask def _initCmdLineParams(self): self._inp = '-inp' self._devnul = '< /dev/null' if self.isSerial(): self._inp = '<' self._devnul = '' # def _isSerialThroughMPI(self): # if self.isSerial(): # if self._serialThroughMPI: # return True # else: # return False def _check(self, x): """ Will check the exit status of the program to be executed """ signal = x & 0xFF exitcode = (x >> 8) & 0xFF if exitcode != 0: raise Exception("Task " + self.name() + " crashed: check your \ settings!\n" + "Command string: " + self.cmdLine()) def _run(self): if os.path.exists('CRASH'): os.remove('CRASH') outdir = self.setting.get('outdir') if outdir != None: os.system(self.setting.paraRemoteShell + ' mkdir -p ' + outdir) if self.setting.get('useTorque'): if self.isSerial(): if self.setting.get('serialPrefix') == '': self._check(os.system(self.cmdLine())) else: self._torque.serial( self.cmdLine(), torqueParams=self.setting.serialTorqueParams) else: self._torque.serial(self.cmdLine(), torqueParams=self.setting.paraTorqueParams) else: self._check(os.system(self.cmdLine())) # if self.setting.paraPrefix != '' and self.setting.paraPrefix in self.cmdLine(): # if self.setting.useTorque: # self._torque.serial(self.cmdLine()) # else: # self._check(os.system(self.cmdLine())) # else: # self._check(os.system(self.cmdLine())) if os.path.exists('CRASH'): raise Exception("Task " + self.name() + " crashed: 'CRASH' file was discovered") def _getCmdLine(self, executable, input, output): self._initCmdLineParams() return self.getPrefix() + ' ' + executable + " " + self.getPostfix() + \ ' ' + self._inp + ' ' + self.setting.get(input) + ' > ' + \ self.setting.get(output) + self._devnul def _setSettingInputOutput(self, configDic, filename=None, configString=None, sectionName=None): """ Helper method for readSetting() """ if sectionName == None: name = self.name() else: name = sectionName self.setting.section(name, configDic) self.input = PWInput( self.setting.pwInput) #self.setting.get('pwInput') ) # add pointer to setting for input filenames synchronization self.input._setting = self.setting self.output = QEOutput(self.setting, type='pw') if filename != None or configString != None: self.syncSetting()