Skip to content

Commit a991e7e

Browse files
authored
Merge pull request #166 from moleculemaker/precomputation
Precomputation (3/4)
2 parents bc053d9 + 82bdbf3 commit a991e7e

40 files changed

+12117
-1511
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ trim_trailing_whitespace = true
1111
[*.ts]
1212
quote_type = single
1313

14+
[*.py]
15+
indent_size = 4
16+
1417
[*.md]
1518
max_line_length = off
1619
trim_trailing_whitespace = false

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ Thumbs.db
4747

4848
# Fetched Helm dependencies
4949
chart/charts/
50+
51+
# Data files
52+
*.xlsx

scripts/poetry.lock

+192
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/process_color_wheel.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import itertools
2+
import json
3+
import os
4+
5+
from utils import get_svg_dimensions, combine_chemical_formulas, combine
6+
7+
workdir = '../src/assets/blocks/10x10x10palette'
8+
9+
with open(os.path.join(workdir, 'blocks.json')) as file:
10+
block_set = json.load(file)
11+
12+
blocks_by_index = [[None], [None], [None]]
13+
14+
15+
def process_blocks():
16+
processed_blocks = [[], [], []]
17+
for block in block_set['blocks']:
18+
blocks_by_index[block['index']].append(block)
19+
20+
_, _, width, height = get_svg_dimensions(block['svgUrl'])
21+
processed_blocks[int(block['index'])].append({
22+
'index': block['index'],
23+
'id': block['id'],
24+
'svgUrl': block['svgUrl'],
25+
'width': width,
26+
'height': height
27+
})
28+
29+
for blocks in processed_blocks:
30+
blocks.sort(key=lambda b: b['id'])
31+
block_set['blocks'] = processed_blocks
32+
33+
34+
def generate_lookup_table():
35+
block_set['table'] = {}
36+
37+
for donor, bridge, acceptor in itertools.product(*blocks_by_index):
38+
d_id = donor['id'] if donor else 0
39+
b_id = bridge['id'] if bridge else 0
40+
a_id = acceptor['id'] if acceptor else 0
41+
key = f'{d_id}:{b_id}:{a_id}'
42+
43+
block_set['table'][key] = {
44+
'key': key,
45+
'chemicalFormula': combine_chemical_formulas(donor, bridge, acceptor),
46+
'smiles': combine('smiles', '')(donor, bridge, acceptor),
47+
'lambdaMaxShift': combine('lambdaMaxShift', 0)(donor, bridge, acceptor),
48+
'molecularWeight': combine('molecularWeight', 0)(donor, bridge, acceptor),
49+
}
50+
51+
52+
process_blocks()
53+
generate_lookup_table()
54+
55+
with open(os.path.join(workdir, 'data.json'), 'w') as file:
56+
json.dump(block_set, file, indent=2)

0 commit comments

Comments
 (0)