-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathribbon.py
133 lines (117 loc) · 3.66 KB
/
ribbon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import axi
import sys
import textwrap
NUMBER = '34'
LABEL = '#%s' % NUMBER
TITLE = textwrap.wrap(
"Beta Subunit of the 20S Proteasome from T. acidophilum"
, 36)
SUBTITLE = textwrap.wrap(
"These coordinates are from the 1995 crystal structure by Lowe et al. (Lowe et al., 1995). PDB entry 1PMA."
# "Coordinates from the 1995 crystal structure by Lowe et al. PDB entry 1PMA."
, 60)
def concat(ds):
result = axi.Drawing()
for d in ds:
result.add(d)
return result
def stack_drawings(ds, spacing=0):
result = axi.Drawing()
y = 0
for d in ds:
d = d.origin().translate(-d.width / 2, y)
result.add(d)
y += d.height + spacing
return result
def grid_drawings(ds, columns, spacing=0):
result = axi.Drawing()
w = max(d.width for d in ds) + spacing
h = max(d.height for d in ds) + spacing
for i, d in enumerate(ds):
r = i / columns
c = i % columns
x = c * w + (w - d.width) / 2
y = r * h + (h - d.height) / 2
d = d.origin().translate(x, y)
result.add(d)
return result
def title():
ds = [axi.Drawing(axi.text(line, axi.TIMESIB)) for line in TITLE]
spacing = max(d.height for d in ds) * 1.5
ds = [d.translate(-d.width / 2, i * spacing) for i, d in enumerate(ds)]
d = concat(ds)
d = d.scale_to_fit_width(8.5 * 4 / 5)
d = d.scale_to_fit_height(0.8)
d = d.join_paths(0.01)
return d
def subtitle():
# ds = [axi.Drawing(p) for p in axi.justify_text(SUBTITLE, axi.TIMESR)]
# spacing = max(d.height for d in ds) * 1.5
# ds = [d.translate(0, i * spacing) for i, d in enumerate(ds)]
ds = [axi.Drawing(axi.text(line, axi.TIMESR)) for line in SUBTITLE]
spacing = max(d.height for d in ds) * 1.5
ds = [d.translate(-d.width / 2, i * spacing) for i, d in enumerate(ds)]
d = concat(ds)
d = d.scale_to_fit_width(8.5 * 2 / 3)
d = d.scale_to_fit_height(0.4)
d = d.join_paths(0.01)
return d
def label():
d = axi.Drawing(axi.text(LABEL, axi.FUTURAL))
d = d.scale_to_fit_height(0.125)
d = d.rotate(-90)
d = d.move(12, 8.5, 1, 1)
d = d.join_paths(0.01)
return d
def main():
text = stack_drawings([title(), subtitle()], 0.3125)
text = text.rotate(-90)
text = text.move(12, 8.5 / 2, 1, 0.5)
# text = title()
filenames = [
sys.argv[1],
# 'ribbon/1j1c.txt',
# 'ribbon/amyloid-beta/1mwp.txt',
# 'ribbon/amyloid-beta/1owt.txt',
# 'ribbon/amyloid-beta/1rw6.txt',
# 'ribbon/amyloid-beta/1iyt.txt',
]
angles = [90, 90, 75, 60]
print 'loading paths'
ds = []
for filename, angle in zip(filenames, angles):
ds.append(axi.Drawing(axi.load_paths(filename)).scale(1, -1))
# d = grid_drawings(ds, 2, 1)
d = ds[0]
print len(d.paths)
print 'joining paths'
d = d.join_paths(0.01)
print len(d.paths)
print 'transforming paths'
# d = d.scale(1, -1)
d = d.rotate(180)
d = d.rotate_and_scale_to_fit(8.5, 12 - text.height)
# d = d.origin()
print 'sorting paths'
d = d.sort_paths()
print 'joining paths'
d = d.join_paths(0.01)
print len(d.paths)
print 'simplifying paths'
d = d.simplify_paths(0.001)
# add title and label and fit to page
# d = stack_drawings([d, text], 1)
# d = d.rotate(-90)
# d = d.center(12, 8.5)
d = d.rotate_and_scale_to_fit(12, 8.5).translate(-text.width * 0.6666, 0)
d.add(text)
# d.add(title())
d.add(label())
print 'rendering paths'
d.render(line_width=0.25/25.4).write_to_png('out.png')
# axi.draw(d)
print d.bounds
d.dump('out.axi')
d.dump_svg('out.svg')
if __name__ == '__main__':
main()