module valenceenergymodule
contains
subroutine valenceenergy(rx,ry,rz,vx,vy,vz,Potential,KE,Etotal)

	implicit none
    double precision, dimension(:), intent(in) :: rx,ry,rz,vx,vy,vz
    double precision, dimension(:), intent(inout) :: Potential,KE,Etotal
    integer p1,p2,e1,e2,n1,n2,i,j
    double precision mp,mne,V,dx,dy,dz,rs 


mp=1836.1526    !proton/electron mass ratio
mne=1838.684    !neutron/electron mass ratio

p1=7
p2=12
e1=1
e2=6
n1=13
n2=18


!!!!! Calculating Potential Energy  !!!!!!!!


!Electron-Proton interaction

do i=e1,e2        !i particle and calculating for this only
    Potential(i)=0
    do j=p1,p2        !j particle pairing with i for pairs (i,j)

!!! pair (p-e) !!!
!i=electron
!j=proton

            dx=rx(i)-rx(j)
            dy=ry(i)-ry(j)
            dz=rz(i)-rz(j)



            rs=(dx*dx)+(dy*dy)+(dz*dz)     !new rs will consider MIC rs's also that are qualifed for cutoff filtrations
            rs=sqrt(rs)
            !p=rs

            V=4.0*((1.0/(1.5*(rs**1.5)))+(8.0*rs))
      
            Potential(i)=Potential(i)+V

    end do
end do


!Electron-Electron interaction

do i=e1,e2        !i particle and calculating for this only
    do j=e1,e2        !j particle pairing with i for pairs (i,j)

!!! pair (e-e) !!!
!i=electron
!j=electron

        if (i/=j) then

            dx=rx(i)-rx(j)
            dy=ry(i)-ry(j)
            dz=rz(i)-rz(j)



            rs=(dx*dx)+(dy*dy)+(dz*dz)     !new rs will consider MIC rs's also that are qualifed for cutoff filtrations
            rs=sqrt(rs)
            !p=rs

            V=4.0*((-1*(rs**0.8)/0.8)+(1.5*rs))
      
            Potential(i)=Potential(i)+V

        end if

    end do
end do




!!!!! Calculating Kinetic Energy  !!!!!!!!


do i=e1,e2        !i particle and calculating for this only


    KE(i)=0.5*(vx(i)*vx(i)+vy(i)*vy(i)+vz(i)*vz(i))

    Etotal(i)=KE(i)+Potential(i)
        

end do







end subroutine valenceenergy
end module valenceenergymodule
	  
