/* trial pseudocharge <-- Z,Zv,R+,R-,dx */ /* external charge density - real space DFT-LDA */ /* LDA: J. P. Perdew and A. Zunger; Phys. Rev., B23, 5048 (1981) */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2005.01.12 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class trialPseudochageECD extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Choice ch_atom,ch_noe,cvw, ch_md; Button bt_reset, bt_start, bt_stop; Scrollbar sc_hh,sc_mixing,sc_broadening,sc_atn,sc_rp,sc_rm; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 30; int dispMode = 3; int dispObj = 0; double mixing = 0.05; double broadening = 0.005; double SDdump = 0.05; double rrPositive = 2.0; double rrNegative = 2.3; int iterCount = 0; int started = 1; double NOE = 2.5; double Zv = 3.0; double Znuclear = 13.0; int Norbit = 8; 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 = 0.5; double dy = 0.5; double dz = 0.5; double dt = 1.0*(dx*dx); int NNx = 32+1; int NNy = 32+1; int NNz = 32+1; int NN = NNx+1; /* max(NNx,NNy,NNz)+1 */ double vv[][][] = new double[NNx][NNy][NNz]; double vvext[][][] = new double[NNx][NNy][NNz]; double vvh[][][] = new double[NNx][NNy][NNz]; double vvx[][][] = new double[NNx][NNy][NNz]; double vvc[][][] = new double[NNx][NNy][NNz]; double rhoExt[][][] = new double[NNx][NNy][NNz]; double rho[][][] = new double[NNx][NNy][NNz]; int NNs = 12; double sdEnergy[] = new double[NNs]; double sdState[][][][] = new double[NNs][NNx][NNy][NNz]; double occ[] = new double[NNs]; 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("1");ch_atom.addItem("2");ch_atom.addItem("3"); ch_atom.addItem("4");ch_atom.addItem("5");ch_atom.addItem("6"); ch_atom.addItem("7"); ch_atom.addItemListener(this); ch_atom.select("3"); ch_noe = new Choice(); ch_noe.addItem("ne=Zv-1");ch_noe.addItem("ne=Zv-0.5"); ch_noe.addItem("ne=Zv");ch_noe.addItem("ne=Zv+0.5");ch_noe.addItem("ne=Zv+1"); ch_noe.addItemListener(this); ch_noe.select("ne=Zv-0.5"); 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.addItemListener(this); cvw.select("ph-0"); 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("Vx"); ch_md.addItem("Vc"); ch_md.addItem("Veff"); ch_md.addItem("rho"); ch_md.addItem("rho 3D");ch_md.addItem("rho+charge"); ch_md.addItemListener(this); ch_md.select("Vext"); 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_hh= new Scrollbar(Scrollbar.HORIZONTAL,50,10,25,110); sc_hh.addAdjustmentListener(this); sc_mixing= new Scrollbar(Scrollbar.HORIZONTAL,5,10,1,100); sc_mixing.addAdjustmentListener(this); sc_broadening= new Scrollbar(Scrollbar.HORIZONTAL,5,10,1,110); sc_broadening.addAdjustmentListener(this); sc_atn= new Scrollbar(Scrollbar.HORIZONTAL,13,10,1,100); sc_atn.addAdjustmentListener(this); sc_rp= new Scrollbar(Scrollbar.HORIZONTAL,200,10,1,510); sc_rp.addAdjustmentListener(this); sc_rm= new Scrollbar(Scrollbar.HORIZONTAL,230,10,1,510); sc_rm.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_noe); pnl.add(sc_mixing); pnl.add(sc_broadening); pnl.add(cvw); pnl.add(ch_md); add(pnl,"North"); Panel pnl2 = new Panel(); pnl2.setLayout(new GridLayout(1,6,5,0)); pnl2.add(sc_atn); pnl2.add(sc_rp); pnl2.add(sc_rm); pnl2.add(sc_hh); pnl2.add(new Label(" ")); pnl2.add(new Label(" ")); add(pnl2,"South"); 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){ Zv = 1.0 + ch_atom.getSelectedIndex(); ch_noe.select("ne=Zv-0.5"); NOE = Zv-0.5; iterCount = 0; setVhQ = 0; setPotential(); } else if (ev.getSource() == ch_noe){ NOE = Zv - 1.0 + 0.5*ch_noe.getSelectedIndex(); /* iterCount = 0; setVhQ = 0; setPotential(); */ } else if (ev.getSource() == cvw){ dispObj = cvw.getSelectedIndex(); } else if (ev.getSource() == ch_md){ dispMode = ch_md.getSelectedIndex(); } } 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_hh) { dx = 0.01*sc_hh.getValue(); dy = dx; dz = dx; SDdump = 0.2*dx*dx; setWIon(16.0*dx, 16.0*dy, 16.0*dz); } else if (ev.getSource() == sc_broadening) { broadening = 0.001*sc_broadening.getValue(); } else if (ev.getSource() == sc_mixing) { mixing = 0.01*(double)(sc_mixing.getValue()); } else if (ev.getSource() == sc_atn) { Znuclear = 1.0*(double)(sc_atn.getValue()); iterCount = 0; setVhQ = 0; setInitialCondition(); } else if (ev.getSource() == sc_rp) { rrPositive = 0.01*(double)(sc_rp.getValue()); setWIon(16.0*dx, 16.0*dy, 16.0*dz); } else if (ev.getSource() == sc_rm) { rrNegative = 0.01*(double)(sc_rm.getValue()); setWIon(16.0*dx, 16.0*dy, 16.0*dz); } } 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 = 500.0; if (dispMode==0 || dispMode==1) { boxPlot(); dens3DPlotSD(dens,dispMode,dispObj); boxPlot2(); } else if (dispMode==2) { gridFnPlot(sdState[dispObj], NNz/2, 50.0); } else if (dispMode==3) { gridFnPlot(vvext, NNz/2, 5.0); } else if (dispMode==4) { gridFnPlot(vvh, NNz/2, 5.0); } else if (dispMode==5) { gridFnPlot(vvx, NNz/2, 5.0); } else if (dispMode==6) { gridFnPlot(vvc, NNz/2, 5.0); } else if (dispMode==7) { gridFnPlot(vv, NNz/2, 5.0); } else if (dispMode==8) { gridFnPlot(rho, NNz/2, 50.0); } else if (dispMode==9) { boxPlot(); rho3DPlot(200.0); boxPlot2(); } else if (dispMode==10) { boxPlot(); charge3DPlot(200.0); boxPlot2(); } gOff.setColor(Color.black); gOff.drawString("Zv="+(int)(Zv+0.5)+" ",630/6*0+10,40); gOff.drawString("ne="+(int)(NOE*10+0.5)/10.0+" ",630/6*1+20,40); gOff.drawString("mix="+(int)(mixing*100.0+0.5)/100.0+" ",630/6*2+20,40); gOff.drawString("kT0="+(int)(broadening*1000+0.5)/1000.0+" ",630/6*3+20,40); gOff.drawString("orbit",630/6*4+10,40); gOff.drawString("view",630/6*5+20,40); gOff.setColor(Color.black); gOff.drawString("Z="+(int)(Znuclear+0.5)+" ",630/6*0+10,330); gOff.drawString("R+="+(int)(rrPositive*100.0+0.5)/100.0+" ",630/6*1+20,330); gOff.drawString("R-="+(int)(rrNegative*100.0+0.5)/100.0+" ",630/6*2+20,330); gOff.drawString("dx="+(int)(dx*100.0+0.5)/100.0+" au, dump="+(int)(SDdump*1000.0+0.5)/1000.0+" ",630/6*3+20,330); gb = 360; gOff.setColor(Color.black); gOff.drawString("kT="+(float)(levelWidth())+" au",gb,60); gOff.drawString("iteration="+iterCount+" ",gb+150,60); gOff.drawString("box="+(int)(NNx*dx)+"x"+ +(int)(NNy*dy)+"x"+(int)(NNz*dz)+" au",gb,80); gOff.drawString("dx="+(int)(dx*100.0)/100.0+" au",gb+150,80); gOff.setColor(Color.black); gOff.drawString("No.",gb,160); gOff.drawString("occupation",gb+30,160); gOff.drawString("energy",gb+150,160); 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 charge3DPlot(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 = 6.0; cxx = mag*(NNx/2.0); cyy = mag*(NNy/2.0); czz = mag*(NNz/2.0); for (i=1; i2) ir = 2; 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; if (ir>0) { gOff.setColor(Color.getHSBColor(0.6f, 0.9f,0.9f)); gOff.fillOval(ix-ir/2,iy-ir/2,ir,ir); } if (rhoExt[i][j][k]<0.0) { ir = 3; gOff.setColor(Color.getHSBColor(0.01f, 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 = 6.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[istate][i][j][k]>=0) { col = 0.33; } else { col = 0.01; } } gOff.setColor(Color.getHSBColor((float)col, (float)(0.3+0.3*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 = 8.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) { for (i=1;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); ec = -0.1423/(1.0+1.0529*sqrtrs+0.3334*rs); vvc[i][j][k] = ec*(1.0+1.22838*sqrtrs+0.4445*rs)/(1.0+1.0529*sqrtrs+0.3334*rs); } else { vvc[i][j][k] = -0.05837-0.0084*rs +(0.0311+0.00133*rs)*Math.log(rs); } } } } } double eeCorrelation(double rh) { double r,ec; r = 0.6204/(Math.pow(rh,0.33333333)+1.0e-20); if (r>=1.0) { ec = -0.1423/(1.0+1.0529*Math.sqrt(r)+0.3334*r); } else { ec = -0.0480-0.0116*r+(0.0311+0.0020*r)*Math.log(r); } return ( ec ); } /* ----------------- Gram-Schmidt --------- */ void GramSchmidt(int stateMax) { int i,j,k,ist,istate; double s; normalize(sdState[0]); for (istate=1; istate