def toLines(self, stru): """Convert Structure stru to a list of lines in DISCUS format. Return list of strings. """ self.stru = stru # if necessary, convert self.stru to PDFFitStructure if not isinstance(stru, PDFFitStructure): self.stru = PDFFitStructure(stru) # build the stru_pdffit dictionary initialized from the defaults # in PDFFitStructure stru_pdffit = PDFFitStructure().pdffit if stru.pdffit: stru_pdffit.update(stru.pdffit) # here we can start self.lines = lines = [] lines.append( "title " + self.stru.title.strip() ) lines.append( "spcgr " + stru_pdffit["spcgr"] ) if stru_pdffit.get('spdiameter', 0.0) > 0.0: line = 'shape sphere, %g' % stru_pdffit['spdiameter'] lines.append(line) if stru_pdffit.get('stepcut', 0.0) > 0.0: line = 'shape stepcut, %g' % stru_pdffit['stepcut'] lines.append(line) lines.append( "cell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" % self.stru.lattice.abcABG() ) lines.append( "ncell %9i, %9i, %9i, %9i" % (1, 1, 1, len(self.stru)) ) lines.append( "atoms" ) for a in self.stru: lines.append( "%-4s %17.8f %17.8f %17.8f %12.4f" % ( a.element.upper(), a.xyz[0], a.xyz[1], a.xyz[2], a.Bisoequiv)) return lines
def toLines(self, stru): """Convert Structure stru to a list of lines in PDFfit format. Return list of strings. """ # build the stru_pdffit dictionary initialized from the defaults # in PDFFitStructure stru_pdffit = PDFFitStructure().pdffit if stru.pdffit: stru_pdffit.update(stru.pdffit) lines = [] # default values of standard deviations d_sigxyz = numpy.zeros(3, dtype=float) d_sigo = 0.0 d_sigU = numpy.zeros((3,3), dtype=float) # here we can start l = "title " + stru.title lines.append( l.strip() ) lines.append( "format pdffit" ) lines.append( "scale %9.6f" % stru_pdffit["scale"] ) lines.append( "sharp %9.6f, %9.6f, %9.6f, %9.6f" % ( stru_pdffit["delta2"], stru_pdffit["delta1"], stru_pdffit["sratio"], stru_pdffit["rcut"]) ) lines.append( "spcgr " + stru_pdffit["spcgr"] ) if stru_pdffit.get('spdiameter', 0.0) > 0.0: line = 'shape sphere, %g' % stru_pdffit['spdiameter'] lines.append(line) if stru_pdffit.get('stepcut', 0.0) > 0.0: line = 'shape stepcut, %g' % stru_pdffit['stepcut'] lines.append(line) lat = stru.lattice lines.append( "cell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" % ( lat.a, lat.b, lat.c, lat.alpha, lat.beta, lat.gamma) ) lines.append( "dcell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" % tuple(stru_pdffit["dcell"]) ) lines.append( "ncell %9i, %9i, %9i, %9i" % (1, 1, 1, len(stru)) ) lines.append( "atoms" ) for a in stru: ad = a.__dict__ lines.append( "%-4s %17.8f %17.8f %17.8f %12.4f" % ( a.element.upper(), a.xyz[0], a.xyz[1], a.xyz[2], a.occupancy) ) sigmas = numpy.concatenate( ( ad.get("sigxyz", d_sigxyz), [ad.get("sigo", d_sigo)] ) ) lines.append( " %18.8f %17.8f %17.8f %12.4f" % tuple(sigmas) ) sigU = ad.get("sigU", d_sigU) Uii = ( a.U[0][0], a.U[1][1], a.U[2][2] ) Uij = ( a.U[0][1], a.U[0][2], a.U[1][2] ) sigUii = ( sigU[0][0], sigU[1][1], sigU[2][2] ) sigUij = ( sigU[0][1], sigU[0][2], sigU[1][2] ) lines.append( " %18.8f %17.8f %17.8f" % Uii ) lines.append( " %18.8f %17.8f %17.8f" % sigUii ) lines.append( " %18.8f %17.8f %17.8f" % Uij ) lines.append( " %18.8f %17.8f %17.8f" % sigUij ) return lines
def toLines(self, stru): """Convert Structure stru to a list of lines in PDFfit format. Return list of strings. """ # build the stru_pdffit dictionary initialized from the defaults # in PDFFitStructure stru_pdffit = PDFFitStructure().pdffit if stru.pdffit: stru_pdffit.update(stru.pdffit) lines = [] # default values of standard deviations d_sigxyz = numpy.zeros(3, dtype=float) d_sigo = 0.0 d_sigU = numpy.zeros((3, 3), dtype=float) # here we can start l = "title " + stru.title lines.append(l.strip()) lines.append("format pdffit") lines.append("scale %9.6f" % stru_pdffit["scale"]) lines.append("sharp %9.6f, %9.6f, %9.6f, %9.6f" % (stru_pdffit["delta2"], stru_pdffit["delta1"], stru_pdffit["sratio"], stru_pdffit["rcut"])) lines.append("spcgr " + stru_pdffit["spcgr"]) if stru_pdffit.get('spdiameter', 0.0) > 0.0: line = 'shape sphere, %g' % stru_pdffit['spdiameter'] lines.append(line) if stru_pdffit.get('stepcut', 0.0) > 0.0: line = 'shape stepcut, %g' % stru_pdffit['stepcut'] lines.append(line) lat = stru.lattice lines.append("cell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" % (lat.a, lat.b, lat.c, lat.alpha, lat.beta, lat.gamma)) lines.append("dcell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" % tuple(stru_pdffit["dcell"])) lines.append("ncell %9i, %9i, %9i, %9i" % (1, 1, 1, len(stru))) lines.append("atoms") for a in stru: ad = a.__dict__ lines.append( "%-4s %17.8f %17.8f %17.8f %12.4f" % (a.element.upper(), a.xyz[0], a.xyz[1], a.xyz[2], a.occupancy)) sigmas = numpy.concatenate( (ad.get("sigxyz", d_sigxyz), [ad.get("sigo", d_sigo)])) lines.append(" %18.8f %17.8f %17.8f %12.4f" % tuple(sigmas)) sigU = ad.get("sigU", d_sigU) Uii = (a.U[0][0], a.U[1][1], a.U[2][2]) Uij = (a.U[0][1], a.U[0][2], a.U[1][2]) sigUii = (sigU[0][0], sigU[1][1], sigU[2][2]) sigUij = (sigU[0][1], sigU[0][2], sigU[1][2]) lines.append(" %18.8f %17.8f %17.8f" % Uii) lines.append(" %18.8f %17.8f %17.8f" % sigUii) lines.append(" %18.8f %17.8f %17.8f" % Uij) lines.append(" %18.8f %17.8f %17.8f" % sigUij) return lines