Bsoft 2.1.4
Bernard's software package
model_mechanics.cpp File Reference

Functions to do molecular mechanics. More...

#include "model_mechanics.h"
#include "model_poly.h"
#include "model_shell.h"
#include "model_transform.h"
#include "model_util.h"
#include "math_util.h"
#include "random_numbers.h"
#include "symmetry.h"
#include "Vector3.h"
#include "linked_list.h"
#include "utilities.h"

Macros

#define ETERMS   16
 

Functions

double model_mechanics (Bmodel *model, Bmodparam &md, int mm_type, int max_iter, double max_shift, double velocitylimit)
 Minimizes the energy of a model. More...
 
int model_minimize (Bmodel *model, double max_shift)
 Move components random distances down the energy gradient. More...
 
double model_verlet (Bmodel *model, double timestep, double Kfriction, double velocitylimit)
 Model dynamics using the velocity verlet integrator. More...
 
double component_harmonic_potential (Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
 
double component_soft_potential (Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
 
double component_lennard_jones_potential (Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
 
double component_morse_potential (Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
 
double component_angular_potential (Bcomponent *comp, Bcomponent *comp1, Bcomponent *comp2, double a0, double Ka)
 
double component_radial_potential (Bcomponent *comp, Vector3< double > point, double d0, double Kradial)
 
double component_distance_potential (Bcomponent *comp1, Bcomponent *comp2, double Kd, int type)
 
double component_electrostatic_potential (Bcomponent *comp1, Bcomponent *comp2, double q1, double q2, double Ke, double cutoff)
 
double model_electrostatic_energy (Bmodel *model, Bmodparam &md)
 Calculates the electrostatic potentials between components. More...
 
double model_distance_energy (Bmodel *model, Bmodparam &md)
 Calculates the distance-related potentials between components. More...
 
double model_grid_distance_energy (Bmodel *model, Bmodparam &md)
 Calculates the non-bonded forces and energy. More...
 
double model_neighbor_distance_energy (Bmodel *model, Bmodparam &md)
 Calculates the distance-related potentials between components and their neighbors. More...
 
double model_soft_sphere_energy (Bmodel *model, double Kd, double d0)
 Calculates the soft sphere potential between components. More...
 
double model_lennard_jones_energy (Bmodel *model, double Kd, double d0)
 Calculates the Lennard-Jones potential between components. More...
 
double model_morse_energy (Bmodel *model, double Kd, double d0)
 Calculates the Morse potential between components. More...
 
double model_link_energy (Bmodel *model, Bmodparam &md)
 Calculates the model link energy. More...
 
double model_link_energy (Bmodel *model, double Klink)
 Calculates the model link energy. More...
 
double model_angle_energy (Bmodel *model, Bmodparam &md)
 Calculates the model angular energy. More...
 
double model_polygon_angle_energy (Bmodel *model, double Kpolyangle)
 Calculates the link angular forces and energy. More...
 
double model_polygon_energy (Bmodel *model, double linklength, double Kpoly)
 Calculates the polygon regularity. More...
 
double model_polygon_energy (Bmodel *model, double Kpoly)
 Calculates the polygon regularity energy and forces. More...
 
double model_polygon_plane_energy (Bmodel *model, double Kpolyplane)
 Calculates the polygon planarity energy and forces. More...
 
double model_neighbor_plane_energy (Bmodel *model, double Kplane)
 Calculates the planarity energy and forces with respect to neighbors. More...
 
double model_point_force (Bmodel *model, Vector3< double > point, double Kpoint, double decay)
 Calculates the forces and energy resulting from a single point force. More...
 
double model_radial_energy (Bmodel *model, Vector3< double > point, double d0, double Kradial)
 Calculates the potential between a components and a point. More...
 
double model_guide_energy (Bmodel *model, Bmodparam &md)
 Calculates the potential with respect to a guide model. More...
 
double model_polyhedron_guide_energy (Bmodel *model, Bmodel *gmod, double Kguide)
 Calculates the potential with respect to a guide polyhedron. More...
 
double model_map_energy (Bmodel *model, Bimage *map, double Kmap)
 Energy calculation of a model into a map.
More...
 
double model_map_gradient_energy (Bmodel *model, Bimage *map, double Kmap)
 
double model_map_energy (Bmodel *model, Bimage *map, double Kmap, double sigma)
 
int model_zero_forces (Bmodel *model)
 Zeroes the component forces. More...
 
int model_calculate_deviations (Bmodel *model)
 Calculates the deviations from regularity in a polyhedral model. More...
 
int model_calculate_deviations (Bmodel *model, Bmodparam &md)
 
double model_average_linklength (Bmodel *model)
 
int model_regularize (Bmodel *model, int max_iter, double distance, double Kdistance, double Klink, double Kpolyangle, double Kpolygon, double Kpolyplane, double Kpoint, double decay)
 Regularizes a model. More...
 

Variables

int verbose
 

Detailed Description

Functions to do molecular mechanics.

Author
Bernard Heymann
Date
Created: 20010828
Modified: 20210318

Macro Definition Documentation

◆ ETERMS

#define ETERMS   16

Function Documentation

◆ component_angular_potential()

double component_angular_potential ( Bcomponent comp,
Bcomponent comp1,
Bcomponent comp2,
double  a0,
double  Ka 
)

◆ component_distance_potential()

double component_distance_potential ( Bcomponent comp1,
Bcomponent comp2,
double  Kd,
int  type 
)

◆ component_electrostatic_potential()

double component_electrostatic_potential ( Bcomponent comp1,
Bcomponent comp2,
double  q1,
double  q2,
double  Ke,
double  cutoff 
)

◆ component_harmonic_potential()

double component_harmonic_potential ( Bcomponent comp1,
Bcomponent comp2,
double  d0,
double  Kd 
)

◆ component_lennard_jones_potential()

double component_lennard_jones_potential ( Bcomponent comp1,
Bcomponent comp2,
double  d0,
double  Kd 
)

◆ component_morse_potential()

double component_morse_potential ( Bcomponent comp1,
Bcomponent comp2,
double  d0,
double  Kd 
)

◆ component_radial_potential()

double component_radial_potential ( Bcomponent comp,
Vector3< double >  point,
double  d0,
double  Kradial 
)

◆ component_soft_potential()

double component_soft_potential ( Bcomponent comp1,
Bcomponent comp2,
double  d0,
double  Kd 
)

◆ model_angle_energy()

double model_angle_energy ( Bmodel model,
Bmodparam md 
)

Calculates the model angular energy.

Parameters
*modelmodel structure.
&mdmodel parameters with reference angle specifications.
Returns
double angular energy.
The angular potential is a harmonic function:
    E = Ka*(a - a0)^2
The force is zero when a = reference angle (a0).
Only the first model in the linked list is used.

◆ model_average_linklength()

double model_average_linklength ( Bmodel model)

◆ model_calculate_deviations() [1/2]

int model_calculate_deviations ( Bmodel model)

Calculates the deviations from regularity in a polyhedral model.

Parameters
*modelmodel structure.
Returns
int 0.
Link deviation:
    d = sqrt(sum((l - l0)^2)/n)
where l is the length and l0 is the reference length.
Angle deviation:
    d = sqrt(sum((a - a0)^2)/n)
where a is the angle between two links and a0 is the reference angle:
    a0 = PI*(1 - 2/v)
where v is the number of vertices in the associated polygon.
Only the first model in the linked list is used.

◆ model_calculate_deviations() [2/2]

int model_calculate_deviations ( Bmodel model,
Bmodparam md 
)

◆ model_distance_energy()

double model_distance_energy ( Bmodel model,
Bmodparam md 
)

Calculates the distance-related potentials between components.

Parameters
*modelmodel structure.
&mdmodel parameters with distance interactions specifications.
Returns
double distance energy.
Distance potential types:
    0   none
    1   harmonic - only for explicit links
    2   soft
    3   Lennard-Jones
    4   Morse
Only the first model in the linked list is used.

◆ model_electrostatic_energy()

double model_electrostatic_energy ( Bmodel model,
Bmodparam md 
)

Calculates the electrostatic potentials between components.

Parameters
*modelmodel structure.
&mdmodel parameters with distance interactions specifications.
Returns
double electrostatic energy.
Electrostaic potential:
    E = Ke*q1*q2/d
Only the first model in the linked list is used.

◆ model_grid_distance_energy()

double model_grid_distance_energy ( Bmodel model,
Bmodparam md 
)

Calculates the non-bonded forces and energy.

Parameters
*modelmodel structure.
&mdmodel parameters with distance interactions specifications.
Returns
double distance energy.
Distance potential types:
    0   none
    1   harmonic - only for explicit links
    2   soft
    3   Lennard-Jones
    4   Morse

◆ model_guide_energy()

double model_guide_energy ( Bmodel model,
Bmodparam md 
)

Calculates the potential with respect to a guide model.

Parameters
*modelmodel structure.
&mdmodel aparameters.
Returns
double energy.
Only the first model in the linked list is used.

◆ model_lennard_jones_energy()

double model_lennard_jones_energy ( Bmodel model,
double  Kd,
double  d0 
)

Calculates the Lennard-Jones potential between components.

Parameters
*modelmodel structure.
Kddistance force constant (Kd).
d0reference distance between components (d0).
Returns
double distance energy.
The Lennard-Jones potential is given by:
    E = Kd*((d0/d)^12 - 2*(d0/d)^6)
The force is zero when d = d0.
The potential is set to zero for d > 3*d0;
Only the first model in the linked list is used.

◆ model_link_energy() [1/2]

double model_link_energy ( Bmodel model,
Bmodparam md 
)

Calculates the model link energy.

Parameters
*modelmodel structure.
&mdmodel parameters with distance interactions specifications.
Returns
double distance energy.
The link potential is a harmonic function:
    E = Kl*(d - l0)^2
The force is zero when d = reference link length (l0).
Only the first model in the linked list is used.

◆ model_link_energy() [2/2]

double model_link_energy ( Bmodel model,
double  Klink 
)

Calculates the model link energy.

Parameters
*modelmodel structure.
Klinklink force constant (Kl).
Returns
double link energy.
The link potential is a harmonic function:
    E = Kl*(d - l0)^2
The force is zero when d = reference link length (l0).
Only the first model in the linked list is used.

◆ model_map_energy() [1/2]

double model_map_energy ( Bmodel model,
Bimage map,
double  Kmap 
)

Energy calculation of a model into a map.

Parameters
*modelmodel structure.
*mapmap.
Kmapmap force constant.
Returns
double energy.
The map must be possitive density.
Only the first model in the linked list is used.

◆ model_map_energy() [2/2]

double model_map_energy ( Bmodel model,
Bimage map,
double  Kmap,
double  sigma 
)

◆ model_map_gradient_energy()

double model_map_gradient_energy ( Bmodel model,
Bimage map,
double  Kmap 
)

◆ model_mechanics()

double model_mechanics ( Bmodel model,
Bmodparam md,
int  mm_type,
int  max_iter,
double  max_shift,
double  velocitylimit 
)

Minimizes the energy of a model.

Parameters
*modelmodel structure.
&mdmodel parameters.
mm_typetype of mechanics: 0=minimization, 1=dynamics
max_iternumber of minimization iterations.
max_shiftmaximum shift per iteration.
velocitylimitlimit on velocity per time step.
Returns
double final energy.
The inclusion of energy terms is based on positive K-constants in the 
model parameter structure.
Only the first model in the linked list is used.

◆ model_minimize()

int model_minimize ( Bmodel model,
double  max_shift 
)

Move components random distances down the energy gradient.

Parameters
*modelmodel structure.
max_shiftmaximum shift for each component.
Returns
int number of components.
The distance of movement is limited to the maximum shift.
Only the first model in the linked list is used.

◆ model_morse_energy()

double model_morse_energy ( Bmodel model,
double  Kd,
double  d0 
)

Calculates the Morse potential between components.

Parameters
*modelmodel structure.
Kddistance force constant (Kd).
d0reference distance between components (d0).
Returns
double distance energy.
The Morse potential is given by:
    E = Kd*((1-exp((a/d0)*(d0-d)))^2 - 1)
The width of the energy well is given by a, set here to 6.
The force is zero when d = d0.
The potential is set to zero for d > 3*d0;
Only the first model in the linked list is used.

◆ model_neighbor_distance_energy()

double model_neighbor_distance_energy ( Bmodel model,
Bmodparam md 
)

Calculates the distance-related potentials between components and their neighbors.

Parameters
*modelmodel structure.
&mdmodel parameters with distance interactions specifications.
Returns
double distance energy.
Distance potential types:
    0   none
    1   harmonic - only for explicit links
    2   soft
    3   Lennard-Jones
    4   Morse
Only the first model in the linked list is used.

◆ model_neighbor_plane_energy()

double model_neighbor_plane_energy ( Bmodel model,
double  Kplane 
)

Calculates the planarity energy and forces with respect to neighbors.

Parameters
*modelmodel structure.
Kplaneneighbor planarity constant.
Returns
double neighbor planar energy.
A plane is fit through the neigbor locations and the normal calculated from:
    n•p = d
where n is the normal vector, p is a point in the plane, and d is the offset.
The deviation of a component location from the neighbor plane is calculated
and converted to a harmonic energy and force.
Only the first model in the linked list is used.

◆ model_point_force()

double model_point_force ( Bmodel model,
Vector3< double >  point,
double  Kpoint,
double  decay 
)

Calculates the forces and energy resulting from a single point force.

Parameters
*modelmodel structure.
pointcenter of point force.
Kpointpoint force constant.
decayenergy decay with distance.
Returns
double point force energy.
The energy is defined as an exponential decay over distance from the 
center of the point force:
    Ep = Kp * exp(-decay*dist)
The force is the derivative of the energy:
    Fp = Kp * decay * dir * exp(-decay*dist)
where Kp is the point force constant, dist is the distance of the component 
from the center of the point force, decay is the energy decay with distance
from the point force center, and dir is the normalized direction vector
pointing from the point force center to the component, indicating the direction
of force.
Only the first model in the linked list is used.

◆ model_polygon_angle_energy()

double model_polygon_angle_energy ( Bmodel model,
double  Kpolyangle 
)

Calculates the link angular forces and energy.

Parameters
*modelmodel structure.
Kpolyangleangle force constant (Ka).
Returns
double total link angle energy.
The energy is defined as a harmonic function around the reference 
link angle, a0:
    Ea = Ka*(cos(a0)-r1*r2/(|r1|*|r2|))^2
    Ea = Ka*(a0 - a)^2
The force is the derivative of the energy on the first and last atoms:
    Fa1 = 2*Ka*(cos(a0)-r1*r2/(|r1|*|r2|))/(|r1|*|r2|) * ((r1*r2/|r1|)*r1-r2)
    Fa3 = 2*Ka*(cos(a0)-r1*r2/(|r1|*|r2|))/(|r1|*|r2|) * ((r1*r2/|r2|)*r2-r1)
where r1 is the vector from atom 2 to atom 1, r2 is the vector from
atom 2 to atom 3, and Ka is the link angle force constant.
Only the first model in the linked list is used.

◆ model_polygon_energy() [1/2]

double model_polygon_energy ( Bmodel model,
double  Kpoly 
)

Calculates the polygon regularity energy and forces.

Parameters
*modelmodel structure.
Kpolypolygon regularity constant (Kp).
Returns
double polygon energy.
Given the distances of all the vertices from the polygon center, the
polygon regularity is defined as the deviation of these distances
from the average distance:
    E = Kp*(d - d0)
Only the first model in the linked list is used.

◆ model_polygon_energy() [2/2]

double model_polygon_energy ( Bmodel model,
double  linklength,
double  Kpoly 
)

Calculates the polygon regularity.

Parameters
*modelmodel structure.
linklengthreference link length (l0).
Kpolypolygon regularity constant (Kp).
Returns
double polygon energy.
Given the distances of all the vertices from the polygon center, the
polygon regularity is defined as the deviation of these distances
from the reference distance:
    E = Kp*(d - d0)
where the reference distance is calculated from the link length:
    d0 = l0/sqrt(2*(1-cos(2PI/n))
where n is the polygon order.
Only the first model in the linked list is used.

◆ model_polygon_plane_energy()

double model_polygon_plane_energy ( Bmodel model,
double  Kpolyplane 
)

Calculates the polygon planarity energy and forces.

Parameters
*modelmodel structure.
Kpolyplanepolygon planarity constant.
Returns
double polygon planar energy.
A plane is fit through the polygon vertices and the normal calculated from:
    n•p = d
where n is the normal vector, p is a point in the plane, and d is the offset.
The polygon plane energy is calculated as a harmonic deviation from 
the fitted plane.
Only the first model in the linked list is used.

◆ model_polyhedron_guide_energy()

double model_polyhedron_guide_energy ( Bmodel model,
Bmodel gmod,
double  Kguide 
)

Calculates the potential with respect to a guide polyhedron.

Parameters
*modelmodel structure.
*gmodguide polyhedron model.
Kguideguide polyhedron force constant.
Returns
double energy.
Only the first model in the linked list is used.

◆ model_radial_energy()

double model_radial_energy ( Bmodel model,
Vector3< double >  point,
double  d0,
double  Kradial 
)

Calculates the potential between a components and a point.

Parameters
*modelmodel structure.
pointreference point = radial center.
d0reference distance between component and point.
Kradialradial force constant.
Returns
double energy.
The radial potential is given by:
    E = Kd*(d - d0)^2
The force is zero when d = d0.
Only the first model in the linked list is used.

◆ model_regularize()

int model_regularize ( Bmodel model,
int  max_iter,
double  distance,
double  Kdistance,
double  Klink,
double  Kpolyangle,
double  Kpolygon,
double  Kpolyplane,
double  Kpoint,
double  decay 
)

Regularizes a model.

Parameters
*modelmodel structure.
max_itermaximum number of iterations.
distancereference distance.
Kdistancedistance strength constant.
Klinklink strength constant.
Kpolyangleangle strength constant.
Kpolygonpolygon regularity constant.
Kpolyplanepolygon planarity constant.
Kpointforce away from the center-of-mass.
decaypoint force decay constant.
Returns
int 0.
Only the first model in the linked list is used.

◆ model_soft_sphere_energy()

double model_soft_sphere_energy ( Bmodel model,
double  Kd,
double  d0 
)

Calculates the soft sphere potential between components.

Parameters
*modelmodel structure.
Kddistance force constant.
d0reference distance between components.
Returns
double distance energy.
The soft sphere potential is given by:
    E = Kd*(d0/d)^12
The potential is set to zero for d > 3*d0;
Only the first model in the linked list is used.

◆ model_verlet()

double model_verlet ( Bmodel model,
double  timestep,
double  Kfriction,
double  velocitylimit 
)

Model dynamics using the velocity verlet integrator.

Parameters
*modelmodel structure.
timestepdynamics time step.
Kfrictionfriction coefficient.
velocitylimitlimit on velocity per time step.
Returns
double kinetic energy.
Leapfrog integration for any coordinate x, velocity vx and force Fx:
    x(t+1) = x(t) + vx(t+1) * dt
    vx(t+1) = (Fx(t) * dt/m + vx(t)) * kf
    where
        kf: friction constant (1=no friction)
        dt: time step
        m: atomic mass
The velocity is limited each time step to damp chaotic oscillations.
Only the first model in the linked list is used.

◆ model_zero_forces()

int model_zero_forces ( Bmodel model)

Zeroes the component forces.

Parameters
*modelmodel.
Returns
int number of components.
Only the first model in the linked list is used.

Variable Documentation

◆ verbose

int verbose
extern