File size: 19,466 Bytes
5631464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
! flexref.cns
!    The HADDOCK semi-flexible refinement in torsion angle space
!    This version supports only distance and symmetry/ncs restraints
!
! ***********************************************************************
! * Copyright 2003-2022 Alexandre Bonvin, Utrecht University.           *
! * All rights reserved.                                                *
! * This code is part of the HADDOCK software and governed by its       *
! * license. Please see the LICENSE file that should have been included *
! * as part of this package.                                            *
! ***********************************************************************

if ( $log_level = "verbose" ) then
    set message=all echo=on end
elseif ( $log_level = "normal" ) then
    set message=normal echo=off end
else
    set message=off echo=off end
end if

!==================================================================!
! Initialisation of variables
!==================================================================!

evaluate ($saprotocol.randrot=$randrot)
evaluate ($saprotocol.separate=$separate)
evaluate ($saprotocol.tadhigh_t=$temp_high)
evaluate ($saprotocol.t1_init=$temp_cool1_init)
evaluate ($saprotocol.t2_init=$temp_cool2_init)
evaluate ($saprotocol.t3_init=$temp_cool3_init)
evaluate ($saprotocol.t1_final=$temp_cool1_final)
evaluate ($saprotocol.t2_final=$temp_cool2_final)
evaluate ($saprotocol.t3_final=$temp_cool3_final)
evaluate ($saprotocol.inter_init_rigid=$sinter_rigid_init)
evaluate ($saprotocol.inter_fin_rigid=$sinter_rigid_final)
evaluate ($saprotocol.inter_init_cool2=$sinter_cool2_init)
evaluate ($saprotocol.inter_fin_cool2=$sinter_cool2_final)
evaluate ($saprotocol.inter_init_cool3=$sinter_cool3_init)
evaluate ($saprotocol.inter_fin_cool3=$sinter_cool3_final)
evaluate ($saprotocol.tempstep=50)
evaluate ($saprotocol.timestep=$timestep)
evaluate ($saprotocol.tadfactor=$tadfactor)
evaluate ($saprotocol.initiosteps=$mdsteps_rigid)
evaluate ($saprotocol.cool1_steps=$mdsteps_cool1)
evaluate ($saprotocol.cool2_steps=$mdsteps_cool2)
evaluate ($saprotocol.cool3_steps=$mdsteps_cool3)
evaluate ($saprotocol.fbeta=100)
evaluate ($saprotocol.mass=100)

evaluate ($data.ncomponents=$ncomponents)


! non-bonded parameter set to use
evaluate ($toppar.par_nonbonded = "OPLSX")

! dihedrals, DNA and distance restraints
evaluate ($Data.dnarest =$dnarest_on)
evaluate ($Data.flags.cdih =$dihedrals_on)
evaluate ($Data.cdih.on =$dihedrals_on)
evaluate ($Data.ssdihed =$ssdihed)
evaluate ($Data.error_dih =$error_dih)
evaluate ($data.dihedrals.on=$dihedrals_on)
evaluate ($data.dihedrals_hot=$dihedrals_hot)
evaluate ($data.dihedrals_cool1=$dihedrals_cool1)
evaluate ($data.dihedrals_cool2=$dihedrals_cool2)
evaluate ($data.dihedrals_cool3=$dihedrals_cool3)

! planarity restraints
evaluate ($Data.flags.plan =  false)

! distance restraints
evaluate ($Data.flags.noe  =  true)
evaluate ($data.unambig_hot=$unambig_hot)
evaluate ($data.unambig_cool1=$unambig_cool1)
evaluate ($data.unambig_cool2=$unambig_cool2)
evaluate ($data.unambig_cool3=$unambig_cool3)
evaluate ($data.randremoval=$randremoval)
evaluate ($data.npart=$npart)

evaluate ($data.ambig_hot=$ambig_hot)
evaluate ($data.ambig_cool1=$ambig_cool1)
evaluate ($data.ambig_cool2=$ambig_cool2)
evaluate ($data.ambig_cool3=$ambig_cool3)

evaluate ($data.hbond_hot=$hbond_hot)
evaluate ($data.hbond_cool1=$hbond_cool1)
evaluate ($data.hbond_cool2=$hbond_cool2)
evaluate ($data.hbond_cool3=$hbond_cool3)

evaluate ($data.mrswi_hot=$mrswi_hot)
evaluate ($data.mrswi_cool1=$mrswi_cool1)
evaluate ($data.mrswi_cool2=$mrswi_cool2)
evaluate ($data.mrswi_cool3=$mrswi_cool3)

