def getInputParam(text, param): "Gets input string, sets param value and returns updated string" # XXX: Parameters should be from "SYSTEM" namelist (extend for K-points) input = QEInput(config=text) input.parse() nl = input.namelist("system") return nl.param(param)
class Q2RGenerator(object): def __init__(self, director, inventory): self._director = director self._inv = inventory self._input = None def setInput(self): "Set namelist 'input'" self._input = QEInput(type='q2r') nl = self._input.namelist("input") zasr = ZASR[ZASRLIST[int(self._inv.zasr)]] nl.set("fildyn", self.fildyn()) # from PH results nl.set("zasr", zasr) nl.set("flfrc", FLFRC) def fildyn(self): "Returns fildyn parameter from PH results" phresults = PHResult(self._director, self._inv.id) return phresults.fildyn() def toString(self): return self._input.toString()
def setInput(self): "Set namelist 'input'" self._input = QEInput(type='q2r') nl = self._input.namelist("input") zasr = ZASR[ZASRLIST[int(self._inv.zasr)]] nl.set("fildyn", self.fildyn()) # from PH results nl.set("zasr", zasr) nl.set("flfrc", FLFRC)
def setInput(self): "Set namelist 'input'" self._input = QEInput(type='dynmat') nl = Namelist("input") self._input.addNamelist(nl) nl.add("fildyn", self._phresults.fildyn()) # from PH results self._addAsr(nl) self._addQPoint(nl)
def _inputFromRecord(self): "Set input object from input configuration" inputs = self._director.clerk.getQEConfigurations(where="taskid='%s'" % self._emTaskId()) if len(inputs) == 0: # No input created return input = inputs[0] fname = defaultInputName(input.type) inputStr = readRecordFile(self._director.dds, input, fname) self._input = QEInput(config=inputStr, type="cp") self._input.parse()
class BANDSGenerator(object): def __init__(self, director, inventory): self._director = director self._inv = inventory self._input = None def setInputpp(self): self._input = QEInput(type="bands") nl = self._input.namelist("inputpp") nl.add("filband", FILBAND) nl.add("lsym", LSIM) def toString(self): return self._input.toString()
class DOSGenerator(object): def __init__(self, director, inventory): self._director = director self._inv = inventory self._input = None def setInputpp(self): self._input = QEInput(type="dos") nl = self._input.namelist("inputpp") nl.add("Emin", self._inv.emin) nl.add("Emax", self._inv.emax) nl.add("DeltaE", self._inv.deltae) def toString(self): return self._input.toString()
def filterInput(self, director): "Default behaviour: standard filtering" input = QEInput(config=self.inventory.text, type=self.inventory.type) filter = filters.filterFactory(self.inventory.type) # Creating filter filter.apply(input) # Apply filter to input fconfig = input.toString() # Filtered config input return director.redirect(actor = 'material_simulations/espresso/input-create', routine = 'createRecord', text = fconfig, id = self.inventory.id, taskid = self.inventory.taskid, type = self.inventory.type, subtype = self.inventory.subtype, fname = self.inventory.fname, description = self.inventory.description)
def filterInput(self, director): "Default behaviour: standard filtering" input = QEInput(config=self.inventory.text, type=self.inventory.type) filter = filters.filterFactory(self.inventory.type) # Creating filter filter.apply(input) # Apply filter to input fconfig = input.toString() # Filtered config input return director.redirect( actor='material_simulations/espresso/input-create', routine='createRecord', text=fconfig, id=self.inventory.id, taskid=self.inventory.taskid, type=self.inventory.type, subtype=self.inventory.subtype, fname=self.inventory.fname, description=self.inventory.description)
class DYNMATGenerator(object): def __init__(self, director, inventory): self._director = director self._inv = inventory self._input = None self._phresults = PHResult(self._director, self._inv.id) def setInput(self): "Set namelist 'input'" self._input = QEInput(type='dynmat') nl = Namelist("input") self._input.addNamelist(nl) nl.add("fildyn", self._phresults.fildyn()) # from PH results self._addAsr(nl) self._addQPoint(nl) def fildyn(self): "Returns fildyn parameter from PH results" return self._phresults.fildyn() def _addAsr(self, nl): "Adds 'asr' parameter for gamma point only" if self._phresults.isGammaPoint(): asr = ZASR[ZASRLIST[int(self._inv.asr)]] nl.add("asr", asr) def _addQPoint(self, nl): "Adds q point" kp = self._phresults.kCoord() if not kp or type(kp) != list: nl.add("q(#)", "ERROR: Phonon coordinate (Kx, Ky, Kz) are not set in PH input") for i in range(len(kp)): nl.add("q(%s)" % str(i+1), kp[i]) def toString(self): return self._input.toString()
def _inputFromRecord(self): "Set input object from input configuration" inputs = self._director.clerk.getQEConfigurations(where="taskid='%s'" % self._emTaskId()) if len(inputs) == 0: # No input created return input = inputs[0] fname = defaultInputName(input.type) inputStr = readRecordFile(self._director.dds, input, fname) self._input = QEInput(config = inputStr, type = "cp") self._input.parse()
def setInputph(self): "Sets inputph depending on the simulation type" self._input = QEInput(type='ph') self._input.header = "phonon simulation\n" nl = Namelist("inputph") self._input.addNamelist(nl) self._simtype = self._simtype() if not self._simtype: # no simtype, no inputph population return if self._simtype == SIMTYPE["multiple-phonon"]: self._multiPhonInput() # population of inputph for multiple phonon elif self._simtype == SIMTYPE["single-phonon"]: self._singlePhonInput() # population of inputph for single phonon
def setInputpp(self): self._input = QEInput(type="dos") nl = self._input.namelist("inputpp") nl.add("Emin", self._inv.emin) nl.add("Emax", self._inv.emax) nl.add("DeltaE", self._inv.deltae)
class PHGenerator(object): def __init__(self, director, inventory): self._director = director self._inv = inventory self._input = None self._pwresult = PWResult(self._director, self._inv.id) # XXX: Handle prefix properly (should be same as in pw input) def setInputph(self): "Sets inputph depending on the simulation type" self._input = QEInput(type='ph') self._input.header = "phonon simulation\n" nl = Namelist("inputph") self._input.addNamelist(nl) self._simtype = self._simtype() if not self._simtype: # no simtype, no inputph population return if self._simtype == SIMTYPE["multiple-phonon"]: self._multiPhonInput() # population of inputph for multiple phonon elif self._simtype == SIMTYPE["single-phonon"]: self._singlePhonInput() # population of inputph for single phonon def toString(self): if not self._input: return "" return self._input.toString() def amasses(self): """Returns list of tuples with amass label and mass value from PW input configuration Example: [("amass(1)", "35.5"), ("amass(2)", "54.3")] """ species = self._pwresult.species() # Example: masses = [("Al", "29.7"), ("Ni", "56.7") ...] if not species: return None # No masses, no amasses :) list = [] # amass list for l in range(len(species)): list.append(("amass(%s)" % str(l+1), species[l][1])) return list def isGammaPoint(self): "Checks if phonon point is gamma point" # Rudimentary filter if self._inv.kx == '' or self._inv.ky == '' or self._inv.kz == '': return False return float(self._inv.kx) == 0.0 and float(self._inv.ky) == 0.0 and float(self._inv.kz) == 0.0 # XXX: Reset parameters 'prefix', 'outdir', 'fildyn' def _singlePhonInput(self): "Takes namelist and populates inputph for single phonon" nl = self._input.namelist("inputph") nl.add("tr2_ph", TR2_PH) nl.add("trans", TRANS) self._addAmasses(nl) self._addEpsil(nl) # for isolator only self._addLnscf(nl) # for non-Gamma point self._input.addAttach("%s %s %s" % (self._inv.kx, self._inv.ky, self._inv.kz)) def _multiPhonInput(self): "Takes namelist and populates inputph for multiple phonons" nl = self._input.namelist("inputph") nl.add("nq1", self._inv.nq1) nl.add("nq2", self._inv.nq2) nl.add("nq3", self._inv.nq3) nl.add("tr2_ph", TR2_PH) nl.add("ldisp", LDISP) #nl.add("prefix", QE_PREFIX) self._addAmasses(nl) self._addEpsil(nl) # for isolator only def _addAmasses(self, nl): "Takes namelist and adds amasses" masses = self.amasses() if not masses: # In case if not masses are found in PW input nl.add("amass", "ERROR: masses not defined in PW input file!") return for m in masses: nl.add(m[0], m[1]) def _addLnscf(self, nl): "Adds 'lnscf' parameter for non-Gamma point" if not self.isGammaPoint(): nl.add("lnscf", LNSCF) def _addEpsil(self, nl): "Add 'epsil' parameter for isolators only. Do nothing otherwise" if self._pwresult.isIsolator(): nl.add("epsil", EPSIL) def _simtype(self): "Be cautious in case if inventory doesn't have simtype" try: simtype = self._inv.simtype except AttributeError: return None return simtype
class CPGenerator(object): "Generator for CP molecular dynamics tasks" def __init__(self, director, inventory, input = None): self._director = director self._inv = inventory self._input = input self._init() def setInput(self): "Update input" self.setControl() self.setSystem() self.setElectrons() self.setIons() self.setCell() self.setExtra() # Methods which should be overwritten in subclasses! def setControl(self): "CONTROL namelist" pass def setSystem(self): "SYSTEM namelist" pass def setElectrons(self): "ELECTRONS namelist" pass def setIons(self): "IONS namelist" pass def setCell(self): "CELL namelist" pass def setExtra(self): "Extra parameters not specified by other namelists or cards" pass def _init(self): self._inputFromRecord() # Note: # - Change to _inputFromResult() if you want to get input from result! def _inputFromRecord(self): "Set input object from input configuration" inputs = self._director.clerk.getQEConfigurations(where="taskid='%s'" % self._emTaskId()) if len(inputs) == 0: # No input created return input = inputs[0] fname = defaultInputName(input.type) inputStr = readRecordFile(self._director.dds, input, fname) self._input = QEInput(config = inputStr, type = "cp") self._input.parse() def _inputFromResult(self): "Set input object from electron-min result" if not self._input: self._input = self._cpInput() def _cpInput(self): "Take input file from results and create QEInput object" result = CPResult(self._director, self._inv.id, linkorder = EM_LINKORDER) return result.input() def _emTaskId(self): "Returns electron-min task id" simtasks = self._director.clerk.getQESimulationTasks(where="simulationid='%s'" % self._inv.id) for st in simtasks: if st: task = self._director.clerk.getQETasks(id=st.taskid) if task.linkorder == 0: return task.id return None def toString(self): if not self._input: return "CP Generator: Electronic Minimization input is not created!" return self._input.toString()
class CPGenerator(object): "Generator for CP molecular dynamics tasks" def __init__(self, director, inventory, input=None): self._director = director self._inv = inventory self._input = input self._init() def setInput(self): "Update input" self.setControl() self.setSystem() self.setElectrons() self.setIons() self.setCell() self.setExtra() # Methods which should be overwritten in subclasses! def setControl(self): "CONTROL namelist" pass def setSystem(self): "SYSTEM namelist" pass def setElectrons(self): "ELECTRONS namelist" pass def setIons(self): "IONS namelist" pass def setCell(self): "CELL namelist" pass def setExtra(self): "Extra parameters not specified by other namelists or cards" pass def _init(self): self._inputFromRecord() # Note: # - Change to _inputFromResult() if you want to get input from result! def _inputFromRecord(self): "Set input object from input configuration" inputs = self._director.clerk.getQEConfigurations(where="taskid='%s'" % self._emTaskId()) if len(inputs) == 0: # No input created return input = inputs[0] fname = defaultInputName(input.type) inputStr = readRecordFile(self._director.dds, input, fname) self._input = QEInput(config=inputStr, type="cp") self._input.parse() def _inputFromResult(self): "Set input object from electron-min result" if not self._input: self._input = self._cpInput() def _cpInput(self): "Take input file from results and create QEInput object" result = CPResult(self._director, self._inv.id, linkorder=EM_LINKORDER) return result.input() def _emTaskId(self): "Returns electron-min task id" simtasks = self._director.clerk.getQESimulationTasks( where="simulationid='%s'" % self._inv.id) for st in simtasks: if st: task = self._director.clerk.getQETasks(id=st.taskid) if task.linkorder == 0: return task.id return None def toString(self): if not self._input: return "CP Generator: Electronic Minimization input is not created!" return self._input.toString()
def setInputpp(self): self._input = QEInput(type="bands") nl = self._input.namelist("inputpp") nl.add("filband", FILBAND) nl.add("lsym", LSIM)