def __init__(self): self.linewidth_pt = None # XXX there are both stroke and fill color spaces self.colorspace = None self.strokeattr = 1 self.fillattr = 1 self.selectedfont = None self.textregion = 0 self.trafo = trafo.trafo() self.fillstyles = []
def processPDF(self, file, writer, context, registry, bbox): # we need to keep track of the resources used by the pattern, hence # we create our own registry, which we merge immediately in the main registry patternregistry = pdfwriter.PDFregistry() patternfile = cStringIO.StringIO() realpatternbbox = bboxmodule.empty() canvas.canvas.processPDF(self, patternfile, writer, pdfwriter.context(), patternregistry, realpatternbbox) patternproc = patternfile.getvalue() patternfile.close() registry.mergeregistry(patternregistry) if self.xstep is None: xstep = unit.topt(realpatternbbox.width()) else: xstep = unit.topt(self.xstep) if self.ystep is None: ystep = unit.topt(realpatternbbox.height()) else: ystep = unit.topt(self.ystep) if not xstep: raise ValueError("xstep in pattern cannot be zero") if not ystep: raise ValueError("ystep in pattern cannot be zero") patternbbox = self.patternbbox or realpatternbbox.enlarged(5 * unit.pt) patterntrafo = self.patterntrafo or trafo.trafo() registry.add( PDFpattern(self.id, self.patterntype, self.painttype, self.tilingtype, patternbbox, xstep, ystep, patterntrafo, patternproc, writer, registry, patternregistry)) # activate pattern if context.colorspace != "Pattern": # we only set the fill color space (see next comment) file.write("/Pattern cs\n") context.colorspace = "Pattern" if context.strokeattr: # using patterns as stroke colors doesn't seem to work, so # we just don't do this... warnings.warn("ignoring stroke color for patterns in PDF") if context.fillattr: file.write("/%s scn\n" % self.id)
def __init__(self, attrs=None, texrunner=None): """construct a canvas The canvas can be modfied by supplying a list of attrs, which have to be instances of one of the following classes: - trafo.trafo (leading to a global transformation of the canvas) - canvas.clip (clips the canvas) - style.strokestyle, style.fillstyle (sets some global attributes of the canvas) Note that, while the first two properties are fixed for the whole canvas, the last one can be changed via canvas.set(). The texrunner instance used for the text method can be specified using the texrunner argument. It defaults to text.defaulttexrunner """ self.items = [] self.trafo = trafo.trafo() self.clipbbox = None if attrs is None: attrs = [] if texrunner is not None: self.texrunner = texrunner else: # prevent cyclic imports import text self.texrunner = text.defaulttexrunner attr.checkattrs(attrs, [trafo.trafo_pt, clip, style.strokestyle, style.fillstyle]) # We have to reverse the trafos such that the PostScript concat operators # are in the right order. Correspondingly, we below multiply the current self.trafo # from the right. # Note that while for the stroke and fill styles the order doesn't matter at all, # this is not true for the clip operation. for aattr in attrs[::-1]: if isinstance(aattr, trafo.trafo_pt): self.trafo = self.trafo * aattr elif isinstance(aattr, clip): if self.clipbbox is None: self.clipbbox = aattr.clipbbox().transformed(self.trafo) else: self.clippbox *= aattr.clipbbox().transformed(self.trafo) self.items.append(aattr)
def __init__(self, attrs=None, texrunner=None): """construct a canvas The canvas can be modfied by supplying a list of attrs, which have to be instances of one of the following classes: - trafo.trafo (leading to a global transformation of the canvas) - canvas.clip (clips the canvas) - style.strokestyle, style.fillstyle (sets some global attributes of the canvas) Note that, while the first two properties are fixed for the whole canvas, the last one can be changed via canvas.set(). The texrunner instance used for the text method can be specified using the texrunner argument. It defaults to text.defaulttexrunner """ self.items = [] self.trafo = trafo.trafo() self.clipbbox = None self.layers = {} if attrs is None: attrs = [] if texrunner is not None: self.texrunner = texrunner else: # prevent cyclic imports import text self.texrunner = text.defaulttexrunner attr.checkattrs( attrs, [trafo.trafo_pt, clip, style.strokestyle, style.fillstyle]) # We have to reverse the trafos such that the PostScript concat operators # are in the right order. Correspondingly, we below multiply the current self.trafo # from the right. # Note that while for the stroke and fill styles the order doesn't matter at all, # this is not true for the clip operation. for aattr in attrs[::-1]: if isinstance(aattr, trafo.trafo_pt): self.trafo = self.trafo * aattr elif isinstance(aattr, clip): if self.clipbbox is None: self.clipbbox = aattr.clipbbox().transformed(self.trafo) else: self.clippbox *= aattr.clipbbox().transformed(self.trafo) self.items.append(aattr)
def processPDF(self, file, writer, context, registry, bbox): # we need to keep track of the resources used by the pattern, hence # we create our own registry, which we merge immediately in the main registry patternregistry = pdfwriter.PDFregistry() patternfile = cStringIO.StringIO() realpatternbbox = bboxmodule.empty() canvas._canvas.processPDF(self, patternfile, writer, pdfwriter.context(), patternregistry, realpatternbbox) patternproc = patternfile.getvalue() patternfile.close() registry.mergeregistry(patternregistry) if self.xstep is None: xstep = unit.topt(realpatternbbox.width()) else: xstep = unit.topt(self.xstep) if self.ystep is None: ystep = unit.topt(realpatternbbox.height()) else: ystep = unit.topt(self.ystep) if not xstep: raise ValueError("xstep in pattern cannot be zero") if not ystep: raise ValueError("ystep in pattern cannot be zero") patternbbox = self.patternbbox or realpatternbbox.enlarged(5*unit.pt) patterntrafo = self.patterntrafo or trafo.trafo() registry.add(PDFpattern(self.id, self.patterntype, self.painttype, self.tilingtype, patternbbox, xstep, ystep, patterntrafo, patternproc, writer, registry, patternregistry)) # activate pattern if context.colorspace != "Pattern": # we only set the fill color space (see next comment) file.write("/Pattern cs\n") context.colorspace = "Pattern" if context.strokeattr: # using patterns as stroke colors doesn't seem to work, so # we just don't do this... warnings.warn("ignoring stroke color for patterns in PDF") if context.fillattr: file.write("/%s scn\n"% self.id)
def cmp_cftrans(qsplit, L, nsites, nspins): """Computes transformation matrix from spherical harmonics to basis specified by qsplit.""" transtype = qsplit_table[qsplit][2] if transtype == 'real': T0 = trafo.trafo(L, False) # False means not pseudo functions, but real functions if nspins == 1: T = T0 else: Z = zeros((len(T0), len(T0)), dtype=complex) T = bmat([[T0, Z], [Z, T0]]) elif transtype == 'relativistic': T = trafoso.trafoso(L) elif transtype == 'none': T = identity(nspins*(2*L+1), dtype=complex) elif transtype == '5d-jeff': if (L==2): s23 = sqrt(2./3.) s16 = sqrt(1./6.) s29 = sqrt(2./9.) s12 = sqrt(1./12.) s34 = sqrt(3./4.) s2 = sqrt(1./2.) alp = 1/2. T=[ # -2,dn, -1,dn, 0,dn, 1,dn, 2,dn, -2,up, -1,up, 0,up, 1,up, 2,up, l.s [ 0j, s23, 0j, 0j, 0j, s16, 0j, 0j, 0j, -s16], # sef=-1/2 1.0 [ -s16, 0j, 0j, 0j, s16, 0j, 0j, 0j, s23, 0j], # sef= 1/2 1.0 [ 0j, alp, 0j, alp, 0j, -alp, 0j, 0j, 0j, alp], # sef=-3/2 -0.5 [ alp, 0j, 0j, 0j, -alp, 0j, alp, 0j, alp, 0j], # sef= 3/2 -0.5 [ -s12, 0j, 0j, 0j, s12, 0j, s34, 0j, -s12, 0j], # sef=-1/2 -0.5 [ 0j, s12, 0j, -s34, 0j, -s12, 0j, 0j, 0j, s12], # sef= 1/2 -0.5 [ 0j, 0j, 1., 0j, 0j, 0j, 0j, 0j, 0j, 0j], # z^2,up 0.0 [ 0j, 0j, 0j, 0j, 0j, 0j, 0j, 1., 0j, 0j], # z^2,dn 0.0 [ s2, 0j, 0j, 0j, s2, 0j, 0j, 0j, 0j, 0j], # x^2-y^2,up 0.0 [ 0j, 0j, 0j, 0j, 0j, s2, 0j, 0j, 0j, s2], # x^2-y^2,dn 0.0 ] T = array(T) else: T = trafoso.trafoso(L) elif transtype == 't2g': T0 = trafo.trafo(L, False) # False means not pseudo functions, but real functions if L == 2: if nspins==1: T = vstack((T0[2:,:],T0[:2,:])) else: z1=zeros(len(T0)) T1=hstack( (T0[2:,:],vstack((z1,z1,z1))) ) # t2g,up T2=hstack( (vstack((z1,z1,z1)),T0[2:,:]) ) # t2g,dn T3=hstack( (T0[:2,:],vstack((z1,z1))) ) # eg,up T4=hstack( (vstack((z1,z1)),T0[:2,:]) ) # eg,dn T = vstack((T1,T2,T3,T4)) else: if nspins==1: T = T0 else: Z = zeros((len(T0), len(T0)), dtype=complex) T = bmat([[T0, Z], [Z, T0]]) elif transtype == 'eg': T = trafo.trafo(L, False) # False means not pseudo functions, but real functions if nspins==2: if L==2: z1=zeros(len(T0)) T1=hstack( (T0[:2,:],vstack((z1,z1))) ) # eg,up T2=hstack( (vstack((z1,z1)),T0[:2,:]) ) # eg,dn T3=hstack( (T0[2:,:],vstack((z1,z1,z1))) ) # t2g,up T4=hstack( (vstack((z1,z1,z1)),T0[2:,:]) ) # t2g,dn T = vstack((T1,T2,T3,T4)) else: Z = zeros((len(T0), len(T0)), dtype=complex) T = bmat([[T0, Z], [Z, T0]]) else: raise Exception, 'ERROR: Transformation `'+transtype+'` not yet implemented.' # make block matrix, one block for each site of (potentially) cluster problem Z = zeros((len(T), len(T)), dtype=complex) S = [[Z]*nsites for i in range(nsites)] for i in range(nsites): S[i][i] = T return asarray(bmat(S))