evaluate ($data.rswi_hot=$rswi_hot)
evaluate ($data.rswi_cool1=$rswi_cool1)
evaluate ($data.rswi_cool2=$rswi_cool2)
evaluate ($data.rswi_cool3=$rswi_cool3)

evaluate ($data.masy_hot=$masy_hot)
evaluate ($data.masy_cool1=$masy_cool1)
evaluate ($data.masy_cool2=$masy_cool2)
evaluate ($data.masy_cool3=$masy_cool3)

evaluate ($data.asy_hot=$asy_hot)
evaluate ($data.asy_cool1=$asy_cool1)
evaluate ($data.asy_cool2=$asy_cool2)
evaluate ($data.asy_cool3=$asy_cool3)

evaluate ($data.cmrest=$cmrest)
evaluate ($data.cmtight=$cmtight)
evaluate ($data.kcm=$kcm)
evaluate ($data.kcont=$kcont)
evaluate ($data.contactairs=$contactairs)
if ($data.contactairs eq true) then
    evaluate ($data.randremoval = false)
end if

! NCS restraints
evaluate ($data.kncs = $kncs)
evaluate ($Data.flags.ncs = $ncs_on)
evaluate ($data.nncs = $nncs)

! Symmetry restraints
evaluate ($data.ksym = $ksym)
evaluate ($Data.flags.sym = $sym_on)
evaluate ($data.nc2sym = $nc2sym)
evaluate ($data.nc3sym = $nc3sym)
evaluate ($data.ns3sym = $ns3sym)
evaluate ($data.nc4sym = $nc4sym)
evaluate ($data.nc5sym = $nc5sym)
evaluate ($data.nc6sym = $nc6sym)

!Electrostatics:
evaluate ($Data.flags.dihed =$dihedflag)
evaluate ($Data.flags.elec =$elecflag)
evaluate ($Data.epsilon =$epsilon)
evaluate ($Data.epsilon_cg =$epsilon_cg)
evaluate ($Data.dielec  =$dielec)

!Interaction matrix:
evaluate ($nmol1=1)
while ($nmol1 <=$data.ncomponents) loop mol1
    evaluate ($nmol2=$nmol1 + 1)
    evaluate ($scale.int_$nmol1_$nmol1 =$int_$nmol1_$nmol1)
    while ($nmol2 <=$data.ncomponents) loop mol2
        evaluate ($scale.int_$nmol1_$nmol2 =$int_$nmol1_$nmol2)
        evaluate ($scale.int_$nmol2_$nmol1 =$int_$nmol1_$nmol2)
        evaluate ($nmol2=$nmol2 + 1)
    end loop mol2
    evaluate ($nmol1 = $nmol1 + 1)
end loop mol1


! Unsupported restraints
evaluate ($Data.flags.em   = false)
evaluate ($Data.flags.rg   = false)
evaluate ($Data.flags.zres = false)
evaluate ($Data.flags.sani = false)
evaluate ($Data.flags.xrdc = false)
evaluate ($Data.flags.xpcs = false)
evaluate ($Data.flags.dani = false)
evaluate ($Data.flags.vean = false)

! Other parameters
evaluate ($refine.keepwater = false)

!==================================================================!

evaluate ($whichMD="torsion")

{* Read paramters and set various force field related variables *}

@MODULE:read_param.cns
set seed $seed end

parameter
    bond  (resn WAT ) (resn WAT ) 1000 TOKEN
    angle (resn WAT ) (resn WAT ) (resn WAT ) 500 TOKEN
    bond  (resn HOH ) (resn HOH ) 1000 TOKEN
    angle (resn HOH ) (resn HOH ) (resn HOH ) 500 TOKEN
    bond  (resn TIP*) (resn TIP*) 1000 TOKEN
    angle (resn TIP*) (resn TIP*) (resn TIP*) 500 TOKEN
end

{* Check for the presence of ions and add covalent bond *}

@MODULE:covalions.cns


{* Define various interaction and energetics settings *}

igroup
    interaction  (not (resn ANI or resn DAN or resn XAN or resn DUM or resn SHA))
                 (not (resn ANI or resn DAN or resn XAN or resn DUM or resn SHA)) weight * 1 end
    interaction  (resn ANI or resn DAN or resn XAN or resn DUM or resn DUM)
                 (resn ANI or resn DAN or resn XAN or resn DUM or resn DUM) weight * 1 vdw 0.0 elec 0.0 end
    interaction  (resn SHA) (not resn SHA) weight * 0 end
    ! turn off vdw interaction of CG charged beads with all other particles
    interaction  (name SCD1) (all) weight vdw 0.0 end
    interaction  (name SCD2) (all) weight vdw 0.0 end
