예제 #1
0
 def kpoints(self,para=dict(),save=True):
     file = self.path+self.__kpoints
     if self.highestFileVersion:
         newfile = [file]
         if not files.getHighestVersion(newfile):
             return dict()
         file=newfile[0]
     result = dict()
     readData = files.readfile(file)
     if para.has_key(par.Kcount):
         readData[1] = para[par.Kcount]
     else:
         s=readData[1].split()[0]
         result[par.Kcount] = str(s)+'\n'
     ktype =""
     if para.has_key(par.Ktype):
         readData[2] = para[par.Ktype]
         ktype=para[par.Ktype]
     else:
         result[par.Ktype] = readData[2]
         ktype=readData[2]
     if ktype[0].lower()=="l":
         if para.has_key(par.Klinetype):
             readData[3] = para[par.Klinetype]
         else:
             result[par.Klinetype] = readData[3]
         if para.has_key(par.Kline):
             for i in range(4,len(readData)):
                 readData[i]=""
             data =[]
             i = 0
             for ks in para[par.Kline]:
                 d=[]
                 for k in ks:
                     d.append(str(k))
                 data.append(" ".join(d))
                 if i%2 == 1:
                     data.append("")
                 i+=1
             readData[4]='\n'.join(data)
         else:
             klinedata =[]
             for i in range(4,len(readData)):
                 if readData[i]!="\n":
                     klinedata.append(readData[i].split())
             result[par.Kline]=klinedata
     else:
         if para.has_key(par.Kmesh):
             if len(para[par.Kmesh])==1:
                 val = para[par.Kmesh][0]
                 para[par.Kmesh] = [val,val,val]
             readData[3] =files.vecToLine(para[par.Kmesh],Int=True)
         else:
             if len(readData)>3:
                 s = str(readData[3])
                 result[par.Kmesh]=s.split()
     if save:
         files.writefile(file,readData)
     return result
예제 #2
0
 def setTempdirstart(self,count):
     if self.sequential:
         count=1
     file =self.temppath+self.tempdirstartFilename
     if os.path.isfile(file):
         self.tempdirstart = int(files.readfile(file)[0])
     else:
         self.tempdirstart=1
     files.writefile(file,"%.0d"%(self.tempdirstart+count+1))
예제 #3
0
 def startjob(self,jobnr):
     print "starte job"
     runfile="test.sh"
     if not self.testrun:
         runfile=self.runLine
     scriptname="run.sh"
     path =self.gettemppath(jobnr)
     self.startedcalcs +=1
     decimalcount = int(math.floor(math.log10(self.calculations)))
     fullname = self.name+("_%"+str(decimalcount+1)+"d/%d")%(self.startedcalcs,self.calculations)
     fullname = fullname.replace(" ","0")
     print "Name: "+fullname+" in folder: "+path
     script = pbs.makescript(path,runfile,self.nodes,self.ppn,self.queue,fullname,self.email,self.outpath,self.memorymultiplikator,self.hours,self.pbsparameters)
     scriptfile =path+scriptname
     files.writefile(scriptfile,script)
     jobid =pbs.qsub(scriptfile)
     open(self.jobidfile,"a").write(jobid+"\n")
     return jobid
예제 #4
0
 def poscar(self,file=__poscar, para = dict(),save=True):
     """
     file: Filename of poscar
     para: dictionary of parameters
     """
     file=self.path+file
     if self.highestFileVersion:
         newfile = [file]
         if not files.getHighestVersion(newfile):
             return dict()
         file=newfile[0]
     result = dict()
     readData = files.readfile(file)
     if para.has_key(par.LatticeConstant):
         readData[1] = files.toLine(para[par.LatticeConstant])
     else:
         if len(readData)>1:
             s = str(readData[1])
             result[par.LatticeConstant] = s.strip(' \n')
     if para.has_key(par.Basisvectors):
         readData[2] = files.matrixToLine(para[par.Basisvectors])
         readData[3] =""
         readData[4]=""
     else:
         if len(readData)>4:
             bv = list()
             for i in range(2,5):
                 bv.append(filter(None,str(readData[i]).strip(' \n').split(" ")))
             result[par.Basisvectors] =bv
     atomcount=0
     if para.has_key(par.Atoms):
         readData[5]=""
         readData[6]=""
         for atom in para[par.Atoms]:
             readData[5]+=" "+atom[0]
             readData[6]+=" "+str(int(float(atom[1])))
             atomcount+=int(float(atom[1]))
         readData[5]+='\n'
         readData[6]+='\n'
     else:
         if len(readData)>6:
             s1 = readData[5].strip(' \n').split()
             s2 = readData[6].strip(' \n').split()
             if (len(s1) == len(s2)):
                 atoms = []
                 for i in range(len(s1)):
                     atoms.append([s1[i],s2[i]])
                     atomcount+=int(float(s2[i]))
                 result[par.Atoms]=atoms
     atomcount = int(atomcount)
     atomlines = range(9,9+atomcount)
     text=list()
     for i in atomlines:
         text.append("")
     ### atomcount has to equal #Atompos & #Atommove
     atomtext=list()
     if not (para.has_key(par.Atompos) and para.has_key(par.Atommove)):
         for i in atomlines:
             atomtext.append(filter(None,str(readData[i]).strip(' \n').split(" ")))
     if para.has_key(par.Atompos):
        if len(para[par.Atompos])==atomcount:
             for i in range(0,atomcount):
                 text[i]=files.vecToLine(para[par.Atompos][i])[:-1]
     else:
        ap= list()
        for i in range(0,atomcount):
             ap.append(atomtext[i][0:3])
             text[i]=" ".join(atomtext[i][0:3])
        result[par.Atompos] = ap
     if para.has_key(par.Atommove):
        if len(para[par.Atommove])==atomcount:
             for i in range(0,atomcount):
                 text[i]+=" "+files.vecToLine(para[par.Atommove][i])[:-1]
        elif len(para[par.Atommove])==1:
             for i in range(0,atomcount):
                 text[i]+=" "+files.vecToLine(para[par.Atommove][0])[:-1]
     else:
        am=list()
        for i in range(0,atomcount):
             am.append(atomtext[i][3:6])
             text[i]+=" "+" ".join(atomtext[i][3:6])
        result[par.Atommove] = am
     if len(atomlines) == 0:
         atomlines.append(9)
     for i in range(atomlines[0],len(readData)):
         readData[i]=""
     while len(readData)<=atomlines[0]:
         readData.append("")
     readData[atomlines[0]]='\n'.join(text)
     if save:
         files.writefile(file,readData)
     return result