gabrielelanaro / chemview

The new generation molecular viewer for IPython notebook
GNU Lesser General Public License v2.1
81 stars 17 forks source link

add_representation for points, not rotated right ? #36

Closed WeiLiPenguin closed 7 years ago

WeiLiPenguin commented 7 years ago

Hi,

I try the points and spheres: spheres rotation has not problem, but points seems does not work right (also the mouse zoom) !

here is my test code, I put a box with lines for reference. you may need ASE to run it.

from ase import Atoms

import numpy as np
import chemview
import time

from chemview.utils import get_atom_color
from chemview import RepresentationViewer
from IPython.display import display
chemview.enable_notebook()

def viewer(atom):

    cell = atom.cell.astype('float32')

    ps = atom.positions.astype('float32')

    original=np.zeros(3,dtype=float)

    lines=[[original,cell[0]],
           [cell[1],cell[1]+cell[0]],
           [cell[2],cell[2]+cell[0]],
           [cell[1]+cell[2],cell[0]+cell[1]+cell[2]],
           [original,cell[1]],
           [cell[0],cell[0]+cell[1]],
           [cell[2],cell[2]+cell[1]],
           [cell[0]+cell[2],cell[0]+cell[1]+cell[2]],
           [original,cell[2]],
           [cell[0],cell[0]+cell[2]],
           [cell[1],cell[1]+cell[2]],
           [cell[0]+cell[1],cell[0]+cell[1]+cell[2]] ]

    rv=RepresentationViewer(600, 600)

    color= np.array([0xFF0000, 0x00FF00, 0x0000FF])[[0, 1, 2]].tolist()

    for line in lines:
        rv.add_representation('lines', {'startCoords': line[0],
                                               'endCoords': line[1],
                                               'startColors': color,
                                               'endColors': color},
                         )
    colors = [get_atom_color(t.upper()) for t in atom.get_chemical_symbols()]

    rv.add_representation('spheres', {'coordinates': ps, 
                                                   'colors': colors , 
                                                   'radii': [0.1]*len(ps), 
                                                   'resolution': 32})

#     rv.add_representation('points', {'coordinates': ps, 
#                                                'colors': colors , 
#                                                'sizes': [50]*len(ps),
#                                                'opacity': 1.0})
    rv.autozoom(ps)
    return rv
atom = Atoms(['Fe','Ni','Ni','Ni'],[(0,0,0),
                   (0.5,0,0.5),
                   (0,0.5,0.5),
                   (0.5,0.5,0)],pbc=[True,True,True])
viewer(atom*4)

Please un-comment the part for points and try to repeat my problem.

This could be use as a extension for crystal?

BTW: does chemview works with the new jupyter notebook, I also try your branch new-widget, but not work for me ?

Best Regards!

gabrielelanaro commented 7 years ago

Hi!

I merged new-widget branch, I was holding off a little bit to wait for the community to adopt the new jupyter.

I tested and it should work, however you should modify the point 'sizes' to be something smaller, like 2, also in the new version you can drop enable_notebook()

I get the following screenshot.

screenshot from 2016-09-26 10 26 42

The installation of the widget for the new jupyter require some other commands, and that could be why this is not working (I'll update the docs accordingly):

If you have chemview git:

cd chemview
pip install -e .
conda install widgetsnbextension
jupyter nbextension enable widgetsnbextension --user --py
jupyter nbextension install --py --symlink chemview
jupyter nbextension enable --py  chemview

If the new master is not working for you that could be a bug, if you can open the javascript console of your browser and tell me what it says I can help

WeiLiPenguin commented 7 years ago

Hi! the new master works!

But the points still not work as yours, for me: all points looks shift from (0,0,0) with the size of points and they are looks smaller than your screenshot. This is for size=10 image

It makes me crazy...

Best Regards!

gabrielelanaro commented 7 years ago

I agree this is pretty weird, do you get any error in the javascript console? What browser are you using? It could also be a video-card issue, do you know which video card you have? (nvidia/ati/intel)

WeiLiPenguin commented 7 years ago

firefox 49.0 chromium 52.0.2743.116 vido card within intel i5 650

I will try another pc, could be the driver problem.

Best!

WeiLiPenguin commented 7 years ago

Hi, It could be the driver problem. change to my laptop, and it has no problem.

thank you for the great work!

Do you have plan to add "Post Processing Effects" like your chemlab for chemview ? they are looks nice!

Best!

gabrielelanaro commented 7 years ago

@WeiLiPenguin Sorry for not answering earlier I forgot about the issue.

I'm leaning towards skipping the post processing effects, because they require advanced webgl techniques, and I found that webgl is still fairly brittle and vendor-dependent. You get bugs just like the one you had (and we're rendering just a bunch of points) and there's really not much that can be done to fix it.