-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
2811 lines (2692 loc) · 119 KB
/
main.lua
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
990
991
992
993
994
995
996
997
998
999
1000
--[[#Header
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
Thanks and Credits for external functions and ideas goes to Seagat, Rav3n_pl, Tlaloc, Gary Forbis and BitSpawn
see http://www.github.com/Darkknight900/foldit/ for latest version of this script
]]
--#Game vars
iVersion = 1250
iSegmentCount = structure.GetCount()
--#Release
isReleaseVersion = true
strReleaseDate = "29th August, 2012"
iReleaseVersion = 5
--Release#
--Game vars#
--#Settings: default
--#Main default description
bDontUseDialog = false -- false If you dont want to use the dialog everytime set the settings like you wish and set this to true to get no Dialog shown at start
isLocalWiggleEnabled = false -- false do local wiggle and rewiggle
isRebuildingEnabled = false -- false rebuild | see #Rebuilding
isCompressingEnabled = false -- false pull hydrophobic amino acids in different modes then fuze | see #Pull
isStructureRebuildEnabled = false -- false rebuild the protein based on the secondary structures | see #Structed rebuilding
isCurlingEnabled = false -- false Do bond the structures and curl it, try to improve it and get some points
isSnappingEnabled = false -- false should we snap every sidechain to different positions
isFuzingEnabled = false -- false should we fuze | see #Fuzing
isMutatingEnabled = false -- false it's a mutating puzzle so we should mutate to get the best out of every single option see #Mutating
isPredictingEnabled = false -- false reset and predict then the secondary structure based on the amino acids of the protein
--isEvolutionEnabled TODO: IDEA to fully automatic random methods -- rebuilding/pushing/pulling
bExploringWork = false -- false if true then the overall score will be taken if a exploration puzzle, if false then just the stability score is used for the methods
--Main#
--#Working default description
iStartSegment = 1 -- 1 the first segment to work with
iEndSegment = iSegmentCount -- iSegmentCount the last segment to work with
iStartingWalk = 1 -- 1 with how many Segments shall we work - Walker
iEndWalk = 3 -- 3 starting at the current segment + iStartingWalk to segment + iEndWalk
--Working#
--#LocalWiggle
fScoreMustChange = 0.001 -- 0.001 an action tries to get this score, then it will repeat itself | adjust a lower value to get the lws script working on high evo- / solos
--LocalWiggle#
--#Rebuilding
bRebuildWorst = false -- false rebuild worst scored parts of the protein | TODO: Do it some times with table of worst segments from worst to best
iWorstSegmentLength = 4 -- 4
iWorstSegments = 3 -- 3
iRebuildTrys = 10 -- 10 how many different shapes we try to get
bRebuildLoops = false -- false rebuild whole loops | TODO: implement max length of loop rebuild max 5 would be good i think then walk through the structure
bRebuildWalking = false -- false walk through the protein rebuilding every segment with different lengths of rebuilds
iRebuildsTillSave = 1 -- 2 max rebuilds till best rebuild will be chosen
iRebuildStrength = 1 -- 1 the iterations a rebuild will do at default, automatically increased if no change in score
--Rebuilding#
--#Pull default description
iCompressingTrys = 1 -- 1 how often should the pull start over?
fCompressingLoss = 1 -- 1 the score / 100 * fCompressingLoss is the general formula for calculating the points we must lose till we fuze
bCompressingConsiderStructure = true -- true don't band Segments of same structure together if Segments are in one struct (between one helix or sheet)
fCompressingBondingPercentage = 8 -- 8
iCompressingBondingLength = 4
bCompressingFixxedBonding = false -- false
iCompressingFixxedStartSegment = 1 -- 1
iCompressingFixxedEndSegment = 1 -- 1
bCompressingSoftBonding = true
bCompressingFuze = true
bCompressingSoloBonding = false -- false just one segment is used on every method and all Segments are tested
bCompressingLocalBonding = false -- false
--Methods
bCompressingPredictedBonding = true -- true bands are created which pull Segments together based on the size, charge and isoelectric point of the amino acids
bCompressingPredictedLocalBonding = false -- false TODO: check if there are bands
bCompressingEvolutionBonding = false -- true
iCompressingEvolutionRounds = 10
bCompressingEvolutionOnlyBetter = true
bCompressingPushPull = true -- true
bCompressingPull = true -- true hydrophobic Segments are pulled together
-- TODO: First Push out then pull in -- test vs combined push,pull
-- TODO: Band Sheets togehter then work, make Helices stable with inner bonding
bCompressingCenterPushPull = true -- true
bCompressingCenterPull = true -- true hydrophobic Segments are pulled to the center segment
-- TODO: IDEA (ErichVanSterich: 'alternate(pictorial) work') creating herds for 'center' like working
--Pull
--#Structed rebuilding
iStructuredRebuildTillSave = 2 -- 2 same as iRebuildsTillSave at #Rebuilding
iStructuredRebuildStrength = 1 -- 1 same as iRebuildStrength at #Rebuilding
bStructuredRebuildHelix = true -- true should we rebuild helices
bStructuredRebuildSheet = true -- true should we rebuild sheets
bStructuredRebuildFuze = false -- false should we fuze after one rebuild | better let it rebuild then handwork it yourself and then fuze!
--Structed rebuilding#
--#Curler
bCurlingHelix = true -- true
bCurlingSheet = true -- true
--Curler#
--#Snapping
-- TODO: Rework Snapping :/ make use of AT implemention | just sidechain snapping with rotamers need new code
--Snapping#
--#Fuzing
bFuzingBlueFuze = true -- true Use Bluefuse else wiggle out with pink fuze
--Fuzing#
--#Mutating
-- TODO: all mutating things into the mutating category and method
bOptimizeSidechain = true
bRebuildAfterMutating = true
bRebuildInMutatingIgnoreStructures = true -- true TODO: implement completly in rebuilding / combine with loop rebuild
bRebuildInMutatingDeepRebuild = true -- true rebuild length 3,4,5 else just 3
bRebuildTweakWholeRebuild = true -- true All Sidechains get tweaked after rebuild not just the one focusing in the rebuild
bMutateAfterCompressing = false
bMutateSurroundingAfter = true -- true
fClashingForMutating = 0.75 -- 0.75 cl for mutating
--Mutating#
--#Predicting
bPredictingFull = false -- false try to detect the secondary structure between every segment, there can be less loops but the protein become difficult to rebuild
bPredictingAddPrefferedSegments = true -- true
bPredictingCombine = false -- false TODO: Doesn't work at all
bPredictingOtherMethod = true
--Predicting#
--#General
iTimeSecsBetweenReports = 60
iTimeMaxHoursToUse = 0
iTimeMaxMinsToUse = 0
iTimeMaxSecsToUse = 0
bUseTimeOptimization = false
--General#
--Settings#
--#Constants | Game vars
tSaveSlots = {}
for _i = 1, 100 do
tSaveSlots[#tSaveSlots + 1] = _i
end
timeStart = os.time()
iTimeChecked = 0
fEstimatedTimeMod = 1
fProgress = 0
bSpheredFuzing = false
bMutating = false
bTweaking = false
bChanged = true
bStructureChanged = true
bSurroundMutatingCurrently = false
fCompressingBondingPercentageWork = iSegmentCount / 100 * fCompressingBondingPercentage
if current.GetExplorationMultiplier() == 0 then
bIsExploringPuzzle = false
else
bIsExploringPuzzle = true
end
math.randomseed(recipe.GetRandomSeed()*os.time())
--Constants | Game vars#
--#Optimizing
--#General
p = print
reset =
{
puzzle = puzzle.StartOver
}
--General#
--#Bonding
local function _addToSegments(segment1, segment2)
local count = band.AddBetweenSegments(segment1, segment2 --[[integer atomIndex1], [integer atomIndex2]])
if count ~= nil then
bands.info[count] = {3.5, 1, segment1, segment2, true}
return true
else
return false
end
end
local function _addToArea(segment, x, y , length, theta, phi)
local count = band.Add(segment, x, y, length, theta, phi)
if count ~= nil then
bands.info[count] = {3.5, 1, x, y, true}
return true
else
return false
end
end
local function _length(_band, len)
band.SetGoalLength(_band, len)
bands.info[_band][bands.part.length] = len
end
local function _strength(_band, str)
band.SetStrength(_band, str)
bands.info[_band][bands.part.strength] = str
end
local function _disable(_band)
if not _band then
band.DisableAll()
local count = get.bandcount()
for i = 1, count do
bands.info[i][bands.part.enabled] = false
end
else
band.Disable(_band)
bands.info[_band][bands.part.enabled] = false
end
end
local function _enable(_band)
if not _band then
band.EnableAll()
local bandcount = get.bandcount()
for i = 1, bandcount do
bands.info[i][bands.part.enabled] = true
end
else
band.Enable(_band)
bands.info[_band][bands.part.enabled] = true
end
end
local function _delete(_band)
if not _band then
band.DeleteAll()
bands.info = {}
else
band.Delete(_band)
bands.info[_band] = {}
end
end
local function _enabled(_band)
return bands.info[_band][bands.part.enabled]
end
local function _endseg(_band)
return bands.info[_band][bands.part._end]
end
local function _startseg(_band)
return bands.info[_band][bands.part.start]
end
local function _getStrength(_band)
return bands.info[_band][bands.part.strength]
end
local function _getLength(_band)
return bands.info[_band][bands.part.strength]
end
bands =
{ -- Band Mod
addToSegments = _addToSegments,
addToArea = _addToArea,
length = _length,
strength = _strength,
disable = _disable,
enable = _enable,
delete = _delete,
get = {
length = _getLength,
strength= _getStrength,
start = _startseg,
_end = _endseg,
enabled = _enabled
},
info = {},
part = {length = 1, strength = 2, start = 3, _end = 4, enabled = 5}
}
--Bonding#
--#Wiggle
local function _localAll(a)
structure.LocalWiggleAll(a, true, true)
end
local function _localAllBackbone(a)
structure.LocalWiggleAll(a, true, false)
end
local function _localAllSidechains(a)
structure.LocalWiggleAll(a, false, true)
end
local function _localSelected(a)
structure.LocalWiggleSelected(a, true, true)
end
local function _localSelectedBackbone(a)
structure.LocalWiggleSelected(a, true, false)
end
local function _localSelectedSidechains(a)
structure.LocalWiggleSelected(a, false, true)
end
local function _all(a)
structure.WiggleAll(a, true, true)
end
local function _selected(a)
structure.WiggleSelected(a, true, true)
end
local function _allSidechains(a)
structure.WiggleAll(a, false, true)
end
local function _selectedSidechains(a)
structure.WiggleSelected(a, false, true)
end
local function _allBackbone(a)
structure.WiggleAll(a, true, false)
end
local function _selectedBackbone(a)
structure.WiggleSelected(a, true, false)
end
wiggle =
{
shake = structure.ShakeSidechainsAll,
shakeSelected = structure.ShakeSidechainsSelected,
localAll = _localAll,
localAllBackbone = _localAllBackbone,
localAllSidechains = _localAllSidechains,
localSelected = _localSelected,
localSelectedBackbone = _localSelectedBackbone,
localSelectedSidechains = _localSelectedSidechains,
all = _all,
selected = _selected,
allSidechains = _allSidechains,
selectedSidechains = _selectedSidechains,
allBackbone = _allBackbone,
selectedBackbone = _selectedBackbone
}
--Wiggle#
local function _Segments(left, right)
if left < 1 then
left = 1
end
workingSegmentLeft = left
if right ~= nil then
if right > iSegmentCount then
right = iSegmentCount
end
workingSegmentRight = right
else
workingSegmentRight = left
end
get.midTable(left, right)
-- get.rangeTable(left, right)
end
set =
{
Segments = _Segments,
_ss = structure.SetSecondaryStructure,
ss = structure.SetSecondaryStructureSelected,
_aa = structure.SetAminoAcid,
aa = structure.SetAminoAcidSelected,
clashImportance = behavior.SetClashImportance,
wiggleAccuracy = behavior.SetWiggleAccuracy,
shakeAccuracy = behavior.SetShakeAccuracy
}
score =
{
current =
{
energyScore = current.GetEnergyScore,
rankedScore = current.GetScore,
multiplier = current.GetExplorationMultiplier,
segmentScore = current.GetSegmentEnergyScore,
segmentScorePart = current.GetSegmentEnergySubscore,
conditions = current.AreConditionsMet
},
recent =
{
energyScore = recentbest.GetEnergyScore,
rankedScore = recentbest.GetScore,
multiplier = recentbest.GetExplorationMultiplier,
segmentScore = recentbest.GetSegmentEnergyScore,
segmentScorePart = recentbest.GetSegmentEnergySubscore,
conditions = recentbest.AreConditionsMet,
restore = recentbest.Restore,
save = recentbest.Save
},
absolutebest =
{
energyScore = absolutebest.GetEnergyScore,
rankedScore = absolutebest.GetScore,
multiplier = absolutebest.GetExplorationMultiplier,
segmentScore = absolutebest.GetSegmentEnergyScore,
segmentScorePart = absolutebest.GetSegmentEnergySubscore,
conditions = absolutebest.AreConditionsMet,
restore = absolutebest.Restore
},
creditbest =
{
energyScore = creditbest.GetEnergyScore,
rankedScore = creditbest.GetScore,
multiplier = creditbest.GetExplorationMultiplier,
segmentScore = creditbest.GetSegmentEnergyScore,
segmentScorePart = creditbest.GetSegmentEnergySubscore,
conditions = creditbest.AreConditionsMet,
restore = creditbest.Restore
},
}
--#Math
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
--Math#
--Optimizing#
--#Amino
local function _short(segment)
return amino.table[aa[segment]][amino.part.short]
end
local function _abbrev(segment)
return amino.table[aa[segment]][amino.part.abbrev]
end
local function _long(segment)
return amino.table[aa[segment]][amino.part.longname]
end
local function _h(segment)
return amino.table[aa[segment]][amino.part.hydro]
end
local function _hscale(segment)
return amino.table[aa[segment]][amino.part.scale]
end
local function _pref(segment)
return amino.table[aa[segment]][amino.part.pref]
end
local function _mol(segment)
return amino.table[aa[segment]][amino.part.mol]
end
local function _pl(segment)
return amino.table[aa[segment]][amino.part.pl]
end
amino =
{ short = _short,
abbrev = _abbrev,
long = _long,
hydro = _h,
hydroscale = _hscale,
preffered = _pref,
size = _mol,
charge = _pl,
part = {short = 0, abbrev = 1, longname = 2, hydro = 3, scale = 4, pref = 5, mol = 6, pl = 7},
Segments = {'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'y'},
table = {
--short = {abbrev,longname, hydrophobic,scale, pref, mol, pl
['a'] = {'Ala', 'Alanine', true, -1.6, 'H', 89.094, 6.01},
['c'] = {'Cys', 'Cysteine', true, -17, 'E', 121.154, 5.05},
['d'] = {'Asp', 'Aspartic acid', false, 6.7, 'L', 133.1038, 2.85},
['e'] = {'Glu', 'Glutamic acid', false, 8.1, 'H', 147.1307, 3.15},
['f'] = {'Phe', 'Phenylalanine', true, -6.3, 'E', 165.1918, 5.49},
['g'] = {'Gly', 'Glycine', true, 1.7, 'L', 75.0671, 6.06},
['h'] = {'His', 'Histidine', false, -5.6, nil, 155.1563, 7.60},
['i'] = {'Ile', 'Isoleucine', true, -2.4, 'E', 131.1746, 6.05},
['k'] = {'Lys', 'Lysine', false, 6.5, 'H', 146.1893, 9.60},
['l'] = {'Leu', 'Leucine', true, 1, 'H', 131.1746, 6.01},
['m'] = {'Met', 'Methionine', true, 3.4, 'H', 149.2078, 5.74},
['n'] = {'Asn', 'Asparagine', false, 8.9, 'L', 132.119, 5.41},
['p'] = {'Pro', 'Proline', true, -0.2, 'L', 115.1319, 6.30},
['q'] = {'Gln', 'Glutamine', false, 9.7, 'H', 146.1459, 5.65},
['r'] = {'Arg', 'Arginine', false, 9.8, 'H', 174.2027, 10.76},
['s'] = {'Ser', 'Serine', false, 3.7, 'L', 105.0934, 5.68},
['t'] = {'Thr', 'Threonine', false, 2.7, 'E', 119.1203, 5.60},
['v'] = {'Val', 'Valine', true, -2.9, 'E', 117.1478, 6.00},
['w'] = {'Trp', 'Tryptophan', true, -9.1, 'E', 204.2284, 5.89},
['y'] = {'Tyr', 'Tyrosine', true, -5.1, 'E', 181.1912, 5.64}
}
}
--#Calculations
local function _calc()
local tCalculatedStrength = {}
local i
for i = 1, #amino.Segments do
tCalculatedStrength[amino.Segments[i]] = {}
end
tCalculatedStrength['a']['a'] = 32.37285621091;tCalculatedStrength['a']['c'] = 27.1852;tCalculatedStrength['a']['d'] = 27.7753;tCalculatedStrength['a']['e'] = 50.4563;tCalculatedStrength['a']['f'] = 20.3536;tCalculatedStrength['a']['g'] = 51.6725;tCalculatedStrength['a']['h'] = 49.4786;tCalculatedStrength['a']['i'] = 27.7753;tCalculatedStrength['a']['k'] = 8.37506;tCalculatedStrength['a']['l'] = 51.6725;tCalculatedStrength['a']['m'] = 51.6725;tCalculatedStrength['a']['n'] = 20.3536;tCalculatedStrength['a']['p'] = 20.3536;tCalculatedStrength['a']['q'] = 34.6395;tCalculatedStrength['a']['r'] = 27.7753;tCalculatedStrength['a']['s'] = 50.243;tCalculatedStrength['a']['t'] = -7.50419;tCalculatedStrength['a']['v'] = -11.1915;tCalculatedStrength['a']['w'] = 20.3536;tCalculatedStrength['a']['y'] = 51.6725;tCalculatedStrength['c']['a'] = 27.1852;tCalculatedStrength['c']['c'] = 48.8752;tCalculatedStrength['c']['d'] = 41.8555;tCalculatedStrength['c']['e'] = 26.6356;tCalculatedStrength['c']['f'] = 43.066;tCalculatedStrength['c']['g'] = 29.8568;tCalculatedStrength['c']['h'] = 36.5647;tCalculatedStrength['c']['i'] = 41.8555;tCalculatedStrength['c']['k'] = 31.0495;tCalculatedStrength['c']['l'] = 29.8568;tCalculatedStrength['c']['m'] = 29.8568;tCalculatedStrength['c']['n'] = 43.066;tCalculatedStrength['c']['p'] = 43.066;tCalculatedStrength['c']['q'] = 53.9513;tCalculatedStrength['c']['r'] = 41.8555;tCalculatedStrength['c']['s'] = 31.249;tCalculatedStrength['c']['t'] = 13.807;tCalculatedStrength['c']['v'] = 17.5416;tCalculatedStrength['c']['w'] = 43.066;tCalculatedStrength['c']['y'] = 29.8568;tCalculatedStrength['d']['a'] = 27.7753;tCalculatedStrength['d']['c'] = 41.8555;tCalculatedStrength['d']['d'] = 45.8231;tCalculatedStrength['d']['e'] = 42.1045;tCalculatedStrength['d']['f'] = 35.2602;tCalculatedStrength['d']['g'] = 52.6048;tCalculatedStrength['d']['h'] = 60.1862;tCalculatedStrength['d']['i'] = 45.8231;tCalculatedStrength['d']['k'] = 23.2728;tCalculatedStrength['d']['l'] = 52.6048;tCalculatedStrength['d']['m'] = 52.6048;tCalculatedStrength['d']['n'] = 35.2602;tCalculatedStrength['d']['p'] = 35.2602;tCalculatedStrength['d']['q'] = 49.2573;tCalculatedStrength['d']['r'] = 45.8231;tCalculatedStrength['d']['s'] = 47.4172;tCalculatedStrength['d']['t'] = 7.0786;tCalculatedStrength['d']['v'] = 5.10629;tCalculatedStrength['d']['w'] = 35.2602;tCalculatedStrength['d']['y'] = 52.6048;tCalculatedStrength['e']['a'] = 50.4563;tCalculatedStrength['e']['c'] = 26.6356;tCalculatedStrength['e']['d'] = 42.1045;tCalculatedStrength['e']['e'] = 49.5598;tCalculatedStrength['e']['f'] = 20.8448;tCalculatedStrength['e']['g'] = 41.1395;tCalculatedStrength['e']['h'] = 37.7893;tCalculatedStrength['e']['i'] = 42.1045;tCalculatedStrength['e']['k'] = 8.8277;tCalculatedStrength['e']['l'] = 41.1395;tCalculatedStrength['e']['m'] = 41.1395;tCalculatedStrength['e']['n'] = 20.8448;tCalculatedStrength['e']['p'] = 20.8448;tCalculatedStrength['e']['q'] = 33.8587;tCalculatedStrength['e']['r'] = 42.1045;tCalculatedStrength['e']['s'] = 48.4217;tCalculatedStrength['e']['t'] = -8.4392;tCalculatedStrength['e']['v'] = -4.57155;tCalculatedStrength['e']['w'] = 20.8448;tCalculatedStrength['e']['y'] = 41.1395;tCalculatedStrength['f']['a'] = 20.3536;tCalculatedStrength['f']['c'] = 43.066;tCalculatedStrength['f']['d'] = 35.2602;tCalculatedStrength['f']['e'] = 20.8448;tCalculatedStrength['f']['f'] = 54.409;tCalculatedStrength['f']['g'] = 24.5751;tCalculatedStrength['f']['h'] = 31.344;tCalculatedStrength['f']['i'] = 35.2602;tCalculatedStrength['f']['k'] = 42.395;tCalculatedStrength['f']['l'] = 24.5751;tCalculatedStrength['f']['m'] = 24.5751;tCalculatedStrength['f']['n'] = 54.409;tCalculatedStrength['f']['p'] = 54.409;tCalculatedStrength['f']['q'] = 48.1544;tCalculatedStrength['f']['r'] = 35.2602;tCalculatedStrength['f']['s'] = 25.507;tCalculatedStrength['f']['t'] = 25.2258;tCalculatedStrength['f']['v'] = 28.5612;tCalculatedStrength['f']['w'] = 54.409;tCalculatedStrength['f']['y'] = 24.5751;tCalculatedStrength['g']['a'] = 51.6725;tCalculatedStrength['g']['c'] = 29.8568;tCalculatedStrength['g']['d'] = 52.6048;tCalculatedStrength['g']['e'] = 41.1395;tCalculatedStrength['g']['f'] = 24.5751;tCalculatedStrength['g']['g'] = 39.4764;tCalculatedStrength['g']['h'] = 35.5605;tCalculatedStrength['g']['i'] = 52.6048;tCalculatedStrength['g']['k'] = 12.5391;tCalculatedStrength['g']['l'] = 39.4764;tCalculatedStrength['g']['m'] = 39.4764;tCalculatedStrength['g']['n'] = 24.5751;tCalculatedStrength['g']['p'] = 24.5751;tCalculatedStrength['g']['q'] = 36.9667;tCalculatedStrength['g']['r'] = 52.6048;tCalculatedStrength['g']['s'] = 45.2846;tCalculatedStrength['g']['t'] = -5.40665;tCalculatedStrength['g']['v'] = 2.1571;tCalculatedStrength['g']['w'] = 24.5751;tCalculatedStrength['g']['y'] = 39.4764;tCalculatedStrength['h']['a'] = 49.4786;tCalculatedStrength['h']['c'] = 36.5647;tCalculatedStrength['h']['d'] = 60.1862;tCalculatedStrength['h']['e'] = 37.7893;tCalculatedStrength['h']['f'] = 31.344;tCalculatedStrength['h']['g'] = 35.5605;tCalculatedStrength['h']['h'] = 41.6144;tCalculatedStrength['h']['i'] = 60.1862;tCalculatedStrength['h']['k'] = 19.3058;tCalculatedStrength['h']['l'] = 35.5605;tCalculatedStrength['h']['m'] = 35.5605;tCalculatedStrength['h']['n'] = 31.344;tCalculatedStrength['h']['p'] = 31.344;tCalculatedStrength['h']['q'] = 43.661;tCalculatedStrength['h']['r'] = 60.1862;tCalculatedStrength['h']['s'] = 41.8801;tCalculatedStrength['h']['t'] = 1.2786;tCalculatedStrength['h']['v'] = 9.28598;tCalculatedStrength['h']['w'] = 31.344;tCalculatedStrength['h']['y'] = 35.5605;tCalculatedStrength['i']['a'] = 27.7753;tCalculatedStrength['i']['c'] = 41.8555;tCalculatedStrength['i']['d'] = 45.8231;tCalculatedStrength['i']['e'] = 42.1045;tCalculatedStrength['i']['f'] = 35.2602;tCalculatedStrength['i']['g'] = 52.6048;tCalculatedStrength['i']['h'] = 60.1862;tCalculatedStrength['i']['i'] = 45.8231;tCalculatedStrength['i']['k'] = 23.2728;tCalculatedStrength['i']['l'] = 52.6048;tCalculatedStrength['i']['m'] = 52.6048;tCalculatedStrength['i']['n'] = 35.2602;tCalculatedStrength['i']['p'] = 35.2602;tCalculatedStrength['i']['q'] = 49.2573;tCalculatedStrength['i']['r'] = 45.8231;tCalculatedStrength['i']['s'] = 47.4172;tCalculatedStrength['i']['t'] = 7.0786;tCalculatedStrength['i']['v'] = 5.10629;tCalculatedStrength['i']['w'] = 35.2602;tCalculatedStrength['i']['y'] = 52.6048;tCalculatedStrength['k']['a'] = 8.37506;tCalculatedStrength['k']['c'] = 31.0495;tCalculatedStrength['k']['d'] = 23.2728;tCalculatedStrength['k']['e'] = 8.8277;tCalculatedStrength['k']['f'] = 42.395;tCalculatedStrength['k']['g'] = 12.5391;tCalculatedStrength['k']['h'] = 19.3058;tCalculatedStrength['k']['i'] = 23.2728;tCalculatedStrength['k']['k'] = 58.3427;tCalculatedStrength['k']['l'] = 12.5391;tCalculatedStrength['k']['m'] = 12.5391;tCalculatedStrength['k']['n'] = 42.395;tCalculatedStrength['k']['p'] = 42.395;tCalculatedStrength['k']['q'] = 36.1375;tCalculatedStrength['k']['r'] = 23.2728;tCalculatedStrength['k']['s'] = 13.4887;tCalculatedStrength['k']['t'] = 41.1708;tCalculatedStrength['k']['v'] = 44.521;tCalculatedStrength['k']['w'] = 42.395;tCalculatedStrength['k']['y'] = 12.5391;tCalculatedStrength['l']['a'] = 51.6725;tCalculatedStrength['l']['c'] = 29.8568;tCalculatedStrength['l']['d'] = 52.6048;tCalculatedStrength['l']['e'] = 41.1395;tCalculatedStrength['l']['f'] = 24.5751;tCalculatedStrength['l']['g'] = 39.4764;tCalculatedStrength['l']['h'] = 35.5605;tCalculatedStrength['l']['i'] = 52.6048;tCalculatedStrength['l']['k'] = 12.5391;tCalculatedStrength['l']['l'] = 39.4764;tCalculatedStrength['l']['m'] = 39.4764;tCalculatedStrength['l']['n'] = 24.5751;tCalculatedStrength['l']['p'] = 24.5751;tCalculatedStrength['l']['q'] = 36.9667;tCalculatedStrength['l']['r'] = 52.6048;tCalculatedStrength['l']['s'] = 45.2846;tCalculatedStrength['l']['t'] = -5.40665;tCalculatedStrength['l']['v'] = 2.1571;tCalculatedStrength['l']['w'] = 24.5751;tCalculatedStrength['l']['y'] = 39.4764;tCalculatedStrength['m']['a'] = 51.6725;tCalculatedStrength['m']['c'] = 29.8568;tCalculatedStrength['m']['d'] = 52.6048;tCalculatedStrength['m']['e'] = 41.1395;tCalculatedStrength['m']['f'] = 24.5751;tCalculatedStrength['m']['g'] = 39.4764;tCalculatedStrength['m']['h'] = 35.5605;tCalculatedStrength['m']['i'] = 52.6048;tCalculatedStrength['m']['k'] = 12.5391;tCalculatedStrength['m']['l'] = 39.4764;tCalculatedStrength['m']['m'] = 39.4764;tCalculatedStrength['m']['n'] = 24.5751;tCalculatedStrength['m']['p'] = 24.5751;tCalculatedStrength['m']['q'] = 36.9667;tCalculatedStrength['m']['r'] = 52.6048;tCalculatedStrength['m']['s'] = 45.2846;tCalculatedStrength['m']['t'] = -5.40665;tCalculatedStrength['m']['v'] = 2.1571;tCalculatedStrength['m']['w'] = 24.5751;tCalculatedStrength['m']['y'] = 39.4764;tCalculatedStrength['n']['a'] = 20.3536;tCalculatedStrength['n']['c'] = 43.066;tCalculatedStrength['n']['d'] = 35.2602;tCalculatedStrength['n']['e'] = 20.8448;tCalculatedStrength['n']['f'] = 54.409;tCalculatedStrength['n']['g'] = 24.5751;tCalculatedStrength['n']['h'] = 31.344;tCalculatedStrength['n']['i'] = 35.2602;tCalculatedStrength['n']['k'] = 42.395;tCalculatedStrength['n']['l'] = 24.5751;tCalculatedStrength['n']['m'] = 24.5751;tCalculatedStrength['n']['n'] = 54.409;tCalculatedStrength['n']['p'] = 54.409;tCalculatedStrength['n']['q'] = 48.1544;tCalculatedStrength['n']['r'] = 35.2602;tCalculatedStrength['n']['s'] = 25.507;tCalculatedStrength['n']['t'] = 25.2258;tCalculatedStrength['n']['v'] = 28.5612;tCalculatedStrength['n']['w'] = 54.409;tCalculatedStrength['n']['y'] = 24.5751;tCalculatedStrength['p']['a'] = 20.3536;tCalculatedStrength['p']['c'] = 43.066;tCalculatedStrength['p']['d'] = 35.2602;tCalculatedStrength['p']['e'] = 20.8448;tCalculatedStrength['p']['f'] = 54.409;tCalculatedStrength['p']['g'] = 24.5751;tCalculatedStrength['p']['h'] = 31.344;tCalculatedStrength['p']['i'] = 35.2602;tCalculatedStrength['p']['k'] = 42.395;tCalculatedStrength['p']['l'] = 24.5751;tCalculatedStrength['p']['m'] = 24.5751;tCalculatedStrength['p']['n'] = 54.409;tCalculatedStrength['p']['p'] = 54.409;tCalculatedStrength['p']['q'] = 48.1544;tCalculatedStrength['p']['r'] = 35.2602;tCalculatedStrength['p']['s'] = 25.507;tCalculatedStrength['p']['t'] = 25.2258;tCalculatedStrength['p']['v'] = 28.5612;tCalculatedStrength['p']['w'] = 54.409;tCalculatedStrength['p']['y'] = 24.5751;tCalculatedStrength['q']['a'] = 34.6395;tCalculatedStrength['q']['c'] = 53.9513;tCalculatedStrength['q']['d'] = 49.2573;tCalculatedStrength['q']['e'] = 33.8587;tCalculatedStrength['q']['f'] = 48.1544;tCalculatedStrength['q']['g'] = 36.9667;tCalculatedStrength['q']['h'] = 43.661;tCalculatedStrength['q']['i'] = 49.2573;tCalculatedStrength['q']['k'] = 36.1375;tCalculatedStrength['q']['l'] = 36.9667;tCalculatedStrength['q']['m'] = 36.9667;tCalculatedStrength['q']['n'] = 48.1544;tCalculatedStrength['q']['p'] = 48.1544;tCalculatedStrength['q']['q'] = 61.1758;tCalculatedStrength['q']['r'] = 49.2573;tCalculatedStrength['q']['s'] = 38.4618;tCalculatedStrength['q']['t'] = 18.8787;tCalculatedStrength['q']['v'] = 22.702;tCalculatedStrength['q']['w'] = 48.1544;tCalculatedStrength['q']['y'] = 36.9667;tCalculatedStrength['r']['a'] = 27.7753;tCalculatedStrength['r']['c'] = 41.8555;tCalculatedStrength['r']['d'] = 45.8231;tCalculatedStrength['r']['e'] = 42.1045;tCalculatedStrength['r']['f'] = 35.2602;tCalculatedStrength['r']['g'] = 52.6048;tCalculatedStrength['r']['h'] = 60.1862;tCalculatedStrength['r']['i'] = 45.8231;tCalculatedStrength['r']['k'] = 23.2728;tCalculatedStrength['r']['l'] = 52.6048;tCalculatedStrength['r']['m'] = 52.6048;tCalculatedStrength['r']['n'] = 35.2602;tCalculatedStrength['r']['p'] = 35.2602;tCalculatedStrength['r']['q'] = 49.2573;tCalculatedStrength['r']['r'] = 45.8231;tCalculatedStrength['r']['s'] = 47.4172;tCalculatedStrength['r']['t'] = 7.0786;tCalculatedStrength['r']['v'] = 5.10629;tCalculatedStrength['r']['w'] = 35.2602;tCalculatedStrength['r']['y'] = 52.6048;tCalculatedStrength['s']['a'] = 50.243;tCalculatedStrength['s']['c'] = 31.249;tCalculatedStrength['s']['d'] = 47.4172;tCalculatedStrength['s']['e'] = 48.4217;tCalculatedStrength['s']['f'] = 25.507;tCalculatedStrength['s']['g'] = 45.2846;tCalculatedStrength['s']['h'] = 41.8801;tCalculatedStrength['s']['i'] = 47.4172;tCalculatedStrength['s']['k'] = 13.4887;tCalculatedStrength['s']['l'] = 45.2846;tCalculatedStrength['s']['m'] = 45.2846;tCalculatedStrength['s']['n'] = 25.507;tCalculatedStrength['s']['p'] = 25.507;tCalculatedStrength['s']['q'] = 38.4618;tCalculatedStrength['s']['r'] = 47.4172;tCalculatedStrength['s']['s'] = 52.9759;tCalculatedStrength['s']['t'] = -3.84333;tCalculatedStrength['s']['v'] = 0.379152;tCalculatedStrength['s']['w'] = 25.507;tCalculatedStrength['s']['y'] = 45.2846;tCalculatedStrength['t']['a'] = -7.50419;tCalculatedStrength['t']['c'] = 13.807;tCalculatedStrength['t']['d'] = 7.0786;tCalculatedStrength['t']['e'] = -8.4392;tCalculatedStrength['t']['f'] = 25.2258;tCalculatedStrength['t']['g'] = -5.40665;tCalculatedStrength['t']['h'] = 1.2786;tCalculatedStrength['t']['i'] = 7.0786;tCalculatedStrength['t']['k'] = 41.1708;tCalculatedStrength['t']['l'] = -5.40665;tCalculatedStrength['t']['m'] = -5.40665;tCalculatedStrength['t']['n'] = 25.2258;tCalculatedStrength['t']['p'] = 25.2258;tCalculatedStrength['t']['q'] = 18.8787;tCalculatedStrength['t']['r'] = 7.0786;tCalculatedStrength['t']['s'] = -3.84333;tCalculatedStrength['t']['t'] = 39.6748;tCalculatedStrength['t']['v'] = 43.5572;tCalculatedStrength['t']['w'] = 25.2258;tCalculatedStrength['t']['y'] = -5.40665;tCalculatedStrength['v']['a'] = -11.1915;tCalculatedStrength['v']['c'] = 17.5416;tCalculatedStrength['v']['d'] = 5.10629;tCalculatedStrength['v']['e'] = -4.57155;tCalculatedStrength['v']['f'] = 28.5612;tCalculatedStrength['v']['g'] = 2.1571;tCalculatedStrength['v']['h'] = 9.28598;tCalculatedStrength['v']['i'] = 5.10629;tCalculatedStrength['v']['k'] = 44.521;tCalculatedStrength['v']['l'] = 2.1571;tCalculatedStrength['v']['m'] = 2.1571;tCalculatedStrength['v']['n'] = 28.5612;tCalculatedStrength['v']['p'] = 28.5612;tCalculatedStrength['v']['q'] = 22.702;tCalculatedStrength['v']['r'] = 5.10629;tCalculatedStrength['v']['s'] = 0.379152;tCalculatedStrength['v']['t'] = 43.5572;tCalculatedStrength['v']['v'] = 48.1268;tCalculatedStrength['v']['w'] = 28.5612;tCalculatedStrength['v']['y'] = 2.1571;tCalculatedStrength['w']['a'] = 20.3536;tCalculatedStrength['w']['c'] = 43.066;tCalculatedStrength['w']['d'] = 35.2602;tCalculatedStrength['w']['e'] = 20.8448;tCalculatedStrength['w']['f'] = 54.409;tCalculatedStrength['w']['g'] = 24.5751;tCalculatedStrength['w']['h'] = 31.344;tCalculatedStrength['w']['i'] = 35.2602;tCalculatedStrength['w']['k'] = 42.395;tCalculatedStrength['w']['l'] = 24.5751;tCalculatedStrength['w']['m'] = 24.5751;tCalculatedStrength['w']['n'] = 54.409;tCalculatedStrength['w']['p'] = 54.409;tCalculatedStrength['w']['q'] = 48.1544;tCalculatedStrength['w']['r'] = 35.2602;tCalculatedStrength['w']['s'] = 25.507;tCalculatedStrength['w']['t'] = 25.2258;tCalculatedStrength['w']['v'] = 28.5612;tCalculatedStrength['w']['w'] = 54.409;tCalculatedStrength['w']['y'] = 24.5751;tCalculatedStrength['y']['a'] = 51.6725;tCalculatedStrength['y']['c'] = 29.8568;tCalculatedStrength['y']['d'] = 52.6048;tCalculatedStrength['y']['e'] = 41.1395;tCalculatedStrength['y']['f'] = 24.5751;tCalculatedStrength['y']['g'] = 39.4764;tCalculatedStrength['y']['h'] = 35.5605;tCalculatedStrength['y']['i'] = 52.6048;tCalculatedStrength['y']['k'] = 12.5391;tCalculatedStrength['y']['l'] = 39.4764;tCalculatedStrength['y']['m'] = 39.4764;tCalculatedStrength['y']['n'] = 24.5751;tCalculatedStrength['y']['p'] = 24.5751;tCalculatedStrength['y']['q'] = 36.9667;tCalculatedStrength['y']['r'] = 52.6048;tCalculatedStrength['y']['s'] = 45.2846;tCalculatedStrength['y']['t'] = -5.40665;tCalculatedStrength['y']['v'] = 2.1571;tCalculatedStrength['y']['w'] = 24.5751;tCalculatedStrength['y']['y'] = 39.4764
--Precalculated Table#
local ii
tPredictedStrength = {}
for i = 1, iSegmentCount do
tPredictedStrength[i] = {}
for ii = i + 1, iSegmentCount do
tPredictedStrength[i][ii] = tCalculatedStrength[aa[i]][aa[ii]]
end -- for ii
end -- for i
end -- function
calc =
{ run = _calc
}
--Calculations#
--Amino#
--#External functions
report =
{ status = recipe.ReportStatus,
start = recipe.SectionStart,
stop = recipe.SectionEnd
}
--#Saveslot manager -- Credits to Tlaloc
local function _release(slot)
tSaveSlots[#tSaveSlots + 1] = slot
end
local function _request()
local slot = tSaveSlots[#tSaveSlots]
tSaveSlots[#tSaveSlots] = nil
return slot
end
QuickSave = save.Quicksave
QuickLoad = save.Quickload
saveSlot =
{ release = _release,
request = _request,
}
--Saveslot manager#
--External functions#
--#Internal functions
--#Getters
local function _distances()
local i
local j
if bChanged then
tDistances = {}
for i = 1, iSegmentCount - 1 do
tDistances[i] = {}
for j = i + 1, iSegmentCount do
tDistances[i][j] = get.distance(i, j)
end -- for j
end -- for i
bChanged = false
end -- if bChanged
end -- function
local function _sphere(segment, radius)
local tSphere = {}
check.distances()
local i
local temp
local temp2
for i = 1, iSegmentCount do
if segment ~= i then
temp2 = segment
temp = i
if temp > segment then
temp, temp2 = segment, i
end -- if temp
if tDistances[temp][temp2] <= radius and not selection.IsSelected(i) then
tSphere[#tSphere + 1] = i
end -- if tDistances
end -- if segment
end -- for i
return tSphere
end -- function
local function _center()
local minDistance = 10000
local distance
local indexCenter
check.distances()
for i = 1, iSegmentCount do
distance = 0
for j = 1, iSegmentCount do
if i ~= j then
local x = i
local y = j
if x > y then
x, y = y, x
end -- if x
distance = distance + tDistances[x][y]
end -- if i ~= j
end -- for j
if distance < minDistance then
minDistance = distance
indexCenter = i
end -- if distance
end -- for i
return indexCenter
end -- function
local function _increase(sectionEnd, slot, step)
if step then
if sectionEnd < step then
QuickLoad(slot)
return
end -- if sc2
end -- if step
if sectionEnd > 0 then
if slot == saveSlotOverall then
local currentScore = get.score()
if currentScore > fMaxScore then
QuickSave(slot)
p("Gain: " .. currentScore - fMaxScore)
fMaxScore = currentScore
p("==NEW=MAX=" .. fMaxScore .. "==")
else -- if sc2
QuickLoad(slot)
end -- if sc2
else
QuickSave(slot)
end -- if slot
return true
else -- if sc2 >
QuickLoad(slot)
return false
end -- if sc2 >
end -- function
local function _mutable()
mutable={}
for i = 1, get.segcount() do
if structure.IsMutable(i) then
mutable[#mutable+1]=i
end
end
end
local function _score()
local s = 0
if not bExploringWork then
s = score.current.rankedScore()
else -- if
s = score.current.energyScore()
end -- if
return s
end -- function
--#Hydrocheck
local function _hydro(s)
if s then
hydro[s] = get.hydro(s)
else -- if
check.aa()
end -- if
end -- function
--Hydrocheck#
--#Ligand Check
local function _ligand()
if ss[iSegmentCount] == 'M' then
iSegmentCount = iSegmentCount - 1
if iEndSegment == iSegmentCount + 1 then
iEndSegment = iSegmentCount
end -- if iEndSegment
end -- if get.ss
end -- function
--Ligand Check#
--#Structurecheck
local function _ss(s)
if s then
ss[s] = get.aa(s)
else -- if
ss = {}
for i = 1, iSegmentCount do
ss[i] = get.ss(i)
end -- for i
end -- if s
end -- function
local function _aa(s)
if s then
aa[s] = get.aa(s)
else -- if
aa = {}
hydro = {}
for i = 1, iSegmentCount do
aa[i] = get.aa(i)
hydro[i] = amino.hydro(i)
end -- for i
end -- if
end -- function
local function _struct()
if bStructureChanged then
check.ss()
local helix
local sheet
local loop
he = {}
sh = {}
lo = {}
for i = 1, iSegmentCount do
if ss[i] == "H" and not helix then
helix = true
sheet = false
loop = false
he[#he + 1] = {}
elseif ss[i] == "E" and not sheet then
sheet = true
loop = false
helix = false
sh[#sh + 1] = {}
elseif ss[i] == "L" and not loop then
loop = true
helix = false
sheet = false
lo[#lo + 1] = {}
end -- if ss
if helix then
if ss[i] == "H" then
he[#he][#he[#he]+1] = i
else -- if ss
helix = false
end -- if ss
end -- if helix
if sheet then
if ss[i] == "E" then
sh[#sh][#sh[#sh]+1] = i
else -- if ss
sheet = false
end -- if ss
end -- if sheet
if loop then
if ss[i] == "L" then
lo[#lo][#lo[#lo]+1] = i
else -- if ss
loop = false
end -- if ss
end -- if loop
end -- for
bStructureChanged = false
end -- if bStructureChanged
end -- function
local function _same(a, b)
check.struct()
local bool
local a_s
local b_s
if ss[a] == "H" and ss[b] == "H" then
for i = 1, #he do
for ii = he[i][1], he[i][#he[i]] do
if a == ii then
a_s = i
end -- if a
if b == ii then
b_s = i
end -- if b
if a_s == b_s and a_s and b_s then
return false
end -- if a_s
end -- for ii
end -- for i
elseif ss[a] == "E" and ss[b] == "E" then
for i = 1, #sh do
for ii = sh[i][1], sh[i][#sh[i]] do
if a == ii then
a_s = sh[i][1]
end -- if a
if b == ii then
b_s = sh[i][1]
end -- if b
if b_s == a_s and a_s and b_s then
return false
end -- if b_s
end -- for ii
end -- for i
else -- if / elseif
return true
end -- if ss[a]
end -- function
local function _checksame(a, b)
if bCompressingConsiderStructure then
return check.sameStruct(a, b)
end
return true
end
--Structurecheck#
local function _segmentScores()
tSegmentScores = {}
local i
for i = 1, iSegmentCount do
tSegmentScores[i] = score.current.segmentScore(i)
end
end
local function _worst(len, nr)
local i
local ii
if tSegmentScores == nil then
get.segmentScores()
for ii = 1, iSegmentCount - len + 1 do
for i = 1, len - 1 do
tSegmentScores[ii] = tSegmentScores[ii] + tSegmentScores[ii + i]
end -- for i
end -- for ii
table.sort(tSegmentScores)
end
set.Segments(tSegmentScores[nr], tSegmentScores[nr] + len - 1)
end
local function _formatTime(secs)
local mins = 0
local hours = 0
while secs > 59 do
mins = mins + 1
secs = secs - 60
if mins > 59 then
hours = hours + 1
mins = mins - 60
end -- if secs
end -- while secs
if hours < 10 then
hours = "0"..hours
end -- if hours
if mins < 10 then
mins = "0"..mins
end -- if mins
if secs < 10 then
secs = "0"..secs
end -- if secs
return (hours..":" .. mins .. ":" .. secs)
end -- function
local function _time()
local currentTime = os.time()
local bool = true
if currentTime - timeStart > (iTimeSecsBetweenReports + iTimeChecked * iTimeSecsBetweenReports) then
iTimeChecked = iTimeChecked + 1
local elapsedSecs = currentTime - timeStart
estimatedTime = math.floor(elapsedSecs * fEstimatedTimeMod + 0.5)
p("Time elapsed: " .. get.formattedTime(elapsedSecs) .. "; Recipe finished ".. fProgress .. "%")
if estimatedTime ~= elapsedSecs then
p("approx. time till that recipe is finished: " .. get.formattedTime(estimatedTime))
p(os.date("Recipe will be approx. finished: %a, %c", estimatedTime + currentTime))
if bUseTimeOptimization then
local iTimeMax = 0
if not bUseTimeMaxDate then
iTimeMax = iTimeMaxHoursToUse * 60 * 60 + iTimeMaxMinsToUse * 60 + iTimeMaxSecsToUse
else
iTimeMax = os.time{year = iTimeMaxDateYear, month = iTimeMaxDateMonth, day = iTimeMaxDateDay, hour = iTimeMaxDateHour, min = iTimeMaxDateMin ,sec = iTimeMaxDateSec}
end
if iTimeMax ~= 0 then
if estimatedTime > iTimeMax then
if isLocalWiggleEnabled or (isRebuildingEnabled and bRebuildWalking) then
if iStartingWalk < iEndWalk then
iEndWalk = iEndWalk - 1
p("Reduced end walking range to ".. iEndWalk)
bool = false
elseif iStartingWalk >= iEndWalk and iStartingWalk > 0 then
iStartingWalk = iStartingWalk - 1
p("Reduced start walking range to ".. iStartingWalk)
bool = false
elseif iStartingWalk == iEndWalk and iStartingWalk == 0 then
if iStartSegment < iEndSegment then
iEndSegment = iEndSegment - 1
p("Reduced end seg to ".. iEndSegment)
bool = false
end
end
elseif isRebuildingEnabled then
if bRebuildLoops then
lo[#lo] = nil
p("deleted ".. #lo - 1 ..". loop")
bool = false
elseif bRebuildWalking then
iWorstSegments = iWorstSegments - 1
p("reduced worst rebuilds to ".. iWorstSegments)
bool = false
end
end
end
end
end
else
p("calculating approx. finish of this recipe")
end
p("==MAX SCORE=" .. fMaxScore .. "==")
end
return bool
end
local function _progress(start1, end1, iter1, vari1, start2, end2, iter2, vari2)
if start2 then
if iter1 == -1 then
if iter2 == 1 then
local done = (vari2 + (start1 - vari1) * end2)
local toDo = (end2 - vari2 + end2 * (vari1 - 1))
fEstimatedTimeMod = toDo / done
fProgress = round(done / (start1 * end2) * 100, 3)
elseif iter2 == -1 then
end
elseif iter1 == 1 then
if iter2 == 1 then
local done = (vari1 - start1) * (end2 - start2) + vari2 - start2 + 1
local toDo = (end2 - vari2) + (end1 - vari1) * (end2 - start2)
fEstimatedTimeMod = toDo / done
fProgress = round(done / (end1 - start1) * (end2 - start2) * 100, 3)
get.progress(iStartSegment, iEndSegment, 1, i, iStartingWalk, iEndWalk, 1, ii)
end
end -- if iter1
else -- if start2
if iter1 == 1 then
fEstimatedTimeMod = (end1 - vari1) / vari1
fProgress = round(vari1 / end1 * 100, 3)
end -- if iter1
end -- if start2
if not check.time() then
return get.progress(start1, end1, iter1, vari1, start2, end2, iter2, vari2)
end
end -- function
local function _midTable(left, right)
while right > left do
right = right - 1
left = left + 1
end
tWorkingMiddleSegments = {}
if right == left then
tWorkingMiddleSegments[1] = right
end
end
local function _rangeTable(left, right)
local i
tWorkingSegments = {}
for i = left, right do
tWorkingSegments[#tWorkingSegments+1] = i
end
end
check =
{ distances = _distances,
increase = _increase,
mutable = _mutable,
ss = _ss,
aa = _aa,
ligand = _ligand,
hydro = _hydro,
struct = _struct,
sameStruct = _same,
time = _time,
same = _checksame
}
get =
{ midTable = _midTable,
rangeTable = _rangeTable,
mid = _mid,
formattedTime = _formatTime,
sphere = _sphere,
center = _center,
Segments = _Segments,
score = _score,
segmentScores = _segmentScores,
worst = _worst,
progress = _progress,
distance = structure.GetDistance,
ss = structure.GetSecondaryStructure,
aa = structure.GetAminoAcid,
segcount = structure.GetCount,
bandcount = band.GetCount,
hydro = structure.IsHydrophobic,
snapcount = rotamer.GetCount,
clashImportance = behavior.GetClashImportance,
wiggleAccuracy = behavior.GetWiggleAccuracy,
shakeAccuracy = behavior.GetShakeAccuracy
}
--Getters#
--#Doers
local function _freeze(f)
if f == "b" then
freeze.FreezeSelected(true, false)
elseif f == "s" then
freeze.FreezeSelected(false, true)
else -- if
freeze.FreezeSelected(true, true)
end -- if
end
do_ =
{ freeze = _freeze,
rebuild = structure.RebuildSelected,
snap = rotamer.SetRotamer,
unfreeze = freeze.UnfreezeAll
}
--Doers#
--#Fuzing
local function _loss(option, cl1, cl2)
if not bTweaking then score.recent.save() end