Skip to content

Commit ec5b9be

Browse files
authored
Updates to reaction rendering (#562)
* Updates to reaction rendering * Show UNSPECIFIED inputs/ouputs in compact mode
1 parent 124b479 commit ec5b9be

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

ord_schema/visualization/filters.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,10 @@ def _get_compact_components(
647647
component: Compound message.
648648
is_last: Whether this is the last compound that will be displayed.
649649
"""
650-
roles_to_keep = [reaction_pb2.ReactionRole.REACTANT]
650+
roles_to_keep = [
651+
reaction_pb2.ReactionRole.REACTANT,
652+
reaction_pb2.ReactionRole.UNSPECIFIED,
653+
]
651654
compounds = []
652655
for _, value in _sort_addition_order(inputs):
653656
for component in value.components:
@@ -660,12 +663,27 @@ def _get_compact_components(
660663
yield compound, False
661664

662665

666+
def _get_compact_products(
667+
products: Iterable[reaction_pb2.ProductCompound]
668+
) -> List[reaction_pb2.ProductCompound]:
669+
"""Returns a list of product compounds for 'compact' visualization."""
670+
roles_to_keep = [
671+
reaction_pb2.ReactionRole.PRODUCT,
672+
reaction_pb2.ReactionRole.UNSPECIFIED,
673+
]
674+
return [
675+
compound for compound in products
676+
if compound.reaction_role in roles_to_keep
677+
]
678+
679+
663680
TEMPLATE_FILTERS = {
664681
'round': _round,
665682
'is_true': _is_true,
666683
'datetimeformat': _datetimeformat,
667684
'uses_addition_order': _uses_addition_order,
668685
'get_compact_components': _get_compact_components,
686+
'get_compact_products': _get_compact_products,
669687
'input_addition': _input_addition,
670688
'compound_svg': _compound_svg,
671689
'compound_png': _compound_png,

ord_schema/visualization/generate_text_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def setUp(self):
5858
name='hexanone',
5959
smiles='CCCCC(=O)C',
6060
).identifiers)
61-
reaction.reaction_id = 'dummy_reaction_id'
6261
self._reaction = reaction
6362

6463
def test_text(self):
@@ -80,7 +79,6 @@ def test_html(self):
8079
self.assertRegex(html, '40 min')
8180
self.assertRegex(html, 'solvent')
8281
self.assertRegex(html, '100 °C')
83-
self.assertRegex(html, 'dummy_reaction_id')
8482

8583
def test_compact_html(self):
8684
html = generate_text.generate_html(self._reaction, compact=True)
@@ -91,7 +89,6 @@ def test_compact_html(self):
9189
self.assertNotRegex(html, '40 min')
9290
self.assertNotRegex(html, 'solvent')
9391
self.assertNotRegex(html, '100 °C')
94-
self.assertRegex(html, 'dummy_reaction_id')
9592

9693

9794
if __name__ == '__main__':

ord_schema/visualization/template.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@
5252
</head>
5353

5454
<body>
55-
{% if not compact %}
56-
<h2>{{ reaction.reaction_id }}</h2>
57-
{% else %}
58-
<p style="font-family: monospace;">{{ reaction.reaction_id }}</p>
59-
{% endif %}
6055

6156
<table class="autogen_reaction_table">
6257

@@ -119,7 +114,7 @@ <h2>{{ reaction.reaction_id }}</h2>
119114
<span style="font-size:36px; padding: 0 10px 0 10px;">&#10230;</span>
120115
</td>
121116
{% for outcome in reaction.outcomes %}
122-
{% for product in outcome.products %}
117+
{% for product in outcome.products|get_compact_products %}
123118
<td class="clean">{{ product|compound_svg(bond_length) }}</td>
124119
{% endfor %}
125120
{% endfor %}

0 commit comments

Comments
 (0)