<commit_before>/*"""
===========================
Universe Application
===========================
This module defines the JavaScript application that is loaded when a user
requests the HTML representation of a universe data container.
*/
'use strict';


require.config({
    shim: {
        'nbextensions/exa/lib/dat.gui.min': {
            exports: 'dat'
        },

        'nbextensions/exa/three.app': {
            exports: 'app3D'
        },

        'nbextensions/exa/utility': {
            exports: 'utility'
        },
    },
});


define([
    'nbextensions/exa/lib/dat.gui.min',
    'nbextensions/exa/three.app',
    'nbextensions/exa/utility',
], function(dat, app3D, utility) {
    var AtomicApp = function(view) {
        /*"""
        AtomicApp
        ============
        */
        var self = this;
        this.view = view;
        this.canvas = this.view.canvas;
        this.index = 0;
        this.length = this.view.framelist.length;
        this.last_frame_index = this.length - 1;
        this.frame = this.view.framelist[this.index];
        this.fps = this.view.fps;
        this.app3d = new app3D.ThreeJSApp(this.canvas);
        this.gui = new dat.GUI({autoPlace: false, width: this.view.gui_width});
        this.gui_style = document.createElement('style');
        this.gui_style.innerHTML = gui_style;
        this.init_gui();
        this.render_atoms(this.index);
    };

    AtomicApp.prototype.init_gui = function() {
        /*"""
        init_gui
        ----------------
        Initialize the graphical user interface.
        */
        var self = this;
        this.f1f = this.gui.addFolder('animation');
        this.f2f = this.gui.addFolder('atoms');
        this.f3f = this.gui.addFolder('bonds');
        this.f4f = this.gui.addFolder('cell');
        this.f5f = this.gui.addFolder('surfaces');
        this.f6f = this.gui.addFolder('volumes');

        this.playing = false;
        this.f1 = {
            pause: function() {
                this.playing = false;
                clearInterval(this._play_callback);
            },
            play: function() {
                if (this.playing == true) {
                    this.pause();
                } else {
                    this.playing = true;
                    if (self.index == self.last_frame_index) {
                        self.index = 0;
                        self.f1.slider.setValue(self.index);
                    };
                    this._play_callback = setInterval(function() {
                        if (self.index < self.last_frame_index) {
                            self.index += 1;
                            self.f1.slider.setValue(self.index);
                        } else {
                            self.f1.pause();
                        };
                    }, 1000 / self.fps);
                };
            },
            index: this.index,
            frame: this.frame,
            fps: this.fps
        };

        this.f1o = {
            'play': this.f1f.add(this.f1, 'play'),
            'slider': this.f1f.add(this.f1, 'index', 0, this.last_frame_index),
            'framelist': this.f1f.add(this.f1, 'frame', this.view.framelist),
            'fps': this.f1f.add(this.f1, 'fps', 1, 60, 1)
        };

        this.f1o.framelist.onChange(function(frame) {
            console.log(frame);
        });
    };

    AtomicApp.prototype.resize = function() {
        this.app3d.resize();
    };

    AtomicApp.prototype.render_atoms =  function(index) {
        /*"""
        render_frame
        --------------
        */
        this.index = index;
        var symbols = this.get_value(this.view.atom_symbols, this.index);
        var radii = utility.mapper(symbols, this.view.atom_radii_dict);
        var colors = utility.mapper(symbols, this.view.atom_colors_dict);
        var x = this.get_value(this.view.atom_x, this.index);
        var y = this.get_value(this.view.atom_y, this.index);
        var z = this.get_value(this.view.atom_z, this.index);
        var v0 = this.get_value(this.view.two_bond0, this.index);
        var v1 = this.get_value(this.view.two_bond1, this.index);
        this.app3d.scene.remove(this.atoms);
        this.atoms = this.app3d.add_points(x, y, z, colors, radii);
        this.app3d.scene.remove(this.bonds);
        this.bonds = this.app3d.add_lines(v0, v1, x, y, z, colors);
        this.set_camera(x, y, z);
    };

    AtomicApp.prototype.set_camera =  function(x, y, z) {
        /*"""
        set_camera
        -------------
        */
        var n = x.length;
        var i = n;
        var oxyz = [0.0, 0.0, 0.0];
        while (i--) {
            oxyz[0] += x[i];
            oxyz[1] += y[i];
            oxyz[2] += z[i];
        };
        oxyz[0] /= n;
        oxyz[1] /= n;
        oxyz[2] /= n;
        this.atoms.geometry.computeBoundingBox();
        var bbox = this.atoms.geometry.boundingBox;
        var x = Math.pow(bbox.max.x - bbox.min.x, 2);
        var y = Math.pow(bbox.max.y - bbox.min.y, 2);
        var z = Math.pow(bbox.max.z - bbox.min.z, 2);
        var d = Math.sqrt(x + y + z);
        console.log(d);
        var xyz = bbox.max;
        xyz.x += d;
        xyz.y += d;
        xyz.z += d;
        console.log(xyz);
        this.app3d.set_camera(100, 100, 100, oxyz[0], oxyz[1], oxyz[2]);
    };

    AtomicApp.prototype.get_value = function(obj, index) {
        /*"""
        get_value
        --------------
        */
        var value = obj[index];
        if (value == undefined) {
            return obj;<commit_msg>auto resize and cam pos<commit_after>/*"""
===========================
Universe Application
===========================
This module defines the JavaScript application that is loaded when a user
requests the HTML representation of a universe data container.
*/
'use strict';


require.config({
    shim: {
        'nbextensions/exa/lib/dat.gui.min': {
            exports: 'dat'
        },

        'nbextensions/exa/three.app': {
            exports: 'app3D'
        },

        'nbextensions/exa/utility': {
            exports: 'utility'
        },
    },
});


define([
    'nbextensions/exa/lib/dat.gui.min',
    'nbextensions/exa/three.app',
    'nbextensions/exa/utility',
], function(dat, app3D, utility) {
    var AtomicApp = function(view) {
        /*"""
        AtomicApp
        ============
        */
        var self = this;
        this.view = view;
        this.canvas = this.view.canvas;
        this.index = 0;
        this.length = this.view.framelist.length;
        this.last_frame_index = this.length - 1;
        this.frame = this.view.framelist[this.index];
        this.fps = this.view.fps;
        this.app3d = new app3D.ThreeJSApp(this.canvas);
        this.gui = new dat.GUI({autoPlace: false, width: this.view.gui_width});
        this.gui_style = document.createElement('style');
        this.gui_style.innerHTML = gui_style;
        this.init_gui();
        this.render_atoms(this.index);
    };

    AtomicApp.prototype.init_gui = function() {
        /*"""
        init_gui
        ----------------
        Initialize the graphical user interface.
        */
        var self = this;
        this.f1f = this.gui.addFolder('animation');
        this.f2f = this.gui.addFolder('atoms');
        this.f3f = this.gui.addFolder('bonds');
        this.f4f = this.gui.addFolder('cell');
        this.f5f = this.gui.addFolder('surfaces');
        this.f6f = this.gui.addFolder('volumes');

        this.playing = false;
        this.f1 = {
            pause: function() {
                this.playing = false;
                clearInterval(this._play_callback);
            },
            play: function() {
                if (this.playing == true) {
                    this.pause();
                } else {
                    this.playing = true;
                    if (self.index == self.last_frame_index) {
                        self.index = 0;
                        self.f1.slider.setValue(self.index);
                    };
                    this._play_callback = setInterval(function() {
                        if (self.index < self.last_frame_index) {
                            self.index += 1;
                            self.f1.slider.setValue(self.index);
                        } else {
                            self.f1.pause();
                        };
                    }, 1000 / self.fps);
                };
            },
            index: this.index,
            frame: this.frame,
            fps: this.fps
        };

        this.f1o = {
            'play': this.f1f.add(this.f1, 'play'),
            'slider': this.f1f.add(this.f1, 'index', 0, this.last_frame_index),
            'framelist': this.f1f.add(this.f1, 'frame', this.view.framelist),
            'fps': this.f1f.add(this.f1, 'fps', 1, 60, 1)
        };

        this.f1o.framelist.onChange(function(frame) {
            console.log(frame);
        });
    };

    AtomicApp.prototype.resize = function() {
        this.app3d.resize();
    };

    AtomicApp.prototype.render_atoms =  function(index) {
        /*"""
        render_frame
        --------------
        */
        this.index = index;
        var symbols = this.get_value(this.view.atom_symbols, this.index);
        var radii = utility.mapper(symbols, this.view.atom_radii_dict);
        var colors = utility.mapper(symbols, this.view.atom_colors_dict);
        var x = this.get_value(this.view.atom_x, this.index);
        var y = this.get_value(this.view.atom_y, this.index);
        var z = this.get_value(this.view.atom_z, this.index);
        var v0 = this.get_value(this.view.two_bond0, this.index);
        var v1 = this.get_value(this.view.two_bond1, this.index);
        this.app3d.scene.remove(this.atoms);
        this.atoms = this.app3d.add_points(x, y, z, colors, radii);
        this.app3d.scene.remove(this.bonds);
        this.bonds = this.app3d.add_lines(v0, v1, x, y, z, colors);
        this.set_camera(x, y, z);
    };

    AtomicApp.prototype.set_camera =  function(x, y, z) {
        /*"""
        set_camera
        -------------
        */
        var n = x.length;
        var i = n;
        var oxyz = [0.0, 0.0, 0.0];
        while (i--) {
            oxyz[0] += x[i];
            oxyz[1] += y[i];
            oxyz[2] += z[i];
        };
        oxyz[0] /= n;
        oxyz[1] /= n;
        oxyz[2] /= n;
        this.atoms.geometry.computeBoundingBox();
        var bbox = this.atoms.geometry.boundingBox;
        var xyz = bbox.max;
        xyz.x *= 1.3;
        xyz.y *= 1.3;
        xyz.z *= 1.3;
        this.app3d.set_camera(xyz.x, xyz.y, xyz.z, oxyz[0], oxyz[1], oxyz[2]);
    };

    AtomicApp.prototype.get_value = function(obj, index) {
        /*"""
        get_value
        --------------
        */
        var value = obj[index];
        if (value == undefined) {
            return obj;
{'fraction_non_alphanumeric': 0.15995587424158852, 'fraction_numerical': 0.013421584850156279, 'mean_word_length': 1.531766348615313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7536569', 'n_tokens_mistral': 3644, 'n_tokens_neox': 3471, 'n_words': 595}