Back to atomic radius page
Top page ( correct Bohr model including the two electron atom )
This program is a little long. So if you copy and paste the below program source code into a text editor,
you can easily compile and run this.
This program's class file name is nitrr, so save this text editor as "nitrr.java", and compile it.
In some version of JAVA, some notes such as "-Xlint : unchecked ---" may appear on the screen, after you compile it.
But you can run it as it is, neglecting those messages.
In this program, the nitrogen nucleus (gray color) is at (12500MM, 12500MM, 12500MM).
Here we use the new units, ( 1 MM = 10-14 meter).
Each coordinate of electrons (+X (MM), +Y (MM), +Z (MM)) in the text box means "relative" positions from this nucleus.
(You can change this coordinates by entering the values into the text boxes, and press the Enter key.)
"nuc (MM)" means the distance between the nucleus and each electron.
"charge Z" is central positive charge of atom.
( You can change these "nuc" and "charge Z", by inputting arbitrary values into each textboxes and press the Enter key. )
V (eV) and T (eV) mean the potential and kinetic energies of each electron.
CF means the force toward the nucleus acting on each electron.
(fx, fy, fz) mean the each component of the "remaining" force other than CF.
(FX, FY, FZ) of the last row mean each component of the force acting on the nucleus.
(The unit of force: 1000 = the force between +e nucleus and an -e electron which are Bohr radius apart from each other)
tV of the last row is the total potential energy (eV).
Waves (wn) means the number of de Broglie's waves contained in one orbit of each electron.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
public class nitrr extends JPanel // virial theorem of Nitrogen(N)
{
public static void main(String arg[])
{
JFrame frame = new JFrame("Nitrogen, phosphate"); // set frame
J2DPanel j2dpanel = new J2DPanel();
frame.getContentPane().add(j2dpanel); frame.setSize(1180,700);
frame.setVisible(true); frame.setBackground(Color.black);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class J2DPanel extends JPanel implements ActionListener
{
double pai=3.141592653589793; double epsi=8.85418781787346e-12;
double h=6.62606896e-34; double elc=1.60217653e-19;
double me=9.1093826e-31; double suh=5291.0*5291.0; // suh=(Bohr radius)^2
// elp[0-4][0-10] = Textboxes of each electron (0-4)
JTextField elp[][]=new JTextField[5][11];
JTextField impho=new JTextField(7); // total V text
JTextField mmpho[]=new JTextField[3]; // nucleus text
// imppo = distance between electron and nucleus text
JTextField imppo=new JTextField(7);
JTextField charge=new JTextField(7); // charge text
int marki[]=new int[3]; int mar=0; // marking
double rtw=Math.sqrt(2); double rth=Math.sqrt(3);
double rsi=Math.sqrt(6); double rfi=Math.sqrt(5);
double hpr[][]=new double[5][11];
double den=5.25; // den= central positive charge Z
double nux[]={12500.0, 12500.0, 12500.0}; // nux[0-2]=nuclear coordinate
double ina1=5332.0; // ina1= distance between nucleus and electron
// te1=initial conditions of each electron
double te1[][]={{2666,-4617.6, 0}, {2666, 4617.6, 0},
{0, 0, 5332}, {-5332, 0, 0},
{0, 0, -5332}};
public J2DPanel()
{
setBackground(Color.black);
JPanel p=new JPanel();
p.setLayout(new GridLayout(7,12));
String vv,zww; int aaa=0;
// hpr[0-4][0-2] = coordinate of each electron (0-4)
for (int el=0; el <=4; el++) {
for (int pos=0; pos <=2; pos++) {
elp[el][pos]=new JTextField(7); elp[el][pos].addActionListener(this);
hpr[el][pos]=0.0;
}}
for (int el=0; el <=4; el++) { // other parameters of each electron
for (int pos=3; pos <=10; pos++) {
elp[el][pos]=new JTextField(7);
hpr[el][pos]=0.0;
}}
// mmpho[0-2] = force components acting on nucleus
for (int pos=0; pos <=2; pos++) {
mmpho[pos]=new JTextField(7);
}
// layout
String sihy[]={"eNo. ", "+X (MM)", "+Y (MM)", "+Z (MM)", "nux (MM)",
"V (eV)", "T (eV)", "Force", "fx ", "fy", "fz", "Waves "};
for (int el=0; el <=11; el++) {
p.add(new Label(sihy[el]));
}
for (int el=0; el <=4; el++) {
p.add(new Label("ele "+el+" "));
for (int pos=0; pos <=10; pos++) {
p.add(elp[el][pos]);
}}
p.add(new Label("nucleus "));
for (int pos=0; pos <=2; pos++) {
p.add(mmpho[pos]);
}
p.add(new Label(" -- "));
p.add(impho); // impho=textbox of total potential energy (tV)
// charge = central charge text
p.add(new Label(" Charge Z = "));
p.add(charge); charge.addActionListener(this);
p.add(new Label(" -- "));
p.add(new Label(" nuc = "));
// imppo=textbox of nuc (distance)
p.add(imppo);
imppo.addActionListener(this);
p.add(new Label(" -- "));
add(p,"South");
for (int el=0; el <=4; el++) {
double nnuc=Math.sqrt(te1[el][0]*te1[el][0]+te1[el][1]*te1[el][1]+te1[el][2]*te1[el][2]);
aaa=(int)(nnuc);
// show distance between nuclei and electrons
elp[el][3].setText(Integer.toString(aaa));
for (int jou=0; jou <=2; jou++) {
hpr[el][jou]=te1[el][jou]+nux[jou];
// show initial coordinate
elp[el][jou].setText(Integer.toString((int)(te1[el][jou])));
}}
imppo.setText(Double.toString(ina1));
charge.setText(Double.toString(den));
} // public J2DPanel() end
public void actionPerformed(ActionEvent e) { // when textboxes change
String ss; ss=" ";
double Rf1=0.0; mar=0;
if (e.getSource()==imppo ) {mar=1; // when "nuc" changes
ss=imppo.getText(); ina1=Double.parseDouble(ss);
if (ina1 > 12000.0) {ina1=12000.0;} if (ina1 < 1000.0) {ina1=1000.0;}
}
for (int ett=0; ett <=4; ett++) {
for (int sws=0; sws <=2; sws++) { // when each coordinate changes
if (e.getSource()==elp[ett][sws] ) {
ss=elp[ett][sws].getText(); Rf1=Double.parseDouble(ss);
hpr[ett][sws]=Rf1+nux[sws];
}
}}
repaint();
}
public void update(Graphics g)
{
paint(g);
}
public void paintComponent(Graphics g)
{
double kro,pot,gx,gy,gz,ggx,ggy,ggz,ttav,toav;
kro=0.0; gx=0.0;gy=0.0;gz=0.0;ggx=0.0; ggy=0.0; ggz=0.0;
int ex,ey,ez; String ww;
double rhp[][]= {{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}};
double mmp[]={0,0,0};
// --------------------- "nuc" = distance changes
if (mar==1) {
for (int yp=0; yp <=4; yp++) {
gx=Math.sqrt((hpr[yp][0]-nux[0])*(hpr[yp][0]-nux[0])+
(hpr[yp][1]-nux[1])*(hpr[yp][1]-nux[1])+(hpr[yp][2]-nux[2])*(hpr[yp][2]-nux[2]));
for (int kj=0; kj <=2; kj++) {
gy=hpr[yp][kj]-nux[kj]; gy=(gy*ina1)/gx; hpr[yp][kj]=gy+nux[kj];
elp[yp][kj].setText(Integer.toString((int)gy));
}} mar=0;
}
ww=charge.getText(); // get charge value from text
den=Double.parseDouble(ww);
toav=0.0; // toav=total potential energy
double ppot;
for (int yp=0; yp <=4; yp++) { //---- interaction between electrons
for (int kj=0; kj <=4; kj++) {
if (yp < kj ) {
// kro=distance between electrons
kro=Math.sqrt((hpr[yp][0]-hpr[kj][0])*(hpr[yp][0]-hpr[kj][0])+
(hpr[yp][1]-hpr[kj][1])*(hpr[yp][1]-hpr[kj][1])+
(hpr[yp][2]-hpr[kj][2])*(hpr[yp][2]-hpr[kj][2]));
if (kro==0) {kro=5000.0;}
// ppot=repulsive potential energy (eV)
ppot=(elc*elc*6.241509e18)/(4.0*pai*epsi*kro*1.0e-14);
toav=toav+ppot;
// rhp[][3]= potential energy of each electron
rhp[yp][3]=rhp[yp][3]+ppot/2.0; rhp[kj][3]=rhp[kj][3]+ppot/2.0;
for (int jou=0; jou <=2; jou++) {
// rhp[][0-2]=force component acting on each electron
ggx=(suh*(hpr[yp][jou]-hpr[kj][jou]))/(kro*kro*kro);
rhp[yp][jou]=rhp[yp][jou]+ggx; rhp[kj][jou]=rhp[kj][jou]-ggx;
}
}}}
// ----- interaction between nucleus and each electron
for (int rv=0; rv <=4; rv++) {
// kro=distance between nucleus and electron
kro=Math.sqrt((hpr[rv][0]-nux[0])*(hpr[rv][0]-nux[0])+
(hpr[rv][1]-nux[1])*(hpr[rv][1]-nux[1])+
(hpr[rv][2]-nux[2])*(hpr[rv][2]-nux[2]));
if (kro == 0) {kro=5000.0;}
ex=(int)(kro); elp[rv][3].setText("nuc "+Integer.toString(ex));
// ppot = each attractive potential energy
ppot=-(elc*elc*den*6.241509e18)/(4.0*pai*epsi*kro*1.0e-14);
toav=toav+ppot;
rhp[rv][3]=rhp[rv][3]+ppot;
// ggx=force component between nucleus and electron
for (int jou=0; jou <=2; jou++) {
ggx=(suh*den*(hpr[rv][jou]-nux[jou]))/(kro*kro*kro);
rhp[rv][jou]=rhp[rv][jou]-ggx;
mmp[jou]=mmp[jou]+ggx; // mmp[0-2] = force acting on nucleus
}}
ex=(int)(100*toav); ggx=ex/100.0;
impho.setText("tV "+Double.toString(ggx)); // show total V (eV)
for (int rv=0; rv <=4; rv++) { // show forces acting on electrons
gx=Math.sqrt((hpr[rv][0]-nux[0])*(hpr[rv][0]-nux[0])+
(hpr[rv][1]-nux[1])*(hpr[rv][1]-nux[1])+(hpr[rv][2]-nux[2])*(hpr[rv][2]-nux[2]));
// gy=forces toward nucleus (CF)
gy=-(rhp[rv][0]*(hpr[rv][0]-nux[0])+rhp[rv][1]*(hpr[rv][1]-nux[1])+rhp[rv][2]*(hpr[rv][2]-nux[2]))/gx;
ex=(int)(1000*gy); ww="CF ";
elp[rv][6].setText(ww+Integer.toString(ex));
// show forces other than CF
for (int jou=0; jou <=2; jou++) {
gz=rhp[rv][jou]-(gy*(nux[jou]-hpr[rv][jou]))/gx;
ex=(int)(1000*gz);
elp[rv][jou+7].setText(Integer.toString(ex));
}
}
for (int jou=0; jou <=2; jou++) { // show forces acting on nucleus
ex=(int)(1000*mmp[jou]); ww=" ";
if (jou==0) {ww="FX=";}
if (jou==1) {ww="FY=";}
if (jou==2) {ww="FZ=";}
mmpho[jou].setText(ww+Integer.toString(ex));
}
// show potential and kinetic energy of each electron
for (int rv=0; rv <=4; rv++) {
ex=(int)(100*rhp[rv][3]); ggx=ex/100.0;
elp[rv][4].setText("V "+Double.toString(ggx));
rhp[rv][4] = -rhp[rv][3] * 0.5;
ex=(int)(100*rhp[rv][4]); ggx=ex/100.0;
elp[rv][5].setText("T "+Double.toString(ggx));
}
for (int rv=0; rv <=4; rv++) { // ------ show de Broglie wave
// gz = total force acting on each electron
gz=Math.sqrt(rhp[rv][0]*rhp[rv][0]+rhp[rv][1]*rhp[rv][1]+rhp[rv][2]*rhp[rv][2]);
// gy=forces (N)
gy=(gz*elc*elc)/(4.0*pai*epsi*suh*1.0e-28);
// gx=velocity (m/s) of each electron
gx=Math.sqrt((2.0*rhp[rv][4]*1.602177e-19)/me);
ggx=(me*gx*gx)/gy; // ggx= rotation radius from centrifugal force
double debroglie = h/(me*gx);
ggy=(2*pai*ggx)/debroglie; // ggy=number of de Broglie's wave in one orbit
ex=(int)(ggy*1000); ggz=ex/1000.0;
elp[rv][10].setText("wn "+Double.toString(ggz));
}
// ---------- show picture
int nmx[]=new int[3]; int hpk[][]=new int[8][4];
for (int kj=0; kj <=2; kj++) { // change MM to pixel in nuclei
nmx[kj]=(int)(nux[kj]/71.428);
}
for (int yp=0; yp <=4; yp++) {
for (int kj=0; kj <=2; kj++) { // change MM to pixel in electrons
hpk[yp][kj]=(int)(hpr[yp][kj]/71.428);
}}
g.clearRect(9,299,1170,699);
g.setColor(Color.cyan); g.drawLine(375,310,375,660); g.drawLine(735,310,735,660);
g.drawString("X - Y plane", 150,290);
g.drawString("X - Z plane", 510,290);
g.drawString("Y - Z plane", 870,290);
g.setColor(Color.lightGray); // show nucleus
g.fillOval(nmx[0]+10,650-nmx[1],20,20);g.fillOval(370+nmx[0],650-nmx[2],20,20);
g.fillOval(730+nmx[1],650-nmx[2],20,20);
g.setColor(Color.white); // show electron 0 (particle)
g.fillOval(hpk[0][0]+13,653-hpk[0][1],14,14);
g.fillOval(hpk[0][0]+373,653-hpk[0][2],14,14);
g.fillOval(hpk[0][1]+733,653-hpk[0][2],14,14);
g.setColor(Color.pink); // show electron 1
g.fillOval(hpk[1][0]+13,653-hpk[1][1],14,14);
g.fillOval(hpk[1][0]+373,653-hpk[1][2],14,14);
g.fillOval(hpk[1][1]+733,653-hpk[1][2],14,14);
g.setColor(Color.red); // show electron 2
g.fillOval(hpk[2][0]+13,653-hpk[2][1],14,14);
g.fillOval(hpk[2][0]+373,653-hpk[2][2],14,14);
g.fillOval(hpk[2][1]+733,653-hpk[2][2],14,14);
g.setColor(Color.green); // show electron 3
g.fillOval(hpk[3][0]+13,653-hpk[3][1],14,14);
g.fillOval(hpk[3][0]+373,653-hpk[3][2],14,14);
g.fillOval(hpk[3][1]+733,653-hpk[3][2],14,14);
// show electron 4
g.fillOval(hpk[4][0]+13,653-hpk[4][1],14,14);
g.fillOval(hpk[4][0]+373,653-hpk[4][2],14,14);
g.fillOval(hpk[4][1]+733,653-hpk[4][2],14,14);
for (int rw=0; rw <=4; rw++) { // show each electron's number
g.setColor(Color.blue);
g.drawString(Integer.toString(rw),hpk[rw][0]+17,665-hpk[rw][1]);
g.drawString(Integer.toString(rw),hpk[rw][0]+377,665-hpk[rw][2] );
g.drawString(Integer.toString(rw),hpk[rw][1]+737,665-hpk[rw][2] );
}
}
}