everburstSun / dash-molstar

The molstar plugin for plotly dash framework
GNU Lesser General Public License v2.1
13 stars 3 forks source link

Downloading pdb and selecting a range of residues to display #10

Open Fede112 opened 7 months ago

Fede112 commented 7 months ago

Hi, First of all, thanks a lot for the tool, it is really useful! I wanted to ask if there is a way to download a protein from AFDB but only display a range of residues, all within a single callback. I am trying the following but it is not working. Initially I see the selection but it gets erased automatically:

@app.callback(Output('viewer', 'data', allow_duplicate=True),
    Output('viewer', 'selection'),
    Input('load_protein', 'n_clicks'),
    prevent_initial_call=True,
    )
def display_output(yes):
    data = molstar_helper.parse_url('https://files.rcsb.org/download/3U7Y.cif')
    target=molstar_helper.get_targets(chain="A", residue=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
    selection=molstar_helper.get_selection(target, select=False)
    return data, selection

Two additional quesitons: 1) Is there I way to submit a range of residues: [1:15]? 2) Do you have any example on how to do a superposition between two proteins?

Thanks in advance!

Fede112 commented 7 months ago

I tried another strategy, which involved adding a component to data. Additionally, by using State('viewer', 'data'), I managed to append more than one protein.

target=molstar_helper.get_targets(chain="A", residue=sResidues)
component=molstar_helper.create_component(f"{protein_name}/{sStart}-{sEnd}", target, 'cartoon')
data = molstar_helper.parse_url(f'{pdb_url}', component=component)
data_viewer.append(data)

However, with this approach, I encountered a strange behavior where the components were not applied to each protein, but rather to the last one. As a result, both proteins were displayed as the same component, Polymer, with the two components created only for the last element of data_viewer.

everburstSun commented 7 months ago

Thank you for liking this tool. The current version does not support showing part of a structure, but it has been planned. When loading a structure, molstar will add default representations for the whole structure. This can be controlled in the 1.2.0 release. By then you will need to create a component with the partition you would like to show.

Your additional quesitons:

Is there I way to submit a range of residues: [1:15]?

To submit a range of residues, you can use an iterator like list(range(1,15)).

Do you have any example on how to do a superposition between two proteins?

I haven't investigated how to do this with code. But maybe you can toggle the control panel of molstar and do superposition manually?

everburstSun commented 7 months ago

I tried another strategy, which involved adding a component to data. Additionally, by using State('viewer', 'data'), I managed to append more than one protein.

target=molstar_helper.get_targets(chain="A", residue=sResidues)
component=molstar_helper.create_component(f"{protein_name}/{sStart}-{sEnd}", target, 'cartoon')
data = molstar_helper.parse_url(f'{pdb_url}', component=component)
data_viewer.append(data)

However, with this approach, I encountered a strange behavior where the components were not applied to each protein, but rather to the last one. As a result, both proteins were displayed as the same component, Polymer, with the two components created only for the last element of data_viewer.

Thank you for reporting this issue. I have fixed it in the 1.1.2-dev branch.