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

drawing a Box and Volume data #2

Open
SimonEnsemble opened this issue Oct 7, 2018 · 15 comments
Open

drawing a Box and Volume data #2

SimonEnsemble opened this issue Oct 7, 2018 · 15 comments

Comments

@SimonEnsemble
Copy link

Thank you! Bio3DView.jl can drastically improve our workflow!

Is there any way you can extend the API to include:

  • loading in volume data, through .cube files (see here) then drawing iso-surfaces (see here)?
  • drawing the outline of a box so we can visualize the unit cell of a crystal? See here.
  • draw a coordinate axes so we can know which way is the x, y, z direction?
  • allow to save a png or pdf

We routinely need to make figures like this:
b24_raw
e.g. see here.

If you can do this, our code to write and visualize potential energy grids of adsorbed gas molecules in porous crystals, PorousMaterials.jl (see here) would be complete. We'd be happy to have you join as a well-deserved coauthor on our software publication if you could get this working. We can provide .cube volume data for an example to work with.

@jgreener64
Copy link
Owner

In brief, yes I would be interested in this. I will have a look at how much work it will be and get back to you.

@jgreener64
Copy link
Owner

I have implemented the loading of volume data and the box outline. Try

isosurface = IsoSurface("benzene.cube", 0.01)
box = Box([0.0, 0.0, 0.0], [6.0, 6.0, 6.0])
viewfile("benzene.sdf", "sdf", isosurface=isosurface, box=box)

I'll have a look at the other stuff too.

@SimonEnsemble
Copy link
Author

cc3bio3dview

