| Bsoft 2.0.5 Bernard's software package

Functions
model_mechanics.h File Reference

Functions to do molecular mechanics. More...

`#include "rwmodel.h"`
`#include "rwmodel_param.h"`
`#include "rwimg.h"`

Go to the source code of this file.

## Functions
double | model_mechanics (Bmodel *model, Bmodparam *mp, 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 | model_distance_energy (Bmodel *model, Bmodparam *mp)
| Calculates the distance-related potentials between components. More...
double | model_neighbor_distance_energy (Bmodel *model, Bmodparam *mp)
| Calculates the distance-related potentials between components and their neighbors. More...
double | model_soft_sphere_energy (Bmodel *model, double Kdistance, double dist_ref)
| Calculates the soft sphere potential between components. More...
double | model_lennard_jones_energy (Bmodel *model, double Kdistance, double distance)
| Calculates the Lennard-Jones potential between components. More...
double | model_morse_energy (Bmodel *model, double Kdistance, double distance)
| Calculates the Morse potential between components. More...
double | model_link_energy (Bmodel *model, Bmodparam *mp)
| 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 *mp)
| Calculates the model angular energy. More...
double | model_polygon_angle_energy (Bmodel *model, double Kangle)
| Calculates the link angular forces and energy. 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 Kd)
| Calculates the potential between a components and a point. 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_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 *mp)
int | model_regularize (Bmodel *model, int reg_iter, double distance, double Kdistance, double Klink, double Kangle, double Kpoly, double Kpolyplane, double Kpoint, double decay)
| Regularizes a model. More...

## Detailed Description

Functions to do molecular mechanics.

Author
  Bernard Heymann

Date
  Created: 20010828
  Modified: 20141006

Definition in file model_mechanics.h.

## Function Documentation

## ◆ model_angle_energy()

double model_angle_energy | ( | Bmodel * | model,
|  | Bmodparam * | mp
| ) |  |

Calculates the model angular energy.

Parameters

  *model | model structure.
  *mp | model 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.

Definition at line 751 of file model_mechanics.cpp.

## ◆ model_calculate_deviations() [1/2]

int model_calculate_deviations | ( | Bmodel * | model | ) |

Calculates the deviations from regularity in a polyhedral model.

Parameters

  *model | model 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.

Definition at line 1247 of file model_mechanics.cpp.

## ◆ model_calculate_deviations() [2/2]

int model_calculate_deviations | ( | Bmodel * | model,
|  | Bmodparam * | mp
| ) |  |

Definition at line 1298 of file model_mechanics.cpp.

## ◆ model_distance_energy()

double model_distance_energy | ( | Bmodel * | model,
|  | Bmodparam * | mp
| ) |  |

Calculates the distance-related potentials between components.

Parameters

  *model | model structure.
  *mp | model 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.

Definition at line 501 of file model_mechanics.cpp.

## ◆ model_lennard_jones_energy()

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

Calculates the Lennard-Jones potential between components.

Parameters

  *model | model structure.
  Kd | distance force constant (Kd).
  d0 | reference 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.

Definition at line 644 of file model_mechanics.cpp.

## ◆ model_link_energy() [1/2]

double model_link_energy | ( | Bmodel * | model,
|  | Bmodparam * | mp
| ) |  |

Calculates the model link energy.

Parameters

  *model | model structure.
  *mp | model 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.

Definition at line 699 of file model_mechanics.cpp.

## ◆ model_link_energy() [2/2]

double model_link_energy | ( | Bmodel * | model,
|  | double | Klink
| ) |  |

Calculates the model link energy.

Parameters

  *model | model structure.
  Klink | link 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.

Definition at line 727 of file model_mechanics.cpp.

## ◆ model_map_energy() [1/2]

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

Energy calculation of a model into a map.

Parameters

  *model | model structure.
  *map | map.
  Kmap | map force constant.

Returns
  double energy.

      The map must be possitive density.
      Only the first model in the linked list is used.

Definition at line 1091 of file model_mechanics.cpp.

## ◆ model_map_energy() [2/2]

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

Definition at line 1131 of file model_mechanics.cpp.

## ◆ model_mechanics()

double model_mechanics | ( | Bmodel * | model,
|  | Bmodparam * | mp,
|  | int | mm_type,
|  | int | max_iter,
|  | double | max_shift,
|  | double | velocitylimit
| ) |  |

Minimizes the energy of a model.

