~sjdv1982/spyder-framework/spyder-haddock

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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
# Copyright 2007-2009 Sjoerd de Vries
# This file is part of the Spyder module: "haddock" 
# For licensing information, see LICENSE.txt 

Type Data_TBL:Data {
  """
  Data in the HADDOCK/CNS TBL format
  statements must be "assign [(...)]x [...]y" where x and y are number of repetitions
  allowed combinations of x and y:
    x=2, y=3
    x=4, y=4, last y is integer rather than floar
    x=6, y=2
  """
}

Type HaddockEasyInterface {
  """
  Web form for the HADDOCK server Easy Interface
  """
  form {
    HEADER runname You may supply a name for your docking run (one word) 
    runname Name
    p1 First molecule
    p2 Second molecule
    HEADER username Username and password
    TYPE username required
    username Username
    TYPE password password
    password Password
  }  
  *String runname
  ## form TYPE runname required
  validate {
    has_r1 = (p1.r != None and (len(p1.r.activereslist) > 0 or len(p1.r.passivereslist) > 0))
    has_r2 = (p2.r != None and (len(p2.r.activereslist) > 0 or len(p2.r.passivereslist) > 0)) 
    if not has_r1: raise HaddockValidationError("You must supply active and/or passive residues for your first protein.")    
    if not has_r2: raise HaddockValidationError("You must supply active and/or passive residues for your second protein.")
    
    if len(p1.r.activereslist) == 0 and len(p2.r.activereslist) == 0:
      raise HaddockValidationError("You have defined only passive residues. HADDOCK needs at least one active residue to drive the docking.")
    if len(p1.r.activereslist) == 0 and len(p2.r.passivereslist) > 0:
      raise HaddockValidationError("Protein 1 has no active residues defined. Therefore, it is meaningless to define passive residues on protein 2. Please remove the passive residues on protein 2.")        
    if len(p2.r.activereslist) == 0 and len(p1.r.passivereslist) > 0:
      raise HaddockValidationError("Protein 2 has no active residues defined. Therefore, it is meaningless to define passive residues on protein 1. Please remove the passive residues on protein 1.")        
  
    if runname != None:
      
      runname = runname.strip()
      self.runname = runname
      if not runname.replace("_","").replace("-","").isalnum():
        raise HaddockValidationError("The name of your run may contain only letters, digits, _ and -")
  }
  HaddockPartnerInterface p1
  HaddockPartnerInterface p2
  *String username
  *String password
}

