 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
36 for ( mol = molgroup->
mol; mol; mol = mol->
next )
37 for( res = mol->
res; res; res = res->
next )
38 for ( atom = res->
atom; atom; atom = atom->
next )
39 strcpy(atom->
type, atom->
el);
42 cout <<
"Atoms renamed : " << n << endl << endl;
59 for ( mol = molgroup->
mol; mol; mol = mol->
next )
60 for( res = mol->
res; res; res = res->
next )
61 for ( atom = atom2 = res->
atom; atom; ) {
62 if ( atom->
tnum == 0 ) {
63 if ( atom == atom2 ) {
80 cout <<
"Hydrogens removed: " << n << endl << endl;
89 for ( bond = molgroup->
bond; bond; bond = bond->
next )
90 if ( bond->
atom1 == atom1 && bond->
atom2 == atom2 )
return 1;
113 cout <<
"Adding disulfide bonds:" << endl;
115 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
116 for( res = mol->
res; res; res = res->
next )
if ( strstr(res->
type,
"CYS") ) {
117 for ( atom = res->
atom; atom; atom = atom->
next )
if ( strstr(atom->
type,
"SG" ) ) {
119 if ( !alist ) alist = la;
127 cout <<
"Cysteine sulfurs found: " << n << endl;
129 for ( n=0, la = alist; la->
next; la = la->
next ) {
130 for ( la2 = la->
next; la2; la2 = la2->
next ) {
146 cout <<
"Disulfide bonds created: " << n << endl << endl;
163 double min = molgroup->
min[2];
164 char molname[20] =
"";
165 char restype[20] =
"UNK";
172 if ( slice_thickness < molgroup->max[2] - molgroup->
min[2] ) {
173 min = slice_thickness*floor(molgroup->
min[2]/slice_thickness);
174 nslices = (int) ((molgroup->
max[2] - min)/slice_thickness + 1);
182 for ( i=0; i<nslices; i++ ) {
183 slice_molgroup[i] = NULL;
185 slice_atom[i] = NULL;
189 cout <<
"System split into " << nslices <<
" slices" << endl << endl;
191 for ( i=0; i<nslices; i++ ) {
192 snprintf(molname, 20,
"%d", i+1);
194 slice_mol =
molecule_add(&slice_molgroup[i]->mol, molname);
199 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
200 for( res = mol->
res; res; res = res->
next ) {
201 for ( atom = res->
atom; atom; atom = atom->
next ) {
202 i = (int) ((atom->
coord[2] - min)/slice_thickness);
203 if ( i < 0 || i >= nslices ) {
204 error_show(
"Error in molgroup_split_into_slices", __FILE__, __LINE__);
205 cerr <<
"Index out of range: " << i << endl;
211 slice_atom[i] =
atom_add(&slice_res[i]->atom, atom->
type);
212 memcpy(slice_atom[i], atom,
sizeof(
Batom));
213 slice_atom[i]->
next = NULL;
221 for ( i=0; i<nslices; i++ ) {
223 cout <<
"Slice " << i+1 <<
":" << endl;
227 return slice_molgroup;
251 int delete_res, nresdel(0), nmoldel(0);
252 long ii, x, y, z, xx, yy, zz, ix, iy, iz;
258 Vector3<int> gridsize((
int) (box[0]/sampling[0] + 0.001),
259 (
int) (box[1]/sampling[1] + 0.001), (
int) (box[2]/sampling[2] + 0.001));
260 gridsize = gridsize.
max(1);
261 for ( i=0; i<3; i++ ) sampling[i] = box[i]/gridsize[i] + 0.001;
262 long gridvol = (long) gridsize.
volume();
265 cout <<
"Inserting a molecule group and deleting overlapping residues" << endl;
268 cout <<
"Distance cutoff: " <<
distance <<
" A" << endl;
274 for ( mol = prevmol = molgroup->
mol; mol; ) {
275 for( res = prevres = mol->
res; res; ) {
277 for ( atom = res->
atom; atom; atom = atom->
next ) {
278 x = (long) ((atom->
coord[0] - molgroup->
min[0])/sampling[0]);
279 y = (long) ((atom->
coord[1] - molgroup->
min[1])/sampling[1]);
280 z = (long) ((atom->
coord[2] - molgroup->
min[2])/sampling[2]);
281 if ( x >=0 && x < gridsize[0] && y >= 0 && y < gridsize[1] && z >= 0 && z < gridsize[2] ) {
282 i = (z*gridsize[1] + y)*gridsize[0] + x;
283 for ( zz=z-1; zz<=z+1; zz++ ) {
285 if ( iz < 0 ) iz += gridsize[2];
286 if ( iz >= gridsize[2]) iz -= gridsize[2];
287 for ( yy=y-1; yy<=y+1; yy++ ) {
289 if ( iy < 0 ) iy += gridsize[1];
290 if ( iy >= gridsize[1] ) iy -= gridsize[1];
291 for ( xx=x-1; xx<=x+1; xx++ ) {
293 if ( ix < 0 ) ix += gridsize[0];
294 if ( ix >= gridsize[0] ) ix -= gridsize[0];
295 ii = (iz*gridsize[1] + iy)*gridsize[0] + ix;
296 for ( latom = alist[ii]; latom; latom = latom->
next ) {
307 cout <<
"Removing a residue" << endl;
308 if ( res == mol->
res ) {
309 mol->
res = prevres = res->
next;
320 if ( res ) res = res->
next;
325 cout <<
"Removing a molecule" << endl;
326 if ( molgroup->
mol == mol ) {
327 molgroup->
mol = prevmol = mol->
next;
338 if ( mol ) mol = mol->
next;
342 for ( i=0; i<gridvol; i++ )
kill_list((
char *) alist[i],
sizeof(
Latom));
346 cout <<
"Molecules and residues deleted: " << nmoldel <<
" " << nresdel << endl;
349 if ( molgroup->
mol ) {
350 for ( mol = molgroup->
mol; mol->
next; mol = mol->
next ) ;
352 }
else molgroup->
mol = molinsert->
mol;
353 molinsert->
mol = NULL;
371 if ( random_max < 1e-30 )
return 0;
382 cout <<
"Randomizing coordinates to maximum: " << random_max <<
" angstrom" << endl << endl;
384 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
385 for( res = mol->
res; res; res = res->
next ) {
386 for ( atom = res->
atom; atom; atom = atom->
next ) {
387 atom->
coord[0] +=
irm*random() - random_max;
388 atom->
coord[1] +=
irm*random() - random_max;
389 atom->
coord[2] +=
irm*random() - random_max;
405 if ( B < 1e-30 )
return 0;
414 double stdev(sqrt(B));
418 cout <<
"Randomizing coordinates with Bfactor: " << B <<
" Ã…^2" << endl << endl;
420 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
421 for( res = mol->
res; res; res = res->
next ) {
422 for ( atom = res->
atom; atom; atom = atom->
next ) {
446 if ( mindist < 0.001 )
return 0;
452 Batom *atom, *atom2, *atom3;
455 cout <<
"DEBUG molgroup_remove_overlapping_atoms: mindist=" << mindist << endl;
457 for ( mol = molgroup->
mol; mol && mol->
next; mol = mol->
next ) {
458 for( res = mol->
res; res; res = res->
next ) {
459 for ( atom = res->
atom; atom; atom = atom->
next ) {
460 for ( mol2 = mol3 = mol; mol2; mol2 = mol2 ? mol2->
next : NULL ) {
461 for( res2 = res3 = mol2->
res; res2; res2 = res2 ? res2->
next : NULL ) {
462 for ( atom2 = atom3 = res2->
atom; atom2; atom2 = atom2 ? atom2->
next : NULL ) {
463 if ( atom != atom2 ) {
465 if ( dist < mindist ) {
466 if ( atom2 == res2->
atom ) {
481 if ( res2 == mol2->
res ) {
494 if ( mol2 == molgroup->
mol ) {
497 mol2 = molgroup->
mol;
510 if ( molgroup->
mol == NULL ) {
511 error_show(
"Error in molgroup_remove_overlapping_atoms: All molecules deleted!", __FILE__, __LINE__);
516 cout <<
"Overlapping atoms removed: " << nrem << endl << endl;
541 for ( bond=molgroup->
bond; bond; bond=bond->
next ) {
544 for ( i=1; i<=atoms_per_bond; i++ ) {
560 long i, vol = (long)size.
volume();
562 char* grid =
new char[vol];
563 for ( i=0; i<vol; i++ ) grid[i] = 0;
565 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
566 for( res = mol->
res; res; res = res->
next ) {
567 for ( atom = res->
atom; atom; atom = atom->
next ) {
568 x = (long) ((atom->
coord[0] - min[0])/sampling);
569 y = (long) ((atom->
coord[1] - min[1])/sampling);
570 z = (long) ((atom->
coord[2] - min[2])/sampling);
571 grid[(z*size[1] + y)*size[0] + x] = 1;
584 long i, vol = (long)size.
volume();
586 char* grid =
new char[vol];
587 for ( i=0; i<vol; i++ ) grid[i] = 0;
589 for( res = mol->
res; res; res = res->
next ) {
590 for ( atom = res->
atom; atom; atom = atom->
next ) {
591 x = (long) ((atom->
coord[0] - min[0])/sampling);
592 y = (long) ((atom->
coord[1] - min[1])/sampling);
593 z = (long) ((atom->
coord[2] - min[2])/sampling);
594 grid[(z*size[1] + y)*size[0] + x] = 1;
613 size[0] = (int) (molgroup->
box[0]/sampling + 1);
614 size[1] = (int) (molgroup->
box[1]/sampling + 1);
615 size[2] = (int) (molgroup->
box[2]/sampling + 1);
616 long vol = (long)size.
volume();
622 for ( mol = molgroup->
mol->
next; mol; mol = mol->
next ) {
625 for ( i=0; i<vol; i++ ) {
627 if ( grid[i] ) mol->
sel++;
632 if ( mol->
sel ) mol->
sel = 0;
650 long nmol(0), ndel(0);
653 for ( mol = mol2 = molgroup->
mol; mol; ) {
654 if ( mol->
sel < 1 ) {
656 cout <<
"Deleting molecule " << mol->
id << endl;
657 if ( mol == molgroup->
mol ) {
660 mol = mol2 = molgroup->
mol;
675 cout <<
"Molecules deleted: " << ndel <<
" (" << ndel*100.0/nmol <<
" %)" << endl << endl;
694 long i, j, natom(atomarray.size()), ndel(0);
696 for ( i=0; i<natom-1; i++ ) atomarray[i]->sel = 1;
698 for ( i=0; i<natom-1; i++ )
if ( atomarray[i]->sel ) {
699 for ( j=i+1; j<natom; j++ )
if ( atomarray[j]->sel ) {
700 if ( atomarray[i]->coord.distance(atomarray[j]->coord) < mindist ) {
701 atomarray[j]->sel = 0;
708 cout <<
"Atoms marked for deletion: " << ndel <<
" (" << ndel*100.0/natom <<
")" << endl << endl;
722 long natom(0), ndel(0);
727 for ( mol = mol2 = molgroup->
mol; mol; ) {
728 for( res = res2 = mol->
res; res; ) {
729 for ( atom = atom2 = res->
atom; atom; ) {
730 if ( atom->
sel < 1 ) {
732 cout <<
"Deleting atom " << atom->
num << endl;
733 if ( atom == res->
atom ) {
736 atom = atom2 = res->
atom;
751 cout <<
"Deleting residue " << res->
num << endl;
752 if ( res == mol->
res ) {
755 res = res2 = mol->
res;
768 cout <<
"Deleting molecule " << mol->
id << endl;
769 if ( mol == molgroup->
mol ) {
772 mol = mol2 = molgroup->
mol;
785 cout <<
"Atoms deleted: " << ndel <<
" (" << ndel*100.0/natom <<
")" << endl << endl;
806 long iter, i, x, y, z, m, m2, nmol;
807 double d, dmax, all_shift = 1;
812 for ( nmol=0, mol = molgroup->
mol; mol; mol = mol->
next ) nmol++;
815 cout <<
"Untangling " << nmol <<
" molecules" << endl;
819 for ( iter=1; all_shift > 0 && iter < 100; iter++ ) {
821 size[0] = (int) (molgroup->
box[0]/sampling + 1);
822 size[1] = (int) (molgroup->
box[1]/sampling + 1);
823 size[2] = (int) (molgroup->
box[2]/sampling + 1);
824 for ( m=0, mol = molgroup->
mol; mol->
next; mol = mol->
next, m++ ) {
827 for ( m2=m+1, mol2 = mol->
next; mol2; mol2 = mol2->
next, m2++ ) {
834 for ( i=z=0; z<size[2]; z++ ) {
835 for ( y=0; y<size[1]; y++ ) {
836 for ( x=0; x<size[0]; x++, i++ ) {
837 if ( grid[i] & grid2[i] ) {
839 v = (v * sampling + molgroup->
min - c);
842 if ( dmax < d ) dmax = d;
858 for ( m=0, mol = molgroup->
mol; mol; mol = mol->
next, m++ ) {
863 molgroup->
box = molgroup->
max - molgroup->
min;
865 cout << iter <<
tab << all_shift << endl;
889 long iter, i, x, y, z, m, m2, nmg;
890 double d, dmax, all_shift = 1;
895 for ( nmg=0, mg = molgroup; mg; mg = mg->
next ) nmg++;
898 cout <<
"Untangling " << nmg <<
" molecule groups" << endl;
899 cout <<
"Sampling: " << sampling <<
" A" << endl;
900 cout <<
"Damping factor: " << lambda << endl;
906 cout <<
"Iter\tShift" << endl;
907 for ( iter=1; all_shift > 0 && iter < 100; iter++ ) {
911 for ( mg = molgroup; mg; mg = mg->
next ) {
916 size[0] = (int) (box[0]/sampling + 1);
917 size[1] = (int) (box[1]/sampling + 1);
918 size[2] = (int) (box[2]/sampling + 1);
919 for ( m=0, mg = molgroup; mg->
next; mg = mg->
next, m++ ) {
922 for ( m2=m+1, mg2 = mg->
next; mg2; mg2 = mg2->
next, m2++ ) {
929 for ( i=z=0; z<size[2]; z++ ) {
930 for ( y=0; y<size[1]; y++ ) {
931 for ( x=0; x<size[0]; x++, i++ ) {
932 if ( grid[i] & grid2[i] ) {
934 v = (v * sampling + min - c);
937 if ( dmax < d ) dmax = d;
953 for ( m=0, mg = molgroup; mg; mg = mg->
next, m++ ) {
960 cout << iter <<
tab << all_shift << endl;
Bmolgroup * molgroup_init()
Initializes and allocates a new molecule group.
long molgroup_stats(Bmolgroup *molgroup, int show)
Calculates the statistics of a molecule group.
int molgroup_untangle_molecules(Bmolgroup *molgroup, double sampling, double lambda)
Moves overlapping molecules away from each other.
Batom * atom_add(Batom **atom, const char *type)
Adds an atom to a linked list.
Bresidue * residue_add(Bresidue **res, const char *type)
Adds a residue to a linked list.
Vector3< T1 > vector3_difference_PBC(Vector3< T1 > &v1, Vector3< T1 > &v2, Vector3< T2 > &box)
Vector3< double > mol_center_of_mass(Bmolecule *mol)
Calculates the center of mass of a molecule.
int residue_kill(Bresidue *res)
Destroys a residue.
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
long molgroup_delete_deselected_molecules(Bmolgroup *molgroup)
Deletes deselected molecules.
Vector3< double > vector3_random_gaussian(double avg, double std)
Generates a random vector within a random gaussian-distributed length.
Header file for functions for creating random images.
3x3 Matrix manipulation functions
int molgroup_remove_overlapping_atoms(Bmolgroup *molgroup, double mindist)
Removes overlapping atoms.
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Bmolgroup ** molgroup_split_into_slices(Bmolgroup *molgroup, double slice_thickness, int &nslices)
Splits a set of coordinates into slices with a given thickness.
Library routines used for atomic coordinates.
vector< Batom * > atom_get_array(Bmolgroup *molgroup)
Generates an array of pointers to atom structures.
int molgroup_bond_pseudo_atoms(Bmolgroup *molgroup, int atoms_per_bond, int wrap)
Places pseudo-atoms on bonds.
double scalar(const Vector3 &v) const
double length(vector< T > v)
Header file for reading residue property files.
int molgroup_add_disulfides(Bmolgroup *molgroup, double distance)
Adds disulfide bonds when sulfur atoms are close to each other.
double distance(const Vector3 &v)
long molgroup_set_atom_types_to_elements(Bmolgroup *molgroup)
Sets atom types to element names.
char * grid_from_molgroup(Bmolgroup *molgroup, Vector3< double > min, double sampling, Vector3< int > size)
long molgroup_delete_deselected_atoms(Bmolgroup *molgroup)
Deletes deselected atoms.
Header file for reading reflection files.
int molgroup_prune_molecules(Bmolgroup *molgroup)
Deletes overlapping molecules.
Header file for reading atom property files.
int molgroup_untangle_groups(Bmolgroup *molgroup, double sampling, double lambda)
Moves overlapping molecules away from each other.
long molgroup_prune_overlapping_atoms(Bmolgroup *molgroup, double mindist)
Prunes overlapping atoms based on a distance criterion.
int molgroup_randomize(Bmolgroup *molgroup, double random_max)
Applies random displacements to coordinates.
Latom ** molgroup_atom_mesh_lists(Bmolgroup *molgroup, Vector3< int > size, Vector3< double > sampling)
Generates lists of atoms based on a grid.
double distance(vector< T1 > &v1, vector< T2 > &v2)
Vector3< T1 > vector3_set_PBC(Vector3< T1 > coord, Vector3< T2 > box)
int molgroup_insert(Bmolgroup *molgroup, Bmolgroup *molinsert, double distance)
Inserts one set of molecules into another.
bool bond_find(Bmolgroup *molgroup, Batom *atom1, Batom *atom2)
Header file for general utilities.
double molgroup_density(Bmolgroup *molgroup)
Calculates the number and mass density of a molecular system.
ostream & tab(ostream &out)
int molgroup_randomize_B(Bmolgroup *molgroup, double B)
Applies random displacements to coordinates.
int molecule_kill(Bmolecule *mol)
Destroys a molecule.
char * grid_from_molecule(Bmolecule *mol, Vector3< double > min, double sampling, Vector3< int > size)
long random_seed()
Gets a random seed and sets the flag.
Bbond * bond_add(Bbond **bond, Batom *atom1, Batom *atom2, double l, double k)
Adds a bond to a linked list.
Vector3< double > molgroup_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Header file for sequence utilities.
Header file for generalized linked list functions.
double irm(1.0L/get_rand_max())
long get_rand_max()
Finds the maximum random number for a system.
int molgroup_remove_hydrogens(Bmolgroup *molgroup)
Removes all hydrogens from a molecular system.
Bmolecule * molecule_add(Bmolecule **mol, char *name)
Adds a molecule to a linked list.
Library routines used for atomic coordinates.