| Bsoft 2.0.5 Bernard's software package

bwater.cpp
Go to the documentation of this file.
1
9 #include "rwmd.h"
10 #include "mol_md.h"
11 #include "rwmolecule.h"
12 #include "mol_water.h"
13 #include "mol_bonds.h"
14 #include "linked_list.h"
15 #include "options.h"
16 #include "utilities.h"
17 #include "timer.h"
18
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21
22
23 /* Usage assistance */
24 const char* use[] = {
25 " ",
26 "Usage: bwater [options] in.pdb out.pdb",
27 "--------------------------------------",
28 "Generates and does molecular dynamics on blocks of water.",
29 " ",
30 "Actions:",
31 "-create rect Generate water, 1=random, 2=rectangular, 3=tetrahedral (use with -size option).",
32 "-rdf 0.05 Calculate the radial distribution function with the given sampling (angstrom).",
33 "-dynamics 4000 Number of iterations for molecular dynamics.",
34 " ",
35 "Parameters:",
36 "-verbose 7 Verbose output.",
37 //"-origin 0,0,0 Origin (angstrom).",
38 "-size 10,10,10 Size for generating water (angstrom).",
39 "-wrap Wrap around (periodic boundaries).",
40 "-timestep 0.01 Integration time step (default 0.001).",
41 "-velocitylimit 0.01 Limit on the velocity (default 0.1 per time step).",
42 "-friction 0.2 Friction constant (default 1 = no friction).",
43 "-Kbond 150 Bond strength (default 1).",
44 "-Kangle 4 Angle strength (default 1).",
45 "-Kvdw 0.1 Van der Waals strength (default 0).",
46 "-Kelectrostatic 0.4 Electrostatic strength (default 0).",
47 "-cutoff 7.8 Distance cutoff for non-bonded forces (default 5 A).",
48 " ",
49 "Input:",
50 "-parameters md.star Molecular dynamics parameter file (default md_param.star).",
51 " ",
52 "Output:",
53 "-output param.star Output parameter file.",
54 " ",
55 NULL
56 };
57
58 int main(int argc, char **argv)
59 {
60 /* Initialize variables */
61 int genwater(0); // Flag to generate water
62 double rdf(0); // Calculate RDF at this sampling (0=not)
63 int wrap(0); // No wrapping as default
64 // int set_origin(0); // Flag to indicate if origin is set
65 Vector3<double> size; // Size for generating water
66 // Vector3<double> origin; // Coordinate origin in angstrom
67 int max_iter(0); // Number of iterations/cycles for minimization
68 double timestep(0.001); // Integration time step
69 double velocitylimit(0.1); // Limit on velocity per time step
70 double Kfriction(1); // Friction constant, 1=no friction
71 double Kbond(1); // Bond strength
72 double Kangle(1); // Angle strength
73 double Kelec(0); // Electrostatic strength
74 double Kvdw(0); // Van der Waals strength
75 double cutoff(5); // Distance cutoff for non-bonded forces and rdf
76 Bstring atom_select("all");
77 Bstring paramfile("water_param.star"); // Default parameter file
78 Bstring paramout; // Output parameter file
79
80 int optind;
81 Boption* option = get_option_list(use, argc, argv, optind);
82 Boption* curropt;
83 for ( curropt = option; curropt; curropt = curropt->next ) {
84 if ( curropt->tag == "create" ) {
85 if ( curropt->value.contains("ran") ) genwater = 1;
86 else if ( curropt->value.contains("rec") ) genwater = 2;
87 else if ( curropt->value.contains("tet") ) genwater = 3;
88 else genwater = curropt->value.integer();
89 }
90 if ( curropt->tag == "rdf" )
91 if ( ( rdf = curropt->value.real() ) < 0.01 )
92 cerr << "-rdf: A sampling interval must be specified!" << endl;
93 if ( curropt->tag == "size" ) {
94 size = curropt->vector3();
95 if ( size.volume() < 1 )
96 cerr << "-size: All three dimensions must be specified" << endl;
97 }
98 // if ( curropt->tag == "origin" ) {
99 // origin = curropt->origin();
100 // set_origin = 1;
101 // }
102 if ( curropt->tag == "wrap" )
103 wrap = 1;
104 if ( curropt->tag == "dynamics" )
105 if ( ( max_iter = curropt->value.integer() ) < 1 )
106 cerr << "-dynamics: The number of iterations must be specified!" << endl;
107 if ( curropt->tag == "timestep" )
108 if ( ( timestep = curropt->value.real() ) < 1e-30 )
109 cerr << "-timestep: The time step must be specified!" << endl;
110 if ( curropt->tag == "velocitylimit" )
111 if ( ( velocitylimit = curropt->value.real() ) < 1e-30 )
112 cerr << "-velocitylimit: The velocity limit must be specified!" << endl;
113 if ( curropt->tag == "friction" )
114 if ( ( Kfriction = curropt->value.real() ) < 1e-30 )
115 cerr << "-friction: The friction constant must be specified!" << endl;
116 if ( curropt->tag == "Kbond" )
117 if ( ( Kbond = curropt->value.real() ) < 1e-30 )
118 cerr << "-Kbond: The bond strength must be specified!" << endl;
119 if ( curropt->tag == "Kangle" )
120 if ( ( Kangle = curropt->value.real() ) < 1e-30 )
121 cerr << "-Kangle: The angle strength must be specified!" << endl;
122 if ( curropt->tag == "Kelectrostatic" )
123 if ( ( Kelec = curropt->value.real() ) < 1e-30 )
124 cerr << "-Kelectrostatic: The electrostatic strength must be specified!" << endl;
125 if ( curropt->tag == "Kvdw" )
126 if ( ( Kvdw = curropt->value.real() ) < 1e-30 )
127 cerr << "-Kvdw: The Van der Waals strength must be specified!" << endl;
128 if ( curropt->tag == "cutoff" )
129 if ( ( cutoff = curropt->value.real() ) < 1e-30 )
130 cerr << "-cutoff: The cutoff distance must be specified!" << endl;
131 if ( curropt->tag == "output" )
132 paramfile = curropt->filename();
133 if ( curropt->tag == "output" )
134 paramout = curropt->filename();
135 }
136 option_kill(option);
137
138 double ti = timer_start();
139
140 Bmolgroup* molgroup = NULL;
141 Bstring filename(argv[optind++]);
142
143 if ( genwater == 1 )
144 molgroup = molgroup_generate_random_water(size);
145 else if ( genwater > 1 )
146 molgroup = molgroup_generate_regular_water(size, genwater);
147 else {
148 molgroup = read_molecule(filename, atom_select, paramfile);
149 if ( size[0] > 0 && size[1] > 0 && size[2] > 0 )
150 molgroup->box = size;
151 else
152 molgroup->box = molgroup->max - molgroup->min;
153 }
154
155 if ( !molgroup ) {
156 cerr << "Error: No molecule to work with!" << endl;
157 bexit(-1);
158 }
159
160 Bmd* md = read_md_parameters(paramfile);
161 if ( !md ) {
162 cerr << "Error: File " << paramfile << " not read!" << endl;
163 bexit(-1);
164 }
165
166 md->timestep = timestep;
167 md->Kfriction = Kfriction;
168 md->Kbond = Kbond;
169 md->Kangle = Kangle;
170 md->Kelec = Kelec;
171 md->Kvdw = Kvdw;
172 md->cutoff = cutoff;
173 md->wrap = wrap;
174
175 water_bond_list(molgroup);
176
177 water_angle_list(molgroup);
178
179 if ( verbose & VERB_PROCESS )
180 molgroup_density(molgroup);
181
182 if ( verbose )
183 md_calculate_deviations(molgroup, md->wrap);
184
185 if ( molgroup->mol && max_iter ) {
186 md_leapfrog(molgroup, md, max_iter, velocitylimit);
187 if ( verbose & VERB_PROCESS )
188 molgroup_density(molgroup);
189 if ( verbose )
190 md_calculate_deviations(molgroup, md->wrap);
191 }
192
193 if ( molgroup->mol && rdf > 0 ) molgroup_calc_water_rdf(molgroup, rdf, cutoff);
194
195 if ( paramout.length() )
196 write_md_parameters(paramout, md);
197
198 if ( optind < argc ) {
199 molecule_update_comment(molgroup, argc, argv);
200 write_molecule(argv[optind], molgroup);
201 }
202
203 molgroup_kill(molgroup);
204 md_kill(md);
205
206 if ( verbose & VERB_TIME )
207 timer_report(ti);
208
209 bexit(0);
210 }
211
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Bstring::real
double real()
Definition: Bstring.cpp:545
md_calculate_deviations
double md_calculate_deviations(Bmolgroup *molgroup, int wrap)
Calculates deviations from the reference bond lengths and angles.
Definition: mol_bonds.cpp:742
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
main
int main(int argc, char **argv)
Definition: bwater.cpp:58
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmd
Definition: rwmd.h:56
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
write_md_parameters
int write_md_parameters(Bstring &filename, Bmd *md)
Writing molecular dynamics parameters to a STAR file.
Definition: rwmd.cpp:237
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
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
molgroup_calc_water_rdf
int molgroup_calc_water_rdf(Bmolgroup *molgroup, double interval, double cutoff)
Calculates a radial distribution function for water molecules.
Definition: mol_water.cpp:323
mol_water.h
Generating and managing water.
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
linked_list.h
Header file for generalized linked list functions.
rwmolecule.h
Header file for reading reflection files.
molgroup_generate_random_water
Bmolgroup * molgroup_generate_random_water(Vector3< double > size)
Generates a block of water with random placement.
Definition: mol_water.cpp:181
Bmolgroup
Definition: rwmolecule.h:170
Bmd::Kbond
double Kbond
Definition: rwmd.h:59
Boption
A class for a command line input option.
Definition: options.h:26
Bmd::Kfriction
double Kfriction
Definition: rwmd.h:58
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
Bmd::Kelec
double Kelec
Definition: rwmd.h:61
molgroup_density
double molgroup_density(Bmolgroup *molgroup)
Calculates the number and mass density of a molecular system.
Definition: mol_util.cpp:548
Bmolgroup::max
Vector3< double > max
Definition: rwmolecule.h:183
water_angle_list
Bangle * water_angle_list(Bmolgroup *molgroup)
Generates a bond angle list for a block of waters.
Definition: mol_water.cpp:291
use
const char * use[]
Definition: bwater.cpp:24
read_md_parameters
Bmd * read_md_parameters(Bstring &filename)
Reading molecular dynamics parameters from STAR files.
Definition: rwmd.cpp:80
molgroup_generate_regular_water
Bmolgroup * molgroup_generate_regular_water(Vector3< double > size, int type)
Generates a block of water based on a regular lattice.
Definition: mol_water.cpp:89
Bmd::Kangle
double Kangle
Definition: rwmd.h:60
Boption::next
Boption * next
Definition: options.h:28
mol_bonds.h
Header for molecular dynamics.
Bstring
Definition: Bstring.h:29
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
Bmd::wrap
int wrap
Definition: rwmd.h:72
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
water_bond_list
Bbond * water_bond_list(Bmolgroup *molgroup)
Generates a bond list for a block of waters.
Definition: mol_water.cpp:249
Bmd::cutoff
double cutoff
Definition: rwmd.h:69
Bmd::timestep
double timestep
Definition: rwmd.h:57
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
rwmd.h
Header to read and write molecular dynamics parameters in STAR format.
md_leapfrog
double md_leapfrog(Bmolgroup *molgroup, Bmd *md, int max_iter, double velocitylimit)
Molecular dynamics using the leapfrog integrator.
Definition: mol_md.cpp:38
Bmolgroup::min
Vector3< double > min
Definition: rwmolecule.h:182
options.h
Header file for option handlers.
md_kill
int md_kill(Bmd *md)
Deallocates a molecular dynamics structure.
Definition: rwmd.cpp:417
Vector3::volume
double volume()
Definition: Vector3.h:235
mol_md.h
Header for molecular dynamics.
Bmd::Kvdw
double Kvdw
Definition: rwmd.h:62
verbose
int verbose
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
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