コード例 #1
0
 def test_mol_from_compound(self, value, identifier_type, expected):
     compound = reaction_pb2.Compound()
     compound.identifiers.add(value=value, type=identifier_type)
     mol = message_helpers.mol_from_compound(compound)
     self.assertEqual(Chem.MolToSmiles(mol), expected)
     mol, identifier = message_helpers.mol_from_compound(
         compound, return_identifier=True)
     self.assertEqual(Chem.MolToSmiles(mol), expected)
     self.assertEqual(identifier, compound.identifiers[0])
コード例 #2
0
ファイル: filters.py プロジェクト: skearnes/ord-interface
def _compound_svg(compound: reaction_pb2.Compound,
                  bond_length: int = 25) -> str:
    """Returns an SVG string for the given compound.

    If the compound does not have a structural identifier, a sentinel value
    is returned instead.

    Args:
        compound: Compound message.
        bond_length: Bond length in pixels.

    Returns:
        String SVG or sentinel value.
    """
    try:
        mol = message_helpers.mol_from_compound(compound)
        if mol:
            svg = drawing.mol_to_svg(mol, bond_length=bond_length)
            if svg is None:
                return message_helpers.get_compound_smiles(
                    compound) or "[Compound]"
            return svg
    except ValueError:
        pass
    return message_helpers.get_compound_smiles(compound) or "[Compound]"
コード例 #3
0
def render_compound():
    """Returns an HTML-tagged SVG for the given Compound."""
    compound = reaction_pb2.Compound()
    compound.ParseFromString(flask.request.get_data())
    try:
        mol = message_helpers.mol_from_compound(compound)
        return flask.jsonify(drawing.mol_to_svg(mol))
    except ValueError:
        return ''
コード例 #4
0
ファイル: filters.py プロジェクト: Aless-T/ord-schema
def _compound_png(compound):
    """Returns a PNG string for the given compound.

    If the compound does not have a structural identifier, a sentinel value
    is returned instead.

    Args:
        compound: Compound message.

    Returns:
        String PNG or sentinel value.
    """
    try:
        mol = message_helpers.mol_from_compound(compound)
        if mol:
            return drawing.mol_to_png(mol)
    except ValueError:
        pass
    return '[Compound]'
コード例 #5
0
 def test_mol_from_compound_failures(self, value, identifier_type):
     compound = reaction_pb2.Compound()
     compound.identifiers.add(value=value, type=identifier_type)
     with self.assertRaisesRegex(ValueError,
                                 'invalid structural identifier'):
         message_helpers.mol_from_compound(compound)