Type HaddockExpertInterface:HaddockEasyInterface {
  """
  Web form for the HADDOCK server Expert Interface
  """
  Delete form
  ## form TYPE runname required
  Delete username
  Delete password
  Delete validate
  form {
    HEADER runname You may supply a name for your docking run (one word) 
    runname Name
    p1 First molecule
    p2 Second molecule
    HEADER username Username and password
    TYPE username required
    username Username
    TYPE password password
    password Password
  }  

  Delete p1
  Delete p2
  HaddockPartnerExpertInterface p1
  HaddockPartnerExpertInterface p2
  
  ## form SUPERHEADER auto_passive_radius Distance restraints
  ## form auto_passive_radius If you specified that passive residues will be defined automatically, all surface residues will be selected within the following radius (in angstroms) around the active residues 
  Float auto_passive_radius = 6.5
  ## form SUPERHEADER tblfile Distance restraints
  ## form tblfile Instead of specifying active and passive residues, you can supply a HADDOCK restraints TBL file  (ambiguous restraints)
  ## form TYPE tblfile required  
  ## form FILE tblfile Data_TBL
  *File tblfile
  ## form SUPERHEADER unambigtblfile Distance restraints    
  ## form unambigtblfile You can supply a HADDOCK restraints TBL file with restraints that will always be enforced (unambiguous restraints)
  ## form TYPE unambigtblfile required  
  ## form FILE unambigtblfile Data_TBL
  *File unambigtblfile
  ## form SUPERHEADER create_narestraints Distance restraints
  ## form HEADER create_narestraints If one of your molecules is DNA/RNA, restraints are automatically created to preserve its structure.
  ## form HEADER create_narestraints Uncheck this option if you are docking with unstructured DNA/RNA
  ## form create_narestraints Create DNA/RNA restraints?
  Bool create_narestraints = True
  ## form SUPERHEADER delenph Distance restraints
  ## form HEADER delenph HADDOCK deletes by default all hydrogens except those bonded to a polar atom (N, O). 
  ## form HEADER delenph Uncheck this option if you have NOEs or other specific restraints to non-polar hydrogens
  ## form delenph Remove non-polar hydrogens?
  Bool delenph = True  
  ## form SUPERHEADER ranair Distance restraints            
  ## form HEADER ranair Random patches
  ## form ranair Define randomly ambiguous interaction restraints from accessible residues
  Bool ranair = False
  ## form SUPERHEADER cmrest Distance restraints            
  ## form HEADER cmrest Center of mass restraints
  ## form cmrest Define center of mass restraints to enforce contact between the molecules
  Bool cmrest = False
  ## form SUPERHEADER kcont Distance restraints            
  ## form kcont Force constant for center of mass contact restraints 
  Float kcont = 1
  ## form SUPERHEADER surfrest Distance restraints
  ## form HEADER surfrest Surface contact restraints
  ## form surfrest Define surface contact restraints to enforce contact between the molecules
  Bool surfrest = False
  ## form SUPERHEADER ksurf Distance restraints
  ## form ksurf Force constant for surface contact restraints 
  Float ksurf = 1
  ## form SUPERHEADER noecv Distance restraints
  ## form HEADER noecv Random exclusion
  ## form noecv Randomly exclude a fraction of the ambiguous restraints (AIRs)
  Bool noecv = True
  ## form SUPERHEADER ncvpart Distance restraints
  ## form ncvpart Number of partitions for random exclusion (%%excluded=100/number of partitions)
  Float ncvpart = 2
   
  ## form SUPERHEADER structures_0 Sampling parameters
  ## form structures_0 Number of structures for rigid body docking 
  Integer structures_0 = 1000
  ## form SUPERHEADER ntrials Sampling parameters
  ## form ntrials Number of trials for rigid body minimisation
  Integer ntrials = 5
  ## form SUPERHEADER rotate180_0 Sampling parameters
  ## form rotate180_0 Sample 180 degrees rotated solutions during rigid body EM
  Bool rotate180_0 = True  
  ## form SUPERHEADER smoothing Sampling parameters
  ## form smoothing Perform smoothed-scoring selection for rigid-body docking solutions
  ## form TYPE smoothing none
  Bool smoothing = False    
  ## form SUPERHEADER structures_1 Sampling parameters
  ## form structures_1 Number of structures for semi-flexible refinement 
  Integer structures_1 = 200
  ## form SUPERHEADER rotate180_1 Sampling parameters
  ## form rotate180_1 Sample 180 degrees rotated solutions during semi-flexible SA
  Bool rotate180_1 = False  
  ## form SUPERHEADER solvent Sampling parameters
  ## form solvent Solvent to use for the last iteration
  Enum solvent("water", "dmso") = "water"   
  ## form SUPERHEADER waterrefine Sampling parameters
  ## form waterrefine Number of structures for the explicit solvent refinement 
  Integer waterrefine = 200
  
  ## form SUPERHEADER epsilon Sampling parameters
  ## form HEADER epsilon Epsilon constant for the electrostatic energy term
  ## form HEADER epsilon Note that for explicit solvent refinement cdie with epsilon=1 is used  
  ## form epsilon Epsilon
  Float epsilon = 10 
  
  ## form SUPERHEADER waterdock Sampling parameters
  ## form HEADER waterdock Solvated docking mode
  ## form waterdock Perform solvated docking
  Bool waterdock = False  

  ## form SUPERHEADER clust_rmsd Parameters for clustering
  ## form clust_rmsd RMSD Cutoff for clustering
  Float clust_rmsd = 7.5

  ## form SUPERHEADER clust_size Parameters for clustering
  ## form clust_size Minimum cluster size
  Integer clust_size = 4

  ##form SUPERHEADER dihedralfile Dihedral and hydrogen bond restraints
  ##form HEADER dihedralfile In addition to distance restraints, you may specify dihedral and hydrogen bond restraints<BR>These restraints can be inter- or intramolecular
  ##form TYPE dihedralfile required
  ##form FILE dihedralfile Data_TBL
  ##form dihedralfile Dihedral angle restraints TBL file
  *File dihedralfile
  ##form SUPERHEADER hbondfile Dihedral and hydrogen bond restraints
  ##form TYPE hbondfile required
  ##form FILE hbondfile Data_TBL
  ##form hbondfile Hydrogen bond restraints TBL file
  *File hbondfile
  
  *String username
  *String password
 
  validate {    
    has_r1 = (p1.r != None and (len(p1.r.activereslist) > 0 or len(p1.r.passivereslist) > 0))
    has_r2 = (p2.r != None and (len(p2.r.activereslist) > 0 or len(p2.r.passivereslist) > 0)) 
    if has_r1 != has_r2: raise HaddockValidationError("You must supply either active and passive residues for both proteins or for neither of them.")
    if has_r1 == (tblfile != None or unambigtblfile != None): 
       if not has_r1: 
         if ranair == False and cmrest == False and surfrest == False:
           raise HaddockValidationError("You can define active and passive residues for both proteins. Alternatively, in Expert/Guru mode, you can also define a restraints table, random restraints, or center-of-mass restraints.\nHADDOCK cannot run without this. Please provide one of the two.")
    if has_r1 == (tblfile != None): 	   
       if has_r1: 
         raise HaddockValidationError("You can define active and passive residues for both proteins. Alternatively, in Expert/Guru mode, you can also define a restraints table, random restraints, or center-of-mass restraints. These options are mutually exclusive, but both have been defined here.\nPlease remove either the restraints table or the active and passive residues.")
    if has_r1:
      if len(p1.r.activereslist) == 0 and len(p2.r.activereslist) == 0:
        raise HaddockValidationError("You have defined only passive residues. HADDOCK needs at least one active residue to drive the docking.")
      if len(p1.r.activereslist) == 0 and len(p2.r.passivereslist) > 0:
        raise HaddockValidationError("Protein 1 has no active residues defined. Therefore, it is meaningless to define passive residues on protein 2. Please remove the passive residues on protein 2.")        
      if len(p2.r.activereslist) == 0 and len(p1.r.passivereslist) > 0:
        raise HaddockValidationError("Protein 2 has no active residues defined. Therefore, it is meaningless to define passive residues on protein 1. Please remove the passive residues on protein 1.")        
    restcount = 0
    if ranair == True: restcount += 1
    if has_r1 or tblfile != None or unambigtblfile != None: restcount += 1
    if restcount > 1:
      raise HaddockValidationError("Manual restraints and random patches are mutually exclusive")
	
    if not (p1.segid == None or (p1.segid != p2.segid)):
       raise HaddockValidationError("You must supply segids for every PDB and they must be different")
    if not (structures_0 > 0): raise HaddockValidationError("At least one rigid body (it0) structure must be generated, increase the number of structures")
    if structures_1 > structures_0:
      raise HaddockValidationError("You cannot generate more structures in it1 than in it0")
    if waterrefine > structures_1:
      raise HaddockValidationError("You cannot generate more structures in the water refinement than in it1")
    if ncvpart <= 1:
      raise HaddockValidationError("The number of crossvalidation partitions may be fractional, but must be larger than 1")
    if ncvpart - int(ncvpart) > 0:
      if tblfile != None:
        raise HaddockValidationError("The number of crossvalidation partitions may be fractional, but not if a restraints table is supplied")

    if runname != None:
      
      runname = runname.strip()
      self.runname = runname
      if not runname.replace("_","").replace("-","").isalnum():
        raise HaddockValidationError("The name of your run may contain only letters, digits, _ and -")
        
  }  
}
Define HaddockExpertInterface(HaddockEasyInterface) CAST
Define HaddockEasyInterface(HaddockExpertInterface) CAST