That is beautiful! Thanks!

  • What is the second argument of the isosurface, 0.01?
  • What is causing the scale to be off (the surface should wrap around the molecule)?
  • The Box is contained in the .cube file. Here is an example .cube file that is commonly used in the chemistry community. The matrix in lines 4-6 contains the unit cell lattice vectors that could be used automatically for constructing the Box?
  • Can this handle slanted boxes, i.e. general Bravais lattices? This is necessary for porous crystals, whose unit cells are not rectangular. Usually you can describe the box by the three unit cell lattice vectors (that don't generally point in the same directions as the Cartesian axes).
  • Should I make a pull request with an example .cube and corresponding .xyz file that corresponds to a porous crystal that you can play with? This could be a nice example for users too.
  • Maybe we should update install directions for Julia 1.0 as well as have the user pull master for this functionality? Once you are ready to register as an official Julia package, I can have my student help you out with a PR if you want, since he registered our package.
add https://github.com/jgreener64/Bio3DView.jl#master

@jgreener64
Copy link
Owner

Thanks.

What is the second argument of the isosurface, 0.01?

The isoval to view the surface at. See ?IsoSurface for other options.

What is causing the scale to be off (the surface should wrap around the molecule)?

Not sure, might be an issue in one of the files? Perhaps one of the unit cell definitions, or the way 3Dmol deals with unit cells? Or it might require changing the isoval.

The matrix in lines 4-6 contains the unit cell lattice vectors that could be used automatically for constructing the Box?

Can this handle slanted boxes, i.e. general Bravais lattices?

This would be possible, probably using the draw line functionality to draw each edge of the box.

Should I make a pull request with an example .cube and corresponding .xyz file that corresponds to a porous crystal that you can play with?

Sure, if you put them in the examples directory I can add them to the tutorial. I'll have a look at them and try and make the visualisation look nice.

Maybe we should update install directions for Julia 1.0 as well as have the user pull master for this functionality?

The instructions should work for Julia 1.0 as is. Currently there is no tagged version so all access is via master. When the package is released everything should be in the released version, and I can change clone to add. I can do the release using Attobot.

@SimonEnsemble
Copy link
Author

I get the following working when I use Pkg.clone(), so that's why I was suggesting to use add.

┌ Warning: Pkg.clone is only kept for legacy CI script reasons, please use `add`

Another idea for usability: viewfile("blah.xyz", "xyz") might be redundant since .xyz is already in the filename? We could do file_extension = split(filename, ".")[end] to infer the file extension?

Pull request coming soon!

@jgreener64
Copy link
Owner

Ah okay I'll change to add then.

Yes the automatic guessing of file type is a good idea, that was on my list too. I'll implement it.

@jgreener64
Copy link
Owner

Above two things added.

I have also added drawing of the unit cell from a vtk file. It's not in the tutorial yet, but try:

viewfile("SBMOF-1.xyz", vtkcell="SBMOF-1.vtk")

I have played with the isosurface scaling issue a bit. It seems the voxel definitions at the top of the cube file are in different units to 3Dmol by a factor of 2. So if I replace the 3 cases of 1.359579 in IRMOF-1.cube with 2.719158 then I think it renders okay.

@SimonEnsemble
Copy link
Author

Thanks, the vtkcell feature looks great!

I found in the source code that 3Dmol.js uses Bohr or Angstrom (the latter is what I assumed) depending on the sign of the integers denoting the number of grid points. 1 Angstrom is approx. 1.88 Bohr, so your finding makes sense. I'll make a PR to update my .cube files.

I also saw some maybe relevant issues for saving to png.

Is it possible for me to host a visualization like this on my Github pages website?

Thanks!

@jgreener64
Copy link
Owner

Ah, that makes sense.

I'll have a look at the saving to png stuff.

Is it possible for me to host a visualization like this on my Github pages website?

If you are asking for permission to do it then yes that's fine. If you are asking for how to do it, one way is to get the html to create a standalone viewer using the new html tag I just added, e.g.:

html = viewpdb("1CRN.pdb", html=true)

Then add this to your pages' html directly.

By the way I switched to using Requires.jl to reduce the need for Blink and BioStructures (quite heavy dependencies) for those who just want to use notebooks. Let me know if you run into any problems.

@SimonEnsemble
Copy link
Author

The new version works correctly on my machine! Removing the dependency will make it easier to integrate into our package PorousMaterials.jl.

Thanks a lot, the html=true flag is a great feature!

One odd phenomenon is that, when I visualize an isosurface of IRMOF-1 in PorousMaterialExample.ipynb in Cell 3, then run cell the isosurface visualization of SBMOF-1 in Cell 4, the isosurface in Cell 3 disappears, but the structure visualization in Cell 3 persists. It must be that only one isosurface can be maintained in a notebook at any one given time.

We have another paper we are prioritizing at the moment, but we will invite you to our Overleaf when we start writing our paper on PorousMaterials.jl. (We also need to improve our documentation.) The ability to save as a publication-quality png or pdf would make it complete.

@SimonEnsemble
Copy link
Author

Very wicked. Is it possible to set a view vector, such as view=[1, 0, 0] to set the view normal to a custom vector? e.g. on my website the slab is oriented in an odd view. Also I wonder if it is possible to draw a triad (the x, y, z axis directions) since this is important to keep track of when manipulating crystals.

@jgreener64
Copy link
Owner

The isosurface disappearing issue is annoying, I'll see if I can fix it. And I'll have a look at the other features: saving, view angle and axes.

@jgreener64
Copy link
Owner

View angle and axes display are kind of implemented, see the last example in the tutorial notebook, though need a bit more documentation. I also combined the tutorial notebooks into one.

It seems you can save from Jupyter by right-clicking or shift-right-clicking and selecting save image, this could be a good way forward.

@SimonEnsemble
Copy link
Author

@jgreener64 Great, thanks!

I'm getting an error for the last example in the tutorial notebook:

UndefVarError: ViewAngle not defined

Stacktrace:
 [1] top-level scope at In[14]:3

The option to save the image doesn't appear in my Jupyter Lab.

I often need to make images in high-throughput, so I think saving via a command like in matplotlib would be best, ideally publication quality (instead of whatever resolution Jupyter gives you). Plus then you can make videos systematically, e.g. by changing the view with your new feature and generating a series of PNGs.

Thanks again!

@jgreener64
Copy link
Owner

Ah yes I renamed it to CameraAngle to avoid confusion but forgot to update the tutorial, have done so now.

Okay cool I'll have a look at the image saving.

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

2 participants