コード例 #1
0
    def render_chemcha(self, molstring, size, ignoreCoords):
        buf = StringIO.StringIO()
        fontSize = int(size / 33)
        if size < 200:
            fontSize = 1
        mol = Chem.MolFromMolBlock(str(molstring), sanitize=False)
        mol.UpdatePropertyCache(strict=False)
        if ignoreCoords:
            AllChem.Compute2DCoords(mol)

        if DrawingOptions:
            options = DrawingOptions()
            options.useFraction = 1.0
            options.dblBondOffset = .13
            options.atomLabelFontSize = fontSize
        else:
            options = {"useFraction": 1.0,
                       "dblBondOffset": .13,
                       'atomLabelFontSize': fontSize,}
        image = draw.MolToImage(mol, size=(size, size), fitImage=True, options=options)
        image = SineWarp().render(image)
        image.save(buf, "PNG")
        return buf.getvalue(), "image/png"
コード例 #2
0
ファイル: image.py プロジェクト: thesgc/chembl_webservices_2
    def render_chemcha(self, molstring, size, ignoreCoords):
        buf = StringIO.StringIO()
        fontSize = int(size / 33)
        if size < 200:
            fontSize = 1
        mol = Chem.MolFromMolBlock(str(molstring), sanitize=False)
        mol.UpdatePropertyCache(strict=False)
        if ignoreCoords:
            AllChem.Compute2DCoords(mol)

        if DrawingOptions:
            options = DrawingOptions()
            options.useFraction = 1.0
            options.dblBondOffset = .13
            options.atomLabelFontSize = fontSize
        else:
            options={"useFraction": 1.0,
                     "dblBondOffset": .13,
                     'atomLabelFontSize': fontSize,}
        image = Draw.MolToImage(mol, size=(size, size), fitImage=True, options=options)
        image = SineWarp().render(image)
        image.save(buf, "PNG")
        return buf.getvalue(), "image/png"
コード例 #3
0
except ImportError:
    import cairocffi
    cairocffi.install_as_pycairo()
    cffi = True
    import io
    import cairo
    if not hasattr(cairo, 'HAS_PDF_SURFACE'):
        cairo.HAS_PDF_SURFACE = False
    if not hasattr(cairo, 'HAS_SVG_SURFACE'):
        cairo.HAS_SVG_SURFACE = True

# ----------------------------------------------------------------------------------------------------------------------

options = DrawingOptions()
options.useFraction = 1.0
options.dblBondOffset = .13
options.bgColor = None

NUMBER_FILTERS = ['exact', 'range', 'gt', 'gte', 'lt', 'lte', 'in', 'isnull']
FLAG_FILTERS = ['exact', 'isnull']
CHAR_FILTERS = [
    'exact', 'iexact', 'contains', 'icontains', 'istartswith', 'startswith',
    'endswith', 'iendswith', 'search', 'regex', 'iregex', 'isnull', 'in'
]
DATE_FILTERS = ['exact', 'year', 'month', 'day', 'week_day', 'isnull']
STANDARD_RDKIT_COLORS = {
    16: (0.8, 0.8, 0),
    1: (0.55, 0.55, 0.55),
    35: (0.5, 0.3, 0.1),
    17: (0, 0.8, 0),
    0: (0.5, 0.5, 0.5),
コード例 #4
0
ファイル: image.py プロジェクト: thesgc/chembl_webservices_2
except ImportError:
    import cairocffi
    cairocffi.install_as_pycairo()
    cffi = True
    import io
    import cairo
    if not hasattr(cairo, 'HAS_PDF_SURFACE'):
        cairo.HAS_PDF_SURFACE = False
    if not hasattr(cairo, 'HAS_SVG_SURFACE'):
        cairo.HAS_SVG_SURFACE = True

SUPPORTED_ENGINES = ['rdkit', 'indigo']

options = DrawingOptions()
options.useFraction = 1.0
options.dblBondOffset = .13

fakeSerializer = ChEMBLApiSerializer('image')
fakeSerializer.formats = ['png', 'svg', 'json']

available_fields = [f.name for f in MoleculeDictionary._meta.fields]

#-----------------------------------------------------------------------------------------------------------------------

class ImageResource(ChemblModelResource):

#-----------------------------------------------------------------------------------------------------------------------

    class Meta(ChemblResourceMeta):
        resource_name = 'image'
        serializer = fakeSerializer