Package com.molecular_java
Class Physics
java.lang.Object
com.molecular_java.Physics
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleMethod counts angle between the tree given balls.static doublebendingPotential(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.static doublebendingPotentialInSystem(SimSpace s, double factor, List<Ball> balls) Method counts bending potential of the system represented by balls in a list.static DoubleThe Boltzmann's factor is count from the temperature and the difference between potentials.static DoublecalculatePotential(SimSpace s, List<Ball> balls, int b1, int b2, Double factor) This method calculates potential for 2 functions -- PotentialInSystem and Pressure in system.static Double[]Computes a position of center of mass of balls in given simulation space.static double[]crossProduct(double[] v1, double[] v2) Cross product for 3D vectors.static DoubledistanceOfTwoBalls(SimSpace s, Ball ball1, Ball ball2) A method to count distance of two given molecules.static doubledot(double[] vector1, double[] vector2) Dot for 3D vectors in an array.static DoublegetPotentialFromTable(Double[][] potentialTable, Double rad) For given value of angle (rad) returns a potentials value from the given table.static DoublehardSpheresForce(Double sigma, Double distance) Counting of force by the "Hard-Spheres" method.static DoublehardSpheresPotential(Double sigma, Double distance) Counts "Hard-Spheres potential".static DoublelennardJonesForce(Double epsilon, Double sigma, Double distance) Counting of force by the "Lennard-Jones" formula.static DoublelennardJonesPotential(SimSpace s, Ball ball1, Ball ball2, Double distance) Method to count "Lennard-Jones potential".static DoublepotentialInSystem(SimSpace s, double factor, List<Ball> balls) Method counts a potential in a system represented by balls in list.static DoubleThis method counts the gyration radius of the balls in system.static DoublesquareWellForce(Double epsilon, Double sigma, Double distance, Double lambda) Counting of force by the "Square-Well" method.static DoublesquareWellPotential(Double epsilon, Double sigma, Double distance, Double lambda) A little bit more complex potential function with discrete stays.static doublevectorLength(double[] vector) Counts a length of given 3D vector.static double[]vectorMultip(double[] v, double r) 3D Vector multiplication.
-
Constructor Details
-
Physics
public Physics()
-
-
Method Details
-
lennardJonesPotential
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 simulationball1- ball for which the potential will be countball2- ball for which the potential will be countdistance- distance of the two given balls- Returns:
- the method returns a value of LJ potential for given values.
-
hardSpheresPotential
Counts "Hard-Spheres potential". It is the simpliest potential which giveszeroif the particles do not touch each other and infinity if they do touch each other.- Parameters:
sigma- is equal to the diameter of particlesdistance- 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 particlesdistance- usually a distance of the two balls the potential is counted forlambda- defines the width of the "well"- Returns:
- potential
-
lennardJonesForce
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 particlesdistance- usually a distance of the two balls the potential is counted for- Returns:
- force
-
hardSpheresForce
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 particlesdistance- usually a distance of the two balls the potential is counted for- Returns:
- force
-
squareWellForce
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 particlesdistance- a distance of the two balls the potential is counted forlambda- defines the depth of potential valley- Returns:
- force
-
distanceOfTwoBalls
A method to count distance of two given molecules.- Parameters:
s- Simulation space.ball1- 1st ballball2- 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 usesswitchconstruction to choose which type of potential it is going to be used. TheSimSpace scontains a variable for the switch.- Parameters:
s- simulation spaceballs- list of ballsb1- index of ball1b2- index of ball2factor- 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 spacefactor- Factor for scalingballs- 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
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 thecenterOfMass(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
Computes a position of center of mass of balls in given simulation space. Used inradiusOfGyration(SimSpace)- Parameters:
s- is the simulation space- Returns:
- center of mass represented by a vector in
Double[] - See Also:
-
angle
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 1v2- vector 2- Returns:
- cross product of v1 and v2
-
vectorMultip
public static double[] vectorMultip(double[] v, double r) 3D Vector multiplication.- Parameters:
v- vectorr- 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
Method counts bending potential of the system represented by balls in a list. UsesbendingPotential(SimSpace, Ball, Ball, Ball)as a subroutine. It is called from theMain.PivotMovesSimulation().- Parameters:
s- simulation spacefactor- 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
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 inbendingPotentialInSystem(SimSpace, double, List).- Parameters:
s- simulation spaceball1- has a bond to ball2ball2- has a bond to ball1 and ball3ball3- has a bond to ball2- Returns:
- bending potential of given balls
- See Also:
-
boltzmannsFactor
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
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).
-