nglviewer / ngl

WebGL protein viewer
http://nglviewer.org/ngl/
MIT License
657 stars 168 forks source link

Export .pdb file #1030

Closed britesma closed 3 months ago

britesma commented 3 months ago

Use case: I loaded my .pdb file and after a selection on it I need to export a .pdb with that selection.

Is there an easy way that I am missing? Thank you!

ppillot commented 3 months ago

The PDBWriter class can take as a first argument a StructureView object. If you change the selection at the level of the component, the component.structureView property contains the subset corresponding to the selection.

const writer = new PdbWriter(component.structureView)
writer.download() // or writer.getData() if you prefer to get the content as a string to manipulate it
britesma commented 3 months ago

Ohhh nice, thank you very much!

But how can I maintain the atom serials ? I mean the new writer rewrites the atom serial from 1, I would like to keep them as the original .pdb. Do I need to manipulate the string as you said?

I got it, I can just pass the flag renumberSerial.