| Bsoft 2.0.5 Bernard's software package

bmoledit.cpp
Go to the documentation of this file.
1
9 #include "rwmolecule.h"
10 #include "mol_symmetry.h"
11 #include "mol_transform.h"
12 #include "mol_edit.h"
13 #include "mol_util.h"
14 #include "utilities.h"
15 #include "options.h"
16 #include "timer.h"
17
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20
21 long molgroup_trim(Bmolgroup* molgroup, Vector3<double> box);
22
23 /* Usage assistance */
24 const char* use[] = {
25 " ",
26 "Usage: bmoledit [options] in.pdb out.pdb",
27 "----------------------------------------",
28 "Manipulates atomic coordinate files.",
29 " ",
30 "Actions:",
31 "-rename D Rename molecules from the given letter.",
32 "-renumber 52 Renumber residues from the given number.",
33 "-select CA Atom selection (default all).",
34 "-elements Use elements as identifiers for atom types.",
35 "-split Split molecule groups, output multiple numbered files.",
36 "-slices 23.7 Split coordinates into slices of this thickness, output multiple numbered files.",
37 "-translate 0,-50,22 Translate (angstrom).",
38 "-trim 200,230,180 Trim to new box size (use with -translate).",
39 "-noH Remove all hydrogens.",
40 "-SS 2.2 Add disulfide bonds within the given separation.",
41 "-nobonds Remove all bond specifications.",
42 "-bonds 2.1 Add bonds between atoms closer than the given distance.",
43 "-pseudobonds 3 Add pseudo-atoms on bonds given the number per bond.",
44 "-random 1.2 Add a random displacement to each coordinate within a maximum (angstrom).",
45 "-prune Remove overlapping molecules.",
46 "-untangle 3.5,0.2 Eliminate overlaps by moving molecules apart (sampling and damping factor).",
47 " ",
48 "Parameters:",
49 "-verbose 7 Verbosity of output.",
50 "-distance 3.5 Distance between overlapping atoms allowed (default 3 angstrom, use with -insert).",
51 " ",
52 "Input:",
53 "-parameters parm.star Atomic properties parameter file (default atom_prop.star).",
54 "-insert in.pdb Insert this into the input file, deleting overlapping atoms in the input file.",
55 " (use with -distance to indicate cutoff to eliminate atoms).",
56 " ",
57 NULL
58 };
59
60 int main(int argc, char **argv)
61 {
62 /* Initialize variables */
63 int elements(0); // Flag to use element names
64 char first_name(0); // First molecule name for renaming
65 int first_res(0); // Don't renumber
66 int split(0); // Flag to split molecule groups
67 double slice_thickness(0); // Slice thickness for splitting up coordinates
68 Transform t; // Transformation details
69 Vector3<double> trim; // New enclosing box
70 int removeH(0); // Flag to remove hydrogens
71 double SSdistance(0); // Maximum distance between sulfur atoms
72 int removeBonds(0); // Flag to remove bonds
73 double addBonds(0); // Cutoff distance to add bonds, 0=don't add
74 int pseudobonds(0); // Pseudo-atoms to add
75 Bstring insert; // Molecules to insert
76 double random_max(0); // Random displacement maximum in angstrom
77 double distance(0); // Distance allowed between overlapping atoms in angstrom
78 int set_wrap(0); // Flag for wrapping coordinates
79 int prune(0); // Flag to remove overlapping molecules
80 double untangle(0); // Sampling for moving overlapping molecules
81 double lambda(0.1); // Damping factor for moving overlapping molecules
82 Vector3<double> box; // Enclosing box
83 Bstring atom_select("ALL");
84 Bstring paramfile; // Use default parameter file
85
86 int optind;
87 Boption* option = get_option_list(use, argc, argv, optind);
88 Boption* curropt;
89 for ( curropt = option; curropt; curropt = curropt->next ) {
90 if ( curropt->tag == "select" ) {
91 atom_select = curropt->value;
92 if ( atom_select.length() < 1 )
93 cerr << "-select: A selection must be specified!" << endl;
94 }
95 if ( curropt->tag == "elements" ) elements = 1;
96 if ( curropt->tag == "split" ) split = 1;
97 if ( curropt->tag == "rename" )
98 if ( ( first_name = curropt->value[0] ) < 1 )
99 cerr << "-rename: The first molecule name must be specified!" << endl;
100 if ( curropt->tag == "renumber" )
101 if ( ( first_res = curropt->value.integer() ) < 1 )
102 cerr << "-renumber: The first residue number must be specified!" << endl;
103 if ( curropt->tag == "slices" ) {
104 if ( ( slice_thickness = curropt->value.real() ) < 1 )
105 cerr << "-slices: A slice thickness must be specified!" << endl;
106 else
107 if ( slice_thickness <= 0 ) slice_thickness = 0;
108 }
109 if ( curropt->tag == "translate" )
110 t.trans = curropt->vector3();
111 if ( curropt->tag == "trim" )
112 trim = curropt->size();
113 if ( curropt->tag == "noH" )
114 removeH = 1;
115 if ( curropt->tag == "SS" )
116 if ( ( SSdistance = curropt->value.real() ) < 0.1 )
117 cerr << "-SS: A maximum separation distance must be specified!" << endl;
118 if ( curropt->tag == "nobonds" )
119 removeBonds = 1;
120 if ( curropt->tag == "bonds" )
121 if ( ( addBonds = curropt->value.real() ) < 0.1 )
122 cerr << "-bonds: A maximum bond length must be specified!" << endl;
123 if ( curropt->tag == "pseudobonds" )
124 if ( ( pseudobonds = curropt->value.integer() ) < 1 )
125 cerr << "-pseudobonds: A number of pseudo-atoms must be specified!" << endl;
126 if ( curropt->tag == "insert" )
127 insert = curropt->filename();
128 if ( curropt->tag == "random" )
129 if ( ( random_max = curropt->value.real() ) < 1 )
130 cerr << "-random: A random displacement maximum must be specified!" << endl;
131 if ( curropt->tag == "prune" ) prune = 1;
132 if ( curropt->tag == "untangle" )
133 if ( curropt->values(untangle, lambda) < 1 )
134 cerr << "-untangle: Grid sampling in angstrom must be specified!" << endl;
135 if ( curropt->tag == "distance" )
136 if ( ( distance = curropt->value.real() ) < 1 )
137 cerr << "-distance: A separation distance must be specified!" << endl;
138 if ( curropt->tag == "wrap" ) {
139 box = curropt->size();
140 set_wrap = 1; // Wrap within periodic boundaries
141 }
142 if ( curropt->tag == "parameters" )
143 paramfile = curropt->filename();
144 }
145 option_kill(option);
146
147 if ( optind >= argc ) bexit(-1);
148
149 double ti = timer_start();
150
151 Bstring filename = argv[optind++];
152 Bmolgroup* molgroup = read_molecule(filename, atom_select, paramfile);
153 if ( !molgroup ) {
154 cerr << "Error: Coordinate file not read!" << endl;
155 bexit(-1);
156 }
157
158 if ( elements )
159 molgroup_set_atom_types_to_elements(molgroup);
160
161 if ( first_name )
162 molgroup_rename(molgroup, first_name);
163
164 if ( first_res > 0 )
165 molgroup_residue_renumber(molgroup, first_res);
166
167 if ( t.trans.length() ) molgroup_coor_shift(molgroup, t.trans);
168
169 if ( trim.volume() ) molgroup_trim(molgroup, trim);
170 else if ( set_wrap ) molgroup->box = box;
171
172 if ( removeH )
173 molgroup_remove_hydrogens(molgroup);
174
175 if ( SSdistance )
176 molgroup_add_disulfides(molgroup, SSdistance);
177
178 if ( removeBonds ) {
179 bond_kill(molgroup->bond);
180 molgroup->bond = NULL;
181 }
182
183 if ( addBonds )
184 molgroup_bond_list_generate(molgroup, addBonds, set_wrap);
185
186 if ( pseudobonds )
187 molgroup_bond_pseudo_atoms(molgroup, pseudobonds, set_wrap);
188
189 Bmolgroup* molinsert = NULL;
190 if ( insert.length() ) {
191 molinsert = read_molecule(insert, atom_select, paramfile);
192 molgroup_insert(molgroup, molinsert, distance); // Remember that the group inserted is deallocated
193 molgroup_kill(molinsert);
194 }
195
196 if ( random_max )
197 molgroup_randomize(molgroup, random_max);
198
199 if ( prune )
200 molgroup_prune_molecules(molgroup);
201
202 if ( untangle )
203 molgroup_untangle_molecules(molgroup, untangle, lambda);
204
205 int i, num(0);
206 Bmolgroup** molgroup_set;
207 if ( optind < argc ) {
208 filename = argv[optind];
209 molecule_update_comment(molgroup, argc, argv);
210 if ( split ) {
211 molecules_to_molgroups(molgroup);
212 molgroup_list_write(filename, molgroup);
213 } else if ( slice_thickness > 0 ) {
214 molgroup_set = molgroup_split_into_slices(molgroup, slice_thickness, num);
215 for ( i=0; i<num; i++ ) {
216 filename = filename.pre_rev('.') + Bstring(i+1, "_%03d.") + filename.post_rev('.');
217 write_molecule(filename, molgroup_set[i]);
218 molgroup_kill(molgroup_set[i]);
219 }
220 delete[] molgroup_set;
221 } else {
222 i = write_molecule(argv[optind], molgroup);
223 if ( i < 1 ) {
224 cerr << "Error: No output file written!" << endl;
225 bexit(-1);
226 }
227 }
228 }
229
230 molgroup_kill(molgroup);
231
232 if ( verbose & VERB_TIME )
233 timer_report(ti);
234
235 bexit(0);
236 }
237
244 long molgroup_trim(Bmolgroup* molgroup, Vector3<double> box)
245 {
246 if ( box.volume() < 1 ) return 0;
247
248 long n(0), nsel(0);
249 Bmolecule* mol;
250 Bresidue* res;
251 Batom* atom;
252 Vector3<double> start, end(box);
253
254 if ( verbose & VERB_PROCESS )
255 cout << "Trimming to a box of size: " << box << endl;
256
257 for ( mol = molgroup->mol; mol; mol = mol->next ) {
258 for( res = mol->res; res; res = res->next ) {
259 for ( atom = res->atom; atom; atom = atom->next, n++ ) {
260 if ( atom->coord.within(start, end) ) {
261 atom->sel = 1;
262 nsel++;
263 } else {
264 atom->sel = 0;
265 }
266 }
267 }
268 }
269
270 long ndel = molgroup_delete_deselected_atoms(molgroup);
271
272 if ( n != nsel + ndel )
273 cerr << "Error: There is a discrepancy between the the total number of atoms ("
274 << n << ") and the sum of selected (" << nsel
275 << ") and deleted (" << ndel << ") atoms!" << endl;
276
277 molgroup->box = box;
278
279 if ( verbose & VERB_PROCESS )
280 cout << "Number of atoms remaining: " << nsel << endl;
281
282 return nsel;
283 }
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:536
molgroup_untangle_molecules
int molgroup_untangle_molecules(Bmolgroup *molgroup, double sampling, double lambda)
Moves overlapping molecules away from each other.
Definition: mol_edit.cpp:766
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Bstring::real
double real()
Definition: Bstring.cpp:545
molgroup_prune_molecules
int molgroup_prune_molecules(Bmolgroup *molgroup)
Deletes overlapping molecules.
Definition: mol_edit.cpp:569
molgroup_delete_deselected_atoms
long molgroup_delete_deselected_atoms(Bmolgroup *molgroup)
Deletes deselected atoms.
Definition: mol_edit.cpp:684
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
molgroup_add_disulfides
int molgroup_add_disulfides(Bmolgroup *molgroup, double distance)
Adds disulfide bonds when sulfur atoms are close to each other.
Definition: mol_edit.cpp:101
Vector3::length
double length()
Definition: Vector3.h:222
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
Boption::tag
Bstring tag
Definition: options.h:29
molecules_to_molgroups
int molecules_to_molgroups(Bmolgroup *molgroup)
Converts molecules in a molecule group to individual molecule groups.
Definition: rwmolecule.cpp:1739
molgroup_randomize
int molgroup_randomize(Bmolgroup *molgroup, double random_max)
Applies random displacements to coordinates.
Definition: mol_edit.cpp:369
Bstring::length
long length() const
Definition: Bstring.cpp:263
mol_transform.h
Library routines used for atomic coordinate transformations.
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
molgroup_insert
int molgroup_insert(Bmolgroup *molgroup, Bmolgroup *molinsert, double distance)
Inserts one set of molecules into another.
Definition: mol_edit.cpp:244
molgroup_rename
int molgroup_rename(Bmolgroup *molgroup, char first_name)
Renames molecules.
Definition: mol_util.cpp:161
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
molgroup_bond_list_generate
Bbond * molgroup_bond_list_generate(Bmolgroup *molgroup, double maxlength, int wrap)
Generates a bond list based on atom separation.
Definition: rwmolecule.cpp:1555
molgroup_list_write
int molgroup_list_write(Bstring &filename, Bmolgroup *molgroup)
Writes a molecule group list.
Definition: rwmolecule.cpp:1048
mol_symmetry.h
Library routines used for symmetry operations on atomic coordinates.
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Batom::sel
int sel
Definition: rwmolecule.h:34
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
mol_util.h
Library routines used for atomic coordinates.
Boption::size
Vector3< long > size()
Definition: options.h:163
molgroup_trim
long molgroup_trim(Bmolgroup *molgroup, Vector3< double > box)
Deletes atoms outside the box.
Definition: bmoledit.cpp:244
Transform
Definition: Transform.h:24
rwmolecule.h
Header file for reading reflection files.
Bmolgroup
Definition: rwmolecule.h:170
Boption
A class for a command line input option.
Definition: options.h:26
use
const char * use[]
Definition: bmoledit.cpp:24
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
verbose
int verbose
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
bond_kill
int bond_kill(Bbond *bond)
Dealocates a list of bonds.
Definition: rwmolecule.cpp:480
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
Bresidue::atom
Batom * atom
Definition: rwmolecule.h:54
molgroup_bond_pseudo_atoms
int molgroup_bond_pseudo_atoms(Bmolgroup *molgroup, int atoms_per_bond, int wrap)
Places pseudo-atoms on bonds.
Definition: mol_edit.cpp:496
Bmolecule
Definition: rwmolecule.h:107
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bmolgroup::bond
Bbond * bond
Definition: rwmolecule.h:190
Bresidue::next
Bresidue * next
Definition: rwmolecule.h:50
Bresidue
Definition: rwmolecule.h:49
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Batom
Definition: rwmolecule.h:24
molecule_update_comment
int molecule_update_comment(Bmolgroup *molgroup, int n, char **strings)
Puts a set of strings and time in the main comment of a molecule group.
Definition: rwmolecule.cpp:1462
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
main
int main(int argc, char **argv)
Definition: bmoledit.cpp:60
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
molgroup_coor_shift
int molgroup_coor_shift(Bmolgroup *molgroup, Vector3< double > shift)
Translates a molecule group.
Definition: mol_transform.cpp:28
Batom::coord
Vector3< double > coord
Definition: rwmolecule.h:30
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
molgroup_remove_hydrogens
int molgroup_remove_hydrogens(Bmolgroup *molgroup)
Removes all hydrogens from a molecular system.
Definition: mol_edit.cpp:52
molgroup_residue_renumber
int molgroup_residue_renumber(Bmolgroup *molgroup, int first)
Renumbers residues.
Definition: mol_util.cpp:182
options.h
Header file for option handlers.
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
split
vector< string > split(const string &s)
Splits a string on whitespace.
Definition: string_util.cpp:92
Vector3::volume
double volume()
Definition: Vector3.h:235
molgroup_set_atom_types_to_elements
long molgroup_set_atom_types_to_elements(Bmolgroup *molgroup)
Sets atom types to element names.
Definition: mol_edit.cpp:29
molgroup_split_into_slices
Bmolgroup ** molgroup_split_into_slices(Bmolgroup *molgroup, double slice_thickness, int &nslices)
Splits a set of coordinates into slices with a given thickness.
Definition: mol_edit.cpp:158
Batom::next
Batom * next
Definition: rwmolecule.h:25
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
mol_edit.h
Library routines used for atomic coordinates.
read_molecule
Bmolgroup * read_molecule(const char *filename, const char *select, const char *paramfile)
The generalized function for reading molecular files.
Definition: rwmolecule.cpp:818
Vector3::within
bool within(Vector3 &v1, Vector3 &v2)
Definition: Vector3.h:279