def printpara(para=dict()): for key,val in para.iteritems(): s="key:"+key+" val:" if isinstance(val, list): s+= files.matrixToLine(val) elif isinstance(val, dict): for key,val in val.iteritems(): s+= key+":"+str(val)+" " else: s+=str(val) print s
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