Icon representing a recipe

Recipe: Trim Tool Test

created by zeroblue

Profile


Name
Trim Tool Test
ID
109034
Shared with
Public
Parent
None
Children
Created on
April 19, 2025 at 05:58 AM UTC
Updated on
April 19, 2025 at 05:59 AM UTC
Description

This script is a test of the trim tool, and demonstrates some of the issues I'm having with it.

It runs three tests:
Trim Only
Wiggle and Shake - Changes whole trimmed structure
Idealize and Fix- Changes only part of the trimmed structure

Best for


Code


--[[ This script is to test the trim tool and demostrate unexpected results ]]-- proteins_list = {{ 1, 365}, { 366, 730}, { 731, 1095}, {1096, 1460} } function ScoreAllSegments() segment_scores = {} total_segment_score = 0 for i = 1, 1460 do segment_scores[i] = current.GetSegmentEnergyScore(i) total_segment_score = total_segment_score + 1 end return total_segment_score, segment_scores end function TrimOnly() end -- Simple wiggle and shake test function WiggleAndShake() behavior.SetClashImportance(0.6) structure.WiggleAll(10) structure.ShakeSidechainsAll(1) end -- Cut, idealize and wiggle test function IdealizeAndFix() helix_start = 46 helix_end = 56 -- 89 -- select a helix and idealize structure.InsertCut(helix_end) freeze.Freeze(helix_start - 1, true, false) selection.SelectRange(helix_start, helix_end) structure.SetSecondaryStructureSelected("H") structure.IdealSSSelected() selection.DeselectAll() selection.SelectRange(helix_end + 1, helix_end + 10) behavior.SetClashImportance(0.1) structure.WiggleSelected(10, true, false) structure.DeleteCut(helix_end) selection.SelectRange(helix_start, helix_end) structure.ShakeSidechainsSelected(1) structure.WiggleSelected(3, true, true) behavior.SetClashImportance(1.0) structure.ShakeSidechainsSelected(1) structure.WiggleSelected(10, true, true) end tests = { {"Trim only", TrimOnly}, {"Wiggle and Shake", WiggleAndShake}, {"Idealize and Fix", IdealizeAndFix} } -- Main loop -- Setup save.Quicksave(1) original_score = current.GetEnergyScore() print("Score at start"..original_score) -- Get segment scores print("Scoring all segments") --original_total_segment_score, original_segment_scores = ScoreAllSegments() --print("Total segment score at start "..original_total_segment_score) behavior.SetWigglePower("l") -- Testing loop for test_idx, test_details in ipairs(tests) do test_name = test_details[1] test = test_details[2] save.Quickload(1) -- test_segment_scores = original_segment_scores trimmed_ideal_example_segment = 212 -- Protein loop for protein_idx, protein in ipairs(proteins_list) do print("-------------------------------------------------") print(" ") print("Running test "..test_name.." on protein "..protein_idx) print(" ") untrimmed_ideal_example_segment = (protein_idx - 1) * 365 + trimmed_ideal_example_segment start_score = current.GetEnergyScore() print("Starting at score "..start_score) selection.DeselectAll() selection.SelectRange(protein[1], protein[2]) -- Trim structure.TrimPose() selection.DeselectAll() -- Score the trim trim_start_score = current.GetEnergyScore() print("Starting trim score "..trim_start_score) -- run the test test() -- Rescore the trim trim_end_score = current.GetEnergyScore() print("End trim score "..trim_end_score) expected_score_change = trim_end_score - trim_start_score print("Expected score change "..expected_score_change) expected_end_score = start_score + expected_score_change print("Expected end score "..expected_end_score) ideal_example_trim_score = current.GetSegmentEnergySubscore(trimmed_ideal_example_segment, "ideality") -- Untrim and check score structure.UntrimPose() ideal_example_untrim_score = current.GetSegmentEnergySubscore(untrimmed_ideal_example_segment, "ideality") ideal_change = ideal_example_untrim_score - ideal_example_trim_score end_score = current.GetEnergyScore() print("Actual end score "..end_score) actual_score_change = end_score - start_score print("Actual score change "..actual_score_change) score_change_diff = actual_score_change - expected_score_change print("-------------------------------------------------") print(" Test results") print(" ") if ideal_change == 0 then print("Segment ideal change test passsed") else print(" *** ") msg = "Unexpected idealize score change on segment %i" print(msg:format(untrimmed_ideal_example_segment)) print("of "..ideal_change) print(" *** ") end print(" ") if score_change_diff == 0 then print("Test "..test_name.." passed for protein "..protein_idx) -- Update segment scores for changed protein -- print("Updating scoring for segments") -- for i = protein[1], protein[2] do -- test_segment_scores[i] = current.GetSegmentEnergyScore(i) -- end else print(" *** ") print("Test "..test_name.." failed for protein "..protein_idx) print("With an unexpected score change ") print("of "..score_change_diff) print(" *** ") -- total_unexpected_change = 0 -- for i = 1, 1460 do -- if i < protein[1] or i < protein[2] then -- seg_current_score = current.GetSegmentEnergyScore(i) -- seg_expected_score = test_segment_scores[i] -- seg_score_change = seg_current_score - seg_expected_score -- msg = "Segment %i has an unexpected score change of %f" -- print(msg:format(i, seg_score_change)) -- total_unexpected_change = total_unexpected_change + math.abs(seg_score_change) -- end -- end -- print("Total unexpected segment score change: "..total_unexpected_change) print("Reloading protein") save.Quickload(1) end print(" ") end end

