 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
30 if ( md->
Kbond ) cout <<
"\tEbond";
31 if ( md->
Kangle ) cout <<
"\tEangle";
32 if ( md->
Kvdw ) cout <<
"\tEvdw";
33 if ( md->
Kelec ) cout <<
"\tEelec";
34 if ( md->
Ksep ) cout <<
"\tEsep";
35 if ( md->
Kpoint ) cout <<
"\tEpoint";
36 if ( md->
Kmap ) cout <<
"\tEmap";
37 cout <<
"\tEpot\tdEpot" << endl;
72 double beta,
double max_angle,
double max_shift,
73 long max_iter,
int rigid,
77 int done(0), accept, select_min(0);
78 long i, isel(0), cycle(0), naccept(0);
79 double r, E, pE, bestE, Z(0), Ze, Zi, Emax;
87 double* Elist =
new double[max_iter+1];
90 long nmol =
count_list((
char *) molgroup->mol);
91 long nbond =
count_list((
char *) molgroup->bond);
95 cout <<
"Monte carlo metropolis energy minimization:" << endl;
96 cout <<
"Molecule file: " << molgroup->filename << endl;
97 cout <<
"Number of molecule groups: " << nmg << endl;
98 cout <<
"Number of molecules: " << nmol << endl;
99 if ( map ) cout <<
"Map file: " << map->
file_name() << endl;
100 cout <<
"Coordinate minima and maxima: " << molgroup->min <<
" " << molgroup->max << endl;
101 cout <<
"Bounding box: " << molgroup->box << endl;
102 cout <<
"Kbond: " << md->
Kbond << endl;
103 cout <<
"Kangle: " << md->
Kangle << endl;
104 cout <<
"Kelectrostatic: " << md->
Kelec << endl;
105 cout <<
"Kvdw: " << md->
Kvdw << endl;
106 cout <<
"Kmap: " << md->
Kmap << endl;
107 cout <<
"Kseparation: " << md->
Ksep << endl;
109 cout <<
"location: " << md->
point << endl;
110 cout <<
"beta constant: " <<
beta << endl;
111 cout <<
"Cutoff distance: " << md->
cutoff << endl;
112 cout <<
"Separation distance: " << md->
sepdist << endl;
113 cout <<
"Maximum shift: " << max_shift << endl;
114 cout <<
"Maximum angular increment: " << max_angle*180.0/
M_PI << endl;
115 cout <<
"Steps along bond: " << md->
bondsteps << endl;
116 cout <<
"Number of bonds: " << nbond << endl;
117 if ( rigid < 1 ) cout <<
"Treating the whole ensemble as a rigid body" << endl;
118 else if ( rigid == 1 ) cout <<
"Treating each file with a molecule group as a rigid body" << endl;
119 else if ( rigid == 2 ) cout <<
"Treating each molecule as a rigid body" << endl;
120 else cout <<
"Modifying each atom's coordinates" << endl;
126 for ( mg = mgc; mg; mg = mg->
next ) mg->
select =
"ALL";
127 }
else if ( rigid == 1 ) {
128 for ( mg = mgc; mg; mg = mg->
next ) {
132 }
else if ( rigid == 2 ) {
133 for ( i=0, mol = mgc->
mol; mol; mol = mol->
next, ++i ) {
138 }
else mgc->
select =
"ATOM";
140 pE = (Efunc)(mgc, map, md);
149 while ( !done && ( cycle < max_iter ) ) {
154 for ( i=0, Emax=-1e30, mg=mgc; mg; mg=mg->
next, i++ ) {
155 if ( Emax < mg->fom ) {
161 isel = (long) ((nmg-0.001)*
irm*random());
163 for ( i=0, mg=mgc; mg; mg=mg->
next, i++ ) {
164 if ( i == isel ) mg->
sel = 1;
167 }
else if ( rigid == 2 ) {
169 for ( i=0, Emax=-1e30, mol=mgc->
mol; mol; mol=mol->
next, i++ ) {
170 if ( Emax < mol->fom ) {
176 isel = (long) ((nmol-0.001)*
irm*random());
178 for ( i=0, mol=mgc->
mol; mol; mol=mol->
next, i++ ) {
179 if ( i == isel ) mol->
sel = 1;
183 (Tfunc)(mgc, max_angle, max_shift);
184 E = (Efunc)(mgc, map, md);
195 if ( E > 1e30 ) accept = 0;
198 if ( exp(
beta*(pE-E)) < r ) accept = 0;
213 for ( i=0, Z=Ze=0; i<=cycle; i++ ) {
214 Zi = exp(-
beta*Elist[i]);
216 if ( Elist[i] - bestE < 0.001 ) Ze += Zi;
227 cout <<
"Total shift: " << gloc << endl;
228 for ( i=0, mol = molgroup->mol; mol; mol = mol->
next, ++i ) {
231 cout <<
tab << mol->
id <<
tab << iloc[i] <<
tab << E << endl;
233 cout <<
"Fraction of perturbations accepted: " << naccept*1.0/cycle << endl;
234 cout <<
"Final energy: " << bestE << endl;
235 cout <<
"Partition function: " << Z << endl;
236 cout <<
"Probability of final orientation: " << Ze/Z << endl << endl;
264 long i, x, y, z, n(0);
273 cout <<
"Generating molecules on a masked grid:" << endl;
274 cout <<
"Bounding box: " << bbmin <<
" " << bbmax << endl;
275 cout <<
"Grid sampling: " << grid_sampling << endl;
276 if ( pmask ) cout <<
"Mask file: " << pmask->
file_name() << endl;
281 for ( loc[2]=bbmin[2]; loc[2]<=bbmax[2]; loc[2]+=grid_sampling[2] ) {
282 for ( loc[1]=bbmin[1]; loc[1]<=bbmax[1]; loc[1]+=grid_sampling[1] ) {
283 for ( loc[0]=bbmin[0]; loc[0]<=bbmax[0]; loc[0]+=grid_sampling[0] ) {
289 i = pmask->
index(0, x, y, z, 0);
290 if ( i < 0 ) accept_flag = 0;
291 else if ( (*pmask)[i] < 0.5 ) accept_flag = 0;
314 cout <<
"Molecules generated: " << n << endl << endl;
322 long i, x, y, z, id(0);
333 cout <<
"Generating models on a masked grid:" << endl;
334 cout <<
"Molecule file name: " << molgroup->
filename << endl;
335 cout <<
"Bounding box: " << bbmin <<
" " << bbmax << endl;
336 cout <<
"Grid sampling: " << grid_sampling << endl;
337 if ( pmask ) cout <<
"Mask file: " << pmask->
file_name() << endl;
342 for ( loc[2]=bbmin[2]; loc[2]<=bbmax[2]; loc[2]+=grid_sampling[2] ) {
343 for ( loc[1]=bbmin[1]; loc[1]<=bbmax[1]; loc[1]+=grid_sampling[1] ) {
344 for ( loc[0]=bbmin[0]; loc[0]<=bbmax[0]; loc[0]+=grid_sampling[0] ) {
350 i = pmask->
index(0, x, y, z, 0);
351 if ( i < 0 ) accept_flag = 0;
352 else if ( (*pmask)[i] < 0.5 ) accept_flag = 0;
368 cout <<
"Components generated: " <<
id << endl << endl;
387 double angle_step,
Bstring filename,
int whole)
391 double theta, phi, phi_step;
399 cout <<
"Theta\tAxis.x\tAxis.y" << endl;
400 for ( theta=0; theta<
M_PI+angle_step/2; theta+=angle_step ) {
401 nphi = (int) (2*
M_PI*sin(theta)/angle_step + 0.5);
403 if ( nphi ) phi_step =
M_PI*2.0/nphi;
404 for ( phi=-
M_PI; phi<
M_PI-phi_step/2; phi+=phi_step ) {
417 for ( mol = mgc->
mol; mol; mol = mol->
next ) {
430 cout <<
"Molecules generated: " << n << endl << endl;
438 double theta, phi, phi_step;
446 for ( theta=0; theta<
M_PI+angle_step/2; theta+=angle_step ) {
447 nphi = (int) (2*
M_PI*sin(theta)/angle_step + 0.5);
449 if ( nphi ) phi_step =
M_PI*2.0/nphi;
450 for ( phi=-
M_PI; phi<
M_PI-phi_step/2; phi+=phi_step ) {
456 comp->
view =
View(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta), 0);
462 cout <<
"Components generated: " <<
id << endl << endl;
486 double max_angle,
double max_shift,
long max_iter,
int rigid)
497 for ( i=1, comp =
model->
comp; comp; comp = comp->
next, i++ ) {
514 comp->
fom = exp(-0.14*md->
Epot);
517 cout << i <<
":\t" << comp->
loc[0] <<
tab << comp->
loc[1] <<
tab <<
544 double max_angle,
double max_shift,
long max_iter,
int rigid)
581 for ( i=1, comp =
model->
comp, mc = mglist; comp && mc; comp = comp->
next, mc = mc->
next, i++ ) {
586 comp->
fom = exp(-0.14*md->
Epot);
588 cout << i <<
":\t" << comp->
loc[0] <<
tab << comp->
loc[1] <<
tab <<
606 if ( !map )
return 0;
614 molgroup->
box = molgroup->
max - molgroup->
min;
631 long i, natom(0), natom_in(0);
633 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
634 for( res = mol->
res; res; res = res->
next ) {
635 for ( atom = res->
atom; atom; atom = atom->
next ) {
636 i = ( atom->
coord[0] >= min[0] && atom->
coord[0] <= max[0] );
637 i += ( atom->
coord[1] >= min[1] && atom->
coord[1] <= max[1] );
638 i += ( atom->
coord[2] >= min[2] && atom->
coord[2] <= max[2] );
639 if ( i > 2 ) natom_in++;
646 cout <<
"Fraction within bounding box: " << natom_in*1.0/natom << endl;
665 if ( map && md->
Kmap ) {
761 if ( md->
Ksep <= 0 )
return 0;
763 long n(0), i, x, y, z;
767 size[0] = (int) (box[0]/sampling[0] + 0.001);
768 size[1] = (int) (box[1]/sampling[1] + 0.001);
769 size[2] = (int) (box[2]/sampling[2] + 0.001);
771 sampling[0] = box[0]/size[0] + 0.001;
772 sampling[1] = box[1]/size[1] + 0.001;
773 sampling[2] = box[2]/size[2] + 0.001;
774 long boxsize = (long) size.
volume();
786 for ( mg = molgroup; mg; mg = mg->
next ) {
787 for ( mol = mg->
mol; mol; mol = mol->
next ) {
788 for ( res = mol->
res; res; res = res->
next ) {
789 for ( atom = res->
atom; atom; atom = atom->
next ) {
790 x = (long) ((atom->
coord[0] - mg->
min[0])/sampling[0]);
791 y = (long) ((atom->
coord[1] - mg->
min[1])/sampling[1]);
792 z = (long) ((atom->
coord[2] - mg->
min[2])/sampling[2]);
793 if ( x>=0 && x<size[0] && y>=0 && y<size[1] && z>=0 && z<size[2] ) {
794 i = p->
index(x, y, z);
800 for ( i=0; i<boxsize; i++ ) {
801 data[i] += dataone[i];
807 for ( i=0; i<boxsize; i++ ) {
808 data[i] += dataone[i];
815 Bstring filename(
"overlap.map");
821 for ( i=n=0; i<boxsize; i++ ) {
824 if ( data[i] > 1 ) md->
Esep += data[i] - 1;
857 t.
angle = max_angle*(random()*
irm*2 - 1);
865 for ( ; molgroup; molgroup=molgroup->
next )
if ( molgroup->
sel ) {
871 for ( mol=molgroup->
mol; mol; mol=mol->
next )
if ( mol->
sel ) {
900 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
901 for ( res = mol->
res; res; res = res->
next ) {
902 for ( atom = res->
atom; atom; atom = atom->
next ) {
903 shift = atom->
F * (random()*
irm);
904 shift = shift.
min(max_shift);
905 atom->
coord += shift;
int mcm_molecule_list(Bmolgroup *molgroup, Bmodel *model, Bmd *md, Bimage *map, double beta, double max_angle, double max_shift, long max_iter, int rigid)
Monte Carlo fit of a molecule to a list of locations and orientations.
Vector3< double > mol_center_of_mass(Bmolecule *mol)
Calculates the center of mass of a molecule.
double mol_map_energy(Bmolecule *mol, Bimage *map, double Kmap)
Energy calculation of a molecule fit into a map.
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Vector3< double > vector3_random_gaussian(double avg, double std)
Generates a random vector within a random gaussian-distributed length.
double molgroup_map_energy(Bmolgroup *molgroup, Bimage *map, double Kmap)
Energy calculation of a molecule fit into a map.
int molgroup_list_kill(Bmolgroup *molgroup)
Destroys a molecule group linked list.
double monte_bond_fit_energy(Bmolgroup *molgroup, Bimage *map, Bmd *md)
Calculates the potential energy for fitting bonds to a map.
double monte_atom_fit_energy(Bmolgroup *molgroup, Bimage *map, Bmd *md)
Calculates the potential energy for fitting atoms to a map.
Header file for functions for creating random images.
Header to read and write molecular dynamics parameters in STAR format.
int display_energy(long iter, Bmd *md, double dE)
Vector3< long > size() const
int mcm_molecule_groups(Bmolgroup *molgroup, Bmodel *model, Bmd *md, Bimage *map, double beta, double max_angle, double max_shift, long max_iter, int rigid)
Monte Carlo fit of a set of molecule groups.
Vector3< double > vector3_random(const double min, const double max)
Generates a random vector within a defined cube.
int display_energy_headers(Bmd *md)
long count_list(char *list)
Counts the number of items in a linked list.
double md_nonbonded_forces(Bmolgroup *molgroup, Bmd *md)
Calculates the non-bonded forces and energy.
Bmodel * model_init(Bstring &id)
Initializes a model structure.
double distance(const Vector3 &v)
Bcomptype * model_add_type_by_filename(Bmodel *model, Bstring &filename, int num)
Add a type to a model if the type with the given file name does not exist already.
void origin(double x, double y, double z)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Header for molecular dynamics.
Header file for reading reflection files.
double molgroup_bond_fit_map_energy(Bmolgroup *molgroup, Bimage *map, double Kmap, int steps)
Energy calculation of a molecule fit into a map.
Transform molgroup_find_transformation(Bmolgroup *molgroup1, Bmolgroup *molgroup2)
Determines the transformation between two groups of identical molecules.
General image parameter class.
int molgroup_rigid_body_transform(Bmolgroup *molgroup, double max_angle, double shift_std)
Randomly transforms a molecule or molecule group.
Bmolgroup * molgroup_generate_masked_grid_list(Bmolgroup *molgroup, Bimage *pmask, Vector3< double > grid_sampling, Bstring filename)
Generates multiple versions of a molecule at different locations.
Library routines used to compare sets of atomic coordinates.
int molgroup_set_box_to_map_boundaries(Bmolgroup *molgroup, Bimage *map)
Sets the box in a molgroup to that defined by the map boundaries.
Header file for general utilities.
ostream & tab(ostream &out)
int molgroup_move_atoms_down_energy(Bmolgroup *molgroup, double max_angle, double max_shift)
Move atoms random distances down the energy gradient.
double monte_rigid_body_fit_energy(Bmolgroup *molgroup, Bimage *map, Bmd *md)
Calculates the potential energy for rigid body fitting.
Vector3< double > molgroup_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Bmolgroup * monte_carlo_metropolis(Bmolgroup *molgroup, Bmd *md, Bimage *map, double beta, double max_angle, double max_shift, long max_iter, int rigid, double(Efunc)(Bmolgroup *, Bimage *, Bmd *), int(Tfunc)(Bmolgroup *, double, double))
Headers of functions using a monte carlo metroplis algorithm to energy minimize molecular positions.
long index(long nx, long ny) const
Header file for 2D and 3D image I/O.
double md_angular_forces(Bmolgroup *molgroup, double Kangle, int wrap)
Calculates the covalent bond angular forces and energy.
Generalized matrix class.
Bmolgroup * molgroup_generate_orientation_list(Bmolgroup *molgroup, double angle_step, Bstring filename, int whole)
Generates multiple versions of a molecule at different locations.
double beta(double volt)
Calculates the relative electron velocity.
int md_zero_forces(Bmolgroup *molgroup)
Zero all atomic forces.
long molgroup_test_if_within_box(Bmolgroup *molgroup, Vector3< double > min, Vector3< double > max)
Tests if a molecule overlaps with a defined box.
Header file for generalized linked list functions.
unsigned char * data_pointer()
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
double molgroup_atom_overlap(Bmolgroup *molgroup, Bmd *md)
Calculates an energy term based on atom overlap.
double md_bond_forces(Bmolgroup *molgroup, double Kbond, int wrap)
Calculates the covalent bond length forces and energy.
Headers of functions to calculate estimates of the fitting of molecules to maps.
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.
bool contains(const Bstring &s)
Bmolgroup * molgroup_list_copy(Bmolgroup *molgroup)
Copies a molecule group list.
Bmolgroup * molgroup_copy(Bmolgroup *molgroup)
Copies a molecule group.
Header for molecular dynamics.
Library routines used for atomic coordinates.
double md_calculate_deviations(Bmolgroup *molgroup, int wrap)
Calculates deviations from the reference bond lengths and angles.