volkamerlab / opencadd

A Python library for structural cheminformatics
https://opencadd.readthedocs.io
MIT License
91 stars 18 forks source link

Pocket visualization #54

Closed dominiquesydow closed 3 years ago

dominiquesydow commented 3 years ago

Description

So far, in order to work with a structure in the pocket module, a local copy of its structure file was needed to satisfy the Pocket class method visualize (nglview visualization of structure/pocket).

This was mainly the case because I could not make it work to show a structure from text in the mol2 format - but I figured it out now. Let's look at our options:

import nglview

# Show structure from file
view = nglview.show_file(filepath)

# Show structure from text (pdb format only!)
view = nglview.show_text(pdb_text)

# Show structure from text (any file format allowed by `nglview` - I tested only for pdb and mol2)
structure = nglview.adaptor.TextStructure(text, ext="mol2")
view = nglview.widget.NGLWidget(structure)

In this PR, the pocket module is updated in a way that Pocket class can be initialized from a file but also from text. This is helpful for the KlifsPocket subclass, where we fetch data via KLIFS IDs. Before, the file was downloaded and linked to the object via the _filepath attribute; now, we simply fetch the file text and format (_text and _extension attributes).

Todos

Questions

None

Status

dominiquesydow commented 3 years ago

@jaimergp - this is a minor update in the pocket module (only in the backend). When you have time, could you please take a look if you approve of these changes?

jaimergp commented 3 years ago

Looks good! The PR description itself is a piece of art and should be framed in the lab :D

Btw, I didn't know about nglview.adaptor.TextStructure! I'll revisit if there're other places where we can apply this nice trick.

The only comment I need to make with this approach is memory usage. I don't think it's going to be a problem in 99% of the cases so we'll leave it like that. But just to make sure we remember this if we hit 1% of the cases, I'll add a note to the class that will store the .text attribute. In massive benchmarks, storing the text will add a liiiittle overhead (nothing compared to other problems). Now that I'm writing this I don't think it's even worth writing it down, so yep, whatever, ignore this :)

Merge!

dominiquesydow commented 3 years ago

Thank you :)