#[cfg(feature = "extern")]
pub mod ex;
#[cfg(feature = "python")]
pub mod py;
mod test;
pub mod legendre;
use std::f64::consts::PI;
use crate::physics::
{
PLANCK_CONSTANT,
BOLTZMANN_CONSTANT
};
pub struct FJC
{
pub hinge_mass: f64,
pub link_length: f64,
pub number_of_links: u8,
pub legendre: legendre::FJC
}
pub fn end_to_end_length(number_of_links: &u8, link_length: &f64, force: &f64, temperature: &f64) -> f64
{
let nondimensional_force = force/BOLTZMANN_CONSTANT/temperature*link_length;
(1.0/nondimensional_force.tanh() - 1.0/nondimensional_force)*(*number_of_links as f64)*link_length
}
pub fn end_to_end_length_per_link(link_length: &f64, force: &f64, temperature: &f64) -> f64
{
let nondimensional_force = force/BOLTZMANN_CONSTANT/temperature*link_length;
(1.0/nondimensional_force.tanh() - 1.0/nondimensional_force)*link_length
}
pub fn nondimensional_end_to_end_length(number_of_links: &u8, nondimensional_force: &f64) -> f64
{
(1.0/nondimensional_force.tanh() - 1.0/nondimensional_force)*(*number_of_links as f64)
}
pub fn nondimensional_end_to_end_length_per_link(nondimensional_force: &f64) -> f64
{
1.0/nondimensional_force.tanh() - 1.0/nondimensional_force
}
pub fn gibbs_free_energy(number_of_links: &u8, link_length: &f64, hinge_mass: &f64, force: &f64, temperature: &f64) -> f64
{
relative_gibbs_free_energy(number_of_links, link_length, force, temperature) - (*number_of_links as f64)*BOLTZMANN_CONSTANT*temperature*(8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln()
}
pub fn gibbs_free_energy_per_link(link_length: &f64, hinge_mass: &f64, force: &f64, temperature: &f64) -> f64
{
relative_gibbs_free_energy_per_link(link_length, force, temperature) - BOLTZMANN_CONSTANT*temperature*(8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln()
}
pub fn relative_gibbs_free_energy(number_of_links: &u8, link_length: &f64, force: &f64, temperature: &f64) -> f64
{
nondimensional_relative_gibbs_free_energy(number_of_links, &(force/BOLTZMANN_CONSTANT/temperature*link_length))*BOLTZMANN_CONSTANT*temperature
}
pub fn relative_gibbs_free_energy_per_link(link_length: &f64, force: &f64, temperature: &f64) -> f64
{
nondimensional_relative_gibbs_free_energy_per_link(&(force/BOLTZMANN_CONSTANT/temperature*link_length))*BOLTZMANN_CONSTANT*temperature
}
pub fn nondimensional_gibbs_free_energy(number_of_links: &u8, link_length: &f64, hinge_mass: &f64, nondimensional_force: &f64, temperature: &f64) -> f64
{
(*number_of_links as f64)*(-(nondimensional_force.sinh()/nondimensional_force).ln() - (8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln())
}
pub fn nondimensional_gibbs_free_energy_per_link(link_length: &f64, hinge_mass: &f64, nondimensional_force: &f64, temperature: &f64) -> f64
{
-(nondimensional_force.sinh()/nondimensional_force).ln() - (8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln()
}
pub fn nondimensional_relative_gibbs_free_energy(number_of_links: &u8, nondimensional_force: &f64) -> f64
{
-(*number_of_links as f64)*(nondimensional_force.sinh()/nondimensional_force).ln()
}
pub fn nondimensional_relative_gibbs_free_energy_per_link(nondimensional_force: &f64) -> f64
{
-(nondimensional_force.sinh()/nondimensional_force).ln()
}
impl FJC
{
pub fn init(number_of_links: u8, link_length: f64, hinge_mass: f64) -> Self
{
FJC
{
hinge_mass,
link_length,
number_of_links,
legendre: legendre::FJC::init(number_of_links, link_length, hinge_mass)
}
}
pub fn end_to_end_length(&self, force: &f64, temperature: &f64) -> f64
{
end_to_end_length(&self.number_of_links, &self.link_length, force, temperature)
}
pub fn end_to_end_length_per_link(&self, force: &f64, temperature: &f64) -> f64
{
end_to_end_length_per_link(&self.link_length, force, temperature)
}
pub fn nondimensional_end_to_end_length(&self, nondimensional_force: &f64) -> f64
{
nondimensional_end_to_end_length(&self.number_of_links, nondimensional_force)
}
pub fn nondimensional_end_to_end_length_per_link(&self, nondimensional_force: &f64) -> f64
{
nondimensional_end_to_end_length_per_link(nondimensional_force)
}
pub fn gibbs_free_energy(&self, force: &f64, temperature: &f64) -> f64
{
gibbs_free_energy(&self.number_of_links, &self.link_length, &self.hinge_mass, force, temperature)
}
pub fn gibbs_free_energy_per_link(&self, force: &f64, temperature: &f64) -> f64
{
gibbs_free_energy_per_link(&self.link_length, &self.hinge_mass, force, temperature)
}
pub fn relative_gibbs_free_energy(&self, force: &f64, temperature: &f64) -> f64
{
relative_gibbs_free_energy(&self.number_of_links, &self.link_length, force, temperature)
}
pub fn relative_gibbs_free_energy_per_link(&self, force: &f64, temperature: &f64) -> f64
{
relative_gibbs_free_energy_per_link(&self.link_length, force, temperature)
}
pub fn nondimensional_gibbs_free_energy(&self, nondimensional_force: &f64, temperature: &f64) -> f64
{
nondimensional_gibbs_free_energy(&self.number_of_links, &self.link_length, &self.hinge_mass, nondimensional_force, temperature)
}
pub fn nondimensional_gibbs_free_energy_per_link(&self, nondimensional_force: &f64, temperature: &f64) -> f64
{
nondimensional_gibbs_free_energy_per_link(&self.link_length, &self.hinge_mass, nondimensional_force, temperature)
}
pub fn nondimensional_relative_gibbs_free_energy(&self, nondimensional_force: &f64) -> f64
{
nondimensional_relative_gibbs_free_energy(&self.number_of_links, nondimensional_force)
}
pub fn nondimensional_relative_gibbs_free_energy_per_link(&self, nondimensional_force: &f64) -> f64
{
nondimensional_relative_gibbs_free_energy_per_link(nondimensional_force)
}
}