<commit_before>'use strict';
var pkas = [{"ha":"HIO3","a":"IO3-","pka":0.8,"specie":{"label":"IO3-","number":1,"pka":0.8}},{"ha":"H3PO4","a":"H2PO4-","pka":2.16,"specie":{"label":"PO4---","number":3,"pka":21.69}},{"ha":"H2PO4-","a":"HPO4--","pka":7.21,"specie":{"label":"PO4---","number":2,"pka":19.53}},{"ha":"HPO4--","a":"PO4---","pka":12.32,"specie":{"label":"PO4---","number":1,"pka":12.32}},{"ha":"HF","a":"F-","pka":3.2,"specie":{"label":"F-","number":1,"pka":3.2}},{"ha":"HNO2","a":"NO2-","pka":3.25,"specie":{"label":"NO2-","number":1,"pka":3.25}},{"ha":"HOCN","a":"OCN-","pka":3.48,"specie":{"label":"OCN-","number":1,"pka":3.48}},{"ha":"H2CO3","a":"HCO3-","pka":6.35,"specie":{"label":"CO3--","number":2,"pka":16.68}},{"ha":"HCO3-","a":"CO3--","pka":10.33,"specie":{"label":"CO3--","number":1,"pka":10.33}},{"ha":"H2S","a":"HS-","pka":7.05,"specie":{"label":"S--","number":2,"pka":19.14}},{"ha":"HS-","a":"S--","pka":12.09,"specie":{"label":"S--","number":1,"pka":12.09}},{"ha":"HClO","a":"ClO-","pka":7.4,"specie":{"label":"ClO-","number":1,"pka":7.4}},{"ha":"HBrO","a":"BrO-","pka":8.6,"specie":{"label":"BrO-","number":1,"pka":8.6}},{"ha":"HCN","a":"CN-","pka":9.21,"specie":{"label":"CN-","number":1,"pka":9.21}},{"ha":"NH4+","a":"NH3","pka":9.25,"specie":{"label":"NH3","number":1,"pka":9.25}},{"ha":"CH2ClCOOH","a":"CH2ClCOO-","pka":2.89,"specie":{"label":"CH2ClCOO-","number":1,"pka":2.89}},{"ha":"HCOOH","a":"HCOO-","pka":3.75,"specie":{"label":"HCOO-","number":1,"pka":3.75}},{"ha":"C6H5COOH","a":"C6H5COO-","pka":4.2,"specie":{"label":"C6H5COO-","number":1,"pka":4.2}},{"ha":"C66H5NH3+","a":"C66H5NH2","pka":4.6,"specie":{"label":"C66H5NH2","number":1,"pka":4.6}},{"ha":"CH3COOH","a":"CH3COO-","pka":4.75,"specie":{"label":"CH3COO-","number":1,"pka":4.75}},{"ha":"C2H5COOH","a":"C2H5COO-","pka":4.87,"specie":{"label":"C2H5COO-","number":1,"pka":4.87}},{"ha":"C5H5NH+","a":"C5H5N","pka":5.25,"specie":{"label":"C5H5N","number":1,"pka":5.25}},{"ha":"CH3NH3+","a":"CH3NH2","pka":10.66,"specie":{"label":"CH3NH2","number":1,"pka":10.66}},{"ha":"(C2H5)3NH+","a":"(C2H5)3N","pka":10.75,"specie":{"label":"(C2H5)3N","number":1,"pka":10.75}},{"ha":"C2H5NH3+","a":"C2H5NH2","pka":10.8,"specie":{"label":"C2H5NH2","number":1,"pka":10.8}},{"ha":"HCl","a":"Cl-","pka":1,"specie":{"label":"Cl-","number":1,"pka":1}}];

