Bsoft  2.1.0
Bernard's software package
rwmodel_mol.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "rwmolecule.h"
11 #include "model_links.h"
12 #include "model_util.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 
25 Bmodel* read_model_molecule(Bstring* file_list, Bstring& paramfile)
26 {
27  Bstring* filename;
28  Bstring atom_select("all");
29  Bstring id;
30  Bmolgroup* molgroup;
31  Bmolecule* mol;
32  Bresidue* res;
33  Batom* atom;
34  Bbond* bond;
35 
36  int i, j;
37  Bmodel* model = NULL;
38  Bmodel* mp = NULL;
39  Bcomponent* comp = NULL;
40  Blink* link = NULL;
41 
42  if ( verbose & VERB_DEBUG )
43  cout << "DEBUG read_model_molecule: " << *file_list << endl;
44 
45  for ( i=1, filename = file_list; filename; filename = filename->next, i++ ) {
46  if ( verbose & VERB_LABEL )
47  cout << "Reading file: " << *filename << endl;
48  molgroup = read_molecule(*filename, atom_select, paramfile);
49  id = Bstring(i, "%d");
50  mp = model_add(&mp, id);
51  if ( !model ) model = mp;
52  mp->type_id = mp->id;
53  if ( molgroup ) {
54  if ( molgroup->id.length() && molgroup->id[0] != ' ') mp->id = molgroup->id;
55  mp->symmetry = molgroup->pointgroup;
56  comp = NULL;
57  link = NULL;
58  for ( bond = molgroup->bond; bond; bond = bond->next ) {
59  link = (Blink *) add_item((char **) &link, sizeof(Blink));
60  if ( !mp->link ) mp->link = link;
61  link->radius = 1;
62  link->sel = 1;
63  for ( j=0; j<4; j++ ) link->color[j] = 1;
64  }
65  for ( mol = molgroup->mol; mol; mol = mol->next ) {
66  for ( res = mol->res; res; res = res->next ) {
67  for ( atom = res->atom; atom; atom = atom->next ) {
68  id = Bstring(atom->num, "%d");
69  comp = component_add(&comp, id);
70  if ( !mp->comp ) mp->comp = comp;
71  comp->loc = atom->coord;
72  comp->fom = atom->b;
73  comp->sel = (int) (atom->q + 0.999);
74  id = atom->type;
75  id = id.no_space();
76  comp->type = model_add_type_by_id(mp, id);
77  for ( bond = molgroup->bond, link = mp->link; bond && link; bond = bond->next, link = link->next ) {
78  if ( atom == bond->atom1 ) link->comp[0] = comp;
79  else if ( atom == bond->atom2 ) link->comp[1] = comp;
80  }
81  }
82  }
83  }
84  molgroup_kill(molgroup);
85  }
86  }
87 
88 // model_list_setup_links(model);
90 
91  return model;
92 }
93 
101 {
102  int i, n;
103  Bstring restype("UNK");
104  Bmolgroup* molgroup = NULL;
105  Bmolgroup* mg = NULL;
106  Bmolgroup* mgc = NULL;
107  Bmolecule* mol = NULL;
108  Bresidue* res = NULL;
109  Batom* atom = NULL, *atom2;
110  Bbond* bond = NULL;
111 
112  Bmodel* mp = NULL;
113  Bcomponent* comp = NULL;
114  Blink* link = NULL;
115 
116  for ( n=i=0, mp = model; mp; mp = mp->next, n++ ) {
117  mg = molgroup_init();
118  if ( !molgroup ) molgroup = mg;
119  else mgc->next = mg;
120  mgc = mg;
121  mg->comment = model->comment.pre('\n') + "\nREMARK Model";
122  mg->id = mp->id;
123  mg->pointgroup = mp->symmetry;
124  mol = molecule_add(&mg->mol, mp->id);
125  res = residue_add(&mol->res, restype);
126  res->num = 1;
127  atom = NULL;
128  for ( comp = mp->comp; comp; comp = comp->next ) {
129  atom = atom_add(&atom, comp->type->id);
130  if ( !res->atom ) res->atom = atom;
131  atom->num = comp->id.integer();
132  atom->coord = comp->loc;
133  atom->sel = comp->sel;
134  atom->q = comp->sel;
135  atom->b = comp->fom;
136  }
137  bond = NULL;
138  for ( link = mp->link; link; link = link->next ) {
139  for ( comp = mp->comp, atom = res->atom; comp && comp != link->comp[0] && atom;
140  comp = comp->next, atom = atom->next ) ;
141  for ( comp = mp->comp, atom2 = res->atom; comp && comp != link->comp[1] && atom2;
142  comp = comp->next, atom2 = atom2->next ) ;
143  if ( atom && atom2 ) {
144  bond = (Bbond *) bond_add(&bond, atom, atom2, link->length, 1);
145  if ( !mg->bond ) mg->bond = bond;
146  } else {
147  cerr << "Error: Problem with link " << link->comp[0]->id << " to " << link->comp[1]->id << endl;
148  }
149  }
150  }
151 
152  if ( verbose & VERB_DEBUG )
153  cout << "DEBUG write_model_molecule: atoms converted: " << i << endl;
154 
155  molgroup_list_write(filename, molgroup);
156 
157  molgroup_list_kill(molgroup);
158 
159  return n;
160 }
161 
molgroup_init
Bmolgroup * molgroup_init()
Initializes and allocates a new molecule group.
Definition: rwmolecule.cpp:45
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
atom_add
Batom * atom_add(Batom **atom, const char *type)
Adds an atom to a linked list.
Definition: rwmolecule.cpp:152
residue_add
Bresidue * residue_add(Bresidue **res, const char *type)
Adds a residue to a linked list.
Definition: rwmolecule.cpp:113
Bcomponent
Definition: rwmodel.h:51
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bresidue::next
Bresidue * next
Definition: rwmolecule.h:50
read_model_molecule
Bmodel * read_model_molecule(Bstring *file_list, Bstring &paramfile)
Reads molecular model parameters.
Definition: rwmodel_mol.cpp:25
rwmodel.h
Header file for reading and writing atomic model files.
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
Bstring
Definition: Bstring.h:29
Bbond::next
Bbond * next
Definition: rwmolecule.h:135
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
Bbond::atom1
Batom * atom1
Definition: rwmolecule.h:136
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
molgroup_list_kill
int molgroup_list_kill(Bmolgroup *molgroup)
Destroys a molecule group linked list.
Definition: rwmolecule.cpp:347
Bresidue::atom
Batom * atom
Definition: rwmolecule.h:54
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Batom::num
int num
Definition: rwmolecule.h:26
component_add
Bcomponent * component_add(Bcomponent **comp, Bstring &id)
Adds a component to a linked list.
Definition: rwmodel.cpp:270
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
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
Bbond::atom2
Batom * atom2
Definition: rwmolecule.h:137
Batom::q
double q
Definition: rwmolecule.h:31
Bmodel::link
Blink * link
Definition: rwmodel.h:133
Batom::next
Batom * next
Definition: rwmolecule.h:25
Bresidue::num
int num
Definition: rwmolecule.h:51
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
write_model_molecule
int write_model_molecule(Bstring &filename, Bmodel *model)
Writes molecular model parameters.
Definition: rwmodel_mol.cpp:100
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:389
rwmolecule.h
Header file for reading reflection files.
Bmodel::id
Bstring id
Definition: rwmodel.h:121
Bbond
Definition: rwmolecule.h:134
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
Bmolecule
Definition: rwmolecule.h:107
Bmolgroup::bond
Bbond * bond
Definition: rwmolecule.h:190
Batom::type
char type[8]
Definition: rwmolecule.h:28
Bmolgroup::next
Bmolgroup * next
Definition: rwmolecule.h:171
Bmodel
Definition: rwmodel.h:119
molgroup_list_write
int molgroup_list_write(Bstring &filename, Bmolgroup *molgroup)
Writes a molecule group list.
Definition: rwmolecule.cpp:1053
Batom::b
double b
Definition: rwmolecule.h:31
utilities.h
Header file for general utilities.
Bmolgroup::comment
Bstring comment
Definition: rwmolecule.h:175
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bcomponent::fom
float fom
Definition: rwmodel.h:65
verbose
int verbose
bond_add
Bbond * bond_add(Bbond **bond, Batom *atom1, Batom *atom2, double l, double k)
Adds a bond to a linked list.
Definition: rwmolecule.cpp:269
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
Bcomptype::id
Bstring id
Definition: rwmodel.h:27
model
Bmodel * model
Definition: bshow.cpp:34
Bstring::next
Bstring * next
Definition: Bstring.h:31
Batom::sel
int sel
Definition: rwmolecule.h:34
Bresidue
Definition: rwmolecule.h:49
linked_list.h
Header file for generalized linked list functions.
model_add
Bmodel * model_add(Bmodel **model, Bstring &id)
Adds a model to a linked list.
Definition: rwmodel.cpp:181
model_util.h
Library routines used for model processing.
model_add_type_by_id
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
Definition: rwmodel.cpp:414
Bmolgroup
Definition: rwmolecule.h:170
Bmolgroup::id
Bstring id
Definition: rwmolecule.h:174
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
molecule_add
Bmolecule * molecule_add(Bmolecule **mol, char *name)
Adds a molecule to a linked list.
Definition: rwmolecule.cpp:76
Bmolgroup::pointgroup
Bstring pointgroup
Definition: rwmolecule.h:177
Bmodel::comment
Bstring comment
Definition: rwmodel.h:126
Batom::coord
Vector3< double > coord
Definition: rwmolecule.h:30
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124
Batom
Definition: rwmolecule.h:24
Bmodel::type_id
Bstring type_id
Definition: rwmodel.h:122
Bcomponent::sel
int sel
Definition: rwmodel.h:66