Skip to content

MDView module

MDView

Bases: widgets.DOMWidget

Source code in evince/mdview.py
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@widgets.register
class MDView(widgets.DOMWidget):
    # Name of the widget view class in front-end
    _view_name = Unicode('MDView').tag(sync=True)

    # Name of the widget model class in front-end
    _model_name = Unicode('MDModel').tag(sync=True)

    # Name of the front-end module containing widget view
    _view_module = Unicode('evince').tag(sync=True)

    # Name of the front-end module containing widget model
    _model_module = Unicode('evince').tag(sync=True)


    # Version of the front-end module containing widget view
    _view_module_version = Unicode(NPM_PACKAGE_RANGE).tag(sync=True)
    # Version of the front-end module containing widget model
    _model_module_version = Unicode(NPM_PACKAGE_RANGE).tag(sync=True)


    #pos = tl.List([1,2,3]).tag(sync=True)
    pos = tl.Bytes().tag(sync=True)

    init = tl.Bool(False).tag(sync=True)
    masses = tl.List([]).tag(sync=True)
    radius = tl.Bytes().tag(sync=True)
    #particle_data = tl.Bytes().tag(sync=True)
    #colors = tl.List([]).tag(sync=True)
    max_instances = tl.Int().tag(sync=True)
    count = tl.Int().tag(sync=True)
    #pos = Array(np.asarray([])).tag(sync=True, **array_binary_serialization)

    colors = tl.Bytes().tag(sync=True)
    box = tl.List([]).tag(sync=True)

    fragment_shader = tl.Unicode('').tag(sync=True)

    #bonds = 

    #colorscheme
    additive = tl.Bool(False).tag(sync=True)

    bg_color = tl.List([]).tag(sync=True)

    def __init__(self, b, additive = False, bg_color = [1.0, 1.0, 1.0], radius = None):

        super().__init__() # execute init of parent class, append:

        # set particle data
        # [position (3 elements) , color (3 elements), radius (1 element)]
        #self.particle_data_array = np.zeros((b.n_bubbles,  7), dtype = np.float32)
        #self.particle_data_array[:,:3] = b.pos.T

        nc = 20
        #self.particle_data_array[:,3:6] = interp1d(np.linspace(0,1,nc), np.random.uniform(0,1,(3, nc)) )(b.masses/b.masses.max()).T
        self.colors = np.array((interp1d(np.linspace(0,1,nc), np.random.uniform(0,1,(3, nc)) )(b.masses/b.masses.max()).T), dtype = np.float32).tobytes()

        if radius is None:
            #self.particle_data_array[:,6] = np.array(get_vwv_radius_from_atomic_number(b.masses), dtype = np.float32) 
            self.radius = np.array(get_vwv_radius_from_atomic_number(b.masses), dtype = np.float32).tobytes()
        else:
            #self.particle_data_array[:,6] = radius
            self.radius = radius

        #self.particle_data = self.particle_data_array.tobytes()





        self.max_instances = 2*b.masses.shape[0]
        self.count = b.masses.shape[0]
        self.additive = additive
        self.bg_color = bg_color
        #pos = np.zeros((b.pos.shape[1],3), dtype = float)
        #pos[:, :b.pos.shape[0]] = b.pos.T
        self.pos = b.pos.T.tobytes()
        #self.radius = radius

        self.box = b.size.tolist()
        self.masses = b.masses.tolist()

        self.init = True #trigger frontend init






    def add_particle(self, position = np.array([0,0,0]), color = np.array([0,0,0]), radius = 1.0):
        self.particle_data_array = np.concatenate( (self.particle_data_array, np.array([position[0], position[1], position[2], color[1], color[2], color[3], radius]).reshape(1,7)), axis = 0)
        self.particle_data = self.particle_data_array.tobytes()

    def remove_particles(self, i):
        indx = np.ones(self.particle_data_array.shape[0], dtype = bool)
        indx[i] = False

        self.particle_data_array = self.particle_data_array[indx]
        self.particle_data = self.particle_data_array.tobytes()




    def save(self, filename, title = ""):
        """
        Save a standalone html embedding of the view
        """
        embed.embed_minimal_html(filename, [self], title)

save(filename, title='')

Save a standalone html embedding of the view

Source code in evince/mdview.py
146
147
148
149
150
def save(self, filename, title = ""):
    """
    Save a standalone html embedding of the view
    """
    embed.embed_minimal_html(filename, [self], title)