end

flag include bond angle impr vdw end

if ($Data.flags.dihed eq true) then
  flag include dihed end
end if

if ($Data.flags.elec eq true) then
    flag include elec end
    if ($Data.dielec eq "rdie") then
        parameter nbonds eps=$Data.epsilon rdie shift switch end end
        ! shift statement needed first to activate switch (CNS bug?)
    else
        parameter nbonds eps=$Data.epsilon cdie end end
    end if
else
    evaluate ($elec=0.0)
    flag exclude elec end
end if

! check for the presence of a CG model
! and adapt non-bonded parameters
do (store4 = 0) (all)
do (store4 = 1) (name BB or name BB#)
show sum (store4) (all)
if ($result > 0) then
    parameter
        nbonds
            nbxmod=5 atom cdie shift
            cutnb=15.0 ctofnb=14.0 ctonnb=12.0 eps=$Data.epsilon_cg e14fac=0.4 inhibit 0.25
            wmin=0.5 tolerance 0.5
        end
    end
    evaluate ($coarse = TRUE)
end if

parameter nbonds ? end end

do (fbeta=$Saprotocol.fbeta) (all)
do (mass=$Saprotocol.mass) (all)

!catch possible bound water and set high T steps to 0
coor select ((resn WAT or resn HOH or resn TIP*)) end
if ($select gt 0) then
    evaluate ($SaProtocol.initiosteps = 0)
    evaluate ($SaProtocol.cool1_steps = 0)
    evaluate ($refine.keepwater = true)
end if

! random placement of molecules
if ($SaProtocol.separate eq true) then
    @MODULE:separate.cns
end if
if ($SaProtocol.randrot eq true) then
    @MODULE:random_rotations.cns
end if

{* Read the distance restraints ================================ *}
set seed $seed end
set message=normal echo=on end
inline @MODULE:read_data.cns

! random removal of restaints
if ($Data.randremoval eq true) then
    noe cv $npart ? end
end if

if ( $log_level = "verbose" ) then
    set message=all echo=on end
elseif ( $log_level = "normal" ) then
    set message=normal echo=off end
else
    set message=off echo=off end
end if

evaluate ($numnoe = 0)

!Make sure that at least as many distance restraints are successfully
!read as the number of partitions for cross-validation
evaluate ($numnoe = 999)
noe ? end
if ($NUMNOE = 0) then
    if ($Data.ncomponents > 1) then
        if ($Data.contactairs eq FALSE) then
            if ($Data.cmrest eq FALSE) then
                evaluate ($errfile = "MODDIR:WARNING")
                fileexist $errfile end
                if ($result eq false) then
                    set display=$errfile end
                    display TOTAL NUMBER OF DISTANCE RESTRAINTS FOR FLEXIBLE REFINEMENT IS ZERO!
                    display CONTROL YOUR PARAMETER SETTINGS AND RESTRAINT DEFINITIONS
                    close $errfile end
                end if
            end if
        end if
    end if
    evaluate ($Data.npart = 1)
    evaluate ($Data.randremoval = FALSE)
end if

if ($NUMNOE lt $Data.npart) then
    noe part=1 end
    evaluate ($Data.npart = 1)
    evaluate ($Data.randremoval = FALSE)
end if


{* set the energy flags ======================================================== *}

inline @MODULE:setflags.cns

{* Check for other restraints ================================================== *}

@MODULE:symmultimer.cns

if ($Data.cmrest eq true ) then
    @MODULE:cm-restraints.cns
end if

if ($Data.contactairs eq true ) then
    @MODULE:contactairs.cns
end if

if ($Data.dnarest eq true ) then
    @MODULE:dna-rna_restraints.cns
end if

if ($Data.ssdihed eq "all" ) then
    inline @MODULE:protein-ss-restraints-all.cns
end if
if ($Data.ssdihed eq "alpha" ) then
    inline @MODULE:protein-ss-restraints-alpha.cns
end if
if ($Data.ssdihed eq "alphabeta" ) then
    inline @MODULE:protein-ss-restraints-alpha-beta.cns
end if

{* Check for the presence of ions and add distance restraints *}
@MODULE:restrain-ions.cns


{* Check first for failed structures =========================================== *}
evaluate ($failure = false)
evaluate ($filefail=$output_pdb_filename - ".pdb" + ".fail")
fileexist $filefail end
evaluate ($failure = $result)


{* Define initial weights for distance restraints ============================== *}
evaluate ($unambig_scale = $Data.unambig_hot)
evaluate ($ambig_scale = $Data.ambig_hot)
evaluate ($hbond_scale = $Data.hbond_hot)

noe
    scale dist $unambig_scale
    scale ambi $ambig_scale
    scale hbon $hbond_scale
end

{* Stage 0 ================================== initial EM for flexible parts only *}

! get initial energy
energy end

! fix the residues describing the shape
fix sele=(resn SHA) end

! define flexible interface
@MODULE:flex_segment_back.cns
fix sele=((attr store5 = 0 or name OO or resn SHA) and not name H* and not (resn WAT or resn HOH or resn TIP*)) end

! energy minimization
if ($nemsteps > 0) then
    minimize powell nstep=$nemsteps drop=10.0 nprint=25 end
end if

fix sele=(not all) end

! get initial energy
energy end

! fix the residues describing the shape
fix sele=(resn SHA) end

! the following is added to avoid the generation of the torsion angle topology if not needed
! in cases where the number of steps is set to 0 (avoid issues with isolated atoms)
eval ($torsiondone = false)

! start SA in torsion angle unless a failure was detected
if ($failure eq false) then

    {* Stage 1 ======================================= rigid body high temperature search*}

    if ($nfle > 0) then
        ! reduce timestep in case of fully flexible segments
        evaluate ($SaProtocol.tadfactor = min(4,$SaProtocol.tadfactor))
    end if
    if ($SaProtocol.initiosteps > 0) then
        inline @MODULE:flex_segment.cns
        @MODULE:torsiontop.cns
        eval ($torsiondone = true)
        @MODULE:sa_ltad_hightemp.cns
    end if

    {* Stage 2 ======================================= rigid body first slow cooling *}

    if ($SaProtocol.cool1_steps > 0) then
        if ($torsiondone ne true) then
            inline @MODULE:flex_segment.cns
            @MODULE:torsiontop.cns
            eval ($torsiondone = true)
        end if
        if ($nfle > 0) then
            ! reduce timestep in case of fully flexible segments
            evaluate ($SaProtocol.tadfactor = min(4,$SaProtocol.tadfactor))
        end if
        @MODULE:sa_ltad_cool1.cns
    end if

    {* Stage 3 ======================================= second slow cooling *}
    {* flexible side-chains and reduced time step *}

    if ($SaProtocol.cool2_steps > 0) then
        if ($torsiondone eq true) then
            dyna tors topo reset end end
        end if
        inline @MODULE:flex_segment_side.cns
        @MODULE:torsiontop.cns
        eval ($torsiondone = true)
        evaluate ($SaProtocol.tadfactor = 1)
        @MODULE:sa_ltad_cool2.cns
    end if

    {* Stage 4 ============================================ third slow cooling *}
    {* flexible side-chains and backbone at interface and reduced time step *}

    if ($SaProtocol.cool3_steps > 0) then
        if ($torsiondone eq true) then
            dyna tors topo reset end end
        end if
        inline @MODULE:flex_segment_back.cns
        @MODULE:torsiontop.cns
        eval ($torsiondone = true)
        evaluate ($SaProtocol.tadfactor = 1)
        @MODULE:sa_ltad_cool3.cns
    end if

end if

{* Stage 5 =========================== final minimization *}

! define flexible segments and fix the remaining of the structure
@MODULE:flex_segment_back.cns
fix sele=((attr store5 = 0 or name OO or resn SHA) and not name H* and not (resn WAT or resn HOH or resn TIP* or resn XAN)) end

! energy minimization
if ($nemsteps > 0) then
    minimize powell nstep=$nemsteps drop=10.0 nprint=25 end
end if

! final energy
fix sele=(not all) end

{* ======================= calculate free molecules internal energy *}

igroup
    interaction (not (resn ANI or resn DAN or resn XAN or resn SHA or resn WAT or resn HOH or resn TIP* or resn DUM))
                (not (resn ANI or resn DAN or resn XAN or resn SHA or resn WAT or resn HOH or resn TIP* or resn DUM)) weight * 1 end
end

do (refx=x) (all)
do (refy=y) (all)
do (refz=z) (all)

fix sele=(resn ANI or resn DAN or resn XAN or resn SHA or resn WAT or resn HOH or resn TIP* or resn DMS) end

flag excl noe dani sani vean xrdc xpcs coll cdih zhar end
flag include bond angle dihe impr vdw end

evaluate ($elec = 0.0)
evaluate ($eintfree = 0.0)
if ($Data.flags.elec eq true) then
    flag include elec end
end if

if ($Data.dielec eq "rdie") then
    parameter nbonds eps=$Data.epsilon rdie shift switch end end
    ! shift statement needed first to activate switch (CNS bug?)
else
    parameter nbonds eps=$Data.epsilon cdie end end
end if
parameter nbonds ? end end
inline @MODULE:calc_free-ene.cns

fix sele=(not all) end

do (x = refx) (all)
do (y = refy) (all)
do (z = refz) (all)


{* ===================== calculate complex internal energy *}

evaluate ($kinter = 1.0)
flag include bond angle dihe impr vdw end
energy end

@MODULE:scale_intra_only.cns

evaluate ($elec = 0.0)
evaluate ($eintcplx = 0.0)
if ($Data.flags.elec eq true) then
    flag include elec end
end if

energy end

evaluate ($eintcplx = $bond + $angl + $impr + $dihe + $vdw + $elec)
evaluate ($ebond = $bond)
evaluate ($eangl= $angl)
evaluate ($eimpr= $impr)
evaluate ($edihe= $dihe)

evaluate ($result=0)
print thres=0.05 bonds
evaluate ($rms_bonds=$result)
evaluate ($result=0)
print thres=5. angles
evaluate ($rms_angles=$result)
evaluate ($result=0)
print thres=5. impropers
evaluate ($rms_impropers=$result)
evaluate ($result=0)
print thres=30. dihedrals
evaluate ($rms_dihedrals=$result)


{* ===================== calculate final energies and write structure *}
evaluate ($cdih=0.0)
flag incl noe cdih end
if ($Data.ncomponents > 1) then
    evaluate ($kinter = 1.0)
    @MODULE:scale_inter_final.cns
else
    @MODULE:scale_intra_only.cns
end if

noe
    scale dist $Data.unambig_cool3
    scale ambi $Data.ambig_cool3
    scale hbon $Data.hbond_cool3
    scale symm 0.0
    scale cont 0.0
end
energy end
evaluate ($eair= $noe)

evaluate ($esym = 0.0)
evaluate ($ncs = 0.0)
evaluate ($zhar = 0.0)
evaluate ($rms_test_noe = 0.0)
evaluate ($violations_test_noe = 0)
if ($Data.flags.sym eq true) then
    ! calculatee first the symmetry energy
    noe reset nres= 1200000 end
    @MODULE:symmultimer.cns
    noe
        scale symm $Data.ksym
    end
    energy end
    evaluate ($esym = $noe)
    noe reset end
    set seed=$seed end
    !read back all the distance restraints:
    @@MODULE:read_noes.cns
    ! random removal of restaints
    if ($Data.randremoval eq true) then
        noe cv $npart ? end
    end if
    noe
        scale dist $Data.unambig_cool3
        scale ambi $Data.ambig_cool3
        scale hbon $Data.hbond_cool3
    end
    evaluate ($result = 0)
    print threshold=0.3 noe
    evaluate ($rms_noe=$result)
    evaluate ($violations_noe=$violations)
    if ($Data.randremoval eq true) then
        evaluate ($rms_test_noe=$test_rms)
        evaluate ($violations_test_noe=$test_violations)
    end if
else
    evaluate ($result = 0)
    print threshold=0.3 noe
    evaluate ($rms_noe=$result)
    evaluate ($violations_noe=$violations)
    if ($Data.randremoval eq true) then
        evaluate ($rms_test_noe=$test_rms)
        evaluate ($violations_test_noe=$test_violations)
    end if
end if

if ($Data.dnarest eq true ) then
    @MODULE:dna-rna_restraints.cns
end if

energy end
evaluate ($etot = $ener - $noe)
evaluate ($noe = $eair)
evaluate ($etot = $etot + $noe)

inline @MODULE:print_coorheader.cns


{* determine whether the final models should be reoriented along their principal *}
{* axes before writing to file ================================================= *}
eval($reorient = true)
evaluate ($ncount = 0)
while ($ncount < $data.ncomponents) loop orientmol
    evaluate ($ncount = $ncount + 1)
    eval($watersegname_$ncount="WA" + encode($ncount))
    if ($mol_fix_origin_$ncount eq true) then
        eval($reorient = false)
    end if
end loop orientmol

if ($reorient = true) then
    coor sele= (not name H* and not resn ANI and not resn XAN and not resn DAN) orient end
end if

inline @MODULE:check_coordinates.cns
  
if ($failure eq true) then
    evaluate ($failfile = $output_pdb_filename - ".pdb" + ".fail")
    set display=$failfile end
    display "MAX/MIN possible coordinates exceeded - stopping"
    close $failfile end
    stop
else
    write coordinates format=pdbo output=$output_pdb_filename end
end if

display OUTPUT: $output_pdb_filename

stop