/* applet No. 967 * * hcp crystal - table function - tight-binding potential * * Created by Ikeuchi Mitsuru on July 02 2006. * Copyright (c) 2006 Ikeuchi Mitsuru. All rights reserved. * * ver 0.0.1 2006.07.02 created * */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class hcpTableTBP extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { /*-------------------------------------- define gloval -----*/ Choice ch_tempMode,ch_mat,ch_mat2,ch_view; Button bt_reset, bt_startStop; Scrollbar sc_temp,sc_scale; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 50; double xMax = 6.4*1.0e-9; double yMax = 6.4*1.0e-9; double zMax = 6.4*1.0e-9; int resetSW = 0; int started = 1; int tempMode = 1; double contTemp = 300.0; int dispMode = 0; int MAT1 = 26; int MAT2 = 18; double dispWidth = 250.0; double dispScale = (dispWidth/xMax); double viewScale = 1.0; int Nmt = 10000; int NN = Nmt + 1; double t = 0.0; double dt = 1.0*1.0e-15; int Nsx = 16; int Nsy = 16; int Nsz = 16; int dgX, dgY, dgXb, dgYb; double cx = 0.5*xMax; double cy = 0.5*yMax; double cz = 0.5*zMax; double theta = -20.0*3.14/180.0; double fai = 10.0*3.14/180.0; double dtheta = 0.0*3.14/180.0; double pai = 3.1415926536; double AU = 1.661e-27; double TB[][] = { /* atom 0 mass 1 A(eV) 2 x(eV) 3 p 4 q 5 r0(A) 6 G/xx 7 color 8 f/bcc */ /* 0 Al*/ { 26.98*AU, 0.1602, 1.5074, 7.5681, 2.7456, 2.8634, 3.552, 0.26, 0.0 }, /* 1 Ca*/ { 40.08*AU, 0.0492, 0.6842, 11.2115, 2.6841, 3.9471, 3.557, 0.20, 0.0 }, /* 2 Ni*/ { 58.71*AU, 0.0565, 1.4005, 14.0867, 1.7937, 2.4918, 3.655, 0.39, 0.0 }, /* 3 Cu*/ { 63.54*AU, 0.0783, 1.2355, 11.1832, 2.3197, 2.5560, 3.589, 0.42, 0.0 }, /* 4 Sr*/ { 87.62*AU, 0.0257, 0.5557, 12.3406, 1.8105, 4.3027, 3.652, 0.17, 0.0 }, /* 5 Rh*/ {102.91*AU, 0.1086, 1.9776, 14.1315, 2.5555, 2.6901, 3.567, 0.60, 0.0 }, /* 6 Pd*/ {106.40*AU, 0.1223, 1.5193, 11.3225, 3.0697, 2.7511, 3.532, 0.63, 0.0 }, /* 7 Ag*/ {107.87*AU, 0.0812, 1.1081, 11.5597, 2.8316, 2.8890, 3.546, 0.66, 0.0 }, /* 8 Ir*/ {192.20*AU, 0.2141, 2.7082, 12.8986, 3.4541, 2.7145, 3.513, 0.70, 0.0 }, /* 9 Pt*/ {195.09*AU, 0.2906, 2.6715, 10.1423, 3.7878, 2.7746, 3.501, 0.73, 0.0 }, /*10 Au*/ {196.97*AU, 0.1935, 1.7581, 10.4342, 3.9472, 2.8838, 3.497, 0.76, 0.0 }, /*11 Pb*/ {207.19*AU, 0.0851, 0.8699, 10.0667, 3.3563, 3.5003, 3.517, 0.79, 0.0 }, /*12 Th*/ {232.04*AU, 0.1200, 2.0937, 9.8344, 1.7972, 3.5951, 3.560, 0.82, 0.0 }, /*13 Li*/ { 6.94*AU, 0.0488, 0.5729, 6.3675, 1.3969, 3.0391, 3.734, 0.11, 1.0 }, /*14 Na*/ { 22.99*AU, 0.0353, 0.4083, 7.8536, 1.7477, 3.7158, 3.579, 0.09, 1.0 }, /*15 K */ { 39.10*AU, 0.0230, 0.3170, 9.3093, 1.6143, 4.6073, 3.633, 0.06, 1.0 }, /*16 V */ { 50.94*AU, 0.2572, 2.3126, 6.8543, 2.1886, 2.6223, 3.435, 0.30, 1.0 }, /*17 Cr*/ { 52.00*AU, 0.0407, 1.1012, 13.1852, 0.8993, 2.4981, 4.048, 0.36, 1.0 }, /*18 Fe*/ { 55.85*AU, 0.1184, 1.5418, 10.7613, 2.0379, 2.4824, 3.479, 0.33, 1.0 }, /*19 Rb*/ { 85.47*AU, 0.0292, 0.3233, 8.1532, 1.9235, 4.9363, 3.516, 0.03, 1.0 }, /*20 Nb*/ { 92.91*AU, 0.4546, 3.6302, 5.2702, 2.0552, 2.6033, 3.474, 0.45, 1.0 }, /*21 Mo*/ { 95.94*AU, 0.2043, 2.5097, 10.0154, 2.0511, 2.7253, 3.475, 0.48, 1.0 }, /*22 Cs*/ {132.91*AU, 0.0270, 0.3036, 8.4120, 1.9433, 5.3174, 3.509, 0.01, 1.0 }, /*23 Ba*/ {137.34*AU, 0.0400, 0.6167, 10.1835, 1.5070, 4.3466, 3.680, 0.14, 1.0 }, /*24 Ta*/ {180.95*AU, 0.3281, 3.3008, 8.2764, 2.2371, 2.8601, 3.422, 0.52, 1.0 }, /*25 W */ {183.85*AU, 0.2490, 3.2055, 10.3715, 1.9916, 2.7410, 3.493, 0.55, 1.0 }, /*26 Ti*/ { 47.90*AU, 0.1519, 1.8112, 8.6200, 2.3900, 2.9510, 3.600, 0.24, 2.0 }, /*27 Zr*/ { 91.22*AU, 0.1934, 2.2792, 8.2500, 2.2490, 3.2320, 3.600, 0.26, 2.0 }, /*28 Co*/ { 58.93*AU, 0.0950, 1.4880, 11.6040, 2.2860, 2.5070, 3.500, 0.30, 2.0 }, /*29 Mg*/ { 24.31*AU, 0.0290, 0.4992, 12.8200, 2.2570, 3.1760, 3.600, 0.22, 2.0 } }; int kindMax = 30; int kind[] = new int[NN]; double xx[] = new double[NN]; /* i-th position */ double yy[] = new double[NN]; double zz[] = new double[NN]; double vx[] = new double[NN]; /* i-th velocity */ double vy[] = new double[NN]; double vz[] = new double[NN]; double ffx[] = new double[NN]; /* i-th force */ double ffy[] = new double[NN]; double ffz[] = new double[NN]; double virx[] = new double[NN]; double viry[] = new double[NN]; double virz[] = new double[NN]; double eDens[] = new double[NN]; int regNr[][] = new int[NN][250]; int section[][][][] = new int[Nsx][Nsy][Nsz][100]; double pairTBL[][][] = new double[kindMax][kindMax][1000]; double faiTBL[][][] = new double[kindMax][kindMax][1000]; double ggRef[][] = new double[kindMax][kindMax]; int srtz[][] = new int[2][NN]; int rdf[][] = new int[4][260]; int vdf[][] = new int[4][220]; double meanvdf[][] = new double[4][220]; double ffvMaxwell[] = new double[220]; double virial[] = new double[256]; int virialp = 0; double px[] = new double[NN]; double py[] = new double[NN]; double pz[] = new double[NN]; double wkx[] = new double[8]; double wky[] = new double[8]; double wkz[] = new double[8]; double pwkx[] = new double[8]; double pwky[] = new double[8]; double pwkz[] = new double[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} }; /*----------------------------- applet control functions -----*/ public void init() { resize(630,420); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); ch_mat = new Choice(); ch_mat.addItem("Al"); ch_mat.addItem("Ca"); ch_mat.addItem("Ni"); ch_mat.addItem("Cu"); ch_mat.addItem("Sr"); ch_mat.addItem("Rh"); ch_mat.addItem("Pd"); ch_mat.addItem("Ag"); ch_mat.addItem("Ir"); ch_mat.addItem("Pt"); ch_mat.addItem("Au"); ch_mat.addItem("Pb"); ch_mat.addItem("Th"); ch_mat.addItem("Li"); ch_mat.addItem("Na"); ch_mat.addItem("K"); ch_mat.addItem("V"); ch_mat.addItem("Cr"); ch_mat.addItem("Fe"); ch_mat.addItem("Rb"); ch_mat.addItem("Nb"); ch_mat.addItem("Mo"); ch_mat.addItem("Cs"); ch_mat.addItem("Ba"); ch_mat.addItem("Ta"); ch_mat.addItem("W"); ch_mat.addItem("Ti"); ch_mat.addItem("Zr"); ch_mat.addItem("Co"); ch_mat.addItem("Mg"); ch_mat.addItemListener(this); ch_mat.select("Ti"); ch_mat2 = new Choice(); ch_mat2.addItem("Al"); ch_mat2.addItem("Ca"); ch_mat2.addItem("Ni"); ch_mat2.addItem("Cu"); ch_mat2.addItem("Sr"); ch_mat2.addItem("Rh"); ch_mat2.addItem("Pd"); ch_mat2.addItem("Ag"); ch_mat2.addItem("Ir"); ch_mat2.addItem("Pt"); ch_mat2.addItem("Au"); ch_mat2.addItem("Pb"); ch_mat2.addItem("Th"); ch_mat2.addItem("Li"); ch_mat2.addItem("Na"); ch_mat2.addItem("K"); ch_mat2.addItem("V"); ch_mat2.addItem("Cr"); ch_mat2.addItem("Fe"); ch_mat2.addItem("Rb"); ch_mat2.addItem("Nb"); ch_mat2.addItem("Mo"); ch_mat2.addItem("Cs"); ch_mat2.addItem("Ba"); ch_mat2.addItem("Ta"); ch_mat2.addItem("W"); ch_mat2.addItem("Ti"); ch_mat2.addItem("Zr"); ch_mat2.addItem("Co"); ch_mat2.addItem("Mg"); ch_mat2.addItemListener(this); ch_mat2.select("Fe"); ch_tempMode = new Choice(); ch_tempMode.addItem("adiabatic"); ch_tempMode.addItem("t scaling"); ch_tempMode.addItem("wall cont."); ch_tempMode.addItemListener(this); ch_tempMode.select("t scaling"); ch_view = new Choice(); ch_view.addItem("ball"); ch_view.addItem("line"); ch_view.addItem("both"); ch_view.addItem("temp"); ch_view.addItem("real"); ch_view.addItem("velocity"); ch_view.addItem("v-space"); ch_view.addItem("Veff"); ch_view.addItem("e-density"); ch_view.addItem("surface"); ch_view.addItemListener(this); ch_view.select("ball"); bt_reset= new Button("reset"); bt_reset.addActionListener(this); bt_startStop= new Button("start/stop"); bt_startStop.addActionListener(this); sc_temp = new Scrollbar(Scrollbar.HORIZONTAL,30,10,1,210); sc_temp.addAdjustmentListener(this); sc_scale = new Scrollbar(Scrollbar.HORIZONTAL,100,10,50,310); sc_scale.addAdjustmentListener(this); addMouseListener(this); addMouseMotionListener(this); setLayout(new BorderLayout()); Panel pnl = new Panel(); pnl.setLayout(new GridLayout(1,6,5,0)); //pnl.add(new Label(" ")); pnl.add(ch_mat); pnl.add(new Label(" ")); //pnl.add(ch_mat2); pnl.add(ch_tempMode); pnl.add(sc_temp); pnl.add(sc_scale); pnl.add(ch_view); 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_mat){ MAT1 = ch_mat.getSelectedIndex(); resetSW = 1; } else if (ev.getSource() == ch_mat2){ MAT2 = ch_mat2.getSelectedIndex(); resetSW = 1; } else if (ev.getSource() == ch_tempMode){ tempMode = ch_tempMode.getSelectedIndex(); } else if (ev.getSource() == ch_view){ dispMode = ch_view.getSelectedIndex(); } } public void actionPerformed(ActionEvent ev){ if(ev.getSource() == bt_reset){ resetSW = 1; } else if (ev.getSource() == bt_startStop){ if (started==0) { started = 1; } else { started = 0; } } } public void adjustmentValueChanged(AdjustmentEvent ev){ if (ev.getSource() == sc_temp) { contTemp = 10.0*(double)(sc_temp.getValue()); vAjustment(); } else if(ev.getSource() == sc_scale) { viewScale = 0.01*(double)(sc_scale.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; } theta += 0.5*3.14/180.0*(dgX-dgXb); fai += 0.5*3.14/180.0*(dgY-dgYb); } 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 gbx,gby; double tmp; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); tmp = temperature(); gbx = 60; gby = 100; if (dispMode==0) { ballPlot(gbx,gby,0.6,0); rdfPlot(400,100,1.0); } else if (dispMode==1) { ballPlot(gbx,gby,0.0,2); rdfPlot(400,100,1.0); } else if (dispMode==2) { ballPlot(gbx,gby,0.5,2); rdfPlot(400,100,1.0); } else if (dispMode==3) { ballPlot(gbx,gby,0.6,1); rdfPlot(400,100,1.0); } else if (dispMode==4) { ballPlot(gbx,gby,1.0,0); rdfPlot(400,100,1.0); } else if (dispMode==5) { velocityPlot(gbx,gby, 50.0); vdfPlot(400,100,1.0); } else if (dispMode==6) { vSpacePlot(gbx,gby); vdfPlot(400,100,1.0); } else if (dispMode==7) { ballPlot(gbx,gby,0.6,0); drawEffectivePotential(400, 100 ,MAT1,MAT1,1.0); } else if (dispMode==8) { ballPlot(gbx,gby,1.0,3); drawEffectivePotential(400, 100 ,MAT1,MAT1,1.0); } else if (dispMode==9) { ballPlot(gbx,gby,1.0,4); drawEffectivePotential(400, 100 ,MAT1,MAT1,1.0); } else if (dispMode==10) { ; } gOff.setColor(Color.getHSBColor((float)(TB[MAT1][7]),0.95f,0.5f)); gOff.drawString("atom 1",630/6*0+10,40); gOff.drawString("r0="+(int)(TB[MAT1][5]*1000+0.5)/1000.0+" A",630/6*0+10,60); if ((int)(TB[MAT1][8]+0.5)==0) { gOff.drawString("fcc",630/6*0+10,80); } else if ((int)(TB[MAT1][8]+0.5)==1) { gOff.drawString("bcc",630/6*0+10,80); } else if ((int)(TB[MAT1][8]+0.5)==2) { gOff.drawString("hcp",630/6*0+10,80); } /* gOff.setColor(Color.getHSBColor((float)(TB[MAT2][7]),0.9f,0.7f)); gOff.drawString("atom 2",630/6*1+10,40); gOff.drawString("r0="+(int)(TB[MAT2][5]*1000+0.5)/1000.0+" A",630/6*1+10,60); if ((int)(TB[MAT2][8]+0.5)==0) { gOff.drawString("fcc",630/6*1+10,80); } else if ((int)(TB[MAT2][8]+0.5)==1) { gOff.drawString("bcc",630/6*1+10,80); } else if ((int)(TB[MAT2][8]+0.5)==2) { gOff.drawString("hcp",630/6*1+10,80); } */ gOff.setColor(Color.black); gOff.drawString("temp control",630/6*2+10,40); gOff.drawString("T_cont="+(int)(contTemp+0.5)+" K",630/6*3+10,40); gOff.drawString("scale="+(int)(viewScale*100.0+0.499)+"%",630/6*4+10,40); gOff.drawString("view",630/6*5+10,40); gOff.setColor(Color.blue); gOff.drawString("t="+Math.floor(t*1.0e15+0.5)+" fs",630/6*2+10,60); gOff.drawString("T="+(int)(tmp*10.0+0.5)/10.0+" K",630/6*3+10,60); gOff.drawString("
="+(int)(pressure()/1.0e6)+"MPa",630/6*4+10,60);
gOff.setColor(Color.black);
gOff.drawString("box="+(int)(xMax*1.0e10+0.5)/10.0+"x"+(int)(yMax*1.0e10+0.5)/10.0+"x"+(int)(zMax*1.0e10+0.5)/10.0+"nm",430,80);
}
/*------------------------------- plot methods ----------*/
void ballPlot(int gbx, int gby, double size,int mode) {
int i,j,k,jj,gx,gy,gz,g2x,g2y;
double sc,sz,bl,rt,rg;
setWaku();
rotate(theta,fai);
zSort();
if (mode>=3) setEDensity();
drawWaku(gbx,gby,0);
sc = dispScale*viewScale;
for (i=0; i