-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathgraphene.html
132 lines (112 loc) · 22.2 KB
/
graphene.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="https://jerkwin.github.io/jscss/pmd.min.css">
<script src="https://jerkwin.github.io/jscss/ChemDoodleWeb.js"></script>
<div class="wrap">
<table>
<tr><td colspan=2>
大小(基本单元):
长 <input type="box" id="wid" value="5" style="width:30px;"/>
宽 <input type="box" id="hig" value="2" style="width:30px;"/>(设为0则根据长度自动计算, 生成尽可能正方的构型)<br>
</td></tr>
<tr><td colspan=2>
原子(基本结构):
键长(Å) <input type="box" id="rcc" value="1.4" style="width:30px;"/>
类型 <input type="box" id="atom" value="C C C C" style="width:150px;"/><br/>
</td></tr>
<tr><td colspan=2>
氧化修饰(原子覆盖度%): <input type='checkbox' id='noPBC'> 取消周期性<br>
内部 -O-
<input type="box" id="fO" value="0" style="width:30px;"/>
<input type='checkbox' id='upO'>随机上下
-OH
<input type="box" id="fOH" value="0" style="width:30px;"/>
<input type='checkbox' id='rotOH'>随机取向
<input type='checkbox' id='upOH'>随机上下
-COOH
<input type="box" id="fCOOH" value="0" style="width:30px;"/>
<input type='checkbox' id='rotCOOH'>随机取向
<input type='checkbox' id='upCOOH'>随机上下<br>
边缘 =O
<input type="box" id="fBO" value="0" style="width:30px;"/>
-OH
<input type="box" id="fBOH" value="0" style="width:30px;"/>
<input type='checkbox' id='rotBOH'>随机旋转
-COOH
<input type="box" id="fBCOOH" value="0" style="width:30px;"/>
<input type='checkbox' id='rotBCOOH'>随机旋转
</td></tr>
<tr><td colspan=2>
整体平移(键长倍数):
X方向 <input type="box" id="trsX" value="0" style="width:30px;"/>
Y方向 <input type="box" id="trsY" value="0" style="width:30px;" />
Z方向(Å) <input type="box" id="trsZ" value="0" style="width:30px;"/>
</td></tr>
<tr><td colspan=2>
坐标随机涨落振幅(Å):
X方向 <input type="box" id="ranX" value="0" style="width:30px;"/>
Y方向 <input type="box" id="ranY" value="0" style="width:30px;" />
Z方向 <input type="box" id="ranZ" value="0" style="width:30px;"/>
</td></tr>
<tr><td colspan=2>
Z 方向波动周期数:
X方向 <input type="box" id="cycX" value="1" style="width:30px;"/>
Y方向 <input type="box" id="cycY" value="1" style="width:30px;"/>
振幅(Å) <input type="box" id="cycZ" value="0" style="width:30px;"/>
</td></tr>
<tr><td colspan=2>
孔洞类型:
<input type="box" id="holeType" value="0" style="width:30px;"/>(0为圆形, 其他整数为正多边形)
孔洞半径(Å):<input type="box" id="rcnt" value="0" style="width:30px;"/><br>
中心点位置:
<input type="radio" name="hole" value="Atom"/>原子
<input type="radio" name="hole" value="Bond"/>键中点
<input type="radio" name="hole" value="Ring" checked="checked"/>碳环中心
</td></tr>
<tr><td colspan=2>
XZ 方向卷曲参数方程(t, pi, tau, xbox, tbox): 扭曲 <input type="box" id="vF" style="width:40%" value=''><br>
X方向 <input type="box" id="Fx" style="width:40%" value=''>
切线 <input type="box" id="dFx" style="width:40%" value=''><br>
Z方向 <input type="box" id="Fz" style="width:40%" value=''>
切线 <input type="box" id="dFz" style="width:40%" value=''><br>
<!--
X方向 <input type="box" id="Fx" style="width:40%" value='xbox/tau*cos(t)'>
切线 <input type="box" id="dFx" style="width:40%" value='-sin(t)'><br>
Z方向 <input type="box" id="Fz" style="width:40%" value='xbox/tau*sin(t)'>
切线 <input type="box" id="dFz" style="width:40%" value='cos(t)'><br>
X方向 <input type="box" id="Fx" style="width:40%" value='16*pow(sin(t),3)' />
切线 <input type="box" id="dFx" style="width:40%" value='10*sin(2*pi*t)' /><br>
Z方向 <input type="box" id="Fz" style="width:40%" value='13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)' />
切线 <input type="box" id="dFz" style="width:40%" value='10*sin(2*pi*t)' /><br>
X方向 <input type="box" id="Fx" style="width:40%" value='10*(cos(t)-.5*cos(2*t))' />
切线 <input type="box" id="dFx" style="width:40%" value='10*sin(2*pi*t)' /><br>
Z方向 <input type="box" id="Fz" style="width:40%" value='10*(sin(t)-.5*sin(2*t))' />
切线 <input type="box" id="dFz" style="width:40%" value='10*sin(2*pi*t)' /><br>
X方向 <input type="box" id="Fx" style="width:40%" value='10*t*sin(2*pi*t)' />
切线 <input type="box" id="dFx" style="width:40%" value='10*sin(2*pi*t)' /><br>
Z方向 <input type="box" id="Fz" style="width:40%" value='10*t*cos(2*pi*t)' />
切线 <input type="box" id="dFz" style="width:40%" value='10*sin(2*pi*t)' /><br>
-->
</td></tr>
<tr><td colspan=2>
<input type="button" value="创建" onClick="genCoor()" style="font-size:1em;font-weight:bold;color:red;width:100%; height:30px" />
</td></tr>
<tr>
<td>
GROMACS构型文件(gro)<br/><textarea id="groCoor" style="width:400px; height:500px; resize: none"></textarea>
</td>
<td>
<figure><figurecaption>结构</figurecaption><br/>
<script>
ChemDoodle.default_backgroundColor = 'black';var Mol1=new ChemDoodle.TransformCanvas3D('Mol-1', 400,500);Mol1.specs.atoms_displayLabels_3D=false;Mol1.specs.atoms_resolution_3D = 15;Mol1.specs.bonds_resolution_3D = 15;Mol1.specs.shapes_color = '#fff';Mol1.specs.projectionPerspective_3D = false;Mol1.specs.set3DRepresentation('Ball and Stick');Mol1.specs.crystals_unitCellLineWidth = 1.5;Mol1.handle = null;Mol1.timeout = 15;Mol1.startAnimation = ChemDoodle._AnimatorCanvas.prototype.startAnimation;Mol1.stopAnimation = ChemDoodle._AnimatorCanvas.prototype.stopAnimation;Mol1.isRunning = ChemDoodle._AnimatorCanvas.prototype.isRunning;Mol1.dblclick = ChemDoodle.RotatorCanvas.prototype.dblclick;Mol1.nextFrame = function(delta){var matrix = [];ChemDoodle.lib.mat4.identity(matrix);var change = delta*Math.PI/15000;ChemDoodle.lib.mat4.rotate(matrix, change, [ 1, 0, 0 ]);ChemDoodle.lib.mat4.rotate(matrix, change, [ 0, 1, 0 ]);ChemDoodle.lib.mat4.rotate(matrix, change, [ 0, 0, 1 ]);ChemDoodle.lib.mat4.multiply(this.rotationMatrix, matrix)};var Fcif='';var cell=ChemDoodle.readCIF(Fcif, 1,1,1);Mol1.loadContent([cell.molecule], [cell.unitCell]);Mol1.startAnimation();var $=function(id){return document.getElementById(id)};function setSupercell1(){var cell=ChemDoodle.readCIF(Fcif, $("Mol1x").value, $("Mol1y").value, $("Mol1z").value);Mol1.loadContent([cell.molecule], [cell.unitCell]);Mol1.repaint()}function setModel1(model){Mol1.specs.set3DRepresentation(model);Mol1.setupScene();Mol1.repaint()}function setProj1(yesPers){Mol1.specs.projectionPerspective_3D = yesPers;Mol1.setupScene();Mol1.repaint()}
</script></figure>
</td>
</tr>
<tr><td colspan="2">
视图: <input type="radio" name="group2" onclick="setProj1(true)">投影<input type="radio" name="group2" onclick="setProj1(false)" checked="">正交<br>模型: <input type="radio" name="model" onclick="setModel1('Ball and Stick')" checked="">球棍<input type="radio" name="model" onclick="setModel1('van der Waals Spheres')">范德华球<input type="radio" name="model" onclick="setModel1('Stick')">棍状<input type="radio" name="model" onclick="setModel1('Wireframe')">线框<input type="radio" name="model" onclick="setModel1('Line')">线型 <input type='checkbox' onclick='Mol1.specs.atoms_displayLabels_3D=this.checked;Mol1.repaint()'>名称<br>超晶胞: X <input type="text" style="width:20px;" id="Mol1x" value="1"> Y <input type="text" style="width:20px;" id="Mol1y" value="1"> Z <input type="text" style="width:20px;" id="Mol1z" value="1"> <input type="button" value="创建" onclick="setSupercell1()"><br>左键: 转动 滚轮: 缩放 双击: 开关自动旋转 Alt+左键: 移动
</td></tr>
</table>
</div>
<script>
function trim(a){return a.replace(/^(\s|\u00A0)+/,"").replace(/(\s|\u00A0)+$/,"")}function mathFunction(a){var c,d,b="pow sqrt exp log abs ceil floor min max round random sin cos tan asin acos atan atan2 toSource valueOf";for(b=b.split(/\s+/),c=0,d=b.length;d>c;c++)a=a.replace(new RegExp(b[c]+"\\(","g"),"Math."+b[c]+"(");return a.replace(/pi/gi,"Math.PI").replace(/tau/gi,"(2*Math.PI)").replace(/xbox/gi,parseInt($("wid").value)*Math.sqrt(3)*parseFloat($("rcc").value))}function genCoor(){var a,b,c,d,e,K,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,ab,bb,cb,db,eb,fb,gb,hb,ib,jb,kb,lb,mb,pb,nb,ob,qb,sb,rb,tb,ub,vb,wb,xb,yb,zb,Ab,Bb,Cb,Db,Eb,Fb,Gb,Hb,Ib,Jb,Kb,Lb,Mb,Nb,Ob,Pb,Qb;for(trim($("Fx").value).length>0&&trim($("Fz").value).length>0&&(isFt=!0),isFt&&trim($("vF").value).length>0&&trim($("dFx").value).length>0&&trim($("dFz").value).length>0&&(isdFt=!0),f=parseInt($("wid").value),g=parseInt($("hig").value),h=parseFloat($("rcc").value),i=parseFloat($("rcnt").value),j=!$("noPBC").checked,k=parseFloat($("fO").value)/100,l=1.2,m=$("upO").checked,n=parseFloat($("fOH").value)/100,o=$("upOH").checked,p=$("rotOH").checked,q=parseFloat($("fCOOH").value)/100,r=$("upCOOH").checked,s=$("rotCOOH").checked,t=parseFloat($("fBO").value)/100,u=parseFloat($("fBOH").value)/100,v=$("rotBOH").checked,w=parseFloat($("fBCOOH").value)/100,x=$("rotBCOOH").checked,y=parseFloat($("cycX").value),z=parseFloat($("ranX").value),A=parseFloat($("cycY").value),B=parseFloat($("ranY").value),C=parseFloat($("cycZ").value),D=parseFloat($("ranZ").value),E=parseFloat($("trsX").value),F=parseFloat($("trsY").value),G=parseFloat($("trsZ").value),H=$("atom").value,I=parseInt($("holeType").value),J=3,L=document.getElementsByName("hole"),L[0].checked&&(J=1,K=L[0].value),L[1].checked&&(J=2,K=L[1].value),L[2].checked&&(J=3,K=L[2].value),0===g&&(g=parseInt(Math.round(Math.sqrt(3)*f/3))),M=Math.sqrt(3)/4,N=[],O=[],P=[],Q=Math.sqrt(3)*h,R=3*h,N[1]=0+M,O[1]=.5,N[4]=0+M,O[4]=2.5,N[2]=Math.sqrt(3)/2+M,O[2]=1,N[3]=Math.sqrt(3)/2+M,O[3]=2,c=1;4>=c;c++)N[c]+=E,N[c]*=h,O[c]+=F,O[c]*=h;if(S=f,T=g,U=S*Q,V=T*R,W=U/2+M*h,X=V/2,y*=2*Math.PI/U,A*=2*Math.PI/V,f%2!=g%2?2==J?W-=Q/2:1==J&&(X+=h):1==J?X+=h/2:3==J&&(W-=Q/2),I>2)for(M=-(.5-1/I)*Math.PI,a=0;I>a;a++)M+=2*Math.PI/I,P[a]=[W+i*Math.cos(M),X+i*Math.sin(M)];if(H=H.replace(/^\s+/,"").replace(/\s+$/,"").split(/\s+/),a=H.length,4>a)for(b=a;4>b;b++)H[b]="C";for(Y=0,Z=0,ab=[],bb=[],cb=[],db=[],eb=[],fb=[],gb=[],b=0;g>b;b++)for(e=b*R,a=0;f>a;a++)for(d=a*Q,c=1;4>=c;c++)Y++,ab[Y]=0,bb[Y]=a+1,cb[Y]=b+1,gb[Y]=H[c-1],db[Y]=N[c]+d,eb[Y]=O[c]+e,fb[Y]=C,y>0&&(fb[Y]*=Math.sin(db[Y]*y)),A>0&&(fb[Y]*=Math.sin(eb[Y]*A)),isIn=1,0==I&&(isIn=Math.pow(db[Y]-W,2)+Math.pow(eb[Y]-X,2)<Math.pow(i,2)),I>2&&(isIn=isInPolygon([db[Y],eb[Y]],P)),isIn||(Z++,ab[Y]=Z);for(ib=-1,jb=[],kb=[],lb=[],mb=[],a=1;Y>=a;a++)lb[a]=[],mb[a]=[],b=a%4,hb=0,1==b?(hb++,lb[a][hb]=a+1,mb[a][1]=a+1,mb[a][2]=a+2,ib++,jb[ib]=a,kb[ib]=a+1,idx=getIdx(f,g,bb[a]-1,cb[a],2),idx>0&&(hb++,lb[a][hb]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx),idx=getIdx(f,g,bb[a],cb[a]-1,4),idx>0&&(hb++,lb[a][hb]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx)):2==b?(lb[a][1]=a+1,lb[a][2]=a-1,mb[a][1]=a+1,mb[a][2]=a-1,ib++,jb[ib]=a,kb[ib]=a+1,idx=getIdx(f,g,bb[a]+1,cb[a],1),idx>0&&(lb[a][3]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx),idx=getIdx(f,g,bb[a]+1,cb[a],1),idx>0&&(lb[a][3]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx)):3==b?(lb[a][1]=a+1,lb[a][2]=a-1,mb[a][1]=a+1,mb[a][2]=a-1,ib++,jb[ib]=a,kb[ib]=a+1,idx=getIdx(f,g,bb[a]+1,cb[a],4),idx>0&&(lb[a][3]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx),idx=getIdx(f,g,bb[a]+1,cb[a],4),idx>0&&(lb[a][3]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx)):0==b&&(lb[a][1]=a-1,mb[a][1]=a-2,mb[a][2]=a-1,idx=getIdx(f,g,bb[a]-1,cb[a],3),idx>0&&(lb[a][2]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx),idx=getIdx(f,g,bb[a],cb[a]+1,1),idx>0&&(lb[a][2]=idx),idx>a&&(ib++,jb[ib]=a,kb[ib]=idx));for(ib++,nb=0,ob=[],a=1;Y>=a;a++)ob[a]=!1,!j&&(1==bb[a]&&1>=a%4||bb[a]==f&&a%4>1||1==cb[a]&&1==a%4||cb[a]==g&&0==a%4)&&(nb++,ob[a]=!0);for(pb=Y-nb,qb=[],qb[1]=[],qb[2]=[],a=0;ib>a;a++)qb[1][a]=jb[a],qb[2][a]=kb[a];if(isFt){for(Ft=new Function("t","r","r[0]="+mathFunction(trim($("Fx").value))+";"+"r[1]=0;"+"r[2]="+mathFunction(trim($("Fz").value))+";"),rb=.001,tb=0,ub=[],vb=[],sb=0;U>=tb;sb+=.5)tb+=sarc(sb,sb+.5,rb);for(sb=tarc(U,0,0,sb,rb),isdFt&&(dFt=new Function("t","r","r[0]="+mathFunction(trim($("dFx").value))+";"+"r[1]=0;"+"r[2]="+mathFunction(trim($("dFz").value))+";"),vFt=new Function("t","tht","return "+mathFunction(trim($("vF").value)).replace("tbox",sb))),a=1;Y>=a;a++)M=tarc(db[a],0,0,sb,rb),Ft(M,ub),db[a]=ub[0],fb[a]=ub[2],isdFt&&(vb=[0,db[a],eb[a],fb[a]],dFt(M,ub),AxiRotMat(vFt(M)/d2r,ub[0],ub[1],ub[2]),RotVect(RotMat,vb,vb[1],.5*V,vb[3]),db[a]=vb[1],eb[a]=vb[2],fb[a]=vb[3])}for(wb=[],wb[0]=-1,a=1;Y>=a;a++)if(wb[a]=a,ob[a]){for(wb[a]=-1,idx=jb.indexOf(a);-1!=idx;)jb.splice(idx,1),kb.splice(idx,1),idx=jb.indexOf(a);for(idx=kb.indexOf(a);-1!=idx;)jb.splice(idx,1),kb.splice(idx,1),idx=kb.indexOf(a)}for(xb=0,yb=0,zb=0,Ab=[];zb<Math.ceil(pb*k)&&jb.length>0;){for(idx=getRandInt(0,jb.length-1),a=jb[idx],b=kb[idx],zb++,xb++,wb[a]=-1,wb[b]=-1,yb=m&&Math.random()<.5?-1:1,gb[Y+xb]="O",fb[Y+xb]=.5*(fb[a]+fb[b]),j?(db[Y+xb]=db[a]+.5*pbcCart(db[b]-db[a],U),eb[Y+xb]=eb[a]+.5*pbcCart(eb[b]-eb[a],V)):(db[Y+xb]=.5*(db[a]+db[b]),eb[Y+xb]=.5*(eb[a]+eb[b])),ang(db[mb[a][1]],eb[mb[a][1]],fb[mb[a][1]],db[a],eb[a],fb[a],db[mb[a][2]],eb[mb[a][2]],fb[mb[a][2]],Ab),db[Y+xb]+=l*yb*Ab[1],eb[Y+xb]+=l*yb*Ab[2],fb[Y+xb]+=l*yb*Ab[3],idx=jb.indexOf(a);-1!=idx;)jb.splice(idx,1),kb.splice(idx,1),idx=jb.indexOf(a);for(idx=jb.indexOf(b);-1!=idx;)jb.splice(idx,1),kb.splice(idx,1),idx=jb.indexOf(b);for(idx=kb.indexOf(a);-1!=idx;)jb.splice(idx,1),kb.splice(idx,1),idx=kb.indexOf(a);for(idx=kb.indexOf(b);-1!=idx;)jb.splice(idx,1),kb.splice(idx,1),idx=kb.indexOf(b)}for(idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1);for(Bb="\nC 0.000 -0.000 0.0000\nO 0.000 0.000 1.4580\nH 0.916 -0.000 1.7598",Bb=trim(Bb).split("\n"),Cb=[],Db=[],Eb=[],Fb=[],a=0;a<Bb.length;a++)Cb[a]=Bb[a].split(/\s+/)[0],Db[a]=parseFloat(Bb[a].split(/\s+/)[1]),Eb[a]=parseFloat(Bb[a].split(/\s+/)[2]),Fb[a]=parseFloat(Bb[a].split(/\s+/)[3]);for(Gb=0;Gb<Math.ceil(pb*n)&&wb.length>0;){for(idx=getRandInt(0,wb.length-1),a=wb[idx],wb[idx]=-1,b=0;ib>b;b++){if(qb[1][b]==a)for(idx=wb.indexOf(qb[2][b]);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(qb[2][b]);if(qb[2][b]==a)for(idx=wb.indexOf(qb[1][b]);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(qb[1][b])}for(Gb++,yb=o&&Math.random()<.5?-1:1,ang(db[mb[a][1]],eb[mb[a][1]],fb[mb[a][1]],db[a],eb[a],fb[a],db[mb[a][2]],eb[mb[a][2]],fb[mb[a][2]],Ab),AxiRotMat(180,Ab[1],Ab[2],Ab[3]+1),b=1;2>=b;b++)xb++,vb=[0,db[a]+yb*Db[b],eb[a]+yb*Eb[b],fb[a]+yb*Fb[b]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),gb[Y+xb]=Cb[b],db[Y+xb]=vb[1],eb[Y+xb]=vb[2],fb[Y+xb]=vb[3];for(M=-30,a%2&&(M=-90),p&&(M+=120*getRandInt(0,3)),AxiRotMat(M,Ab[1],Ab[2],Ab[3]),vb=[0,db[Y+xb],eb[Y+xb],fb[Y+xb]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),db[Y+xb]=vb[1],eb[Y+xb]=vb[2],fb[Y+xb]=vb[3],idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1)}for(idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1);for(Hb="\nC 0.000 0.000 0.0000\nC 0.000 -0.000 1.5608\nO 0.992 -0.000 2.2318\nO -1.228 -0.061 2.0680\nH -1.192 -0.119 3.0366",Hb=trim(Hb).split("\n"),Ib=[],Jb=[],Kb=[],Lb=[],a=0;a<Hb.length;a++)Ib[a]=Hb[a].split(/\s+/)[0],Jb[a]=parseFloat(Hb[a].split(/\s+/)[1]),Kb[a]=parseFloat(Hb[a].split(/\s+/)[2]),Lb[a]=parseFloat(Hb[a].split(/\s+/)[3]);for(Mb=0;Mb<Math.ceil(pb*q)&&wb.length>0;){for(idx=getRandInt(0,wb.length-1),a=wb[idx],wb[idx]=-1,b=0;ib>b;b++){if(qb[1][b]==a)for(idx=wb.indexOf(qb[2][b]);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(qb[2][b]);if(qb[2][b]==a)for(idx=wb.indexOf(qb[1][b]);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(qb[1][b])}for(Mb++,yb=r&&Math.random()<.5?-1:1,ang(db[mb[a][1]],eb[mb[a][1]],fb[mb[a][1]],db[a],eb[a],fb[a],db[mb[a][2]],eb[mb[a][2]],fb[mb[a][2]],Ab),AxiRotMat(180,Ab[1],Ab[2],Ab[3]+1),b=1;4>=b;b++)xb++,vb=[0,db[a]+yb*Jb[b],eb[a]+yb*Kb[b],fb[a]+yb*Lb[b]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),gb[Y+xb]=Ib[b],db[Y+xb]=vb[1],eb[Y+xb]=vb[2],fb[Y+xb]=vb[3];for(M=-5,a%2&&(M=-65),s&&(M+=120*getRandInt(0,3)),AxiRotMat(M,Ab[1],Ab[2],Ab[3]),b=0;4>b;b++)vb=[0,db[Y+xb-b],eb[Y+xb-b],fb[Y+xb-b]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),db[Y+xb-b]=vb[1],eb[Y+xb-b]=vb[2],fb[Y+xb-b]=vb[3];for(idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1)}for(wb=[],a=0;Y>=a;a++)wb[a]=a,ob[a]||(wb[a]=-1);for(idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1);for(Nb=0;Nb<Math.ceil(nb*t)&&wb.length>0;)for(idx=getRandInt(0,wb.length-1),a=wb[idx],wb[idx]=-1,vb=[db[lb[a][1]]-db[a],eb[lb[a][1]]-eb[a],fb[lb[a][1]]-fb[a]],lb[a].length>2&&(vb[0]+=db[lb[a][2]]-db[a],vb[1]+=eb[lb[a][2]]-eb[a],vb[2]+=fb[lb[a][2]]-fb[a]),ub=1/Math.sqrt(vb[0]*vb[0]+vb[1]*vb[1]+vb[2]*vb[2]),Nb++,xb++,gb[Y+xb]="O",db[Y+xb]=db[a]-1.2*vb[0]*ub,eb[Y+xb]=eb[a]-1.2*vb[1]*ub,fb[Y+xb]=fb[a]-1.2*vb[2]*ub,idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1);for(Ob=0;Ob<Math.ceil(pb*u)&&wb.length>0;){for(idx=getRandInt(0,wb.length-1),a=wb[idx],wb[idx]=-1,Ab=[0,db[lb[a][1]]-db[a],eb[lb[a][1]]-eb[a],fb[lb[a][1]]-fb[a]],lb[a].length>2&&(Ab[1]+=db[lb[a][2]]-db[a],Ab[2]+=eb[lb[a][2]]-eb[a],Ab[3]+=fb[lb[a][2]]-fb[a]),ub=-1/Math.sqrt(Ab[1]*Ab[1]+Ab[2]*Ab[2]+Ab[3]*Ab[3]),Ab[1]*=ub,Ab[2]*=ub,Ab[3]*=ub,AxiRotMat(180,Ab[1],Ab[2],Ab[3]+1),Ob++,b=1;2>=b;b++)xb++,vb=[0,db[a]+Db[b],eb[a]+Eb[b],fb[a]+Fb[b]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),gb[Y+xb]=Cb[b],db[Y+xb]=vb[1],eb[Y+xb]=vb[2],fb[Y+xb]=vb[3];for(v&&(M=getRandInt(0,360),AxiRotMat(M,Ab[1],Ab[2],Ab[3]),vb=[0,db[Y+xb],eb[Y+xb],fb[Y+xb]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),db[Y+xb]=vb[1],eb[Y+xb]=vb[2],fb[Y+xb]=vb[3]),idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1)}for(Pb=0;Pb<Math.ceil(pb*w)&&wb.length>0;){for(idx=getRandInt(0,wb.length-1),a=wb[idx],wb[idx]=-1,Ab=[0,db[lb[a][1]]-db[a],eb[lb[a][1]]-eb[a],fb[lb[a][1]]-fb[a]],lb[a].length>2&&(Ab[1]+=db[lb[a][2]]-db[a],Ab[2]+=eb[lb[a][2]]-eb[a],Ab[3]+=fb[lb[a][2]]-fb[a]),ub=-1/Math.sqrt(Ab[1]*Ab[1]+Ab[2]*Ab[2]+Ab[3]*Ab[3]),Ab[1]*=ub,Ab[2]*=ub,Ab[3]*=ub,AxiRotMat(180,Ab[1],Ab[2],Ab[3]+1),Pb++,b=1;4>=b;b++)xb++,vb=[0,db[a]+Jb[b],eb[a]+Kb[b],fb[a]+Lb[b]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),gb[Y+xb]=Ib[b],db[Y+xb]=vb[1],eb[Y+xb]=vb[2],fb[Y+xb]=vb[3];if(x)for(M=getRandInt(0,360),AxiRotMat(M,Ab[1],Ab[2],Ab[3]),b=0;4>b;b++)vb=[0,db[Y+xb-b],eb[Y+xb-b],fb[Y+xb-b]],RotVect(RotMat,vb,db[a],eb[a],fb[a]),db[Y+xb-b]=vb[1],eb[Y+xb-b]=vb[2],fb[Y+xb-b]=vb[3];for(idx=wb.indexOf(-1);-1!=idx;)wb.splice(idx,1),idx=wb.indexOf(-1)}for(Qb="MOL: "+f+" "+g+" Rcc="+printf("%5.3f",h)+" Rhole="+printf("%5.3f",i)+" Center: "+K+printf("%12.6f",W)+printf("%12.6f",X)+"\n"+(Z+xb)+"\n",Fcif="data_GRA\n"+Z+xb+"\n_symmetry_space_group_name_' '"+"\n_cell_length_a "+U+"\n_cell_length_b "+V+"\n_cell_length_c "+10*h+"\n_cell_angle_alpha 90\n_cell_angle_beta 90\n_cell_angle_gamma 90"+"\nloop_\n_atom_site_label\n_atom_site_type_symbol\n_atom_site_fract_x\n_atom_site_fract_y\n_atom_site_fract_z\n",b=0,a=1;Y+xb>=a;a++)(ab[a]||a>Y)&&(b++,z&&(db[a]+=normRand(0,z)),B&&(eb[a]+=normRand(0,B)),D&&(fb[a]+=normRand(0,D)),Qb+=printf(" 1MOL%7s%5f%8.3f%8.3f%8.3f\n",gb[a],b,.1*db[a],.1*eb[a],.1*(G+fb[a])),Fcif+=printf("GRA %s %8.3f%8.3f%8.3f\n",gb[a],db[a]/U,eb[a]/V,.1*fb[a]/h));for(Qb+=printf("%12.6f %12.6f %12.6f\n",.1*f*Q,.1*g*R,.1*2*h),i>.5&&(Fcif+=printf("GRA O %8.3f%8.3f 0.\n",W/U,X/V)),$("groCoor").value=Qb,cell=ChemDoodle.readCIF(Fcif,1,1,1),a=0;a<cell.molecule.atoms.length-1;a++)cell.molecule.atoms[a].altLabel=a+1;Mol1.loadContent([cell.molecule],[cell.unitCell]),Mol1.startAnimation()}function isInPolygon(a,b){var d,e,g,c=0,h=b.length,f=b[0];for(d=1;h>=d;d++)g=b[d%h],a[0]>Math.min(f[0],g[0])&&a[0]<=Math.max(f[0],g[0])&&a[1]<=Math.max(f[1],g[1])&&f[0]!=g[0]&&(e=f[1]+(a[0]-f[0])*(g[1]-f[1])/(g[0]-f[0]),(f[1]==g[1]||a[1]<=e)&&c++),f=g;return 0==c%2?!1:!0}function sarc(a,b,c){for(var d,e,f,g=[],h=[],i=0,j=0,k=1e99,l=2;k>c;){for(i=j,j=0,l*=2,f=(b-a)/l,d=0;l>d;d++)e=a+d*f,Ft(e,g),Ft(e+f,h),h[0]-=g[0],h[1]-=g[1],h[2]-=g[2],j+=Math.sqrt(h[0]*h[0]+h[1]*h[1]+h[2]*h[2]);k=j-i}return j}function tarc(a,b,c,d,e){var f,g,h;for(h=sarc(c,d,e),a-=sarc(b,c,e),f=c+a*(d-c)/h,g=sarc(c,f,e);Math.abs(a-g)>e;)a>g?(c=f,a-=g,h-=g):(d=f,h=g),f=c+a*(d-c)/h,g=sarc(c,f,e);return f}function dot(a,b){return a[1]*b[1]+a[2]*b[2]+a[3]*b[3]}function cross(a,b,c){c[1]=a[2]*b[3]-a[3]*b[2],c[2]=a[3]*b[1]-a[1]*b[3],c[3]=a[1]*b[2]-a[2]*b[1]}function ang(a,b,c,d,e,f,g,h,i,j){var m,k=[],l=[];return k[1]=a-d,l[1]=g-d,k[2]=b-e,l[2]=h-e,k[3]=c-f,l[3]=i-f,cross(k,l,j),m=j[1]*j[1]+j[2]*j[2]+j[3]*j[3],m>0&&1!=m&&(m=1/Math.sqrt(m),j[1]*=m,j[2]*=m,j[3]*=m),Math.acos(dot(k,l)/Math.sqrt(dot(k,k)*dot(l,l)))*r2d}function RotVect(a,b,c,d,e){var f=b[1]-c,g=b[2]-d,h=b[3]-e;b[1]=a[1][1]*f+a[1][2]*g+a[1][3]*h+c,b[2]=a[2][1]*f+a[2][2]*g+a[2][3]*h+d,b[3]=a[3][1]*f+a[3][2]*g+a[3][3]*h+e}function AxiRotMat(a,b,c,d){var e=b*b+c*c+d*d;e>0&&1!=e&&(e=1/Math.sqrt(e),b*=e,c*=e,d*=e),a*=d2r,e=Math.sin(a/2),w=Math.cos(a/2),b*=e,c*=e,d*=e,RotMat[1][1]=1-2*(c*c+d*d),RotMat[1][2]=2*(b*c-w*d),RotMat[1][3]=2*(b*d+w*c),RotMat[2][1]=2*(b*c+w*d),RotMat[2][2]=1-2*(b*b+d*d),RotMat[2][3]=2*(c*d-w*b),RotMat[3][1]=2*(b*d-w*c),RotMat[3][2]=2*(c*d+w*b),RotMat[3][3]=1-2*(b*b+c*c)}function printf(){var a={s:function(a,b){return b*=1,m=Array(Math.max(Math.abs(b)-a.length+1,0)).join(" "),b>0?m+a:a+m},f:function(a,b){return b=b.split("."),a=parseFloat(a).toFixed(b[1]),m=Array(Math.max(Math.abs(b[0])-a.length+1,0)).join(" "),b[0]>0?m+a:a+m}},b=Array.prototype.slice.call(arguments).slice();return b.shift().toString().replace(/%(-*\d*\.*\d*)([sf])/g,function(c,d,e){if(!b.length)throw new Error("Too few elements");return a[e](b.shift(),d)})}function getRandInt(a,b){return a=Math.ceil(a),b=Math.floor(b),Math.floor(Math.random()*(b-a+1))+a}function normRand(a,b){var c=0,d=0,e=0,f=0;do c=2*Math.random()-1,d=2*Math.random()-1,e=c*c+d*d;while(0==e||e>=1);return f=Math.sqrt(-2*Math.log(e)/e),a+c*f*b}function getIdx(a,b,c,d,e,f){if(f)0==c&&(c=a),c>a&&(c=1),0==d&&(d=b),d>b&&(d=1);else if(1>c||c>a||1>d||d>b)return 0;return 4*(a*(d-1)+c-1)+e}function pbcCart(a,b){return a>.5*b?a-=b:-.5*b>a&&(a+=b),a}var Ft,dFt,vFt,d2r=Math.atan2(1,1)/45,r2d=1/d2r,$=function(a){return document.getElementById(a)},isFt=!1,isdFt=!1,RotMat=[[0,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];
</script>