nglviewer / ngl

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

Support for molecular structure modification #296

Open hshany opened 7 years ago

hshany commented 7 years ago

Hi! I'm trying to develop a WebApp which carries out some preprocessing of a protein structure downloaded from PDB to prepare it for MD runs and would like to take advantage of ngl's visualization capacity. My app needs to modify loaded structures by for example adding or removing atoms or mutating residues. Does ngl support modification of loaded molecular structures? I couldn't find related API in the documentation.

Any suggestion would be appreciated .

ppillot commented 7 years ago

NGL is a viewing "only" library and doesn't have this modeling capabilities. I know that JSmol does have such capabilities and can perform some energy minimization to a certain extent.

hainm commented 7 years ago

@hshany I suggest to look for more dedicated tools to do that.

hshany commented 7 years ago

Thanks Paul. I'm quite new to the front end and have been studying your libmol code as an example, which is very helpful. The plan here is to implement the modeling logic either in this app or as a service that this app consumes, so my code will decide which atom to add and where. What I need is a viewer that has an API to update the structure, but you're right, that's already modeling. Of course I can modify the structure and interface with ngl using say pdb files but that doesn't sound right does it?

I'll take a closer look at JSmol. I looked at the demo of ngl and JSmol before and it seemed that ngl loads a lot faster and the rendering is nicer.

ppillot commented 7 years ago

@hshany, glad that I could have been helpful and congrats for making some sense of my code! If I understand you correctly, your code will create the new coordinates and you need to update the structure in order to reflect those changes? Then JSmol is not what you need (it has a mutate capability and makes these calculations) and the best option seems to me to load back the entire updated structure.

arose commented 7 years ago

Hi @hshany I am glad you found NGL. As said before, at present NGL does not support changing the topology of loaded structures. Changing the positions of atoms is, however, supported. If you are interested in helping with adding editing functionality to NGL, please let me know. Flipping through rotamers (only requires position changes) might be a good first step.

Also, for your specific use case, there might be ways around altering the structure. If you don't change the backbone, representations like cartoon will be unaffected. You could show mutated sidechains by adding a separate structure and hide that specific sidechain in a "ball+stick" representation of the original structure. Only when you want to download the structure you would need to combine the original structure and all the mutated sidechains.

hshany commented 7 years ago

@ppillot, Loading back the updated structure indeed seems the most straightforward solution for me, especially considering that I may need to call other libraries for certain modeling functionality like building a missing loop, which I'll need to interface using a file. But now that I started looking at NGL's code, I feel that designing another layer of data structure for structure representation on top of NGL is kind of duplicating and potentially confusing.

@arose, due to the above mentioned reason I'm indeed interested in adding some editing functionality to NGL and reuse the code as much as I can, but I'm thinking of it along the line of more general operations like deleting atoms, adding atoms, changing coordinates of existing atoms, than specific operations like flipping through rotamers. I'm still looking at your code but do you think these will fit in your data structure without too much twisting? Or is there a reason that implementing such general editing operations are not logical in the current framework?

arose commented 7 years ago

@hshany It would be great to have general editing functionality in NGL and there is nothing illogical about it. However, the data structures to store molecules with their models, chains, groups and atoms is not directly changeable in the sense that you can add atoms or groups to it. Adding/removing groups or atoms requires moving other atoms groups around and requires to re-calculate bonding data and spatial-search acceleration data structures... Changing coordinates is generally ok.

luxaritas commented 2 years ago

We're currently working on integrating NGL into Eterna (https://github.com/eternagame/eternajs) for visualizing the molecules we're working on in 3D on top of our existing 2D interface. We conventionally do sequence design, and while we don't currently have a tractable method to integrate actual 3D structure prediction, we would like to still be able to support visualizing isolated base changes. That is, without changing the backbone or the orientation of a given base, simply swap out, say, a guanine for a uracil. Currently we're just keeping track of bases to be overridden and changing the color in our custom representation. However, it would be great if NGL supported a way to "actually" swap out the base.

This issue is a few years old - this doesn't happen to be something doable today, does it?

fredludlow commented 2 years ago

I think the basic constraints are still there - changing coordinates is straightforward, but changing the structure requires updating other bits of data. I don't really have an idea how hard this is.

If you look at the implementation of concatStructures https://github.com/nglviewer/ngl/blob/81f363347294e4c620b329aedab54de5d844f486/src/structure/structure-utils.ts#L988 you could have a go at similarly appending new atoms then using selection expressions to hide the old residue and show the new one.

What we've done (which isn't particularly elegant, but works in practice) is to replace the molecule each time the structure changes beyond just coordinate changes - this is practical for small molecule ligands (which parse and render pretty much instantly) but may not be great for larger structures.