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

"Downloading" files within my machine #24

Open
Raiyan-Rizwan opened this issue May 6, 2024 · 13 comments
Open

"Downloading" files within my machine #24

Raiyan-Rizwan opened this issue May 6, 2024 · 13 comments

Comments

@Raiyan-Rizwan
Copy link

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
Copy link
Member

Hi @Raiyan-Rizwan,

Please see #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
Copy link
Author

Raiyan-Rizwan commented May 14, 2024

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 JonStargaryen reopened this May 14, 2024
@JonStargaryen
Copy link
Member

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
Copy link
Author

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

Thanks

@JonStargaryen
Copy link
Member

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

@midlik
Copy link
Collaborator

midlik commented May 22, 2024

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
Copy link
Collaborator

midlik commented May 22, 2024

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
Copy link
Author

It worked with S3. Thanks!

@Raiyan-Rizwan
Copy link
Author

Raiyan-Rizwan commented Jun 27, 2024

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
Copy link
Author

Raiyan-Rizwan commented Jul 2, 2024

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
Copy link
Collaborator

midlik commented Jul 8, 2024

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/

@Raiyan-Rizwan
Copy link
Author

Raiyan-Rizwan commented Jul 28, 2024

Thank you guys for the response to my last question. I was able to host the file on Amazon AWS and view the structure.

I do have one more issue where I initially specify in my code that the protein(cluster) is to be represented by type "ball_and_stick". However after I visualize it, it appears in type "cartoon" as I posted right below:

cluster 2

Then when I manually switch the type from "ball_and_stick" to "cartoon" and then back to "ball_and_stick", that's when it shows the structure in the proper "ball_and_stick" format as I posted below:

cluster 1

So why doesn't it show the structure in the proper "ball_and_stick" format directly from my code? I am pretty sure I am setting the representation parameter to type=ball_and_stick correctly. Can you please check if this is a bug on your end?

Thanks a lot.

@midlik
Copy link
Collaborator

midlik commented Aug 9, 2024

Hi,
looking at the pictures, there are both ball-and-stick.
The difference is that the first one uses MolViewSpec parameters (larger ball size) while the second one uses default Molstar parameters for ball-and-stick.
MolViewSpec parameters were selected to make typical structures look nice (see attached images), while your data are just a bunch of points.

ball-and-stick-MVS
ball-and-stick-default-molstar

In the current MVS implementation, we don't have any mechanism to specify the parameter values, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants