-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
655 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "visyn_core", | ||
"description": "Core repository for datavisyn applications.", | ||
"version": "10.0.2", | ||
"version": "10.0.3", | ||
"author": { | ||
"name": "datavisyn GmbH", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,34 @@ | ||
from collections.abc import Callable | ||
|
||
from rdkit.Chem import Mol # type: ignore | ||
from rdkit.Chem.Draw import SimilarityMaps, rdMolDraw2D # type: ignore | ||
from rdkit.Chem.Draw.rdMolDraw2D import MolDraw2DSVG # type: ignore | ||
from rdkit.Chem.Draw.SimilarityMaps import GetSimilarityMapForFingerprint # type: ignore | ||
|
||
|
||
def _draw_wrapper(draw_inner: Callable[[MolDraw2DSVG, ...], None]) -> Callable[..., str]: # type: ignore | ||
"""Function wrapper for drawing | ||
Can annotate any function that takes a drawer as first arg, ignores its return type | ||
Passes a drawer into annotated function | ||
Passes on args and kwargs | ||
Returns a svg as string | ||
""" | ||
|
||
def inner(*args, **kwargs): | ||
drawer = rdMolDraw2D.MolDraw2DSVG(300, 300) | ||
_options = drawer.drawOptions() | ||
_options.clearBackground = False | ||
|
||
draw_inner(drawer, *args, **kwargs) | ||
def get_drawer(size: int): | ||
drawer = rdMolDraw2D.MolDraw2DSVG(size, size) | ||
_options = drawer.drawOptions() | ||
_options.clearBackground = False | ||
return drawer | ||
|
||
drawer.FinishDrawing() | ||
return drawer.GetDrawingText().replace("<?xml version='1.0' encoding='iso-8859-1'?>\n", "") | ||
|
||
return inner | ||
def finish_drawing(drawer: MolDraw2DSVG) -> str: | ||
drawer.FinishDrawing() | ||
return drawer.GetDrawingText().replace("<?xml version='1.0' encoding='iso-8859-1'?>\n", "") | ||
|
||
|
||
@_draw_wrapper | ||
def draw(drawer: MolDraw2DSVG, structure, substructure=None): | ||
def draw(structure, *, size: int, substructure: str | None = None): | ||
drawer = get_drawer(size) | ||
highlight_atoms = structure.GetSubstructMatch(substructure) if substructure else None | ||
drawer.DrawMolecule(structure, highlightAtoms=highlight_atoms, highlightBonds=None, highlightAtomColors=None, highlightBondColors=None) | ||
return finish_drawing(drawer) | ||
|
||
|
||
def _similarity(m, i): | ||
"""https://github.com/rdkit/rdkit/blob/master/rdkit/Chem/Draw/SimilarityMaps.py""" | ||
return SimilarityMaps.GetMorganFingerprint(m, i, radius=2, fpType="bv") | ||
|
||
|
||
@_draw_wrapper | ||
def draw_similarity(drawer: MolDraw2DSVG, ref: Mol, probe=Mol, *_): # ignore args after probe | ||
def draw_similarity(ref: Mol, probe=Mol, *_): # ignore args after probe | ||
drawer = get_drawer(300) | ||
GetSimilarityMapForFingerprint(ref, probe, fpFunction=_similarity, draw2d=drawer) | ||
return finish_drawing(drawer) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions
129
visyn_core/tests/rdkit/valid_CC(=O)OC1=CC=CC=C1C(=O)O.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.