Hi,

Getting the similarity maps for multiple structures should be straightforward, 
just add the function call in your loop.
Concerning the export of the generated images to a web service, I did the 
following:
(assuming the figure returned by the SimilarityMaps.GetSimilarityMapForModel() 
function is called "fig")
import io
from matplotlib import pyplot as plt
buf = io.BytesIO()
DPI = fig.get_dpi()
plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0, dpi=DPI/2)
plt.close(fig)
img = buf.getvalue()
buf.close()

I remember having to play around with the picture size, the coordScale and dpi 
in order to get an image of a proper size (as requested by the user, in pixels) 
and adequate font size:
fig = Draw.MolToMPL(mol, coordScale=1.5, size=(int(width/1.3),int(height/1.3)))
I can't exactly remember the details, but worth looking at these parameters if 
the image you get is not ok.

I use Flask for the web server;
I send the picture trough the server this way:
flask.send_file(io.BytesIO(img), mimetype='image/png')

Best,

Grégori

On Wednesday, December 13, 2017 06:39 CET, Greg Landrum 
<greg.land...@gmail.com> wrote:
 I know that Michal has done some work with this as part of the beta for the 
new ChEMBL interface.@Michal: do you have a bit of time to explain what you did 
in order to get images that you could serve via the web? On Tue, Dec 12, 2017 
at 1:50 PM, Bruno Neves <bruno.lab...@gmail.com> wrote:Dear colleagues I want 
to develop mechanistically interpretable machine learning models (i.e., using 
similarity maps) and implement them in web services. I've already managed to 
generate a map from a smiles. However, I can not generate maps for multiple 
molecules in a data set (CSV ou SDF). I’m also having some difficulty trying to 
save the new similarity map images. The scripts available in RDKit the tutorial 
do not provide detailed information to solve this problem.  Do you have any 
idea how I can solve this?  # Use the random forest to predict a new molecule 
(SMILES)>>> m = 
Chem.MolFromSmiles('FC(F)(F)C1=CC=C(OC(CCNC2=CC=CC=C2)C2=CC=CC=C2)C=C1')>>> fp 
= np.zeros((1,))>>> 
DataStructs.ConvertToNumpyArray(AllChem.GetMorganFingerprintAsBitVect(m, 
radius, nBits, useFeatures), fp)>>> print(rf.predict((fp,)))>>> 
print(rf.predict_proba((fp,))) # Get predicted probability map>>> def 
getProba(fp, predictionFunction):>>> return predictionFunction((fp,))[0][1]>>> 
fig, maxweight = SimilarityMaps.GetSimilarityMapForModel(m, 
SimilarityMaps.GetMorganFingerprint, lambda x: getProba(x, rf.predict_proba)) # 
Open CSV file with multiple molecules>>> m = 
pd.read_csv('C:\\Users\\bruno\\Desktop\\maps\\data\\logBB_S.csv', 
delimiter=',')>>> mols = []>>> y = []>>> for mol in Chem.SDMolSupplier(fname):  
  >>> if mol is not None:        >>> mols.append(mol)>>> fps = 
[AllChem.GetMorganFingerprintAsBitVect(m, radius, nBits,useFeatures) for m in 
mols]>>> def rdkit_np_convert(fp):   >>> output = []    >>> for f in fp:        
>>> arr = np.zeros((1,))        >>> DataStructs.ConvertToNumpyArray(f, arr)     
   >>> output.append(arr)    >>> return np.asarray(output)>>> x = 
rdkit_np_convert(fps)>>> x.shape>>> print(fp)>>> print(rf.predict(x))>>> 
print(rf.predict_proba((x))) # Get predicted probability maps for multiple 
structures??????????????????????????????  Best regards, Prof. Dr. Bruno Junior 
NevesLaboratório de QuimioinformáticaCentro Universitário de Anápolis - 
UniEVANGÉLICA             
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
 
 
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to