Comments


zeroblue Lv 1

I also roughed in checking the segments in the untrimmed parts for score changes, but ran out of time to test and run this part.

zeroblue Lv 1

Here are my results from running the script on puzzle 2596 on a Windows 10 computer:

Score at start-186976.22652354
Scoring all segments
————————————————-

Running test Trim only on protein 1

Starting at score -186976.22652354
Starting trim score -28956.604092001
End trim score -28956.604092001
Expected score change 0
Expected end score -186976.22652354
Actual end score -186976.22652354
Actual score change 0
————————————————-
Test results

Segment ideal change test passsed

Test Trim only passed for protein 1


Running test Trim only on protein 2

Starting at score -186976.22652354
Starting trim score -21967.922105462
End trim score -21967.922105462
Expected score change 0
Expected end score -186976.22652354
Actual end score -186976.22652354
Actual score change 0
————————————————-
Test results

Segment ideal change test passsed

Test Trim only passed for protein 2


Running test Trim only on protein 3

Starting at score -186976.22652354
Starting trim score -100960.50921253
End trim score -100960.50921253
Expected score change 0
Expected end score -186976.22652354
Actual end score -186976.22652354
Actual score change 0
————————————————-
Test results

Segment ideal change test passsed

Test Trim only passed for protein 3


Running test Trim only on protein 4

Starting at score -186976.22652354
Starting trim score -11091.191113543
End trim score -11091.191113543
Expected score change 0
Expected end score -186976.22652354
Actual end score -186976.22652354
Actual score change 0
————————————————-
Test results

Segment ideal change test passsed

Test Trim only passed for protein 4


Running test Wiggle and Shake on protein 1

Starting at score -186976.22652354
Starting trim score -28956.604092001
End trim score 6245.8752143339
Expected score change 35202.479306335
Expected end score -151773.7472172
Actual end score -205617.81341496
Actual score change -18641.58689142
————————————————-
Test results


Unexpected idealize score change on segment 212
of -5363.4282472836
***


Test Wiggle and Shake failed for protein 1
With an unexpected score change
of -53844.066197755
***
Reloading protein


Running test Wiggle and Shake on protein 2

Starting at score -186976.22652354
Starting trim score -21967.922105462
End trim score 3539.6904917304
Expected score change 25507.612597192
Expected end score -161468.61392634
Actual end score -204737.23749055
Actual score change -17761.010967018
————————————————-
Test results