Type HaddockGuruInterface:HaddockExpertInterface {
  """
  Web form for the HADDOCK server Guru Interface
  """
  Delete username
  Delete password

  ## form HEADER xplortodiana Atomname nomenclature 
  ## form HEADER xplortodiana  set True if you have IUPAC (e.g. LEU HB2 and HB3 and not HB2 and HB1) data (e.g. from XEASY) 
  ## form TYPE xplortodiana none
  *Bool xplortodiana = False 

  ## form SUPERHEADER ncs Noncrystallographic symmetry restraints
  ## form ncs NCS parameters
  SymmetrySpecification ncs = dict(on=False, constant = 1)
  ## form SUPERHEADER ncssegments Noncrystallographic symmetry restraints
  ## form ncssegments Segment pair
  ## form TYPE ncssegments required
  ## form LENGTH ncssegments 5
  *LabeledRangePairArray ncssegments

  ## form SUPERHEADER symmetry Symmetry restraints
  ## form symmetry Symmetry parameters
  SymmetrySpecification symmetry = dict(on=False, constant = 10)
  ## form SUPERHEADER c2segments Symmetry restraints
  ## form c2segments C2 symmetry segment pair
  ## form TYPE c2segments required
  ## form LENGTH c2segments 10
  *LabeledRangePairArray c2segments
  ## form SUPERHEADER c3segments Symmetry restraints
  ## form c3segments C3 symmetry segment triple
  ## form TYPE c3segments required
  ## form LENGTH c3segments 2
  *LabeledRangeTripleArray c3segments
  ## form SUPERHEADER c4segments Symmetry restraints
  ## form c4segments C4 symmetry segment quadruple
  ## form TYPE c4segments none
  *LabeledRangeQuadrupleArray c4segments
  ## form SUPERHEADER c5segments Symmetry restraints
  ## form c5segments C5 symmetry segment quintuple
  ## form TYPE c5segments required
  ## form LENGTH c5segments 1
  *LabeledRangeQuintupleArray c5segments
  ## form SUPERHEADER s3segments Symmetry restraints
  ## form s3segments S3 symmetry segment triple
  ## form TYPE s3segments none
  ## form LENGTH s3segments 4
  *LabeledRangeTripleArray s3segments
  
  ## form SUPERHEADER unamb Restraints energy constants  
  ## form unamb Energy constants for unambiguous restraints
  ## form SUPERHEADER amb Restraints energy constants  
  ## form amb Energy constants for ambiguous restraints
  ## form SUPERHEADER hbond Restraints energy constants  
  ## form hbond Energy constants for hydrogen bond restraints
  ExtStageConstants unamb = (0,2,(10,10,50,50))
  ExtStageConstants amb = (0,2,(10,10,50,50))
  ExtStageConstants hbond = (1,2,(10,10,50,50))  
  ## form SUPERHEADER dihedrals Restraints energy constants  
  ## form dihedrals Energy constants for dihedral angle restraints  
  StageConstants dihedrals = (5,5,50,200)  
  ## form air_scaling Use automated distance restraints weighting
  ## form TYPE air_scaling none
  Bool air_scaling = False 
  ## form tot_unamb Number of distance restraints for automated weighting
  ## form TYPE tot_unamb none
  Integer tot_unamb = 25
  ## form tot_amb Number of AIR restraints for automated weighting
  ## form TYPE tot_amb none
  Integer tot_amb = 0
  ## form mrswi potential shape
  ## form TYPE mrswi none
  ## form TYPE rswi none
  ## form TYPE masy none
  ## form TYPE asy none
  StageConstants mrswi = (0.5,0.5,0.5,0.5)
  StageConstants rswi = (0.5,0.5,0.5,0.5)
  StageConstants masy = (-1,-1,-0.1,-0.1)
  StageConstants asy = (1,1,0.1,0.1)

  ## form HEADER c1 Karplus coupling restraints 
  ## form HEADER c1 The jcoupling restraint files should be present in the data/jcouplings directory 
  ## form HEADER c1 and named c1.tbl, c2.tbl, ... 
  ## form TYPE c1 none
  ## form TYPE c2 none
  ## form TYPE c3 none
  ## form TYPE c4 none  
  ## form TYPE c5 none    
  KarplusConstants c1 = (False, 6.98,-1.38,1.72,-60,(0,0.2,1,1))
  KarplusConstants c2 = (False, 6.98,-1.38,1.72,-120,(0,0.2,1,1))
  KarplusConstants c3 = (False, 6.98,-1.38,1.72,-120,(0,0.2,1,1))
  KarplusConstants c4 = (False, 6.98,-1.38,1.72,-120,(0,0.2,1,1))
  KarplusConstants c5 = (False, 6.98,-1.38,1.72,-120,(0,0.2,1,1))
  
  ## form SUPERHEADER rdc1 Residual dipolar couplings
  ## form SUPERHEADER rdc2 Residual dipolar couplings
  ## form SUPERHEADER rdc3 Residual dipolar couplings
  ## form SUPERHEADER rdc4 Residual dipolar couplings
  ## form SUPERHEADER rdc5 Residual dipolar couplings
  ## form HEADER rdc1 Residual dipolar couplings 1
  ## form HEADER rdc2 Residual dipolar couplings 2
  ## form HEADER rdc3 Residual dipolar couplings 3
  ## form HEADER rdc4 Residual dipolar couplings 4
  ## form HEADER rdc5 Residual dipolar couplings 5
  RDCInterface rdc1 = ("NO", 0.4, 8,(0,2,(0.1,1,1,1)), (1,10,40,40), (10,40,40,40), (0.25,2.5,10,10), (2.5,10,10,10))
  RDCInterface rdc2 = ("NO", 0.4, 8,(0,2,(0.1,1,1,1)), (1,10,40,40), (10,40,40,40), (0.25,2.5,10,10), (2.5,10,10,10))
  RDCInterface rdc3 = ("NO", 0.4, 8,(0,2,(0.1,1,1,1)), (1,10,40,40), (10,40,40,40), (0.25,2.5,10,10), (2.5,10,10,10))
  RDCInterface rdc4 = ("NO", 0.4, 8,(0,2,(0.1,1,1,1)), (1,10,40,40), (10,40,40,40), (0.25,2.5,10,10), (2.5,10,10,10))
  RDCInterface rdc5 = ("NO", 0.4, 8,(0,2,(0.1,1,1,1)), (1,10,40,40), (10,40,40,40), (0.25,2.5,10,10), (2.5,10,10,10))

  ## form SUPERHEADER dan1 Relaxation anisotropy restraints
  ## form SUPERHEADER dan2 Relaxation anisotropy restraints  
  ## form SUPERHEADER dan3 Relaxation anisotropy restraints
  ## form SUPERHEADER dan4 Relaxation anisotropy restraints
  ## form SUPERHEADER dan5 Relaxation anisotropy restraints
  ## form HEADER dan1 Anisotropy restraints 1
  ## form HEADER dan2 Anisotropy restraints 2
  ## form HEADER dan3 Anisotropy restraints 3  
  ## form HEADER dan4 Anisotropy restraints 4
  ## form HEADER dan5 Anisotropy restraints 5  
  DANIInterface dan1 = ("NO", (0,2,(1,5,10,10)), 9.771, 1.557, 0.455, 599.91, 60.82)
  DANIInterface dan2 = ("NO", (0,1,(1,5,10,10)), 9.84, -1.35, 0.308, 599.91, 60.82)
  DANIInterface dan3 = ("NO", (1,1,(1,5,10,10)), 9.84, -1.35, 0.308, 599.91, 60.82)
  DANIInterface dan4 = ("NO", (0,2,(1,5,10,10)), 9.84, -1.35, 0.308, 599.91, 60.82)
  DANIInterface dan5 = ("NO", (0,2,(1,5,10,10)), 9.84, -1.35, 0.308, 599.91, 60.82)

  ## form SUPERHEADER par_nonbonded Energy and interaction parameters  
  ## form par_nonbonded Nonbonded parameters
  Enum par_nonbonded("PROLSQ", "PARMALLH6", "PARALLHDG", "OPLSX") = "OPLSX"

  ## form SUPERHEADER dihedflag Energy and interaction parameters
  ## form HEADER dihedflag Do you want to include dihedral angle energy terms?
  ## form HEADER dihedflag These are independent of dihedral angle restraints
  ## form dihedflag Include dihedral angle restraints
  Bool dihedflag = True 

  ## form SUPERHEADER elecflag_0 Energy and interaction parameters
  ## form HEADER elecflag_0 Do you want to include the electrostatic energy term for docking? 
  ## form HEADER elecflag_0 Note that it will be automatically included in the solvent refinement 

  ## form elecflag_0 Include electrostatic during rigid body docking (it0) 
  Bool elecflag_0 = True 
  ## form SUPERHEADER elecflag_1 Energy and interaction parameters
  ## form elecflag_1 Include electrostatic during semi-flexible SA (it1)
  Bool elecflag_1 = True 

  ## form SUPERHEADER dielec Energy and interaction parameters
  ## form dielec Use constant (cdie) or distance-dependent (rdie) dielectric 
  Enum dielec("cdie", "rdie") = "cdie"

  ## form SUPERHEADER inter_rigid Energy and interaction parameters
  ## form inter_rigid Scaling of intermolecular interactions for rigid body EM
  Float inter_rigid = 1

  ## form HEADER inter_rigid Scaling of intermolecular interactions for semi-flexible SA (it1)
  ## form SUPERHEADER scaling_init Energy and interaction parameters
  ## form scaling_init Initial value
  ScalingConstants scaling_init = (0.001,0.001,0.05)
  ## form SUPERHEADER scaling_fin Energy and interaction parameters
  ## form scaling_fin Final value
  ScalingConstants scaling_fin = (0.001,1,1)

  ## form SUPERHEADER w_vdw Scoring parameters
  ## form HEADER w_vdw Define the weights for the various terms for the sorting of structures (scoring) 
  ## form HEADER w_vdw 1: Rigid body EM (it0) 
  ## form HEADER w_vdw 2: semi-flexible SA (it1) 
  ## form HEADER w_vdw 3: water refinement 
  ## form SUPERHEADER w_elec Scoring parameters
  ## form SUPERHEADER w_dist Scoring parameters
  ## form SUPERHEADER w_sani Scoring parameters
  ## form SUPERHEADER w_dani Scoring parameters
  ## form SUPERHEADER w_vean Scoring parameters
  ## form SUPERHEADER w_cdih Scoring parameters
  ## form SUPERHEADER w_sym Scoring parameters
  ## form SUPERHEADER w_bsa Scoring parameters
  ## form SUPERHEADER w_deint Scoring parameters
  ## form SUPERHEADER w_desolv Scoring parameters
  ## form w_vdw Evdw  
  ## form w_elec Eelec
  ## form w_dist Edist
  ## form w_sani Esani
  ## form w_dani Edani
  ## form w_vean Evean
  ## form w_cdih Ecdih
  ## form w_sym Esym
  ## form w_bsa BSA
  ## form w_deint dEint
  ## form w_desolv Edesolv
  FloatArray w_vdw[3] = (0.01,1,1)
  FloatArray w_elec[3] = (1,1,0.2)
  FloatArray w_dist[3] = (0.01,0.1,0.1)
  FloatArray w_sani[3] = (0.1,0.1,0.1)
  FloatArray w_dani[3] = (0.01,0.1,0.1)
  FloatArray w_vean[3] = (0.1,0.1,0.1)
  FloatArray w_cdih[3] = (0,0,0)
  FloatArray w_sym[3] = (0.1,0.1,0.1)
  FloatArray w_bsa[3] = (-0.01,-0.01,0)
  FloatArray w_deint[3] = (0,0,0)
  FloatArray w_desolv[3] = (1,1,1)

  ## form HEADER skip_struc It is possible to skip structures in the selection of structure in it0
  ## form HEADER skip_struc Give for this the number of structures to skip:
  ## form TYPE skip_struc none
  Integer skip_struc = 0

  ## form SUPERHEADER crossdock Advanced sampling parameters
  ## form HEADER crossdock Do you want to cross-dock all combinations in the ensembles of starting structures? 
  ## form HEADER crossdock Turn off this option if you only want to dock structure 1 of ensemble A 
  ## form HEADER crossdock  to structure 1 of ensemble B, structure 2 to structure 2, etc.   
  ## form crossdock Perform cross-docking
  Bool crossdock = True
  
  ## form SUPERHEADER ensemble_multiply Advanced sampling parameters
  ## form HEADER ensemble_multiply Enable this option to multiply the number of structures in all iterations by the number of starting structure combinations. 
  ## form HEADER ensemble_multiply The number of combinations depends on the cross-docking parameter.
  ## form HEADER ensemble_multiply If cross-docking is disabled, the number of combinations is the size of the first ensemble.
  ## form HEADER ensemble_multiply If cross-docking is enabled, the number of combinations is the sizes of all ensembles multiplied. 
  ## form ensemble_multiply Multiply the number of calculated structures by all combinations
  Bool ensemble_multiply = False

  ## form SUPERHEADER randorien Advanced sampling parameters
  ## form randorien Randomize starting orientations
  Bool randorien = True

  ## form SUPERHEADER rigidmini Advanced sampling parameters
  ## form rigidmini Perform initial rigid body minimisation
  Bool rigidmini = True

  ## form SUPERHEADER rigidtrans Advanced sampling parameters
  ## form rigidtrans Allow translation in rigid body minimisation
  Bool rigidtrans = True

  ## form SUPERHEADER iniseed Advanced sampling parameters
  ## form iniseed initial seed for random number generator
  Integer iniseed = 917 

  ## form SUPERHEADER tadhigh_t Advanced sampling parameters
  ## form HEADER tadhigh_t it1 parameters
  ## form tadhigh_t temperature for rigid body high temperature TAD
  Integer tadhigh_t = 2000
  ## form SUPERHEADER tadinit1_t Advanced sampling parameters
  ## form tadinit1_t initial temperature for rigid body first TAD cooling step
  Integer tadinit1_t = 2000 
  ## form SUPERHEADER tadfinal1_t Advanced sampling parameters
  ## form tadfinal1_t final temperature after first cooling step
  Integer tadfinal1_t = 500
  ## form SUPERHEADER tadinit2_t Advanced sampling parameters
  ## form tadinit2_t initial temperature for second TAD cooling step with flexible side-chain at the inferface
  Integer tadinit2_t = 1000 
  ## form SUPERHEADER tadfinal2_t Advanced sampling parameters
  ## form tadfinal2_t final temperature after second cooling step
  Integer tadfinal2_t = 50 

  ## form SUPERHEADER tadinit3_t Advanced sampling parameters
  ## form tadinit3_t initial temperature for third TAD cooling step with fully flexible interface
  Integer tadinit3_t = 500
  ## form SUPERHEADER tadfinal3_t Advanced sampling parameters
  ## form tadfinal3_t final temperature after third cooling step 
  Integer tadfinal3_t = 50 

  ## form SUPERHEADER timestep Advanced sampling parameters
  ## form timestep time step
  Float timestep = 0.002
  ## form SUPERHEADER tadfactor Advanced sampling parameters
  ## form tadfactor factor for timestep in TAD
  Integer tadfactor = 8 

  ## form SUPERHEADER initiosteps Advanced sampling parameters  
  ## form initiosteps number of MD steps for rigid body high temperature TAD
  Integer initiosteps = 500
  ## form SUPERHEADER cool1_steps Advanced sampling parameters  
  ## form cool1_steps number of MD steps during first rigid body cooling stage
  Integer cool1_steps = 500
  ## form SUPERHEADER cool2_steps Advanced sampling parameters  
  ## form cool2_steps number of MD steps during second cooling stage with flexible side-chains at interface
  Integer cool2_steps = 1000 
  ## form SUPERHEADER cool3_steps Advanced sampling parameters  
  ## form cool3_steps number of MD steps during third cooling stage with fully flexible interface
  Integer cool3_steps = 1000 

  ## form SUPERHEADER firstwater Advanced sampling parameters  
  ## form firstwater Explicit solvent refinement for the last iteration
  Enum firstwater("yes", "no") = "yes" 
  ## form TYPE firstwater none
  
  ## form HEADER waterheatsteps final solvated refinement
  ## form SUPERHEADER waterheatsteps Advanced sampling parameters  
  ## form waterheatsteps number of steps for heating phase (100, 200, 300K)
  Integer waterheatsteps = 100

  ## form SUPERHEADER watersteps Advanced sampling parameters  
  ## form watersteps number of steps for 300K phase
  Integer watersteps = 1250

  ## form SUPERHEADER watercoolsteps Advanced sampling parameters  
  ## form watercoolsteps number of steps for cooling phase (300, 200, 100K)
  Integer watercoolsteps = 500

  ## form SUPERHEADER calcdesolv Advanced sampling parameters  
  ## form calcdesolv calculate explicit desolvation energy (note this will double the cpu requirements)
  Bool calcdesolv = False

  ## form SUPERHEADER solvate_method Solvated docking parameters
  ## form HEADER solvate_method Solvated docking can be enabled in the Sampling Parameters section
  ## form HEADER solvate_method
  ## form HEADER solvate_method Which method to use for solvating? 
  ## form HEADER solvate_method  db: database-based, restraints: for restr.,pnt: pos,neg and Tyr, "": for uniform waterlayer 
  ## form solvate_method Method
  Enum solvate_method("db", "restraints", "pnt") = "db" 
  ## form TYPE solvate_method none

  ## form SUPERHEADER water_restraint_initial Solvated docking parameters
  ## form water_restraint_initial Initial cutoff for restraints solvating method
  Float water_restraint_initial = 5

  ## form SUPERHEADER water_restraint_cutoff Solvated docking parameters
  ## form water_restraint_cutoff Cutoff for restraints solvating method
  Float water_restraint_cutoff = 5

  ## form SUPERHEADER water_restraint_scale Solvated docking parameters
  ## form water_restraint_scale Scale factor for restraints solvating method
  Float water_restraint_scale = 25

  ## form SUPERHEADER water_tokeep Solvated docking parameters
  ## form water_tokeep Fraction of water to keep in ntrial loop
  Float water_tokeep = 0.25

  ## form SUPERHEADER water_randfrac Solvated docking parameters
  ## form water_randfrac Additional random fraction of water to keep in ntrial loop
  Float water_randfrac = 0

  ## form SUPERHEADER water_surfcutoff Solvated docking parameters
  ## form water_surfcutoff Water-surface-cutoff 
  Float water_surfcutoff = 8

  ## form SUPERHEADER water_analysis Solvated docking parameters
  ## form water_analysis Do some water analysis 
  Bool water_analysis = False

  ## form SUPERHEADER transwater Solvated docking parameters
  ## form transwater Use translation in loop miniwater
  Bool transwater = True

  ## form SUPERHEADER waterensemble Solvated docking parameters
  ## form waterensemble How many different solvation shells to generate
  Integer waterensemble = 1

  ## form SUPERHEADER anastruc_1 Analysis parameters
  ## form anastruc_1 Number of structures to analyze
  Integer anastruc_1 = 200

  ## form SUPERHEADER dist_hb Analysis parameters  
  ## form dist_hb Cutoff distance (proton-acceptor) to define an hydrogen bond
  Float dist_hb = 2.5
  ## form SUPERHEADER dist_nb Analysis parameters    
  ## form dist_nb Cutoff distance (carbon-carbon) to define an hydrophobic contact
  Float dist_nb = 3.9

  ## form SUPERHEADER keepwater Analysis parameters  
  ## form keepwater After the final solvent refinement, write additional PDB files including solvent
  Bool keepwater = False 
  
  *String username
  *String password
  validate {
    assert ncssegments == None or len(ncssegments) <= 5    
    assert c2segments == None or len(c2segments) <= 10
    assert c3segments == None or len(c3segments) <= 5
    assert c4segments == None or len(c4segments) == 0
    assert c5segments == None or len(c5segments) <= 1
    assert auto_passive_radius >= 0 and auto_passive_radius <= 1000
  }
}