Parameters

  *model | model structure.
  *mp | model parameters.
  mm_type | type of mechanics: 0=minimization, 1=dynamics
  max_iter | number of minimization iterations.
  max_shift | maximum shift per iteration.
  velocitylimit | limit 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.

Definition at line 40 of file model_mechanics.cpp.

## ◆ model_minimize()

int model_minimize | ( | Bmodel * | model,
|  | double | max_shift
| ) |  |

Move components random distances down the energy gradient.

    The distance of movement is limited to the maximum shift.
    Only the first model in the linked list is used.

Parameters

  *model | model structure.
  max_shift | maximum shift for each component.

Returns
  int number of components.

Definition at line 215 of file model_mechanics.cpp.

## ◆ model_morse_energy()

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

Calculates the Morse potential between components.

Parameters

  *model | model structure.
  Kd | distance force constant (Kd).
  d0 | reference 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.

Definition at line 673 of file model_mechanics.cpp.

## ◆ model_neighbor_distance_energy()

double model_neighbor_distance_energy | ( | Bmodel * | model,
|  | Bmodparam * | mp
| ) |  |

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

Parameters

  *model | model structure.
  *mp | model 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.

Definition at line 556 of file model_mechanics.cpp.

## ◆ model_neighbor_plane_energy()

double model_neighbor_plane_energy | ( | Bmodel * | model,
|  | double | Kplane
| ) |  |

Calculates the planarity energy and forces with respect to neighbors.

Parameters

  *model | model structure.
  Kplane | neighbor 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.

Definition at line 937 of file model_mechanics.cpp.

## ◆ 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

  *model | model structure.
  point | center of point force.
  Kpoint | point force constant.
  decay | energy 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.

Definition at line 984 of file model_mechanics.cpp.

## ◆ model_polygon_angle_energy()

double model_polygon_angle_energy | ( | Bmodel * | model,
|  | double | Kpolyangle
| ) |  |

Calculates the link angular forces and energy.

Parameters

  *model | model structure.
  Kpolyangle | angle 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.

Definition at line 794 of file model_mechanics.cpp.

## ◆ model_polygon_energy()

double model_polygon_energy | ( | Bmodel * | model,
|  | double | Kpoly
| ) |  |

Calculates the polygon regularity energy and forces.

Parameters

  *model | model structure.
  Kpoly | polygon 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.

Definition at line 882 of file model_mechanics.cpp.

## ◆ model_polygon_plane_energy()

double model_polygon_plane_energy | ( | Bmodel * | model,
|  | double | Kpolyplane
| ) |  |

Calculates the polygon planarity energy and forces.

Parameters

  *model | model structure.
  Kpolyplane | polygon 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.

Definition at line 900 of file model_mechanics.cpp.

## ◆ 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

  *model | model structure.
  *gmod | guide polyhedron model.
  Kguide | guide polyhedron force constant.

Returns
  double energy.

      Only the first model in the linked list is used.

Definition at line 1041 of file model_mechanics.cpp.

## ◆ 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

  *model | model structure.
  point | reference point = radial center.
  d0 | reference distance between component and point.
  Kradial | radial 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.

Definition at line 1019 of file model_mechanics.cpp.

## ◆ 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

  *model | model structure.
  max_iter | maximum number of iterations.
  distance | reference distance.
  Kdistance | distance strength constant.
  Klink | link strength constant.
  Kpolyangle | angle strength constant.
  Kpolygon | polygon regularity constant.
  Kpolyplane | polygon planarity constant.
  Kpoint | force away from the center-of-mass.
  decay | point force decay constant.

Returns
  int 0.

      Only the first model in the linked list is used.

Definition at line 1411 of file model_mechanics.cpp.

## ◆ model_soft_sphere_energy()

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

Calculates the soft sphere potential between components.

Parameters

  *model | model structure.
  Kd | distance force constant.
  d0 | reference 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.

Definition at line 616 of file model_mechanics.cpp.

## ◆ model_verlet()

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

Model dynamics using the velocity verlet integrator.

Parameters

  *model | model structure.
  timestep | dynamics time step.
  Kfriction | friction coefficient.
  velocitylimit | limit 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.

Definition at line 254 of file model_mechanics.cpp.

## ◆ model_zero_forces()

int model_zero_forces | ( | Bmodel * | model | ) |

Zeroes the component forces.

Parameters

  *model | model.

Returns
  int number of components.

      Only the first model in the linked list is used.

Definition at line 1221 of file model_mechanics.cpp.