/* dimer - real space DFT-LSD */ /* LSD Vxc: J.P. Perdew, A. Zunger; Phys. Rev. B 23 5048 (1981) */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2004.12.04 */ /* ver 0.0.2 2004.12.05 bug ( in setVxc() ) fixed */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class dimerLSDPZ extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Choice ch_atom, ch_atom2, cvw, ch_md, ch_noe; Button bt_reset, bt_start, bt_stop; Scrollbar sc_dist,sc_mixing,sc_broadening; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 30; int dispMode = 1; int dispObj = 13; double ppDistance = 3.0; double mixing = 0.2; double broadening = 0.001; int iterCount = 0; int started = 1; double NOE = 14.0; double Znuc = 14.0; int Norbit = 20; int setVhQ = 0; int dgX, dgY, dgXb,dgYb; double viewTheta = -15.0*3.14/180.0; double viewFai = -72.0*3.14/180.0; double dtheta = 0.0*3.14/180.0; double pai = 3.1415926536; double cosTh = Math.cos(viewTheta); double sinTh = Math.sin(viewTheta); double cosFi = Math.cos(viewFai); double sinFi = Math.sin(viewFai); double t = 0.0; double dx = 1.0/4.0; double dy = 1.0/4.0; double dz = 1.0/4.0; double dt = 1.0*(dx*dx); int NNx = 64+1; int NNy = 64+1; int NNz = 64+1; int NN = NNx+1; /* max(NNx,NNy,NNz)+1 */ int NNs = 12; double vvUp[][][] = new double[NNx][NNy][NNz]; double vvDown[][][] = new double[NNx][NNy][NNz]; double vvext[][][] = new double[NNx][NNy][NNz]; double vvh[][][] = new double[NNx][NNy][NNz]; double vvxcUp[][][] = new double[NNx][NNy][NNz]; double vvxcDown[][][] = new double[NNx][NNy][NNz]; double rhoUp[][][] = new double[NNx][NNy][NNz]; double rhoDown[][][] = new double[NNx][NNy][NNz]; int psis[][] = new int[Norbit][2]; double sdEnergy[] = new double[Norbit]; double sdState[][][][] = new double[NNs][NNx][NNy][NNz]; double occ[] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; double nuc[][] = { { 6.0, 8.0-2.0 , 8.0 , 8.0 }, { 8.0, 8.0+1.0 , 8.0 , 8.0 }, { 0.0, 0.0 , 0.0 , 0.0 } }; int pxBox[] = new int[8]; int pyBox[] = new int[8]; int boxp[][] = { {0,1},{0,2},{0,4},{1,3},{1,5},{2,3},{2,6},{4,5},{4,6},{3,7},{5,7},{6,7} }; int xpts[] = new int[NN]; int ypts[] = new int[NN]; /* ----------------------------- applet control ------ */ public void init() { resize(630,360); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); ch_atom = new Choice(); ch_atom.addItem("H");ch_atom.addItem("He"); ch_atom.addItem("Li");ch_atom.addItem("Be"); ch_atom.addItem("B");ch_atom.addItem("C"); ch_atom.addItem("N");ch_atom.addItem("O"); ch_atom.addItem("F");ch_atom.addItem("Ne"); ch_atom.addItemListener(this); ch_atom.select("C"); ch_atom2 = new Choice(); ch_atom2.addItem("H");ch_atom2.addItem("He"); ch_atom2.addItem("Li");ch_atom2.addItem("Be"); ch_atom2.addItem("B");ch_atom2.addItem("C"); ch_atom2.addItem("N");ch_atom2.addItem("O"); ch_atom2.addItem("F");ch_atom2.addItem("Ne"); ch_atom2.addItemListener(this); ch_atom2.select("O"); cvw = new Choice(); cvw.addItem("ph-0");cvw.addItem("ph-1");cvw.addItem("ph-2"); cvw.addItem("ph-3");cvw.addItem("ph-4");cvw.addItem("ph-5"); cvw.addItem("ph-6");cvw.addItem("ph-7");cvw.addItem("ph-8"); cvw.addItem("ph-9");cvw.addItem("ph-10");cvw.addItem("ph-11"); cvw.addItem("ph-12");cvw.addItem("ph-13");cvw.addItem("ph-14"); cvw.addItem("ph-15");cvw.addItem("ph-16");cvw.addItem("ph-17"); cvw.addItem("ph-18");cvw.addItem("ph-19"); cvw.addItemListener(this); cvw.select("ph-13"); ch_md = new Choice(); ch_md.addItem("density");ch_md.addItem("phase");ch_md.addItem("ph-grid"); ch_md.addItem("Vext"); ch_md.addItem("VH"); ch_md.addItem("VxcUp");ch_md.addItem("VxcDown"); ch_md.addItem("VeffUp");ch_md.addItem("VeffDown"); ch_md.addItem("rhoUp");ch_md.addItem("rhoDown"); ch_md.addItem("rho 3D");ch_md.addItem("rho+nuc"); ch_md.addItemListener(this); ch_md.select("phase"); ch_noe = new Choice(); ch_noe.addItem("ne=Z-1");ch_noe.addItem("ne=Z-0.5"); ch_noe.addItem("ne=Z");ch_noe.addItem("ne=Z+0.5");ch_noe.addItem("ne=Z+1"); ch_noe.addItemListener(this); ch_noe.select("ne=Z"); bt_reset= new Button("reset"); bt_reset.addActionListener(this); bt_start= new Button("start"); bt_start.addActionListener(this); bt_stop = new Button("stop"); bt_stop.addActionListener(this); sc_dist= new Scrollbar(Scrollbar.HORIZONTAL,12,10,4,40); sc_dist.addAdjustmentListener(this); sc_mixing= new Scrollbar(Scrollbar.HORIZONTAL,20,10,1,100); sc_mixing.addAdjustmentListener(this); sc_broadening= new Scrollbar(Scrollbar.HORIZONTAL,1,10,1,110); sc_broadening.addAdjustmentListener(this); addMouseListener(this); addMouseMotionListener(this); setLayout(new BorderLayout()); Panel pnl = new Panel(); pnl.setLayout(new GridLayout(1,6,5,0)); pnl.add(ch_atom); pnl.add(ch_atom2); pnl.add(sc_dist); pnl.add(sc_broadening); /* pnl.add(new Label(" ")); */ pnl.add(cvw); pnl.add(ch_md); add(pnl,"North"); setInitialCondition(); } public void start() { if (th == null) { th = new Thread(this); th.start(); } } public void stop() { if (th != null) { th.stop(); th = null; } } public void itemStateChanged(ItemEvent ev){ if (ev.getSource() == ch_atom){ nuc[0][0] = 1.0 + ch_atom.getSelectedIndex(); Znuc = nuc[0][0]+nuc[1][0]; NOE = Znuc; iterCount = 0; setVhQ = 0; setPotential(); offPaint(); repaint(); } else if (ev.getSource() == ch_atom2){ nuc[1][0] = 1.0 + ch_atom2.getSelectedIndex(); Znuc = nuc[0][0]+nuc[1][0]; NOE = Znuc; iterCount = 0; setVhQ = 0; setPotential(); offPaint(); repaint(); } else if (ev.getSource() == ch_noe){ NOE = Znuc - 1.0 + 0.5*ch_noe.getSelectedIndex(); nuc[0][0] = Znuc; iterCount = 0; setVhQ = 0; setPotential(); offPaint(); repaint(); } else if (ev.getSource() == cvw){ dispObj = cvw.getSelectedIndex(); offPaint(); repaint(); } else if (ev.getSource() == ch_md){ dispMode = ch_md.getSelectedIndex(); offPaint(); repaint(); } } public void actionPerformed(ActionEvent ev){ if(ev.getSource() == bt_reset){ started = -1; } else if(ev.getSource() == bt_start){ started = 1; } else if(ev.getSource() == bt_stop){ started = 0; } } public void adjustmentValueChanged(AdjustmentEvent ev){ if (ev.getSource() == sc_dist) { ppDistance = 0.25*sc_dist.getValue(); nuc[1][1] = nuc[0][1]+ppDistance; iterCount = 0; setPotential(); } else if (ev.getSource() == sc_broadening) { broadening = 0.001*sc_broadening.getValue(); setPotential(); } else if (ev.getSource() == sc_mixing) { mixing = 0.01*(double)(sc_mixing.getValue()); } } public void mousePressed(MouseEvent ev){ } public void mouseReleased(MouseEvent ev){ dgXb = 0; dgYb = 0; dgX = 0; dgY = 0; } public void mouseClicked(MouseEvent ev){ } public void mouseEntered(MouseEvent ev){ } public void mouseExited (MouseEvent ev){ } public void mouseMoved (MouseEvent ev){ } public void mouseDragged(MouseEvent ev){ dgXb = dgX; dgYb = dgY; dgX=ev.getX(); dgY=ev.getY(); if (dgXb==0 && dgYb==0) { dgXb = dgX; dgYb = dgY; } viewTheta += 0.5*3.14/180.0*(dgX-dgXb); viewFai += 0.5*3.14/180.0*(dgY-dgYb); cosTh = Math.cos(viewTheta); sinTh = Math.sin(viewTheta); cosFi = Math.cos(viewFai); sinFi = Math.sin(viewFai); } public void run() { while (th != null) { try { timeEvolution(); offPaint(); repaint(); Thread.sleep(sleepTime); } catch (InterruptedException e) { } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(imgOff,0,0,this); } /* ----------------------------- offPaint -------------------- */ void offPaint() { int i,gb; double ev,ek; double dens; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); dens = 800.0; if (dispMode==0 || dispMode==1) { boxPlot(); dens3DPlotSD(dens,dispMode,dispObj); boxPlot2(); } else if (dispMode==2) { gridFnPlot(sdState[psis[dispObj][0]], NNz/2, 20.0); } else if (dispMode==3) { gridFnPlot(vvext, NNz/2, 2.0); } else if (dispMode==4) { gridFnPlot(vvh, NNz/2, 2.0); } else if (dispMode==5) { gridFnPlot(vvxcUp, NNz/2, 2.0); } else if (dispMode==6) { gridFnPlot(vvxcDown, NNz/2, 2.0); } else if (dispMode==7) { gridFnPlot(vvUp, NNz/2, 2.0); } else if (dispMode==8) { gridFnPlot(vvDown, NNz/2, 2.0); } else if (dispMode==9) { gridFnPlot(rhoUp, NNz/2, 2.0); } else if (dispMode==10) { gridFnPlot(rhoDown, NNz/2, 2.0); } else if (dispMode==11) { boxPlot(); rho3DPlot(20.0); boxPlot2(); } else if (dispMode==12) { boxPlot(); nuc3DPlot(20.0); boxPlot2(); } gOff.setColor(Color.black); gOff.drawString("atom R0 ",630/6*0+10,40); gOff.drawString("atom R1 ",630/6*1+10,40); gOff.drawString("|R0-R1|="+(int)(ppDistance*100.0+0.5)/100.0+" ",630/6*2+10,40); gOff.drawString("kT0="+(int)(broadening*1000+0.5)/1000.0+" ",630/6*3+20,40); gOff.drawString("orbit,spin"+psis[dispObj][1]+"/2",630/6*4+10,40); gOff.drawString("view",630/6*5+20,40); gb = 340; gOff.setColor(Color.black); gOff.drawString("kT="+(float)(levelWidth())+" au",gb,60); gOff.drawString("iteration="+iterCount+" ",gb+150,60); gOff.drawString("total energy="+(float)totalEnergy()+" au",gb,80); gOff.setColor(Color.black); gOff.drawString("No. spin occupation",gb,100); gOff.drawString("energy",gb+180,100); for (i=0; i0) { if (ir>10) { ir = 10; } z = k*mag; ppy = cosFi*(j*mag-cyy)+sinFi*(z-czz) + cyy; ppz = -sinFi*(j*mag-cyy)+cosFi*(z-czz) + czz; ppx = cosTh*(i*mag-cxx)+sinTh*(ppz-czz) + cxx; ppz = -sinTh*(i*mag-cxx)+cosTh*(ppz-czz) + czz; ix = (int)(ppx)+gbx; iy = (int)(ppy)+gby; gOff.setColor(Color.getHSBColor((float)(0.66-0.66*dens), 0.9f,0.9f)); gOff.fillOval(ix-ir/2,iy-ir/2,ir,ir); } } } } } void nuc3DPlot(double weight) { int i,j,k,ix,iy,ir,inuc; int gbx,gby; double cxx,cyy,czz; double z,ppx,ppy,ppz; double mag,dens,col; gbx = 60; gby = 80; mag = 3.0; cxx = mag*(NNx/2.0); cyy = mag*(NNy/2.0); czz = mag*(NNz/2.0); for (inuc=0; inuc<20; inuc++) { if (nuc[inuc][0]<=0.0) break; ir = (int)(nuc[inuc][0]+5); i = (int)(nuc[inuc][1]/dx); j = (int)(nuc[inuc][2]/dy); k = (int)(nuc[inuc][3]/dz); z = k*mag; ppy = cosFi*(j*mag-cyy)+sinFi*(z-czz) + cyy; ppz = -sinFi*(j*mag-cyy)+cosFi*(z-czz) + czz; ppx = cosTh*(i*mag-cxx)+sinTh*(ppz-czz) + cxx; ppz = -sinTh*(i*mag-cxx)+cosTh*(ppz-czz) + czz; ix = (int)(ppx)+gbx; iy = (int)(ppy)+gby; gOff.setColor(Color.getHSBColor(0.01f, 0.9f,0.9f)); gOff.fillOval(ix-ir/2,iy-ir/2,ir,ir); } for (i=1; i0) { if (ir>1) { ir = 1; } z = k*mag; ppy = cosFi*(j*mag-cyy)+sinFi*(z-czz) + cyy; ppz = -sinFi*(j*mag-cyy)+cosFi*(z-czz) + czz; ppx = cosTh*(i*mag-cxx)+sinTh*(ppz-czz) + cxx; ppz = -sinTh*(i*mag-cxx)+cosTh*(ppz-czz) + czz; ix = (int)(ppx)+gbx; iy = (int)(ppy)+gby; gOff.setColor(Color.getHSBColor(0.6f, 0.9f,0.9f)); gOff.fillOval(ix-ir/2,iy-ir/2,ir,ir); } } } } } void dens3DPlotSD(double weight,int mode, int istate) { int i,j,k,ix,iy,ir; int gbx,gby; double cxx,cyy,czz; double z,ppx,ppy,ppz; double mag,dens,col; gbx = 60; gby = 80; mag = 3.0; cxx = mag*(NNx/2.0); cyy = mag*(NNy/2.0); czz = mag*(NNz/2.0); for (i=1; i0) { if (ir>10) { ir = 10; } z = k*mag; ppy = cosFi*(j*mag-cyy)+sinFi*(z-czz) + cyy; ppz = -sinFi*(j*mag-cyy)+cosFi*(z-czz) + czz; ppx = cosTh*(i*mag-cxx)+sinTh*(ppz-czz) + cxx; ppz = -sinTh*(i*mag-cxx)+cosTh*(ppz-czz) + czz; ix = (int)(ppx)+gbx; iy = (int)(ppy)+gby; col = 0.0; if (mode==0) { col = 0.66 -0.05*dens; if (col<0.0) { col = 0.0; } } else if (mode==1) { if (sdState[psis[istate][0]][i][j][k]>=0) { col = 0.33; } else { col = 0.01; } } gOff.setColor(Color.getHSBColor((float)col, (float)(0.3+0.6*occ[istate]),0.9f)); gOff.fillOval(ix-ir/2,iy-ir/2,ir,ir); } } } } } void gridFnPlot(double fn[][][], int zPos, double weight) { int i,j,k,gbx,gby; int cx,cy,cz; double z,px,py,pz,sc; double ph2; cx = NNx/2; cy = NNy/2; cz = 0; sc = 4.0; gbx = 30+(int)(cx/sc); gby = 20+(int)(cy/sc); k = zPos; for(j=0; j=0; ist--) { if (sdEnergy[ist]>sdEnergy[ist+1]+0.0001) { iw = psis[ist][0]; psis[ist][0]=psis[ist+1][0]; psis[ist+1][0]=iw; iw = psis[ist][1]; psis[ist][1]=psis[ist+1][1]; psis[ist+1][1]=iw; w = sdEnergy[ist]; sdEnergy[ist]=sdEnergy[ist+1];sdEnergy[ist+1]=w; } } } /* ----------------------------- occupation --------------------- */ void setOcc(int maxState, double nElectron) { int i; double eUpper,eLower,eFermi,ntrial; eUpper = sdEnergy[maxState-1]+1.0; eLower = sdEnergy[0]-1.0; for (i=0;ieUpper) eUpper = sdEnergy[i]; if(sdEnergy[i]1.0e-12) { eFermi = (eUpper+eLower)/2.0; ntrial = trialOcc(maxState, eFermi); if (ntrial=1.0) { sqrtrs = Math.sqrt(rs); eecp = -0.1423/(1.0+1.0529*sqrtrs+0.3334*rs); eecf = -0.0843/(1.0+1.3981*sqrtrs+0.2611*rs); } else { lnrs = Math.log(rs); eecp = 0.0311*lnrs-0.048+0.002*rs*lnrs-0.0116*rs; eecf = 0.01555*lnrs-0.0269+0.0007*rs*lnrs-0.0048*rs; } excp = eexp+eecp; excf = eexf+eecf; fz = (Math.pow(1+zz,1.33333333)+Math.pow(1-zz,1.33333333)-2.0)/0.519842; return ( excp+(excf-excp)*fz ); } /* ----------------- Gram-Schmidt --------- */ void GramSchmidt(int stateMax) { int i,j,k,ist,istate; double s; normalize(sdState[0]); for (istate=1; istate