Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding mol name to mapping figure? #233

Closed
RiesBen opened this issue Sep 13, 2023 · 3 comments · Fixed by #241 · May be fixed by #237
Closed

adding mol name to mapping figure? #233

RiesBen opened this issue Sep 13, 2023 · 3 comments · Fixed by #241 · May be fixed by #237
Labels
enhancement New feature or request

Comments

@RiesBen
Copy link
Contributor

RiesBen commented Sep 13, 2023

https://github.com/OpenFreeEnergy/gufe/blob/441b70a6f716038dfa6c139c89c2ce2ebff6db14/gufe/visualization/mapping_visualization.py#L167C1-L173C6

@richardjgowers
How about this addition, if we can assume ofe-name is always present?:

    d2d.DrawMolecules(
        copies,
        highlightAtoms=atoms_list,
        highlightBonds=bonds_list,
        highlightAtomColors=atom_colors,
        highlightBondColors=bond_colors,
        legends=[copies[i].GetProp("ofe-name"), copies[j].GetProp("ofe-name")]
    )

image

@RiesBen RiesBen assigned RiesBen and unassigned RiesBen Sep 13, 2023
@RiesBen
Copy link
Contributor Author

RiesBen commented Sep 13, 2023

additional this bit could be useful to plot all mappings of a network for example:
(code shamelessly used from here: https://greglandrum.github.io/rdkit-blog/posts/2023-05-26-drawing-options-explained.html)

from PIL import Image, ImageOps
from io import BytesIO

def show_images(imgs,buffer=4, ncols=3):
    height = 0
    width = 0
    nrows= (len(imgs)+1)//ncols if(len(imgs)%3>0) else len(imgs)//ncols
    
    for img in imgs:
        height = max(height, img.height)
        width = max(width, img.width)
        
    #simplistic columnizing
    print(ncols, nrows)

    height = height* nrows
    width = width * ncols
    
    width += buffer*ncols
    height += buffer*nrows
    print(width,height)
    
    res = Image.new("RGBA",(width,height))
    
    x = 0
    y = 0
    for i, img in enumerate(imgs):
        img = ImageOps.expand(img, border=3, fill="grey")
        res.paste(img,(x,y))
        x += img.width + buffer
        
        if(i%ncols == 0 and i!=0):
            y+= img.height + buffer
            x=0
            
    return res

views = []
for m in mappings:
    view = draw_mapping(m._compA_to_compB, m.componentA.to_rdkit(),
                                          m.componentB.to_rdkit(),)
    bio = BytesIO(view)
    view = Image.open(bio)
    views.append(view)
res = show_images(views)
res.save(out_name)

res

image

@richardjgowers
Copy link
Contributor

@RiesBen yes please!

@RiesBen RiesBen added the enhancement New feature or request label Sep 15, 2023
@RiesBen
Copy link
Contributor Author

RiesBen commented Sep 15, 2023

@richardjgowers Started a branch with a first draft :)

@RiesBen RiesBen linked a pull request Sep 15, 2023 that will close this issue
@RiesBen RiesBen linked a pull request Sep 27, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants