仓库源文站点原文


layout: post title: 弱酸和配合物分布曲线绘制工具 categories:


写了一个计算弱酸和配合物分布曲线工具的在线工具, 因为觉得用处不是太大, 除了做分析化学的可能需要, 所以就一直没有发布, 只当是拿来熟悉下echarts的使用. 但想到对某些人可能还是有用的, 就放在这里吧.

计算方法参考的是: 孙晓波, 王进平; Origin在弱酸和配合物分布曲线绘制中的应用; 高师理科学刊 34(1):79-81, 2014. 默认设置是用于绘制EDTA分布分数的.

<table> <tr><td> <input type="radio" name='Kab' id="Ka" checked="checked">Ka <input type="radio" name='Kab' id="pKa">pKa<br> <input type="radio" name='Kab' id="beta">β  <input type="radio" name='Kab' id="logb">logβ<br> 级数 常数值<br> <textarea id="input" style="width:150px; height:100px;"></textarea><br> 设置 pH(用于Ka, pKa)<br>或 对数浓度(用于β,logβ)<br> 初值: <input type="text" id="minPH" style="width:30px" value="0"> 终值: <input type="text" id="maxPH" style="width:30px" value="14"> 间隔: <input type="text" id="dPH" style="width:30px" value="0.1"><br><br> <input type="button" id="btn" style="width:150px" value="绘图" onClick="plot()"> </td></tr> <tr><td><div id="echarts" style="height:400px; width:600px"></div></td></tr> <tr> <td>分布数据<BR><textarea id="singCol" style="width:600px; height:400px;"></textarea></td> </tr> </table><script src="https://echarts.baidu.com/build/dist/echarts.js"></script><script> var $=function(id){return document.getElementById(id)}; var myChart, option require.config({ paths: {echarts: 'https://echarts.baidu.com/build/dist'} }); require( ['echarts', 'echarts/chart/bar','echarts/chart/line'], function (ec) { option = { title: { text: '分布分数' }, legend: { data:['分布分数'] }, tooltip: {trigger:'axis'}, toolbox: { show: true, feature: { mark: {show: false}, dataZoom: {show: true}, dataView: {show: true, readOnly: false}, magicType: { show: true, type: ['line', 'bar'] }, restore: {show: true}, saveAsImage: {show: true} } }, dataZoom: { show: true, realtime: true, start: 0, end: 100 }, xAxis: [{ type:'value', axisLine:{show: false}, axisLabel: {formatter:'{value}'}, min:0, max:14 }], yAxis: [{ type:'value', min:0, max:1, axisLabel: {formatter: '{value}'} }], series: [{ name:'相对分布', type:'line', data:[[0]] }] } myChart = ec.init($('echarts')); myChart.setOption(option); } ) $('input').value= "1 1.3E-1 " +"\n2 2.5E-2 " +"\n3 1.0E-2 " +"\n4 2.14E-3 " +"\n5 6.92E-7 " +"\n6 5.50E-11 " /*$('input').value= "1 4.31 " +"\n2 7.98 " +"\n3 11.02 " +"\n4 13.32 " +"\n5 12.86 "*/ function plot() { $('btn').value='正在绘图...' var i, j, data, Kab=[], PiKab=[] var txt=$('input').value.replace(/^\s*\n*/,"").replace(/\s*\n*$/,"").replace(/\s+[\n|$]/g,"\n"), txt=txt.split("\n"), NumKab=txt.length for(i=0; i<NumKab; i++) { data=txt[i].split(/\s+/) if($('Ka').checked || $('beta').checked) Kab[data[0]]=data[1] if($('pKa').checked) Kab[data[0]]=Math.pow(10, -data[1]) if($('logb').checked) Kab[data[0]]=Math.pow(10, data[1]) } PiKab[0]=1 for(i=1; i<=NumKab; i++) { PiKab[i]=1 if($('Ka').checked || $('pKa').checked) for(j=1; j<=i; j++) PiKab[i] *= Kab[j] if($('beta').checked || $('logb').checked) PiKab[i]=Kab[i] } var C, Ftot, PH=[], Fac=[], Delt=[], minPH=parseFloat($('minPH').value), maxPH=parseFloat($('maxPH').value), dPH=parseFloat($('dPH').value), numPH=Math.floor((maxPH-minPH)/dPH) for(i=0; i<=NumKab; i++) Delt[i]=[] txt=' #pH/logC δ0 δ1 δ2 δ3 δ4 δ5 δ6 δ7 δ8 ...\n' for(k=0; k<=numPH; k++) { PH[k]=minPH+k*dPH if($('Ka').checked || $('pKa').checked) { C=Math.pow(10, -PH[k]) for(i=0; i<=NumKab; i++) Fac[i]=Math.pow(C, NumKab-i)*PiKab[i] } if($('beta').checked || $('logb').checked) { C=Math.pow(10, PH[k]) for(i=0; i<=NumKab; i++) Fac[i]=Math.pow(C, i)*PiKab[i] } Ftot=0 for(i=0; i<=NumKab; i++) { Ftot += Fac[i] } txt += fmtNum(PH[k], 8.3) for(i=0; i<=NumKab; i++) { Delt[i][k] = Fac[i]/Ftot txt += ' '+fmtNum(Delt[i][k], 10.8) } if($('beta').checked || $('logb').checked) { var avgN=0 for(i=1; i<=NumKab; i++) avgN += i*Fac[i] txt += ' '+fmtNum(avgN/Ftot, 10.8) } txt += '\n' } $('singCol').value=txt option.series=[] option.legend.data=[] option.xAxis[0].type='category' option.xAxis[0].data=PH for(i=0; i<=NumKab; i++) { option.legend.data.push('δ'+i) option.series.push({ "name": 'δ'+i, "type": "line" }) option.series[i].data=Delt[i] } myChart=require('echarts').init($('echarts')); myChart.setOption(option); $('btn').value='绘图' } function fmtNum(num, fmt) { var fmt=String(fmt), m=fmt.split(".")[0] num=num.toFixed(fmt.split(".")[1]) if(num.length<m) num=Array(m-num.length+1).join(" ")+num return num } </script>