Bsoft  2.1.0
Bernard's software package
mol_select.cpp
Go to the documentation of this file.
1 
9 #include "rwmolecule.h"
10 #include "rwatomprop.h"
11 #include "rwresprop.h"
12 #include "mol_select.h"
13 #include "mol_util.h"
14 #include "seq_util.h"
15 #include "linked_list.h"
16 #include "Matrix.h"
17 #include "utilities.h"
18 
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21 
28 {
29  long n(0);
30  Bmolecule* mol;
31  Bresidue* res;
32  Batom* atom;
33 
34  for ( mol = molgroup->mol; mol; mol = mol->next )
35  for( res = mol->res; res; res = res->next )
36  for ( atom = res->atom; atom; atom = atom->next )
37  if ( atom->sel ) ++n;
38 
39  if ( verbose )
40  cout << "Atoms selected: " << n << endl << endl;
41 
42  return n;
43 }
44 
51 long molgroup_select(Bmolgroup* molgroup, Bstring selstr)
52 {
53  if ( selstr == "all" )
54  return molgroup_select_all(molgroup);
55 
56  long i, j, len(selstr.length());
57  Bmolecule* mol;
58  Bresidue* res;
59  Batom* atom;
60 
61  Bstring mol_id;
62  Bstring res_id;
63  Bstring atom_id;
64 
65  molgroup_deselect_all(molgroup);
66 
67  for ( i=0; i<len; ++i ) {
68  if ( selstr[i] == '#' ) {
69  j = ++i;
70  while ( i<len && selstr[i] != ':' && selstr[i] != '@' ) ++i;
71  mol_id = selstr.substr(j, i-1);
72  }
73  if ( selstr[i] == ':' ) {
74  j = ++i;
75  while ( i<len && selstr[i] != '@' ) ++i;
76  res_id = selstr.substr(j, i-1);
77  }
78  if ( selstr[i] == '@' ) {
79  atom_id = selstr.substr(++i, len-1);
80  }
81  }
82 
83  if ( verbose ) {
84  cout << "Selection identifiers:" << endl;
85  if ( mol_id.length() )
86  cout << "Model: " << mol_id << endl;
87  if ( res_id.length() )
88  cout << "Residue: " << res_id << endl;
89  if ( atom_id.length() )
90  cout << "Atom: " << atom_id << endl;
91 // cout << endl;
92  }
93 
94  for ( mol = molgroup->mol; mol; mol = mol->next ) {
95  if ( mol_id.length() ) {
96  if ( mol->id == mol_id ) mol->sel = 1;
97  else mol->sel = 0;
98  }
99  for( res = mol->res; res; res = res->next ) {
100  if ( res_id.length() ) {
101 // cout << "-" << res->type << "-" << endl;
102  if ( strstr(res_id.c_str(), res->type) ) i = 1;
103  else i = 0;
104  }
105  if ( i ) {
106  for ( atom = res->atom; atom; atom = atom->next ) {
107  atom->sel = 1;
108  if ( atom_id.length() ) {
109  if ( strstr(atom->type, atom_id.c_str()) ) atom->sel = 1;
110  else atom->sel = 0;
111  }
112  }
113  }
114  }
115  }
116 
117  return molgroup_atoms_selected(molgroup);
118 }
119 
126 {
127  long n(0);
128  Bmolecule* mol;
129  Bresidue* res;
130  Batom* atom;
131 
132  for ( mol = molgroup->mol; mol; mol = mol->next ) {
133  mol->sel = 1;
134  for( res = mol->res; res; res = res->next )
135  for ( atom = res->atom; atom; atom = atom->next, n++ )
136  atom->sel = 1;
137  }
138 
139  return n;
140 }
141 
148 {
149  long n(0);
150  Bmolecule* mol;
151  Bresidue* res;
152  Batom* atom;
153 
154  for ( mol = molgroup->mol; mol; mol = mol->next )
155  for( res = mol->res; res; res = res->next )
156  for ( atom = res->atom; atom; atom = atom->next, n++ )
157  atom->sel = 0;
158 
159  return n;
160 }
161 
169 {
170  int nsel(0);
171  Bmolecule* mol;
172 
173  if ( verbose )
174  cout << "Selecting chains: " << chains << endl;
175 
176  for ( mol = molgroup->mol; mol; mol = mol->next ) {
177  if ( chains.contains(mol->id) ) {
178  mol->sel = 1;
179  nsel++;
180  } else {
181  mol->sel = 0;
182  }
183  }
184 
185  return nsel;
186 }
187 
195 int molgroup_coor_select_ring(Bmolgroup* molgroup, double rmin, double rmax)
196 {
197  if ( ( rmin < 0 ) && ( rmax > 1000 ) ) return 0;
198 
199  int sel;
200  double d;
201  Bmolecule* mol;
202  Bresidue* res;
203  Batom* atom;
204 
205  if ( verbose & VERB_LABEL )
206  cout << "Selecting ring: " << rmin << " " << rmax << endl;
207 
208  for ( mol = molgroup->mol; mol; mol = mol->next ) {
209  for( res = mol->res; res; res = res->next ) {
210  sel = 0;
211  for ( atom = res->atom; atom; atom = atom->next ) {
212  atom->sel = 0;
213  d = sqrt(atom->coord[0]*atom->coord[0]+atom->coord[1]*atom->coord[1]);
214  if ( ( d > rmin ) && ( d < rmax ) ) sel = 1;
215  }
216  if ( sel )
217  for ( atom = res->atom; atom; atom = atom->next )
218  atom->sel = 1;
219 
220  }
221  }
222 
223  return 0;
224 }
225 
234 {
235  Bmolecule* mol;
236  Bresidue* res;
237  Batom* atom;
238 
239  if ( verbose & VERB_LABEL )
240  cout << "Selecting atoms: " << min << " - " << max << endl;
241 
242  for ( mol = molgroup->mol; mol; mol = mol->next ) {
243  for( res = mol->res; res; res = res->next ) {
244  for ( atom = res->atom; atom; atom = atom->next ) {
245  atom->sel = 1;
246  if ( atom->coord[0] < min[0] || atom->coord[0] > max[0] ||
247  atom->coord[1] < min[1] || atom->coord[1] > max[1] ||
248  atom->coord[2] < min[2] || atom->coord[2] > max[2] )
249  atom->sel = 0;
250  }
251  }
252  }
253 
254  return 0;
255 }
256 
257 
molgroup_select_all
long molgroup_select_all(Bmolgroup *molgroup)
Sets selection for all atoms.
Definition: mol_select.cpp:125
Bresidue::next
Bresidue * next
Definition: rwmolecule.h:50
molgroup_coor_select_ring
int molgroup_coor_select_ring(Bmolgroup *molgroup, double rmin, double rmax)
Selects atoms in a ring.
Definition: mol_select.cpp:195
Bstring
Definition: Bstring.h:29
mol_select.h
Library routines to select atomic coordinates.
Bresidue::atom
Batom * atom
Definition: rwmolecule.h:54
molgroup_deselect_all
long molgroup_deselect_all(Bmolgroup *molgroup)
Unsets selection for all atoms.
Definition: mol_select.cpp:147
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Vector3< double >
verbose
int verbose
Batom::next
Batom * next
Definition: rwmolecule.h:25
rwresprop.h
Header file for reading residue property files.
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
molgroup_coor_select
int molgroup_coor_select(Bmolgroup *molgroup, Vector3< double > min, Vector3< double > max)
Selects atoms within a box.
Definition: mol_select.cpp:233
molgroup_select
long molgroup_select(Bmolgroup *molgroup, Bstring selstr)
Sets selection based on a specification.
Definition: mol_select.cpp:51
rwmolecule.h
Header file for reading reflection files.
molgroup_atoms_selected
long molgroup_atoms_selected(Bmolgroup *molgroup)
Returns the number of atoms selected.
Definition: mol_select.cpp:27
rwatomprop.h
Header file for reading atom property files.
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
Bmolecule
Definition: rwmolecule.h:107
Batom::type
char type[8]
Definition: rwmolecule.h:28
utilities.h
Header file for general utilities.
Bstring::substr
Bstring substr(long start, long len)
Definition: Bstring.cpp:332
Bstring::length
long length() const
Definition: Bstring.cpp:263
seq_util.h
Header file for sequence utilities.
Bresidue::type
char type[6]
Definition: rwmolecule.h:53
molgroup_select_chains
int molgroup_select_chains(Bmolgroup *molgroup, Bstring chains)
Selects molecules.
Definition: mol_select.cpp:168
Batom::sel
int sel
Definition: rwmolecule.h:34
Matrix.h
Generalized matrix class.
Bresidue
Definition: rwmolecule.h:49
linked_list.h
Header file for generalized linked list functions.
Bmolgroup
Definition: rwmolecule.h:170
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
Bmolecule::sel
int sel
Definition: rwmolecule.h:120
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
Batom::coord
Vector3< double > coord
Definition: rwmolecule.h:30
Batom
Definition: rwmolecule.h:24
Bmolecule::id
Bstring id
Definition: rwmolecule.h:110
mol_util.h
Library routines used for atomic coordinates.