Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2023 The plumed team
3 : (see the PEOPLE file at the root of the distribution for a list of names)
4 :
5 : See http://www.plumed.org for more information.
6 :
7 : This file is part of plumed, version 2.
8 :
9 : plumed is free software: you can redistribute it and/or modify
10 : it under the terms of the GNU Lesser General Public License as published by
11 : the Free Software Foundation, either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : plumed is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU Lesser General Public License for more details.
18 :
19 : You should have received a copy of the GNU Lesser General Public License
20 : along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 : #include "SecondaryStructureBase.h"
23 : #include "core/ActionShortcut.h"
24 : #include "core/ActionRegister.h"
25 :
26 : namespace PLMD {
27 : namespace secondarystructure {
28 :
29 : //+PLUMEDOC COLVAR ANTIBETARMSD
30 : /*
31 : Probe the antiparallel beta sheet content of your protein structure.
32 :
33 : Two protein segments containing three contiguous residues can form an antiparallel beta sheet.
34 : Although if the two segments are part of the same protein chain they must be separated by
35 : a minimum of 2 residues to make room for the turn. This colvar thus generates the set of
36 : all possible six residue sections that could conceivably form an antiparallel beta sheet
37 : and calculates the [DRMSD](DRMSD.md) or [RMSD](RMSD.md) distance between the configuration in which the residues find themselves
38 : and an idealized antiparallel beta sheet structure. These distances can be calculated by either
39 : aligning the instantaneous structure with the reference structure and measuring each
40 : atomic displacement or by calculating differences between the set of inter-atomic
41 : distances in the reference and instantaneous structures.
42 :
43 : This colvar is based on ideas from the paper cited below. The authors of
44 : this paper use the set of distances from the anti parallel beta sheet configurations to measure
45 : the number of segments that have an configuration that resembles an anti parallel beta sheet. This is done by calculating
46 : the following sum of functions of the rmsd distances:
47 :
48 : $$
49 : s = \sum_i \frac{ 1 - \left(\frac{r_i-d_0}{r_0}\right)^n } { 1 - \left(\frac{r_i-d_0}{r_0}\right)^m }
50 : $$
51 :
52 : where the sum runs over all possible segments of antiparallel beta sheet. By default the
53 : NN, MM and D_0 parameters are set equal to those used in the paper cited below. The R_0
54 : parameter must be set by the user - the value used in the paper below was 0.08 nm.
55 :
56 : If you change the function in the above sum you can calculate quantities such as the average
57 : distance from a purely configuration composed of pure anti-parallel beta sheets or the distance between the set of
58 : residues that is closest to an anti-parallel beta sheet and the reference configuration. To do these sorts of
59 : calculations you can use the AVERAGE and MIN keywords. In addition you can use the LESS_THAN
60 : keyword if you would like to change the form of the switching function. If you use any of these
61 : options you no longer need to specify NN, R_0, MM and D_0.
62 :
63 : The following input calculates the number of six residue segments of
64 : protein that are in an antiparallel beta sheet configuration.
65 :
66 : ```plumed
67 : #SETTINGS MOLFILE=regtest/basic/rt32/helix.pdb
68 : MOLINFO STRUCTURE=regtest/basic/rt32/helix.pdb
69 : ab: ANTIBETARMSD RESIDUES=all STRANDS_CUTOFF=1 R_0=0.1
70 : PRINT ARG=ab FILE=colvar
71 : ```
72 :
73 : Here the same is done use [RMSD](RMSD.md) instead of [DRMSD](DRMSD.md), which is normally faster.
74 :
75 : ```plumed
76 : #SETTINGS MOLFILE=regtest/basic/rt32/helix.pdb
77 : MOLINFO STRUCTURE=regtest/basic/rt32/helix.pdb
78 : WHOLEMOLECULES ENTITY0=1-100
79 : hh: ANTIBETARMSD RESIDUES=all TYPE=OPTIMAL LESS_THAN={RATIONAL R_0=0.1 NN=8 MM=12} STRANDS_CUTOFF=1
80 : PRINT ARG=hh.lessthan FILE=colvar
81 : ```
82 :
83 : __YOUR CALCULATION WILL BE MUCH FASTER IF YOU USE THE `STRANDS_CUTOFF` KEYWORD.__ As you can see from the
84 : expanded version of the inputs above this keyword reduces the computational cost of the calculation by
85 : avoiding calculations of the RMSD values for segments that have the two strands of the beta sheet further apart
86 : than a cutoff.
87 :
88 : ## Periodic boundary conditions
89 :
90 : You can turn off periodic boundary conditions by using the NOPBC flag as shown below:
91 :
92 : ```plumed
93 : #SETTINGS MOLFILE=regtest/basic/rt32/helix.pdb
94 : MOLINFO STRUCTURE=regtest/basic/rt32/helix.pdb
95 : ab: ANTIBETARMSD RESIDUES=all STRANDS_CUTOFF=1 R_0=0.1 NOPBC
96 : PRINT ARG=ab FILE=colvar
97 : ```
98 :
99 : If you are using [DRMSD](DRMSD.md) to measure distances and you __don't__ use the NOPBC flag then
100 : all distances in the instaneous structure are evaluated in a way that takes the periodic boundary conditions
101 : into account. Using the NOPBC flag turns off this treatment.
102 :
103 : If you are using [RMSD](RMSD.md) to measure distances and you __don't__ use the NOPBC flag the the instaneous positions of
104 : each segment for which the RMSD is computed is reconstructed using the procedure outlined in the documentation for [WHOLEMOLECULES](WHOLEMOLECULES.md)
105 : before the RMSD is computed. Using the NOPBC flag turns off this treatment.
106 :
107 : */
108 : //+ENDPLUMEDOC
109 :
110 : class AntibetaRMSD : public ActionShortcut {
111 : public:
112 : static void registerKeywords( Keywords& keys );
113 : explicit AntibetaRMSD(const ActionOptions&);
114 : };
115 :
116 : PLUMED_REGISTER_ACTION(AntibetaRMSD,"ANTIBETARMSD")
117 :
118 100 : void AntibetaRMSD::registerKeywords( Keywords& keys ) {
119 100 : SecondaryStructureBase<Vector>::registerKeywords( keys );
120 100 : keys.remove("ATOMS");
121 100 : keys.remove("SEGMENT");
122 100 : keys.remove("STRUCTURE");
123 100 : keys.remove("MASK");
124 100 : keys.remove("ALIGN_STRANDS");
125 200 : keys.setValueDescription("scalar/vector","if LESS_THAN is present the RMSD distance between each residue and the ideal antiparallel beta sheet. If LESS_THAN is not present the number of residue segments where the structure is similar to an anti parallel beta sheet");
126 100 : keys.add("compulsory","STYLE","all","Antiparallel beta sheets can either form in a single chain or from a pair of chains. If STYLE=all all "
127 : "chain configuration with the appropriate geometry are counted. If STYLE=inter "
128 : "only sheet-like configurations involving two chains are counted, while if STYLE=intra "
129 : "only sheet-like configurations involving a single chain are counted");
130 100 : keys.add("optional","STRANDS_CUTOFF","If in a segment of protein the two strands are further apart then the calculation "
131 : "of the actual RMSD is skipped as the structure is very far from being beta-sheet like. "
132 : "This keyword speeds up the calculation enormously when you are using the LESS_THAN option. "
133 : "However, if you are using some other option, then this cannot be used");
134 100 : keys.needsAction("DISTANCE");
135 100 : keys.needsAction("CUSTOM");
136 100 : }
137 :
138 17 : AntibetaRMSD::AntibetaRMSD(const ActionOptions&ao):
139 : Action(ao),
140 17 : ActionShortcut(ao) {
141 : // Read in the input and create a string that describes how to compute the less than
142 : std::string ltmap;
143 17 : bool uselessthan=SecondaryStructureBase<Vector>::readShortcutWords( ltmap, this );
144 : // read in the backbone atoms
145 : std::vector<unsigned> chains;
146 : std::vector<std::string> all_atoms;
147 34 : SecondaryStructureBase<Vector>::readBackboneAtoms( this, plumed, "protein", chains, all_atoms );
148 :
149 : bool intra_chain(false), inter_chain(false);
150 : std::string style;
151 34 : parse("STYLE",style);
152 17 : if( Tools::caseInSensStringCompare(style, "all") ) {
153 : intra_chain=true;
154 : inter_chain=true;
155 2 : } else if( Tools::caseInSensStringCompare(style, "inter") ) {
156 : intra_chain=false;
157 : inter_chain=true;
158 1 : } else if( Tools::caseInSensStringCompare(style, "intra") ) {
159 : intra_chain=true;
160 : inter_chain=false;
161 : } else {
162 0 : error( style + " is not a valid directive for the STYLE keyword");
163 : }
164 :
165 17 : double strands_cutoff=-1.0;
166 34 : parse("STRANDS_CUTOFF",strands_cutoff);
167 : std::string scutoff_action;
168 17 : if( strands_cutoff>0 ) {
169 32 : scutoff_action=getShortcutLabel() + "_cut_dists: DISTANCE ";
170 : }
171 :
172 : // This constructs all conceivable sections of antibeta sheet in the backbone of the chains
173 : std::string seglist;
174 17 : unsigned k=1;
175 17 : if( intra_chain ) {
176 : unsigned nprevious=0;
177 16 : std::vector<unsigned> nlist(30);
178 287 : for(unsigned i=0; i<chains.size(); ++i) {
179 271 : if( chains[i]<40 ) {
180 0 : error("segment of backbone is not long enough to form an antiparallel beta hairpin. Each backbone fragment must contain a minimum of 8 residues");
181 : }
182 : // Loop over all possible triples in each 8 residue segment of protein
183 271 : unsigned nres=chains[i]/5;
184 271 : if( chains[i]%5!=0 ) {
185 0 : error("backbone segment received does not contain a multiple of five residues");
186 : }
187 546 : for(unsigned ires=0; ires<nres-7; ires++) {
188 560 : for(unsigned jres=ires+7; jres<nres; jres++) {
189 4560 : for(unsigned kk=0; kk<15; ++kk) {
190 4275 : nlist[kk]=nprevious + ires*5+kk;
191 4275 : nlist[kk+15]=nprevious + (jres-2)*5+kk;
192 : }
193 : std::string nlstr, num;
194 285 : Tools::convert( nlist[0], nlstr );
195 285 : Tools::convert(k, num);
196 285 : ++k;
197 570 : seglist += " SEGMENT" + num + "=" + nlstr;
198 8550 : for(unsigned kk=1; kk<nlist.size(); ++kk ) {
199 8265 : Tools::convert( nlist[kk], nlstr );
200 16530 : seglist += "," + nlstr;
201 : }
202 285 : if( strands_cutoff>0 ) {
203 570 : scutoff_action += " ATOMS" + num + "=" + all_atoms[nlist[6]] + "," + all_atoms[nlist[21]];
204 : }
205 : }
206 : }
207 271 : nprevious+=chains[i];
208 : }
209 : }
210 17 : if( inter_chain ) {
211 16 : if( chains.size()==1 && !Tools::caseInSensStringCompare(style, "all") ) {
212 0 : error("there is only one chain defined so cannot use inter_chain option");
213 : }
214 16 : std::vector<unsigned> nlist(30);
215 255 : for(unsigned ichain=1; ichain<chains.size(); ++ichain) {
216 : unsigned iprev=0;
217 2382 : for(unsigned i=0; i<ichain; ++i) {
218 2143 : iprev+=chains[i];
219 : }
220 239 : unsigned inres=chains[ichain]/5;
221 239 : if( chains[ichain]%5!=0 ) {
222 0 : error("backbone segment received does not contain a multiple of five residues");
223 : }
224 1668 : for(unsigned ires=0; ires<inres-2; ++ires) {
225 14282 : for(unsigned jchain=0; jchain<ichain; ++jchain) {
226 : unsigned jprev=0;
227 81397 : for(unsigned i=0; i<jchain; ++i) {
228 68544 : jprev+=chains[i];
229 : }
230 12853 : unsigned jnres=chains[jchain]/5;
231 12853 : if( chains[jchain]%5!=0 ) {
232 0 : error("backbone segment received does not contain a multiple of five residues");
233 : }
234 89966 : for(unsigned jres=0; jres<jnres-2; ++jres) {
235 1233808 : for(unsigned kk=0; kk<15; ++kk) {
236 1156695 : nlist[kk]=iprev + ires*5+kk;
237 1156695 : nlist[kk+15]=jprev + jres*5+kk;
238 : }
239 : std::string nlstr, num;
240 77113 : Tools::convert( nlist[0], nlstr );
241 77113 : Tools::convert(k, num);
242 77113 : k++;
243 154226 : seglist += " SEGMENT" + num + "=" + nlstr;
244 2313390 : for(unsigned kk=1; kk<nlist.size(); ++kk ) {
245 2236277 : Tools::convert( nlist[kk], nlstr );
246 4472554 : seglist += "," + nlstr;
247 : }
248 77113 : if( strands_cutoff>0 ) {
249 154224 : scutoff_action += " ATOMS" + num + "=" + all_atoms[nlist[6]] + "," + all_atoms[nlist[21]];
250 : }
251 : }
252 : }
253 : }
254 : }
255 : }
256 :
257 : // Build the reference structure ( in angstroms )
258 17 : std::vector<Vector> reference(30);
259 17 : reference[0]=Vector( 2.263, -3.795, 1.722); // N i
260 17 : reference[1]=Vector( 2.493, -2.426, 2.263); // CA
261 17 : reference[2]=Vector( 3.847, -1.838, 1.761); // CB
262 17 : reference[3]=Vector( 1.301, -1.517, 1.921); // C
263 17 : reference[4]=Vector( 0.852, -1.504, 0.739); // O
264 17 : reference[5]=Vector( 0.818, -0.738, 2.917); // N i+1
265 17 : reference[6]=Vector(-0.299, 0.243, 2.748); // CA
266 17 : reference[7]=Vector(-1.421, -0.076, 3.757); // CB
267 17 : reference[8]=Vector( 0.273, 1.680, 2.854); // C
268 17 : reference[9]=Vector( 0.902, 1.993, 3.888); // O
269 17 : reference[10]=Vector( 0.119, 2.532, 1.813); // N i+2
270 17 : reference[11]=Vector( 0.683, 3.916, 1.680); // CA
271 17 : reference[12]=Vector( 1.580, 3.940, 0.395); // CB
272 17 : reference[13]=Vector(-0.394, 5.011, 1.630); // C
273 17 : reference[14]=Vector(-1.459, 4.814, 0.982); // O
274 17 : reference[15]=Vector(-2.962, 3.559, -1.359); // N j-2
275 17 : reference[16]=Vector(-2.439, 2.526, -2.287); // CA
276 17 : reference[17]=Vector(-1.189, 3.006, -3.087); // CB
277 17 : reference[18]=Vector(-2.081, 1.231, -1.520); // C
278 17 : reference[19]=Vector(-1.524, 1.324, -0.409); // O
279 17 : reference[20]=Vector(-2.326, 0.037, -2.095); // N j-1
280 17 : reference[21]=Vector(-1.858, -1.269, -1.554); // CA
281 17 : reference[22]=Vector(-3.053, -2.199, -1.291); // CB
282 17 : reference[23]=Vector(-0.869, -1.949, -2.512); // C
283 17 : reference[24]=Vector(-1.255, -2.070, -3.710); // O
284 17 : reference[25]=Vector( 0.326, -2.363, -2.072); // N j
285 17 : reference[26]=Vector( 1.405, -2.992, -2.872); // CA
286 17 : reference[27]=Vector( 2.699, -2.129, -2.917); // CB
287 17 : reference[28]=Vector( 1.745, -4.399, -2.330); // C
288 17 : reference[29]=Vector( 1.899, -4.545, -1.102); // O
289 : // Store the secondary structure ( last number makes sure we convert to internal units nm )
290 : std::string ref0, ref1, ref2;
291 17 : Tools::convert( reference[0][0], ref0 );
292 17 : Tools::convert( reference[0][1], ref1 );
293 17 : Tools::convert( reference[0][2], ref2 );
294 34 : std::string structure=" STRUCTURE1=" + ref0 + "," + ref1 + "," + ref2;
295 510 : for(unsigned i=1; i<30; ++i) {
296 1972 : for(unsigned kk=0; kk<3; ++kk) {
297 1479 : Tools::convert( reference[i][kk], ref0 );
298 2958 : structure += "," + ref0;
299 : }
300 : }
301 :
302 17 : std::string nopbcstr="";
303 : bool nopbc;
304 17 : parseFlag("NOPBC",nopbc);
305 17 : if( nopbc ) {
306 : nopbcstr = " NOPBC";
307 : }
308 17 : std::string usegpustr="";
309 : {
310 : bool usegpu;
311 17 : parseFlag("USEGPU",usegpu);
312 17 : if( usegpu ) {
313 : usegpustr = " USEGPU";
314 : }
315 : }
316 : std::string type;
317 17 : parse("TYPE",type);
318 17 : std::string lab = getShortcutLabel() + "_rmsd";
319 17 : if( uselessthan ) {
320 17 : lab = getShortcutLabel();
321 : }
322 17 : std::string atoms="ATOMS=" + all_atoms[0];
323 10890 : for(unsigned i=1; i<all_atoms.size(); ++i) {
324 21746 : atoms += "," + all_atoms[i];
325 : }
326 17 : std::string inputLine = lab+":";
327 17 : if( type=="DRMSD" ) {
328 : inputLine+=" SECONDARY_STRUCTURE_DRMSD BONDLENGTH=0.17";
329 : } else {
330 22 : inputLine+=" SECONDARY_STRUCTURE_RMSD TYPE=" +type;
331 : }
332 34 : inputLine+=" ALIGN_STRANDS " + seglist + structure
333 34 : + " " + atoms + nopbcstr + usegpustr;
334 :
335 17 : if( strands_cutoff>0 ) {
336 16 : readInputLine( scutoff_action );
337 : std::string str_cut;
338 16 : Tools::convert( strands_cutoff, str_cut );
339 48 : readInputLine( getShortcutLabel() + "_cut: CUSTOM ARG=" + getShortcutLabel()
340 32 : + "_cut_dists FUNC=step(" + str_cut + "-x) PERIODIC=NO");
341 32 : inputLine+=" MASK=" + getShortcutLabel() + "_cut";
342 16 : readInputLine(inputLine);
343 16 : if( ltmap.length()>0 ) {
344 : // Create the less than object
345 48 : readInputLine( getShortcutLabel() + "_ltu: LESS_THAN ARG=" + lab
346 48 : + " SWITCH={" + ltmap +"} MASK=" + getShortcutLabel() + "_cut");
347 : // Multiply by the strands cutoff
348 32 : readInputLine( getShortcutLabel()
349 48 : + "_lt: CUSTOM ARG=" + getShortcutLabel() + "_ltu,"
350 48 : + getShortcutLabel() + "_cut"
351 : " FUNC=x*y PERIODIC=NO");
352 : }
353 : } else {
354 1 : readInputLine(inputLine);
355 1 : if( ltmap.length()>0 ) {
356 : // Create the less than object
357 2 : readInputLine( getShortcutLabel() + "_lt: LESS_THAN ARG=" + lab + " SWITCH={" + ltmap +"}");
358 : }
359 : }
360 : // Create the less than object
361 17 : if( ltmap.length()>0 ) {
362 17 : if( uselessthan ) {
363 34 : readInputLine( getShortcutLabel() + "_lessthan: SUM ARG=" + getShortcutLabel() + "_lt PERIODIC=NO");
364 : } else {
365 0 : readInputLine( getShortcutLabel() + ": SUM ARG=" + getShortcutLabel() + "_lt PERIODIC=NO");
366 : }
367 : }
368 34 : }
369 :
370 : }
371 : }
|