Define HaddockGuruInterface(HaddockExpertInterface) CAST
Define HaddockGuruInterface(HaddockEasyInterface) CAST
Define HaddockExpertInterface(HaddockGuruInterface) CAST
Define HaddockEasyInterface(HaddockGuruInterface) CAST


Type HaddockRunParameters:HaddockGuruInterface {
  """
  Data model for HADDOCK parameter files
  """
  Delete p1
  Delete p2
  HaddockPartnerParameters p1
  HaddockPartnerParameters p2
  Delete tblfile
  *String tbldata
  Delete unambigtblfile
  *String unambigtbldata
  Delete dihedralfile
  *String dihedraldata 
  Delete hbondfile
  *String hbonddata
  Delete rdc1
  Delete rdc2
  Delete rdc3
  Delete rdc4
  Delete rdc5
  RDCParameters rdc1
  RDCParameters rdc2
  RDCParameters rdc3
  RDCParameters rdc4
  RDCParameters rdc5
  Delete dan1
  Delete dan2
  Delete dan3
  Delete dan4
  Delete dan5            
  DANIParameters dan1
  DANIParameters dan2
  DANIParameters dan3
  DANIParameters dan4
  DANIParameters dan5
  Delete validate    
}

Define HaddockRunParameters(HaddockGuruInterface i) {
  ii = i.dict()
  if "pdbfile" in ii["p1"]["pdb"]: 
    ii["p1"]["pdb"]["pdbdata"] = File(**ii["p1"]["pdb"]["pdbfile"]).data().textdata()
    ii["p1"]["pdb"] = PDBData(ii["p1"]["pdb"])
  if "pdbfile" in ii["p2"]["pdb"]: 
    ii["p2"]["pdb"]["pdbdata"] = File(**ii["p2"]["pdb"]["pdbfile"]).data().textdata()
    ii["p2"]["pdb"] = PDBData(ii["p2"]["pdb"])
  r = "tblfile"
  if r in ii:
    ii["tbldata"] = File(**ii[r]).data().textdata()
  r = "unambigtblfile"
  if r in ii:
    ii["unambigtbldata"] = File(**ii[r]).data().textdata()
  
  dihedraldata = None
  r = "dihedralfile" 
  if r in ii:
    fil = File(**ii[r])
    dihedraldata = fil.data().textdata()
  ii["dihedraldata"] = dihedraldata
  
  hbonddata = None
  r = "hbondfile" 
  if r in ii:
    fil = File(**ii[r])
    hbonddata = fil.data().textdata()
  ii["hbonddata"] = hbonddata

  for v in ("rdc1", "rdc2", "rdc3", "rdc4", "rdc5"):
    vv = ii[v]
    rdcdata = None
    r = "rdcfile"    
    if r in vv:
      fil = File(**vv[r])
      rdcdata = fil.data().textdata()
    vv["rdcdata"] = rdcdata

  for v in ("dan1", "dan2", "dan3", "dan4", "dan5"):
    vv = ii[v]
    danidata = None
    r = "danifile"
    if r in vv:
      fil = File(**vv[r])
      danidata = fil.data().textdata()
    vv["danidata"] = danidata
  
  return HaddockRunParameters(ii)
}


