-
Notifications
You must be signed in to change notification settings - Fork 195
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
Support for partial bonds #639
Comments
Thanks for getting back to this idea so quickly, @dkoes. That's an interesting option, albeit non-conventional. At these low values (like 0.1) it does start to look a bit better. I had another thought too, what if the opacity (alpha value) of the bond color was changed to represent a dashed bond? For example, could we just "paint" the tube representing the bond with a series of low alpha values (even 0) to simulate the dashed effect? |
Yes, adjusting the opacity would be a nice way to go, but unfortunately also would require a lot of work as transparency, as currently implemented, is done per-object (different bonds of the same molecule can't have different opacities). Even though I agree it isn't the best possible visualization, I'm going to go with fractional bond orders scaling the bond radius. This is trivial to implement (I've already done it!) and gives the user some control over the style. Perhaps in the future bond order 8 can be implemented to mean dashed and/or transparent. |
@dkoes wow, thanks for the quick work on this! Looks good! I did notice one quirk here. Is there some issue with how the bonds are being parsed now? Maybe I'm missing something.
vs.
|
I think you must have edited those SDF files by hand because they have 5 bond records but the bond count is 4 in the header. Change the |
🤦🏻 thank you @dkoes! I was editing these by hand to add the additional transition bond and missed that. If I wanted to work on a feature to make the bonds actually dashed, how much effort do you think that would be and can you point to the best place in the code to tackle it? This is really useful, but I can see the advantage of having dashed bonds also. |
You'd need to refactor GLShape.addDashedCylinder so that the core functionality that adds a dashed cylinder to a geometry is in its own helper function that can be called by both addDashedCylinder and drawBondSticks (like is done with GLDraw.drawCylinder). |
@dkoes thanks for your suggestions! I did a little bit of research and had an alternate proposal, and wanted to see your thoughts:
this.addDashedCylinder = function(cylinderSpec) {
cylinderSpec.dashLength = cylinderSpec.dashLength || 0.25;
cylinderSpec.gapLength = cylinderSpec.gapLength || 0.25;
return this.addCylinder(cylinderSpec);
};
|
|
|
I was thinking we could make it:
and, leave the dashed as an optional parameter, therefore making it legacy compatible. If dashed was not specified, there would be no change to the functionality. My understanding of the for loop code in GLShape's addDashedCylinder is that basically we need to just call GLDraw drawCylinder multiple times in order to make a bond "dashed". So, there is some logic there to calculate the distance, new starting point, new ending point, etc. Why not move that logic directly into drawCylinder? If there isn't any dash specified, then the for loop would just run once. |
There are multiple configuration parameters for dashed - isn't just a boolean. |
@dkoes I took your idea, and have a functional prototype. I don't really understand why the molecules I'm interested in are using drawStickImposter and not drawCylinder, but nevertheless, I've just made some code adjustments to show a working version. There are some definite issues here, like the fact that (I think?) the bonds are being created in halves, but this could be fixed with some more clever calculations I think. It would also be cool to have the ability to do "1.5" and "2.5" style bonds, where one of them is dashed and the other is solid, and maybe some variant of this could be used for full implementation. |
Stick imposters are more efficient and higher quality ways of drawing cylinders. The dashed code should use those. |
Dash can be created by rendering a dash texture in the area projected by a cylinder that connects the two atom. The height of the projected area will be taken as the height of the texture and it will be repeated along one direction to create a impression of dash. |
I hadn't thought of that, but I doubt it would have the desired 3D effect with sticks. However, with lines I eventually need to reimplement them as 2D flat imposters (since line drawing has been deprecated in WebGL for a while) and this would work in that context (since the rendering is flat). Although probably makes more sense to incorporate the dashedness into the imposter code. |
It does use the stickImposter code, I think? Open to your feedback after review. |
This reverts commit 8225d95.
@dxdc Did you end up getting this to work? I am trying to visualize hydrogen bonding in DNA. |
Is your feature request related to a problem? Please describe.
Related to #368, would like to add a "dashed" or "partial" bond type. It could be added with bondOrder = 0.5. This would be useful to show transition states as well as hydrogen bonding, chelated metals, etc.
This is a natively supported feature in certain filetypes (e.g., MOL), but is not supported by 3Dmol. See: http://wiki.jmol.org/index.php/Support_for_bond_orders
For example, consider this MOL/SDF format, notice that the bond order is listed as "8".
Describe the solution you'd like
Adding some code here would be terrific, e.g.
3Dmol.js/src/GLModel.ts
Lines 400 to 486 in a36f54c
(Or, alternatively, we could just use some
addLineDashed
function. WhileaddLineDashed
is also used in the GLViewer code, I'm not sure how to port that over here).Describe alternatives you've considered(Optional)
Custom cylinders or lines can be added on a per-molecule basis, but this is not very practical particularly when trying to use animations.
The text was updated successfully, but these errors were encountered: