Bsoft  2.1.0
Bernard's software package
bmolsym.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 /* Usage assistance */
22 const char* use[] = {
23 " ",
24 "Usage: bmolsym [options] in.pdb out.pdb",
25 "---------------------------------------",
26 "Performs symmetry operations on molecules.",
27 " ",
28 "Actions:",
29 "-translate 0,-50,22 Translate (angstrom).",
30 "-rotate 0.5,0,5.8,45 Rotate around a vector (x,y,z) by an angle.",
31 "-select CA Atom selection (default all).",
32 "-apply C5 Apply point group symmetry.",
33 "-find C5 Find standard orientation for this point group symmetry.",
34 "-Bfactor D5 Calculate B factors for this point group symmetry.",
35 "-pdbsymmetry Read SMTRY matrices from a PDB file and apply them.",
36 "-pdbbiomt Read BIOMT matrices from a PDB file and apply them.",
37 "-rename D Rename molecules from the given letter.",
38 "-show Show operational symmetry matrices.",
39 " ",
40 "Parameters:",
41 "-verbose 7 Verbosity of output.",
42 "-origin 10,-10,20 Origin for rotation (default 0,0,0, can be \"center\" for COM).",
43 "-reference 0,1.5,-0.2,35 Reference symmetry axis and rotation angle (default 0,0,1,0).",
44 "-distance 3.5 Distance between overlapping atoms allowed (default 3 angstrom, use with -apply).",
45 " ",
46 "Input:",
47 "-parameters parm.star Atomic properties parameter file (default atom_prop.star).",
48 "-similarity sim.star Residue similarity matrix for finding orientation (default blosum62.star).",
49 " ",
50 NULL
51 };
52 
53 int main(int argc, char **argv)
54 {
55  /* Initialize variables */
56  char first_name(0); // First molecule name for renaming
57  int com_origin(0); // Flag to set the center-of-mass as origin of rotation
58  Transform t; // Rotation origin, axis and angle
59  Bstring atom_select("ALL");
60  View ref_view; // Reference view for symmetry application
61  Bsymmetry* sym = NULL; // Point group
62  Bsymmetry* sym_B = NULL; // Symmetry for B factor calculation
63  int sym_flag(0);
64  int pdbsym_flag(0); // Flag to get SMTRY matrices from a PDB file
65  int pdbbio_flag(0); // Flag to get BIOMT matrices from a PDB file
66  double distance(0); // Distance allowed between overlapping atoms in angstrom
67  int show(0); // Flag to show operational matrices
68  Bstring paramfile; // Use default parameter file
69  Bstring simfile; // Use default similarity matrix file
70 
71  int optind;
72  Boption* option = get_option_list(use, argc, argv, optind);
73  Boption* curropt;
74  for ( curropt = option; curropt; curropt = curropt->next ) {
75  if ( curropt->tag == "rename" )
76  if ( ( first_name = curropt->value[0] ) < 1 )
77  cerr << "-rename: The first molecule name must be specified!" << endl;
78  if ( curropt->tag == "translate" )
79  t.trans = curropt->vector3();
80  if ( curropt->tag == "rotate" ) {
81  vector<double> d = curropt->value.split_into_doubles(",");
82  if ( d.size() < 4 )
83  cerr << "-rotate: All three vector elements and an angle must be specified!" << endl;
84  else {
85  t.axis = Vector3<double>(d[0], d[1], d[2]);
86  t.angle = d[3] * M_PI/180.0;
87  }
88  }
89  if ( curropt->tag == "origin" ) {
90  if ( curropt->value.contains("cen") )
91  com_origin = 1;
92  else
93  t.origin = curropt->origin();
94  }
95  if ( curropt->tag == "select" ) {
96  atom_select = curropt->value;
97  if ( atom_select.length() < 1 )
98  cerr << "-select: A selection must be specified!" << endl;
99  }
100  if ( curropt->tag == "apply" ) {
101  sym = curropt->symmetry();
102  if ( !sym )
103  cerr << "-apply: A point group must be specified!" << endl;
104  else
105  sym_flag = 1;
106  }
107  if ( curropt->tag == "find" ) {
108  sym = curropt->symmetry();
109  if ( !sym )
110  cerr << "-find: A point group must be specified!" << endl;
111  else
112  sym_flag = 2;
113  }
114  if ( curropt->tag == "Bfactor" )
115  sym_B = curropt->symmetry();
116  if ( curropt->tag == "pdbsymmetry" ) pdbsym_flag = 1;
117  if ( curropt->tag == "pdbbiomt" ) pdbbio_flag = 1;
118  if ( curropt->tag == "reference" )
119  ref_view = curropt->view();
120  if ( curropt->tag == "distance" )
121  if ( ( distance = curropt->value.real() ) < 0.1 )
122  cerr << "-distance: A separation distance must be specified!" << endl;
123  if ( curropt->tag == "show" )
124  show = 1;
125  if ( curropt->tag == "parameters" )
126  paramfile = curropt->filename();
127  if ( curropt->tag == "similarity" )
128  simfile = curropt->filename();
129  }
130  option_kill(option);
131 
132  double ti = timer_start();
133 
135 
136  if ( optind >= argc ) bexit(-1);
137 
138  Bstring filename(argv[optind++]);
139  Bmolgroup* molgroup = read_molecule(filename, atom_select, paramfile);
140  if ( !molgroup ) {
141  cerr << "Error: Coordinate file not read!" << endl;
142  bexit(-1);
143  }
144 
145  if ( com_origin )
146  t.origin = molgroup_center_of_mass(molgroup);
147 
148  if ( t.angle == 0 )
149  molgroup_coor_shift(molgroup, t.trans);
150  else
151  molgroup_coor_rotate(molgroup, t);
152 
153  molgroup_stats(molgroup);
154 
155  Bresidue_matrix* simat;
156  if ( sym_flag == 2 && sym ) {
157 // molgroup_find_standard_view(molgroup, sym, ref_view);
158  simat = get_residue_matrix(simfile);
159  molgroup_orient_to_standard_view(molgroup, sym, ref_view, simat);
160  residue_matrix_kill(simat);
161  }
162 
163  if ( sym_flag == 1 && sym ) {
164  molgroup_apply_point_group(molgroup, sym, ref_view);
166  }
167 
168  if ( pdbsym_flag )
169  molgroup_apply_symmetry_from_pdb(molgroup, filename);
170 
171  if ( pdbbio_flag )
172  molgroup_apply_matrices_from_pdb(molgroup, filename);
173 
174  if ( molgroup && sym_B )
175  molgroup_symmetry_B(molgroup, sym_B);
176 
177  if ( molgroup && sym )
178  molgroup_symmetry_RMSD(molgroup, sym);
179 
180  if ( first_name )
181  molgroup_rename(molgroup, first_name);
182 
183  if ( optind < argc ) {
184  molecule_update_comment(molgroup, argc, argv);
185  if ( write_molecule(argv[optind], molgroup) < 1 )
186  cerr << "Error: " << argv[optind] << " not written!" << endl;
187  }
188 
189  molgroup_kill(molgroup);
190  if ( sym ) kill_symmetry(sym);
191  if ( sym_B ) kill_symmetry(sym_B);
192 
193  if ( verbose & VERB_TIME )
194  timer_report(ti);
195 
196  bexit(0);
197 }
Boption
A class for a command line input option.
Definition: options.h:26
molgroup_stats
long molgroup_stats(Bmolgroup *molgroup, int show)
Calculates the statistics of a molecule group.
Definition: rwmolecule.cpp:1296
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
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:1467
Bstring
Definition: Bstring.h:29
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
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
main
int main(int argc, char **argv)
Definition: bmolsym.cpp:53
Bstring::real
double real()
Definition: Bstring.cpp:553
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
options.h
Header file for option handlers.
View
Definition: View.h:26
Boption::origin
Vector3< double > origin()
Definition: options.h:180
Boption::view
View view()
Definition: options.h:247
Bsymmetry
Definition: symmetry.h:38
mol_transform.h
Library routines used for atomic coordinate transformations.
Transform::origin
Vector3< double > origin
Definition: Transform.h:27
molgroup_coor_rotate
int molgroup_coor_rotate(Bmolgroup *molgroup, Transform t)
Rotates and translates a molecule group.
Definition: mol_transform.cpp:87
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:240
Boption::tag
Bstring tag
Definition: options.h:29
molgroup_remove_overlapping_atoms
int molgroup_remove_overlapping_atoms(Bmolgroup *molgroup, double mindist)
Removes overlapping atoms.
Definition: mol_edit.cpp:444
rwmolecule.h
Header file for reading reflection files.
use
const char * use[]
Definition: bmolsym.cpp:22
Boption::value
Bstring value
Definition: options.h:30
molgroup_symmetry_B
double molgroup_symmetry_B(Bmolgroup *molgroup, Bsymmetry *sym)
Calculates the B factors from symmetry-related molecules.
Definition: mol_symmetry.cpp:883
timer.h
Utilities for timing functions.
show
int show(0)
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:673
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:538
molgroup_orient_to_standard_view
int molgroup_orient_to_standard_view(Bmolgroup *molgroup, Bsymmetry *sym, View ref_view, Bresidue_matrix *simat)
Searches for the standard view based on point group symmetry.
Definition: mol_symmetry.cpp:608
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
molgroup_coor_shift
int molgroup_coor_shift(Bmolgroup *molgroup, Vector3< double > shift)
Translates a molecule group.
Definition: mol_transform.cpp:28
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
verbose
int verbose
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
Bstring::length
long length() const
Definition: Bstring.cpp:263
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
molgroup_center_of_mass
Vector3< double > molgroup_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Definition: mol_util.cpp:307
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
sym_show_operational_matrices
int sym_show_operational_matrices(Bsymmetry *sym)
Show symmetry matrices associated with each symmetry operator.
Definition: symmetry.cpp:1140
molgroup_rename
int molgroup_rename(Bmolgroup *molgroup, char first_name)
Renames molecules.
Definition: mol_util.cpp:161
mol_symmetry.h
Library routines used for symmetry operations on atomic coordinates.
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
Boption::filename
Bstring filename()
Definition: options.h:85
residue_matrix_kill
int residue_matrix_kill(Bresidue_matrix *resmat)
Deallocating a residue matrix.
Definition: rwresprop.cpp:208
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
molgroup_symmetry_RMSD
double molgroup_symmetry_RMSD(Bmolgroup *molgroup, Bsymmetry *sym)
Calculates the RMSD for symmetry in the standard orientation.
Definition: mol_symmetry.cpp:830
molgroup_apply_point_group
int molgroup_apply_point_group(Bmolgroup *molgroup, Bsymmetry *sym, View ref_view)
Generates all symmetry-related coordinates.
Definition: mol_symmetry.cpp:34
Bmolgroup
Definition: rwmolecule.h:170
Transform::axis
Vector3< double > axis
Definition: Transform.h:28
Transform::angle
double angle
Definition: Transform.h:29
molgroup_apply_matrices_from_pdb
int molgroup_apply_matrices_from_pdb(Bmolgroup *molgroup, Bstring &filename)
Generates all symmetry-related coordinates using PDB file matrices.
Definition: mol_symmetry.cpp:270
Transform
Definition: Transform.h:24
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
Bresidue_matrix
Definition: rwresprop.h:44
get_residue_matrix
Bresidue_matrix * get_residue_matrix(Bstring &filename)
Reading a residue matrix from a file.
Definition: rwresprop.cpp:164
molgroup_apply_symmetry_from_pdb
int molgroup_apply_symmetry_from_pdb(Bmolgroup *molgroup, Bstring &filename)
Generates all symmetry-related coordinates using PDB file matrices.
Definition: mol_symmetry.cpp:200
mol_util.h
Library routines used for atomic coordinates.