Define HaddockGuruInterface(HaddockRunParameters i) {  
  ii = i.dict()
  if "pdbdata" in ii["p1"]["pdb"]: 
    v = Data_PDB(ii["p1"]["pdb"]["pdbdata"])
    ii["p1"]["pdb"]["pdbfile"] = v.totempfile()            
    ii["p1"]["pdb"] = PDBInterface.fromdict(ii["p1"]["pdb"])
  if "pdbdata" in ii["p2"]["pdb"]: 
    v = Data_PDB(ii["p2"]["pdb"]["pdbdata"])
    ii["p2"]["pdb"]["mode"] = "submit"
    ii["p2"]["pdb"]["pdbfile"] = v.totempfile()
    ii["p2"]["pdb"] = PDBInterface.fromdict(ii["p2"]["pdb"])
  r = "tbldata"
  if r in ii:
    ii["tblfile"] = ii[r].totempfile()
  r = "unambigtbldata"
  if r in ii:
    ii["unambigtblfile"] = ii[r].totempfile()
  
  dihedralfile = None
  r = "dihedraldata" 
  if r in ii:    
    dihedralfile = ii[r].totempfile()
  ii["dihedralfile"] = dihedralfile
  
  hbondfile = None
  r = "hbonddata" 
  if r in ii:    
    hbondfile = ii[r].totempfile()
  ii["hbondfile"] = hbondfile

  for v in ("rdc1", "rdc2", "rdc3", "rdc4", "rdc5"):
    vv = ii[v]
    rdcfile = None
    r = "rdcdata"    
    if r in vv:
      rdcfile = vv[r].totempfile()
    vv["rdcfile"] = rdcfile

  for v in ("dan1", "dan2", "dan3", "dan4", "dan5"):
    vv = ii[v]
    danifile = None
    r = "danidata"
    if r in vv:
      danifile = vv[r].totempfile()
    vv["danifile"] = danifile
  
  return HaddockGuruInterface(ii)
}

