Class Physics

java.lang.Object
com.molecular_java.Physics

public class Physics extends Object
This class makes the "physical engine" behind the simulation. When some method wants to count potential, force, pressure, distance between two Ball objects or so, a method for that is here. This class also contains methods for moving balls in the simulation space.
  • Constructor Details

    • Physics

      public Physics()
  • Method Details

    • lennardJonesPotential

      public static Double lennardJonesPotential(SimSpace s, Ball ball1, Ball ball2, Double distance)
      Method to count "Lennard-Jones potential". It is harmonic potential very well used for many types of molecular simulatons.
      Parameters:
      s - contains the variables needed for the simulation
      ball1 - ball for which the potential will be count
      ball2 - ball for which the potential will be count
      distance - distance of the two given balls
      Returns:
      the method returns a value of LJ potential for given values.
    • hardSpheresPotential

      public static Double hardSpheresPotential(Double sigma, Double distance)
      Counts "Hard-Spheres potential". It is the simpliest potential which gives zero if the particles do not touch each other and infinity if they do touch each other.
      Parameters:
      sigma - is equal to the diameter of particles
      distance - usually a distance of the two balls the potential is counted for.
      Returns:
      potential
    • squareWellPotential

      public static Double squareWellPotential(Double epsilon, Double sigma, Double distance, Double lambda)
      A little bit more complex potential function with discrete stays.
      Parameters:
      epsilon - defines the depth of the "well"
      sigma - defines is equal to the diameter of particles
      distance - usually a distance of the two balls the potential is counted for
      lambda - defines the width of the "well"
      Returns:
      potential
    • lennardJonesForce

      public static Double lennardJonesForce(Double epsilon, Double sigma, Double distance)
      Counting of force by the "Lennard-Jones" formula. It is basically a "Lennard-Jones" potential formula derived by the distance.
      Parameters:
      epsilon - defines the depth of the "well"
      sigma - is a parameter equal to the diameter of particles
      distance - usually a distance of the two balls the potential is counted for
      Returns:
      force
    • hardSpheresForce

      public static Double hardSpheresForce(Double sigma, Double distance)
      Counting of force by the "Hard-Spheres" method. It is basically a "Hard-Spheres" potential formula derived by the distance.
      Parameters:
      sigma - is a parameter equal to the diameter of particles
      distance - usually a distance of the two balls the potential is counted for
      Returns:
      force
    • squareWellForce

      public static Double squareWellForce(Double epsilon, Double sigma, Double distance, Double lambda)
      Counting of force by the "Square-Well" method. It is basically a "Square-Well" potential formula derived by the distance.
      Parameters:
      epsilon - defines the depth of the "well"
      sigma - is a parameter equal to the diameter of particles
      distance - a distance of the two balls the potential is counted for
      lambda - defines the depth of potential valley
      Returns:
      force
    • distanceOfTwoBalls

      public static Double distanceOfTwoBalls(SimSpace s, Ball ball1, Ball ball2)
      A method to count distance of two given molecules.
      Parameters:
      s - Simulation space.
      ball1 - 1st ball
      ball2 - 2nd ball Quite important constant -- affects scaling of the distance. Usually equal 1, however it can have different values for different types of wanted pressure.
      Returns:
      distance of two balls
    • calculatePotential

      public static Double calculatePotential(SimSpace s, List<Ball> balls, int b1, int b2, Double factor) throws OperationNotSupportedException
      This method calculates potential for 2 functions -- PotentialInSystem and Pressure in system. For each of them it has different factor for scaling. It can count 3 types of potential -- LJ, HS and SW, however only LJ is legit for more realistic simulations. It uses switch construction to choose which type of potential it is going to be used. The SimSpace s contains a variable for the switch.
      Parameters:
      s - simulation space
      balls - list of balls
      b1 - index of ball1
      b2 - index of ball2
      factor - factor for scaling
      Returns:
      potential of two balls
      Throws:
      OperationNotSupportedException - if the parameters are not given properly.. See the error description.
    • potentialInSystem

      public static Double potentialInSystem(SimSpace s, double factor, List<Ball> balls) throws OperationNotSupportedException
      Method counts a potential in a system represented by balls in list.
      Parameters:
      s - Simulation space
      factor - Factor for scaling
      balls - list of balls (Ball) to count potential over it
      Returns:
      potential in system
      Throws:
      OperationNotSupportedException - if the parameters are not given properly.. See the error description.
    • radiusOfGyration

      public static Double radiusOfGyration(SimSpace s)
      This method counts the gyration radius of the balls in system. It uses usual formula for it (e.g. https://en.wikipedia.org/wiki/Radius_of_gyration). It uses also the centerOfMass(SimSpace) method to get the center of mass.
      Parameters:
      s - is a simulation space, which contains the list of balls and constants needed for the computation.
      Returns:
      radius of gyration
    • centerOfMass

      public static Double[] centerOfMass(SimSpace s)
      Computes a position of center of mass of balls in given simulation space. Used in radiusOfGyration(SimSpace)
      Parameters:
      s - is the simulation space
      Returns:
      center of mass represented by a vector in Double[]
      See Also:
    • angle

      public static double angle(Ball ball1, Ball ball_middle, Ball ball2)
      Method counts angle between the tree given balls.
      Parameters:
      ball1 - 1st ball.
      ball_middle - the ball in the middle.
      ball2 - 2nd ball.
      Returns:
      double value of the angle between two given balls (vectors between them).
    • dot

      public static double dot(double[] vector1, double[] vector2)
      Dot for 3D vectors in an array.
      Parameters:
      vector1 - is the 1st given vector.
      vector2 - is the 2nd given vector.
      Returns:
      dot of the two given vectors.
    • crossProduct

      public static double[] crossProduct(double[] v1, double[] v2)
      Cross product for 3D vectors.
      Parameters:
      v1 - vector 1
      v2 - vector 2
      Returns:
      cross product of v1 and v2
    • vectorMultip

      public static double[] vectorMultip(double[] v, double r)
      3D Vector multiplication.
      Parameters:
      v - vector
      r - scalar
      Returns:
      multiplication of given vectors
    • vectorLength

      public static double vectorLength(double[] vector)
      Counts a length of given 3D vector.
      Parameters:
      vector - given vector
      Returns:
      length of the given vector
    • bendingPotentialInSystem

      public static double bendingPotentialInSystem(SimSpace s, double factor, List<Ball> balls)
      Method counts bending potential of the system represented by balls in a list. Uses bendingPotential(SimSpace, Ball, Ball, Ball) as a subroutine. It is called from the Main.PivotMovesSimulation().
      Parameters:
      s - simulation space
      factor - factor for scaling (equals 1 by default)
      balls - list of balls to count the bending potential over.
      Returns:
      bending potential in system
      See Also:
    • bendingPotential

      public static double bendingPotential(SimSpace s, Ball ball1, Ball ball2, Ball ball3)
      This function is used to count bending potential over three balls, assuming, that ball1 has bond to ball2 and ball2 has bond to ball3. Implements standard formula, see https://en.wikipedia.org/wiki/Law_of_cosines. It is used in bendingPotentialInSystem(SimSpace, double, List).
      Parameters:
      s - simulation space
      ball1 - has a bond to ball2
      ball2 - has a bond to ball1 and ball3
      ball3 - has a bond to ball2
      Returns:
      bending potential of given balls
      See Also:
    • boltzmannsFactor

      public static Double boltzmannsFactor(SimSpace s)
      The Boltzmann's factor is count from the temperature and the difference between potentials. The equation for it is: boltzmann = Math.exp(-beta * differenceBetweenPotentials); The temperature is included in the "beta" factor, which is count as follows: beta = 1/(k_B*T), where k_B is Boltzmann's constant and T is temperature in Kelvins. Currently, this function modifys the temperature in system, so it linearily changes from the initial state to the final state.
      Parameters:
      s - simulation space
      Returns:
      Boltzmann's factor for the right value of temperature in system.
    • getPotentialFromTable

      public static Double getPotentialFromTable(Double[][] potentialTable, Double rad)
      For given value of angle (rad) returns a potentials value from the given table.
      Parameters:
      potentialTable - table with degrees and their potential values.
      rad - angle in rads. (can be also distance for non-bonding potential)
      Returns:
      gets the nearest potential value according to the given rads (can be also distance for non-bonding potential).