define(['lodash'], function (_) {
    class AcidBase {
        constructor(customPkas) {
            this.pkas = customPkas || pkas;
            this.components = [];
        }

        static getAllAcidBaseLabels() {
            var species = new Set();
            for(var i=0; i<pkas.length; i++) {
                species.add(pkas[i].ha);
                species.add(pkas[i].a);
            }
            return Array.from(species);
        }

        addAcidBase(label, total) {
            var titrProtonCount;
            var titrSpecie = pkas.find(function(pka) {
                return pka.ha === label
            });
            if(titrSpecie) {
                titrProtonCount = titrSpecie.specie.number;
                titrSpecie = titrSpecie.specie.label;
            } else {
                titrSpecie = pkas.find(function(pka) {
                    return pka.a === label;
                });
                if(titrSpecie) titrProtonCount = 0;
                else throw new Error('Could not find acid/base');
                titrSpecie = titrSpecie.specie.label;
            }

            this.addComponent(titrSpecie, total);
            this.addComponent('H+', titrProtonCount * total);
        }

        addComponent(label, total) {
            if(!total) total = 0;
            var comp = this.components.find(c => c.label === label);
            if(comp) comp.total += total;
            else {
                this.components.push({
                    label, total
                });
            }
        }

        setTotal(componentLabel, total) {
            var c = this.components.find(c => c.label === componentLabel);
            c.total = total;
            c.atEquilibrium = undefined;
        }

        setAtEquilibrium(componentLabel, atEquilibrium) {
            var c = this.components.find(c => c.label === componentLabel);
            c.atEquilibrium = atEquilibrium;
            c.total = undefined;
        }

        getModel() {
            // Get all involved pkas
            var pkas = this.pkas.filter(pka => {
                return this.components.find(function (c) {
                    return String(c.label) === String(pka.specie.label);
                });
            });

            // group pkas by component<commit_msg>acidModel: add OH- is like adding negative H+<commit_after>'use strict';
var pkas = [{"ha":"HIO3","a":"IO3-","pka":0.8,"specie":{"label":"IO3-","number":1,"pka":0.8}},{"ha":"H3PO4","a":"H2PO4-","pka":2.16,"specie":{"label":"PO4---","number":3,"pka":21.69}},{"ha":"H2PO4-","a":"HPO4--","pka":7.21,"specie":{"label":"PO4---","number":2,"pka":19.53}},{"ha":"HPO4--","a":"PO4---","pka":12.32,"specie":{"label":"PO4---","number":1,"pka":12.32}},{"ha":"HF","a":"F-","pka":3.2,"specie":{"label":"F-","number":1,"pka":3.2}},{"ha":"HNO2","a":"NO2-","pka":3.25,"specie":{"label":"NO2-","number":1,"pka":3.25}},{"ha":"HOCN","a":"OCN-","pka":3.48,"specie":{"label":"OCN-","number":1,"pka":3.48}},{"ha":"H2CO3","a":"HCO3-","pka":6.35,"specie":{"label":"CO3--","number":2,"pka":16.68}},{"ha":"HCO3-","a":"CO3--","pka":10.33,"specie":{"label":"CO3--","number":1,"pka":10.33}},{"ha":"H2S","a":"HS-","pka":7.05,"specie":{"label":"S--","number":2,"pka":19.14}},{"ha":"HS-","a":"S--","pka":12.09,"specie":{"label":"S--","number":1,"pka":12.09}},{"ha":"HClO","a":"ClO-","pka":7.4,"specie":{"label":"ClO-","number":1,"pka":7.4}},{"ha":"HBrO","a":"BrO-","pka":8.6,"specie":{"label":"BrO-","number":1,"pka":8.6}},{"ha":"HCN","a":"CN-","pka":9.21,"specie":{"label":"CN-","number":1,"pka":9.21}},{"ha":"NH4+","a":"NH3","pka":9.25,"specie":{"label":"NH3","number":1,"pka":9.25}},{"ha":"CH2ClCOOH","a":"CH2ClCOO-","pka":2.89,"specie":{"label":"CH2ClCOO-","number":1,"pka":2.89}},{"ha":"HCOOH","a":"HCOO-","pka":3.75,"specie":{"label":"HCOO-","number":1,"pka":3.75}},{"ha":"C6H5COOH","a":"C6H5COO-","pka":4.2,"specie":{"label":"C6H5COO-","number":1,"pka":4.2}},{"ha":"C66H5NH3+","a":"C66H5NH2","pka":4.6,"specie":{"label":"C66H5NH2","number":1,"pka":4.6}},{"ha":"CH3COOH","a":"CH3COO-","pka":4.75,"specie":{"label":"CH3COO-","number":1,"pka":4.75}},{"ha":"C2H5COOH","a":"C2H5COO-","pka":4.87,"specie":{"label":"C2H5COO-","number":1,"pka":4.87}},{"ha":"C5H5NH+","a":"C5H5N","pka":5.25,"specie":{"label":"C5H5N","number":1,"pka":5.25}},{"ha":"CH3NH3+","a":"CH3NH2","pka":10.66,"specie":{"label":"CH3NH2","number":1,"pka":10.66}},{"ha":"(C2H5)3NH+","a":"(C2H5)3N","pka":10.75,"specie":{"label":"(C2H5)3N","number":1,"pka":10.75}},{"ha":"C2H5NH3+","a":"C2H5NH2","pka":10.8,"specie":{"label":"C2H5NH2","number":1,"pka":10.8}},{"ha":"HCl","a":"Cl-","pka":1,"specie":{"label":"Cl-","number":1,"pka":1}}];

define(['lodash'], function (_) {
    class AcidBase {
        constructor(customPkas) {
            this.pkas = customPkas || pkas;
            this.components = [];
        }

        static getAllAcidBaseLabels() {
            var species = new Set();
            for(var i=0; i<pkas.length; i++) {
                species.add(pkas[i].ha);
                species.add(pkas[i].a);
            }
            return Array.from(species);
        }

        addAcidBase(label, total) {
            var titrProtonCount;
            var titrSpecie = pkas.find(function(pka) {
                return pka.ha === label
            });
            if(titrSpecie) {
                titrProtonCount = titrSpecie.specie.number;
                titrSpecie = titrSpecie.specie.label;
            } else {
                titrSpecie = pkas.find(function(pka) {
                    return pka.a === label;
                });
                if(titrSpecie) titrProtonCount = 0;
                else throw new Error('Could not find acid/base');
                titrSpecie = titrSpecie.specie.label;
            }

            this.addComponent(titrSpecie, total);
            this.addComponent('H+', titrProtonCount * total);
        }

        addComponent(label, total) {
            if(label = 'OH-') {
                label = 'H+';
                total = -total;
            }
            if(!total) total = 0;
            var comp = this.components.find(c => c.label === label);
            if(comp) comp.total += total;
            else {
                this.components.push({
                    label, total
                });
            }
        }

        setTotal(componentLabel, total) {
            var c = this.components.find(c => c.label === componentLabel);
            c.total = total;
            c.atEquilibrium = undefined;
        }

        setAtEquilibrium(componentLabel, atEquilibrium) {
            var c = this.components.find(c => c.label === componentLabel);
            c.atEquilibrium = atEquilibrium;
            c.total = undefined;
        }

        getModel() {
            // Get all involved pkas
            var pkas = this.pkas.filter(pka => {
                return this.components.find(function (c) {
                    return String(c.label) === String(pka.specie.label);
                });
            });

            // group pkas by component
{'fraction_non_alphanumeric': 0.2903673643741991, 'fraction_numerical': 0.05809483126868859, 'mean_word_length': 3.121919014084507, 'pattern_counts': {'":': 364, '<': 5, '<?xml version=': 0, '>': 11, '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': '1179808', 'n_tokens_mistral': 3814, 'n_tokens_neox': 3530, 'n_words': 258}