Skip to content

Commit

Permalink
Updates to reaction rendering (#562)
Browse files Browse the repository at this point in the history
* Updates to reaction rendering

* Show UNSPECIFIED inputs/ouputs in compact mode
  • Loading branch information
skearnes authored Feb 18, 2021
1 parent 124b479 commit ec5b9be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
20 changes: 19 additions & 1 deletion ord_schema/visualization/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,10 @@ def _get_compact_components(
component: Compound message.
is_last: Whether this is the last compound that will be displayed.
"""
roles_to_keep = [reaction_pb2.ReactionRole.REACTANT]
roles_to_keep = [
reaction_pb2.ReactionRole.REACTANT,
reaction_pb2.ReactionRole.UNSPECIFIED,
]
compounds = []
for _, value in _sort_addition_order(inputs):
for component in value.components:
Expand All @@ -660,12 +663,27 @@ def _get_compact_components(
yield compound, False


def _get_compact_products(
products: Iterable[reaction_pb2.ProductCompound]
) -> List[reaction_pb2.ProductCompound]:
"""Returns a list of product compounds for 'compact' visualization."""
roles_to_keep = [
reaction_pb2.ReactionRole.PRODUCT,
reaction_pb2.ReactionRole.UNSPECIFIED,
]
return [
compound for compound in products
if compound.reaction_role in roles_to_keep
]


TEMPLATE_FILTERS = {
'round': _round,
'is_true': _is_true,
'datetimeformat': _datetimeformat,
'uses_addition_order': _uses_addition_order,
'get_compact_components': _get_compact_components,
'get_compact_products': _get_compact_products,
'input_addition': _input_addition,
'compound_svg': _compound_svg,
'compound_png': _compound_png,
Expand Down
3 changes: 0 additions & 3 deletions ord_schema/visualization/generate_text_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def setUp(self):
name='hexanone',
smiles='CCCCC(=O)C',
).identifiers)
reaction.reaction_id = 'dummy_reaction_id'
self._reaction = reaction

def test_text(self):
Expand All @@ -80,7 +79,6 @@ def test_html(self):
self.assertRegex(html, '40 min')
self.assertRegex(html, 'solvent')
self.assertRegex(html, '100 °C')
self.assertRegex(html, 'dummy_reaction_id')

def test_compact_html(self):
html = generate_text.generate_html(self._reaction, compact=True)
Expand All @@ -91,7 +89,6 @@ def test_compact_html(self):
self.assertNotRegex(html, '40 min')
self.assertNotRegex(html, 'solvent')
self.assertNotRegex(html, '100 °C')
self.assertRegex(html, 'dummy_reaction_id')


if __name__ == '__main__':
Expand Down
7 changes: 1 addition & 6 deletions ord_schema/visualization/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
</head>

<body>
{% if not compact %}
<h2>{{ reaction.reaction_id }}</h2>
{% else %}
<p style="font-family: monospace;">{{ reaction.reaction_id }}</p>
{% endif %}

<table class="autogen_reaction_table">

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

0 comments on commit ec5b9be

Please sign in to comment.