Type HaddockRunParameterInterface {
  """
  Web form for the HADDOCK server File Upload Interface
  """
  *String runname
  ## form TYPE runname required
  File params
  ##form FILE params Data
  *String username
  *String password
  form {
    HEADER runname You may supply a name for your docking run (one word) 
    runname Name
    HEADER params Please upload a parameter file for your docking run
    params Parameter file
    HEADER username Username and password
    TYPE username required
    username Username
    TYPE password password
    password Password
  }
  validate {
    if runname != None:      
      runname = runname.strip()
      self.runname = runname
      if not runname.replace("_","").replace("-","").isalnum():
        raise HaddockValidationError("The name of your run may contain only letters, digits, _ and -")  
    ok = False
    for filetype in HaddockMultiRunParameters, HaddockRunParameters:      
      try:
        Spyder.core.fastparsestring(params.data().data(), filetype)
        ok = True
        break
      except:
        pass
    if not ok: raise HaddockValidationError(
      "The file that you uploaded is of an unknown format. Please upload a HADDOCK server parameter file"
    )  
  }
}

Type HaddockMultiInterface {
  *String runname 
  ## form TYPE runname required
  *HaddockMultiPartnerInterfaceArray p
  Include HaddockGuruInterface
  Delete p1
  Delete p2  
  Delete validate
  form {
    p Partner molecule
    LENGTH p 6
    TYPE p required
  }
  validate {
    if p == None or len(p) == 0: raise HaddockValidationError("Please specify at least one partner molecule")
    if p != None: assert len(p) <= 6
    if runname != None:
      runname = runname.strip()
      self.runname = runname
      if not runname.replace("_","").replace("-","").isalnum():
        raise HaddockValidationError("The name of your run may contain only letters, digits, _ and -")  
    if len(p) >= 2: 
      self.convert(HaddockGuruInterface)
      for n in range(len(p)):
        if p[n].segid == None: continue
        for nn in range(n+1, len(p)):
          if p[n].segid == p[nn].segid:
            raise HaddockValidationError("Protein %d and %d have the same segid" % (n+1, nn+1))
    else:    
      if not (structures_0 > 0): raise HaddockValidationError("At least one rigid body (it0) structure must be generated, increase the number of structures")
      if structures_1 > structures_0:
        raise HaddockValidationError("You cannot generate more structures in it1 than in it0")
      if waterrefine > structures_1:
        raise HaddockValidationError("You cannot generate more structures in the water refinement than in it1")
      if ncvpart <= 1:
        raise HaddockValidationError("The number of crossvalidation partitions may be fractional, but must be larger than 1")
      if ncvpart - int(ncvpart) > 0:
        if tblfile != None:
          raise HaddockValidationError("The number of crossvalidation partitions may be fractional, but not if a restraints table is supplied")      
  }
  
}

