molstar / mol-view-spec

https://molstar.org/mol-view-spec/
MIT License
8 stars 1 forks source link

"Downloading" files within my machine #24

Open Raiyan-Rizwan opened 2 months ago

Raiyan-Rizwan commented 2 months ago

Hi, I noticed that the API allows download via url, but what would I do if I am to use a pdb file within my machine's file system?

JonStargaryen commented 2 months ago

Hi @Raiyan-Rizwan,

Please see https://github.com/molstar/mol-view-spec/issues/18 for details. Local files aren't supported because the resulting MVS file wouldn't work on other machines. You can always upload your data to S3, Google Drive, Dropbox, ...

Best, Sebastian

Raiyan-Rizwan commented 2 months ago

Good Afternoon, So I am using Google Drive as a web platform to host the pdb files I am going to visualize on Molstar. I get the file from google drive and produce the download link using the following code:

def get_drive_download_link(drive_url): """ Converts a Google Drive sharing URL into a direct download link. """ file_id = drive_url.split('/')[-2] return f'https://drive.google.com/uc?export=download&id={file_id}'

Then I run the download link through the builder(made using molviewspec built in functions). However, I get the following error. Do you have any suggestions for fixing this error?

molview error

Thanks

JonStargaryen commented 2 months ago

Indeed, thanks for giving this a try. We'll look into this, though I'm not sure if this is fixable in Mol*/MolViewSpec or if this is a more general issue with how Google Drive decides to share files.

Raiyan-Rizwan commented 1 month ago

Good Afternoon, Were you guys able to get to what is causing the issue? Please let me know.

Thanks

JonStargaryen commented 1 month ago

@midlik Do you think this can be addressed in the Mol* code or is this a limitation of Google Drive?

midlik commented 1 month ago

Hi, this looks as a CORS problem. So there is no way of addressing this in Mol*. The files must be served with CORS enabled (and unfortunately I don't think GoogleDrive allows this, S3 might allow you to enable it).

midlik commented 1 month ago

If you have no possibility of hosting those structure files with CORS enabled, you can still use relative URL and pack you MVSJ + structure files into a MVSX file (https://molstar.org/mol-view-spec-docs/#mvsx). Something like this:

builder.download(url='./my-structure.cif')
...
builder.save_state(destination='example.mvsj')

import zipfile
with zipfile.ZipFile('example.mvsx', mode='w') as z:
    z.write('example.mvsj', arcname='index.mvsj')
    z.write('my-structure.cif', arcname='my-structure.cif')
Raiyan-Rizwan commented 1 month ago

It worked with S3. Thanks!

Raiyan-Rizwan commented 2 weeks ago

The following is an example from the code you guys provided within your Python Collab Notebook:

builder = mvs.create_builder() structure1 = ( builder.download(url="https://files.wwpdb.org/download/1oj6.cif") .parse(format="mmcif") .assembly_structure() )

1st structure colored in orange

structure1.component(selector='polymer').representation(type='cartoon').color(color='#e19039') structure1.component(selector='ligand').representation(type='ball_and_stick').color(color='#eec190')

structure2 = ( builder.download(url="https://files.wwpdb.org/download/5mjd.cif") .parse(format="mmcif") .assembly_structure()

move these coordinates to align both structures

.transform(
    rotation=[-0.39652203922082313, 0.918022802798312, 0.002099036562725462, 0.9068461182538327, 0.39133670281585825, 0.1564790811487865, 0.14282993460796656, 0.06395090751149791, -0.9876790426086504],
    translation=[-17.636085896690037, 7.970761314734439, 88.54613248028247]
)

)

2nd structure colored in blue

structure2.component(selector='polymer').representation(type='cartoon').color(color='#4b7fcc') structure2.component(selector='ligand').representation(type='ball_and_stick').color(color='#9cb8e3')

print(builder.get_state())

I have used a similar structure in my code to represent two different protein structures together. However, When I directly convert the JSON form of the state into a URL and use it on the web, I get a "URI too long" error. However, you guys were successfully able to visualize it. May I ask what technique you guys used for the URL conversion? It would be very helpful for me.

Thanks

Raiyan-Rizwan commented 2 weeks ago

Hello, Can you guys please let me know what technique you used to convert the output of builder..get_state(), which is in JSON format to URL in this specific case? Would be very helpful.

Thanks

midlik commented 1 week ago

Hi Raiyan, I understand that your question is about using the mvs-data URL parameter. Unfortunately, URL length is limited in most browsers and only very simple MVS views fit into this limit. If you have a more complex view, you'll have to use a different method of sharing, e.g. host the file somewhere and use the mvs-url parameter.

Find some documentation here: http://molstar.org/mol-view-spec-docs/mvs-molstar-extension/