Sample JAVA program to visualize the electrons of Bohr model ethylene (ethene).

Back to the C-C bond 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 ethene, so save this text editor as "ethene.java", and compile it.

In this program, nuclei are gray circles.
Each particle is shown on x-y (left) and the x-z (right) planes.
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" position from these nuclei.
(ele 0-3 are from carbon nucleus 0 (C0), ele 4-7 are from C1, ele 8 is from hydrogen nucleus 0 (H0), ele9 is from H1, ele10 is from H2, and ele 11 is from H3).
You can change the coordinates (+X, +Y, +Z) of electrons (0,2,4,6,8, and 10).
Other electrons are arranged automatically based on these electrons.
(Enter the values into the textboxes of ele 0,2,4,6,8 and 10, and press the Enter key.)
"nuc (MM)" means the distance between these nuclei and electrons.
V (eV) and T (eV) means the potential, and kinetic energies of each electron.
tV (eV) is the total potential energy.
CF of ele0-7 means the force toward the center, CF of ele8-11 means the force toward each C-H line.
(fx, fy, fz) means force components other than CF.
(FX, FY, FZ) means the force component acting on each nucleus.
CnH0, CnH2 mean the force components acting on H0, H2 nuclei toward the C nucleus.
(In this program, the informations of two carbon nuclei (C0, C1) and two hydrogen nuclei (H0 and H2) are shown.)
Waves (wn) is number of de Broglie's waves contained in one orbit.
When you choose the value of the scrollbar, and click the C=C (MM) button, C=C length of ethylene changes.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
public class ethene extends JPanel     // virial theorem of ethene
 {
  public static void main(String arg[])
 {
   JFrame frame = new JFrame("H2C=CH2 (ethene)");
   J2DPanel j2dpanel = new J2DPanel();
   frame.getContentPane().add(j2dpanel); frame.setSize(1180,720);
   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=5200.0*5200.0; // suh=(Bohr radius)^2
 
    JTextField elp[][]=new JTextField[9][11];  JTextField impho=new JTextField(7); 
    JTextField mmpho[][]=new JTextField[4][3];  JTextField imppo=new JTextField(7);
    JTextField imppp=new JTextField(7);
    JButton b1=new JButton("C=C (MM)");

    String ope[]={"12500","13390","15000"};   // scrollbar of C=C distances
    JComboBox coom=new JComboBox(ope);
    
    double rtw=Math.sqrt(2); double rth=Math.sqrt(3); 
    double rsi=Math.sqrt(6); double rfi=Math.sqrt(5);
    double hpr[][]=new double[12][11]; double hpr2[][]=new double[12][3];
  
    double den=4.217;                      // den: central charge 
    double cclen=13390.0;                  // cclen: C=C length (MM)
    double angl=121.3;                     // angl: C=C-H angle
    double chlen=10870.0;                  // chlen: C-H length (MM)
                                          
     double cc2=chlen*Math.sin(angl*pai/180.0);  
     double cc3=-chlen*Math.cos(angl*pai/180.0);

            // nux[0-5][0-2] =nucleus coordinate : 0=C0, 1=C1, 2=H0, 3=H1, 4=H2, 5=H3
    double nux[][]={{18571.28+cclen*0.5, 13214.18, 13214.18, den},
     {18571.28-cclen*0.5, 13214.18, 13214.18, den},
    {18571.28+cclen*0.5+cc3, 13214.18-cc2, 13214.18, 1.0},
    {18571.28+cclen*0.5+cc3, 13214.18+cc2, 13214.18, 1.0},
    {18571.28-cclen*0.5-cc3, 13214.18, 13214.18-cc2, 1.0},
    {18571.28-cclen*0.5-cc3, 13214.18, 13214.18+cc2, 1.0}}; 
                                  // nux2= "original" each nucleus coordinate
   double nux2[][]={{18571.28+cclen*0.5, 13214.18, 13214.18, den},
     {18571.28-cclen*0.5, 13214.18, 13214.18, den},
    {18571.28+cclen*0.5+cc3, 13214.18-cc2, 13214.18, 1.0},
    {18571.28+cclen*0.5+cc3, 13214.18+cc2, 13214.18, 1.0},
    {18571.28-cclen*0.5-cc3, 13214.18+cc2, 13214.18, 1.0},
    {18571.28-cclen*0.5-cc3, 13214.18-cc2, 13214.18, 1.0}}; 
                                                                                              
                                    //  te1[][]:control C=C length =13390 MM
    double te1[][]={{-3869, 0, 5249}, {-3869, 0, -5249}, 
    {3500, 5294, 0}, {3750, -5260, 0}, 
    {3750, 5260, 0}, {-3568, 0, -5290}, {560, -1100, 4270},
    {560, 1100, -4270}, {-560, -4280, -1100}};

                                             //   te2[][]: C=C length =15000 MM
   double te2[][]={{-3910, 0, 5260}, {-3910, 0, -5260}, 
    {3490, 5210, 0}, {+3770, -5270, 0}, 
    {3770, 5270, 0}, {-3590, 0, -5197}, {600, -1100, 4290},
    {600, 1100, -4290}, {-610, -4290, -1100}};
                                           // te3[][]: C=C length=12500 MM
   double te3[][]={{-3850, 0, 5200}, {-3850, 0, -5200}, 
    {3500, 5350, 0}, {3750, -5240, 0}, 
    {3750, 5240, 0}, {-3620, 0, -5350}, {560, -1150, 4265},
    {560, 1150, -4265}, {-560, -4280, -1100}};


  public J2DPanel()
 {
  setBackground(Color.black);
  JPanel p=new JPanel();
  p.setLayout(new GridLayout(12,12));
  int aaa=0; 
                   //  elp[el=0-8][] : textboxes of electrons 0,1,2,4,5,6,8,9,10              
  for (int el=0; el <=8; el++) {         
  for (int pos=0; pos <=2; pos++) {
  elp[el][pos]=new JTextField(7); 
  if (el==0) {elp[el][pos].addActionListener(this);}
  if (el== 2 || el==3) {elp[el][pos].addActionListener(this);}
  if (el== 5 || el==6) {elp[el][pos].addActionListener(this);}
  if (el == 8) {elp[el][pos].addActionListener(this);}
  }}
                                   
   for (int el=0; el <=8; el++) {        
  for (int pos=3; pos <=10; pos++) {
  elp[el][pos]=new JTextField(7);     
  }}

   for (int el=0; el <=3; el++) {
   for (int pos=0; pos <=2; pos++) {
    mmpho[el][pos]=new JTextField(7);
   }}

                                        // layout
   String sihy[]={"eNo ", "+X(MM)", "+Y(MM)", "+Z(MM)", "nuc(MM)", 
   "V(eV)", "T(eV)", "Force", "fx ", "fy", "fz", "Waves"};
  for (int el=0; el <=11; el++) {
   p.add(new Label(sihy[el]));
  }

   String yy;
  for (int el=0; el <=8; el++) {   
  yy=" ";    
  if (el==0) {yy="ele "; aaa=0;}
  if (el==1) {yy=" "; aaa=1;}
  if (el == 2) {yy="ele "; aaa=2;}
  if (el == 3) {yy="ele "; aaa=4;}
  if (el==4) {yy=" "; aaa=5;}
  if (el == 5) {yy="ele "; aaa=6;}
  if (el == 6) {yy="ele "; aaa=8;}
  if (el==7) {yy=" "; aaa=9;}
  if (el == 8) {yy="ele "; aaa=10;}
  p.add(new Label(yy+aaa+" "));
  for (int pos=0; pos <=10; pos++) {
  p.add(elp[el][pos]);
  }}

   p.add(new Label("C0 nuc "));
  for (int pos=0; pos <=2; pos++) {
  p.add(mmpho[0][pos]);  
  }
    p.add(new Label(" -- ")); p.add(impho);
    p.add(new Label("C1 nuc "));
  for (int pos=0; pos <=2; pos++) {
  p.add(mmpho[1][pos]);  
  }
   p.add(new Label(" -- ")); p.add(new Label(" -- "));
 
   p.add(new Label("H0nuc "));
  for (int pos=0; pos <=2; pos++) {
  p.add(mmpho[2][pos]);
  } p.add(imppo);

   p.add(new Label("H2nuc "));
  for (int pos=0; pos <=2; pos++) {
  p.add(mmpho[3][pos]);
  }   p.add(imppp);

  p.add(b1); p.add(coom); coom.setSelectedItem("13390"); b1.addActionListener(this);
  add(p,"South");
  
                                 
   for (int el=0; el <=8; 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); 
   elp[el][3].setText(Integer.toString(aaa));
                              // hpr[0-11][0-2] = coordinate of each electron (0-11) 
    for (int jou=0; jou <=2; jou++) {          
    if (el < 3) {hpr[el][jou]=te1[el][jou]+nux[0][jou];}
     if (el > 2 && el < 6) {hpr[el+1][jou]=te1[el][jou]+nux[1][jou];}
     if (el > 5) {hpr[el+2][jou]=te1[el][jou]+nux[el-4][jou];}
     
     elp[el][jou].setText(Integer.toString((int)(te1[el][jou])));
     }}
    }     // public J2DPanel() end
 
  public void actionPerformed(ActionEvent e) {  
    String ss; double Rf=0.0;

    if (e.getSource() == b1) {          // when C=C distance change (b1 click)
   ss=(String)coom.getSelectedItem();
   if (ss=="12500") {cclen=12500;}  if (ss=="13390") {cclen=13390; } 
   if (ss=="15000") {cclen=15000;}  
   double nuxx[][]={{18571.28+cclen*0.5, 13214.18, 13214.18},
     {18571.28-cclen*0.5, 13214.18, 13214.18, den},
    {18571.28+cclen*0.5+cc3, 13214.18-cc2, 13214.18},
    {18571.28+cclen*0.5+cc3, 13214.18+cc2, 13214.18},
    {18571.28-cclen*0.5-cc3, 13214.18, 13214.18-cc2},
    {18571.28-cclen*0.5-cc3, 13214.18, 13214.18+cc2}}; 
    
    for (int ett=0; ett <= 5; ett++) {
     for (int sws=0; sws <=2; sws++) { 
     nux[ett][sws]=nuxx[ett][sws];
    }}
      for (int ett=0; ett <= 8; ett++) {
      for (int sws=0; sws <= 2; sws++) {  
     if (cclen==12500) {Rf=te3[ett][sws];}  if (cclen==13390) {Rf=te1[ett][sws];}  
     if (cclen==15000) {Rf=te2[ett][sws];}  
    elp[ett][sws].setText(Integer.toString((int)Rf));
     }}
    }

   repaint();
  }

  public void update(Graphics g)
 {
  paint(g);
 }
 public void paintComponent(Graphics g)
 {
   
  double kro,krr,krk,kro2,krr2,krk2,kkk,kkk2, pot,pota,potb,
  pot2,pota2,potb2,potc,potc2,gx,gy,gz,ggx,ggy,ggz,ttav,toav;
  kro=0.0; krr=0.0; krk=0.0; kro2=0.0; krr2=0.0; krk2=0.0; kkk=0.0; kkk2=0.0;
  int ex,ey,ez,xk,yk,zk; String ww,pyw;
  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},{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},
  {0,0,0,0,0,0},{0,0,0,0,0,0}};
  double rpp[][]= {{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,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};  
  double teqq[][]={{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,0,0}};
   double noxx[][]={{0,0,0,0},{0,0,0,0}}; 
 
         // set electrons 0(=elp[0]), 2(=elp[2]), 4(=elp[3]), 6(=elp[5]), 8(=elp[6]), 10(=elp[8])     
   for (int jou=0; jou <=2; jou++) {
   ww=elp[0][jou].getText(); gx=Double.parseDouble(ww);
   hpr[0][jou]=gx;                                
    }       
   for (int jou=0; jou <=2; jou++) {
   ww=elp[2][jou].getText(); gx=Double.parseDouble(ww);
   hpr[2][jou]=gx;                                
    }   
   for (int jou=0; jou <=2; jou++) {
   ww=elp[3][jou].getText(); gx=Double.parseDouble(ww);
   hpr[4][jou]=gx;                                
    }     
   for (int jou=0; jou <=2; jou++) {
   ww=elp[5][jou].getText(); gx=Double.parseDouble(ww);
   hpr[6][jou]=gx;                                
    }  
   for (int jou=0; jou <=2; jou++) {
   ww=elp[6][jou].getText(); gx=Double.parseDouble(ww);
   hpr[8][jou]=gx;                                
    }   
   for (int jou=0; jou <=2; jou++) {
   ww=elp[8][jou].getText(); gx=Double.parseDouble(ww);
   hpr[10][jou]=gx;                                
    }               
          // set other electrons' coordinates based on the upper electrons                          
   hpr[1][0]=hpr[0][0]; hpr[1][1]=-hpr[0][1]; hpr[1][2]=-hpr[0][2];
   hpr[3][0]=hpr[2][0]; hpr[3][1]=-hpr[2][1]; hpr[3][2]=-hpr[2][2];
   hpr[5][0]=hpr[4][0]; hpr[5][1]=-hpr[4][1]; hpr[5][2]=-hpr[4][2];
   hpr[7][0]=hpr[6][0]; hpr[7][1]=-hpr[6][1]; hpr[7][2]=-hpr[6][2];
   hpr[9][0]=hpr[8][0]; hpr[9][1]=-hpr[8][1]; hpr[9][2]=-hpr[8][2];
   hpr[11][0]=hpr[10][0]; hpr[11][1]=-hpr[10][1]; hpr[11][2]=-hpr[10][2];
   
                  // hpr[0-11][0-2] = absolute coordinate of electrons 0-11
     for (int yp=0; yp <=3; yp++) { 
   for (int jou=0; jou <=2; jou++) {
   if (yp==1) {elp[1][jou].setText(Integer.toString((int)hpr[yp][jou]));}
   hpr[yp][jou]=hpr[yp][jou]+nux[0][jou]; 
   }}

   for (int yp=4; yp <=7; yp++) { 
   for (int jou=0; jou <=2; jou++) {
   if (yp==5) {elp[4][jou].setText(Integer.toString((int)hpr[yp][jou]));}
   hpr[yp][jou]=hpr[yp][jou]+nux[1][jou];
   }}

   for (int yp=8; yp <=11; yp++) {
   for (int jou=0; jou <=2; jou++) {
   if (yp==9) {elp[7][jou].setText(Integer.toString((int)hpr[yp][jou]));}
   hpr[yp][jou]=hpr[yp][jou]+nux[yp-6][jou];
   }}

                                  // noxx[0][0-2]=center of electrons 0-3
                                  // noxx[1][0-2]=center of electrons 4-7                                      
   for (int yp=0; yp <=3; yp++) { 
   for (int jou=0; jou <=2; jou++) {
   noxx[0][jou]=noxx[0][jou]+hpr[yp][jou];
   noxx[1][jou]=noxx[1][jou]+hpr[yp+4][jou];
    }}
    for (int jou=0; jou <=2; jou++) {
    noxx[0][jou]=noxx[0][jou]/4.0;  noxx[1][jou]=noxx[1][jou]/4.0;
    }
  
         // hpr2[8-11][0-2]= symmetric positions of ele 8-11 with respect to each H-C-H plane
   for (int yp=8; yp <=9; yp++) {     
   hpr2[yp][0]=hpr[yp][0]; hpr2[yp][1]=hpr[yp][1]; 
   hpr2[yp][2]=-(hpr[yp][2]-nux[yp-6][2])+nux[yp-6][2];   
     }      
   for (int yp=10; yp <=11; yp++) {     
   hpr2[yp][0]=hpr[yp][0]; hpr2[yp][2]=hpr[yp][2]; 
   hpr2[yp][1]=-(hpr[yp][1]-nux[yp-6][1])+nux[yp-6][1];   
     }                      

   toav=0.0;                // toav=total potential energy (eV)

     double ppot;
             
                //----------------------- interaction among electrons 0-3, (and among 4-7)

   for (int yp=0; yp <=3; yp++) {             
    for (int kj=0; kj <=3; kj++) { 
    if (yp < kj ) {                 // kro =distance between electrons 0-3   
    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;}
                                   // kro2 =distance between electrons 4-7
    kro2=Math.sqrt((hpr[yp+4][0]-hpr[kj+4][0])*(hpr[yp+4][0]-hpr[kj+4][0])+
   (hpr[yp+4][1]-hpr[kj+4][1])*(hpr[yp+4][1]-hpr[kj+4][1])+
   (hpr[yp+4][2]-hpr[kj+4][2])*(hpr[yp+4][2]-hpr[kj+4][2]));
    if (kro2==0) {kro2=5000.0;}
     ppot=(elc*elc*6.241509e18)/(4*pai*epsi*kro*1.0e-14);   // potential energy (eV)
     potb=(elc*elc*6.241509e18)/(4*pai*epsi*kro2*1.0e-14); 
    toav=toav+ppot+potb;   
                                    // rhp[el][3] = each electron's V (eV)
                             // teqq[el][3] = each electron's V (eV) only in carbon atom
   rhp[yp][3]=rhp[yp][3]+ppot/2.0; rhp[kj][3]=rhp[kj][3]+ppot/2.0;
   teqq[yp][3]=teqq[yp][3]+ppot/2;  teqq[kj][3]=teqq[kj][3]+ppot/2;
   rhp[yp+4][3]=rhp[yp+4][3]+potb/2.0; rhp[kj+4][3]=rhp[kj+4][3]+potb/2.0;
   teqq[yp+4][3]=teqq[yp+4][3]+potb/2;  teqq[kj+4][3]=teqq[kj+4][3]+potb/2;
    for (int jou=0; jou <=2; jou++) {
                               // ggx=force components between electrons
                                // rhp[el][0-2]=force components acting on each electron
                       // teqq[el][0-2]=force components acting on electron only in carbon atom
   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;   
   teqq[yp][jou]=teqq[yp][jou]+ggx; teqq[kj][jou]=teqq[kj][jou]-ggx;
   ggy=(suh*(hpr[yp+4][jou]-hpr[kj+4][jou]))/(kro2*kro2*kro2);
   rhp[yp+4][jou]=rhp[yp+4][jou]+ggy; rhp[kj+4][jou]=rhp[kj+4][jou]-ggy;   
   teqq[yp+4][jou]=teqq[yp+4][jou]+ggy; teqq[kj+4][jou]=teqq[kj+4][jou]-ggy;
    } 
   }}}  

         //---------------------------------- interaction between ele (0-3) x ele (4-7)

    for (int yp=0; yp <=3; yp++) {    
    for (int kj=4; kj <=7; kj++) { 
    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;}
    pot=(elc*elc*6.241509e18)/(4*pai*epsi*kro*1.0e-14);   // potential energy (eV)
    rhp[yp][3]=rhp[yp][3]+pot/2.0; rhp[kj][3]=rhp[kj][3]+pot/2.0;
    toav=toav+pot;
      for (int jou=0; jou <=2; jou++) {
   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;
                  // rpp[0-7][0-2] = the total force from other nuclei's electrons and 6 nuclei
   rpp[yp][jou]=rpp[yp][jou]+ggx;  rpp[kj][jou]=rpp[kj][jou]-ggx;  
    }
     }}

       //------------------------- interaction between ele (0-3) (and 4-7)x other ele(8-11) 

    for (int yp=0; yp <=3; yp++) {    
    for (int kj=8; kj <=11; kj++) { 
    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;}
                             // kro2 = distance between electron (0-3) and hpr2[8-11][]
     kro2=Math.sqrt((hpr[yp][0]-hpr2[kj][0])*(hpr[yp][0]-hpr2[kj][0])+
   (hpr[yp][1]-hpr2[kj][1])*(hpr[yp][1]-hpr2[kj][1])+
   (hpr[yp][2]-hpr2[kj][2])*(hpr[yp][2]-hpr2[kj][2]));
   if (kro2==0) {kro2=5000.0;}
      krr=Math.sqrt((hpr[yp+4][0]-hpr[kj][0])*(hpr[yp+4][0]-hpr[kj][0])+
   (hpr[yp+4][1]-hpr[kj][1])*(hpr[yp+4][1]-hpr[kj][1])+
   (hpr[yp+4][2]-hpr[kj][2])*(hpr[yp+4][2]-hpr[kj][2]));
   if (krr==0) {krr=5000.0;}
                            // krr2 = distance between electron (4-7) and hpr2[8-11][]
     krr2=Math.sqrt((hpr[yp+4][0]-hpr2[kj][0])*(hpr[yp+4][0]-hpr2[kj][0])+
   (hpr[yp+4][1]-hpr2[kj][1])*(hpr[yp+4][1]-hpr2[kj][1])+
   (hpr[yp+4][2]-hpr2[kj][2])*(hpr[yp+4][2]-hpr2[kj][2]));
   if (krr2==0) {krr2=5000.0;}

    pot=(elc*elc*6.241509e18)/(4*pai*epsi*kro*1.0e-14);    // potential energy (eV)
    pot2=(elc*elc*6.241509e18)/(4*pai*epsi*kro2*1.0e-14);
    rhp[yp][3]=rhp[yp][3]+pot/4.0+pot2/4.0; rhp[kj][3]=rhp[kj][3]+pot/2.0;
   
    pota=(elc*elc*6.241509e18)/(4*pai*epsi*krr*1.0e-14); 
    pota2=(elc*elc*6.241509e18)/(4*pai*epsi*krr2*1.0e-14);
   
    rhp[yp+4][3]=rhp[yp+4][3]+pota/4.0+pota2/4.0; rhp[kj][3]=rhp[kj][3]+pota/2.0;
    toav=toav+pot+pota;

     for (int jou=0; jou <=2; jou++) {
   ggx=(suh*(hpr[yp][jou]-hpr[kj][jou]))/(kro*kro*kro);
   ggy=(suh*(hpr[yp][jou]-hpr2[kj][jou]))/(kro2*kro2*kro2);              
   rhp[yp][jou]=rhp[yp][jou]+ggx*0.5+ggy*0.5; rhp[kj][jou]=rhp[kj][jou]-ggx;
            // rpp[0-7][0-2] = the total force from other nuclei's electrons and 6 nuclei
   rpp[yp][jou]=rpp[yp][jou]+ggx*0.5+ggy*0.5;  
   ggx=(suh*(hpr[yp+4][jou]-hpr[kj][jou]))/(krr*krr*krr);
   ggy=(suh*(hpr[yp+4][jou]-hpr2[kj][jou]))/(krr2*krr2*krr2);
   rhp[yp+4][jou]=rhp[yp+4][jou]+ggx*0.5+ggy*0.5; rhp[kj][jou]=rhp[kj][jou]-ggx;
   rpp[yp+4][jou]=rpp[yp+4][jou]+ggx*0.5+ggy*0.5;   
    }
    }}

      //----------------------------- interaction among ele (8-11) 

    for (int yp=8; yp <=11; yp++) {    
    for (int kj=8; kj <=11; kj++) {
    if (yp > kj) { 
    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;}
    pot=(elc*elc*6.241509e18)/(4*pai*epsi*kro*1.0e-14);   //potential energy (eV)
    rhp[yp][3]=rhp[yp][3]+pot/2.0; rhp[kj][3]=rhp[kj][3]+pot/2.0;
    toav=toav+pot;

      for (int jou=0; jou <=2; jou++) {
   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 noxx and ele0-3 (and ele 4-7) 

    for (int rv=0; rv <=3; rv++) {     
                      // kro=distance between electrons 0-3 and noxx[0][]  
    kro=Math.sqrt((hpr[rv][0]-noxx[0][0])*(hpr[rv][0]-noxx[0][0])+
   (hpr[rv][1]-noxx[0][1])*(hpr[rv][1]-noxx[0][1])+
   (hpr[rv][2]-noxx[0][2])*(hpr[rv][2]-noxx[0][2]));
    if (kro == 0) {kro=5000.0;} 
                     // kro2=distance between electrons 4-7 and noxx[1][] 
    kro2=Math.sqrt((hpr[rv+4][0]-noxx[1][0])*(hpr[rv+4][0]-noxx[1][0])+
   (hpr[rv+4][1]-noxx[1][1])*(hpr[rv+4][1]-noxx[1][1])+
   (hpr[rv+4][2]-noxx[1][2])*(hpr[rv+4][2]-noxx[1][2]));
    if (kro2 == 0) {kro2=5000.0;}   
       ppot=(elc*elc*den*6.241509e18)/(4*pai*epsi*kro*1.0e-14);
      teqq[rv][3]=teqq[rv][3]-ppot;   // teqq[0-3][3]=potential energy only in carbon 0 atom
        potb=(elc*elc*den*6.241509e18)/(4*pai*epsi*kro2*1.0e-14);
      teqq[rv+4][3]=teqq[rv+4][3]-potb;  // teqq[4-7][3]=potential energy only in carbon 1 atom
    for (int jou=0; jou <=2; jou++) {
     ggx=(suh*den*(hpr[rv][jou]-noxx[0][jou]))/(kro*kro*kro);
     ggy=(suh*den*(hpr[rv+4][jou]-noxx[1][jou]))/(kro2*kro2*kro2);
                                // teqq[][0-2]=force components only in carbon  atom
     teqq[rv][jou]=teqq[rv][jou]-ggx; teqq[rv+4][jou]=teqq[rv+4][jou]-ggy;
     }}

                                    // interaction between electrons and nuclei
   for (int rv=0; rv <=11; rv++) {    
                                              // ---------------- C 0,1nucleus

   for (int yp=0; yp <=1; yp++) {
   kro=Math.sqrt((hpr[rv][0]-nux[yp][0])*(hpr[rv][0]-nux[yp][0])+
   (hpr[rv][1]-nux[yp][1])*(hpr[rv][1]-nux[yp][1])+
   (hpr[rv][2]-nux[yp][2])*(hpr[rv][2]-nux[yp][2])); kro2=1000.0;
    if (kro == 0) {kro=5000.0;}
                             // kro2=distance between hpr2[8-11][0-2] and C nucleus
   if (rv > 7) {kro2=Math.sqrt((hpr2[rv][0]-nux[yp][0])*(hpr2[rv][0]-nux[yp][0])+
   (hpr2[rv][1]-nux[yp][1])*(hpr2[rv][1]-nux[yp][1])+
   (hpr2[rv][2]-nux[yp][2])*(hpr2[rv][2]-nux[yp][2])); 
    if (kro2 == 0) {kro2=5000.0;}
     }

    pot =-den/kro;         
   ttav= (elc*elc*6.241509e18*pot)/(4*pai*epsi*1.0e-14);  // ttav=potential energy (eV)
   rhp[rv][3]=rhp[rv][3]+ttav;  toav=toav+ttav;   gx=0;
      
        
   if (rv < 4 && yp==0) {ex=(int)(kro); gx=1; 
                          // show distance between electrons 0,1,2 and C0 nucleus
   if (rv < 3) {elp[rv][3].setText("nuc "+Integer.toString(ex)); }
    }

   if (rv > 3 && rv < 8) { 
       if (yp==1) {ex=(int)(kro);  gx=2;
     if (rv < 7)  {elp[rv-1][3].setText("nuc "+Integer.toString(ex));} }
    }   
                       // rhp[rv][5]=interaction between each electron and other nuclei
   if (gx==0) {rhp[rv][5]=rhp[rv][5]+ttav;}

   for (int kj=0; kj <=2; kj++) {    
                    // ggx (ggy) = force component between C nucleus and each electron                                      
   ggx=(suh*den*(hpr[rv][kj]-nux[yp][kj]))/(kro*kro*kro); ggy=ggx;
   if (rv > 7) {ggy=(suh*den*(hpr2[rv][kj]-nux[yp][kj]))/(kro2*kro2*kro2);}
                     // mmp[0-1][0-2]=force component acting on C0,1nuclei
    mmp[yp][kj]=mmp[yp][kj]+ggx;  rhp[rv][kj]=rhp[rv][kj]-ggx;
                 // rpp[0-7][0-2] = the total force from other nuclei's electrons and 6 nuclei   
   if (rv < 8) {rpp[rv][kj]=rpp[rv][kj]-ggx;}
   }
    }  

                               // ----------------------------- H nuclei (nux[2-5][])

    for (int yp=2; yp <=5; yp++) { 
      krr=Math.sqrt((hpr[rv][0]-nux[yp][0])*(hpr[rv][0]-nux[yp][0])+
    (hpr[rv][1]-nux[yp][1])*(hpr[rv][1]-nux[yp][1])+
    (hpr[rv][2]-nux[yp][2])*(hpr[rv][2]-nux[yp][2])); krr2=1000.0;
   if (krr ==0) {krr=5000.0;}

   if (rv > 7) {krr2=Math.sqrt((hpr2[rv][0]-nux[yp][0])*(hpr2[rv][0]-nux[yp][0])+
   (hpr2[rv][1]-nux[yp][1])*(hpr2[rv][1]-nux[yp][1])+
   (hpr2[rv][2]-nux[yp][2])*(hpr2[rv][2]-nux[yp][2])); 
    if (krr2 == 0) {krr2=5000.0;}
     }
      pota=-1.0/krr;
     ttav= (elc*elc*6.241509e18*pota)/(4*pai*epsi*1.0e-14);  // ttav=potential energy (eV)
     rhp[rv][3]=rhp[rv][3]+ttav;  toav=toav+ttav;
    
      if (rv==yp+6) {ex=(int)(krr); 
                    // show distance between electron (8,9,10) and nucleus (H0,H1,H2)
     if (rv > 7 && rv < 11) { elp[rv-2][3].setText("nuc "+Integer.toString(ex));}}

                    // rhp[rv][5]=interaction between each electron and other nuclei
      if (rv != yp+6) {rhp[rv][5]=rhp[rv][5]+ttav;}
   for (int kj=0; kj <=2; kj++) {
   ggx=(suh*(hpr[rv][kj]-nux[yp][kj]))/(krr*krr*krr); ggy=ggx;
   if (rv > 7) {ggy=(suh*(hpr2[rv][kj]-nux[yp][kj]))/(krr2*krr2*krr2);}
                            // mmp[2,3][0-2]=force component acting on H0, H2 nuclei
  if (yp==2) {mmp[2][kj]=mmp[2][kj]+ggx/2.0+ggy/2.0;} 
  if (yp==4) {mmp[3][kj]=mmp[3][kj]+ggx/2.0+ggy/2.0;}  
  rhp[rv][kj]=rhp[rv][kj]-ggx;
   if (rv < 8) {rpp[rv][kj]=rpp[rv][kj]-ggx;}
   }
   }  
   }        
    
                
    potc=0.0; double potf=0.0;
    for (int rv=0; rv <=5; rv++) {         // interaction among 6 nuclei
    for (int el=0; el <=5; el++) {
     if (rv > el) {
     kro=Math.sqrt((nux[rv][0]-nux[el][0])*(nux[rv][0]-nux[el][0])+
  (nux[rv][1]-nux[el][1])*(nux[rv][1]-nux[el][1])+
   (nux[rv][2]-nux[el][2])*(nux[rv][2]-nux[el][2]));

    ttav=(elc*elc*6.241509e18*nux[rv][3]*nux[el][3])/(4*pai*epsi*kro*1.0e-14);
    toav=toav+ttav; potc=potc+ttav;    // potc=the sum of potential energy among 6 nuclei
      for (int jou=0; jou <=2; jou++) {
     ggx=(suh*nux[rv][3]*nux[el][3]*(nux[rv][jou]-nux[el][jou]))/(kro*kro*kro);
     if (rv < 3) {mmp[rv][jou]=mmp[rv][jou]+ggx;}  
     if (rv==4) {mmp[3][jou]=mmp[3][jou]+ggx;}
     if (el < 3) {mmp[el][jou]=mmp[el][jou]-ggx;}
     if (el==4) {mmp[3][jou]=mmp[3][jou]-ggx;}
    }
   }   
   }}    
   
     for (int rv=0; rv <=5; rv++) {       // interaction among 6 nuclei (original position)
    for (int el=0; el <=5; el++) {
     if (rv > el) {
     kro=Math.sqrt((nux2[rv][0]-nux2[el][0])*(nux2[rv][0]-nux2[el][0])+
  (nux2[rv][1]-nux2[el][1])*(nux2[rv][1]-nux2[el][1])+
   (nux2[rv][2]-nux2[el][2])*(nux2[rv][2]-nux2[el][2]));

    ttav=(elc*elc*6.241509e18*nux2[rv][3]*nux2[el][3])/(4*pai*epsi*kro*1.0e-14);
    potf=potf+ttav;  // potf=the sum of potential energy among 6 nuclei of original positions
    }}}
                                      
   ex=(int)(100*(toav-potc+potf)); ggx=ex/100.0;
   impho.setText("tV "+Double.toString(ggx));     // show total V to two decimal places
 
                 // distribute repulsive V among nuclei to each electron based on rhp[][5]
     double hiwa=0.0;
  for (int rv=0; rv <=11; rv++) { hiwa=hiwa+rhp[rv][5]; }
  for (int rv=0; rv <=11; rv++) {
  rhp[rv][3]=rhp[rv][3]+(potc*rhp[rv][5])/hiwa;
  
   ex=(int)(100*rhp[rv][3]); ggx=ex/100.0;
   if (rv < 3) {elp[rv][4].setText("V "+Double.toString(ggx));}
    if (rv > 3 && rv <7) {elp[rv-1][4].setText("V "+Double.toString(ggx));}
    if (rv > 7 && rv <11) {elp[rv-2][4].setText("V "+Double.toString(ggx));}
   }

   gx=0.0;                       // gx=sum of each potential energy
   for (int rv=0; rv <=11; rv++) { gx=gx+rhp[rv][3]; }    
                               
   gy=-toav*0.5;             // gy=total kinetic energy         
                        // distribute kinetic energy to each electron based on rhp[][3]
   for (int rv=0; rv <=11; rv++) {       
    gz=(gy*rhp[rv][3])/gx; rhp[rv][4]=gz;    
   ex=(int)(100*gz); gz=ex/100.0; 
    if (rv <3) {elp[rv][5].setText("T "+Double.toString(gz));}
    if (rv > 3 && rv <7) {elp[rv-1][5].setText("T "+Double.toString(gz));} 
    if (rv > 7 && rv < 11) {elp[rv-2][5].setText("T "+Double.toString(gz));}
    }               
   
    int rvv=0;
    for (int el=0; el <=1; el++) {
    for (int rv=0; rv <=3; rv++) {        // show force component acting on elctrons 0-7 
    rvv=rv+el*4;
    gx=Math.sqrt(rpp[rvv][0]*rpp[rvv][0]+rpp[rvv][1]*rpp[rvv][1]+rpp[rvv][2]*rpp[rvv][2]);
                     // gy=inner product of rhp and rpp = force in the direction of rpp
    gy=(rhp[rvv][0]*rpp[rvv][0]+rhp[rvv][1]*rpp[rvv][1]+rhp[rvv][2]*rpp[rvv][2])/gx;
    ex=(int)(1000*gy); ww="CF ";
    if (rvv < 3) {elp[rvv][6].setText(ww+Integer.toString(ex));}
    if (rvv > 3 && rvv <7) {elp[rvv-1][6].setText(ww+Integer.toString(ex));}
    for (int jou=0; jou <=2; jou++) {                                 
    gz=rhp[rvv][jou]-(gy*rpp[rvv][jou])/gx;
    ex=(int)(1000*gz);       // show force component other than CF
    if (rvv < 3) {elp[rvv][jou+7].setText(Integer.toString(ex));}
    if (rvv > 3 && rvv <7) {elp[rvv-1][jou+7].setText(Integer.toString(ex));}
     }
    }}


  for (int rv=8; rv <=11; rv++) {      // show force component acting on electron 8-11
   ez=0; if (rv > 9) {ez=1;}           
                                // ggy=distance between C-H (nuclei)         
   ggy=Math.sqrt((nux[ez][0]-nux[rv-6][0])*(nux[ez][0]-nux[rv-6][0])+
  (nux[ez][1]-nux[rv-6][1])*(nux[ez][1]-nux[rv-6][1])+(nux[ez][2]-nux[rv-6][2])*(nux[ez][2]-nux[rv-6][2]));   
                                // gy=inner product
  gy=((nux[ez][0]-hpr[rv][0])*(nux[ez][0]-nux[rv-6][0])+
  (nux[ez][1]-hpr[rv][1])*(nux[ez][1]-nux[rv-6][1])+(nux[ez][2]-hpr[rv][2])*(nux[ez][2]-nux[rv-6][2]))/ggy;

    double ttj[][]=new double[6][4];
    for (int jou=0; jou <=2; jou++) {
                         // ttj[][0-2]=vector perpendicular to each C-H line
    ttj[rv-8][jou]=(gy*(nux[rv-6][jou]-nux[ez][jou]))/ggy-(hpr[rv][jou]-nux[ez][jou]);
     }

    ggz=Math.sqrt(ttj[rv-8][0]*ttj[rv-8][0]+ttj[rv-8][1]*ttj[rv-8][1]+ttj[rv-8][2]*ttj[rv-8][2]);
           // gz= force component (CF) in the direction of ttj = inner product of rhp and ttj 
    gz=(rhp[rv][0]*ttj[rv-8][0]+rhp[rv][1]*ttj[rv-8][1]+rhp[rv][2]*ttj[rv-8][2])/ggz;
    ex=(int)(1000*gz); ww="CF ";
   if (rv <10 ) {elp[rv-2][6].setText(ww+Integer.toString(ex));}
   if (rv==10 ) {elp[8][6].setText(ww+Integer.toString(ex));}

    for (int jou=0; jou <=2; jou++) {     // show force component other than CF
     gx=rhp[rv][jou]-(gz*ttj[rv-8][jou])/ggz;
     ex=(int)(1000*gx); 
     if (rv <10) {elp[rv-2][jou+7].setText(Integer.toString(ex));}
     if (rv==10) {elp[8][jou+7].setText(Integer.toString(ex));}
     }
    }
                                              

    for (int rv=0; rv <=3; rv++) {
    for (int jou=0; jou <=2; jou++) {       // show mmpho[0-3][0-2]= force acting on each nuclei
    ex=(int)(1000*mmp[rv][jou]); ww=" ";
   if (jou==0) {ww="FX=";}
   if (jou==1) {ww="FY=";}
   if (jou==2) {ww="FZ=";}
    mmpho[rv][jou].setText(ww+Integer.toString(ex));
    }}
   
    // ggy=distance between C0 and H0 nuclei
   ggy=Math.sqrt((nux[0][0]-nux[2][0])*(nux[0][0]-nux[2][0])+
  (nux[0][1]-nux[2][1])*(nux[0][1]-nux[2][1])+(nux[0][2]-nux[2][2])*(nux[0][2]-nux[2][2]));

                   // ggz=force component of H0 nucleus toward C0 nucleus 
  ggz=(mmp[2][0]*(nux[0][0]-nux[2][0])+mmp[2][1]*(nux[0][1]-nux[2][1])+mmp[2][2]*(nux[0][2]-nux[2][2]))/ggy;
  imppo.setText("CnH0 = "+Integer.toString((int)(1000*ggz)));

  // ggy=distance between C1 and H2 nuclei
   ggy=Math.sqrt((nux[1][0]-nux[4][0])*(nux[1][0]-nux[4][0])+
  (nux[1][1]-nux[4][1])*(nux[1][1]-nux[4][1])+(nux[1][2]-nux[4][2])*(nux[1][2]-nux[4][2]));

                   // ggz=force component of H0 nucleus toward C0 nucleus 
  ggz=(mmp[3][0]*(nux[1][0]-nux[4][0])+mmp[3][1]*(nux[1][1]-nux[4][1])+mmp[3][2]*(nux[1][2]-nux[4][2]))/ggy;
  imppp.setText("CnH2 = "+Integer.toString((int)(1000*ggz)));
                                                                           
                                 
   for (int rv=0; rv <=11; rv++) {         // show de Broglie wave of each electron
   
   gz=Math.sqrt(rhp[rv][0]*rhp[rv][0]+rhp[rv][1]*rhp[rv][1]+rhp[rv][2]*rhp[rv][2]);
   
   if (rv <8) {gz=Math.sqrt(teqq[rv][0]*teqq[rv][0]+teqq[rv][1]*teqq[rv][1]+teqq[rv][2]*teqq[rv][2]);
    }

   gy=(gz*elc*elc)/(4*pai*epsi*suh*1.0e-28);    // gy=force (N)
   gx=Math.sqrt((2*rhp[rv][4]*1.602177e-19)/me);  // gx=velocity (m/s) from kinetic energy

                         // electrons 0-4 use potential V (and T) only in carbon atom
   if (rv < 8) { gx=Math.sqrt((-teqq[rv][3]*1.602177e-19)/me); }

   ggx=(me*gx*gx)/gy;             // ggx= "tenporary" radius (m)
   ggy=(2*pai*ggx*me*gx)/h;    // ggy (wn) = number of de Broglie's waves contained in one orbit 
   
  ex=(int)(ggy*1000);  ggy=ex/1000.0;   // show wn to three decimal places
  if (rv <3) {elp[rv][10].setText("wn "+Double.toString(ggy));}
  if (rv >3 && rv <7) {elp[rv-1][10].setText("wn "+Double.toString(ggy));}
  if (rv >7 && rv <11) {elp[rv-2][10].setText("wn "+Double.toString(ggy));}
   }

                          // --------------------- show picture
   int nmx[][]=new int[8][3]; int hpk[][]=new int[12][4]; 

 
  for (int yp=0; yp <=5; yp++) {
  for (int kj=0; kj <=2; kj++) {     // change MM to pixel in nuclei
  nmx[yp][kj]=(int)(nux[yp][kj]/71.428);
  }}
  for (int yp=0; yp <=11; yp++) {
  for (int kj=0; kj <=2; kj++) {     // change MM to pixel in electrons
  hpk[yp][kj]=(int)(hpr[yp][kj]/71.428);
   if (hpk[yp][kj] > 529 && kj==0) {hpk[yp][kj]=529;}    // upper and lower limit
   if (hpk[yp][kj] > 369 && kj > 0) {hpk[yp][kj]=369;} 
   if (hpk[yp][kj] < 1) {hpk[yp][kj]=1;}
  }}

  g.clearRect(9,299,1170,699);
  g.setColor(Color.cyan); g.drawLine(555,310,555,660); 

  

    for (int rv=0; rv <=11; rv++) {
    g.setColor(Color.blue);
  if (rv < 4) {g.drawLine(hpk[rv][0]+20,680-hpk[rv][1],nmx[0][0]+20,680-nmx[0][1]);
      g.drawLine(hpk[rv][0]+560,680-hpk[rv][2],nmx[0][0]+560,680-nmx[0][2]);}
  if (rv < 8 && rv > 3) {g.drawLine(hpk[rv][0]+20,680-hpk[rv][1],nmx[1][0]+20,680-nmx[1][1]);
      g.drawLine(hpk[rv][0]+560,680-hpk[rv][2],nmx[1][0]+560,680-nmx[1][2]);}

  g.setColor(Color.white);           // set color based on electron
  if (rv > 1 && rv < 4) {g.setColor(Color.red);}
  if (rv > 3 && rv < 6) {g.setColor(Color.green);}
   if (rv > 5 && rv < 8) {g.setColor(Color.pink);}
    if (rv > 7 && rv < 10) {g.setColor(Color.green);}
    if (rv > 9 && rv < 12) {g.setColor(Color.yellow);}
       
  g.fillOval(hpk[rv][0]+13,673-hpk[rv][1],14,14); 
  g.fillOval(hpk[rv][0]+553,673-hpk[rv][2],14,14);
  }
   
   g.setColor(Color.lightGray);         // show six nuclei
  for (int rv=0; rv <=1; rv++) {
  g.fillOval(nmx[rv][0]+10,670-nmx[rv][1],20,20);g.fillOval(550+nmx[rv][0],670-nmx[0][2],20,20);
   }
   for (int rv=2; rv <=5; rv++) {
  g.fillOval(13+nmx[rv][0],673-nmx[rv][1],14,14);g.fillOval(553+nmx[rv][0],673-nmx[rv][2],14,14);
  } 
  
  for (int rw=0; rw <=5; rw++) {         // show each nucleus number
  g.setColor(Color.white);
  if (rw < 2) { ww="C"+Integer.toString(rw);
  g.drawString(ww,nmx[rw][0]+13,685-nmx[rw][1]);
  g.drawString(ww,nmx[rw][0]+553,685-nmx[rw][2] );}
  if (rw > 1) { ex=rw-2; ww="H"+Integer.toString(ex);
   g.drawString(ww,nmx[rw][0]+13,685-nmx[rw][1]);
  g.drawString(ww,nmx[rw][0]+553,685-nmx[rw][2] );}  
  }                                
    
  for (int rw=0; rw <=11; rw++) {         // show each electron's number
  g.setColor(Color.blue);
  if (rw < 10) {
  g.drawString(Integer.toString(rw),hpk[rw][0]+17,685-hpk[rw][1]);
  g.drawString(Integer.toString(rw),hpk[rw][0]+557,685-hpk[rw][2] );}
  if (rw > 9) {
   g.drawString(Integer.toString(rw),hpk[rw][0]+14,685-hpk[rw][1]);
  g.drawString(Integer.toString(rw),hpk[rw][0]+554,685-hpk[rw][2] );}
    
  }
   }
   }