forked from pemsley/coot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra-restraints-kk.cc
225 lines (205 loc) · 8.27 KB
/
extra-restraints-kk.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* ideal/extra-restraints-kk.cc
*
* Copyright 2011, 2012 by Kevin Keating
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License and
* the GNU Lesser General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA, 02110-1301, USA.
*/
#include <stdexcept>
#include "simple-restraint.hh"
void
coot::restraints_container_t::add_extra_start_pos_restraints(const extra_restraints_t &extra_restraints) {
for (unsigned int i=0; i<extra_restraints.start_pos_restraints.size(); i++) {
mmdb::Residue *r_1 = NULL;
mmdb::Atom *at_1 = 0;
bool fixed_1 = 0;
if (from_residue_vector) {
for (unsigned int ir=0; ir<residues_vec.size(); ir++) {
if (coot::residue_spec_t(extra_restraints.start_pos_restraints[i].atom_1) ==
coot::residue_spec_t(residues_vec[ir].second)) {
r_1 = residues_vec[ir].second;
fixed_1 = residues_vec[ir].first;
}
}
} else {
// bleugh.
int selHnd = mol->NewSelection();
mol->Select (selHnd, mmdb::STYPE_RESIDUE, 1, // .. TYPE, iModel
chain_id_save.c_str(), // Chain(s)
istart_res, "*", // starting res
iend_res, "*", // ending res
"*", // residue name
"*", // Residue must contain this atom name?
"*", // Residue must contain this Element?
"*", // altLocs
mmdb::SKEY_NEW // selection key
);
int nSelResidues_local = 0;
mmdb::PPResidue SelResidue_local= 0;
mol->GetSelIndex (selHnd, SelResidue_local, nSelResidues_local);
for (int ir=0; ir<nSelResidues_local; ir++) {
if (coot::residue_spec_t(extra_restraints.start_pos_restraints[i].atom_1) ==
coot::residue_spec_t(SelResidue_local[ir])) {
r_1 = SelResidue_local[ir];
}
}
mol->DeleteSelection(selHnd);
}
if (r_1) {
mmdb::PPAtom residue_atoms_1 = 0;
int n_residue_atoms_1;
r_1->GetAtomTable(residue_atoms_1, n_residue_atoms_1);
for (int iat=0; iat<n_residue_atoms_1; iat++) {
std::string atom_name_1(residue_atoms_1[iat]->name);
if (atom_name_1 == extra_restraints.start_pos_restraints[i].atom_1.atom_name) {
std::string alt_loc_1(residue_atoms_1[iat]->altLoc);
if (alt_loc_1 == extra_restraints.start_pos_restraints[i].atom_1.alt_conf) {
at_1 = residue_atoms_1[iat];
break;
}
}
}
if (at_1) {
int index_1 = -1;
at_1->GetUDData(udd_atom_index_handle, index_1);
if (index_1 != -1) {
bool fixed_flag = fixed_check(index_1);
if (! (fixed_flag)) {
//if the atom is fixed, then a start position retraint will have no effect, so we don't add it
add_user_defined_start_pos_restraint(START_POS_RESTRAINT, index_1, fixed_flag,
extra_restraints.start_pos_restraints[i].esd, 0.0);
}
}
}
}
}
}
void
coot::restraints_container_t::add_extra_angle_restraints(const extra_restraints_t &extra_restraints) {
for (unsigned int i=0; i<extra_restraints.angle_restraints.size(); i++) {
mmdb::Residue *r_1 = NULL;
mmdb::Residue *r_2 = NULL;
mmdb::Residue *r_3 = NULL;
mmdb::Atom *at_1 = 0;
mmdb::Atom *at_2 = 0;
mmdb::Atom *at_3 = 0;
bool fixed_1 = 0;
bool fixed_2 = 0;
bool fixed_3 = 0;
if (from_residue_vector) {
for (unsigned int ir=0; ir<residues_vec.size(); ir++) {
if (coot::residue_spec_t(extra_restraints.angle_restraints[i].atom_1) ==
coot::residue_spec_t(residues_vec[ir].second)) {
r_1 = residues_vec[ir].second;
fixed_1 = residues_vec[ir].first;
}
if (coot::residue_spec_t(extra_restraints.angle_restraints[i].atom_2) ==
coot::residue_spec_t(residues_vec[ir].second)) {
r_2 = residues_vec[ir].second;
fixed_2 = residues_vec[ir].first;
}
if (coot::residue_spec_t(extra_restraints.angle_restraints[i].atom_3) ==
coot::residue_spec_t(residues_vec[ir].second)) {
r_3 = residues_vec[ir].second;
fixed_3 = residues_vec[ir].first;
}
}
} else {
// bleugh.
int selHnd = mol->NewSelection();
mol->Select (selHnd, mmdb::STYPE_RESIDUE, 1, // .. TYPE, iModel
chain_id_save.c_str(), // Chain(s)
istart_res, "*", // starting res
iend_res, "*", // ending res
"*", // residue name
"*", // Residue must contain this atom name?
"*", // Residue must contain this Element?
"*", // altLocs
mmdb::SKEY_NEW // selection key
);
int nSelResidues_local = 0;
mmdb::PPResidue SelResidue_local= 0;
mol->GetSelIndex (selHnd, SelResidue_local, nSelResidues_local);
for (int ir=0; ir<nSelResidues_local; ir++) {
if (coot::residue_spec_t(extra_restraints.angle_restraints[i].atom_1) ==
coot::residue_spec_t(SelResidue_local[ir]))
r_1 = SelResidue_local[ir];
if (coot::residue_spec_t(extra_restraints.angle_restraints[i].atom_2) ==
coot::residue_spec_t(SelResidue_local[ir]))
r_2 = SelResidue_local[ir];
if (coot::residue_spec_t(extra_restraints.angle_restraints[i].atom_3) ==
coot::residue_spec_t(SelResidue_local[ir]))
r_3 = SelResidue_local[ir];
}
mol->DeleteSelection(selHnd);
}
if (r_1 && r_2 && r_3) {
mmdb::PPAtom residue_atoms = 0;
int n_residue_atoms;
r_1->GetAtomTable(residue_atoms, n_residue_atoms);
for (int iat=0; iat<n_residue_atoms; iat++) {
if (coot::atom_spec_t(residue_atoms[iat]) == extra_restraints.angle_restraints[i].atom_1) {
at_1 = residue_atoms[iat];
break;
}
}
residue_atoms = 0; // just to be safe
r_2->GetAtomTable(residue_atoms, n_residue_atoms);
for (int iat=0; iat<n_residue_atoms; iat++) {
if (coot::atom_spec_t(residue_atoms[iat]) == extra_restraints.angle_restraints[i].atom_2) {
at_2 = residue_atoms[iat];
break;
}
}
residue_atoms = 0; // just to be safe
r_3->GetAtomTable(residue_atoms, n_residue_atoms);
for (int iat=0; iat<n_residue_atoms; iat++) {
if (coot::atom_spec_t(residue_atoms[iat]) == extra_restraints.angle_restraints[i].atom_3) {
at_3 = residue_atoms[iat];
break;
}
}
if (at_1 && at_2 && at_3) {
int index_1 = -1;
int index_2 = -1;
int index_3 = -1;
at_1->GetUDData(udd_atom_index_handle, index_1);
at_2->GetUDData(udd_atom_index_handle, index_2);
at_3->GetUDData(udd_atom_index_handle, index_3);
if ((index_1 != -1) && (index_2 != -1) && (index_3 != -1)) {
std::vector<bool> fixed_flags = make_fixed_flags(index_1, index_2, index_3);
if (fixed_1) fixed_flags[0] = 1;
if (fixed_2) fixed_flags[1] = 1;
if (fixed_3) fixed_flags[2] = 1;
if (0)
std::cout << "DEBUG:: adding user-defined angle restraint with fixed flags: "
<< "[" << index_1 << " " << coot::atom_spec_t(atom[index_1]) << " " << fixed_flags[0] << "] "
<< "[" << index_2 << " " << coot::atom_spec_t(atom[index_2]) << " " << fixed_flags[1] << "] "
<< "[" << index_3 << " " << coot::atom_spec_t(atom[index_3]) << " " << fixed_flags[2] << "] "
<< std::endl;
add_user_defined_angle_restraint(ANGLE_RESTRAINT,
index_1, index_2, index_3,
fixed_flags,
extra_restraints.angle_restraints[i].angle,
extra_restraints.angle_restraints[i].esd,
1.2); // dummy value);
//mark the 1 and 3 as "bonded" so that we don't add a non-bonded restraint between them
bonded_atom_indices[index_1].insert(index_3);
bonded_atom_indices[index_3].insert(index_1);
}
}
}
}
}