Coverage for /builds/ase/ase/ase/io/eps.py : 100.00%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import time
2from ase.utils import writer
3from ase.io.utils import PlottingVariables, make_patch_list
6class EPS(PlottingVariables):
7 def __init__(self, atoms,
8 rotation='', radii=None,
9 bbox=None, colors=None, scale=20, maxwidth=500,
10 **kwargs):
11 """Encapsulated PostScript writer.
13 show_unit_cell: int
14 0: Don't show unit cell (default). 1: Show unit cell.
15 2: Show unit cell and make sure all of it is visible.
16 """
17 PlottingVariables.__init__(
18 self, atoms, rotation=rotation,
19 radii=radii, bbox=bbox, colors=colors, scale=scale,
20 maxwidth=maxwidth,
21 **kwargs)
23 def write(self, fd):
24 renderer = self._renderer(fd)
25 self.write_header(fd)
26 self.write_body(fd, renderer)
27 self.write_trailer(fd, renderer)
29 def write_header(self, fd):
30 from matplotlib.backends.backend_ps import psDefs
32 fd.write('%!PS-Adobe-3.0 EPSF-3.0\n')
33 fd.write('%%Creator: G2\n')
34 fd.write('%%CreationDate: %s\n' % time.ctime(time.time()))
35 fd.write('%%Orientation: portrait\n')
36 bbox = (0, 0, self.w, self.h)
37 fd.write('%%%%BoundingBox: %d %d %d %d\n' % bbox)
38 fd.write('%%EndComments\n')
40 Ndict = len(psDefs)
41 fd.write('%%BeginProlog\n')
42 fd.write('/mpldict %d dict def\n' % Ndict)
43 fd.write('mpldict begin\n')
44 for d in psDefs:
45 d = d.strip()
46 for line in d.split('\n'):
47 fd.write(line.strip() + '\n')
48 fd.write('%%EndProlog\n')
50 fd.write('mpldict begin\n')
51 fd.write('%d %d 0 0 clipbox\n' % (self.w, self.h))
53 def _renderer(self, fd):
54 # Subclass can override
55 from matplotlib.backends.backend_ps import RendererPS
56 return RendererPS(self.w, self.h, fd)
58 def write_body(self, fd, renderer):
59 patch_list = make_patch_list(self)
60 for patch in patch_list:
61 patch.draw(renderer)
63 def write_trailer(self, fd, renderer):
64 fd.write('end\n')
65 fd.write('showpage\n')
68@writer
69def write_eps(fd, atoms, **parameters):
70 EPS(atoms, **parameters).write(fd)