Define HaddockGuruInterface(HaddockMultiInterface i) {
  if i.p == None or len(i.p) < 2: return None
  d = i.dict()
  d["p1"] = i.p[0].dict()
  d["p2"] = i.p[1].dict()
  ret = HaddockGuruInterface(d)
  return ret
}

Type HaddockMultiRunParameters:HaddockRunParameters {
  Delete p1
  Delete p2
  *HaddockPartnerParametersArray p
  validate {
    if p == None or len(p) == 0: raise HaddockValidationError("Please specify at least one partner molecule")
  }
}


Define HaddockMultiRunParameters(HaddockMultiInterface i) {
  ii = i.dict()  
  if i.p != None:
    for n in range(len(i.p)):
      cur = ii["p"][n]
      if "pdbfile" in cur["pdb"]: 
        cur["pdb"]["pdbdata"] = File(**cur["pdb"]["pdbfile"]).data().textdata()
        cur["pdb"] = PDBData(cur["pdb"])
      HaddockPartnerParameters(cur)
  r = "tblfile"
  if r in ii:
    ii["tbldata"] = File(**ii[r]).data().textdata()
  r = "unambigtblfile"
  if r in ii:
    ii["unambigtbldata"] = File(**ii[r]).data().textdata()
  
  dihedraldata = None
  r = "dihedralfile" 
  if r in ii:
    fil = File(**ii[r])
    dihedraldata = fil.data().textdata()
  ii["dihedraldata"] = dihedraldata
  
  hbonddata = None
  r = "hbondfile" 
  if r in ii:
    fil = File(**ii[r])
    hbonddata = fil.data().textdata()
  ii["hbonddata"] = hbonddata

  for v in ("rdc1", "rdc2", "rdc3", "rdc4", "rdc5"):
    vv = ii[v]
    rdcdata = None
    r = "rdcfile"    
    if r in vv:
      fil = File(**vv[r])
      rdcdata = fil.data().textdata()
    vv["rdcdata"] = rdcdata

  for v in ("dan1", "dan2", "dan3", "dan4", "dan5"):
    vv = ii[v]
    danidata = None
    r = "danifile"
    if r in vv:
      fil = File(**vv[r])
      danidata = fil.data().textdata()
    vv["danidata"] = danidata
  
  return HaddockMultiRunParameters(ii)
}


