| Bsoft 2.0.5 Bernard's software package

mol_param.cpp
Go to the documentation of this file.
1
9 #include "rwmolecule.h"
10 #include "rwmd.h"
11 #include "mol_bonds.h"
12 #include "Matrix.h"
13 #include "linked_list.h"
14 #include "utilities.h"
15
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18
19
26 Batomtype* molgroup_get_atom_types(Bmolgroup* molgroup, int elements)
27 {
28 Bmolecule* mol;
29 Bresidue* res;
30 Batom* atom;
31 Batomtype* at = NULL;
32 Batomtype* atlist = NULL;
33 char string[32];
34
35 if ( verbose )
36 cout << "Atom types:" << endl;
37
38 for ( mol = molgroup->mol; mol; mol = mol->next ) {
39 for ( res = mol->res; res; res = res->next ) {
40 for ( atom = res->atom; atom; atom = atom->next ) {
41 if ( elements ) strcpy(string, atom->el);
42 else strcpy(string, atom->type);
43 if ( atlist )
44 for ( at = atlist; at && strcmp(at->name, string); at = at->next ) ;
45 if ( !at ) {
46 at = atom_type_add(&atlist, string);
47 at->z = 1;
48 at->el[0] = string[0];
49 at->mass = 1;
50 }
51 at->number++;
52 }
53 }
54 }
55
56 if ( verbose )
57 cout << "Type\tNumber" << endl;
58 for ( at = atlist; at; at = at->next )
59 cout << at->name << tab << at->number << endl;
60 cout << endl;
61
62 return atlist;
63 }
64
73 Bmd* md_calculate_parameters(Bmolgroup* molgroup, int elements, int show_bond, int show_angle)
74 {
75 Bmd* md = md_init();
76
77 Bbond* bond = NULL;
78 Bangle* angle = NULL;
79 Bbondtype* bt = NULL;
80 Bangletype* at = NULL;
81
82 double d;
83
84 if ( !md->atom ) md->atom = molgroup_get_atom_types(molgroup, elements);
85
86 if ( !molgroup->bond ) molgroup->bond = mol_bond_list_generate(molgroup, 1.8, 0);
87
88 if ( !molgroup->angle ) md_generate_angle_list(molgroup, md);
89
90 if ( verbose )
91 cout << "Bond types:" << endl;
92
93 for ( bond = molgroup->bond; bond; bond = bond->next ) {
94 bt = md_find_bond_type(bond->atom1, bond->atom2, md->bond);
95 if ( !bt ) bt = (Bbondtype *) add_item((char **) &md->bond, sizeof(Bbondtype));
96 if ( elements ) {
97 strncpy(bt->type1, bond->atom1->el, 2);
98 strncpy(bt->type2, bond->atom2->el, 2);
99 } else {
100 strncpy(bt->type1, bond->atom1->type, 8);
101 strncpy(bt->type2, bond->atom2->type, 8);
102 }
103 d = bond->atom1->coord.distance(bond->atom2->coord);
104 if ( show_bond ) cout << bond->atom1->type << tab << bond->atom2->type << tab << d << endl;
105 bt->covlength += d;
106 bt->std += d*d;
107 bt->number++;
108 }
109
110 if ( verbose )
111 cout << "Type1\tType2\tNumber\tLength\tSTD" << endl;
112 for ( bt = md->bond; bt; bt = bt->next ) if ( bt->number ) {
113 bt->covlength /= bt->number;
114 bt->std = bt->std/bt->number - bt->covlength*bt->covlength;
115 if ( bt->std > 0 ) bt->std = sqrt(bt->std);
116 else bt->std = 0;
117 if ( verbose )
118 cout << bt->type1 << tab << bt->type2 << tab << bt->number << tab << bt->covlength << tab << bt->std << endl;
119 }
120
121 if ( verbose )
122 cout << endl << "Angle types:" << endl;
123
124 for ( angle = molgroup->angle; angle; angle = angle->next ) {
125 at = md_find_angle_type(angle->atom1, angle->atom2, angle->atom3, md->angle);
126 if ( show_angle ) cout << angle->atom1->type << tab << angle->atom2->type << tab << angle->atom3->type << tab << angle->a*180.0/M_PI << endl;
127 if ( !at ) {
128 at = (Bangletype *) add_item((char **) &md->angle, sizeof(Bangletype));
129 if ( elements ) {
130 strncpy(at->type1, angle->atom1->el, 2);
131 strncpy(at->type2, angle->atom2->el, 2);
132 strncpy(at->type3, angle->atom3->el, 2);
133 } else {
134 strncpy(at->type1, angle->atom1->type, 8);
135 strncpy(at->type2, angle->atom2->type, 8);
136 strncpy(at->type3, angle->atom3->type, 8);
137 }
138 }
139 at->angle += angle->a;
140 at->std += angle->a*angle->a;
141 at->number++;
142 }
143
144 for ( at = md->angle; at; at = at->next ) {
145 at->angle /= at->number;
146 at->std = at->std/at->number - at->angle*at->angle;
147 if ( at->std > 0 ) at->std = sqrt(at->std);
148 else at->std = 0;
149 }
150
151 if ( verbose ) {
152 cout << "Type1\tType2\tType3\tNumber\tAngle\tSTD" << endl;
153 for ( at = md->angle; at; at = at->next )
154 cout << at->type1 << tab << at->type2 << tab << at->type3 << tab <<
155 at->number << tab << at->angle*180.0/M_PI << tab << at->std*180.0/M_PI << endl;
156 cout << endl;
157 }
158
159 return md;
160 }
Bmolgroup::angle
Bangle * angle
Definition: rwmolecule.h:191
verbose
int verbose
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Bangletype::type1
char type1[8]
Definition: rwmd.h:40
Bangletype::angle
float angle
Definition: rwmd.h:43
Batomtype::number
long number
Definition: rwatomprop.h:32
utilities.h
Header file for general utilities.
Batomtype::next
Batomtype * next
Definition: rwatomprop.h:20
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
Bbondtype::number
long number
Definition: rwmd.h:27
Bangle::next
Bangle * next
Definition: rwmolecule.h:151
atom_type_add
Batomtype * atom_type_add(Batomtype **atype, const char *aname)
Adds an atom type structure to a linked list.
Definition: rwatomprop.cpp:144
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
mol_bond_list_generate
Bbond * mol_bond_list_generate(Bmolgroup *molgroup, double bondlength, int wrap)
Generates an intramolecular distance-based bond list.
Definition: rwmolecule.cpp:1675
Matrix.h
Generalized matrix class.
Bmd
Definition: rwmd.h:56
Batomtype::mass
float mass
Definition: rwatomprop.h:24
Bbondtype::covlength
float covlength
Definition: rwmd.h:25
md_find_bond_type
Bbondtype * md_find_bond_type(Batom *atom1, Batom *atom2, Bbondtype *bondtype)
Finds the bond type.
Definition: mol_bonds.cpp:542
md_find_angle_type
Bangletype * md_find_angle_type(Batom *atom1, Batom *atom2, Batom *atom3, Bangletype *angletype)
Finds the reference angle type between three atoms.
Definition: mol_bonds.cpp:663
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Bangletype::next
Bangletype * next
Definition: rwmd.h:39
Bangle
Definition: rwmolecule.h:150
Bmd::angle
Bangletype * angle
Definition: rwmd.h:85
Batom::type
char type[8]
Definition: rwmolecule.h:28
Bbond::atom2
Batom * atom2
Definition: rwmolecule.h:137
Bbondtype::type2
char type2[8]
Definition: rwmd.h:24
Bangletype::std
float std
Definition: rwmd.h:45
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
rwmolecule.h
Header file for reading reflection files.
Bmolgroup
Definition: rwmolecule.h:170
Batomtype
Definition: rwatomprop.h:19
Batomtype::name
char name[8]
Definition: rwatomprop.h:23
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
Bbondtype::next
Bbondtype * next
Definition: rwmd.h:22
Bangletype::number
long number
Definition: rwmd.h:44
Batomtype::z
int z
Definition: rwatomprop.h:21
Bbondtype::type1
char type1[8]
Definition: rwmd.h:23
md_generate_angle_list
Bangle * md_generate_angle_list(Bmolgroup *molgroup, Bmd *md)
Generates an angle list.
Definition: mol_bonds.cpp:415
Bangle::atom2
Batom * atom2
Definition: rwmolecule.h:153
md_calculate_parameters
Bmd * md_calculate_parameters(Bmolgroup *molgroup, int elements, int show_bond, int show_angle)
Calculates atomic parameters from molecule groups.
Definition: mol_param.cpp:73
Bresidue::atom
Batom * atom
Definition: rwmolecule.h:54
Bmolecule
Definition: rwmolecule.h:107
Bmolgroup::bond
Bbond * bond
Definition: rwmolecule.h:190
Bresidue::next
Bresidue * next
Definition: rwmolecule.h:50
Bresidue
Definition: rwmolecule.h:49
Bangletype::type2
char type2[8]
Definition: rwmd.h:41
mol_bonds.h
Header for molecular dynamics.
Batom
Definition: rwmolecule.h:24
Bangletype
Definition: rwmd.h:38
Batomtype::el
char el[4]
Definition: rwatomprop.h:22
Bbond::atom1
Batom * atom1
Definition: rwmolecule.h:136
Bangle::a
double a
Definition: rwmolecule.h:155
molgroup_get_atom_types
Batomtype * molgroup_get_atom_types(Bmolgroup *molgroup, int elements)
Obtains atomic types from molecule groups.
Definition: mol_param.cpp:26
Batom::coord
Vector3< double > coord
Definition: rwmolecule.h:30
Bmd::atom
Batomtype * atom
Definition: rwmd.h:83
Bbond
Definition: rwmolecule.h:134
Bbond::next
Bbond * next
Definition: rwmolecule.h:135
Bangletype::type3
char type3[8]
Definition: rwmd.h:42
Bbondtype::std
float std
Definition: rwmd.h:28
Batom::el
char el[4]
Definition: rwmolecule.h:27
rwmd.h
Header to read and write molecular dynamics parameters in STAR format.
md_init
Bmd * md_init()
Initializes a molecular dynamics structure.
Definition: rwmd.cpp:28
Bangle::atom1
Batom * atom1
Definition: rwmolecule.h:152
Bbondtype
Definition: rwmd.h:21
Bmd::bond
Bbondtype * bond
Definition: rwmd.h:84
Bangle::atom3
Batom * atom3
Definition: rwmolecule.h:154
Batom::next
Batom * next
Definition: rwmolecule.h:25
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21