 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
41 double max_shift,
double velocitylimit)
44 cerr <<
"Error: No model selected!" << endl << endl;
50 if ( max_shift < 1 ) max_shift = 1e30;
64 cout <<
"Dynamics for model " <<
model->
id <<
":" << endl;
65 cout <<
"Time step: " << mp->
timestep << endl;
66 cout <<
"Kfriction: " << mp->
Kfriction << endl;
68 cout <<
"Minimizing model " <<
model->
id <<
":" << endl;
70 cout <<
"Kdistance: " << mp->
Kdistance << endl;
71 cout <<
"Klink: " << mp->
Klink << endl;
72 cout <<
"Kangle: " << mp->
Kangle << endl;
73 cout <<
"Kpolyangle: " << mp->
Kpolyangle << endl;
74 cout <<
"Kpolygon: " << mp->
Kpolygon << endl;
75 cout <<
"Kpolyplane: " << mp->
Kpolyplane << endl;
76 cout <<
"Kpoint and decay: " << mp->
Kpoint <<
" (" << mp->
pointdecay <<
")" << endl;
77 cout <<
"Kradial and radius: " << mp->
Kradial <<
" (" << mp->
radius <<
")" << endl;
78 cout <<
"Kplane: " << mp->
Kplane << endl;
80 cout <<
"Guide model: " << mp->
guide->
id << endl;
81 cout <<
"Kguide: " << mp->
Kguide << endl;
85 cout <<
"Kmap: " << mp->
Kmap << endl;
86 cout <<
"Sigma: " << mp->
sigma <<
" A" << endl;
87 cout <<
"Kernel size: " << ksize << endl;
89 cout <<
"Maximum shift per iteration: " << max_shift <<
" A" << endl;
97 for ( i=0; i<
ETERMS; i++ ) {
101 if ( mp->
Klink > 0 ) h[0] = 1;
102 if ( mp->
Kangle > 0 ) h[1] = 1;
107 if ( mp->
Kpoint > 0 ) h[6] = 1;
108 if ( mp->
Kradial > 0 ) h[7] = 1;
109 if ( mp->
Kplane > 0 ) h[8] = 1;
110 if ( mp->
Kguide > 0 ) h[9] = 1;
111 if ( mp->
Kmap ) h[10] = 1;
137 for ( i=0, head = head_list; i<
ETERMS && head; i++, head = head->
next )
if ( h[i] )
138 cout <<
tab << *head;
139 cout <<
"\tEpotential";
140 if ( mm_type ) cout <<
"\tEkinetic";
143 for ( iter=1; iter<=max_iter; iter++ ) {
159 cerr << endl <<
"***** Warning: The system exploded!!! *****" << endl << endl;
163 for ( i=0; i<
ETERMS; i++ ) E0[i] = E[i];
172 for ( i=0; i<
ETERMS; i++ )
if ( h[i] )
175 if ( mm_type ) cout <<
tab << mp->
Ekin;
177 cout <<
"\r" << flush;
187 cout << endl << endl;
188 cout <<
"EnergyTerm\tStart \tEnd \tChange" << endl;
189 for ( i=0, head = head_list; i<
ETERMS && head; i++, head = head->
next )
if ( h[i] ) {
190 cout << *head <<
tab << E0[i] <<
tab << E[i] <<
tab << E[i] - E0[i] << endl;
192 cout <<
"Epotential\t" << Epot0 <<
tab << mp->
Epot <<
tab << mp->
Epot - Epot0 << endl;
193 if ( mm_type ) cout <<
"Ekinetic\t\t" << mp->
Ekin << endl;
194 cout <<
"Gyration radius\t" << gyrad0 <<
tab << gyrad <<
tab << gyrad - gyrad0 << endl;
224 for ( n=0, comp =
model->
comp; comp; comp = comp->
next, n++ )
if ( comp->
sel ) {
226 shift = comp->
vec * (random()*
irm);
227 shift = shift.
min(max_shift);
228 shift = shift.
max(-max_shift);
257 double minvel = -velocitylimit, maxvel = velocitylimit;
262 comp->
vel *= Kfriction;
264 comp->
loc += comp->
vel * timestep;
267 Ekin += 0.5*comp->
type->
mass*vel*vel;
287 if ( d0 <= 0 || Kd <= 0 )
return 0;
289 double d, dev, fac, E(0);
292 v = comp1->
loc - comp2->
loc;
304 cout <<
"DEBUG component_harmonic_potential: c1=" << comp1->
id <<
305 " c2=" << comp2->
id <<
" Kd=" << Kd <<
" d0=" << d0 <<
" E=" << E << endl;
324 if ( d0 <= 0 || Kd <= 0 )
return 0;
326 double d2, d02 = d0*d0, fac, E(0);
327 double rd2, rd6, rd12;
330 v = comp2->
loc - comp1->
loc;
337 fac = -12*Kd*rd12/d2;
361 if ( d0 <= 0 || Kd <= 0 )
return 0;
363 double d2, d02 = d0*d0, fac, E(0);
364 double rd2, rd6, rd12;
367 v = comp2->
loc - comp1->
loc;
373 E = Kd*(rd12 - 2*rd6);
374 fac = -12*Kd*(rd12 - rd6)/d2;
399 if ( d0 <= 0 || Kd <= 0 )
return 0;
402 double ef, ef1, a = 6/d0;
405 v = comp2->
loc - comp1->
loc;
408 ef = exp(a*(d0 - d));
410 E = Kd*(ef1*ef1 - 1);
411 fac = 2*a*Kd*ef1*ef/d;
435 if ( Ka <= 0 )
return 0;
437 double v1len, v2len, da, fac, E(0);
440 v1 = comp1->
loc - comp->
loc;
441 v2 = comp2->
loc - comp->
loc;
446 da = acos(v1.
scalar(v2)) - a0;
448 E = Ka*da*da*v1len*v2len;
449 comp1->
vec -= n.
cross(v1) * fac * v1len;
450 comp2->
vec += n.
cross(v2) * fac * v2len;
469 if ( Kradial <= 0 )
return 0;
471 double d, dev, fac, E(0);
474 v = comp->
loc - point;
479 fac = -2*Kradial*dev/d;
506 cout <<
"DEBUG model_distance_energy: Kd=" << mp->
Kdistance << endl;
514 for ( comp2 = comp->
next; comp2; comp2 = comp2->
next )
if ( comp2->
sel && comp2->
type->
index >= 0 ) {
518 cout <<
"DEBUG model_distance_energy: c1=" << comp->
id <<
519 " c2=" << comp2->
id <<
" type=" << mp->
pot[i] <<
520 " Kd=" << Kd <<
" d0=" << mp->
dist[i] << endl;
521 switch ( mp->
pot[i] ) {
561 cout <<
"DEBUG model_neighbor_distance_energy: Kd=" << mp->
Kdistance << endl;
574 if ( ( comp->
id < comp2->
id ) && comp2->
sel ) {
575 i = i1*mp->
ntype + i2;
578 cout <<
"DEBUG model_neighbor_distance_energy: c1=" << comp->
id <<
579 " c2=" << comp2->
id <<
" type=" << mp->
pot[i] <<
580 " Kd=" << Kd <<
" d0=" << mp->
dist[i] << endl;
581 switch ( mp->
pot[i] ) {
618 if ( Kd <= 0 )
return 0;
625 for ( comp2 = comp->
next; comp2; comp2 = comp2->
next )
646 if ( Kd <= 0 )
return 0;
653 for ( comp2 = comp->
next; comp2; comp2 = comp2->
next )
675 if ( Kd <= 0 )
return 0;
682 for ( comp2 = comp->
next; comp2; comp2 = comp2->
next )
701 if ( mp->
Klink <= 0 )
return 0;
729 if ( Klink <= 0 )
return 0;
753 if ( mp->
Kangle <= 0 )
return 0;
764 comp1 = comp->
link[j];
765 for ( k=0; k<j && comp->
link[k]; k++ ) {
766 comp2 = comp->
link[k];
796 if ( Kpolyangle <= 0 )
return 0;
807 for ( i=0, comp1 = poly->
comp[poly->
number-1]; i<MAXLINK && poly->comp[i]; comp1 = comp, i++ ) {
808 comp = poly->
comp[i];
809 comp2 = poly->
comp[i+1];
810 if ( !comp2 ) comp2 = poly->
comp[0];
836 if ( Kpoly <= 0 )
return 0;
839 double dr, dist, dev, fac, E(0);
846 for ( i=0, polycen = 0; i<
MAXLINK && poly->
comp[i]; i++ )
849 if ( linklength > 0 ) {
850 dr = linklength/sqrt(2*(1 - cos(
TWOPI/i)));
852 for ( i=0, dcen = 0; i<
MAXLINK && poly->
comp[i]; i++ )
858 d = poly->
comp[i]->
loc - polycen;
862 fac = -2*Kpoly*dev/dist;
902 if ( Kpolyplane <= 0 )
return 0;
905 double dev, fac, E(0), offset;
915 E += Kpolyplane*dev*dev;
916 fac = -2*Kpolyplane*dev;
917 poly->
comp[i]->
vec += normal*fac;
939 if ( Kplane <= 0 )
return 0;
941 double dev, fac, E(0), offset;
950 comp->
vec += normal*fac;
986 if ( Kpoint <= 0 )
return 0;
988 double dist, en1, energy(0);
994 for ( comp = mp->
comp; comp; comp = comp->
next ) {
995 dir = comp->
loc - point;
997 en1 = Kpoint*exp(-decay*dist);
999 comp->
vec += dir * (decay*en1/dist);
1021 if ( Kradial <= 0 )
return 0;
1043 if ( Kguide <= 0 )
return 0;
1044 if ( !gmod )
return 0;
1047 double d, len, fac, E(0);
1053 for ( n=0, gcomp = gmod->
comp; gcomp; gcomp = gcomp->
next, n++ )
1054 center += gcomp->
loc;
1056 if ( n ) center /= n;
1059 for ( gcomp = gmod->
comp; gcomp; gcomp = gcomp->
next )
1066 cerr <<
"d not finite: " << d << endl;
1072 fac = 2*Kguide*d/len;
1073 F = comp->
loc * fac;
1093 if ( !
model )
return 0;
1094 if ( !map )
return 0;
1095 if ( Kmap == 0 )
return 0;
1111 if ( x>0 && x<map->sizeX()-1 && y>0 && y<map->
sizeY()-1 && z>0 && z<map->
sizeZ()-1 ) {
1112 i = map->
index(0, x, y, z, 0);
1114 (*map)[i+slicesize] - (*map)[i-slicesize]);
1116 comp->
vec += F * invunit;
1123 cout <<
"Warning: Model outside map boundaries!" << endl;
1133 if ( !
model )
return 0;
1134 if ( !map )
return 0;
1135 if ( Kmap == 0 )
return 0;
1137 if ( sigma < map->sampling(0)[0] ) sigma = map->
sampling(0)[0];
1144 ksize = ksize.
max(3);
1149 long x, y, z, ix, iy, iz, kx, ky, kz;
1150 double dx, dy, dz, v, w, E1, E(0);
1151 double sigma2 = sigma*sigma;
1152 double ffac = Kmap/sigma2;
1156 for ( i=0, z=0; z<ksize[2]; z++ ) {
1157 dz = (z - hksize[2])/pixsigma[2];
1158 for ( y=0; y<ksize[1]; y++ ) {
1159 dy = (y - hksize[1])/pixsigma[1];
1160 for ( x=0; x<ksize[0]; x++, i++ ) {
1161 dx = (x - hksize[0])/pixsigma[0];
1162 kernel[i] = exp(-0.5*(dx*dx + dy*dy + dz*dz));
1173 for ( iz = z - hksize[2], kz=0; kz<ksize[2]; iz++, kz++ )
if ( iz>=0 && iz<map->sizeZ() ) {
1174 dz = (kz - hksize[2])*map->
sampling(0)[2];
1175 for ( iy = y - hksize[1], ky=0; ky<ksize[1]; iy++, ky++ )
if ( iy>=0 && iy<map->sizeY() ) {
1176 dy = (ky - hksize[1])*map->
sampling(0)[1];
1177 for ( ix = x - hksize[0], kx=0; kx<ksize[0]; ix++, kx++ )
if ( ix>=0 && ix<map->sizeX() ) {
1178 dx = (kx - hksize[0])*map->
sampling(0)[0];
1179 i = map->
index(0, x, y, z, 0);
1180 k = (kz*ksize[1] + ky)*ksize[0] + kx;
1197 comp->
vec += F * ffac;
1204 cout <<
"Warning: Model outside map boundaries!" << endl;
1250 double ll, d, dd, a, aa, ar, ad;
1256 for ( n=0, ll=dd=0, link =
model->
link; link; link = link->
next, n++ ) {
1269 cout <<
"Link average and deviation: " << ll <<
" " << dd <<
" A" << endl;
1273 for ( i=0, comp1 = poly->
comp[poly->
number-1]; i<MAXLINK && poly->comp[i]; comp1 = comp2, i++ ) {
1274 comp2 = poly->
comp[i];
1275 comp3 = poly->
comp[i+1];
1276 if ( !comp3 ) comp3 = poly->
comp[0];
1277 d1 = comp2->
loc - comp1->
loc;
1278 d2 = comp2->
loc - comp3->
loc;
1293 cout <<
"Angle average and deviation: " << aa*180.0/
M_PI <<
" " << ad*180.0/
M_PI <<
" degrees" << endl << endl;
1301 double ll, d, dd, a, aa, ar, ad;
1308 cout <<
" \tAverage\tDeviation" << endl;
1310 for ( n=0, ll=dd=0, link =
model->
link; link; link = link->
next, n++ ) {
1324 cout <<
"Links \t" << ll <<
tab << dd << endl;
1326 for ( n=0, aa=ad=0, comp =
model->
comp; comp; comp = comp->
next ) {
1328 comp1 = comp->
link[j];
1329 for ( k=0; k<j && comp->
link[k]; k++ ) {
1330 comp2 = comp->
link[k];
1332 if ( mp->
angle[i] ) {
1333 d1 = comp1->
loc - comp->
loc;
1334 d2 = comp2->
loc - comp->
loc;
1351 cout <<
"Angles \t" << aa*180.0/
M_PI <<
tab << ad*180.0/
M_PI << endl;
1355 for ( i=0, comp1 = poly->
comp[poly->
number-1]; i<MAXLINK && poly->comp[i]; comp1 = comp, i++ ) {
1356 comp = poly->
comp[i];
1357 comp2 = poly->
comp[i+1];
1358 if ( !comp2 ) comp2 = poly->
comp[0];
1359 d1 = comp1->
loc - comp->
loc;
1360 d2 = comp2->
loc - comp->
loc;
1375 cout <<
"Polygon angles\t" << aa*180.0/
M_PI <<
tab << ad*180.0/
M_PI << endl << endl;
1384 double linklength(0);
1388 linklength += link->
length;
1390 if ( n ) linklength /= n;
1412 double Kdistance,
double Klink,
double Kpolyangle,
double Kpolygon,
1413 double Kpolyplane,
double Kpoint,
double decay)
1416 cout <<
"No model selected for regularization!" << endl << endl;
1422 double max_shift = 0.1*linklength;
1424 if ( max_shift < 1 ) max_shift = 0.1*
distance;
1426 if ( max_shift < 1 ) max_shift = 10;
1429 cout <<
"Regularizing a model:" << endl;
1430 cout <<
"Reference distance: " <<
distance <<
" A" << endl;
1431 cout <<
"Kdistance: " << Kdistance << endl;
1432 cout <<
"Link length: " << linklength <<
" A" << endl;
1433 cout <<
"Klink: " << Klink << endl;
1434 cout <<
"Kpolyangle: " << Kpolyangle << endl;
1435 cout <<
"Kpolygon: " << Kpolygon << endl;
1436 cout <<
"Kpolyplane: " << Kpolyplane << endl;
1437 cout <<
"Kpoint: " << Kpoint <<
" (" << decay <<
")" << endl;
1438 cout <<
"Maximum shift per iteration: " << max_shift <<
" A" << endl << endl;
1442 double Edist0(0), Elink0(0), Eangle0(0), Epoly0(0), Eplane0(0), Epoint0(0), E0(0);
1443 double Edist(0), Elink(0), Eangle(0), Epoly(0), Eplane(0), Epoint(0), E(0);
1450 cout <<
"Iter\tEdist\tElink\tEangle\tEpoly\tEplane\tEpoint\tE" << endl;
1451 for ( iter=1; iter<=max_iter; iter++ ) {
1459 E = Edist + Elink + Eangle + Epoly + Eplane + Epoint;
1472 cout << iter <<
tab << Edist <<
tab << Elink <<
tab << Eangle <<
tab
1473 << Epoly <<
tab << Eplane <<
tab << Epoint <<
tab << E << endl;
1477 cout << endl <<
"\tEdistance\tElinklength\tEangledev\tEpolyreg\tEpolyplane\tEpointdist\tE" << endl;
1478 cout <<
"Start:\t" << Edist0 <<
tab << Elink0 <<
tab << Eangle0 <<
tab <<
1479 Epoly0 <<
tab << Eplane0 <<
tab << Epoint0 <<
tab << E0 << endl;
1480 cout <<
"End:\t" << Edist <<
tab << Elink <<
tab << Eangle <<
tab <<
1481 Epoly <<
tab << Eplane <<
tab << Epoint <<
tab << E << endl;
1482 cout <<
"Change:\t" << Edist - Edist0 <<
tab << Elink - Elink0 <<
tab <<
1483 Eangle - Eangle0 <<
tab << Epoly - Epoly0 <<
tab << Eplane - Eplane0 <<
tab <<
1484 Epoint - Epoint0 <<
tab << E - E0 << endl << endl;
double model_map_energy(Bmodel *model, Bimage *map, double Kmap)
Energy calculation of a model into a map.
double model_link_energy(Bmodel *model, Bmodparam *mp)
Calculates the model link energy.
Vector3< double > component_plane(Bcomponent **comparray, double &offset)
Calculates a plane through an array of components.
double model_polyhedron_guide_energy(Bmodel *model, Bmodel *gmod, double Kguide)
Calculates the potential with respect to a guide polyhedron.
double model_distance_energy(Bmodel *model, Bmodparam *mp)
Calculates the distance-related potentials between components.
double model_average_linklength(Bmodel *model)
Vector3< Type > vector3_scalar_range(Vector3< Type > vec, double min, double max)
double model_inside_outside(Vector3< double > vec, Bmodel *model, int curv_flag, int fast)
Header file for general symmetry functions.
double component_soft_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
int model_calculate_deviations(Bmodel *model)
Calculates the deviations from regularity in a polyhedral model.
Header file for functions for creating random images.
int bexit(int value)
Exit function for cleanup and debugging.
double model_morse_energy(Bmodel *model, double Kd, double d0)
Calculates the Morse potential between components.
double component_harmonic_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
int model_zero_forces(Bmodel *model)
Zeroes the component forces.
Vector3< double > model_center_of_mass(Bmodel *model)
double scalar(const Vector3 &v) const
double component_morse_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
double standard_deviation()
double model_polygon_plane_energy(Bmodel *model, double Kpolyplane)
Calculates the polygon planarity energy and forces.
double component_radial_potential(Bcomponent *comp, Vector3< double > point, double d0, double Kradial)
double distance(const Vector3 &v)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void origin(double x, double y, double z)
double model_angle_energy(Bmodel *model, Bmodparam *mp)
Calculates the model angular energy.
double model_neighbor_plane_energy(Bmodel *model, double Kplane)
Calculates the planarity energy and forces with respect to neighbors.
int model_minimize(Bmodel *model, double max_shift)
Move components random distances down the energy gradient.
General image parameter class.
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
double model_neighbor_distance_energy(Bmodel *model, Bmodparam *mp)
Calculates the distance-related potentials between components and their neighbors.
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.
double model_polygon_angle_energy(Bmodel *model, double Kpolyangle)
Calculates the link angular forces and energy.
Class for 3-value vectors.
Functions to do molecular mechanics.
double distance(vector< T1 > &v1, vector< T2 > &v2)
double model_lennard_jones_energy(Bmodel *model, double Kd, double d0)
Calculates the Lennard-Jones potential between components.
double component_lennard_jones_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
Header file for general utilities.
double model_verlet(Bmodel *model, double timestep, double Kfriction, double velocitylimit)
Model dynamics using the velocity verlet integrator.
ostream & tab(ostream &out)
Bcomponent * comp[MAXLINK]
bool isfinite(complex< T > &value)
void change_type(char letter)
Get the data type indicated by a single letter code.
long index(long nx, long ny) const
double model_mechanics(Bmodel *model, Bmodparam *mp, int mm_type, int max_iter, double max_shift, double velocitylimit)
Minimizes the energy of a model.
double model_radial_energy(Bmodel *model, Vector3< double > point, double d0, double Kradial)
Calculates the potential between a components and a point.
double angle(Vector3< T2 > &v)
double component_angular_potential(Bcomponent *comp, Bcomponent *comp1, Bcomponent *comp2, double a0, double Ka)
Header file for generalized linked list functions.
Header file for general utilities.
Functions to manipulate polyhedral coordinate files.
int model_poly_generate(Bmodel *model)
Generates polygons based on a vertex network.
Library routines used for model processing.
double model_gyration_radius(Bmodel *model)
Calculates the radius of gyration for a model.
double irm(1.0L/get_rand_max())
void sampling(long nn, Vector3< double > u)
long get_rand_max()
Finds the maximum random number for a system.
double model_polygon_energy(Bmodel *model, double linklength, double Kpoly)
Calculates the polygon regularity.
double model_point_force(Bmodel *model, Vector3< double > point, double Kpoint, double decay)
Calculates the forces and energy resulting from a single point force.
Bcomponent * link[MAXLINK]
Library routines used for shell model processing.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Bcomponent * neighbor[MAXLINK]
double model_soft_sphere_energy(Bmodel *model, double Kd, double d0)
Calculates the soft sphere potential between components.
Vector3 cross(const Vector3 &v)
double model_mass(Bmodel *model)
Calculates the mass of a model from component masses.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.