Define HaddockMultiInterface(HaddockMultiRunParameters i) {  
  ii = i.dict()
  if ii["p"] != None:
    for n in range(len(ii["p"])):
      cur = ii["p"][n]
      if "pdbdata" in cur["pdb"]: 
        v = Data_PDB(cur["pdb"]["pdbdata"])
        cur["pdb"]["pdbfile"] = v.totempfile()            
        cur["pdb"] = PDBInterface.fromdict(cur["pdb"])
  r = "tbldata"
  if r in ii:
    ii["tblfile"] = ii[r].totempfile()
  r = "unambigtbldata"
  if r in ii:
    ii["unambigtblfile"] = ii[r].totempfile()
  
  dihedralfile = None
  r = "dihedraldata" 
  if r in ii:    
    dihedralfile = ii[r].totempfile()
  ii["dihedralfile"] = dihedralfile
  
  hbondfile = None
  r = "hbonddata" 
  if r in ii:    
    hbondfile = ii[r].totempfile()
  ii["hbondfile"] = hbondfile

  for v in ("rdc1", "rdc2", "rdc3", "rdc4", "rdc5"):
    vv = ii[v]
    rdcfile = None
    r = "rdcdata"    
    if r in vv:
      rdcfile = vv[r].totempfile()
    vv["rdcfile"] = rdcfile

  for v in ("dan1", "dan2", "dan3", "dan4", "dan5"):
    vv = ii[v]
    danifile = None
    r = "danidata"
    if r in vv:
      danifile = vv[r].totempfile()
    vv["danifile"] = danifile
  
  return HaddockMultiInterface(ii)
}

Define HaddockRunParameters(HaddockMultiRunParameters i) {
  if i.p == None or len(i.p) < 2: return None
  d = i.dict()
  d["p1"] = i.p[0].dict()
  d["p2"] = i.p[1].dict()
  ret = HaddockRunParameters(d)
  return ret
}

Define HaddockMultiRunParameters(HaddockRunParameters i) {
  d = i.dict()
  d["p"] = [d["p1"], d["p2"]]
  ret = HaddockMultiRunParameters(d)
  return ret
}

Define HaddockMultiRunParameters(HaddockRunParameterInterface i) {
  ret = Spyder.core.fastparsestring(i.params.data().data())
  ret = ret.convert(HaddockMultiRunParameters)
  if i.runname != None: ret.runname = i.runname
  if i.username != None: ret.username = i.username
  if i.password != None: ret.password = i.password
  ret.validate()
  return ret   
}