Unexpected idealize score change on segment 577
of -5363.4288075283
***


Test Wiggle and Shake failed for protein 2
With an unexpected score change
of -43268.623564211
***
Reloading protein


Running test Wiggle and Shake on protein 3

Starting at score -186976.22652354
Starting trim score -100960.50921253
End trim score -68452.920724404
Expected score change 32507.588488126
Expected end score -154468.63803541
Actual end score -219347.93919093
Actual score change -32371.712667393
————————————————-
Test results


Unexpected idealize score change on segment 942
of -5363.4277723449
***


Test Wiggle and Shake failed for protein 3
With an unexpected score change
of -64879.301155519
***
Reloading protein


Running test Wiggle and Shake on protein 4

Starting at score -186976.22652354
Starting trim score -11091.191113543
End trim score 18955.004931552
Expected score change 30046.196045095
Expected end score -156930.03047844
Actual end score -221449.89283122
Actual score change -34473.666307683
————————————————-
Test results


Unexpected idealize score change on segment 1307
of -5363.4268499749
***


Test Wiggle and Shake failed for protein 4
With an unexpected score change
of -64519.862352778
***
Reloading protein


Running test Idealize and Fix on protein 1

Starting at score -186976.22652354
Starting trim score -28956.604092001
End trim score -28225.861093512
Expected score change 730.7429984889
Expected end score -186245.48352505
Actual end score -196987.66749697
Actual score change -10011.44097343
————————————————-
Test results

Segment ideal change test passsed


Test Idealize and Fix failed for protein 1
With an unexpected score change
of -10742.183971919
***
Reloading protein


Running test Idealize and Fix on protein 2

Starting at score -186976.22652354
Starting trim score -21967.922105462
End trim score -19686.857220655
Expected score change 2281.0648848068
Expected end score -184695.16163873
Actual end score -195428.45167921
Actual score change -8452.225155677
————————————————-
Test results

Segment ideal change test passsed


Test Idealize and Fix failed for protein 2
With an unexpected score change
of -10733.290040484
***
Reloading protein


Running test Idealize and Fix on protein 3

Starting at score -186976.22652354
Starting trim score -100960.50921253
End trim score -98320.617468621
Expected score change 2639.8917439087
Expected end score -184336.33477963
Actual end score -195064.84269403
Actual score change -8088.6161704888
————————————————-
Test results

Segment ideal change test passsed


Test Idealize and Fix failed for protein 3
With an unexpected score change
of -10728.507914397
***
Reloading protein


Running test Idealize and Fix on protein 4

Starting at score -186976.22652354
Starting trim score -11091.191113543
End trim score -10488.458762346
Expected score change 602.73235119705
Expected end score -186373.49417234
Actual end score -197106.59776497
Actual score change -10130.371241435
————————————————-
Test results

Segment ideal change test passsed


Test Idealize and Fix failed for protein 4
With an unexpected score change
of -10733.103592632
***
Reloading protein

bravosk8erboy Lv 1

i have also been noticing that untrim will mess with the ideal score of a few segments. you can take the 10 lowest scoring segments and shake them to fix this issue. the shake doesn't seem to do much to the actual rotamer of the sidechain but does fix the score. you can hand pick the red segments or write a recipe that picks the 10 worst scoring segments. that way you only have to shake a few and it is a quick fix to the score with no real change in atom positions.

bravosk8erboy Lv 1

trim tool on it's own is kinda tricky and unituitive. segments in the trim will often expand over other trimmed out segments. when untrimmed these segments will overlap and give worst scores. this can be tricky to fix and sometimes is worse over all. using a larger trim then selecting a small group of segments within the trim so there is a buffer to the grayed out segments can help, but this issue you experienced is still going to happen. you can look at this recipe for more info on how trim needs additional steps to work properly in recipes. also segment index numbers will change https://fold.it/recipes/108963

zeroblue Lv 1

Thanks, I'll take a look. I've been trying to trim entire proteins (as shown in my script) and so the reindexing is pretty easy.